1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
32 #include "gtkcontainer.h"
33 #include "gtkaccelmap.h"
34 #include "gtkclipboard.h"
35 #include "gtkiconfactory.h"
38 #include "gtkmarshalers.h"
40 #include "gtkselection.h"
41 #include "gtksettings.h"
42 #include "gtksizegroup.h"
43 #include "gtkwidget.h"
44 #include "gtkwindow.h"
45 #include "gtkbindings.h"
46 #include "gtkprivate.h"
48 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
49 #include <gobject/gvaluecollector.h>
50 #include <gobject/gobjectnotifyqueue.c>
51 #include "gdk/gdkkeysyms.h"
53 #include "gtkaccessible.h"
54 #include "gtktooltips.h"
55 #include "gtkinvisible.h"
57 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
58 #define INIT_PATH_SIZE (512)
98 PROPERTY_NOTIFY_EVENT,
99 SELECTION_CLEAR_EVENT,
100 SELECTION_REQUEST_EVENT,
101 SELECTION_NOTIFY_EVENT,
116 VISIBILITY_NOTIFY_EVENT,
120 ACCEL_CLOSURES_CHANGED,
140 PROP_RECEIVES_DEFAULT,
141 PROP_COMPOSITE_CHILD,
144 PROP_EXTENSION_EVENTS,
148 typedef struct _GtkStateData GtkStateData;
153 guint state_restoration : 1;
154 guint parent_sensitive : 1;
155 guint use_forall : 1;
159 /* --- prototypes --- */
160 static void gtk_widget_class_init (GtkWidgetClass *klass);
161 static void gtk_widget_init (GtkWidget *widget);
162 static void gtk_widget_set_property (GObject *object,
166 static void gtk_widget_get_property (GObject *object,
170 static void gtk_widget_dispose (GObject *object);
171 static void gtk_widget_real_destroy (GtkObject *object);
172 static void gtk_widget_finalize (GObject *object);
173 static void gtk_widget_real_show (GtkWidget *widget);
174 static void gtk_widget_real_hide (GtkWidget *widget);
175 static void gtk_widget_real_map (GtkWidget *widget);
176 static void gtk_widget_real_unmap (GtkWidget *widget);
177 static void gtk_widget_real_realize (GtkWidget *widget);
178 static void gtk_widget_real_unrealize (GtkWidget *widget);
179 static void gtk_widget_real_size_request (GtkWidget *widget,
180 GtkRequisition *requisition);
181 static void gtk_widget_real_size_allocate (GtkWidget *widget,
182 GtkAllocation *allocation);
183 static void gtk_widget_style_set (GtkWidget *widget,
184 GtkStyle *previous_style);
185 static void gtk_widget_direction_changed (GtkWidget *widget,
186 GtkTextDirection previous_direction);
188 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
189 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
190 GtkWidgetHelpType help_type);
192 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
194 GParamSpec **pspecs);
195 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
197 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
199 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
200 GdkEventFocus *event);
201 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
202 GdkEventFocus *event);
203 static gboolean gtk_widget_real_focus (GtkWidget *widget,
204 GtkDirectionType direction);
205 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
206 static void gtk_widget_propagate_state (GtkWidget *widget,
208 static void gtk_widget_reset_rc_style (GtkWidget *widget);
209 static void gtk_widget_set_style_internal (GtkWidget *widget,
211 gboolean initial_emission);
212 static gint gtk_widget_event_internal (GtkWidget *widget,
214 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
215 gboolean group_cycling);
216 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
217 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
218 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
219 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
220 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
222 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
223 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
224 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
227 static void gtk_widget_set_usize_internal (GtkWidget *widget,
232 /* --- variables --- */
233 static gpointer parent_class = NULL;
234 static guint widget_signals[LAST_SIGNAL] = { 0 };
235 static GMemChunk *aux_info_mem_chunk = NULL;
236 static GtkStyle *gtk_default_style = NULL;
237 static GSList *colormap_stack = NULL;
238 static guint composite_child_stack = 0;
239 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
240 static GParamSpecPool *style_property_spec_pool = NULL;
242 static GQuark quark_property_parser = 0;
243 static GQuark quark_aux_info = 0;
244 static GQuark quark_accel_path = 0;
245 static GQuark quark_accel_closures = 0;
246 static GQuark quark_event_mask = 0;
247 static GQuark quark_extension_event_mode = 0;
248 static GQuark quark_parent_window = 0;
249 static GQuark quark_shape_info = 0;
250 static GQuark quark_colormap = 0;
251 static GQuark quark_pango_context = 0;
252 static GQuark quark_rc_style = 0;
253 static GQuark quark_accessible_object = 0;
254 static GQuark quark_mnemonic_labels = 0;
255 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
256 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
258 /* --- functions --- */
260 gtk_widget_get_type (void)
262 static GType widget_type = 0;
266 static const GTypeInfo widget_info =
268 sizeof (GtkWidgetClass),
269 NULL, /* base_init */
270 NULL, /* base_finalize */
271 (GClassInitFunc) gtk_widget_class_init,
272 NULL, /* class_finalize */
273 NULL, /* class_init */
276 (GInstanceInitFunc) gtk_widget_init,
277 NULL, /* value_table */
280 static const GInterfaceInfo accessibility_info =
282 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
283 (GInterfaceFinalizeFunc) NULL,
284 NULL /* interface data */
287 widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
288 &widget_info, G_TYPE_FLAG_ABSTRACT);
290 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
291 &accessibility_info) ;
299 child_property_notify_dispatcher (GObject *object,
303 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
307 gtk_widget_class_init (GtkWidgetClass *klass)
309 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
310 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
311 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
312 GtkBindingSet *binding_set;
314 parent_class = g_type_class_peek_parent (klass);
316 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
317 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
318 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
319 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
320 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
321 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
322 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
323 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
324 quark_colormap = g_quark_from_static_string ("gtk-colormap");
325 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
326 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
327 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
328 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
330 style_property_spec_pool = g_param_spec_pool_new (FALSE);
331 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
332 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
333 cpn_context.dispatcher = child_property_notify_dispatcher;
334 _gtk_widget_child_property_notify_context = &cpn_context;
336 gobject_class->dispose = gtk_widget_dispose;
337 gobject_class->finalize = gtk_widget_finalize;
338 gobject_class->set_property = gtk_widget_set_property;
339 gobject_class->get_property = gtk_widget_get_property;
341 object_class->destroy = gtk_widget_real_destroy;
343 klass->activate_signal = 0;
344 klass->set_scroll_adjustments_signal = 0;
345 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
346 klass->show = gtk_widget_real_show;
347 klass->show_all = gtk_widget_show;
348 klass->hide = gtk_widget_real_hide;
349 klass->hide_all = gtk_widget_hide;
350 klass->map = gtk_widget_real_map;
351 klass->unmap = gtk_widget_real_unmap;
352 klass->realize = gtk_widget_real_realize;
353 klass->unrealize = gtk_widget_real_unrealize;
354 klass->size_request = gtk_widget_real_size_request;
355 klass->size_allocate = gtk_widget_real_size_allocate;
356 klass->state_changed = NULL;
357 klass->parent_set = NULL;
358 klass->hierarchy_changed = NULL;
359 klass->style_set = gtk_widget_style_set;
360 klass->direction_changed = gtk_widget_direction_changed;
361 klass->grab_notify = NULL;
362 klass->child_notify = NULL;
363 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
364 klass->grab_focus = gtk_widget_real_grab_focus;
365 klass->focus = gtk_widget_real_focus;
367 klass->button_press_event = NULL;
368 klass->button_release_event = NULL;
369 klass->motion_notify_event = NULL;
370 klass->delete_event = NULL;
371 klass->destroy_event = NULL;
372 klass->expose_event = NULL;
373 klass->key_press_event = gtk_widget_real_key_press_event;
374 klass->key_release_event = gtk_widget_real_key_release_event;
375 klass->enter_notify_event = NULL;
376 klass->leave_notify_event = NULL;
377 klass->configure_event = NULL;
378 klass->focus_in_event = gtk_widget_real_focus_in_event;
379 klass->focus_out_event = gtk_widget_real_focus_out_event;
380 klass->map_event = NULL;
381 klass->unmap_event = NULL;
382 klass->window_state_event = NULL;
383 klass->property_notify_event = _gtk_selection_property_notify;
384 klass->selection_clear_event = gtk_selection_clear;
385 klass->selection_request_event = _gtk_selection_request;
386 klass->selection_notify_event = _gtk_selection_notify;
387 klass->selection_received = NULL;
388 klass->proximity_in_event = NULL;
389 klass->proximity_out_event = NULL;
390 klass->drag_begin = NULL;
391 klass->drag_end = NULL;
392 klass->drag_data_delete = NULL;
393 klass->drag_leave = NULL;
394 klass->drag_motion = NULL;
395 klass->drag_drop = NULL;
396 klass->drag_data_received = NULL;
397 klass->screen_changed = NULL;
398 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
400 klass->show_help = gtk_widget_real_show_help;
402 /* Accessibility support */
403 klass->get_accessible = gtk_widget_real_get_accessible;
405 klass->no_expose_event = NULL;
407 g_object_class_install_property (gobject_class,
409 g_param_spec_string ("name",
411 P_("The name of the widget"),
414 g_object_class_install_property (gobject_class,
416 g_param_spec_object ("parent",
418 P_("The parent widget of this widget. Must be a Container widget"),
422 g_object_class_install_property (gobject_class,
424 g_param_spec_int ("width_request",
426 P_("Override for width request of the widget, or -1 if natural request should be used"),
431 g_object_class_install_property (gobject_class,
433 g_param_spec_int ("height_request",
434 P_("Height request"),
435 P_("Override for height request of the widget, or -1 if natural request should be used"),
440 g_object_class_install_property (gobject_class,
442 g_param_spec_boolean ("visible",
444 P_("Whether the widget is visible"),
447 g_object_class_install_property (gobject_class,
449 g_param_spec_boolean ("sensitive",
451 P_("Whether the widget responds to input"),
454 g_object_class_install_property (gobject_class,
456 g_param_spec_boolean ("app_paintable",
457 P_("Application paintable"),
458 P_("Whether the application will paint directly on the widget"),
461 g_object_class_install_property (gobject_class,
463 g_param_spec_boolean ("can_focus",
465 P_("Whether the widget can accept the input focus"),
468 g_object_class_install_property (gobject_class,
470 g_param_spec_boolean ("has_focus",
472 P_("Whether the widget has the input focus"),
475 g_object_class_install_property (gobject_class,
477 g_param_spec_boolean ("is_focus",
479 P_("Whether the widget is the focus widget within the toplevel"),
482 g_object_class_install_property (gobject_class,
484 g_param_spec_boolean ("can_default",
486 P_("Whether the widget can be the default widget"),
489 g_object_class_install_property (gobject_class,
491 g_param_spec_boolean ("has_default",
493 P_("Whether the widget is the default widget"),
496 g_object_class_install_property (gobject_class,
497 PROP_RECEIVES_DEFAULT,
498 g_param_spec_boolean ("receives_default",
499 P_("Receives default"),
500 P_("If TRUE, the widget will receive the default action when it is focused"),
503 g_object_class_install_property (gobject_class,
504 PROP_COMPOSITE_CHILD,
505 g_param_spec_boolean ("composite_child",
506 P_("Composite child"),
507 P_("Whether the widget is part of a composite widget"),
510 g_object_class_install_property (gobject_class,
512 g_param_spec_object ("style",
514 P_("The style of the widget, which contains information about how it will look (colors etc)"),
517 g_object_class_install_property (gobject_class,
519 g_param_spec_flags ("events",
521 P_("The event mask that decides what kind of GdkEvents this widget gets"),
525 g_object_class_install_property (gobject_class,
526 PROP_EXTENSION_EVENTS,
527 g_param_spec_enum ("extension_events",
528 P_("Extension events"),
529 P_("The mask that decides what kind of extension events this widget gets"),
530 GDK_TYPE_EXTENSION_MODE,
531 GDK_EXTENSION_EVENTS_NONE,
533 g_object_class_install_property (gobject_class,
535 g_param_spec_boolean ("no_show_all",
537 P_("Whether gtk_widget_show_all() should not affect this widget"),
540 widget_signals[SHOW] =
541 g_signal_new ("show",
542 G_TYPE_FROM_CLASS (gobject_class),
544 G_STRUCT_OFFSET (GtkWidgetClass, show),
546 _gtk_marshal_VOID__VOID,
548 widget_signals[HIDE] =
549 g_signal_new ("hide",
550 G_TYPE_FROM_CLASS (gobject_class),
552 G_STRUCT_OFFSET (GtkWidgetClass, hide),
554 _gtk_marshal_VOID__VOID,
556 widget_signals[MAP] =
558 G_TYPE_FROM_CLASS (gobject_class),
560 G_STRUCT_OFFSET (GtkWidgetClass, map),
562 _gtk_marshal_VOID__VOID,
564 widget_signals[UNMAP] =
565 g_signal_new ("unmap",
566 G_TYPE_FROM_CLASS (gobject_class),
568 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
570 _gtk_marshal_VOID__VOID,
572 widget_signals[REALIZE] =
573 g_signal_new ("realize",
574 G_TYPE_FROM_CLASS (gobject_class),
576 G_STRUCT_OFFSET (GtkWidgetClass, realize),
578 _gtk_marshal_VOID__VOID,
580 widget_signals[UNREALIZE] =
581 g_signal_new ("unrealize",
582 G_TYPE_FROM_CLASS (gobject_class),
584 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
586 _gtk_marshal_VOID__VOID,
588 widget_signals[SIZE_REQUEST] =
589 g_signal_new ("size_request",
590 G_TYPE_FROM_CLASS (gobject_class),
592 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
594 _gtk_marshal_VOID__BOXED,
596 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
597 widget_signals[SIZE_ALLOCATE] =
598 g_signal_new ("size_allocate",
599 G_TYPE_FROM_CLASS (gobject_class),
601 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
603 _gtk_marshal_VOID__BOXED,
605 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
606 widget_signals[STATE_CHANGED] =
607 g_signal_new ("state_changed",
608 G_TYPE_FROM_CLASS (gobject_class),
610 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
612 _gtk_marshal_VOID__ENUM,
614 GTK_TYPE_STATE_TYPE);
615 widget_signals[PARENT_SET] =
616 g_signal_new ("parent_set",
617 G_TYPE_FROM_CLASS (gobject_class),
619 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
621 _gtk_marshal_VOID__OBJECT,
624 widget_signals[HIERARCHY_CHANGED] =
625 g_signal_new ("hierarchy_changed",
626 G_TYPE_FROM_CLASS (gobject_class),
628 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
630 _gtk_marshal_VOID__OBJECT,
633 widget_signals[STYLE_SET] =
634 g_signal_new ("style_set",
635 G_TYPE_FROM_CLASS (gobject_class),
637 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
639 _gtk_marshal_VOID__OBJECT,
642 widget_signals[DIRECTION_CHANGED] =
643 g_signal_new ("direction_changed",
644 G_TYPE_FROM_CLASS (gobject_class),
646 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
648 _gtk_marshal_VOID__ENUM,
650 GTK_TYPE_TEXT_DIRECTION);
651 widget_signals[GRAB_NOTIFY] =
652 g_signal_new ("grab_notify",
653 G_TYPE_FROM_CLASS (gobject_class),
655 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
657 _gtk_marshal_VOID__BOOLEAN,
662 * GtkWidget::child-notify:
663 * @widget: the object which received the signal.
664 * @pspec: the #GParamSpec of the changed child property.
666 * The ::child-notify signal is emitted for each child property that has
667 * changed on an object. The signal's detail holds the property name.
669 widget_signals[CHILD_NOTIFY] =
670 g_signal_new ("child_notify",
671 G_TYPE_FROM_CLASS (gobject_class),
672 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
673 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
675 g_cclosure_marshal_VOID__PARAM,
678 widget_signals[MNEMONIC_ACTIVATE] =
679 g_signal_new ("mnemonic_activate",
680 G_TYPE_FROM_CLASS (gobject_class),
682 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
683 _gtk_boolean_handled_accumulator, NULL,
684 _gtk_marshal_BOOLEAN__BOOLEAN,
687 widget_signals[GRAB_FOCUS] =
688 g_signal_new ("grab_focus",
689 G_TYPE_FROM_CLASS (gobject_class),
690 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
691 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
693 _gtk_marshal_VOID__VOID,
695 widget_signals[FOCUS] =
696 g_signal_new ("focus",
697 G_TYPE_FROM_CLASS (object_class),
699 G_STRUCT_OFFSET (GtkWidgetClass, focus),
700 _gtk_boolean_handled_accumulator, NULL,
701 _gtk_marshal_BOOLEAN__ENUM,
703 GTK_TYPE_DIRECTION_TYPE);
704 widget_signals[EVENT] =
705 g_signal_new ("event",
706 G_TYPE_FROM_CLASS (gobject_class),
708 G_STRUCT_OFFSET (GtkWidgetClass, event),
709 _gtk_boolean_handled_accumulator, NULL,
710 _gtk_marshal_BOOLEAN__BOXED,
712 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
713 widget_signals[EVENT_AFTER] =
714 g_signal_new ("event-after",
715 G_TYPE_FROM_CLASS (gobject_class),
719 _gtk_marshal_VOID__BOXED,
721 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
722 widget_signals[BUTTON_PRESS_EVENT] =
723 g_signal_new ("button_press_event",
724 G_TYPE_FROM_CLASS (gobject_class),
726 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
727 _gtk_boolean_handled_accumulator, NULL,
728 _gtk_marshal_BOOLEAN__BOXED,
730 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
731 widget_signals[BUTTON_RELEASE_EVENT] =
732 g_signal_new ("button_release_event",
733 G_TYPE_FROM_CLASS (gobject_class),
735 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
736 _gtk_boolean_handled_accumulator, NULL,
737 _gtk_marshal_BOOLEAN__BOXED,
739 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
740 widget_signals[SCROLL_EVENT] =
741 g_signal_new ("scroll_event",
742 G_TYPE_FROM_CLASS (gobject_class),
744 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
745 _gtk_boolean_handled_accumulator, NULL,
746 _gtk_marshal_BOOLEAN__BOXED,
748 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
749 widget_signals[MOTION_NOTIFY_EVENT] =
750 g_signal_new ("motion_notify_event",
751 G_TYPE_FROM_CLASS (gobject_class),
753 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
754 _gtk_boolean_handled_accumulator, NULL,
755 _gtk_marshal_BOOLEAN__BOXED,
757 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
760 * GtkWidget::delete-event:
761 * @widget: the object which received the signal.
762 * @event: the event which triggered this signal
764 * The ::delete-event signal is emitted if a user requests that
765 * a toplevel window is closed. The default handler for this signal
766 * destroys the window. Connecting gtk_widget_hide_on_delete() to
767 * this signal will cause the window to be hidden instead, so that
768 * it can later be shown again without reconstructing it.
770 * Returns: %TRUE to stop other handlers from being invoked for the event.
771 * %FALSE to propagate the event further.
773 widget_signals[DELETE_EVENT] =
774 g_signal_new ("delete_event",
775 G_TYPE_FROM_CLASS (gobject_class),
777 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
778 _gtk_boolean_handled_accumulator, NULL,
779 _gtk_marshal_BOOLEAN__BOXED,
781 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
784 * GtkWidget::destroy-event:
785 * @widget: the object which received the signal.
786 * @event: the event which triggered this signal
788 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
789 * You rarely get this signal, because most widgets disconnect themselves
790 * from their window before they destroy it, so no widget owns the
791 * window at destroy time.
793 * Returns: %TRUE to stop other handlers from being invoked for the event.
794 * %FALSE to propagate the event further.
796 widget_signals[DESTROY_EVENT] =
797 g_signal_new ("destroy_event",
798 G_TYPE_FROM_CLASS (gobject_class),
800 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
801 _gtk_boolean_handled_accumulator, NULL,
802 _gtk_marshal_BOOLEAN__BOXED,
804 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
805 widget_signals[EXPOSE_EVENT] =
806 g_signal_new ("expose_event",
807 G_TYPE_FROM_CLASS (gobject_class),
809 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
810 _gtk_boolean_handled_accumulator, NULL,
811 _gtk_marshal_BOOLEAN__BOXED,
813 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
814 widget_signals[KEY_PRESS_EVENT] =
815 g_signal_new ("key_press_event",
816 G_TYPE_FROM_CLASS (gobject_class),
818 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
819 _gtk_boolean_handled_accumulator, NULL,
820 _gtk_marshal_BOOLEAN__BOXED,
822 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
823 widget_signals[KEY_RELEASE_EVENT] =
824 g_signal_new ("key_release_event",
825 G_TYPE_FROM_CLASS (gobject_class),
827 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
828 _gtk_boolean_handled_accumulator, NULL,
829 _gtk_marshal_BOOLEAN__BOXED,
831 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
832 widget_signals[ENTER_NOTIFY_EVENT] =
833 g_signal_new ("enter_notify_event",
834 G_TYPE_FROM_CLASS (gobject_class),
836 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
837 _gtk_boolean_handled_accumulator, NULL,
838 _gtk_marshal_BOOLEAN__BOXED,
840 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
841 widget_signals[LEAVE_NOTIFY_EVENT] =
842 g_signal_new ("leave_notify_event",
843 G_TYPE_FROM_CLASS (gobject_class),
845 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
846 _gtk_boolean_handled_accumulator, NULL,
847 _gtk_marshal_BOOLEAN__BOXED,
849 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
850 widget_signals[CONFIGURE_EVENT] =
851 g_signal_new ("configure_event",
852 G_TYPE_FROM_CLASS (gobject_class),
854 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
855 _gtk_boolean_handled_accumulator, NULL,
856 _gtk_marshal_BOOLEAN__BOXED,
858 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
859 widget_signals[FOCUS_IN_EVENT] =
860 g_signal_new ("focus_in_event",
861 G_TYPE_FROM_CLASS (gobject_class),
863 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
864 _gtk_boolean_handled_accumulator, NULL,
865 _gtk_marshal_BOOLEAN__BOXED,
867 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
868 widget_signals[FOCUS_OUT_EVENT] =
869 g_signal_new ("focus_out_event",
870 G_TYPE_FROM_CLASS (gobject_class),
872 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
873 _gtk_boolean_handled_accumulator, NULL,
874 _gtk_marshal_BOOLEAN__BOXED,
876 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
877 widget_signals[MAP_EVENT] =
878 g_signal_new ("map_event",
879 G_TYPE_FROM_CLASS (gobject_class),
881 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
882 _gtk_boolean_handled_accumulator, NULL,
883 _gtk_marshal_BOOLEAN__BOXED,
885 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
886 widget_signals[UNMAP_EVENT] =
887 g_signal_new ("unmap_event",
888 G_TYPE_FROM_CLASS (gobject_class),
890 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
891 _gtk_boolean_handled_accumulator, NULL,
892 _gtk_marshal_BOOLEAN__BOXED,
894 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
895 widget_signals[PROPERTY_NOTIFY_EVENT] =
896 g_signal_new ("property_notify_event",
897 G_TYPE_FROM_CLASS (gobject_class),
899 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
900 _gtk_boolean_handled_accumulator, NULL,
901 _gtk_marshal_BOOLEAN__BOXED,
903 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
904 widget_signals[SELECTION_CLEAR_EVENT] =
905 g_signal_new ("selection_clear_event",
906 G_TYPE_FROM_CLASS (gobject_class),
908 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
909 _gtk_boolean_handled_accumulator, NULL,
910 _gtk_marshal_BOOLEAN__BOXED,
912 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
913 widget_signals[SELECTION_REQUEST_EVENT] =
914 g_signal_new ("selection_request_event",
915 G_TYPE_FROM_CLASS (gobject_class),
917 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
918 _gtk_boolean_handled_accumulator, NULL,
919 _gtk_marshal_BOOLEAN__BOXED,
921 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
922 widget_signals[SELECTION_NOTIFY_EVENT] =
923 g_signal_new ("selection_notify_event",
924 G_TYPE_FROM_CLASS (gobject_class),
926 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
927 _gtk_boolean_handled_accumulator, NULL,
928 _gtk_marshal_BOOLEAN__BOXED,
930 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
931 widget_signals[SELECTION_RECEIVED] =
932 g_signal_new ("selection_received",
933 G_TYPE_FROM_CLASS (gobject_class),
935 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
937 _gtk_marshal_VOID__BOXED_UINT,
939 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
941 widget_signals[SELECTION_GET] =
942 g_signal_new ("selection_get",
943 G_TYPE_FROM_CLASS (gobject_class),
945 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
947 _gtk_marshal_VOID__BOXED_UINT_UINT,
949 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
952 widget_signals[PROXIMITY_IN_EVENT] =
953 g_signal_new ("proximity_in_event",
954 G_TYPE_FROM_CLASS (gobject_class),
956 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
957 _gtk_boolean_handled_accumulator, NULL,
958 _gtk_marshal_BOOLEAN__BOXED,
960 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
961 widget_signals[PROXIMITY_OUT_EVENT] =
962 g_signal_new ("proximity_out_event",
963 G_TYPE_FROM_CLASS (gobject_class),
965 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
966 _gtk_boolean_handled_accumulator, NULL,
967 _gtk_marshal_BOOLEAN__BOXED,
969 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
972 * GtkWidget::drag-leave:
973 * @widget: the object which received the signal.
974 * @drag_context: the drag context
975 * @time: the timestamp of the motion event
977 * The ::drag-leave signal is emitted on the drop site when the cursor leaves the widget.
978 * A typical reason to connect to this signal is to undo things done in ::drag-motion, e.g.
979 * undo highlighting with gtk_drag_unhighlight()
981 widget_signals[DRAG_LEAVE] =
982 g_signal_new ("drag_leave",
983 G_TYPE_FROM_CLASS (gobject_class),
985 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
987 _gtk_marshal_VOID__OBJECT_UINT,
989 GDK_TYPE_DRAG_CONTEXT,
993 * GtkWidget::drag-begin:
994 * @widget: the object which received the signal.
995 * @drag_context: the drag context
997 * The ::drag-begin signal is emitted on the drag source when a drag is started.
998 * A typical reason to connect to this signal is to set up a custom drag icon with
999 * gtk_drag_source_set_icon().
1001 widget_signals[DRAG_BEGIN] =
1002 g_signal_new ("drag_begin",
1003 G_TYPE_FROM_CLASS (gobject_class),
1005 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
1007 _gtk_marshal_VOID__OBJECT,
1009 GDK_TYPE_DRAG_CONTEXT);
1012 * GtkWidget::drag-end:
1013 * @widget: the object which received the signal.
1014 * @drag_context: the drag context
1016 * The ::drag-end signal is emitted on the drag source when a drag is finished.
1017 * A typical reason to connect to this signal is to undo things done in ::drag-begin.
1019 widget_signals[DRAG_END] =
1020 g_signal_new ("drag_end",
1021 G_TYPE_FROM_CLASS (gobject_class),
1023 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
1025 _gtk_marshal_VOID__OBJECT,
1027 GDK_TYPE_DRAG_CONTEXT);
1030 * GtkWidget::drag-data-delete:
1031 * @widget: the object which received the signal.
1032 * @drag_context: the drag context
1034 * The ::drag-data-delete signal is emitted on the drag source when a drag with the action
1035 * %GDK_ACTION_MOVE is successfully completed. The signal handler is responsible for deleting
1036 * the data that has been dropped. What "delete" means, depends on the context of the drag
1039 widget_signals[DRAG_DATA_DELETE] =
1040 g_signal_new ("drag_data_delete",
1041 G_TYPE_FROM_CLASS (gobject_class),
1043 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
1045 _gtk_marshal_VOID__OBJECT,
1047 GDK_TYPE_DRAG_CONTEXT);
1050 * GtkWidget::drag-motion:
1051 * @widget: the object which received the signal.
1052 * @drag_context: the drag context
1053 * @x: the x coordinate of the current cursor position
1054 * @y: the y coordinate of the current cursor position
1055 * @time: the timestamp of the motion event
1056 * @returns: whether the cursor position is in a drop zone
1058 * The ::drag-motion signal is emitted on the drop site when the user moves the cursor over
1059 * the widget during a drag. The signal handler must determine whether the cursor position is in
1060 * a drop zone or not. If it is not in a drop zone, it returns %FALSE and no further processing is
1061 * necessary. Otherwise, the handler returns %TRUE. In this case, the handler is responsible for
1062 * providing the necessary information for displaying feedback to the user, by calling
1063 * gdk_drag_status(). If the decision whether the drop will be accepted or rejected can't be made
1064 * based solely on the cursor position and the type of the data, the handler may inspect the dragged
1065 * data by calling gtk_drag_get_data() and defer the gdk_drag_status() call to the ::drag-data-received
1068 * Note that there is no ::drag-enter signal. The drag receiver has to keep track of whether
1069 * he has received any ::drag-motion signals since the last ::drag-leave and if not, treat the
1070 * ::drag-motion signal as an "enter" signal. Upon an "enter", the handler will typically highlight
1071 * the drop site with gtk_drag_highlight().
1073 * <informalexample><programlisting>
1075 * drag_motion (GtkWidget *widget,
1076 * GdkDragContext *context,
1083 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1085 * if (!private_data->drag_highlight)
1087 * private_data->drag_highlight = 1;
1088 * gtk_drag_highlight (widget);
1091 * target = gtk_drag_dest_find_target (widget, context, NULL);
1092 * if (target == GDK_NONE)
1093 * gdk_drag_status (context, 0, time);
1096 * private_data->pending_status = context->suggested_action;
1097 * gtk_drag_get_data (widget, context, target, time);
1104 * drag_data_received (GtkWidget *widget,
1105 * GdkDragContext *context,
1108 * GtkSelectionData *selection_data,
1112 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1114 * if (private_data->suggested_action)
1116 * private_data->suggested_action = 0;
1118 * /<!-- -->* We are getting this data due to a request in drag_motion,
1119 * * rather than due to a request in drag_drop, so we are just
1120 * * supposed to call gdk_drag_status(<!-- -->), not actually paste in the data.
1122 * str = gtk_selection_data_get_text (selection_data);
1123 * if (!data_is_acceptable (str))
1124 * gdk_drag_status (context, 0, time);
1126 * gdk_drag_status (context, private_data->suggested_action, time);
1130 * /<!-- -->* accept the drop *<!-- -->/
1133 * </programlisting></informalexample>
1135 widget_signals[DRAG_MOTION] =
1136 g_signal_new ("drag_motion",
1137 G_TYPE_FROM_CLASS (gobject_class),
1139 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
1140 _gtk_boolean_handled_accumulator, NULL,
1141 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1143 GDK_TYPE_DRAG_CONTEXT,
1149 * GtkWidget::drag-drop:
1150 * @widget: the object which received the signal.
1151 * @drag_context: the drag context
1152 * @x: the x coordinate of the current cursor position
1153 * @y: the y coordinate of the current cursor position
1154 * @time: the timestamp of the motion event
1155 * @returns: whether the cursor position is in a drop zone
1157 * The ::drag-drop signal is emitted on the drop site when the user drops the data
1158 * onto the widget. The signal handler must determine whether the cursor position is in
1159 * a drop zone or not. If it is not in a drop zone, it returns %FALSE and no further
1160 * processing is necessary. Otherwise, the handler returns %TRUE. In this case, the handler
1161 * must ensure that gtk_drag_finish() is called to let the source know that the drop is done.
1162 * The call to gtk_drag_finish() can be done either directly or in a ::drag-data-received handler
1163 * which gets triggered by calling gtk_drop_get_data() to receive the data for one or more of the
1164 * supported targets.
1166 widget_signals[DRAG_DROP] =
1167 g_signal_new ("drag_drop",
1168 G_TYPE_FROM_CLASS (gobject_class),
1170 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
1171 _gtk_boolean_handled_accumulator, NULL,
1172 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1174 GDK_TYPE_DRAG_CONTEXT,
1180 * GtkWidget::drag-data-get:
1181 * @widget: the object which received the signal.
1182 * @drag_context: the drag context
1183 * @data: the #GtkSelectionData to be filled with the dragged data
1184 * @info: the info that has been registered with the target in the #GtkTargetList.
1185 * @time: the timestamp at which the data was requested
1187 * The ::drag-data-get signal is emitted on the drag source when the drop site requests
1188 * the data which is dragged. It is the responsibility of the signal handler to fill @data
1189 * with the data in the format which is indicated by @info. See gtk_selection_data_set() and
1190 * gtk_selection_data_set_text().
1192 widget_signals[DRAG_DATA_GET] =
1193 g_signal_new ("drag_data_get",
1194 G_TYPE_FROM_CLASS (gobject_class),
1196 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
1198 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
1200 GDK_TYPE_DRAG_CONTEXT,
1201 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1206 * GtkWidget::drag-data-received:
1207 * @widget: the object which received the signal.
1208 * @drag_context: the drag context
1209 * @x: where the drop happened
1210 * @y: where the drop happened
1211 * @data: the received data
1212 * @info: the info that has been registered with the target in the #GtkTargetList.
1213 * @time: the timestamp at which the data was received
1215 * The ::drag-data-received signal is emitted on the drop site when the dragged data has been
1216 * received. If the data was received in order to determine whether the drop will be accepted,
1217 * the handler is expected to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
1218 * If the data was received in response to a ::drag-drop signal (and this is the last target to be
1219 * received), the handler for this signal is expected to process the received data and then call
1220 * gtk_drag_finish(), setting the @success parameter depending on whether the data was processed
1223 * The handler may inspect and modify @drag_context->action before calling gtk_drag_finish(),
1224 * e.g. to implement %GDK_ACTION_ASK as shown in the following example:
1225 * <informalexample><programlisting>
1227 * drag_data_received (GtkWidget *widget,
1228 * GdkDragContext *drag_context,
1231 * GtkSelectionData *data,
1235 * if ((data->length >= 0) && (data->format == 8))
1237 * if (drag_context->action == GDK_ACTION_ASK)
1239 * GtkWidget *dialog;
1242 * dialog = gtk_message_dialog_new (NULL,
1243 * GTK_DIALOG_MODAL |
1244 * GTK_DIALOG_DESTROY_WITH_PARENT,
1246 * GTK_BUTTONS_YES_NO,
1247 * "Move the data ?\n");
1248 * response = gtk_dialog_run (GTK_DIALOG (dialog));
1249 * gtk_widget_destroy (dialog);
1251 * if (response == GTK_RESPONSE_YES)
1252 * drag_context->action = GDK_ACTION_MOVE;
1254 * drag_context->action = GDK_ACTION_COPY;
1257 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
1261 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
1263 * </programlisting></informalexample>
1265 widget_signals[DRAG_DATA_RECEIVED] =
1266 g_signal_new ("drag_data_received",
1267 G_TYPE_FROM_CLASS (gobject_class),
1269 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
1271 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
1273 GDK_TYPE_DRAG_CONTEXT,
1276 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1279 widget_signals[VISIBILITY_NOTIFY_EVENT] =
1280 g_signal_new ("visibility_notify_event",
1281 G_TYPE_FROM_CLASS (gobject_class),
1283 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
1284 _gtk_boolean_handled_accumulator, NULL,
1285 _gtk_marshal_BOOLEAN__BOXED,
1287 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1288 widget_signals[CLIENT_EVENT] =
1289 g_signal_new ("client_event",
1290 G_TYPE_FROM_CLASS (gobject_class),
1292 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
1293 _gtk_boolean_handled_accumulator, NULL,
1294 _gtk_marshal_BOOLEAN__BOXED,
1296 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1297 widget_signals[NO_EXPOSE_EVENT] =
1298 g_signal_new ("no_expose_event",
1299 G_TYPE_FROM_CLASS (gobject_class),
1301 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
1302 _gtk_boolean_handled_accumulator, NULL,
1303 _gtk_marshal_BOOLEAN__BOXED,
1305 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1306 widget_signals[WINDOW_STATE_EVENT] =
1307 g_signal_new ("window_state_event",
1308 G_TYPE_FROM_CLASS (gobject_class),
1310 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
1311 _gtk_boolean_handled_accumulator, NULL,
1312 _gtk_marshal_BOOLEAN__BOXED,
1314 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1316 * GtkWidget::popup-menu
1317 * @widget: the object which received the signal
1318 * @returns: TRUE if a menu was activated
1320 * This signal gets emitted whenever a widget should pop up a context-sensitive
1321 * menu. This usually happens through the standard key binding mechanism; by
1322 * pressing a certain key while a widget is focused, the user can cause the
1323 * widget to pop up a menu. For example, the #GtkEntry widget creates a menu
1324 * with clipboard commands. See <xref linkend="checklist-popup-menu"/> for an
1325 * example of how to use this signal.
1327 widget_signals[POPUP_MENU] =
1328 g_signal_new ("popup_menu",
1329 G_TYPE_FROM_CLASS (gobject_class),
1330 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1331 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
1332 _gtk_boolean_handled_accumulator, NULL,
1333 _gtk_marshal_BOOLEAN__VOID,
1335 widget_signals[SHOW_HELP] =
1336 g_signal_new ("show_help",
1337 G_TYPE_FROM_CLASS (gobject_class),
1338 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1339 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
1340 _gtk_boolean_handled_accumulator, NULL,
1341 _gtk_marshal_BOOLEAN__ENUM,
1343 GTK_TYPE_WIDGET_HELP_TYPE);
1344 widget_signals[ACCEL_CLOSURES_CHANGED] =
1345 g_signal_new ("accel_closures_changed",
1346 G_TYPE_FROM_CLASS (gobject_class),
1350 _gtk_marshal_NONE__NONE,
1352 widget_signals[SCREEN_CHANGED] =
1353 g_signal_new ("screen_changed",
1354 G_TYPE_FROM_CLASS (gobject_class),
1356 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
1358 _gtk_marshal_VOID__OBJECT,
1362 * GtkWidget::can-activate-accel:
1363 * @widget: the object which received the signal
1364 * @signal_id: the ID of a signal installed on @widget
1365 * @returns: %TRUE if the signal can be activated.
1367 * Determines whether an accelerator that activates the signal
1368 * identified by @signal_id can currently be activated.
1369 * This signal is present to allow applications and derived
1370 * widgets to override the default #GtkWidget handling
1371 * for determining whether an accelerator can be activated.
1373 widget_signals[CAN_ACTIVATE_ACCEL] =
1374 g_signal_new ("can_activate_accel",
1375 G_TYPE_FROM_CLASS (gobject_class),
1377 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
1378 _gtk_boolean_handled_accumulator, NULL,
1379 _gtk_marshal_BOOLEAN__UINT,
1380 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
1382 binding_set = gtk_binding_set_by_class (klass);
1383 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
1385 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
1388 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
1390 GTK_TYPE_WIDGET_HELP_TYPE,
1391 GTK_WIDGET_HELP_TOOLTIP);
1392 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
1394 GTK_TYPE_WIDGET_HELP_TYPE,
1395 GTK_WIDGET_HELP_TOOLTIP);
1396 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
1398 GTK_TYPE_WIDGET_HELP_TYPE,
1399 GTK_WIDGET_HELP_WHATS_THIS);
1400 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
1402 GTK_TYPE_WIDGET_HELP_TYPE,
1403 GTK_WIDGET_HELP_WHATS_THIS);
1405 gtk_widget_class_install_style_property (klass,
1406 g_param_spec_boolean ("interior_focus",
1407 P_("Interior Focus"),
1408 P_("Whether to draw the focus indicator inside widgets"),
1412 gtk_widget_class_install_style_property (klass,
1413 g_param_spec_int ("focus-line-width",
1414 P_("Focus linewidth"),
1415 P_("Width, in pixels, of the focus indicator line"),
1419 gtk_widget_class_install_style_property (klass,
1420 g_param_spec_string ("focus-line-pattern",
1421 P_("Focus line dash pattern"),
1422 P_("Dash pattern used to draw the focus indicator"),
1425 gtk_widget_class_install_style_property (klass,
1426 g_param_spec_int ("focus-padding",
1427 P_("Focus padding"),
1428 P_("Width, in pixels, between focus indicator and the widget 'box'"),
1431 gtk_widget_class_install_style_property (klass,
1432 g_param_spec_boxed ("cursor-color",
1434 P_("Color with which to draw insertion cursor"),
1437 gtk_widget_class_install_style_property (klass,
1438 g_param_spec_boxed ("secondary-cursor-color",
1439 P_("Secondary cursor color"),
1440 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
1443 gtk_widget_class_install_style_property (klass,
1444 g_param_spec_float ("cursor-aspect-ratio",
1445 P_("Cursor line aspect ratio"),
1446 P_("Aspect ratio with which to draw insertion cursor"),
1452 gtk_widget_set_property (GObject *object,
1454 const GValue *value,
1457 GtkWidget *widget = GTK_WIDGET (object);
1461 guint32 saved_flags;
1464 gtk_widget_set_name (widget, g_value_get_string (value));
1467 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
1469 case PROP_WIDTH_REQUEST:
1470 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
1472 case PROP_HEIGHT_REQUEST:
1473 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
1476 if (g_value_get_boolean (value))
1477 gtk_widget_show (widget);
1479 gtk_widget_hide (widget);
1481 case PROP_SENSITIVE:
1482 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
1484 case PROP_APP_PAINTABLE:
1485 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
1487 case PROP_CAN_FOCUS:
1488 saved_flags = GTK_WIDGET_FLAGS (widget);
1489 if (g_value_get_boolean (value))
1490 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
1492 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
1493 if (saved_flags != GTK_WIDGET_FLAGS (widget))
1494 gtk_widget_queue_resize (widget);
1496 case PROP_HAS_FOCUS:
1497 if (g_value_get_boolean (value))
1498 gtk_widget_grab_focus (widget);
1501 if (g_value_get_boolean (value))
1502 gtk_widget_grab_focus (widget);
1504 case PROP_CAN_DEFAULT:
1505 saved_flags = GTK_WIDGET_FLAGS (widget);
1506 if (g_value_get_boolean (value))
1507 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
1509 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT);
1510 if (saved_flags != GTK_WIDGET_FLAGS (widget))
1511 gtk_widget_queue_resize (widget);
1513 case PROP_HAS_DEFAULT:
1514 if (g_value_get_boolean (value))
1515 gtk_widget_grab_default (widget);
1517 case PROP_RECEIVES_DEFAULT:
1518 if (g_value_get_boolean (value))
1519 GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1521 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1524 gtk_widget_set_style (widget, g_value_get_object (value));
1527 if (!GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget))
1528 gtk_widget_set_events (widget, g_value_get_flags (value));
1530 case PROP_EXTENSION_EVENTS:
1531 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
1533 case PROP_NO_SHOW_ALL:
1534 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
1542 gtk_widget_get_property (GObject *object,
1547 GtkWidget *widget = GTK_WIDGET (object);
1552 GdkExtensionMode *modep;
1556 g_value_set_string (value, widget->name);
1558 g_value_set_string (value, "");
1562 g_value_set_object (value, widget->parent);
1564 g_value_set_object (value, NULL);
1566 case PROP_WIDTH_REQUEST:
1569 gtk_widget_get_size_request (widget, &w, NULL);
1570 g_value_set_int (value, w);
1573 case PROP_HEIGHT_REQUEST:
1576 gtk_widget_get_size_request (widget, NULL, &h);
1577 g_value_set_int (value, h);
1581 g_value_set_boolean (value, (GTK_WIDGET_VISIBLE (widget) != FALSE));
1583 case PROP_SENSITIVE:
1584 g_value_set_boolean (value, (GTK_WIDGET_SENSITIVE (widget) != FALSE));
1586 case PROP_APP_PAINTABLE:
1587 g_value_set_boolean (value, (GTK_WIDGET_APP_PAINTABLE (widget) != FALSE));
1589 case PROP_CAN_FOCUS:
1590 g_value_set_boolean (value, (GTK_WIDGET_CAN_FOCUS (widget) != FALSE));
1592 case PROP_HAS_FOCUS:
1593 g_value_set_boolean (value, (GTK_WIDGET_HAS_FOCUS (widget) != FALSE));
1596 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
1598 case PROP_CAN_DEFAULT:
1599 g_value_set_boolean (value, (GTK_WIDGET_CAN_DEFAULT (widget) != FALSE));
1601 case PROP_HAS_DEFAULT:
1602 g_value_set_boolean (value, (GTK_WIDGET_HAS_DEFAULT (widget) != FALSE));
1604 case PROP_RECEIVES_DEFAULT:
1605 g_value_set_boolean (value, (GTK_WIDGET_RECEIVES_DEFAULT (widget) != FALSE));
1607 case PROP_COMPOSITE_CHILD:
1608 g_value_set_boolean (value, (GTK_WIDGET_COMPOSITE_CHILD (widget) != FALSE));
1611 g_value_set_object (value, gtk_widget_get_style (widget));
1614 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
1616 g_value_set_flags (value, 0);
1618 g_value_set_flags (value, *eventp);
1620 case PROP_EXTENSION_EVENTS:
1621 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
1623 g_value_set_enum (value, 0);
1625 g_value_set_enum (value, (GdkExtensionMode) *modep);
1627 case PROP_NO_SHOW_ALL:
1628 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
1631 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1637 gtk_widget_init (GtkWidget *widget)
1639 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
1640 widget->state = GTK_STATE_NORMAL;
1641 widget->saved_state = GTK_STATE_NORMAL;
1642 widget->name = NULL;
1643 widget->requisition.width = 0;
1644 widget->requisition.height = 0;
1645 widget->allocation.x = -1;
1646 widget->allocation.y = -1;
1647 widget->allocation.width = 1;
1648 widget->allocation.height = 1;
1649 widget->window = NULL;
1650 widget->parent = NULL;
1652 GTK_WIDGET_SET_FLAGS (widget,
1654 GTK_PARENT_SENSITIVE |
1655 (composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
1656 GTK_DOUBLE_BUFFERED);
1658 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
1659 GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
1660 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
1662 widget->style = gtk_widget_get_default_style ();
1663 g_object_ref (widget->style);
1668 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
1670 GParamSpec **pspecs)
1672 GtkWidget *container = widget->parent;
1675 for (i = 0; widget->parent == container && i < n_pspecs; i++)
1676 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
1680 * gtk_widget_freeze_child_notify:
1681 * @widget: a #GtkWidget
1683 * Stops emission of "child-notify" signals on @widget. The signals are
1684 * queued until gtk_widget_thaw_child_notify() is called on @widget.
1686 * This is the analogue of g_object_freeze_notify() for child properties.
1689 gtk_widget_freeze_child_notify (GtkWidget *widget)
1691 g_return_if_fail (GTK_IS_WIDGET (widget));
1693 if (!G_OBJECT (widget)->ref_count)
1696 g_object_ref (widget);
1697 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1698 g_object_unref (widget);
1702 * gtk_widget_child_notify:
1703 * @widget: a #GtkWidget
1704 * @child_property: the name of a child property installed on the
1705 * class of @widget<!-- -->'s parent.
1707 * Emits a "child-notify" signal for the
1708 * <link linkend="child-properties">child property</link> @child_property
1711 * This is the analogue of g_object_notify() for child properties.
1714 gtk_widget_child_notify (GtkWidget *widget,
1715 const gchar *child_property)
1719 g_return_if_fail (GTK_IS_WIDGET (widget));
1720 g_return_if_fail (child_property != NULL);
1721 if (!G_OBJECT (widget)->ref_count || !widget->parent)
1724 g_object_ref (widget);
1725 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
1727 G_OBJECT_TYPE (widget->parent),
1730 g_warning ("%s: container class `%s' has no child property named `%s'",
1732 G_OBJECT_TYPE_NAME (widget->parent),
1736 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1738 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
1739 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1741 g_object_unref (widget);
1745 * gtk_widget_thaw_child_notify:
1746 * @widget: a #GtkWidget
1748 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
1749 * This causes all queued "child-notify" signals on @widget to be emitted.
1752 gtk_widget_thaw_child_notify (GtkWidget *widget)
1754 GObjectNotifyQueue *nqueue;
1756 g_return_if_fail (GTK_IS_WIDGET (widget));
1758 if (!G_OBJECT (widget)->ref_count)
1761 g_object_ref (widget);
1762 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1763 if (!nqueue || !nqueue->freeze_count)
1764 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
1765 G_OBJECT_TYPE_NAME (widget), widget);
1767 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1768 g_object_unref (widget);
1774 * @type: type ID of the widget to create
1775 * @first_property_name: name of first property to set
1776 * @Varargs: value of first property, followed by more properties, %NULL-terminated
1778 * This is a convenience function for creating a widget and setting
1779 * its properties in one go. For example you might write:
1780 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
1781 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
1782 * g_object_new(), but returns a widget so you don't have to
1783 * cast the object yourself.
1785 * Return value: a new #GtkWidget of type @widget_type
1788 gtk_widget_new (GType type,
1789 const gchar *first_property_name,
1795 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
1797 va_start (var_args, first_property_name);
1798 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
1806 * @widget: a #GtkWidget
1807 * @first_property_name: name of first property to set
1808 * @Varargs: value of first property, followed by more properties, %NULL-terminated
1810 * Like g_object_set() - there's no reason to use this instead of
1814 gtk_widget_set (GtkWidget *widget,
1815 const gchar *first_property_name,
1820 g_return_if_fail (GTK_IS_WIDGET (widget));
1822 va_start (var_args, first_property_name);
1823 g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
1828 gtk_widget_queue_draw_child (GtkWidget *widget)
1832 parent = widget->parent;
1833 if (parent && GTK_WIDGET_DRAWABLE (parent))
1834 gtk_widget_queue_draw_area (parent,
1835 widget->allocation.x,
1836 widget->allocation.y,
1837 widget->allocation.width,
1838 widget->allocation.height);
1842 * gtk_widget_unparent:
1843 * @widget: a #GtkWidget
1845 * This function is only for use in widget implementations.
1846 * Should be called by implementations of the remove method
1847 * on #GtkContainer, to dissociate a child from the container.
1850 gtk_widget_unparent (GtkWidget *widget)
1852 GObjectNotifyQueue *nqueue;
1853 GtkWidget *toplevel;
1854 GtkWidget *old_parent;
1856 g_return_if_fail (GTK_IS_WIDGET (widget));
1857 if (widget->parent == NULL)
1860 /* keep this function in sync with gtk_menu_detach()
1863 g_object_freeze_notify (G_OBJECT (widget));
1864 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1866 toplevel = gtk_widget_get_toplevel (widget);
1867 if (GTK_WIDGET_TOPLEVEL (toplevel))
1868 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
1870 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
1871 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
1873 /* If we are unanchoring the child, we save around the toplevel
1874 * to emit hierarchy changed
1876 if (GTK_WIDGET_ANCHORED (widget->parent))
1877 g_object_ref (toplevel);
1881 gtk_widget_queue_draw_child (widget);
1883 /* Reset the width and height here, to force reallocation if we
1884 * get added back to a new parent. This won't work if our new
1885 * allocation is smaller than 1x1 and we actually want a size of 1x1...
1886 * (would 0x0 be OK here?)
1888 widget->allocation.width = 1;
1889 widget->allocation.height = 1;
1891 if (GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_IN_REPARENT (widget))
1892 gtk_widget_unrealize (widget);
1894 /* Removing a widget from a container restores the child visible
1895 * flag to the default state, so it doesn't affect the child
1896 * in the next parent.
1898 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
1900 old_parent = widget->parent;
1901 widget->parent = NULL;
1902 gtk_widget_set_parent_window (widget, NULL);
1903 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
1906 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
1907 g_object_unref (toplevel);
1910 g_object_notify (G_OBJECT (widget), "parent");
1911 g_object_thaw_notify (G_OBJECT (widget));
1912 if (!widget->parent)
1913 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
1914 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1915 g_object_unref (widget);
1919 * gtk_widget_destroy:
1920 * @widget: a #GtkWidget
1922 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
1923 * you don't have to cast the widget to #GtkObject. When a widget is
1924 * destroyed, it will break any references it holds to other objects.
1925 * If the widget is inside a container, the widget will be removed
1926 * from the container. If the widget is a toplevel (derived from
1927 * #GtkWindow), it will be removed from the list of toplevels, and the
1928 * reference GTK+ holds to it will be removed. Removing a
1929 * widget from its container or the list of toplevels results in the
1930 * widget being finalized, unless you've added additional references
1931 * to the widget with g_object_ref().
1933 * In most cases, only toplevel widgets (windows) require explicit
1934 * destruction, because when you destroy a toplevel its children will
1935 * be destroyed as well.
1939 gtk_widget_destroy (GtkWidget *widget)
1941 g_return_if_fail (GTK_IS_WIDGET (widget));
1943 gtk_object_destroy ((GtkObject*) widget);
1947 * gtk_widget_destroyed:
1948 * @widget: a #GtkWidget
1949 * @widget_pointer: address of a variable that contains @widget
1951 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
1952 * %NULL. It's intended to be used as a callback connected to the
1953 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
1954 * as a signal handler, and pass the address of your widget variable
1955 * as user data. Then when the widget is destroyed, the variable will
1956 * be set to %NULL. Useful for example to avoid multiple copies
1957 * of the same dialog.
1961 gtk_widget_destroyed (GtkWidget *widget,
1962 GtkWidget **widget_pointer)
1964 /* Don't make any assumptions about the
1966 * Even check widget_pointer.
1969 *widget_pointer = NULL;
1974 * @widget: a #GtkWidget
1976 * Flags a widget to be displayed. Any widget that isn't shown will
1977 * not appear on the screen. If you want to show all the widgets in a
1978 * container, it's easier to call gtk_widget_show_all() on the
1979 * container, instead of individually showing the widgets.
1981 * Remember that you have to show the containers containing a widget,
1982 * in addition to the widget itself, before it will appear onscreen.
1984 * When a toplevel container is shown, it is immediately realized and
1985 * mapped; other shown widgets are realized and mapped when their
1986 * toplevel container is realized and mapped.
1990 gtk_widget_show (GtkWidget *widget)
1992 if (!GTK_WIDGET_VISIBLE (widget))
1994 g_object_ref (widget);
1995 if (!GTK_WIDGET_TOPLEVEL (widget))
1996 gtk_widget_queue_resize (widget);
1997 g_signal_emit (widget, widget_signals[SHOW], 0);
1998 g_object_notify (G_OBJECT (widget), "visible");
1999 g_object_unref (widget);
2004 gtk_widget_real_show (GtkWidget *widget)
2006 if (!GTK_WIDGET_VISIBLE (widget))
2008 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
2010 if (widget->parent &&
2011 GTK_WIDGET_MAPPED (widget->parent) &&
2012 GTK_WIDGET_CHILD_VISIBLE (widget) &&
2013 !GTK_WIDGET_MAPPED (widget))
2014 gtk_widget_map (widget);
2019 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
2022 g_signal_handlers_disconnect_by_func (widget,
2023 gtk_widget_show_map_callback,
2028 * gtk_widget_show_now:
2029 * @widget: a #GtkWidget
2031 * Shows a widget. If the widget is an unmapped toplevel widget
2032 * (i.e. a #GtkWindow that has not yet been shown), enter the main
2033 * loop and wait for the window to actually be mapped. Be careful;
2034 * because the main loop is running, anything can happen during
2038 gtk_widget_show_now (GtkWidget *widget)
2042 g_return_if_fail (GTK_IS_WIDGET (widget));
2044 /* make sure we will get event */
2045 if (!GTK_WIDGET_MAPPED (widget) &&
2046 GTK_WIDGET_TOPLEVEL (widget))
2048 gtk_widget_show (widget);
2050 g_signal_connect (widget, "map_event",
2051 G_CALLBACK (gtk_widget_show_map_callback),
2055 gtk_main_iteration ();
2058 gtk_widget_show (widget);
2063 * @widget: a #GtkWidget
2065 * Reverses the effects of gtk_widget_show(), causing the widget to be
2066 * hidden (invisible to the user).
2069 gtk_widget_hide (GtkWidget *widget)
2071 g_return_if_fail (GTK_IS_WIDGET (widget));
2073 if (GTK_WIDGET_VISIBLE (widget))
2075 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
2077 g_object_ref (widget);
2078 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
2079 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
2081 g_signal_emit (widget, widget_signals[HIDE], 0);
2082 if (!GTK_WIDGET_TOPLEVEL (widget))
2083 gtk_widget_queue_resize (widget);
2084 g_object_notify (G_OBJECT (widget), "visible");
2085 g_object_unref (widget);
2090 gtk_widget_real_hide (GtkWidget *widget)
2092 if (GTK_WIDGET_VISIBLE (widget))
2094 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
2096 if (GTK_WIDGET_MAPPED (widget))
2097 gtk_widget_unmap (widget);
2102 * gtk_widget_hide_on_delete:
2103 * @widget: a #GtkWidget
2105 * Utility function; intended to be connected to the "delete_event"
2106 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
2107 * argument, then returns %TRUE. If connected to "delete_event", the
2108 * result is that clicking the close button for a window (on the
2109 * window frame, top right corner usually) will hide but not destroy
2110 * the window. By default, GTK+ destroys windows when "delete_event"
2113 * Return value: %TRUE
2116 gtk_widget_hide_on_delete (GtkWidget *widget)
2118 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2120 gtk_widget_hide (widget);
2126 * gtk_widget_show_all:
2127 * @widget: a #GtkWidget
2129 * Recursively shows a widget, and any child widgets (if the widget is
2133 gtk_widget_show_all (GtkWidget *widget)
2135 GtkWidgetClass *class;
2137 g_return_if_fail (GTK_IS_WIDGET (widget));
2139 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
2142 class = GTK_WIDGET_GET_CLASS (widget);
2144 if (class->show_all)
2145 class->show_all (widget);
2149 * gtk_widget_hide_all:
2150 * @widget: a #GtkWidget
2152 * Recursively hides a widget and any child widgets.
2155 gtk_widget_hide_all (GtkWidget *widget)
2157 GtkWidgetClass *class;
2159 g_return_if_fail (GTK_IS_WIDGET (widget));
2161 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
2164 class = GTK_WIDGET_GET_CLASS (widget);
2166 if (class->hide_all)
2167 class->hide_all (widget);
2172 * @widget: a #GtkWidget
2174 * This function is only for use in widget implementations. Causes
2175 * a widget to be mapped if it isn't already.
2179 gtk_widget_map (GtkWidget *widget)
2181 g_return_if_fail (GTK_IS_WIDGET (widget));
2182 g_return_if_fail (GTK_WIDGET_VISIBLE (widget));
2183 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
2185 if (!GTK_WIDGET_MAPPED (widget))
2187 if (!GTK_WIDGET_REALIZED (widget))
2188 gtk_widget_realize (widget);
2190 g_signal_emit (widget, widget_signals[MAP], 0);
2192 if (GTK_WIDGET_NO_WINDOW (widget))
2193 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
2199 * @widget: a #GtkWidget
2201 * This function is only for use in widget implementations. Causes
2202 * a widget to be unmapped if it's currently mapped.
2206 gtk_widget_unmap (GtkWidget *widget)
2208 g_return_if_fail (GTK_IS_WIDGET (widget));
2210 if (GTK_WIDGET_MAPPED (widget))
2212 if (GTK_WIDGET_NO_WINDOW (widget))
2213 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
2214 g_signal_emit (widget, widget_signals[UNMAP], 0);
2219 * gtk_widget_realize:
2220 * @widget: a #GtkWidget
2222 * Creates the GDK (windowing system) resources associated with a
2223 * widget. For example, @widget->window will be created when a widget
2224 * is realized. Normally realization happens implicitly; if you show
2225 * a widget and all its parent containers, then the widget will be
2226 * realized and mapped automatically.
2228 * Realizing a widget requires all
2229 * the widget's parent widgets to be realized; calling
2230 * gtk_widget_realize() realizes the widget's parents in addition to
2231 * @widget itself. If a widget is not yet inside a toplevel window
2232 * when you realize it, bad things will happen.
2234 * This function is primarily used in widget implementations, and
2235 * isn't very useful otherwise. Many times when you think you might
2236 * need it, a better approach is to connect to a signal that will be
2237 * called after the widget is realized automatically, such as
2238 * "expose_event". Or simply g_signal_connect_after() to the
2243 gtk_widget_realize (GtkWidget *widget)
2246 GdkExtensionMode mode;
2247 GtkWidgetShapeInfo *shape_info;
2249 g_return_if_fail (GTK_IS_WIDGET (widget));
2250 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
2251 GTK_IS_INVISIBLE (widget));
2253 if (!GTK_WIDGET_REALIZED (widget))
2256 if (GTK_IS_CONTAINER (widget) && !GTK_WIDGET_NO_WINDOW (widget))
2257 g_message ("gtk_widget_realize(%s)", g_type_name (GTK_WIDGET_TYPE (widget)));
2260 if (widget->parent == NULL &&
2261 !GTK_WIDGET_TOPLEVEL (widget))
2262 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
2263 "inside a toplevel window is not going to work very well. "
2264 "Widgets must be inside a toplevel container before realizing them.");
2266 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
2267 gtk_widget_realize (widget->parent);
2269 gtk_widget_ensure_style (widget);
2271 g_signal_emit (widget, widget_signals[REALIZE], 0);
2273 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
2275 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
2276 gdk_window_shape_combine_mask (widget->window,
2277 shape_info->shape_mask,
2278 shape_info->offset_x,
2279 shape_info->offset_y);
2282 if (!GTK_WIDGET_NO_WINDOW (widget))
2284 mode = gtk_widget_get_extension_events (widget);
2285 if (mode != GDK_EXTENSION_EVENTS_NONE)
2287 events = gtk_widget_get_events (widget);
2288 gdk_input_set_extension_events (widget->window, events, mode);
2296 * gtk_widget_unrealize:
2297 * @widget: a #GtkWidget
2299 * This function is only useful in widget implementations.
2300 * Causes a widget to be unrealized (frees all GDK resources
2301 * associated with the widget, such as @widget->window).
2305 gtk_widget_unrealize (GtkWidget *widget)
2307 g_return_if_fail (GTK_IS_WIDGET (widget));
2309 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
2310 gtk_widget_shape_combine_mask (widget, NULL, -1, -1);
2312 if (GTK_WIDGET_REALIZED (widget))
2314 g_object_ref (widget);
2315 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
2316 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
2317 g_object_unref (widget);
2321 /*****************************************
2323 *****************************************/
2326 * gtk_widget_queue_draw_area:
2327 * @widget: a #GtkWidget
2328 * @x: x coordinate of upper-left corner of rectangle to redraw
2329 * @y: y coordinate of upper-left corner of rectangle to redraw
2330 * @width: width of region to draw
2331 * @height: height of region to draw
2333 * Invalidates the rectangular area of @widget defined by @x, @y,
2334 * @width and @height by calling gdk_window_invalidate_rect() on the
2335 * widget's window and all its child windows. Once the main loop
2336 * becomes idle (after the current batch of events has been processed,
2337 * roughly), the window will receive expose events for the union of
2338 * all regions that have been invalidated.
2340 * Normally you would only use this function in widget
2341 * implementations. You might also use it, or
2342 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
2343 * #GtkDrawingArea or some portion thereof.
2345 * Frequently you can just call gdk_window_invalidate_rect() or
2346 * gdk_window_invalidate_region() instead of this function. Those
2347 * functions will invalidate only a single window, instead of the
2348 * widget and all its children.
2350 * The advantage of adding to the invalidated region compared to
2351 * simply drawing immediately is efficiency; using an invalid region
2352 * ensures that you only have to redraw one time.
2356 gtk_widget_queue_draw_area (GtkWidget *widget,
2362 GdkRectangle invalid_rect;
2365 g_return_if_fail (GTK_IS_WIDGET (widget));
2367 if (!GTK_WIDGET_REALIZED (widget))
2370 /* Just return if the widget or one of its ancestors isn't mapped */
2371 for (w = widget; w != NULL; w = w->parent)
2372 if (!GTK_WIDGET_MAPPED (w))
2375 /* Find the correct widget */
2377 if (!GTK_WIDGET_NO_WINDOW (widget))
2381 /* Translate widget relative to window-relative */
2383 gint wx, wy, wwidth, wheight;
2385 gdk_window_get_position (widget->window, &wx, &wy);
2386 x -= wx - widget->allocation.x;
2387 y -= wy - widget->allocation.y;
2389 gdk_drawable_get_size (widget->window, &wwidth, &wheight);
2391 if (x + width <= 0 || y + height <= 0 ||
2392 x >= wwidth || y >= wheight)
2403 if (x + width > wwidth)
2405 if (y + height > wheight)
2406 height = wheight - y;
2412 invalid_rect.width = width;
2413 invalid_rect.height = height;
2415 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
2419 * gtk_widget_queue_draw:
2420 * @widget: a #GtkWidget
2422 * Equivalent to calling gtk_widget_queue_draw_area() for the
2423 * entire area of a widget.
2427 gtk_widget_queue_draw (GtkWidget *widget)
2429 g_return_if_fail (GTK_IS_WIDGET (widget));
2431 if (widget->allocation.width || widget->allocation.height)
2433 if (GTK_WIDGET_NO_WINDOW (widget))
2434 gtk_widget_queue_draw_area (widget, widget->allocation.x,
2435 widget->allocation.y,
2436 widget->allocation.width,
2437 widget->allocation.height);
2439 gtk_widget_queue_draw_area (widget, 0, 0,
2440 widget->allocation.width,
2441 widget->allocation.height);
2445 /* Invalidates the given area (allocation-relative-coordinates)
2446 * in all of the widget's windows
2449 * gtk_widget_queue_clear_area:
2450 * @widget: a #GtkWidget
2451 * @x: x coordinate of upper-left corner of rectangle to redraw
2452 * @y: y coordinate of upper-left corner of rectangle to redraw
2453 * @width: width of region to draw
2454 * @height: height of region to draw
2456 * This function is no longer different from
2457 * gtk_widget_queue_draw_area(), though it once was. Now it just calls
2458 * gtk_widget_queue_draw_area(). Originally
2459 * gtk_widget_queue_clear_area() would force a redraw of the
2460 * background for %GTK_NO_WINDOW widgets, and
2461 * gtk_widget_queue_draw_area() would not. Now both functions ensure
2462 * the background will be redrawn.
2464 * @Deprecated: Use gtk_widget_queue_draw_area() instead.
2467 gtk_widget_queue_clear_area (GtkWidget *widget,
2473 g_return_if_fail (GTK_IS_WIDGET (widget));
2475 gtk_widget_queue_draw_area (widget, x, y, width, height);
2479 * gtk_widget_queue_clear:
2480 * @widget: a #GtkWidget
2482 * This function does the same as gtk_widget_queue_draw().
2484 * @Deprecated: Use gtk_widget_queue_draw() instead.
2487 gtk_widget_queue_clear (GtkWidget *widget)
2489 g_return_if_fail (GTK_IS_WIDGET (widget));
2491 gtk_widget_queue_draw (widget);
2495 * gtk_widget_queue_resize:
2496 * @widget: a #GtkWidget
2498 * This function is only for use in widget implementations.
2499 * Flags a widget to have its size renegotiated; should
2500 * be called when a widget for some reason has a new size request.
2501 * For example, when you change the text in a #GtkLabel, #GtkLabel
2502 * queues a resize to ensure there's enough space for the new text.
2505 gtk_widget_queue_resize (GtkWidget *widget)
2507 g_return_if_fail (GTK_IS_WIDGET (widget));
2509 if (GTK_WIDGET_REALIZED (widget))
2510 gtk_widget_queue_shallow_draw (widget);
2512 _gtk_size_group_queue_resize (widget);
2516 * gtk_widget_queue_resize_no_redraw:
2517 * @widget: a #GtkWidget
2519 * This function works like gtk_widget_queue_resize(), except that the
2520 * widget is not invalidated.
2525 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
2527 g_return_if_fail (GTK_IS_WIDGET (widget));
2529 _gtk_size_group_queue_resize (widget);
2534 * @widget: a #GtkWidget
2535 * @area: area to draw
2537 * In GTK+ 1.2, this function would immediately render the
2538 * region @area of a widget, by invoking the virtual draw method of a
2539 * widget. In GTK+ 2.0, the draw method is gone, and instead
2540 * gtk_widget_draw() simply invalidates the specified region of the
2541 * widget, then updates the invalid region of the widget immediately.
2542 * Usually you don't want to update the region immediately for
2543 * performance reasons, so in general gtk_widget_queue_draw_area() is
2544 * a better choice if you want to draw a region of a widget.
2548 gtk_widget_draw (GtkWidget *widget,
2551 g_return_if_fail (GTK_IS_WIDGET (widget));
2553 if (GTK_WIDGET_DRAWABLE (widget))
2556 gtk_widget_queue_draw_area (widget,
2558 area->width, area->height);
2560 gtk_widget_queue_draw (widget);
2562 gdk_window_process_updates (widget->window, TRUE);
2567 * gtk_widget_size_request:
2568 * @widget: a #GtkWidget
2569 * @requisition: a #GtkRequisition to be filled in
2571 * This function is typically used when implementing a #GtkContainer
2572 * subclass. Obtains the preferred size of a widget. The container
2573 * uses this information to arrange its child widgets and decide what
2574 * size allocations to give them with gtk_widget_size_allocate().
2576 * You can also call this function from an application, with some
2577 * caveats. Most notably, getting a size request requires the widget
2578 * to be associated with a screen, because font information may be
2579 * needed. Multihead-aware applications should keep this in mind.
2581 * Also remember that the size request is not necessarily the size
2582 * a widget will actually be allocated.
2584 * See also gtk_widget_get_child_requisition().
2587 gtk_widget_size_request (GtkWidget *widget,
2588 GtkRequisition *requisition)
2590 g_return_if_fail (GTK_IS_WIDGET (widget));
2592 #ifdef G_ENABLE_DEBUG
2593 if (requisition == &widget->requisition)
2594 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.");
2595 #endif /* G_ENABLE_DEBUG */
2597 _gtk_size_group_compute_requisition (widget, requisition);
2601 * gtk_widget_get_child_requisition:
2602 * @widget: a #GtkWidget
2603 * @requisition: a #GtkRequisition to be filled in
2605 * This function is only for use in widget implementations. Obtains
2606 * @widget->requisition, unless someone has forced a particular
2607 * geometry on the widget (e.g. with gtk_widget_set_usize()), in which
2608 * case it returns that geometry instead of the widget's requisition.
2610 * This function differs from gtk_widget_size_request() in that
2611 * it retrieves the last size request value from @widget->requisition,
2612 * while gtk_widget_size_request() actually calls the "size_request" method
2613 * on @widget to compute the size request and fill in @widget->requisition,
2614 * and only then returns @widget->requisition.
2616 * Because this function does not call the "size_request" method, it
2617 * can only be used when you know that @widget->requisition is
2618 * up-to-date, that is, gtk_widget_size_request() has been called
2619 * since the last time a resize was queued. In general, only container
2620 * implementations have this information; applications should use
2621 * gtk_widget_size_request().
2624 gtk_widget_get_child_requisition (GtkWidget *widget,
2625 GtkRequisition *requisition)
2627 _gtk_size_group_get_child_requisition (widget, requisition);
2631 invalidate_predicate (GdkWindow *window,
2636 gdk_window_get_user_data (window, &user_data);
2638 return (user_data == data);
2641 /* Invalidate @region in widget->window and all children
2642 * of widget->window owned by widget. @region is in the
2643 * same coordinates as widget->allocation and will be
2644 * modified by this call.
2647 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
2650 if (!GTK_WIDGET_REALIZED (widget))
2653 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
2657 gdk_window_get_position (widget->window, &x, &y);
2658 gdk_region_offset (region, -x, -y);
2661 gdk_window_invalidate_maybe_recurse (widget->window, region,
2662 invalidate_predicate, widget);
2666 * gtk_widget_queue_shallow_draw:
2667 * @widget: a #GtkWidget
2669 * Like gtk_widget_queue_draw(), but only windows owned
2670 * by @widget are invalidated.
2673 gtk_widget_queue_shallow_draw (GtkWidget *widget)
2677 g_return_if_fail (GTK_IS_WIDGET (widget));
2679 region = gdk_region_rectangle (&widget->allocation);
2680 gtk_widget_invalidate_widget_windows (widget, region);
2681 gdk_region_destroy (region);
2685 * gtk_widget_size_allocate:
2686 * @widget: a #GtkWidget
2687 * @allocation: position and size to be allocated to @widget
2689 * This function is only used by #GtkContainer subclasses, to assign a size
2690 * and position to their child widgets.
2694 gtk_widget_size_allocate (GtkWidget *widget,
2695 GtkAllocation *allocation)
2697 GtkWidgetAuxInfo *aux_info;
2698 GdkRectangle real_allocation;
2699 GdkRectangle old_allocation;
2700 gboolean alloc_needed;
2701 gboolean size_changed;
2702 gboolean position_changed;
2704 g_return_if_fail (GTK_IS_WIDGET (widget));
2706 #ifdef G_ENABLE_DEBUG
2707 if (gtk_debug_flags & GTK_DEBUG_GEOMETRY)
2718 parent = gtk_widget_get_parent (parent);
2721 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
2722 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
2723 2 * depth, " ", name,
2724 allocation->width, allocation->height);
2726 #endif /* G_ENABLE_DEBUG */
2728 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
2729 if (!GTK_WIDGET_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
2730 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
2732 old_allocation = widget->allocation;
2733 real_allocation = *allocation;
2734 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
2738 if (aux_info->x_set)
2739 real_allocation.x = aux_info->x;
2740 if (aux_info->y_set)
2741 real_allocation.y = aux_info->y;
2744 if (real_allocation.width < 0 || real_allocation.height < 0)
2746 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
2747 real_allocation.width,
2748 real_allocation.height);
2751 real_allocation.width = MAX (real_allocation.width, 1);
2752 real_allocation.height = MAX (real_allocation.height, 1);
2754 size_changed = (old_allocation.width != real_allocation.width ||
2755 old_allocation.height != real_allocation.height);
2756 position_changed = (old_allocation.x != real_allocation.x ||
2757 old_allocation.y != real_allocation.y);
2759 if (!alloc_needed && !size_changed && !position_changed)
2762 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
2764 if (GTK_WIDGET_MAPPED (widget))
2766 if (GTK_WIDGET_NO_WINDOW (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
2768 /* Invalidate union(old_allaction,widget->allocation) in widget->window
2770 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
2771 gdk_region_union_with_rect (invalidate, &old_allocation);
2773 gdk_window_invalidate_region (widget->window, invalidate, FALSE);
2774 gdk_region_destroy (invalidate);
2779 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
2781 /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
2783 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
2784 gdk_region_union_with_rect (invalidate, &old_allocation);
2786 gtk_widget_invalidate_widget_windows (widget, invalidate);
2787 gdk_region_destroy (invalidate);
2792 if ((size_changed || position_changed) && widget->parent &&
2793 GTK_WIDGET_REALIZED (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
2795 GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
2796 gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
2797 gdk_region_destroy (invalidate);
2802 * gtk_widget_common_ancestor:
2803 * @widget_a: a #GtkWidget
2804 * @widget_b: a #GtkWidget
2806 * Find the common ancestor of @widget_a and @widget_b that
2807 * is closest to the two widgets.
2809 * Return value: the closest common ancestor of @widget_a and
2810 * @widget_b or %NULL if @widget_a and @widget_b do not
2811 * share a common ancestor.
2814 gtk_widget_common_ancestor (GtkWidget *widget_a,
2815 GtkWidget *widget_b)
2817 GtkWidget *parent_a;
2818 GtkWidget *parent_b;
2822 parent_a = widget_a;
2823 while (parent_a->parent)
2825 parent_a = parent_a->parent;
2829 parent_b = widget_b;
2830 while (parent_b->parent)
2832 parent_b = parent_b->parent;
2836 if (parent_a != parent_b)
2839 while (depth_a > depth_b)
2841 widget_a = widget_a->parent;
2845 while (depth_b > depth_a)
2847 widget_b = widget_b->parent;
2851 while (widget_a != widget_b)
2853 widget_a = widget_a->parent;
2854 widget_b = widget_b->parent;
2861 * gtk_widget_translate_coordinates:
2862 * @src_widget: a #GtkWidget
2863 * @dest_widget: a #GtkWidget
2864 * @src_x: X position relative to @src_widget
2865 * @src_y: Y position relative to @src_widget
2866 * @dest_x: location to store X position relative to @dest_widget
2867 * @dest_y: location to store Y position relative to @dest_widget
2869 * Translate coordinates relative to @src_widget's allocation to coordinates
2870 * relative to @dest_widget's allocations. In order to perform this
2871 * operation, both widgets must be realized, and must share a common
2874 * Return value: %FALSE if either widget was not realized, or there
2875 * was no common ancestor. In this case, nothing is stored in
2876 * *@dest_x and *@dest_y. Otherwise %TRUE.
2879 gtk_widget_translate_coordinates (GtkWidget *src_widget,
2880 GtkWidget *dest_widget,
2886 GtkWidget *ancestor;
2889 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
2890 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
2892 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
2893 if (!ancestor || !GTK_WIDGET_REALIZED (src_widget) || !GTK_WIDGET_REALIZED (dest_widget))
2896 /* Translate from allocation relative to window relative */
2897 if (!GTK_WIDGET_NO_WINDOW (src_widget) && src_widget->parent)
2900 gdk_window_get_position (src_widget->window, &wx, &wy);
2902 src_x -= wx - src_widget->allocation.x;
2903 src_y -= wy - src_widget->allocation.y;
2907 src_x += src_widget->allocation.x;
2908 src_y += src_widget->allocation.y;
2911 /* Translate to the common ancestor */
2912 window = src_widget->window;
2913 while (window != ancestor->window)
2917 gdk_window_get_position (window, &dx, &dy);
2922 window = gdk_window_get_parent (window);
2924 if (!window) /* Handle GtkHandleBox */
2929 window = dest_widget->window;
2930 while (window != ancestor->window)
2934 gdk_window_get_position (window, &dx, &dy);
2939 window = gdk_window_get_parent (window);
2941 if (!window) /* Handle GtkHandleBox */
2945 /* Translate from window relative to allocation relative */
2946 if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent)
2949 gdk_window_get_position (dest_widget->window, &wx, &wy);
2951 src_x += wx - dest_widget->allocation.x;
2952 src_y += wy - dest_widget->allocation.y;
2956 src_x -= dest_widget->allocation.x;
2957 src_y -= dest_widget->allocation.y;
2969 gtk_widget_real_size_allocate (GtkWidget *widget,
2970 GtkAllocation *allocation)
2972 widget->allocation = *allocation;
2974 if (GTK_WIDGET_REALIZED (widget) &&
2975 !GTK_WIDGET_NO_WINDOW (widget))
2977 gdk_window_move_resize (widget->window,
2978 allocation->x, allocation->y,
2979 allocation->width, allocation->height);
2984 gtk_widget_real_can_activate_accel (GtkWidget *widget,
2987 /* widgets must be onscreen for accels to take effect */
2988 return GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_DRAWABLE (widget) && gdk_window_is_viewable (widget->window);
2992 * gtk_widget_can_activate_accel:
2993 * @widget: a #GtkWidget
2994 * @signal_id: the ID of a signal installed on @widget
2996 * Determines whether an accelerator that activates the signal
2997 * identified by @signal_id can currently be activated.
2998 * This is done by emitting the GtkWidget::can-activate-accel
2999 * signal on @widget; if the signal isn't overridden by a
3000 * handler or in a derived widget, then the default check is
3001 * that the widget must be sensitive, and the widget and all
3002 * its ancestors mapped.
3004 * Return value: %TRUE if the accelerator can be activated.
3009 gtk_widget_can_activate_accel (GtkWidget *widget,
3012 gboolean can_activate = FALSE;
3013 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3014 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
3015 return can_activate;
3024 closure_accel_activate (GClosure *closure,
3025 GValue *return_value,
3026 guint n_param_values,
3027 const GValue *param_values,
3028 gpointer invocation_hint,
3029 gpointer marshal_data)
3031 AccelClosure *aclosure = (AccelClosure*) closure;
3032 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
3035 g_signal_emit (closure->data, aclosure->signal_id, 0);
3037 /* whether accelerator was handled */
3038 g_value_set_boolean (return_value, can_activate);
3042 closures_destroy (gpointer data)
3044 GSList *slist, *closures = data;
3046 for (slist = closures; slist; slist = slist->next)
3048 g_closure_invalidate (slist->data);
3049 g_closure_unref (slist->data);
3051 g_slist_free (closures);
3055 widget_new_accel_closure (GtkWidget *widget,
3058 AccelClosure *aclosure;
3059 GClosure *closure = NULL;
3060 GSList *slist, *closures;
3062 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
3063 for (slist = closures; slist; slist = slist->next)
3064 if (!gtk_accel_group_from_accel_closure (slist->data))
3066 /* reuse this closure */
3067 closure = slist->data;
3072 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
3073 closures = g_slist_prepend (closures, g_closure_ref (closure));
3074 g_closure_sink (closure);
3075 g_closure_set_marshal (closure, closure_accel_activate);
3077 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
3079 aclosure = (AccelClosure*) closure;
3080 g_assert (closure->data == widget);
3081 g_assert (closure->marshal == closure_accel_activate);
3082 aclosure->signal_id = signal_id;
3088 * gtk_widget_add_accelerator
3089 * @widget: widget to install an accelerator on
3090 * @accel_signal: widget signal to emit on accelerator activation
3091 * @accel_group: accel group for this widget, added to its toplevel
3092 * @accel_key: GDK keyval of the accelerator
3093 * @accel_mods: modifier key combination of the accelerator
3094 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
3096 * Installs an accelerator for this @widget in @accel_group that causes
3097 * @accel_signal to be emitted if the accelerator is activated.
3098 * The @accel_group needs to be added to the widget's toplevel via
3099 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
3100 * Accelerators added through this function are not user changeable during
3101 * runtime. If you want to support accelerators that can be changed by the
3102 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
3103 * gtk_menu_item_set_accel_path() instead.
3106 gtk_widget_add_accelerator (GtkWidget *widget,
3107 const gchar *accel_signal,
3108 GtkAccelGroup *accel_group,
3110 GdkModifierType accel_mods,
3111 GtkAccelFlags accel_flags)
3116 g_return_if_fail (GTK_IS_WIDGET (widget));
3117 g_return_if_fail (accel_signal != NULL);
3118 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
3120 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
3121 if (!query.signal_id ||
3122 !(query.signal_flags & G_SIGNAL_ACTION) ||
3123 query.return_type != G_TYPE_NONE ||
3126 /* hmm, should be elaborate enough */
3127 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
3128 G_OBJECT_TYPE_NAME (widget), accel_signal);
3132 closure = widget_new_accel_closure (widget, query.signal_id);
3134 g_object_ref (widget);
3136 /* install the accelerator. since we don't map this onto an accel_path,
3137 * the accelerator will automatically be locked.
3139 gtk_accel_group_connect (accel_group,
3142 accel_flags | GTK_ACCEL_LOCKED,
3145 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3147 g_object_unref (widget);
3151 * gtk_widget_remove_accelerator:
3152 * @widget: widget to install an accelerator on
3153 * @accel_group: accel group for this widget
3154 * @accel_key: GDK keyval of the accelerator
3155 * @accel_mods: modifier key combination of the accelerator
3156 * @returns: whether an accelerator was installed and could be removed
3158 * Removes an accelerator from @widget, previously installed with
3159 * gtk_widget_add_accelerator().
3162 gtk_widget_remove_accelerator (GtkWidget *widget,
3163 GtkAccelGroup *accel_group,
3165 GdkModifierType accel_mods)
3167 GtkAccelGroupEntry *ag_entry;
3168 GList *slist, *clist;
3171 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3172 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
3174 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
3175 clist = gtk_widget_list_accel_closures (widget);
3176 for (slist = clist; slist; slist = slist->next)
3180 for (i = 0; i < n; i++)
3181 if (slist->data == (gpointer) ag_entry[i].closure)
3183 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
3185 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3187 g_list_free (clist);
3192 g_list_free (clist);
3194 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
3195 accel_key, accel_mods, accel_group,
3196 G_OBJECT_TYPE_NAME (widget), widget);
3202 * gtk_widget_list_accel_closures
3203 * @widget: widget to list accelerator closures for
3204 * @returns: a newly allocated #GList of closures
3206 * Lists the closures used by @widget for accelerator group connections
3207 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
3208 * The closures can be used to monitor accelerator changes on @widget,
3209 * by connecting to the ::accel_changed signal of the #GtkAccelGroup of a
3210 * closure which can be found out with gtk_accel_group_from_accel_closure().
3213 gtk_widget_list_accel_closures (GtkWidget *widget)
3216 GList *clist = NULL;
3218 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3220 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
3221 if (gtk_accel_group_from_accel_closure (slist->data))
3222 clist = g_list_prepend (clist, slist->data);
3229 GtkAccelGroup *accel_group;
3234 destroy_accel_path (gpointer data)
3236 AccelPath *apath = data;
3238 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
3240 /* closures_destroy takes care of unrefing the closure */
3241 g_object_unref (apath->accel_group);
3248 * gtk_widget_set_accel_path:
3249 * @widget: a #GtkWidget
3250 * @accel_path: path used to look up the the accelerator
3251 * @accel_group: a #GtkAccelGroup.
3253 * Given an accelerator group, @accel_group, and an accelerator path,
3254 * @accel_path, sets up an accelerator in @accel_group so whenever the
3255 * key binding that is defined for @accel_path is pressed, @widget
3256 * will be activated. This removes any accelerators (for any
3257 * accelerator group) installed by previous calls to
3258 * gtk_widget_set_accel_path(). Associating accelerators with
3259 * paths allows them to be modified by the user and the modifications
3260 * to be saved for future use. (See gtk_accel_map_save().)
3262 * This function is a low level function that would most likely
3263 * be used by a menu creation system like #GtkItemFactory. If you
3264 * use #GtkItemFactory, setting up accelerator paths will be done
3267 * Even when you you aren't using #GtkItemFactory, if you only want to
3268 * set up accelerators on menu items gtk_menu_item_set_accel_path()
3269 * provides a somewhat more convenient interface.
3272 gtk_widget_set_accel_path (GtkWidget *widget,
3273 const gchar *accel_path,
3274 GtkAccelGroup *accel_group)
3278 g_return_if_fail (GTK_IS_WIDGET (widget));
3279 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
3283 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
3284 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
3286 gtk_accel_map_add_entry (accel_path, 0, 0);
3287 apath = g_new (AccelPath, 1);
3288 apath->widget = widget;
3289 apath->accel_group = g_object_ref (accel_group);
3290 apath->path_quark = g_quark_from_string (accel_path);
3291 apath->closure = widget_new_accel_closure (apath->widget, GTK_WIDGET_GET_CLASS (apath->widget)->activate_signal);
3296 /* also removes possible old settings */
3297 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
3300 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
3302 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3306 _gtk_widget_get_accel_path (GtkWidget *widget,
3311 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3313 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
3315 *locked = apath ? apath->accel_group->lock_count > 0 : TRUE;
3316 return apath ? g_quark_to_string (apath->path_quark) : NULL;
3320 gtk_widget_mnemonic_activate (GtkWidget *widget,
3321 gboolean group_cycling)
3325 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3327 group_cycling = group_cycling != FALSE;
3328 if (!GTK_WIDGET_IS_SENSITIVE (widget))
3331 g_signal_emit (widget,
3332 widget_signals[MNEMONIC_ACTIVATE],
3340 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
3341 gboolean group_cycling)
3343 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
3344 gtk_widget_activate (widget);
3345 else if (GTK_WIDGET_CAN_FOCUS (widget))
3346 gtk_widget_grab_focus (widget);
3349 g_warning ("widget `%s' isn't suitable for mnemonic activation",
3350 G_OBJECT_TYPE_NAME (widget));
3351 gdk_display_beep (gtk_widget_get_display (widget));
3357 gtk_widget_real_key_press_event (GtkWidget *widget,
3360 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
3364 gtk_widget_real_key_release_event (GtkWidget *widget,
3367 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
3371 gtk_widget_real_focus_in_event (GtkWidget *widget,
3372 GdkEventFocus *event)
3374 gtk_widget_queue_shallow_draw (widget);
3380 gtk_widget_real_focus_out_event (GtkWidget *widget,
3381 GdkEventFocus *event)
3383 gtk_widget_queue_shallow_draw (widget);
3388 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
3389 (event->type == GDK_FOCUS_CHANGE || GTK_WIDGET_REALIZED(widget))
3393 * @widget: a #GtkWidget
3394 * @event: a #GdkEvent
3396 * Rarely-used function. This function is used to emit
3397 * the event signals on a widget (those signals should never
3398 * be emitted without using this function to do so).
3399 * If you want to synthesize an event though, don't use this function;
3400 * instead, use gtk_main_do_event() so the event will behave as if
3401 * it were in the event queue. Don't synthesize expose events; instead,
3402 * use gdk_window_invalidate_rect() to invalidate a region of the
3405 * Return value: return from the event signal emission (%TRUE if the event was handled)
3408 gtk_widget_event (GtkWidget *widget,
3411 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
3412 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
3414 if (event->type == GDK_EXPOSE)
3416 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
3417 "the same effect, call gdk_window_invalidate_rect/region(), "
3418 "followed by gdk_window_process_updates().");
3422 return gtk_widget_event_internal (widget, event);
3427 * gtk_widget_send_expose:
3428 * @widget: a #GtkWidget
3429 * @event: a expose #GdkEvent
3431 * Very rarely-used function. This function is used to emit
3432 * an expose event signals on a widget. This function is not
3433 * normally used directly. The only time it is used is when
3434 * propagating an expose event to a child %NO_WINDOW widget, and
3435 * that is normally done using gtk_container_propagate_expose().
3437 * If you want to force an area of a window to be redrawn,
3438 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
3439 * To cause the redraw to be done immediately, follow that call
3440 * with a call to gdk_window_process_updates().
3442 * Return value: return from the event signal emission (%TRUE if the event was handled)
3445 gtk_widget_send_expose (GtkWidget *widget,
3448 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
3449 g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), TRUE);
3450 g_return_val_if_fail (event != NULL, TRUE);
3451 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
3453 if (event->type != GDK_EXPOSE)
3456 return gtk_widget_event_internal (widget, event);
3460 event_window_is_still_viewable (GdkEvent *event)
3462 /* Some programs, such as gnome-theme-manager, fake widgets
3463 * into exposing onto a pixmap by sending expose events with
3464 * event->window pointing to a pixmap
3466 if (GDK_IS_PIXMAP (event->any.window))
3467 return event->type == GDK_EXPOSE;
3469 /* Check that we think the event's window is viewable before
3470 * delivering the event, to prevent suprises. We do this here
3471 * at the last moment, since the event may have been queued
3472 * up behind other events, held over a recursive main loop, etc.
3474 switch (event->type)
3477 case GDK_MOTION_NOTIFY:
3478 case GDK_BUTTON_PRESS:
3479 case GDK_2BUTTON_PRESS:
3480 case GDK_3BUTTON_PRESS:
3482 case GDK_ENTER_NOTIFY:
3483 case GDK_PROXIMITY_IN:
3485 return event->any.window && gdk_window_is_viewable (event->any.window);
3488 /* The following events are the second half of paired events;
3489 * we always deliver them to deal with widgets that clean up
3490 * on the second half.
3492 case GDK_BUTTON_RELEASE:
3493 case GDK_KEY_RELEASE:
3494 case GDK_LEAVE_NOTIFY:
3495 case GDK_PROXIMITY_OUT:
3499 /* Remaining events would make sense on an not-viewable window,
3500 * or don't have an associated window.
3507 gtk_widget_event_internal (GtkWidget *widget,
3510 gboolean return_val = FALSE;
3512 /* We check only once for is-still-visible; if someone
3513 * hides the window in on of the signals on the widget,
3514 * they are responsible for returning TRUE to terminate
3517 if (!event_window_is_still_viewable (event))
3520 g_object_ref (widget);
3522 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
3523 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
3528 switch (event->type)
3533 case GDK_BUTTON_PRESS:
3534 case GDK_2BUTTON_PRESS:
3535 case GDK_3BUTTON_PRESS:
3536 signal_num = BUTTON_PRESS_EVENT;
3539 signal_num = SCROLL_EVENT;
3541 case GDK_BUTTON_RELEASE:
3542 signal_num = BUTTON_RELEASE_EVENT;
3544 case GDK_MOTION_NOTIFY:
3545 signal_num = MOTION_NOTIFY_EVENT;
3548 signal_num = DELETE_EVENT;
3551 signal_num = DESTROY_EVENT;
3554 signal_num = KEY_PRESS_EVENT;
3556 case GDK_KEY_RELEASE:
3557 signal_num = KEY_RELEASE_EVENT;
3559 case GDK_ENTER_NOTIFY:
3560 signal_num = ENTER_NOTIFY_EVENT;
3562 case GDK_LEAVE_NOTIFY:
3563 signal_num = LEAVE_NOTIFY_EVENT;
3565 case GDK_FOCUS_CHANGE:
3566 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
3569 signal_num = CONFIGURE_EVENT;
3572 signal_num = MAP_EVENT;
3575 signal_num = UNMAP_EVENT;
3577 case GDK_WINDOW_STATE:
3578 signal_num = WINDOW_STATE_EVENT;
3580 case GDK_PROPERTY_NOTIFY:
3581 signal_num = PROPERTY_NOTIFY_EVENT;
3583 case GDK_SELECTION_CLEAR:
3584 signal_num = SELECTION_CLEAR_EVENT;
3586 case GDK_SELECTION_REQUEST:
3587 signal_num = SELECTION_REQUEST_EVENT;
3589 case GDK_SELECTION_NOTIFY:
3590 signal_num = SELECTION_NOTIFY_EVENT;
3592 case GDK_PROXIMITY_IN:
3593 signal_num = PROXIMITY_IN_EVENT;
3595 case GDK_PROXIMITY_OUT:
3596 signal_num = PROXIMITY_OUT_EVENT;
3599 signal_num = NO_EXPOSE_EVENT;
3601 case GDK_CLIENT_EVENT:
3602 signal_num = CLIENT_EVENT;
3605 signal_num = EXPOSE_EVENT;
3607 case GDK_VISIBILITY_NOTIFY:
3608 signal_num = VISIBILITY_NOTIFY_EVENT;
3611 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
3615 if (signal_num != -1)
3616 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
3618 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
3619 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
3623 g_object_unref (widget);
3629 * gtk_widget_activate:
3630 * @widget: a #GtkWidget that's activatable
3632 * For widgets that can be "activated" (buttons, menu items, etc.)
3633 * this function activates them. Activation is what happens when you
3634 * press Enter on a widget during key navigation. If @widget isn't
3635 * activatable, the function returns %FALSE.
3637 * Return value: %TRUE if the widget was activatable
3640 gtk_widget_activate (GtkWidget *widget)
3642 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3644 if (WIDGET_CLASS (widget)->activate_signal)
3646 /* FIXME: we should eventually check the signals signature here */
3647 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
3656 * gtk_widget_set_scroll_adjustments:
3657 * @widget: a #GtkWidget
3658 * @hadjustment: an adjustment for horizontal scrolling, or %NULL
3659 * @vadjustment: an adjustment for vertical scrolling, or %NULL
3661 * For widgets that support scrolling, sets the scroll adjustments and
3662 * returns %TRUE. For widgets that don't support scrolling, does
3663 * nothing and returns %FALSE. Widgets that don't support scrolling
3664 * can be scrolled by placing them in a #GtkViewport, which does
3665 * support scrolling.
3667 * Return value: %TRUE if the widget supports scrolling
3670 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
3671 GtkAdjustment *hadjustment,
3672 GtkAdjustment *vadjustment)
3674 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3676 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
3678 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
3680 if (WIDGET_CLASS (widget)->set_scroll_adjustments_signal)
3682 /* FIXME: we should eventually check the signals signature here */
3683 g_signal_emit (widget,
3684 WIDGET_CLASS (widget)->set_scroll_adjustments_signal, 0,
3685 hadjustment, vadjustment);
3693 gtk_widget_reparent_subwindows (GtkWidget *widget,
3694 GdkWindow *new_window)
3696 if (GTK_WIDGET_NO_WINDOW (widget))
3698 GList *children = gdk_window_get_children (widget->window);
3701 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
3704 GdkWindow *window = tmp_list->data;
3706 gdk_window_get_user_data (window, (void **)&child);
3707 while (child && child != widget)
3708 child = child->parent;
3711 gdk_window_reparent (window, new_window, 0, 0);
3714 g_list_free (children);
3717 gdk_window_reparent (widget->window, new_window, 0, 0);
3721 gtk_widget_reparent_fixup_child (GtkWidget *widget,
3722 gpointer client_data)
3724 g_return_if_fail (client_data != NULL);
3726 if (GTK_WIDGET_NO_WINDOW (widget))
3729 g_object_unref (widget->window);
3730 widget->window = (GdkWindow*) client_data;
3732 g_object_ref (widget->window);
3734 if (GTK_IS_CONTAINER (widget))
3735 gtk_container_forall (GTK_CONTAINER (widget),
3736 gtk_widget_reparent_fixup_child,
3742 * gtk_widget_reparent:
3743 * @widget: a #GtkWidget
3744 * @new_parent: a #GtkContainer to move the widget into
3746 * Moves a widget from one #GtkContainer to another, handling reference
3747 * count issues to avoid destroying the widget.
3751 gtk_widget_reparent (GtkWidget *widget,
3752 GtkWidget *new_parent)
3754 g_return_if_fail (GTK_IS_WIDGET (widget));
3755 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
3756 g_return_if_fail (widget->parent != NULL);
3758 if (widget->parent != new_parent)
3760 /* First try to see if we can get away without unrealizing
3761 * the widget as we reparent it. if so we set a flag so
3762 * that gtk_widget_unparent doesn't unrealize widget
3764 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent))
3765 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
3767 g_object_ref (widget);
3768 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
3769 gtk_container_add (GTK_CONTAINER (new_parent), widget);
3770 g_object_unref (widget);
3772 if (GTK_WIDGET_IN_REPARENT (widget))
3774 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
3776 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
3777 gtk_widget_reparent_fixup_child (widget,
3778 gtk_widget_get_parent_window (widget));
3781 g_object_notify (G_OBJECT (widget), "parent");
3786 * gtk_widget_intersect:
3787 * @widget: a #GtkWidget
3788 * @area: a rectangle
3789 * @intersection: rectangle to store intersection of @widget and @area
3791 * Computes the intersection of a @widget's area and @area, storing
3792 * the intersection in @intersection, and returns %TRUE if there was
3793 * an intersection. @intersection may be %NULL if you're only
3794 * interested in whether there was an intersection.
3796 * Return value: %TRUE if there was an intersection
3799 gtk_widget_intersect (GtkWidget *widget,
3801 GdkRectangle *intersection)
3807 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3808 g_return_val_if_fail (area != NULL, FALSE);
3811 dest = intersection;
3815 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
3817 if (return_val && intersection && !GTK_WIDGET_NO_WINDOW (widget))
3819 intersection->x -= widget->allocation.x;
3820 intersection->y -= widget->allocation.y;
3827 * gtk_widget_region_intersect:
3828 * @widget: a #GtkWidget
3829 * @region: a #GdkRegion, in the same coordinate system as
3830 * @widget->allocation. That is, relative to @widget->window
3831 * for %NO_WINDOW widgets; relative to the parent window
3832 * of @widget->window for widgets with their own window.
3833 * @returns: A newly allocated region holding the intersection of @widget
3834 * and @region. The coordinates of the return value are
3835 * relative to @widget->window for %NO_WINDOW widgets, and
3836 * relative to the parent window of @widget->window for
3837 * widgets with their own window.
3839 * Computes the intersection of a @widget's area and @region, returning
3840 * the intersection. The result may be empty, use gdk_region_empty() to
3844 gtk_widget_region_intersect (GtkWidget *widget,
3849 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3850 g_return_val_if_fail (region != NULL, NULL);
3852 dest = gdk_region_rectangle (&widget->allocation);
3854 gdk_region_intersect (dest, region);
3860 * _gtk_widget_grab_notify:
3861 * @widget: a #GtkWidget
3862 * @was_grabbed: whether a grab is now in effect
3864 * Emits the signal "grab_notify" on @widget.
3869 _gtk_widget_grab_notify (GtkWidget *widget,
3870 gboolean was_grabbed)
3872 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
3876 * gtk_widget_grab_focus:
3877 * @widget: a #GtkWidget
3879 * Causes @widget to have the keyboard focus for the #GtkWindow it's
3880 * inside. @widget must be a focusable widget, such as a #GtkEntry;
3881 * something like #GtkFrame won't work. (More precisely, it must have the
3882 * %GTK_CAN_FOCUS flag set.)
3886 gtk_widget_grab_focus (GtkWidget *widget)
3888 g_return_if_fail (GTK_IS_WIDGET (widget));
3890 if (!GTK_WIDGET_IS_SENSITIVE (widget))
3893 g_object_ref (widget);
3894 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
3895 g_object_notify (G_OBJECT (widget), "has_focus");
3896 g_object_unref (widget);
3900 reset_focus_recurse (GtkWidget *widget,
3903 if (GTK_IS_CONTAINER (widget))
3905 GtkContainer *container;
3907 container = GTK_CONTAINER (widget);
3908 gtk_container_set_focus_child (container, NULL);
3910 gtk_container_foreach (container,
3911 reset_focus_recurse,
3917 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
3919 if (GTK_WIDGET_CAN_FOCUS (focus_widget))
3921 GtkWidget *toplevel;
3924 /* clear the current focus setting, break if the current widget
3925 * is the focus widget's parent, since containers above that will
3926 * be set by the next loop.
3928 toplevel = gtk_widget_get_toplevel (focus_widget);
3929 if (GTK_WIDGET_TOPLEVEL (toplevel))
3931 widget = GTK_WINDOW (toplevel)->focus_widget;
3933 if (widget == focus_widget)
3935 /* We call _gtk_window_internal_set_focus() here so that the
3936 * toplevel window can request the focus if necessary.
3937 * This is needed when the toplevel is a GtkPlug
3939 if (!GTK_WIDGET_HAS_FOCUS (widget))
3940 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
3947 while (widget->parent && widget->parent != focus_widget->parent)
3949 widget = widget->parent;
3950 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
3954 else if (toplevel != focus_widget)
3956 /* gtk_widget_grab_focus() operates on a tree without window...
3957 * actually, this is very questionable behaviour.
3960 gtk_container_foreach (GTK_CONTAINER (toplevel),
3961 reset_focus_recurse,
3965 /* now propagate the new focus up the widget tree and finally
3966 * set it on the window
3968 widget = focus_widget;
3969 while (widget->parent)
3971 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
3972 widget = widget->parent;
3974 if (GTK_IS_WINDOW (widget))
3975 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
3980 gtk_widget_real_show_help (GtkWidget *widget,
3981 GtkWidgetHelpType help_type)
3983 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
3985 _gtk_tooltips_toggle_keyboard_mode (widget);
3993 gtk_widget_real_focus (GtkWidget *widget,
3994 GtkDirectionType direction)
3996 if (!GTK_WIDGET_CAN_FOCUS (widget))
3999 if (!gtk_widget_is_focus (widget))
4001 gtk_widget_grab_focus (widget);
4009 * gtk_widget_is_focus:
4010 * @widget: a #GtkWidget
4012 * Determines if the widget is the focus widget within its
4013 * toplevel. (This does not mean that the %HAS_FOCUS flag is
4014 * necessarily set; %HAS_FOCUS will only be set if the
4015 * toplevel widget additionally has the global input focus.)
4017 * Return value: %TRUE if the widget is the focus widget.
4020 gtk_widget_is_focus (GtkWidget *widget)
4022 GtkWidget *toplevel;
4024 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4026 toplevel = gtk_widget_get_toplevel (widget);
4028 if (GTK_IS_WINDOW (toplevel))
4029 return widget == GTK_WINDOW (toplevel)->focus_widget;
4035 * gtk_widget_grab_default:
4036 * @widget: a #GtkWidget
4038 * Causes @widget to become the default widget. @widget must have the
4039 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
4040 * yourself by calling <literal>GTK_WIDGET_SET_FLAGS (@widget,
4041 * GTK_CAN_DEFAULT)</literal>. The default widget is activated when the user
4042 * presses Enter in a window. Default widgets must be activatable,
4043 * that is, gtk_widget_activate() should affect them.
4047 gtk_widget_grab_default (GtkWidget *widget)
4051 g_return_if_fail (GTK_IS_WIDGET (widget));
4052 g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget));
4054 window = gtk_widget_get_toplevel (widget);
4056 if (window && GTK_WIDGET_TOPLEVEL (window))
4057 gtk_window_set_default (GTK_WINDOW (window), widget);
4059 g_warning (G_STRLOC ": widget not within a GtkWindow");
4063 * gtk_widget_set_name:
4064 * @widget: a #GtkWidget
4065 * @name: name for the widget
4067 * Widgets can be named, which allows you to refer to them from a
4068 * gtkrc file. You can apply a style to widgets with a particular name
4069 * in the gtkrc file. See the documentation for gtkrc files (on the
4070 * same page as the docs for #GtkRcStyle).
4072 * Note that widget names are separated by periods in paths (see
4073 * gtk_widget_path()), so names with embedded periods may cause confusion.
4076 gtk_widget_set_name (GtkWidget *widget,
4081 g_return_if_fail (GTK_IS_WIDGET (widget));
4083 new_name = g_strdup (name);
4084 g_free (widget->name);
4085 widget->name = new_name;
4087 if (GTK_WIDGET_RC_STYLE (widget))
4088 gtk_widget_reset_rc_style (widget);
4090 g_object_notify (G_OBJECT (widget), "name");
4094 * gtk_widget_get_name:
4095 * @widget: a #GtkWidget
4097 * Retrieves the name of a widget. See gtk_widget_set_name() for the
4098 * significance of widget names.
4100 * Return value: name of the widget. This string is owned by GTK+ and
4101 * should not be modified or freed
4103 G_CONST_RETURN gchar*
4104 gtk_widget_get_name (GtkWidget *widget)
4106 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4109 return widget->name;
4110 return g_type_name (GTK_WIDGET_TYPE (widget));
4114 * gtk_widget_set_state:
4115 * @widget: a #GtkWidget
4116 * @state: new state for @widget
4118 * This function is for use in widget implementations. Sets the state
4119 * of a widget (insensitive, prelighted, etc.) Usually you should set
4120 * the state using wrapper functions such as gtk_widget_set_sensitive().
4124 gtk_widget_set_state (GtkWidget *widget,
4127 g_return_if_fail (GTK_IS_WIDGET (widget));
4129 if (state == GTK_WIDGET_STATE (widget))
4132 if (state == GTK_STATE_INSENSITIVE)
4133 gtk_widget_set_sensitive (widget, FALSE);
4139 data.state_restoration = FALSE;
4140 data.use_forall = FALSE;
4142 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
4144 data.parent_sensitive = TRUE;
4146 gtk_widget_propagate_state (widget, &data);
4148 if (GTK_WIDGET_DRAWABLE (widget))
4149 gtk_widget_queue_draw (widget);
4154 gtk_widget_set_app_paintable (GtkWidget *widget,
4155 gboolean app_paintable)
4157 g_return_if_fail (GTK_IS_WIDGET (widget));
4159 app_paintable = (app_paintable != FALSE);
4161 if (GTK_WIDGET_APP_PAINTABLE (widget) != app_paintable)
4164 GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE);
4166 GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE);
4168 if (GTK_WIDGET_DRAWABLE (widget))
4169 gtk_widget_queue_draw (widget);
4171 g_object_notify (G_OBJECT (widget), "app_paintable");
4176 * gtk_widget_set_double_buffered:
4177 * @widget: a #GtkWidget
4178 * @double_buffered: %TRUE to double-buffer a widget
4180 * Widgets are double buffered by default; you can use this function
4181 * to turn off the buffering. "Double buffered" simply means that
4182 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
4183 * automatically around expose events sent to the
4184 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
4185 * window to an offscreen buffer, and gdk_window_end_paint() draws the
4186 * buffer to the screen. The result is that users see the window
4187 * update in one smooth step, and don't see individual graphics
4188 * primitives being rendered.
4190 * In very simple terms, double buffered widgets don't flicker,
4191 * so you would only use this function to turn off double buffering
4192 * if you had special needs and really knew what you were doing.
4196 gtk_widget_set_double_buffered (GtkWidget *widget,
4197 gboolean double_buffered)
4199 g_return_if_fail (GTK_IS_WIDGET (widget));
4201 if (double_buffered)
4202 GTK_WIDGET_SET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
4204 GTK_WIDGET_UNSET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
4208 * gtk_widget_set_redraw_on_allocate:
4209 * @widget: a #GtkWidget
4210 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
4211 * when it is allocated to a new size. Otherwise, only the
4212 * new portion of the widget will be redrawn.
4214 * Sets whether a when a widgets size allocation changes, the entire
4215 * widget is queued for drawing. By default, this setting is %TRUE and
4216 * the entire widget is redrawn on every size change. If your widget
4217 * leaves the upper left unchanged when made bigger, turning this
4218 * setting on will improve performance.
4220 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
4221 * off all allocation on resizing: the widget will not even redraw if
4222 * its position changes; this is to allow containers that don't draw
4223 * anything to avoid excess invalidations. If you set this flag on a
4224 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
4225 * you are responsible for invalidating both the old and new allocation
4226 * of the widget when the widget is moved and responsible for invalidating
4227 * regions newly when the widget increases size.
4230 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
4231 gboolean redraw_on_allocate)
4233 g_return_if_fail (GTK_IS_WIDGET (widget));
4235 if (redraw_on_allocate)
4236 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
4238 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
4242 * gtk_widget_set_sensitive:
4243 * @widget: a #GtkWidget
4244 * @sensitive: %TRUE to make the widget sensitive
4246 * Sets the sensitivity of a widget. A widget is sensitive if the user
4247 * can interact with it. Insensitive widgets are "grayed out" and the
4248 * user can't interact with them. Insensitive widgets are known as
4249 * "inactive", "disabled", or "ghosted" in some other toolkits.
4253 gtk_widget_set_sensitive (GtkWidget *widget,
4258 g_return_if_fail (GTK_IS_WIDGET (widget));
4260 sensitive = (sensitive != FALSE);
4262 if (sensitive == (GTK_WIDGET_SENSITIVE (widget) != FALSE))
4267 GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE);
4268 data.state = GTK_WIDGET_SAVED_STATE (widget);
4272 GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE);
4273 data.state = GTK_WIDGET_STATE (widget);
4275 data.state_restoration = TRUE;
4276 data.use_forall = TRUE;
4279 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
4281 data.parent_sensitive = TRUE;
4283 gtk_widget_propagate_state (widget, &data);
4284 if (GTK_WIDGET_DRAWABLE (widget))
4285 gtk_widget_queue_draw (widget);
4287 g_object_notify (G_OBJECT (widget), "sensitive");
4291 * gtk_widget_set_parent:
4292 * @widget: a #GtkWidget
4293 * @parent: parent container
4295 * This function is useful only when implementing subclasses of #GtkContainer.
4296 * Sets the container as the parent of @widget, and takes care of
4297 * some details such as updating the state and style of the child
4298 * to reflect its new location. The opposite function is
4299 * gtk_widget_unparent().
4303 gtk_widget_set_parent (GtkWidget *widget,
4308 g_return_if_fail (GTK_IS_WIDGET (widget));
4309 g_return_if_fail (GTK_IS_WIDGET (parent));
4310 g_return_if_fail (widget != parent);
4311 if (widget->parent != NULL)
4313 g_warning ("Can't set a parent on widget which has a parent\n");
4316 if (GTK_WIDGET_TOPLEVEL (widget))
4318 g_warning ("Can't set a parent on a toplevel widget\n");
4322 /* keep this function in sync with gtk_menu_attach_to_widget()
4325 g_object_ref (widget);
4326 gtk_object_sink (GTK_OBJECT (widget));
4327 widget->parent = parent;
4329 if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
4330 data.state = GTK_WIDGET_STATE (parent);
4332 data.state = GTK_WIDGET_STATE (widget);
4333 data.state_restoration = FALSE;
4334 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (parent) != FALSE);
4335 data.use_forall = GTK_WIDGET_IS_SENSITIVE (parent) != GTK_WIDGET_IS_SENSITIVE (widget);
4337 gtk_widget_propagate_state (widget, &data);
4339 gtk_widget_reset_rc_styles (widget);
4341 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
4342 if (GTK_WIDGET_ANCHORED (widget->parent))
4343 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
4344 g_object_notify (G_OBJECT (widget), "parent");
4346 /* Enforce realized/mapped invariants
4348 if (GTK_WIDGET_REALIZED (widget->parent))
4349 gtk_widget_realize (widget);
4351 if (GTK_WIDGET_VISIBLE (widget->parent) &&
4352 GTK_WIDGET_VISIBLE (widget))
4354 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
4355 GTK_WIDGET_MAPPED (widget->parent))
4356 gtk_widget_map (widget);
4358 gtk_widget_queue_resize (widget);
4363 * gtk_widget_get_parent:
4364 * @widget: a #GtkWidget
4366 * Returns the parent container of @widget.
4368 * Return value: the parent container of @widget, or %NULL
4371 gtk_widget_get_parent (GtkWidget *widget)
4373 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4375 return widget->parent;
4378 /*****************************************
4380 * see docs/styles.txt
4381 *****************************************/
4384 * gtk_widget_set_style:
4385 * @widget: a #GtkWidget
4386 * @style: a #GtkStyle, or %NULL to remove the effect of a previous
4387 * gtk_widget_set_style() and go back to the default style
4389 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
4390 * want to use this function; it interacts badly with themes, because
4391 * themes work by replacing the #GtkStyle. Instead, use
4392 * gtk_widget_modify_style().
4396 gtk_widget_set_style (GtkWidget *widget,
4399 g_return_if_fail (GTK_IS_WIDGET (widget));
4403 gboolean initial_emission;
4405 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
4407 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
4408 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
4410 gtk_widget_set_style_internal (widget, style, initial_emission);
4414 if (GTK_WIDGET_USER_STYLE (widget))
4415 gtk_widget_reset_rc_style (widget);
4420 * gtk_widget_ensure_style:
4421 * @widget: a #GtkWidget
4423 * Ensures that @widget has a style (@widget->style). Not a very useful
4424 * function; most of the time, if you want the style, the widget is
4425 * realized, and realized widgets are guaranteed to have a style
4430 gtk_widget_ensure_style (GtkWidget *widget)
4432 g_return_if_fail (GTK_IS_WIDGET (widget));
4434 if (!GTK_WIDGET_USER_STYLE (widget) &&
4435 !GTK_WIDGET_RC_STYLE (widget))
4436 gtk_widget_reset_rc_style (widget);
4439 /* Look up the RC style for this widget, unsetting any user style that
4440 * may be in effect currently
4443 gtk_widget_reset_rc_style (GtkWidget *widget)
4445 GtkStyle *new_style = NULL;
4446 gboolean initial_emission;
4448 g_return_if_fail (GTK_IS_WIDGET (widget));
4450 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
4452 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
4453 GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
4455 if (gtk_widget_has_screen (widget))
4456 new_style = gtk_rc_get_style (widget);
4458 new_style = gtk_widget_get_default_style ();
4460 if (initial_emission || new_style != widget->style)
4461 gtk_widget_set_style_internal (widget, new_style, initial_emission);
4465 * gtk_widget_get_style:
4466 * @widget: a #GtkWidget
4468 * Simply an accessor function that returns @widget->style.
4470 * Return value: the widget's #GtkStyle
4473 gtk_widget_get_style (GtkWidget *widget)
4475 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4477 return widget->style;
4481 * gtk_widget_modify_style:
4482 * @widget: a #GtkWidget
4483 * @style: the #GtkRcStyle holding the style modifications
4485 * Modifies style values on the widget. Modifications made using this
4486 * technique take precedence over style values set via an RC file,
4487 * however, they will be overriden if a style is explicitely set on
4488 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
4489 * is designed so each field can either be set or unset, so it is
4490 * possible, using this function, to modify some style values and
4491 * leave the others unchanged.
4493 * Note that modifications made with this function are not cumulative
4494 * with previous calls to gtk_widget_modify_style() or with such
4495 * functions as gtk_widget_modify_fg(). If you wish to retain
4496 * previous values, you must first call gtk_widget_get_modifier_style(),
4497 * make your modifications to the returned style, then call
4498 * gtk_widget_modify_style() with that style. On the other hand,
4499 * if you first call gtk_widget_modify_style(), subsequent calls
4500 * to such functions gtk_widget_modify_fg() will have a cumulative
4501 * effect with the initial modifications.
4504 gtk_widget_modify_style (GtkWidget *widget,
4507 GtkRcStyle *old_style;
4509 g_return_if_fail (GTK_IS_WIDGET (widget));
4510 g_return_if_fail (GTK_IS_RC_STYLE (style));
4512 old_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
4514 g_object_set_qdata_full (G_OBJECT (widget),
4516 gtk_rc_style_copy (style),
4517 (GDestroyNotify) gtk_rc_style_unref);
4519 /* note that "style" may be invalid here if it was the old
4520 * modifier style and the only reference was our own.
4523 if (GTK_WIDGET_RC_STYLE (widget))
4524 gtk_widget_reset_rc_style (widget);
4528 * gtk_widget_get_modifier_style:
4529 * @widget: a #GtkWidget
4531 * Returns the current modifier style for the widget. (As set by
4532 * gtk_widget_modify_style().) If no style has previously set, a new
4533 * #GtkRcStyle will be created with all values unset, and set as the
4534 * modifier style for the widget. If you make changes to this rc
4535 * style, you must call gtk_widget_modify_style(), passing in the
4536 * returned rc style, to make sure that your changes take effect.
4538 * Caution: passing the style back to gtk_widget_modify_style() will
4539 * normally end up destroying it, because gtk_widget_modify_style() copies
4540 * the passed-in style and sets the copy as the new modifier style,
4541 * thus dropping any reference to the old modifier style. Add a reference
4542 * to the modifier style if you want to keep it alive.
4544 * Return value: the modifier style for the widget. This rc style is
4545 * owned by the widget. If you want to keep a pointer to value this
4546 * around, you must add a refcount using gtk_rc_style_ref().
4549 gtk_widget_get_modifier_style (GtkWidget *widget)
4551 GtkRcStyle *rc_style;
4553 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4555 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
4559 rc_style = gtk_rc_style_new ();
4560 g_object_set_qdata_full (G_OBJECT (widget),
4563 (GDestroyNotify) gtk_rc_style_unref);
4570 gtk_widget_modify_color_component (GtkWidget *widget,
4571 GtkRcFlags component,
4573 const GdkColor *color)
4575 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
4582 rc_style->fg[state] = *color;
4585 rc_style->bg[state] = *color;
4588 rc_style->text[state] = *color;
4591 rc_style->base[state] = *color;
4594 g_assert_not_reached();
4597 rc_style->color_flags[state] |= component;
4600 rc_style->color_flags[state] &= ~component;
4602 gtk_widget_modify_style (widget, rc_style);
4606 * gtk_widget_modify_fg:
4607 * @widget: a #GtkWidget.
4608 * @state: the state for which to set the foreground color.
4609 * @color: the color to assign (does not need to be allocated),
4610 * or %NULL to undo the effect of previous calls to
4611 * of gtk_widget_modify_fg().
4613 * Sets the foreground color for a widget in a particular state. All
4614 * other style values are left untouched. See also
4615 * gtk_widget_modify_style().
4618 gtk_widget_modify_fg (GtkWidget *widget,
4620 const GdkColor *color)
4622 g_return_if_fail (GTK_IS_WIDGET (widget));
4623 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4625 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
4629 * gtk_widget_modify_bg:
4630 * @widget: a #GtkWidget.
4631 * @state: the state for which to set the background color.
4632 * @color: the color to assign (does not need to be allocated),
4633 * or %NULL to undo the effect of previous calls to
4634 * of gtk_widget_modify_bg().
4636 * Sets the background color for a widget in a particular state. All
4637 * other style values are left untouched. See also
4638 * gtk_widget_modify_style().
4641 gtk_widget_modify_bg (GtkWidget *widget,
4643 const GdkColor *color)
4645 g_return_if_fail (GTK_IS_WIDGET (widget));
4646 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4648 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
4652 * gtk_widget_modify_text:
4653 * @widget: a #GtkWidget.
4654 * @state: the state for which to set the text color.
4655 * @color: the color to assign (does not need to be allocated),
4656 * or %NULL to undo the effect of previous calls to
4657 * of gtk_widget_modify_text().
4659 * Sets the text color for a widget in a particular state. All other
4660 * style values are left untouched. The text color is the foreground
4661 * color used along with the base color (see gtk_widget_modify_base())
4662 * for widgets such as #GtkEntry and #GtkTextView. See also
4663 * gtk_widget_modify_style().
4666 gtk_widget_modify_text (GtkWidget *widget,
4668 const GdkColor *color)
4670 g_return_if_fail (GTK_IS_WIDGET (widget));
4671 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4673 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
4677 * gtk_widget_modify_base:
4678 * @widget: a #GtkWidget.
4679 * @state: the state for which to set the base color.
4680 * @color: the color to assign (does not need to be allocated),
4681 * or %NULL to undo the effect of previous calls to
4682 * of gtk_widget_modify_base().
4684 * Sets the base color for a widget in a particular state.
4685 * All other style values are left untouched. The base color
4686 * is the background color used along with the text color
4687 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
4688 * and #GtkTextView. See also gtk_widget_modify_style().
4691 gtk_widget_modify_base (GtkWidget *widget,
4693 const GdkColor *color)
4695 g_return_if_fail (GTK_IS_WIDGET (widget));
4696 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4698 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
4702 * gtk_widget_modify_font:
4703 * @widget: a #GtkWidget
4704 * @font_desc: the font description to use, or %NULL to undo
4705 * the effect of previous calls to gtk_widget_modify_font().
4707 * Sets the font to use for a widget. All other style values are left
4708 * untouched. See also gtk_widget_modify_style().
4711 gtk_widget_modify_font (GtkWidget *widget,
4712 PangoFontDescription *font_desc)
4714 GtkRcStyle *rc_style;
4716 g_return_if_fail (GTK_IS_WIDGET (widget));
4718 rc_style = gtk_widget_get_modifier_style (widget);
4720 if (rc_style->font_desc)
4721 pango_font_description_free (rc_style->font_desc);
4724 rc_style->font_desc = pango_font_description_copy (font_desc);
4726 rc_style->font_desc = NULL;
4728 gtk_widget_modify_style (widget, rc_style);
4732 gtk_widget_direction_changed (GtkWidget *widget,
4733 GtkTextDirection previous_direction)
4735 gtk_widget_queue_resize (widget);
4739 gtk_widget_style_set (GtkWidget *widget,
4740 GtkStyle *previous_style)
4742 if (GTK_WIDGET_REALIZED (widget) &&
4743 !GTK_WIDGET_NO_WINDOW (widget))
4744 gtk_style_set_background (widget->style, widget->window, widget->state);
4748 gtk_widget_set_style_internal (GtkWidget *widget,
4750 gboolean initial_emission)
4752 g_object_ref (widget);
4753 g_object_freeze_notify (G_OBJECT (widget));
4755 if (widget->style != style || initial_emission)
4757 PangoContext *context = gtk_widget_peek_pango_context (widget);
4759 pango_context_set_font_description (context, style->font_desc);
4762 if (widget->style != style)
4764 GtkStyle *previous_style;
4766 if (GTK_WIDGET_REALIZED (widget))
4768 gtk_widget_reset_shapes (widget);
4769 gtk_style_detach (widget->style);
4772 previous_style = widget->style;
4773 widget->style = style;
4774 g_object_ref (widget->style);
4776 if (GTK_WIDGET_REALIZED (widget))
4777 widget->style = gtk_style_attach (widget->style, widget->window);
4779 g_signal_emit (widget,
4780 widget_signals[STYLE_SET],
4782 initial_emission ? NULL : previous_style);
4783 g_object_unref (previous_style);
4785 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
4786 gtk_widget_queue_resize (widget);
4788 else if (initial_emission)
4789 g_signal_emit (widget,
4790 widget_signals[STYLE_SET],
4793 g_object_notify (G_OBJECT (widget), "style");
4794 g_object_thaw_notify (G_OBJECT (widget));
4795 g_object_unref (widget);
4799 GtkWidget *previous_toplevel;
4800 GdkScreen *previous_screen;
4801 GdkScreen *new_screen;
4802 } HierarchyChangedInfo;
4805 do_screen_change (GtkWidget *widget,
4806 GdkScreen *old_screen,
4807 GdkScreen *new_screen)
4809 if (old_screen != new_screen)
4813 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
4815 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
4818 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
4823 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
4824 gpointer client_data)
4826 gboolean new_anchored;
4827 HierarchyChangedInfo *info = client_data;
4829 new_anchored = GTK_WIDGET_TOPLEVEL (widget) ||
4830 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
4832 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
4834 g_object_ref (widget);
4837 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
4839 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
4841 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
4842 do_screen_change (widget, info->previous_screen, info->new_screen);
4844 if (GTK_IS_CONTAINER (widget))
4845 gtk_container_forall (GTK_CONTAINER (widget),
4846 gtk_widget_propagate_hierarchy_changed_recurse,
4849 g_object_unref (widget);
4854 * _gtk_widget_propagate_hierarchy_changed:
4855 * @widget: a #GtkWidget
4856 * @previous_toplevel: Previous toplevel
4858 * Propagates changes in the anchored state to a widget and all
4859 * children, unsetting or setting the %ANCHORED flag, and
4860 * emitting ::hierarchy_changed.
4863 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
4864 GtkWidget *previous_toplevel)
4866 HierarchyChangedInfo info;
4868 info.previous_toplevel = previous_toplevel;
4869 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
4871 if (GTK_WIDGET_TOPLEVEL (widget) ||
4872 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
4873 info.new_screen = gtk_widget_get_screen (widget);
4875 info.new_screen = NULL;
4877 if (info.previous_screen)
4878 g_object_ref (info.previous_screen);
4879 if (previous_toplevel)
4880 g_object_ref (previous_toplevel);
4882 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
4884 if (previous_toplevel)
4885 g_object_unref (previous_toplevel);
4886 if (info.previous_screen)
4887 g_object_unref (info.previous_screen);
4891 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
4892 gpointer client_data)
4894 HierarchyChangedInfo *info = client_data;
4896 g_object_ref (widget);
4898 do_screen_change (widget, info->previous_screen, info->new_screen);
4900 if (GTK_IS_CONTAINER (widget))
4901 gtk_container_forall (GTK_CONTAINER (widget),
4902 gtk_widget_propagate_screen_changed_recurse,
4905 g_object_unref (widget);
4909 * _gtk_widget_propagate_screen_changed:
4910 * @widget: a #GtkWidget
4911 * @previous_screen: Previous screen
4913 * Propagates changes in the screen for a widget to all
4914 * children, emitting ::screen_changed.
4917 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
4918 GdkScreen *previous_screen)
4920 HierarchyChangedInfo info;
4922 info.previous_screen = previous_screen;
4923 info.new_screen = gtk_widget_get_screen (widget);
4925 if (previous_screen)
4926 g_object_ref (previous_screen);
4928 gtk_widget_propagate_screen_changed_recurse (widget, &info);
4930 if (previous_screen)
4931 g_object_unref (previous_screen);
4935 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
4937 if (GTK_WIDGET_RC_STYLE (widget))
4938 gtk_widget_reset_rc_style (widget);
4940 if (GTK_IS_CONTAINER (widget))
4941 gtk_container_forall (GTK_CONTAINER (widget),
4942 reset_rc_styles_recurse,
4947 gtk_widget_reset_rc_styles (GtkWidget *widget)
4949 g_return_if_fail (GTK_IS_WIDGET (widget));
4951 reset_rc_styles_recurse (widget, NULL);
4955 * gtk_widget_get_default_style:
4957 * Returns the default style used by all widgets initially.
4959 * Returns: the default style. This #GtkStyle object is owned by GTK+ and
4960 * should not be modified or freed.
4963 gtk_widget_get_default_style (void)
4965 if (!gtk_default_style)
4967 gtk_default_style = gtk_style_new ();
4968 g_object_ref (gtk_default_style);
4971 return gtk_default_style;
4974 static PangoContext *
4975 gtk_widget_peek_pango_context (GtkWidget *widget)
4977 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
4981 * gtk_widget_get_pango_context:
4982 * @widget: a #GtkWidget
4984 * Gets a #PangoContext with the appropriate colormap, font description
4985 * and base direction for this widget. Unlike the context returned
4986 * by gtk_widget_create_pango_context(), this context is owned by
4987 * the widget (it can be used until the screen for the widget changes
4988 * or the widget is removed from its toplevel), and will be updated to
4989 * match any changes to the widget's attributes.
4991 * If you create and keep a #PangoLayout using this context, you must
4992 * deal with changes to the context by calling pango_layout_context_changed()
4993 * on the layout in response to the ::style-set and ::direction-changed signals
4996 * Return value: the #PangoContext for the widget.
4999 gtk_widget_get_pango_context (GtkWidget *widget)
5001 PangoContext *context;
5003 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5005 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
5008 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
5009 g_object_set_qdata_full (G_OBJECT (widget),
5010 quark_pango_context,
5019 * gtk_widget_create_pango_context:
5020 * @widget: a #GtkWidget
5022 * Creates a new #PangoContext with the appropriate colormap,
5023 * font description, and base direction for drawing text for
5024 * this widget. See also gtk_widget_get_pango_context().
5026 * Return value: the new #PangoContext
5029 gtk_widget_create_pango_context (GtkWidget *widget)
5032 PangoContext *context;
5034 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5036 screen = gtk_widget_get_screen_unchecked (widget);
5039 GTK_NOTE (MULTIHEAD,
5040 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
5042 screen = gdk_screen_get_default ();
5045 context = gdk_pango_context_get_for_screen (screen);
5047 pango_context_set_base_dir (context,
5048 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
5049 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
5050 pango_context_set_font_description (context, widget->style->font_desc);
5051 pango_context_set_language (context, gtk_get_default_language ());
5057 * gtk_widget_create_pango_layout:
5058 * @widget: a #GtkWidget
5059 * @text: text to set on the layout (can be %NULL)
5061 * Creates a new #PangoLayout with the appropriate colormap,
5062 * font description, and base direction for drawing text for
5065 * If you keep a #PangoLayout created in this way around, in order
5066 * notify the layout of changes to the base direction or font of this
5067 * widget, you must call pango_layout_context_changed() in response to
5068 * the ::style-set and ::direction-changed signals for the widget.
5070 * Return value: the new #PangoLayout
5073 gtk_widget_create_pango_layout (GtkWidget *widget,
5076 PangoLayout *layout;
5077 PangoContext *context;
5079 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5081 context = gtk_widget_get_pango_context (widget);
5082 layout = pango_layout_new (context);
5085 pango_layout_set_text (layout, text, -1);
5091 * gtk_widget_render_icon:
5092 * @widget: a #GtkWidget
5093 * @stock_id: a stock ID
5094 * @size: a stock size. A size of (GtkIconSize)-1 means render at
5095 * the size of the source and don't scale (if there are multiple
5096 * source sizes, GTK+ picks one of the available sizes).
5097 * @detail: render detail to pass to theme engine
5099 * A convenience function that uses the theme engine and RC file
5100 * settings for @widget to look up @stock_id and render it to
5101 * a pixbuf. @stock_id should be a stock icon ID such as
5102 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
5103 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
5104 * identifies the widget or code doing the rendering, so that
5105 * theme engines can special-case rendering for that widget or code.
5107 * The pixels in the returned #GdkPixbuf are shared with the rest of
5108 * the application and should not be modified. The pixbuf should be freed
5109 * after use with g_object_unref().
5111 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
5114 gtk_widget_render_icon (GtkWidget *widget,
5115 const gchar *stock_id,
5117 const gchar *detail)
5119 GtkIconSet *icon_set;
5122 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5123 g_return_val_if_fail (stock_id != NULL, NULL);
5124 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
5126 gtk_widget_ensure_style (widget);
5128 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
5130 if (icon_set == NULL)
5133 retval = gtk_icon_set_render_icon (icon_set,
5135 gtk_widget_get_direction (widget),
5136 GTK_WIDGET_STATE (widget),
5145 * gtk_widget_set_parent_window:
5146 * @widget: a #GtkWidget.
5147 * @parent_window: the new parent window.
5149 * Sets a non default parent window for @widget.
5152 gtk_widget_set_parent_window (GtkWidget *widget,
5153 GdkWindow *parent_window)
5155 GdkWindow *old_parent_window;
5157 g_return_if_fail (GTK_IS_WIDGET (widget));
5159 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
5160 quark_parent_window);
5162 if (parent_window != old_parent_window)
5164 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
5166 if (old_parent_window)
5167 g_object_unref (old_parent_window);
5169 g_object_ref (parent_window);
5175 * gtk_widget_set_child_visible:
5176 * @widget: a #GtkWidget
5177 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
5179 * Sets whether @widget should be mapped along with its when its parent
5180 * is mapped and @widget has been shown with gtk_widget_show().
5182 * The child visibility can be set for widget before it is added to
5183 * a container with gtk_widget_set_parent(), to avoid mapping
5184 * children unnecessary before immediately unmapping them. However
5185 * it will be reset to its default state of %TRUE when the widget
5186 * is removed from a container.
5188 * Note that changing the child visibility of a widget does not
5189 * queue a resize on the widget. Most of the time, the size of
5190 * a widget is computed from all visible children, whether or
5191 * not they are mapped. If this is not the case, the container
5192 * can queue a resize itself.
5194 * This function is only useful for container implementations and
5195 * never should be called by an application.
5198 gtk_widget_set_child_visible (GtkWidget *widget,
5199 gboolean is_visible)
5201 g_return_if_fail (GTK_IS_WIDGET (widget));
5202 g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
5204 g_object_ref (widget);
5207 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
5210 GtkWidget *toplevel;
5212 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
5214 toplevel = gtk_widget_get_toplevel (widget);
5215 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
5216 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
5219 if (widget->parent && GTK_WIDGET_REALIZED (widget->parent))
5221 if (GTK_WIDGET_MAPPED (widget->parent) &&
5222 GTK_WIDGET_CHILD_VISIBLE (widget) &&
5223 GTK_WIDGET_VISIBLE (widget))
5224 gtk_widget_map (widget);
5226 gtk_widget_unmap (widget);
5229 g_object_unref (widget);
5233 * gtk_widget_get_child_visible:
5234 * @widget: a #GtkWidget
5236 * Gets the value set with gtk_widget_set_child_visible().
5237 * If you feel a need to use this function, your code probably
5238 * needs reorganization.
5240 * This function is only useful for container implementations and
5241 * never should be called by an application.
5243 * Return value: %TRUE if the widget is mapped with the parent.
5246 gtk_widget_get_child_visible (GtkWidget *widget)
5248 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5250 return GTK_WIDGET_CHILD_VISIBLE (widget);
5254 gtk_widget_get_screen_unchecked (GtkWidget *widget)
5256 GtkWidget *toplevel;
5258 toplevel = gtk_widget_get_toplevel (widget);
5260 if (GTK_WIDGET_TOPLEVEL (toplevel))
5262 if (GTK_IS_WINDOW (toplevel))
5263 return GTK_WINDOW (toplevel)->screen;
5264 else if (GTK_IS_INVISIBLE (toplevel))
5265 return GTK_INVISIBLE (widget)->screen;
5272 * gtk_widget_get_screen:
5273 * @widget: a #GtkWidget
5275 * Get the #GdkScreen from the toplevel window associated with
5276 * this widget. This function can only be called after the widget
5277 * has been added to a widget hierarchy with a #GtkWindow
5280 * In general, you should only create screen specific
5281 * resources when a widget has been realized, and you should
5282 * free those resources when the widget is unrealized.
5284 * Return value: the #GdkScreen for the toplevel for this widget.
5289 gtk_widget_get_screen (GtkWidget *widget)
5293 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5295 screen = gtk_widget_get_screen_unchecked (widget);
5302 g_warning (G_STRLOC ": Can't get associated screen"
5303 " for a widget unless it is inside a toplevel GtkWindow\n"
5304 " widget type is %s associated top level type is %s",
5305 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
5306 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
5308 return gdk_screen_get_default ();
5313 * gtk_widget_has_screen:
5314 * @widget: a #GtkWidget
5316 * Checks whether there is a #GdkScreen is associated with
5317 * this widget. All toplevel widgets have an associated
5318 * screen, and all widgets added into a heirarchy with a toplevel
5319 * window at the top.
5321 * Return value: %TRUE if there is a #GdkScreen associcated
5327 gtk_widget_has_screen (GtkWidget *widget)
5329 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5331 return (gtk_widget_get_screen_unchecked (widget) != NULL);
5335 * gtk_widget_get_display:
5336 * @widget: a #GtkWidget
5338 * Get the #GdkDisplay for the toplevel window associated with
5339 * this widget. This function can only be called after the widget
5340 * has been added to a widget hierarchy with a #GtkWindow at the top.
5342 * In general, you should only create display specific
5343 * resources when a widget has been realized, and you should
5344 * free those resources when the widget is unrealized.
5346 * Return value: the #GdkDisplay for the toplevel for this widget.
5351 gtk_widget_get_display (GtkWidget *widget)
5353 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5355 return gdk_screen_get_display (gtk_widget_get_screen (widget));
5359 * gtk_widget_get_root_window:
5360 * @widget: a #GtkWidget
5362 * Get the root window where this widget is located. This function can
5363 * only be called after the widget has been added to a widget
5364 * heirarchy with #GtkWindow at the top.
5366 * The root window is useful for such purposes as creating a popup
5367 * #GdkWindow associated with the window. In general, you should only
5368 * create display specific resources when a widget has been realized,
5369 * and you should free those resources when the widget is unrealized.
5371 * Return value: the #GdkWindow root window for the toplevel for this widget.
5376 gtk_widget_get_root_window (GtkWidget *widget)
5378 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5380 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
5384 * gtk_widget_get_parent_window:
5385 * @widget: a #GtkWidget.
5386 * @returns: the parent window of @widget.
5388 * Gets @widget's parent window.
5391 gtk_widget_get_parent_window (GtkWidget *widget)
5393 GdkWindow *parent_window;
5395 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5396 g_return_val_if_fail (widget->parent != NULL, NULL);
5398 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
5400 return (parent_window != NULL) ? parent_window : widget->parent->window;
5404 * gtk_widget_child_focus:
5405 * @widget: a #GtkWidget
5406 * @direction: direction of focus movement
5408 * This function is used by custom widget implementations; if you're
5409 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
5410 * to a particular widget, and gtk_container_set_focus_chain() to
5411 * change the focus tab order. So you may want to investigate those
5412 * functions instead.
5414 * gtk_widget_child_focus() is called by containers as the user moves
5415 * around the window using keyboard shortcuts. @direction indicates
5416 * what kind of motion is taking place (up, down, left, right, tab
5417 * forward, tab backward). gtk_widget_child_focus() invokes the
5418 * "focus" signal on #GtkWidget; widgets override the default handler
5419 * for this signal in order to implement appropriate focus behavior.
5421 * The "focus" default handler for a widget should return %TRUE if
5422 * moving in @direction left the focus on a focusable location inside
5423 * that widget, and %FALSE if moving in @direction moved the focus
5424 * outside the widget. If returning %TRUE, widgets normally
5425 * call gtk_widget_grab_focus() to place the focus accordingly;
5426 * if returning %FALSE, they don't modify the current focus location.
5428 * This function replaces gtk_container_focus() from GTK+ 1.2. It was
5429 * necessary to check that the child was visible, sensitive, and
5430 * focusable before calling
5431 * gtk_container_focus(). gtk_widget_child_focus() returns %FALSE if
5432 * the widget is not currently in a focusable state, so there's no
5433 * need for those checks.
5435 * Return value: %TRUE if focus ended up inside @widget
5438 gtk_widget_child_focus (GtkWidget *widget,
5439 GtkDirectionType direction)
5441 gboolean return_val;
5443 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5445 if (!GTK_WIDGET_VISIBLE (widget) ||
5446 !GTK_WIDGET_IS_SENSITIVE (widget))
5449 /* child widgets must set CAN_FOCUS, containers
5450 * don't have to though.
5452 if (!GTK_IS_CONTAINER (widget) &&
5453 !GTK_WIDGET_CAN_FOCUS (widget))
5456 g_signal_emit (widget,
5457 widget_signals[FOCUS],
5459 direction, &return_val);
5465 * gtk_widget_set_uposition:
5466 * @widget: a #GtkWidget
5467 * @x: x position; -1 to unset x; -2 to leave x unchanged
5468 * @y: y position; -1 to unset y; -2 to leave y unchanged
5471 * Sets the position of a widget. The funny "u" in the name comes from
5472 * the "user position" hint specified by the X Window System, and
5473 * exists for legacy reasons. This function doesn't work if a widget
5474 * is inside a container; it's only really useful on #GtkWindow.
5476 * Don't use this function to center dialogs over the main application
5477 * window; most window managers will do the centering on your behalf
5478 * if you call gtk_window_set_transient_for(), and it's really not
5479 * possible to get the centering to work correctly in all cases from
5480 * application code. But if you insist, use gtk_window_set_position()
5481 * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
5484 * Note that although @x and @y can be individually unset, the position
5485 * is not honoured unless both @x and @y are set.
5488 gtk_widget_set_uposition (GtkWidget *widget,
5492 /* FIXME this function is the only place that aux_info->x and
5493 * aux_info->y are even used I believe, and this function is
5494 * deprecated. Should be cleaned up.
5496 * (Actually, size_allocate uses them) -Yosh
5499 GtkWidgetAuxInfo *aux_info;
5501 g_return_if_fail (GTK_IS_WIDGET (widget));
5503 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
5508 aux_info->x_set = FALSE;
5511 aux_info->x_set = TRUE;
5519 aux_info->y_set = FALSE;
5522 aux_info->y_set = TRUE;
5527 if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
5528 _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
5530 if (GTK_WIDGET_VISIBLE (widget) && widget->parent)
5531 gtk_widget_size_allocate (widget, &widget->allocation);
5535 gtk_widget_set_usize_internal (GtkWidget *widget,
5539 GtkWidgetAuxInfo *aux_info;
5540 gboolean changed = FALSE;
5542 g_return_if_fail (GTK_IS_WIDGET (widget));
5544 g_object_freeze_notify (G_OBJECT (widget));
5546 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
5548 if (width > -2 && aux_info->width != width)
5550 g_object_notify (G_OBJECT (widget), "width_request");
5551 aux_info->width = width;
5554 if (height > -2 && aux_info->height != height)
5556 g_object_notify (G_OBJECT (widget), "height_request");
5557 aux_info->height = height;
5561 if (GTK_WIDGET_VISIBLE (widget) && changed)
5562 gtk_widget_queue_resize (widget);
5564 g_object_thaw_notify (G_OBJECT (widget));
5568 * gtk_widget_set_usize:
5569 * @widget: a #GtkWidget
5570 * @width: minimum width, or -1 to unset
5571 * @height: minimum height, or -1 to unset
5573 * Sets the minimum size of a widget; that is, the widget's size
5574 * request will be @width by @height. You can use this function to
5575 * force a widget to be either larger or smaller than it is. The
5576 * strange "usize" name dates from the early days of GTK+, and derives
5577 * from X Window System terminology. In many cases,
5578 * gtk_window_set_default_size() is a better choice for toplevel
5579 * windows than this function; setting the default size will still
5580 * allow users to shrink the window. Setting the usize will force them
5581 * to leave the window at least as large as the usize. When dealing
5582 * with window sizes, gtk_window_set_geometry_hints() can be a useful
5585 * Note the inherent danger of setting any fixed size - themes,
5586 * translations into other languages, different fonts, and user action
5587 * can all change the appropriate size for a given widget. So, it's
5588 * basically impossible to hardcode a size that will always be
5591 * @Deprecated: Use gtk_widget_set_size_request() instead.
5594 gtk_widget_set_usize (GtkWidget *widget,
5598 g_return_if_fail (GTK_IS_WIDGET (widget));
5600 gtk_widget_set_usize_internal (widget, width, height);
5604 * gtk_widget_set_size_request:
5605 * @widget: a #GtkWidget
5606 * @width: width @widget should request, or -1 to unset
5607 * @height: height @widget should request, or -1 to unset
5609 * Sets the minimum size of a widget; that is, the widget's size
5610 * request will be @width by @height. You can use this function to
5611 * force a widget to be either larger or smaller than it normally
5614 * In most cases, gtk_window_set_default_size() is a better choice for
5615 * toplevel windows than this function; setting the default size will
5616 * still allow users to shrink the window. Setting the size request
5617 * will force them to leave the window at least as large as the size
5618 * request. When dealing with window sizes,
5619 * gtk_window_set_geometry_hints() can be a useful function as well.
5621 * Note the inherent danger of setting any fixed size - themes,
5622 * translations into other languages, different fonts, and user action
5623 * can all change the appropriate size for a given widget. So, it's
5624 * basically impossible to hardcode a size that will always be
5627 * The size request of a widget is the smallest size a widget can
5628 * accept while still functioning well and drawing itself correctly.
5629 * However in some strange cases a widget may be allocated less than
5630 * its requested size, and in many cases a widget may be allocated more
5631 * space than it requested.
5633 * If the size request in a given direction is -1 (unset), then
5634 * the "natural" size request of the widget will be used instead.
5636 * Widgets can't actually be allocated a size less than 1 by 1, but
5637 * you can pass 0,0 to this function to mean "as small as possible."
5640 gtk_widget_set_size_request (GtkWidget *widget,
5644 g_return_if_fail (GTK_IS_WIDGET (widget));
5645 g_return_if_fail (width >= -1);
5646 g_return_if_fail (height >= -1);
5653 gtk_widget_set_usize_internal (widget, width, height);
5658 * gtk_widget_get_size_request:
5659 * @widget: a #GtkWidget
5660 * @width: return location for width, or %NULL
5661 * @height: return location for height, or %NULL
5663 * Gets the size request that was explicitly set for the widget using
5664 * gtk_widget_set_size_request(). A value of -1 stored in @width or
5665 * @height indicates that that dimension has not been set explicitly
5666 * and the natural requisition of the widget will be used intead. See
5667 * gtk_widget_set_size_request(). To get the size a widget will
5668 * actually use, call gtk_widget_size_request() instead of
5674 gtk_widget_get_size_request (GtkWidget *widget,
5678 GtkWidgetAuxInfo *aux_info;
5680 g_return_if_fail (GTK_IS_WIDGET (widget));
5682 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
5685 *width = aux_info ? aux_info->width : -1;
5688 *height = aux_info ? aux_info->height : -1;
5692 * gtk_widget_set_events:
5693 * @widget: a #GtkWidget
5694 * @events: event mask
5696 * Sets the event mask (see #GdkEventMask) for a widget. The event
5697 * mask determines which events a widget will receive. Keep in mind
5698 * that different widgets have different default event masks, and by
5699 * changing the event mask you may disrupt a widget's functionality,
5700 * so be careful. This function must be called while a widget is
5701 * unrealized. Consider gtk_widget_add_events() for widgets that are
5702 * already realized, or if you want to preserve the existing event
5703 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
5704 * to get events on those widgets, place them inside a #GtkEventBox
5705 * and receive events on the event box.
5709 gtk_widget_set_events (GtkWidget *widget,
5714 g_return_if_fail (GTK_IS_WIDGET (widget));
5715 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
5717 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
5722 eventp = g_new (gint, 1);
5725 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, eventp);
5730 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, NULL);
5733 g_object_notify (G_OBJECT (widget), "events");
5737 * gtk_widget_add_events:
5738 * @widget: a #GtkWidget
5739 * @events: an event mask, see #GdkEventMask
5741 * Adds the events in the bitfield @events to the event mask for
5742 * @widget. See gtk_widget_set_events() for details.
5746 gtk_widget_add_events (GtkWidget *widget,
5751 g_return_if_fail (GTK_IS_WIDGET (widget));
5753 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
5759 eventp = g_new (gint, 1);
5764 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, eventp);
5769 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, NULL);
5772 if (GTK_WIDGET_REALIZED (widget))
5774 if (GTK_WIDGET_NO_WINDOW (widget))
5776 GList *children = gdk_window_get_children (widget->window);
5777 GList *tmp_list = children;
5781 GdkWindow *window = tmp_list->data;
5784 gdk_window_get_user_data (window, &user_data);
5785 if (user_data == widget)
5786 gdk_window_set_events (window, gdk_window_get_events (window) | events);
5787 tmp_list = tmp_list->next;
5790 g_list_free (children);
5794 gdk_window_set_events (widget->window, gdk_window_get_events (widget->window) | events);
5798 g_object_notify (G_OBJECT (widget), "events");
5802 * gtk_widget_set_extension_events:
5803 * @widget: a #GtkWidget
5804 * @mode: bitfield of extension events to receive
5806 * Sets the extension events mask to @mode. See #GdkExtensionMode
5807 * and gdk_input_set_extension_events().
5811 gtk_widget_set_extension_events (GtkWidget *widget,
5812 GdkExtensionMode mode)
5814 GdkExtensionMode *modep;
5816 g_return_if_fail (GTK_IS_WIDGET (widget));
5818 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
5821 modep = g_new (GdkExtensionMode, 1);
5824 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode, modep);
5825 g_object_notify (G_OBJECT (widget), "extension_events");
5829 * gtk_widget_get_toplevel:
5830 * @widget: a #GtkWidget
5832 * This function returns the topmost widget in the container hierarchy
5833 * @widget is a part of. If @widget has no parent widgets, it will be
5834 * returned as the topmost widget. No reference will be added to the
5835 * returned widget; it should not be unreferenced.
5837 * Note the difference in behavior vs. gtk_widget_get_ancestor();
5838 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
5840 * %NULL if @widget wasn't inside a toplevel window, and if the
5841 * window was inside a #GtkWindow-derived widget which was in turn
5842 * inside the toplevel #GtkWindow. While the second case may
5843 * seem unlikely, it actually happens when a #GtkPlug is embedded
5844 * inside a #GtkSocket within the same application.
5846 * To reliably find the toplevel #GtkWindow, use
5847 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
5848 * is set on the result.
5849 * <informalexample><programlisting>
5850 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5851 * if (GTK_WIDGET_TOPLEVEL (toplevel))
5853 * [ Perform action on toplevel. ]
5855 * </programlisting></informalexample>
5857 * Return value: the topmost ancestor of @widget, or @widget itself if there's no ancestor.
5860 gtk_widget_get_toplevel (GtkWidget *widget)
5862 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5864 while (widget->parent)
5865 widget = widget->parent;
5871 * gtk_widget_get_ancestor:
5872 * @widget: a #GtkWidget
5873 * @widget_type: ancestor type
5875 * Gets the first ancestor of @widget with type @widget_type. For example,
5876 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets the
5877 * first #GtkBox that's
5878 * an ancestor of @widget. No reference will be added to the returned widget;
5879 * it should not be unreferenced. See note about checking for a toplevel
5880 * #GtkWindow in the docs for gtk_widget_get_toplevel().
5882 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
5883 * considers @widget to be an ancestor of itself.
5885 * Return value: the ancestor widget, or %NULL if not found
5888 gtk_widget_get_ancestor (GtkWidget *widget,
5891 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5893 while (widget && !g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))
5894 widget = widget->parent;
5896 if (!(widget && g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)))
5903 * gtk_widget_get_colormap:
5904 * @widget: a #GtkWidget
5906 * Gets the colormap that will be used to render @widget. No reference will
5907 * be added to the returned colormap; it should not be unreferenced.
5909 * Return value: the colormap used by @widget
5912 gtk_widget_get_colormap (GtkWidget *widget)
5914 GdkColormap *colormap;
5915 GtkWidget *tmp_widget;
5917 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5921 colormap = gdk_drawable_get_colormap (widget->window);
5922 /* If window was destroyed previously, we'll get NULL here */
5927 tmp_widget = widget;
5930 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
5934 tmp_widget= tmp_widget->parent;
5937 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
5941 * gtk_widget_get_visual:
5942 * @widget: a #GtkWidget
5944 * Gets the visual that will be used to render @widget.
5946 * Return value: the visual for @widget
5949 gtk_widget_get_visual (GtkWidget *widget)
5951 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5953 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
5957 * gtk_widget_get_settings:
5958 * @widget: a #GtkWidget
5960 * Gets the settings object holding the settings (global property
5961 * settings, RC file information, etc) used for this widget.
5963 * Note that this function can only be called when the #GtkWidget
5964 * is attached to a toplevel, since the settings object is specific
5965 * to a particular #GdkScreen.
5967 * Return value: the relevant #GtkSettings object
5970 gtk_widget_get_settings (GtkWidget *widget)
5972 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5974 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
5978 * gtk_widget_set_colormap:
5979 * @widget: a #GtkWidget
5980 * @colormap: a colormap
5982 * Sets the colormap for the widget to the given value. Widget must not
5983 * have been previously realized. This probably should only be used
5984 * from an <function>init()</function> function (i.e. from the constructor
5989 gtk_widget_set_colormap (GtkWidget *widget,
5990 GdkColormap *colormap)
5992 g_return_if_fail (GTK_IS_WIDGET (widget));
5993 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
5994 g_return_if_fail (GDK_IS_COLORMAP (colormap));
5996 g_object_ref (colormap);
5998 g_object_set_qdata_full (G_OBJECT (widget),
6005 * gtk_widget_get_events:
6006 * @widget: a #GtkWidget
6008 * Returns the event mask for the widget (a bitfield containing flags
6009 * from the #GdkEventMask enumeration). These are the events that the widget
6012 * Return value: event mask for @widget
6015 gtk_widget_get_events (GtkWidget *widget)
6019 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
6021 events = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
6029 * gtk_widget_get_extension_events:
6030 * @widget: a #GtkWidget
6032 * Retrieves the extension events the widget will receive; see
6033 * gdk_input_set_extension_events().
6035 * Return value: extension events for @widget
6038 gtk_widget_get_extension_events (GtkWidget *widget)
6040 GdkExtensionMode *mode;
6042 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
6044 mode = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
6052 * gtk_widget_get_pointer:
6053 * @widget: a #GtkWidget
6054 * @x: return location for the X coordinate, or %NULL
6055 * @y: return location for the Y coordinate, or %NULL
6057 * Obtains the location of the mouse pointer in widget coordinates.
6058 * Widget coordinates are a bit odd; for historical reasons, they are
6059 * defined as @widget->window coordinates for widgets that are not
6060 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
6061 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
6065 gtk_widget_get_pointer (GtkWidget *widget,
6069 g_return_if_fail (GTK_IS_WIDGET (widget));
6076 if (GTK_WIDGET_REALIZED (widget))
6078 gdk_window_get_pointer (widget->window, x, y, NULL);
6080 if (GTK_WIDGET_NO_WINDOW (widget))
6083 *x -= widget->allocation.x;
6085 *y -= widget->allocation.y;
6091 * gtk_widget_is_ancestor:
6092 * @widget: a #GtkWidget
6093 * @ancestor: another #GtkWidget
6095 * Determines whether @widget is somewhere inside @ancestor, possibly with
6096 * intermediate containers.
6098 * Return value: %TRUE if @ancestor contains @widget as a child, grandchild, great grandchild, etc.
6101 gtk_widget_is_ancestor (GtkWidget *widget,
6102 GtkWidget *ancestor)
6104 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6105 g_return_val_if_fail (ancestor != NULL, FALSE);
6109 if (widget->parent == ancestor)
6111 widget = widget->parent;
6117 static GQuark quark_composite_name = 0;
6120 * gtk_widget_set_composite_name:
6121 * @widget: a #GtkWidget.
6122 * @name: the name to set.
6124 * Sets a widgets composite name. The widget must be
6125 * a composite child of its parent; see gtk_widget_push_composite_child().
6128 gtk_widget_set_composite_name (GtkWidget *widget,
6131 g_return_if_fail (GTK_IS_WIDGET (widget));
6132 g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget));
6133 g_return_if_fail (name != NULL);
6135 if (!quark_composite_name)
6136 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
6138 g_object_set_qdata_full (G_OBJECT (widget),
6139 quark_composite_name,
6145 * gtk_widget_get_composite_name:
6146 * @widget: a #GtkWidget.
6147 * @returns: the composite name of @widget, or %NULL if @widget is not
6148 * a composite child. The string should not be freed when it is no
6151 * Obtains the composite name of a widget.
6154 gtk_widget_get_composite_name (GtkWidget *widget)
6156 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6158 if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent)
6159 return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
6166 * gtk_widget_push_composite_child:
6168 * Makes all newly-created widgets as composite children until
6169 * the corresponding gtk_widget_pop_composite_child() call.
6171 * A composite child is a child that's an implementation detail of the
6172 * container it's inside and should not be visible to people using the
6173 * container. Composite children aren't treated differently by GTK (but
6174 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
6175 * builders might want to treat them in a different way.
6177 * Here is a simple example:
6178 * <informalexample><programlisting>
6179 * gtk_widget_push_composite_child (<!-- -->);
6180 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
6181 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
6182 * gtk_widget_pop_composite_child (<!-- -->);
6183 * gtk_widget_set_parent (scrolled_window->hscrollbar,
6184 * GTK_WIDGET (scrolled_window));
6185 * g_object_ref (scrolled_window->hscrollbar);
6186 * </programlisting></informalexample>
6189 gtk_widget_push_composite_child (void)
6191 composite_child_stack++;
6195 * gtk_widget_pop_composite_child:
6197 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
6200 gtk_widget_pop_composite_child (void)
6202 if (composite_child_stack)
6203 composite_child_stack--;
6207 * gtk_widget_push_colormap:
6208 * @cmap: a #GdkColormap
6210 * Pushes @cmap onto a global stack of colormaps; the topmost
6211 * colormap on the stack will be used to create all widgets.
6212 * Remove @cmap with gtk_widget_pop_colormap(). There's little
6213 * reason to use this function.
6217 gtk_widget_push_colormap (GdkColormap *cmap)
6219 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
6221 colormap_stack = g_slist_prepend (colormap_stack, cmap);
6225 * gtk_widget_pop_colormap:
6227 * Removes a colormap pushed with gtk_widget_push_colormap().
6231 gtk_widget_pop_colormap (void)
6234 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
6238 * gtk_widget_set_default_colormap:
6239 * @colormap: a #GdkColormap
6241 * Sets the default colormap to use when creating widgets.
6242 * gtk_widget_push_colormap() is a better function to use if
6243 * you only want to affect a few widgets, rather than all widgets.
6246 gtk_widget_set_default_colormap (GdkColormap *colormap)
6248 g_return_if_fail (GDK_IS_COLORMAP (colormap));
6250 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
6255 * gtk_widget_get_default_colormap:
6257 * Obtains the default colormap used to create widgets.
6259 * Return value: default widget colormap
6262 gtk_widget_get_default_colormap (void)
6264 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
6268 * gtk_widget_get_default_visual:
6270 * Obtains the visual of the default colormap. Not really useful;
6271 * used to be useful before gdk_colormap_get_visual() existed.
6273 * Return value: visual of the default colormap
6276 gtk_widget_get_default_visual (void)
6278 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
6282 gtk_widget_emit_direction_changed (GtkWidget *widget,
6283 GtkTextDirection old_dir)
6285 PangoContext *context = gtk_widget_peek_pango_context (widget);
6288 pango_context_set_base_dir (context,
6289 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
6290 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
6292 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
6296 * gtk_widget_set_direction:
6297 * @widget: a #GtkWidget
6298 * @dir: the new direction
6300 * Sets the reading direction on a particular widget. This direction
6301 * controls the primary direction for widgets containing text,
6302 * and also the direction in which the children of a container are
6303 * packed. The ability to set the direction is present in order
6304 * so that correct localization into languages with right-to-left
6305 * reading directions can be done. Generally, applications will
6306 * let the default reading direction present, except for containers
6307 * where the containers are arranged in an order that is explicitely
6308 * visual rather than logical (such as buttons for text justification).
6310 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
6311 * set by gtk_widget_set_default_direction() will be used.
6314 gtk_widget_set_direction (GtkWidget *widget,
6315 GtkTextDirection dir)
6317 GtkTextDirection old_dir;
6319 g_return_if_fail (GTK_IS_WIDGET (widget));
6320 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
6322 old_dir = gtk_widget_get_direction (widget);
6324 if (dir == GTK_TEXT_DIR_NONE)
6325 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
6328 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
6329 if (dir == GTK_TEXT_DIR_LTR)
6330 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
6332 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
6335 if (old_dir != gtk_widget_get_direction (widget))
6336 gtk_widget_emit_direction_changed (widget, old_dir);
6340 * gtk_widget_get_direction:
6341 * @widget: a #GtkWidget
6343 * Gets the reading direction for a particular widget. See
6344 * gtk_widget_set_direction().
6346 * Return value: the reading direction for the widget.
6349 gtk_widget_get_direction (GtkWidget *widget)
6351 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
6353 if (GTK_WIDGET_DIRECTION_SET (widget))
6354 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
6356 return gtk_default_direction;
6360 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
6362 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
6364 g_object_ref (widget);
6366 if (!GTK_WIDGET_DIRECTION_SET (widget))
6367 gtk_widget_emit_direction_changed (widget, old_dir);
6369 if (GTK_IS_CONTAINER (widget))
6370 gtk_container_forall (GTK_CONTAINER (widget),
6371 gtk_widget_set_default_direction_recurse,
6374 g_object_unref (widget);
6378 * gtk_widget_set_default_direction:
6379 * @dir: the new default direction. This cannot be
6380 * %GTK_TEXT_DIR_NONE.
6382 * Sets the default reading direction for widgets where the
6383 * direction has not been explicitly set by gtk_widget_set_direction().
6386 gtk_widget_set_default_direction (GtkTextDirection dir)
6388 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
6390 if (dir != gtk_default_direction)
6392 GList *toplevels, *tmp_list;
6393 GtkTextDirection old_dir = gtk_default_direction;
6395 gtk_default_direction = dir;
6397 tmp_list = toplevels = gtk_window_list_toplevels ();
6398 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
6402 gtk_widget_set_default_direction_recurse (tmp_list->data,
6403 GUINT_TO_POINTER (old_dir));
6404 g_object_unref (tmp_list->data);
6405 tmp_list = tmp_list->next;
6408 g_list_free (toplevels);
6413 * gtk_widget_get_default_direction:
6415 * Obtains the current default reading direction. See
6416 * gtk_widget_set_default_direction().
6418 * Return value: the current default direction.
6421 gtk_widget_get_default_direction (void)
6423 return gtk_default_direction;
6427 gtk_widget_dispose (GObject *object)
6429 GtkWidget *widget = GTK_WIDGET (object);
6432 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
6433 else if (GTK_WIDGET_VISIBLE (widget))
6434 gtk_widget_hide (widget);
6436 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
6437 if (GTK_WIDGET_REALIZED (widget))
6438 gtk_widget_unrealize (widget);
6440 G_OBJECT_CLASS (parent_class)->dispose (object);
6444 gtk_widget_real_destroy (GtkObject *object)
6446 /* gtk_object_destroy() will already hold a refcount on object */
6447 GtkWidget *widget = GTK_WIDGET (object);
6449 /* wipe accelerator closures (keep order) */
6450 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
6451 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
6453 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
6454 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
6456 gtk_grab_remove (widget);
6458 g_object_unref (widget->style);
6459 widget->style = gtk_widget_get_default_style ();
6460 g_object_ref (widget->style);
6462 GTK_OBJECT_CLASS (parent_class)->destroy (object);
6466 gtk_widget_finalize (GObject *object)
6468 GtkWidget *widget = GTK_WIDGET (object);
6469 GtkWidgetAuxInfo *aux_info;
6471 GdkExtensionMode *mode;
6472 GtkAccessible *accessible;
6474 gtk_grab_remove (widget);
6476 g_object_unref (widget->style);
6477 widget->style = NULL;
6480 g_free (widget->name);
6482 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
6484 gtk_widget_aux_info_destroy (aux_info);
6486 events = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
6490 mode = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
6494 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
6496 g_object_unref (accessible);
6498 G_OBJECT_CLASS (parent_class)->finalize (object);
6501 /*****************************************
6502 * gtk_widget_real_map:
6507 *****************************************/
6510 gtk_widget_real_map (GtkWidget *widget)
6512 g_return_if_fail (GTK_WIDGET_REALIZED (widget) == TRUE);
6514 if (!GTK_WIDGET_MAPPED (widget))
6516 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
6518 if (!GTK_WIDGET_NO_WINDOW (widget))
6519 gdk_window_show (widget->window);
6523 /*****************************************
6524 * gtk_widget_real_unmap:
6529 *****************************************/
6532 gtk_widget_real_unmap (GtkWidget *widget)
6534 if (GTK_WIDGET_MAPPED (widget))
6536 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
6538 if (!GTK_WIDGET_NO_WINDOW (widget))
6539 gdk_window_hide (widget->window);
6543 /*****************************************
6544 * gtk_widget_real_realize:
6549 *****************************************/
6552 gtk_widget_real_realize (GtkWidget *widget)
6554 g_return_if_fail (GTK_WIDGET_NO_WINDOW (widget));
6556 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
6559 widget->window = gtk_widget_get_parent_window (widget);
6560 g_object_ref (widget->window);
6562 widget->style = gtk_style_attach (widget->style, widget->window);
6565 /*****************************************
6566 * gtk_widget_real_unrealize:
6571 *****************************************/
6574 gtk_widget_real_unrealize (GtkWidget *widget)
6576 if (GTK_WIDGET_MAPPED (widget))
6577 gtk_widget_real_unmap (widget);
6579 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
6581 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
6584 /* We must do unrealize child widget BEFORE container widget.
6585 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
6586 * So, unrealizing container widget bofore its children causes the problem
6587 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
6590 if (GTK_IS_CONTAINER (widget))
6591 gtk_container_forall (GTK_CONTAINER (widget),
6592 (GtkCallback) gtk_widget_unrealize,
6595 gtk_style_detach (widget->style);
6596 if (!GTK_WIDGET_NO_WINDOW (widget))
6598 gdk_window_set_user_data (widget->window, NULL);
6599 gdk_window_destroy (widget->window);
6600 widget->window = NULL;
6604 g_object_unref (widget->window);
6605 widget->window = NULL;
6608 gtk_selection_remove_all (widget);
6610 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
6614 gtk_widget_real_size_request (GtkWidget *widget,
6615 GtkRequisition *requisition)
6617 requisition->width = widget->requisition.width;
6618 requisition->height = widget->requisition.height;
6622 * _gtk_widget_peek_colormap:
6624 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
6626 * Return value: the currently pushed colormap, or %NULL if there is none.
6629 _gtk_widget_peek_colormap (void)
6632 return (GdkColormap*) colormap_stack->data;
6637 gtk_widget_propagate_state (GtkWidget *widget,
6642 /* don't call this function with state==GTK_STATE_INSENSITIVE,
6643 * parent_sensitive==TRUE on a sensitive widget
6646 old_state = GTK_WIDGET_STATE (widget);
6648 if (data->parent_sensitive)
6650 GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
6652 if (GTK_WIDGET_IS_SENSITIVE (widget))
6654 if (data->state_restoration)
6655 GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget);
6657 GTK_WIDGET_STATE (widget) = data->state;
6661 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
6662 if (!data->state_restoration &&
6663 data->state != GTK_STATE_INSENSITIVE)
6664 GTK_WIDGET_SAVED_STATE (widget) = data->state;
6669 GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
6670 if (!data->state_restoration)
6672 if (data->state != GTK_STATE_INSENSITIVE)
6673 GTK_WIDGET_SAVED_STATE (widget) = data->state;
6675 else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
6676 GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget);
6677 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
6680 if (gtk_widget_is_focus (widget) && !GTK_WIDGET_IS_SENSITIVE (widget))
6684 window = gtk_widget_get_toplevel (widget);
6685 if (window && GTK_WIDGET_TOPLEVEL (window))
6686 gtk_window_set_focus (GTK_WINDOW (window), NULL);
6689 if (old_state != GTK_WIDGET_STATE (widget))
6691 g_object_ref (widget);
6693 if (!GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_HAS_GRAB (widget))
6694 gtk_grab_remove (widget);
6696 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
6698 if (GTK_IS_CONTAINER (widget))
6700 data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE);
6701 data->state = GTK_WIDGET_STATE (widget);
6702 if (data->use_forall)
6703 gtk_container_forall (GTK_CONTAINER (widget),
6704 (GtkCallback) gtk_widget_propagate_state,
6707 gtk_container_foreach (GTK_CONTAINER (widget),
6708 (GtkCallback) gtk_widget_propagate_state,
6711 g_object_unref (widget);
6716 * _gtk_widget_get_aux_info:
6717 * @widget: a #GtkWidget
6718 * @create: if %TRUE, create the structure if it doesn't exist
6720 * Get the #GtkWidgetAuxInfo structure for the widget.
6722 * Return value: the #GtkAuxInfo structure for the widget, or
6723 * %NULL if @create is %FALSE and one doesn't already exist.
6726 _gtk_widget_get_aux_info (GtkWidget *widget,
6729 GtkWidgetAuxInfo *aux_info;
6731 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
6732 if (!aux_info && create)
6734 if (!aux_info_mem_chunk)
6735 aux_info_mem_chunk = g_mem_chunk_new ("widget aux info mem chunk",
6736 sizeof (GtkWidgetAuxInfo),
6737 1024, G_ALLOC_AND_FREE);
6738 aux_info = g_chunk_new (GtkWidgetAuxInfo, aux_info_mem_chunk);
6740 aux_info->width = -1;
6741 aux_info->height = -1;
6744 aux_info->x_set = FALSE;
6745 aux_info->y_set = FALSE;
6746 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
6752 /*****************************************
6753 * gtk_widget_aux_info_destroy:
6758 *****************************************/
6761 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
6763 g_mem_chunk_free (aux_info_mem_chunk, aux_info);
6767 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
6769 g_object_unref (info->shape_mask);
6774 * gtk_widget_shape_combine_mask:
6775 * @widget: a #GtkWidget.
6776 * @shape_mask: shape to be added, or %NULL to remove an existing shape.
6777 * @offset_x: X position of shape mask with respect to @window.
6778 * @offset_y: Y position of shape mask with respect to @window.
6780 * Sets a shape for this widget's GDK window. This allows for
6781 * transparent windows etc., see gdk_window_shape_combine_mask()
6782 * for more information.
6785 gtk_widget_shape_combine_mask (GtkWidget *widget,
6786 GdkBitmap *shape_mask,
6790 GtkWidgetShapeInfo* shape_info;
6792 g_return_if_fail (GTK_IS_WIDGET (widget));
6793 /* set_shape doesn't work on widgets without gdk window */
6794 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
6798 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
6801 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
6803 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
6807 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
6809 shape_info = g_new (GtkWidgetShapeInfo, 1);
6810 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
6811 (GDestroyNotify) gtk_widget_shape_info_destroy);
6813 shape_info->shape_mask = g_object_ref (shape_mask);
6814 shape_info->offset_x = offset_x;
6815 shape_info->offset_y = offset_y;
6817 /* set shape if widget has a gdk window allready.
6818 * otherwise the shape is scheduled to be set by gtk_widget_realize.
6821 gdk_window_shape_combine_mask (widget->window, shape_mask,
6822 offset_x, offset_y);
6827 gtk_reset_shapes_recurse (GtkWidget *widget,
6833 gdk_window_get_user_data (window, &data);
6837 gdk_window_shape_combine_mask (window, NULL, 0, 0);
6838 for (list = gdk_window_peek_children (window); list; list = list->next)
6839 gtk_reset_shapes_recurse (widget, list->data);
6843 * gtk_widget_reset_shapes:
6844 * @widget: a #GtkWidget.
6846 * Recursively resets the shape on this widget and its descendants.
6849 gtk_widget_reset_shapes (GtkWidget *widget)
6851 g_return_if_fail (GTK_IS_WIDGET (widget));
6852 g_return_if_fail (GTK_WIDGET_REALIZED (widget));
6854 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
6855 gtk_reset_shapes_recurse (widget, widget->window);
6860 * @widget: a #GtkWidget
6862 * Adds a reference to a widget. This function is exactly the same
6863 * as calling g_object_ref(), and exists mostly for historical
6864 * reasons. It can still be convenient to avoid casting a widget
6865 * to a #GObject, it saves a small amount of typing.
6867 * Return value: the widget that was referenced
6870 gtk_widget_ref (GtkWidget *widget)
6872 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6874 return (GtkWidget*) g_object_ref ((GObject*) widget);
6879 * @widget: a #GtkWidget
6881 * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
6885 gtk_widget_unref (GtkWidget *widget)
6887 g_return_if_fail (GTK_IS_WIDGET (widget));
6889 g_object_unref ((GObject*) widget);
6897 * gtk_widget_class_install_style_property_parser:
6898 * @klass: a #GtkWidgetClass
6899 * @pspec: the #GParamSpec for the style property
6900 * @parser: the parser for the style property
6902 * Installs a style property on a widget class.
6905 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
6907 GtkRcPropertyParser parser)
6909 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
6910 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
6911 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
6912 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
6914 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
6916 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
6917 G_OBJECT_CLASS_NAME (klass),
6922 g_param_spec_ref (pspec);
6923 g_param_spec_sink (pspec);
6924 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
6925 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
6929 * gtk_widget_class_install_style_property:
6930 * @klass: a #GtkWidgetClass
6931 * @pspec: the #GParamSpec for the property
6933 * Installs a style property on a widget class. The parser for the
6934 * style property is determined by the value type of @pspec.
6937 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
6940 GtkRcPropertyParser parser;
6942 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
6943 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
6945 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
6947 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
6951 * gtk_widget_class_find_style_property:
6952 * @klass: a #GtkWidgetClass
6953 * @property_name: the name of the style property to find
6954 * @returns: the #GParamSpec of the style property or %NULL if @class has no
6955 * style property with that name.
6957 * Finds a style property of a widget class by name.
6962 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
6963 const gchar *property_name)
6965 g_return_val_if_fail (property_name != NULL, NULL);
6967 return g_param_spec_pool_lookup (style_property_spec_pool,
6969 G_OBJECT_CLASS_TYPE (klass),
6974 * gtk_widget_class_list_style_properties:
6975 * @klass: a #GtkWidgetClass
6976 * @n_properties: location to return the number of style properties found
6977 * @returns: an newly allocated array of #GParamSpec*. The array must be freed with g_free().
6979 * Returns all style properties of a widget class.
6984 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
6985 guint *n_properties)
6987 GParamSpec **pspecs;
6990 pspecs = g_param_spec_pool_list (style_property_spec_pool,
6991 G_OBJECT_CLASS_TYPE (klass),
7000 * gtk_widget_style_get_property:
7001 * @widget: a #GtkWidget
7002 * @property_name: the name of a style property
7003 * @value: location to return the property value
7005 * Gets the value of a style property of @widget.
7008 gtk_widget_style_get_property (GtkWidget *widget,
7009 const gchar *property_name,
7014 g_return_if_fail (GTK_IS_WIDGET (widget));
7015 g_return_if_fail (property_name != NULL);
7016 g_return_if_fail (G_IS_VALUE (value));
7018 g_object_ref (widget);
7019 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
7021 G_OBJECT_TYPE (widget),
7024 g_warning ("%s: widget class `%s' has no property named `%s'",
7026 G_OBJECT_TYPE_NAME (widget),
7030 const GValue *peek_value;
7032 peek_value = _gtk_style_peek_property_value (widget->style,
7033 G_OBJECT_TYPE (widget),
7035 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
7037 /* auto-conversion of the caller's value type
7039 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
7040 g_value_copy (peek_value, value);
7041 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
7042 g_value_transform (peek_value, value);
7044 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
7046 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
7047 G_VALUE_TYPE_NAME (value));
7049 g_object_unref (widget);
7053 * gtk_widget_style_get_valist:
7054 * @widget: a #GtkWidget
7055 * @first_property_name: the name of the first property to get
7056 * @var_args: a <type>va_list</type> of pairs of property names and
7057 * locations to return the property values, starting with the location
7058 * for @first_property_name.
7060 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
7064 gtk_widget_style_get_valist (GtkWidget *widget,
7065 const gchar *first_property_name,
7070 g_return_if_fail (GTK_IS_WIDGET (widget));
7072 g_object_ref (widget);
7074 name = first_property_name;
7077 const GValue *peek_value;
7081 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
7083 G_OBJECT_TYPE (widget),
7087 g_warning ("%s: widget class `%s' has no property named `%s'",
7089 G_OBJECT_TYPE_NAME (widget),
7093 /* style pspecs are always readable so we can spare that check here */
7095 peek_value = _gtk_style_peek_property_value (widget->style,
7096 G_OBJECT_TYPE (widget),
7098 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
7099 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
7102 g_warning ("%s: %s", G_STRLOC, error);
7107 name = va_arg (var_args, gchar*);
7110 g_object_unref (widget);
7114 * gtk_widget_style_get:
7115 * @widget: a #GtkWidget
7116 * @first_property_name: the name of the first property to get
7117 * @Varargs: pairs of property names and locations to
7118 * return the property values, starting with the location for
7119 * @first_property_name, terminated by %NULL.
7121 * Gets the values of a multiple style properties of @widget.
7124 gtk_widget_style_get (GtkWidget *widget,
7125 const gchar *first_property_name,
7130 g_return_if_fail (GTK_IS_WIDGET (widget));
7132 va_start (var_args, first_property_name);
7133 gtk_widget_style_get_valist (widget, first_property_name, var_args);
7139 * @widget: a #GtkWidget
7140 * @path_length: location to store length of the path, or %NULL
7141 * @path: location to store allocated path string, or %NULL
7142 * @path_reversed: location to store allocated reverse path string, or %NULL
7144 * Obtains the full path to @widget. The path is simply the name of a
7145 * widget and all its parents in the container hierarchy, separated by
7146 * periods. The name of a widget comes from
7147 * gtk_widget_get_name(). Paths are used to apply styles to a widget
7148 * in gtkrc configuration files. Widget names are the type of the
7149 * widget by default (e.g. "GtkButton") or can be set to an
7150 * application-specific value with gtk_widget_set_name(). By setting
7151 * the name of a widget, you allow users or theme authors to apply
7152 * styles to that specific widget in their gtkrc
7153 * file. @path_reversed_p fills in the path in reverse order,
7154 * i.e. starting with @widget's name instead of starting with the name
7155 * of @widget's outermost ancestor.
7159 gtk_widget_path (GtkWidget *widget,
7162 gchar **path_reversed)
7164 static gchar *rev_path = NULL;
7165 static guint tmp_path_len = 0;
7168 g_return_if_fail (GTK_IS_WIDGET (widget));
7173 const gchar *string;
7178 string = gtk_widget_get_name (widget);
7179 l = strlen (string);
7180 while (tmp_path_len <= len + l + 1)
7182 tmp_path_len += INIT_PATH_SIZE;
7183 rev_path = g_realloc (rev_path, tmp_path_len);
7191 widget = widget->parent;
7194 rev_path[len++] = '.';
7196 rev_path[len++] = 0;
7201 *path_length = len - 1;
7203 *path_reversed = g_strdup (rev_path);
7206 *path = g_strdup (rev_path);
7207 g_strreverse (*path);
7212 * gtk_widget_class_path:
7213 * @widget: a #GtkWidget
7214 * @path_length: location to store the length of the class path, or %NULL
7215 * @path: location to store the class path as an allocated string, or %NULL
7216 * @path_reversed: location to store the reverse class path as an allocated string, or %NULL
7218 * Same as gtk_widget_path(), but always uses the name of a widget's type,
7219 * never uses a custom name set with gtk_widget_set_name().
7223 gtk_widget_class_path (GtkWidget *widget,
7226 gchar **path_reversed)
7228 static gchar *rev_path = NULL;
7229 static guint tmp_path_len = 0;
7232 g_return_if_fail (GTK_IS_WIDGET (widget));
7237 const gchar *string;
7242 string = g_type_name (GTK_WIDGET_TYPE (widget));
7243 l = strlen (string);
7244 while (tmp_path_len <= len + l + 1)
7246 tmp_path_len += INIT_PATH_SIZE;
7247 rev_path = g_realloc (rev_path, tmp_path_len);
7255 widget = widget->parent;
7258 rev_path[len++] = '.';
7260 rev_path[len++] = 0;
7265 *path_length = len - 1;
7267 *path_reversed = g_strdup (rev_path);
7270 *path = g_strdup (rev_path);
7271 g_strreverse (*path);
7276 * gtk_requisition_copy:
7277 * @requisition: a #GtkRequisition.
7278 * @returns: a copy of @requisition.
7280 * Copies a #GtkRequisition.
7283 gtk_requisition_copy (const GtkRequisition *requisition)
7285 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
7289 * gtk_requisition_free:
7290 * @requisition: a #GtkRequisition.
7292 * Frees a #GtkRequisition.
7295 gtk_requisition_free (GtkRequisition *requisition)
7297 g_free (requisition);
7301 gtk_requisition_get_type (void)
7303 static GType our_type = 0;
7306 our_type = g_boxed_type_register_static ("GtkRequisition",
7307 (GBoxedCopyFunc) gtk_requisition_copy,
7308 (GBoxedFreeFunc) gtk_requisition_free);
7314 gtk_widget_get_accessible (GtkWidget *widget)
7316 GtkWidgetClass *klass;
7318 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7320 klass = GTK_WIDGET_GET_CLASS (widget);
7322 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
7324 return klass->get_accessible (widget);
7328 gtk_widget_real_get_accessible (GtkWidget *widget)
7330 AtkObject* accessible;
7332 accessible = g_object_get_qdata (G_OBJECT (widget),
7333 quark_accessible_object);
7336 AtkObjectFactory *factory;
7337 AtkRegistry *default_registry;
7339 default_registry = atk_get_default_registry ();
7340 factory = atk_registry_get_factory (default_registry,
7341 G_TYPE_FROM_INSTANCE (widget));
7343 atk_object_factory_create_accessible (factory,
7345 g_object_set_qdata (G_OBJECT (widget),
7346 quark_accessible_object,
7353 * Initialize a AtkImplementorIface instance's virtual pointers as
7354 * appropriate to this implementor's class (GtkWidget).
7357 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
7359 iface->ref_accessible = gtk_widget_ref_accessible;
7363 gtk_widget_ref_accessible (AtkImplementor *implementor)
7365 AtkObject *accessible;
7367 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
7369 g_object_ref (accessible);
7374 * gtk_widget_get_clipboard:
7375 * @widget: a #GtkWidget
7376 * @selection: a #GdkAtom which identifies the clipboard
7377 * to use. %GDK_SELECTION_CLIPBOARD gives the
7378 * default clipboard. Another common value
7379 * is %GDK_SELECTION_PRIMARY, which gives
7380 * the primary X selection.
7382 * Returns the clipboard object for the given selection to
7383 * be used with @widget. @widget must have a #GdkDisplay
7384 * associated with it, so must be attached to a toplevel
7387 * Return value: the appropriate clipboard object. If no
7388 * clipboard already exists, a new one will
7389 * be created. Once a clipboard object has
7390 * been created, it is persistent for all time.
7395 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
7397 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7398 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
7400 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
7405 * gtk_widget_list_mnemonic_labels:
7406 * @widget: a #GtkWidget
7408 * Returns a newly allocated list of the widgets, normally labels, for
7409 * which this widget is a the target of a mnemonic (see for example,
7410 * gtk_label_set_mnemonic_widget()).
7412 * The widgets in the list are not individually referenced. If you
7413 * want to iterate through the list and perform actions involving
7414 * callbacks that might destroy the widgets, you
7415 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
7416 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
7417 * widgets afterwards.
7419 * Return value: the list of mnemonic labels; free this list
7420 * with g_list_free() when you are done with it.
7425 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
7430 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7432 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
7433 list = g_list_prepend (list, l->data);
7439 * gtk_widget_add_mnemonic_label:
7440 * @widget: a #GtkWidget
7441 * @label: a #GtkWidget that acts as a mnemonic label for @widget.
7443 * Adds a widget to the list of mnemonic labels for
7444 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
7445 * list of mnemonic labels for the widget is cleared when the
7446 * widget is destroyed, so the caller must make sure to update
7447 * it's internal state at this point as well, by using a connection
7448 * to the ::destroy signal or a weak notifier.
7453 gtk_widget_add_mnemonic_label (GtkWidget *widget,
7456 GSList *old_list, *new_list;
7458 g_return_if_fail (GTK_IS_WIDGET (widget));
7459 g_return_if_fail (GTK_IS_WIDGET (label));
7461 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
7462 new_list = g_slist_prepend (old_list, label);
7464 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
7465 new_list, (GDestroyNotify) g_slist_free);
7469 * gtk_widget_remove_mnemonic_label:
7470 * @widget: a #GtkWidget
7471 * @label: a #GtkWidget that was previously set as a mnemnic label for
7472 * @widget with gtk_widget_add_mnemonic_label().
7474 * Removes a widget from the list of mnemonic labels for
7475 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
7476 * must have previously been added to the list with
7477 * gtk_widget_add_mnemonic_label().
7482 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
7485 GSList *old_list, *new_list;
7487 g_return_if_fail (GTK_IS_WIDGET (widget));
7488 g_return_if_fail (GTK_IS_WIDGET (label));
7490 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
7491 new_list = g_slist_remove (old_list, label);
7494 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
7495 new_list, (GDestroyNotify) g_slist_free);
7499 * gtk_widget_get_no_show_all:
7500 * @widget: a #GtkWidget
7502 * Returns the current value of the "no_show_all" property, which determines
7503 * whether calls to gtk_widget_show_all() and gtk_widget_hide_all()
7504 * will affect this widget.
7506 * Return value: the current value of the "no_show_all" property.
7511 gtk_widget_get_no_show_all (GtkWidget *widget)
7513 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7515 return (GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
7519 * gtk_widget_set_no_show_all:
7520 * @widget: a #GtkWidget
7521 * @no_show_all: the new value for the "no_show_all" property
7523 * Sets the "no_show_all" property, which determines whether calls to
7524 * gtk_widget_show_all() and gtk_widget_hide_all() will affect this widget.
7526 * This is mostly for use in constructing widget hierarchies with externally
7527 * controlled visibility, see #GtkUIManager.
7532 gtk_widget_set_no_show_all (GtkWidget *widget,
7533 gboolean no_show_all)
7535 g_return_if_fail (GTK_IS_WIDGET (widget));
7537 no_show_all = (no_show_all != FALSE);
7539 if (no_show_all == ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0))
7543 GTK_WIDGET_SET_FLAGS (widget, GTK_NO_SHOW_ALL);
7545 GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_SHOW_ALL);
7547 g_object_notify (G_OBJECT (widget), "no_show_all");