1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include "gtkcontainer.h"
32 #include "gtkaccelmap.h"
33 #include "gtkclipboard.h"
34 #include "gtkiconfactory.h"
37 #include "gtkmarshalers.h"
39 #include "gtkselection.h"
40 #include "gtksettings.h"
41 #include "gtksizegroup.h"
42 #include "gtkwidget.h"
43 #include "gtkwindow.h"
44 #include "gtkbindings.h"
45 #include "gtkprivate.h"
47 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
48 #include <gobject/gvaluecollector.h>
49 #include <gobject/gobjectnotifyqueue.c>
50 #include "gdk/gdkkeysyms.h"
52 #include "gtkaccessible.h"
53 #include "gtktooltips.h"
54 #include "gtkinvisible.h"
57 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
58 #define INIT_PATH_SIZE (512)
98 PROPERTY_NOTIFY_EVENT,
99 SELECTION_CLEAR_EVENT,
100 SELECTION_REQUEST_EVENT,
101 SELECTION_NOTIFY_EVENT,
116 VISIBILITY_NOTIFY_EVENT,
120 ACCEL_CLOSURES_CHANGED,
140 PROP_RECEIVES_DEFAULT,
141 PROP_COMPOSITE_CHILD,
144 PROP_EXTENSION_EVENTS,
148 typedef struct _GtkStateData GtkStateData;
153 guint state_restoration : 1;
154 guint parent_sensitive : 1;
155 guint use_forall : 1;
159 /* --- prototypes --- */
160 static void gtk_widget_class_init (GtkWidgetClass *klass);
161 static void gtk_widget_init (GtkWidget *widget);
162 static void gtk_widget_set_property (GObject *object,
166 static void gtk_widget_get_property (GObject *object,
170 static void gtk_widget_dispose (GObject *object);
171 static void gtk_widget_real_destroy (GtkObject *object);
172 static void gtk_widget_finalize (GObject *object);
173 static void gtk_widget_real_show (GtkWidget *widget);
174 static void gtk_widget_real_hide (GtkWidget *widget);
175 static void gtk_widget_real_map (GtkWidget *widget);
176 static void gtk_widget_real_unmap (GtkWidget *widget);
177 static void gtk_widget_real_realize (GtkWidget *widget);
178 static void gtk_widget_real_unrealize (GtkWidget *widget);
179 static void gtk_widget_real_size_request (GtkWidget *widget,
180 GtkRequisition *requisition);
181 static void gtk_widget_real_size_allocate (GtkWidget *widget,
182 GtkAllocation *allocation);
183 static void gtk_widget_style_set (GtkWidget *widget,
184 GtkStyle *previous_style);
185 static void gtk_widget_direction_changed (GtkWidget *widget,
186 GtkTextDirection previous_direction);
188 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
189 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
190 GtkWidgetHelpType help_type);
192 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
194 GParamSpec **pspecs);
195 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
197 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
199 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
200 GdkEventFocus *event);
201 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
202 GdkEventFocus *event);
203 static gboolean gtk_widget_real_focus (GtkWidget *widget,
204 GtkDirectionType direction);
205 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
206 static void gtk_widget_propagate_state (GtkWidget *widget,
208 static void gtk_widget_reset_rc_style (GtkWidget *widget);
209 static void gtk_widget_set_style_internal (GtkWidget *widget,
211 gboolean initial_emission);
212 static gint gtk_widget_event_internal (GtkWidget *widget,
214 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
215 gboolean group_cycling);
216 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
217 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
218 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
219 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
220 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
222 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
223 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
224 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
227 static void gtk_widget_set_usize_internal (GtkWidget *widget,
230 static void gtk_widget_get_draw_rectangle (GtkWidget *widget,
234 /* --- variables --- */
235 static gpointer parent_class = NULL;
236 static guint widget_signals[LAST_SIGNAL] = { 0 };
237 static GMemChunk *aux_info_mem_chunk = NULL;
238 static GtkStyle *gtk_default_style = NULL;
239 static GSList *colormap_stack = NULL;
240 static guint composite_child_stack = 0;
241 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
242 static GParamSpecPool *style_property_spec_pool = NULL;
244 static GQuark quark_property_parser = 0;
245 static GQuark quark_aux_info = 0;
246 static GQuark quark_accel_path = 0;
247 static GQuark quark_accel_closures = 0;
248 static GQuark quark_event_mask = 0;
249 static GQuark quark_extension_event_mode = 0;
250 static GQuark quark_parent_window = 0;
251 static GQuark quark_shape_info = 0;
252 static GQuark quark_colormap = 0;
253 static GQuark quark_pango_context = 0;
254 static GQuark quark_rc_style = 0;
255 static GQuark quark_accessible_object = 0;
256 static GQuark quark_mnemonic_labels = 0;
257 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
258 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
260 /* --- functions --- */
262 gtk_widget_get_type (void)
264 static GType widget_type = 0;
268 static const GTypeInfo widget_info =
270 sizeof (GtkWidgetClass),
271 NULL, /* base_init */
272 NULL, /* base_finalize */
273 (GClassInitFunc) gtk_widget_class_init,
274 NULL, /* class_finalize */
275 NULL, /* class_init */
278 (GInstanceInitFunc) gtk_widget_init,
279 NULL, /* value_table */
282 static const GInterfaceInfo accessibility_info =
284 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
285 (GInterfaceFinalizeFunc) NULL,
286 NULL /* interface data */
289 widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
290 &widget_info, G_TYPE_FLAG_ABSTRACT);
292 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
293 &accessibility_info) ;
301 child_property_notify_dispatcher (GObject *object,
305 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
309 gtk_widget_class_init (GtkWidgetClass *klass)
311 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
312 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
313 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
314 GtkBindingSet *binding_set;
316 parent_class = g_type_class_peek_parent (klass);
318 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
319 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
320 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
321 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
322 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
323 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
324 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
325 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
326 quark_colormap = g_quark_from_static_string ("gtk-colormap");
327 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
328 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
329 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
330 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
332 style_property_spec_pool = g_param_spec_pool_new (FALSE);
333 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
334 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
335 cpn_context.dispatcher = child_property_notify_dispatcher;
336 _gtk_widget_child_property_notify_context = &cpn_context;
338 gobject_class->dispose = gtk_widget_dispose;
339 gobject_class->finalize = gtk_widget_finalize;
340 gobject_class->set_property = gtk_widget_set_property;
341 gobject_class->get_property = gtk_widget_get_property;
343 object_class->destroy = gtk_widget_real_destroy;
345 klass->activate_signal = 0;
346 klass->set_scroll_adjustments_signal = 0;
347 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
348 klass->show = gtk_widget_real_show;
349 klass->show_all = gtk_widget_show;
350 klass->hide = gtk_widget_real_hide;
351 klass->hide_all = gtk_widget_hide;
352 klass->map = gtk_widget_real_map;
353 klass->unmap = gtk_widget_real_unmap;
354 klass->realize = gtk_widget_real_realize;
355 klass->unrealize = gtk_widget_real_unrealize;
356 klass->size_request = gtk_widget_real_size_request;
357 klass->size_allocate = gtk_widget_real_size_allocate;
358 klass->state_changed = NULL;
359 klass->parent_set = NULL;
360 klass->hierarchy_changed = NULL;
361 klass->style_set = gtk_widget_style_set;
362 klass->direction_changed = gtk_widget_direction_changed;
363 klass->grab_notify = NULL;
364 klass->child_notify = NULL;
365 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
366 klass->grab_focus = gtk_widget_real_grab_focus;
367 klass->focus = gtk_widget_real_focus;
369 klass->button_press_event = NULL;
370 klass->button_release_event = NULL;
371 klass->motion_notify_event = NULL;
372 klass->delete_event = NULL;
373 klass->destroy_event = NULL;
374 klass->expose_event = NULL;
375 klass->key_press_event = gtk_widget_real_key_press_event;
376 klass->key_release_event = gtk_widget_real_key_release_event;
377 klass->enter_notify_event = NULL;
378 klass->leave_notify_event = NULL;
379 klass->configure_event = NULL;
380 klass->focus_in_event = gtk_widget_real_focus_in_event;
381 klass->focus_out_event = gtk_widget_real_focus_out_event;
382 klass->map_event = NULL;
383 klass->unmap_event = NULL;
384 klass->window_state_event = NULL;
385 klass->property_notify_event = _gtk_selection_property_notify;
386 klass->selection_clear_event = gtk_selection_clear;
387 klass->selection_request_event = _gtk_selection_request;
388 klass->selection_notify_event = _gtk_selection_notify;
389 klass->selection_received = NULL;
390 klass->proximity_in_event = NULL;
391 klass->proximity_out_event = NULL;
392 klass->drag_begin = NULL;
393 klass->drag_end = NULL;
394 klass->drag_data_delete = NULL;
395 klass->drag_leave = NULL;
396 klass->drag_motion = NULL;
397 klass->drag_drop = NULL;
398 klass->drag_data_received = NULL;
399 klass->screen_changed = NULL;
400 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
402 klass->show_help = gtk_widget_real_show_help;
404 /* Accessibility support */
405 klass->get_accessible = gtk_widget_real_get_accessible;
407 klass->no_expose_event = NULL;
409 g_object_class_install_property (gobject_class,
411 g_param_spec_string ("name",
413 P_("The name of the widget"),
415 GTK_PARAM_READWRITE));
416 g_object_class_install_property (gobject_class,
418 g_param_spec_object ("parent",
420 P_("The parent widget of this widget. Must be a Container widget"),
422 GTK_PARAM_READWRITE));
424 g_object_class_install_property (gobject_class,
426 g_param_spec_int ("width-request",
428 P_("Override for width request of the widget, or -1 if natural request should be used"),
432 GTK_PARAM_READWRITE));
433 g_object_class_install_property (gobject_class,
435 g_param_spec_int ("height-request",
436 P_("Height request"),
437 P_("Override for height request of the widget, or -1 if natural request should be used"),
441 GTK_PARAM_READWRITE));
442 g_object_class_install_property (gobject_class,
444 g_param_spec_boolean ("visible",
446 P_("Whether the widget is visible"),
448 GTK_PARAM_READWRITE));
449 g_object_class_install_property (gobject_class,
451 g_param_spec_boolean ("sensitive",
453 P_("Whether the widget responds to input"),
455 GTK_PARAM_READWRITE));
456 g_object_class_install_property (gobject_class,
458 g_param_spec_boolean ("app-paintable",
459 P_("Application paintable"),
460 P_("Whether the application will paint directly on the widget"),
462 GTK_PARAM_READWRITE));
463 g_object_class_install_property (gobject_class,
465 g_param_spec_boolean ("can-focus",
467 P_("Whether the widget can accept the input focus"),
469 GTK_PARAM_READWRITE));
470 g_object_class_install_property (gobject_class,
472 g_param_spec_boolean ("has-focus",
474 P_("Whether the widget has the input focus"),
476 GTK_PARAM_READWRITE));
477 g_object_class_install_property (gobject_class,
479 g_param_spec_boolean ("is-focus",
481 P_("Whether the widget is the focus widget within the toplevel"),
483 GTK_PARAM_READWRITE));
484 g_object_class_install_property (gobject_class,
486 g_param_spec_boolean ("can-default",
488 P_("Whether the widget can be the default widget"),
490 GTK_PARAM_READWRITE));
491 g_object_class_install_property (gobject_class,
493 g_param_spec_boolean ("has-default",
495 P_("Whether the widget is the default widget"),
497 GTK_PARAM_READWRITE));
498 g_object_class_install_property (gobject_class,
499 PROP_RECEIVES_DEFAULT,
500 g_param_spec_boolean ("receives-default",
501 P_("Receives default"),
502 P_("If TRUE, the widget will receive the default action when it is focused"),
504 GTK_PARAM_READWRITE));
505 g_object_class_install_property (gobject_class,
506 PROP_COMPOSITE_CHILD,
507 g_param_spec_boolean ("composite-child",
508 P_("Composite child"),
509 P_("Whether the widget is part of a composite widget"),
511 GTK_PARAM_READABLE));
512 g_object_class_install_property (gobject_class,
514 g_param_spec_object ("style",
516 P_("The style of the widget, which contains information about how it will look (colors etc)"),
518 GTK_PARAM_READWRITE));
519 g_object_class_install_property (gobject_class,
521 g_param_spec_flags ("events",
523 P_("The event mask that decides what kind of GdkEvents this widget gets"),
526 GTK_PARAM_READWRITE));
527 g_object_class_install_property (gobject_class,
528 PROP_EXTENSION_EVENTS,
529 g_param_spec_enum ("extension-events",
530 P_("Extension events"),
531 P_("The mask that decides what kind of extension events this widget gets"),
532 GDK_TYPE_EXTENSION_MODE,
533 GDK_EXTENSION_EVENTS_NONE,
534 GTK_PARAM_READWRITE));
535 g_object_class_install_property (gobject_class,
537 g_param_spec_boolean ("no-show-all",
539 P_("Whether gtk_widget_show_all() should not affect this widget"),
541 GTK_PARAM_READWRITE));
542 widget_signals[SHOW] =
543 g_signal_new ("show",
544 G_TYPE_FROM_CLASS (gobject_class),
546 G_STRUCT_OFFSET (GtkWidgetClass, show),
548 _gtk_marshal_VOID__VOID,
550 widget_signals[HIDE] =
551 g_signal_new ("hide",
552 G_TYPE_FROM_CLASS (gobject_class),
554 G_STRUCT_OFFSET (GtkWidgetClass, hide),
556 _gtk_marshal_VOID__VOID,
558 widget_signals[MAP] =
560 G_TYPE_FROM_CLASS (gobject_class),
562 G_STRUCT_OFFSET (GtkWidgetClass, map),
564 _gtk_marshal_VOID__VOID,
566 widget_signals[UNMAP] =
567 g_signal_new ("unmap",
568 G_TYPE_FROM_CLASS (gobject_class),
570 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
572 _gtk_marshal_VOID__VOID,
574 widget_signals[REALIZE] =
575 g_signal_new ("realize",
576 G_TYPE_FROM_CLASS (gobject_class),
578 G_STRUCT_OFFSET (GtkWidgetClass, realize),
580 _gtk_marshal_VOID__VOID,
582 widget_signals[UNREALIZE] =
583 g_signal_new ("unrealize",
584 G_TYPE_FROM_CLASS (gobject_class),
586 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
588 _gtk_marshal_VOID__VOID,
590 widget_signals[SIZE_REQUEST] =
591 g_signal_new ("size_request",
592 G_TYPE_FROM_CLASS (gobject_class),
594 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
596 _gtk_marshal_VOID__BOXED,
598 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
599 widget_signals[SIZE_ALLOCATE] =
600 g_signal_new ("size_allocate",
601 G_TYPE_FROM_CLASS (gobject_class),
603 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
605 _gtk_marshal_VOID__BOXED,
607 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
608 widget_signals[STATE_CHANGED] =
609 g_signal_new ("state_changed",
610 G_TYPE_FROM_CLASS (gobject_class),
612 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
614 _gtk_marshal_VOID__ENUM,
616 GTK_TYPE_STATE_TYPE);
617 widget_signals[PARENT_SET] =
618 g_signal_new ("parent_set",
619 G_TYPE_FROM_CLASS (gobject_class),
621 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
623 _gtk_marshal_VOID__OBJECT,
626 widget_signals[HIERARCHY_CHANGED] =
627 g_signal_new ("hierarchy_changed",
628 G_TYPE_FROM_CLASS (gobject_class),
630 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
632 _gtk_marshal_VOID__OBJECT,
636 * GtkWidget::style-set:
637 * @widget: the object on which the signal is emitted
638 * @previous_style: the previous style, or %NULL if the widget
639 * just got its initial style
641 * The style-set signal is emitted when a new style has been set
642 * on a widget. Note that style-modifying functions like
643 * gtk_widget_modify_base() also cause this signal to be emitted.
645 widget_signals[STYLE_SET] =
646 g_signal_new ("style_set",
647 G_TYPE_FROM_CLASS (gobject_class),
649 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
651 _gtk_marshal_VOID__OBJECT,
654 widget_signals[DIRECTION_CHANGED] =
655 g_signal_new ("direction_changed",
656 G_TYPE_FROM_CLASS (gobject_class),
658 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
660 _gtk_marshal_VOID__ENUM,
662 GTK_TYPE_TEXT_DIRECTION);
663 widget_signals[GRAB_NOTIFY] =
664 g_signal_new ("grab_notify",
665 G_TYPE_FROM_CLASS (gobject_class),
667 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
669 _gtk_marshal_VOID__BOOLEAN,
674 * GtkWidget::child-notify:
675 * @widget: the object which received the signal.
676 * @pspec: the #GParamSpec of the changed child property.
678 * The ::child-notify signal is emitted for each child property that has
679 * changed on an object. The signal's detail holds the property name.
681 widget_signals[CHILD_NOTIFY] =
682 g_signal_new ("child_notify",
683 G_TYPE_FROM_CLASS (gobject_class),
684 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
685 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
687 g_cclosure_marshal_VOID__PARAM,
690 widget_signals[MNEMONIC_ACTIVATE] =
691 g_signal_new ("mnemonic_activate",
692 G_TYPE_FROM_CLASS (gobject_class),
694 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
695 _gtk_boolean_handled_accumulator, NULL,
696 _gtk_marshal_BOOLEAN__BOOLEAN,
699 widget_signals[GRAB_FOCUS] =
700 g_signal_new ("grab_focus",
701 G_TYPE_FROM_CLASS (gobject_class),
702 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
703 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
705 _gtk_marshal_VOID__VOID,
707 widget_signals[FOCUS] =
708 g_signal_new ("focus",
709 G_TYPE_FROM_CLASS (object_class),
711 G_STRUCT_OFFSET (GtkWidgetClass, focus),
712 _gtk_boolean_handled_accumulator, NULL,
713 _gtk_marshal_BOOLEAN__ENUM,
715 GTK_TYPE_DIRECTION_TYPE);
716 widget_signals[EVENT] =
717 g_signal_new ("event",
718 G_TYPE_FROM_CLASS (gobject_class),
720 G_STRUCT_OFFSET (GtkWidgetClass, event),
721 _gtk_boolean_handled_accumulator, NULL,
722 _gtk_marshal_BOOLEAN__BOXED,
724 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
725 widget_signals[EVENT_AFTER] =
726 g_signal_new ("event-after",
727 G_TYPE_FROM_CLASS (gobject_class),
731 _gtk_marshal_VOID__BOXED,
733 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
734 widget_signals[BUTTON_PRESS_EVENT] =
735 g_signal_new ("button_press_event",
736 G_TYPE_FROM_CLASS (gobject_class),
738 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
739 _gtk_boolean_handled_accumulator, NULL,
740 _gtk_marshal_BOOLEAN__BOXED,
742 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
743 widget_signals[BUTTON_RELEASE_EVENT] =
744 g_signal_new ("button_release_event",
745 G_TYPE_FROM_CLASS (gobject_class),
747 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
748 _gtk_boolean_handled_accumulator, NULL,
749 _gtk_marshal_BOOLEAN__BOXED,
751 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
752 widget_signals[SCROLL_EVENT] =
753 g_signal_new ("scroll_event",
754 G_TYPE_FROM_CLASS (gobject_class),
756 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
757 _gtk_boolean_handled_accumulator, NULL,
758 _gtk_marshal_BOOLEAN__BOXED,
760 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
761 widget_signals[MOTION_NOTIFY_EVENT] =
762 g_signal_new ("motion_notify_event",
763 G_TYPE_FROM_CLASS (gobject_class),
765 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
766 _gtk_boolean_handled_accumulator, NULL,
767 _gtk_marshal_BOOLEAN__BOXED,
769 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
772 * GtkWidget::delete-event:
773 * @widget: the object which received the signal.
774 * @event: the event which triggered this signal
776 * The ::delete-event signal is emitted if a user requests that
777 * a toplevel window is closed. The default handler for this signal
778 * destroys the window. Connecting gtk_widget_hide_on_delete() to
779 * this signal will cause the window to be hidden instead, so that
780 * it can later be shown again without reconstructing it.
782 * Returns: %TRUE to stop other handlers from being invoked for the event.
783 * %FALSE to propagate the event further.
785 widget_signals[DELETE_EVENT] =
786 g_signal_new ("delete_event",
787 G_TYPE_FROM_CLASS (gobject_class),
789 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
790 _gtk_boolean_handled_accumulator, NULL,
791 _gtk_marshal_BOOLEAN__BOXED,
793 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
796 * GtkWidget::destroy-event:
797 * @widget: the object which received the signal.
798 * @event: the event which triggered this signal
800 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
801 * You rarely get this signal, because most widgets disconnect themselves
802 * from their window before they destroy it, so no widget owns the
803 * window at destroy time.
805 * Returns: %TRUE to stop other handlers from being invoked for the event.
806 * %FALSE to propagate the event further.
808 widget_signals[DESTROY_EVENT] =
809 g_signal_new ("destroy_event",
810 G_TYPE_FROM_CLASS (gobject_class),
812 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
813 _gtk_boolean_handled_accumulator, NULL,
814 _gtk_marshal_BOOLEAN__BOXED,
816 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
817 widget_signals[EXPOSE_EVENT] =
818 g_signal_new ("expose_event",
819 G_TYPE_FROM_CLASS (gobject_class),
821 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
822 _gtk_boolean_handled_accumulator, NULL,
823 _gtk_marshal_BOOLEAN__BOXED,
825 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
826 widget_signals[KEY_PRESS_EVENT] =
827 g_signal_new ("key_press_event",
828 G_TYPE_FROM_CLASS (gobject_class),
830 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
831 _gtk_boolean_handled_accumulator, NULL,
832 _gtk_marshal_BOOLEAN__BOXED,
834 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
835 widget_signals[KEY_RELEASE_EVENT] =
836 g_signal_new ("key_release_event",
837 G_TYPE_FROM_CLASS (gobject_class),
839 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
840 _gtk_boolean_handled_accumulator, NULL,
841 _gtk_marshal_BOOLEAN__BOXED,
843 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
844 widget_signals[ENTER_NOTIFY_EVENT] =
845 g_signal_new ("enter_notify_event",
846 G_TYPE_FROM_CLASS (gobject_class),
848 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
849 _gtk_boolean_handled_accumulator, NULL,
850 _gtk_marshal_BOOLEAN__BOXED,
852 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
853 widget_signals[LEAVE_NOTIFY_EVENT] =
854 g_signal_new ("leave_notify_event",
855 G_TYPE_FROM_CLASS (gobject_class),
857 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
858 _gtk_boolean_handled_accumulator, NULL,
859 _gtk_marshal_BOOLEAN__BOXED,
861 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
862 widget_signals[CONFIGURE_EVENT] =
863 g_signal_new ("configure_event",
864 G_TYPE_FROM_CLASS (gobject_class),
866 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
867 _gtk_boolean_handled_accumulator, NULL,
868 _gtk_marshal_BOOLEAN__BOXED,
870 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
871 widget_signals[FOCUS_IN_EVENT] =
872 g_signal_new ("focus_in_event",
873 G_TYPE_FROM_CLASS (gobject_class),
875 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
876 _gtk_boolean_handled_accumulator, NULL,
877 _gtk_marshal_BOOLEAN__BOXED,
879 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
880 widget_signals[FOCUS_OUT_EVENT] =
881 g_signal_new ("focus_out_event",
882 G_TYPE_FROM_CLASS (gobject_class),
884 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
885 _gtk_boolean_handled_accumulator, NULL,
886 _gtk_marshal_BOOLEAN__BOXED,
888 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
889 widget_signals[MAP_EVENT] =
890 g_signal_new ("map_event",
891 G_TYPE_FROM_CLASS (gobject_class),
893 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
894 _gtk_boolean_handled_accumulator, NULL,
895 _gtk_marshal_BOOLEAN__BOXED,
897 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
898 widget_signals[UNMAP_EVENT] =
899 g_signal_new ("unmap_event",
900 G_TYPE_FROM_CLASS (gobject_class),
902 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
903 _gtk_boolean_handled_accumulator, NULL,
904 _gtk_marshal_BOOLEAN__BOXED,
906 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
907 widget_signals[PROPERTY_NOTIFY_EVENT] =
908 g_signal_new ("property_notify_event",
909 G_TYPE_FROM_CLASS (gobject_class),
911 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
912 _gtk_boolean_handled_accumulator, NULL,
913 _gtk_marshal_BOOLEAN__BOXED,
915 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
916 widget_signals[SELECTION_CLEAR_EVENT] =
917 g_signal_new ("selection_clear_event",
918 G_TYPE_FROM_CLASS (gobject_class),
920 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
921 _gtk_boolean_handled_accumulator, NULL,
922 _gtk_marshal_BOOLEAN__BOXED,
924 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
925 widget_signals[SELECTION_REQUEST_EVENT] =
926 g_signal_new ("selection_request_event",
927 G_TYPE_FROM_CLASS (gobject_class),
929 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
930 _gtk_boolean_handled_accumulator, NULL,
931 _gtk_marshal_BOOLEAN__BOXED,
933 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
934 widget_signals[SELECTION_NOTIFY_EVENT] =
935 g_signal_new ("selection_notify_event",
936 G_TYPE_FROM_CLASS (gobject_class),
938 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
939 _gtk_boolean_handled_accumulator, NULL,
940 _gtk_marshal_BOOLEAN__BOXED,
942 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
943 widget_signals[SELECTION_RECEIVED] =
944 g_signal_new ("selection_received",
945 G_TYPE_FROM_CLASS (gobject_class),
947 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
949 _gtk_marshal_VOID__BOXED_UINT,
951 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
953 widget_signals[SELECTION_GET] =
954 g_signal_new ("selection_get",
955 G_TYPE_FROM_CLASS (gobject_class),
957 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
959 _gtk_marshal_VOID__BOXED_UINT_UINT,
961 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
964 widget_signals[PROXIMITY_IN_EVENT] =
965 g_signal_new ("proximity_in_event",
966 G_TYPE_FROM_CLASS (gobject_class),
968 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
969 _gtk_boolean_handled_accumulator, NULL,
970 _gtk_marshal_BOOLEAN__BOXED,
972 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
973 widget_signals[PROXIMITY_OUT_EVENT] =
974 g_signal_new ("proximity_out_event",
975 G_TYPE_FROM_CLASS (gobject_class),
977 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
978 _gtk_boolean_handled_accumulator, NULL,
979 _gtk_marshal_BOOLEAN__BOXED,
981 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
984 * GtkWidget::drag-leave:
985 * @widget: the object which received the signal.
986 * @drag_context: the drag context
987 * @time: the timestamp of the motion event
989 * The ::drag-leave signal is emitted on the drop site when the cursor leaves the widget.
990 * A typical reason to connect to this signal is to undo things done in ::drag-motion, e.g.
991 * undo highlighting with gtk_drag_unhighlight()
993 widget_signals[DRAG_LEAVE] =
994 g_signal_new ("drag_leave",
995 G_TYPE_FROM_CLASS (gobject_class),
997 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
999 _gtk_marshal_VOID__OBJECT_UINT,
1001 GDK_TYPE_DRAG_CONTEXT,
1005 * GtkWidget::drag-begin:
1006 * @widget: the object which received the signal.
1007 * @drag_context: the drag context
1009 * The ::drag-begin signal is emitted on the drag source when a drag is started.
1010 * A typical reason to connect to this signal is to set up a custom drag icon with
1011 * gtk_drag_source_set_icon().
1013 widget_signals[DRAG_BEGIN] =
1014 g_signal_new ("drag_begin",
1015 G_TYPE_FROM_CLASS (gobject_class),
1017 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
1019 _gtk_marshal_VOID__OBJECT,
1021 GDK_TYPE_DRAG_CONTEXT);
1024 * GtkWidget::drag-end:
1025 * @widget: the object which received the signal.
1026 * @drag_context: the drag context
1028 * The ::drag-end signal is emitted on the drag source when a drag is finished.
1029 * A typical reason to connect to this signal is to undo things done in ::drag-begin.
1031 widget_signals[DRAG_END] =
1032 g_signal_new ("drag_end",
1033 G_TYPE_FROM_CLASS (gobject_class),
1035 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
1037 _gtk_marshal_VOID__OBJECT,
1039 GDK_TYPE_DRAG_CONTEXT);
1042 * GtkWidget::drag-data-delete:
1043 * @widget: the object which received the signal.
1044 * @drag_context: the drag context
1046 * The ::drag-data-delete signal is emitted on the drag source when a drag with the action
1047 * %GDK_ACTION_MOVE is successfully completed. The signal handler is responsible for deleting
1048 * the data that has been dropped. What "delete" means, depends on the context of the drag
1051 widget_signals[DRAG_DATA_DELETE] =
1052 g_signal_new ("drag_data_delete",
1053 G_TYPE_FROM_CLASS (gobject_class),
1055 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
1057 _gtk_marshal_VOID__OBJECT,
1059 GDK_TYPE_DRAG_CONTEXT);
1062 * GtkWidget::drag-motion:
1063 * @widget: the object which received the signal.
1064 * @drag_context: the drag context
1065 * @x: the x coordinate of the current cursor position
1066 * @y: the y coordinate of the current cursor position
1067 * @time: the timestamp of the motion event
1068 * @returns: whether the cursor position is in a drop zone
1070 * The ::drag-motion signal is emitted on the drop site when the user moves the cursor over
1071 * the widget during a drag. The signal handler must determine whether the cursor position is in
1072 * a drop zone or not. If it is not in a drop zone, it returns %FALSE and no further processing is
1073 * necessary. Otherwise, the handler returns %TRUE. In this case, the handler is responsible for
1074 * providing the necessary information for displaying feedback to the user, by calling
1075 * gdk_drag_status(). If the decision whether the drop will be accepted or rejected can't be made
1076 * based solely on the cursor position and the type of the data, the handler may inspect the dragged
1077 * data by calling gtk_drag_get_data() and defer the gdk_drag_status() call to the ::drag-data-received
1080 * Note that there is no ::drag-enter signal. The drag receiver has to keep track of whether
1081 * he has received any ::drag-motion signals since the last ::drag-leave and if not, treat the
1082 * ::drag-motion signal as an "enter" signal. Upon an "enter", the handler will typically highlight
1083 * the drop site with gtk_drag_highlight().
1085 * <informalexample><programlisting>
1087 * drag_motion (GtkWidget *widget,
1088 * GdkDragContext *context,
1095 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1097 * if (!private_data->drag_highlight)
1099 * private_data->drag_highlight = 1;
1100 * gtk_drag_highlight (widget);
1103 * target = gtk_drag_dest_find_target (widget, context, NULL);
1104 * if (target == GDK_NONE)
1105 * gdk_drag_status (context, 0, time);
1108 * private_data->pending_status = context->suggested_action;
1109 * gtk_drag_get_data (widget, context, target, time);
1116 * drag_data_received (GtkWidget *widget,
1117 * GdkDragContext *context,
1120 * GtkSelectionData *selection_data,
1124 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1126 * if (private_data->suggested_action)
1128 * private_data->suggested_action = 0;
1130 * /<!-- -->* We are getting this data due to a request in drag_motion,
1131 * * rather than due to a request in drag_drop, so we are just
1132 * * supposed to call gdk_drag_status(<!-- -->), not actually paste in the data.
1134 * str = gtk_selection_data_get_text (selection_data);
1135 * if (!data_is_acceptable (str))
1136 * gdk_drag_status (context, 0, time);
1138 * gdk_drag_status (context, private_data->suggested_action, time);
1142 * /<!-- -->* accept the drop *<!-- -->/
1145 * </programlisting></informalexample>
1147 widget_signals[DRAG_MOTION] =
1148 g_signal_new ("drag_motion",
1149 G_TYPE_FROM_CLASS (gobject_class),
1151 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
1152 _gtk_boolean_handled_accumulator, NULL,
1153 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1155 GDK_TYPE_DRAG_CONTEXT,
1161 * GtkWidget::drag-drop:
1162 * @widget: the object which received the signal.
1163 * @drag_context: the drag context
1164 * @x: the x coordinate of the current cursor position
1165 * @y: the y coordinate of the current cursor position
1166 * @time: the timestamp of the motion event
1167 * @returns: whether the cursor position is in a drop zone
1169 * The ::drag-drop signal is emitted on the drop site when the user drops the data
1170 * onto the widget. The signal handler must determine whether the cursor position is in
1171 * a drop zone or not. If it is not in a drop zone, it returns %FALSE and no further
1172 * processing is necessary. Otherwise, the handler returns %TRUE. In this case, the handler
1173 * must ensure that gtk_drag_finish() is called to let the source know that the drop is done.
1174 * The call to gtk_drag_finish() can be done either directly or in a ::drag-data-received handler
1175 * which gets triggered by calling gtk_drop_get_data() to receive the data for one or more of the
1176 * supported targets.
1178 widget_signals[DRAG_DROP] =
1179 g_signal_new ("drag_drop",
1180 G_TYPE_FROM_CLASS (gobject_class),
1182 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
1183 _gtk_boolean_handled_accumulator, NULL,
1184 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1186 GDK_TYPE_DRAG_CONTEXT,
1192 * GtkWidget::drag-data-get:
1193 * @widget: the object which received the signal.
1194 * @drag_context: the drag context
1195 * @data: the #GtkSelectionData to be filled with the dragged data
1196 * @info: the info that has been registered with the target in the #GtkTargetList.
1197 * @time: the timestamp at which the data was requested
1199 * The ::drag-data-get signal is emitted on the drag source when the drop site requests
1200 * the data which is dragged. It is the responsibility of the signal handler to fill @data
1201 * with the data in the format which is indicated by @info. See gtk_selection_data_set() and
1202 * gtk_selection_data_set_text().
1204 widget_signals[DRAG_DATA_GET] =
1205 g_signal_new ("drag_data_get",
1206 G_TYPE_FROM_CLASS (gobject_class),
1208 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
1210 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
1212 GDK_TYPE_DRAG_CONTEXT,
1213 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1218 * GtkWidget::drag-data-received:
1219 * @widget: the object which received the signal.
1220 * @drag_context: the drag context
1221 * @x: where the drop happened
1222 * @y: where the drop happened
1223 * @data: the received data
1224 * @info: the info that has been registered with the target in the #GtkTargetList.
1225 * @time: the timestamp at which the data was received
1227 * The ::drag-data-received signal is emitted on the drop site when the dragged data has been
1228 * received. If the data was received in order to determine whether the drop will be accepted,
1229 * the handler is expected to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
1230 * If the data was received in response to a ::drag-drop signal (and this is the last target to be
1231 * received), the handler for this signal is expected to process the received data and then call
1232 * gtk_drag_finish(), setting the @success parameter depending on whether the data was processed
1235 * The handler may inspect and modify @drag_context->action before calling gtk_drag_finish(),
1236 * e.g. to implement %GDK_ACTION_ASK as shown in the following example:
1237 * <informalexample><programlisting>
1239 * drag_data_received (GtkWidget *widget,
1240 * GdkDragContext *drag_context,
1243 * GtkSelectionData *data,
1247 * if ((data->length >= 0) && (data->format == 8))
1249 * if (drag_context->action == GDK_ACTION_ASK)
1251 * GtkWidget *dialog;
1254 * dialog = gtk_message_dialog_new (NULL,
1255 * GTK_DIALOG_MODAL |
1256 * GTK_DIALOG_DESTROY_WITH_PARENT,
1258 * GTK_BUTTONS_YES_NO,
1259 * "Move the data ?\n");
1260 * response = gtk_dialog_run (GTK_DIALOG (dialog));
1261 * gtk_widget_destroy (dialog);
1263 * if (response == GTK_RESPONSE_YES)
1264 * drag_context->action = GDK_ACTION_MOVE;
1266 * drag_context->action = GDK_ACTION_COPY;
1269 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
1273 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
1275 * </programlisting></informalexample>
1277 widget_signals[DRAG_DATA_RECEIVED] =
1278 g_signal_new ("drag_data_received",
1279 G_TYPE_FROM_CLASS (gobject_class),
1281 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
1283 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
1285 GDK_TYPE_DRAG_CONTEXT,
1288 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1291 widget_signals[VISIBILITY_NOTIFY_EVENT] =
1292 g_signal_new ("visibility_notify_event",
1293 G_TYPE_FROM_CLASS (gobject_class),
1295 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
1296 _gtk_boolean_handled_accumulator, NULL,
1297 _gtk_marshal_BOOLEAN__BOXED,
1299 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1300 widget_signals[CLIENT_EVENT] =
1301 g_signal_new ("client_event",
1302 G_TYPE_FROM_CLASS (gobject_class),
1304 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
1305 _gtk_boolean_handled_accumulator, NULL,
1306 _gtk_marshal_BOOLEAN__BOXED,
1308 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1309 widget_signals[NO_EXPOSE_EVENT] =
1310 g_signal_new ("no_expose_event",
1311 G_TYPE_FROM_CLASS (gobject_class),
1313 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
1314 _gtk_boolean_handled_accumulator, NULL,
1315 _gtk_marshal_BOOLEAN__BOXED,
1317 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1318 widget_signals[WINDOW_STATE_EVENT] =
1319 g_signal_new ("window_state_event",
1320 G_TYPE_FROM_CLASS (gobject_class),
1322 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
1323 _gtk_boolean_handled_accumulator, NULL,
1324 _gtk_marshal_BOOLEAN__BOXED,
1326 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1328 * GtkWidget::popup-menu
1329 * @widget: the object which received the signal
1330 * @returns: TRUE if a menu was activated
1332 * This signal gets emitted whenever a widget should pop up a context-sensitive
1333 * menu. This usually happens through the standard key binding mechanism; by
1334 * pressing a certain key while a widget is focused, the user can cause the
1335 * widget to pop up a menu. For example, the #GtkEntry widget creates a menu
1336 * with clipboard commands. See <xref linkend="checklist-popup-menu"/> for an
1337 * example of how to use this signal.
1339 widget_signals[POPUP_MENU] =
1340 g_signal_new ("popup_menu",
1341 G_TYPE_FROM_CLASS (gobject_class),
1342 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1343 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
1344 _gtk_boolean_handled_accumulator, NULL,
1345 _gtk_marshal_BOOLEAN__VOID,
1347 widget_signals[SHOW_HELP] =
1348 g_signal_new ("show_help",
1349 G_TYPE_FROM_CLASS (gobject_class),
1350 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1351 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
1352 _gtk_boolean_handled_accumulator, NULL,
1353 _gtk_marshal_BOOLEAN__ENUM,
1355 GTK_TYPE_WIDGET_HELP_TYPE);
1356 widget_signals[ACCEL_CLOSURES_CHANGED] =
1357 g_signal_new ("accel_closures_changed",
1358 G_TYPE_FROM_CLASS (gobject_class),
1362 _gtk_marshal_NONE__NONE,
1364 widget_signals[SCREEN_CHANGED] =
1365 g_signal_new ("screen_changed",
1366 G_TYPE_FROM_CLASS (gobject_class),
1368 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
1370 _gtk_marshal_VOID__OBJECT,
1374 * GtkWidget::can-activate-accel:
1375 * @widget: the object which received the signal
1376 * @signal_id: the ID of a signal installed on @widget
1377 * @returns: %TRUE if the signal can be activated.
1379 * Determines whether an accelerator that activates the signal
1380 * identified by @signal_id can currently be activated.
1381 * This signal is present to allow applications and derived
1382 * widgets to override the default #GtkWidget handling
1383 * for determining whether an accelerator can be activated.
1385 widget_signals[CAN_ACTIVATE_ACCEL] =
1386 g_signal_new ("can_activate_accel",
1387 G_TYPE_FROM_CLASS (gobject_class),
1389 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
1390 _gtk_boolean_handled_accumulator, NULL,
1391 _gtk_marshal_BOOLEAN__UINT,
1392 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
1394 binding_set = gtk_binding_set_by_class (klass);
1395 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
1397 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
1400 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
1402 GTK_TYPE_WIDGET_HELP_TYPE,
1403 GTK_WIDGET_HELP_TOOLTIP);
1404 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
1406 GTK_TYPE_WIDGET_HELP_TYPE,
1407 GTK_WIDGET_HELP_TOOLTIP);
1408 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
1410 GTK_TYPE_WIDGET_HELP_TYPE,
1411 GTK_WIDGET_HELP_WHATS_THIS);
1412 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
1414 GTK_TYPE_WIDGET_HELP_TYPE,
1415 GTK_WIDGET_HELP_WHATS_THIS);
1417 gtk_widget_class_install_style_property (klass,
1418 g_param_spec_boolean ("interior-focus",
1419 P_("Interior Focus"),
1420 P_("Whether to draw the focus indicator inside widgets"),
1422 GTK_PARAM_READABLE));
1424 gtk_widget_class_install_style_property (klass,
1425 g_param_spec_int ("focus-line-width",
1426 P_("Focus linewidth"),
1427 P_("Width, in pixels, of the focus indicator line"),
1429 GTK_PARAM_READABLE));
1431 gtk_widget_class_install_style_property (klass,
1432 g_param_spec_string ("focus-line-pattern",
1433 P_("Focus line dash pattern"),
1434 P_("Dash pattern used to draw the focus indicator"),
1436 GTK_PARAM_READABLE));
1437 gtk_widget_class_install_style_property (klass,
1438 g_param_spec_int ("focus-padding",
1439 P_("Focus padding"),
1440 P_("Width, in pixels, between focus indicator and the widget 'box'"),
1442 GTK_PARAM_READABLE));
1443 gtk_widget_class_install_style_property (klass,
1444 g_param_spec_boxed ("cursor-color",
1446 P_("Color with which to draw insertion cursor"),
1448 GTK_PARAM_READABLE));
1449 gtk_widget_class_install_style_property (klass,
1450 g_param_spec_boxed ("secondary-cursor-color",
1451 P_("Secondary cursor color"),
1452 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
1454 GTK_PARAM_READABLE));
1455 gtk_widget_class_install_style_property (klass,
1456 g_param_spec_float ("cursor-aspect-ratio",
1457 P_("Cursor line aspect ratio"),
1458 P_("Aspect ratio with which to draw insertion cursor"),
1460 GTK_PARAM_READABLE));
1461 gtk_widget_class_install_style_property (klass,
1462 g_param_spec_boxed ("draw-border",
1464 P_("Size of areas outside the widget's allocation to draw"),
1466 GTK_PARAM_READABLE));
1470 gtk_widget_set_property (GObject *object,
1472 const GValue *value,
1475 GtkWidget *widget = GTK_WIDGET (object);
1479 guint32 saved_flags;
1482 gtk_widget_set_name (widget, g_value_get_string (value));
1485 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
1487 case PROP_WIDTH_REQUEST:
1488 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
1490 case PROP_HEIGHT_REQUEST:
1491 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
1494 if (g_value_get_boolean (value))
1495 gtk_widget_show (widget);
1497 gtk_widget_hide (widget);
1499 case PROP_SENSITIVE:
1500 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
1502 case PROP_APP_PAINTABLE:
1503 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
1505 case PROP_CAN_FOCUS:
1506 saved_flags = GTK_WIDGET_FLAGS (widget);
1507 if (g_value_get_boolean (value))
1508 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
1510 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
1511 if (saved_flags != GTK_WIDGET_FLAGS (widget))
1512 gtk_widget_queue_resize (widget);
1514 case PROP_HAS_FOCUS:
1515 if (g_value_get_boolean (value))
1516 gtk_widget_grab_focus (widget);
1519 if (g_value_get_boolean (value))
1520 gtk_widget_grab_focus (widget);
1522 case PROP_CAN_DEFAULT:
1523 saved_flags = GTK_WIDGET_FLAGS (widget);
1524 if (g_value_get_boolean (value))
1525 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
1527 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT);
1528 if (saved_flags != GTK_WIDGET_FLAGS (widget))
1529 gtk_widget_queue_resize (widget);
1531 case PROP_HAS_DEFAULT:
1532 if (g_value_get_boolean (value))
1533 gtk_widget_grab_default (widget);
1535 case PROP_RECEIVES_DEFAULT:
1536 if (g_value_get_boolean (value))
1537 GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1539 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1542 gtk_widget_set_style (widget, g_value_get_object (value));
1545 if (!GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget))
1546 gtk_widget_set_events (widget, g_value_get_flags (value));
1548 case PROP_EXTENSION_EVENTS:
1549 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
1551 case PROP_NO_SHOW_ALL:
1552 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
1560 gtk_widget_get_property (GObject *object,
1565 GtkWidget *widget = GTK_WIDGET (object);
1570 GdkExtensionMode *modep;
1574 g_value_set_string (value, widget->name);
1576 g_value_set_string (value, "");
1580 g_value_set_object (value, widget->parent);
1582 g_value_set_object (value, NULL);
1584 case PROP_WIDTH_REQUEST:
1587 gtk_widget_get_size_request (widget, &w, NULL);
1588 g_value_set_int (value, w);
1591 case PROP_HEIGHT_REQUEST:
1594 gtk_widget_get_size_request (widget, NULL, &h);
1595 g_value_set_int (value, h);
1599 g_value_set_boolean (value, (GTK_WIDGET_VISIBLE (widget) != FALSE));
1601 case PROP_SENSITIVE:
1602 g_value_set_boolean (value, (GTK_WIDGET_SENSITIVE (widget) != FALSE));
1604 case PROP_APP_PAINTABLE:
1605 g_value_set_boolean (value, (GTK_WIDGET_APP_PAINTABLE (widget) != FALSE));
1607 case PROP_CAN_FOCUS:
1608 g_value_set_boolean (value, (GTK_WIDGET_CAN_FOCUS (widget) != FALSE));
1610 case PROP_HAS_FOCUS:
1611 g_value_set_boolean (value, (GTK_WIDGET_HAS_FOCUS (widget) != FALSE));
1614 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
1616 case PROP_CAN_DEFAULT:
1617 g_value_set_boolean (value, (GTK_WIDGET_CAN_DEFAULT (widget) != FALSE));
1619 case PROP_HAS_DEFAULT:
1620 g_value_set_boolean (value, (GTK_WIDGET_HAS_DEFAULT (widget) != FALSE));
1622 case PROP_RECEIVES_DEFAULT:
1623 g_value_set_boolean (value, (GTK_WIDGET_RECEIVES_DEFAULT (widget) != FALSE));
1625 case PROP_COMPOSITE_CHILD:
1626 g_value_set_boolean (value, (GTK_WIDGET_COMPOSITE_CHILD (widget) != FALSE));
1629 g_value_set_object (value, gtk_widget_get_style (widget));
1632 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
1634 g_value_set_flags (value, 0);
1636 g_value_set_flags (value, *eventp);
1638 case PROP_EXTENSION_EVENTS:
1639 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
1641 g_value_set_enum (value, 0);
1643 g_value_set_enum (value, (GdkExtensionMode) *modep);
1645 case PROP_NO_SHOW_ALL:
1646 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
1649 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1655 gtk_widget_init (GtkWidget *widget)
1657 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
1658 widget->state = GTK_STATE_NORMAL;
1659 widget->saved_state = GTK_STATE_NORMAL;
1660 widget->name = NULL;
1661 widget->requisition.width = 0;
1662 widget->requisition.height = 0;
1663 widget->allocation.x = -1;
1664 widget->allocation.y = -1;
1665 widget->allocation.width = 1;
1666 widget->allocation.height = 1;
1667 widget->window = NULL;
1668 widget->parent = NULL;
1670 GTK_WIDGET_SET_FLAGS (widget,
1672 GTK_PARENT_SENSITIVE |
1673 (composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
1674 GTK_DOUBLE_BUFFERED);
1676 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
1677 GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
1678 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
1680 widget->style = gtk_widget_get_default_style ();
1681 g_object_ref (widget->style);
1686 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
1688 GParamSpec **pspecs)
1690 GtkWidget *container = widget->parent;
1693 for (i = 0; widget->parent == container && i < n_pspecs; i++)
1694 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
1698 * gtk_widget_freeze_child_notify:
1699 * @widget: a #GtkWidget
1701 * Stops emission of "child-notify" signals on @widget. The signals are
1702 * queued until gtk_widget_thaw_child_notify() is called on @widget.
1704 * This is the analogue of g_object_freeze_notify() for child properties.
1707 gtk_widget_freeze_child_notify (GtkWidget *widget)
1709 g_return_if_fail (GTK_IS_WIDGET (widget));
1711 if (!G_OBJECT (widget)->ref_count)
1714 g_object_ref (widget);
1715 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1716 g_object_unref (widget);
1720 * gtk_widget_child_notify:
1721 * @widget: a #GtkWidget
1722 * @child_property: the name of a child property installed on the
1723 * class of @widget<!-- -->'s parent.
1725 * Emits a "child-notify" signal for the
1726 * <link linkend="child-properties">child property</link> @child_property
1729 * This is the analogue of g_object_notify() for child properties.
1732 gtk_widget_child_notify (GtkWidget *widget,
1733 const gchar *child_property)
1737 g_return_if_fail (GTK_IS_WIDGET (widget));
1738 g_return_if_fail (child_property != NULL);
1739 if (!G_OBJECT (widget)->ref_count || !widget->parent)
1742 g_object_ref (widget);
1743 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
1745 G_OBJECT_TYPE (widget->parent),
1748 g_warning ("%s: container class `%s' has no child property named `%s'",
1750 G_OBJECT_TYPE_NAME (widget->parent),
1754 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1756 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
1757 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1759 g_object_unref (widget);
1763 * gtk_widget_thaw_child_notify:
1764 * @widget: a #GtkWidget
1766 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
1767 * This causes all queued "child-notify" signals on @widget to be emitted.
1770 gtk_widget_thaw_child_notify (GtkWidget *widget)
1772 GObjectNotifyQueue *nqueue;
1774 g_return_if_fail (GTK_IS_WIDGET (widget));
1776 if (!G_OBJECT (widget)->ref_count)
1779 g_object_ref (widget);
1780 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1781 if (!nqueue || !nqueue->freeze_count)
1782 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
1783 G_OBJECT_TYPE_NAME (widget), widget);
1785 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1786 g_object_unref (widget);
1792 * @type: type ID of the widget to create
1793 * @first_property_name: name of first property to set
1794 * @Varargs: value of first property, followed by more properties, %NULL-terminated
1796 * This is a convenience function for creating a widget and setting
1797 * its properties in one go. For example you might write:
1798 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
1799 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
1800 * g_object_new(), but returns a widget so you don't have to
1801 * cast the object yourself.
1803 * Return value: a new #GtkWidget of type @widget_type
1806 gtk_widget_new (GType type,
1807 const gchar *first_property_name,
1813 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
1815 va_start (var_args, first_property_name);
1816 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
1824 * @widget: a #GtkWidget
1825 * @first_property_name: name of first property to set
1826 * @Varargs: value of first property, followed by more properties, %NULL-terminated
1828 * Like g_object_set() - there's no reason to use this instead of
1832 gtk_widget_set (GtkWidget *widget,
1833 const gchar *first_property_name,
1838 g_return_if_fail (GTK_IS_WIDGET (widget));
1840 va_start (var_args, first_property_name);
1841 g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
1846 gtk_widget_queue_draw_child (GtkWidget *widget)
1850 parent = widget->parent;
1851 if (parent && GTK_WIDGET_DRAWABLE (parent))
1852 gtk_widget_queue_draw_area (parent,
1853 widget->allocation.x,
1854 widget->allocation.y,
1855 widget->allocation.width,
1856 widget->allocation.height);
1860 * gtk_widget_unparent:
1861 * @widget: a #GtkWidget
1863 * This function is only for use in widget implementations.
1864 * Should be called by implementations of the remove method
1865 * on #GtkContainer, to dissociate a child from the container.
1868 gtk_widget_unparent (GtkWidget *widget)
1870 GObjectNotifyQueue *nqueue;
1871 GtkWidget *toplevel;
1872 GtkWidget *old_parent;
1874 g_return_if_fail (GTK_IS_WIDGET (widget));
1875 if (widget->parent == NULL)
1878 /* keep this function in sync with gtk_menu_detach()
1881 g_object_freeze_notify (G_OBJECT (widget));
1882 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1884 toplevel = gtk_widget_get_toplevel (widget);
1885 if (GTK_WIDGET_TOPLEVEL (toplevel))
1886 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
1888 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
1889 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
1891 /* If we are unanchoring the child, we save around the toplevel
1892 * to emit hierarchy changed
1894 if (GTK_WIDGET_ANCHORED (widget->parent))
1895 g_object_ref (toplevel);
1899 gtk_widget_queue_draw_child (widget);
1901 /* Reset the width and height here, to force reallocation if we
1902 * get added back to a new parent. This won't work if our new
1903 * allocation is smaller than 1x1 and we actually want a size of 1x1...
1904 * (would 0x0 be OK here?)
1906 widget->allocation.width = 1;
1907 widget->allocation.height = 1;
1909 if (GTK_WIDGET_REALIZED (widget))
1911 if (GTK_WIDGET_IN_REPARENT (widget))
1912 gtk_widget_unmap (widget);
1914 gtk_widget_unrealize (widget);
1917 /* Removing a widget from a container restores the child visible
1918 * flag to the default state, so it doesn't affect the child
1919 * in the next parent.
1921 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
1923 old_parent = widget->parent;
1924 widget->parent = NULL;
1925 gtk_widget_set_parent_window (widget, NULL);
1926 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
1929 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
1930 g_object_unref (toplevel);
1933 g_object_notify (G_OBJECT (widget), "parent");
1934 g_object_thaw_notify (G_OBJECT (widget));
1935 if (!widget->parent)
1936 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
1937 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1938 g_object_unref (widget);
1942 * gtk_widget_destroy:
1943 * @widget: a #GtkWidget
1945 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
1946 * you don't have to cast the widget to #GtkObject. When a widget is
1947 * destroyed, it will break any references it holds to other objects.
1948 * If the widget is inside a container, the widget will be removed
1949 * from the container. If the widget is a toplevel (derived from
1950 * #GtkWindow), it will be removed from the list of toplevels, and the
1951 * reference GTK+ holds to it will be removed. Removing a
1952 * widget from its container or the list of toplevels results in the
1953 * widget being finalized, unless you've added additional references
1954 * to the widget with g_object_ref().
1956 * In most cases, only toplevel widgets (windows) require explicit
1957 * destruction, because when you destroy a toplevel its children will
1958 * be destroyed as well.
1962 gtk_widget_destroy (GtkWidget *widget)
1964 g_return_if_fail (GTK_IS_WIDGET (widget));
1966 gtk_object_destroy ((GtkObject*) widget);
1970 * gtk_widget_destroyed:
1971 * @widget: a #GtkWidget
1972 * @widget_pointer: address of a variable that contains @widget
1974 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
1975 * %NULL. It's intended to be used as a callback connected to the
1976 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
1977 * as a signal handler, and pass the address of your widget variable
1978 * as user data. Then when the widget is destroyed, the variable will
1979 * be set to %NULL. Useful for example to avoid multiple copies
1980 * of the same dialog.
1984 gtk_widget_destroyed (GtkWidget *widget,
1985 GtkWidget **widget_pointer)
1987 /* Don't make any assumptions about the
1989 * Even check widget_pointer.
1992 *widget_pointer = NULL;
1997 * @widget: a #GtkWidget
1999 * Flags a widget to be displayed. Any widget that isn't shown will
2000 * not appear on the screen. If you want to show all the widgets in a
2001 * container, it's easier to call gtk_widget_show_all() on the
2002 * container, instead of individually showing the widgets.
2004 * Remember that you have to show the containers containing a widget,
2005 * in addition to the widget itself, before it will appear onscreen.
2007 * When a toplevel container is shown, it is immediately realized and
2008 * mapped; other shown widgets are realized and mapped when their
2009 * toplevel container is realized and mapped.
2013 gtk_widget_show (GtkWidget *widget)
2015 if (!GTK_WIDGET_VISIBLE (widget))
2017 g_object_ref (widget);
2018 if (!GTK_WIDGET_TOPLEVEL (widget))
2019 gtk_widget_queue_resize (widget);
2020 g_signal_emit (widget, widget_signals[SHOW], 0);
2021 g_object_notify (G_OBJECT (widget), "visible");
2022 g_object_unref (widget);
2027 gtk_widget_real_show (GtkWidget *widget)
2029 if (!GTK_WIDGET_VISIBLE (widget))
2031 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
2033 if (widget->parent &&
2034 GTK_WIDGET_MAPPED (widget->parent) &&
2035 GTK_WIDGET_CHILD_VISIBLE (widget) &&
2036 !GTK_WIDGET_MAPPED (widget))
2037 gtk_widget_map (widget);
2042 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
2045 g_signal_handlers_disconnect_by_func (widget,
2046 gtk_widget_show_map_callback,
2051 * gtk_widget_show_now:
2052 * @widget: a #GtkWidget
2054 * Shows a widget. If the widget is an unmapped toplevel widget
2055 * (i.e. a #GtkWindow that has not yet been shown), enter the main
2056 * loop and wait for the window to actually be mapped. Be careful;
2057 * because the main loop is running, anything can happen during
2061 gtk_widget_show_now (GtkWidget *widget)
2065 g_return_if_fail (GTK_IS_WIDGET (widget));
2067 /* make sure we will get event */
2068 if (!GTK_WIDGET_MAPPED (widget) &&
2069 GTK_WIDGET_TOPLEVEL (widget))
2071 gtk_widget_show (widget);
2073 g_signal_connect (widget, "map_event",
2074 G_CALLBACK (gtk_widget_show_map_callback),
2078 gtk_main_iteration ();
2081 gtk_widget_show (widget);
2086 * @widget: a #GtkWidget
2088 * Reverses the effects of gtk_widget_show(), causing the widget to be
2089 * hidden (invisible to the user).
2092 gtk_widget_hide (GtkWidget *widget)
2094 g_return_if_fail (GTK_IS_WIDGET (widget));
2096 if (GTK_WIDGET_VISIBLE (widget))
2098 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
2100 g_object_ref (widget);
2101 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
2102 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
2104 g_signal_emit (widget, widget_signals[HIDE], 0);
2105 if (!GTK_WIDGET_TOPLEVEL (widget))
2106 gtk_widget_queue_resize (widget);
2107 g_object_notify (G_OBJECT (widget), "visible");
2108 g_object_unref (widget);
2113 gtk_widget_real_hide (GtkWidget *widget)
2115 if (GTK_WIDGET_VISIBLE (widget))
2117 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
2119 if (GTK_WIDGET_MAPPED (widget))
2120 gtk_widget_unmap (widget);
2125 * gtk_widget_hide_on_delete:
2126 * @widget: a #GtkWidget
2128 * Utility function; intended to be connected to the "delete_event"
2129 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
2130 * argument, then returns %TRUE. If connected to "delete_event", the
2131 * result is that clicking the close button for a window (on the
2132 * window frame, top right corner usually) will hide but not destroy
2133 * the window. By default, GTK+ destroys windows when "delete_event"
2136 * Return value: %TRUE
2139 gtk_widget_hide_on_delete (GtkWidget *widget)
2141 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2143 gtk_widget_hide (widget);
2149 * gtk_widget_show_all:
2150 * @widget: a #GtkWidget
2152 * Recursively shows a widget, and any child widgets (if the widget is
2156 gtk_widget_show_all (GtkWidget *widget)
2158 GtkWidgetClass *class;
2160 g_return_if_fail (GTK_IS_WIDGET (widget));
2162 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
2165 class = GTK_WIDGET_GET_CLASS (widget);
2167 if (class->show_all)
2168 class->show_all (widget);
2172 * gtk_widget_hide_all:
2173 * @widget: a #GtkWidget
2175 * Recursively hides a widget and any child widgets.
2178 gtk_widget_hide_all (GtkWidget *widget)
2180 GtkWidgetClass *class;
2182 g_return_if_fail (GTK_IS_WIDGET (widget));
2184 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
2187 class = GTK_WIDGET_GET_CLASS (widget);
2189 if (class->hide_all)
2190 class->hide_all (widget);
2195 * @widget: a #GtkWidget
2197 * This function is only for use in widget implementations. Causes
2198 * a widget to be mapped if it isn't already.
2202 gtk_widget_map (GtkWidget *widget)
2204 g_return_if_fail (GTK_IS_WIDGET (widget));
2205 g_return_if_fail (GTK_WIDGET_VISIBLE (widget));
2206 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
2208 if (!GTK_WIDGET_MAPPED (widget))
2210 if (!GTK_WIDGET_REALIZED (widget))
2211 gtk_widget_realize (widget);
2213 g_signal_emit (widget, widget_signals[MAP], 0);
2215 if (GTK_WIDGET_NO_WINDOW (widget))
2216 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
2222 * @widget: a #GtkWidget
2224 * This function is only for use in widget implementations. Causes
2225 * a widget to be unmapped if it's currently mapped.
2229 gtk_widget_unmap (GtkWidget *widget)
2231 g_return_if_fail (GTK_IS_WIDGET (widget));
2233 if (GTK_WIDGET_MAPPED (widget))
2235 if (GTK_WIDGET_NO_WINDOW (widget))
2236 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
2237 g_signal_emit (widget, widget_signals[UNMAP], 0);
2242 * gtk_widget_realize:
2243 * @widget: a #GtkWidget
2245 * Creates the GDK (windowing system) resources associated with a
2246 * widget. For example, @widget->window will be created when a widget
2247 * is realized. Normally realization happens implicitly; if you show
2248 * a widget and all its parent containers, then the widget will be
2249 * realized and mapped automatically.
2251 * Realizing a widget requires all
2252 * the widget's parent widgets to be realized; calling
2253 * gtk_widget_realize() realizes the widget's parents in addition to
2254 * @widget itself. If a widget is not yet inside a toplevel window
2255 * when you realize it, bad things will happen.
2257 * This function is primarily used in widget implementations, and
2258 * isn't very useful otherwise. Many times when you think you might
2259 * need it, a better approach is to connect to a signal that will be
2260 * called after the widget is realized automatically, such as
2261 * "expose_event". Or simply g_signal_connect_after() to the
2266 gtk_widget_realize (GtkWidget *widget)
2269 GdkExtensionMode mode;
2270 GtkWidgetShapeInfo *shape_info;
2272 g_return_if_fail (GTK_IS_WIDGET (widget));
2273 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
2274 GTK_IS_INVISIBLE (widget));
2276 if (!GTK_WIDGET_REALIZED (widget))
2279 if (GTK_IS_CONTAINER (widget) && !GTK_WIDGET_NO_WINDOW (widget))
2280 g_message ("gtk_widget_realize(%s)", g_type_name (GTK_WIDGET_TYPE (widget)));
2283 if (widget->parent == NULL &&
2284 !GTK_WIDGET_TOPLEVEL (widget))
2285 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
2286 "inside a toplevel window is not going to work very well. "
2287 "Widgets must be inside a toplevel container before realizing them.");
2289 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
2290 gtk_widget_realize (widget->parent);
2292 gtk_widget_ensure_style (widget);
2294 g_signal_emit (widget, widget_signals[REALIZE], 0);
2296 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
2298 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
2299 gdk_window_shape_combine_mask (widget->window,
2300 shape_info->shape_mask,
2301 shape_info->offset_x,
2302 shape_info->offset_y);
2305 if (!GTK_WIDGET_NO_WINDOW (widget))
2307 mode = gtk_widget_get_extension_events (widget);
2308 if (mode != GDK_EXTENSION_EVENTS_NONE)
2310 events = gtk_widget_get_events (widget);
2311 gdk_input_set_extension_events (widget->window, events, mode);
2319 * gtk_widget_unrealize:
2320 * @widget: a #GtkWidget
2322 * This function is only useful in widget implementations.
2323 * Causes a widget to be unrealized (frees all GDK resources
2324 * associated with the widget, such as @widget->window).
2328 gtk_widget_unrealize (GtkWidget *widget)
2330 g_return_if_fail (GTK_IS_WIDGET (widget));
2332 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
2333 gtk_widget_shape_combine_mask (widget, NULL, -1, -1);
2335 if (GTK_WIDGET_REALIZED (widget))
2337 g_object_ref (widget);
2338 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
2339 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
2340 g_object_unref (widget);
2344 /*****************************************
2346 *****************************************/
2349 * gtk_widget_queue_draw_area:
2350 * @widget: a #GtkWidget
2351 * @x: x coordinate of upper-left corner of rectangle to redraw
2352 * @y: y coordinate of upper-left corner of rectangle to redraw
2353 * @width: width of region to draw
2354 * @height: height of region to draw
2356 * Invalidates the rectangular area of @widget defined by @x, @y,
2357 * @width and @height by calling gdk_window_invalidate_rect() on the
2358 * widget's window and all its child windows. Once the main loop
2359 * becomes idle (after the current batch of events has been processed,
2360 * roughly), the window will receive expose events for the union of
2361 * all regions that have been invalidated.
2363 * Normally you would only use this function in widget
2364 * implementations. You might also use it, or
2365 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
2366 * #GtkDrawingArea or some portion thereof.
2368 * Frequently you can just call gdk_window_invalidate_rect() or
2369 * gdk_window_invalidate_region() instead of this function. Those
2370 * functions will invalidate only a single window, instead of the
2371 * widget and all its children.
2373 * The advantage of adding to the invalidated region compared to
2374 * simply drawing immediately is efficiency; using an invalid region
2375 * ensures that you only have to redraw one time.
2379 gtk_widget_queue_draw_area (GtkWidget *widget,
2385 GdkRectangle invalid_rect;
2388 g_return_if_fail (GTK_IS_WIDGET (widget));
2390 if (!GTK_WIDGET_REALIZED (widget))
2393 /* Just return if the widget or one of its ancestors isn't mapped */
2394 for (w = widget; w != NULL; w = w->parent)
2395 if (!GTK_WIDGET_MAPPED (w))
2398 /* Find the correct widget */
2400 if (!GTK_WIDGET_NO_WINDOW (widget))
2404 /* Translate widget relative to window-relative */
2406 gint wx, wy, wwidth, wheight;
2408 gdk_window_get_position (widget->window, &wx, &wy);
2409 x -= wx - widget->allocation.x;
2410 y -= wy - widget->allocation.y;
2412 gdk_drawable_get_size (widget->window, &wwidth, &wheight);
2414 if (x + width <= 0 || y + height <= 0 ||
2415 x >= wwidth || y >= wheight)
2426 if (x + width > wwidth)
2428 if (y + height > wheight)
2429 height = wheight - y;
2435 invalid_rect.width = width;
2436 invalid_rect.height = height;
2438 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
2442 widget_add_child_draw_rectangle (GtkWidget *widget,
2445 GdkRectangle child_rect;
2447 if (!GTK_WIDGET_MAPPED (widget) ||
2448 widget->window != widget->parent->window)
2451 gtk_widget_get_draw_rectangle (widget, &child_rect);
2452 gdk_rectangle_union (rect, &child_rect, rect);
2456 gtk_widget_get_draw_rectangle (GtkWidget *widget,
2459 if (GTK_WIDGET_NO_WINDOW (widget))
2461 GtkBorder *draw_border = NULL;
2463 *rect = widget->allocation;
2465 gtk_widget_style_get (widget,
2466 "draw-border", &draw_border,
2470 rect->x -= draw_border->top;
2471 rect->y -= draw_border->left;
2472 rect->width += draw_border->left + draw_border->right;
2473 rect->height += draw_border->top + draw_border->bottom;
2476 if (GTK_IS_CONTAINER (widget))
2477 gtk_container_forall (GTK_CONTAINER (widget),
2478 (GtkCallback)widget_add_child_draw_rectangle,
2485 rect->width = widget->allocation.width;
2486 rect->height = widget->allocation.height;
2491 * gtk_widget_queue_draw:
2492 * @widget: a #GtkWidget
2494 * Equivalent to calling gtk_widget_queue_draw_area() for the
2495 * entire area of a widget.
2499 gtk_widget_queue_draw (GtkWidget *widget)
2503 g_return_if_fail (GTK_IS_WIDGET (widget));
2505 gtk_widget_get_draw_rectangle (widget, &rect);
2507 gtk_widget_queue_draw_area (widget,
2509 rect.width, rect.height);
2512 /* Invalidates the given area (allocation-relative-coordinates)
2513 * in all of the widget's windows
2516 * gtk_widget_queue_clear_area:
2517 * @widget: a #GtkWidget
2518 * @x: x coordinate of upper-left corner of rectangle to redraw
2519 * @y: y coordinate of upper-left corner of rectangle to redraw
2520 * @width: width of region to draw
2521 * @height: height of region to draw
2523 * This function is no longer different from
2524 * gtk_widget_queue_draw_area(), though it once was. Now it just calls
2525 * gtk_widget_queue_draw_area(). Originally
2526 * gtk_widget_queue_clear_area() would force a redraw of the
2527 * background for %GTK_NO_WINDOW widgets, and
2528 * gtk_widget_queue_draw_area() would not. Now both functions ensure
2529 * the background will be redrawn.
2531 * @Deprecated: Use gtk_widget_queue_draw_area() instead.
2534 gtk_widget_queue_clear_area (GtkWidget *widget,
2540 g_return_if_fail (GTK_IS_WIDGET (widget));
2542 gtk_widget_queue_draw_area (widget, x, y, width, height);
2546 * gtk_widget_queue_clear:
2547 * @widget: a #GtkWidget
2549 * This function does the same as gtk_widget_queue_draw().
2551 * @Deprecated: Use gtk_widget_queue_draw() instead.
2554 gtk_widget_queue_clear (GtkWidget *widget)
2556 g_return_if_fail (GTK_IS_WIDGET (widget));
2558 gtk_widget_queue_draw (widget);
2562 * gtk_widget_queue_resize:
2563 * @widget: a #GtkWidget
2565 * This function is only for use in widget implementations.
2566 * Flags a widget to have its size renegotiated; should
2567 * be called when a widget for some reason has a new size request.
2568 * For example, when you change the text in a #GtkLabel, #GtkLabel
2569 * queues a resize to ensure there's enough space for the new text.
2572 gtk_widget_queue_resize (GtkWidget *widget)
2574 g_return_if_fail (GTK_IS_WIDGET (widget));
2576 if (GTK_WIDGET_REALIZED (widget))
2577 gtk_widget_queue_shallow_draw (widget);
2579 _gtk_size_group_queue_resize (widget);
2583 * gtk_widget_queue_resize_no_redraw:
2584 * @widget: a #GtkWidget
2586 * This function works like gtk_widget_queue_resize(), except that the
2587 * widget is not invalidated.
2592 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
2594 g_return_if_fail (GTK_IS_WIDGET (widget));
2596 _gtk_size_group_queue_resize (widget);
2601 * @widget: a #GtkWidget
2602 * @area: area to draw
2604 * In GTK+ 1.2, this function would immediately render the
2605 * region @area of a widget, by invoking the virtual draw method of a
2606 * widget. In GTK+ 2.0, the draw method is gone, and instead
2607 * gtk_widget_draw() simply invalidates the specified region of the
2608 * widget, then updates the invalid region of the widget immediately.
2609 * Usually you don't want to update the region immediately for
2610 * performance reasons, so in general gtk_widget_queue_draw_area() is
2611 * a better choice if you want to draw a region of a widget.
2615 gtk_widget_draw (GtkWidget *widget,
2618 g_return_if_fail (GTK_IS_WIDGET (widget));
2620 if (GTK_WIDGET_DRAWABLE (widget))
2623 gtk_widget_queue_draw_area (widget,
2625 area->width, area->height);
2627 gtk_widget_queue_draw (widget);
2629 gdk_window_process_updates (widget->window, TRUE);
2634 * gtk_widget_size_request:
2635 * @widget: a #GtkWidget
2636 * @requisition: a #GtkRequisition to be filled in
2638 * This function is typically used when implementing a #GtkContainer
2639 * subclass. Obtains the preferred size of a widget. The container
2640 * uses this information to arrange its child widgets and decide what
2641 * size allocations to give them with gtk_widget_size_allocate().
2643 * You can also call this function from an application, with some
2644 * caveats. Most notably, getting a size request requires the widget
2645 * to be associated with a screen, because font information may be
2646 * needed. Multihead-aware applications should keep this in mind.
2648 * Also remember that the size request is not necessarily the size
2649 * a widget will actually be allocated.
2651 * See also gtk_widget_get_child_requisition().
2654 gtk_widget_size_request (GtkWidget *widget,
2655 GtkRequisition *requisition)
2657 g_return_if_fail (GTK_IS_WIDGET (widget));
2659 #ifdef G_ENABLE_DEBUG
2660 if (requisition == &widget->requisition)
2661 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.");
2662 #endif /* G_ENABLE_DEBUG */
2664 _gtk_size_group_compute_requisition (widget, requisition);
2668 * gtk_widget_get_child_requisition:
2669 * @widget: a #GtkWidget
2670 * @requisition: a #GtkRequisition to be filled in
2672 * This function is only for use in widget implementations. Obtains
2673 * @widget->requisition, unless someone has forced a particular
2674 * geometry on the widget (e.g. with gtk_widget_set_usize()), in which
2675 * case it returns that geometry instead of the widget's requisition.
2677 * This function differs from gtk_widget_size_request() in that
2678 * it retrieves the last size request value from @widget->requisition,
2679 * while gtk_widget_size_request() actually calls the "size_request" method
2680 * on @widget to compute the size request and fill in @widget->requisition,
2681 * and only then returns @widget->requisition.
2683 * Because this function does not call the "size_request" method, it
2684 * can only be used when you know that @widget->requisition is
2685 * up-to-date, that is, gtk_widget_size_request() has been called
2686 * since the last time a resize was queued. In general, only container
2687 * implementations have this information; applications should use
2688 * gtk_widget_size_request().
2691 gtk_widget_get_child_requisition (GtkWidget *widget,
2692 GtkRequisition *requisition)
2694 _gtk_size_group_get_child_requisition (widget, requisition);
2698 invalidate_predicate (GdkWindow *window,
2703 gdk_window_get_user_data (window, &user_data);
2705 return (user_data == data);
2708 /* Invalidate @region in widget->window and all children
2709 * of widget->window owned by widget. @region is in the
2710 * same coordinates as widget->allocation and will be
2711 * modified by this call.
2714 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
2717 if (!GTK_WIDGET_REALIZED (widget))
2720 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
2724 gdk_window_get_position (widget->window, &x, &y);
2725 gdk_region_offset (region, -x, -y);
2728 gdk_window_invalidate_maybe_recurse (widget->window, region,
2729 invalidate_predicate, widget);
2733 * gtk_widget_queue_shallow_draw:
2734 * @widget: a #GtkWidget
2736 * Like gtk_widget_queue_draw(), but only windows owned
2737 * by @widget are invalidated.
2740 gtk_widget_queue_shallow_draw (GtkWidget *widget)
2745 g_return_if_fail (GTK_IS_WIDGET (widget));
2747 if (!GTK_WIDGET_REALIZED (widget))
2750 gtk_widget_get_draw_rectangle (widget, &rect);
2752 /* get_draw_rectangle() gives us window coordinates, we
2753 * need to convert to the coordinates that widget->allocation
2756 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
2760 gdk_window_get_position (widget->window, &wx, &wy);
2766 region = gdk_region_rectangle (&rect);
2767 gtk_widget_invalidate_widget_windows (widget, region);
2768 gdk_region_destroy (region);
2772 * gtk_widget_size_allocate:
2773 * @widget: a #GtkWidget
2774 * @allocation: position and size to be allocated to @widget
2776 * This function is only used by #GtkContainer subclasses, to assign a size
2777 * and position to their child widgets.
2781 gtk_widget_size_allocate (GtkWidget *widget,
2782 GtkAllocation *allocation)
2784 GtkWidgetAuxInfo *aux_info;
2785 GdkRectangle real_allocation;
2786 GdkRectangle old_allocation;
2787 gboolean alloc_needed;
2788 gboolean size_changed;
2789 gboolean position_changed;
2791 g_return_if_fail (GTK_IS_WIDGET (widget));
2793 #ifdef G_ENABLE_DEBUG
2794 if (gtk_debug_flags & GTK_DEBUG_GEOMETRY)
2805 parent = gtk_widget_get_parent (parent);
2808 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
2809 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
2810 2 * depth, " ", name,
2811 allocation->width, allocation->height);
2813 #endif /* G_ENABLE_DEBUG */
2815 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
2816 if (!GTK_WIDGET_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
2817 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
2819 old_allocation = widget->allocation;
2820 real_allocation = *allocation;
2821 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
2825 if (aux_info->x_set)
2826 real_allocation.x = aux_info->x;
2827 if (aux_info->y_set)
2828 real_allocation.y = aux_info->y;
2831 if (real_allocation.width < 0 || real_allocation.height < 0)
2833 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
2834 real_allocation.width,
2835 real_allocation.height);
2838 real_allocation.width = MAX (real_allocation.width, 1);
2839 real_allocation.height = MAX (real_allocation.height, 1);
2841 size_changed = (old_allocation.width != real_allocation.width ||
2842 old_allocation.height != real_allocation.height);
2843 position_changed = (old_allocation.x != real_allocation.x ||
2844 old_allocation.y != real_allocation.y);
2846 if (!alloc_needed && !size_changed && !position_changed)
2849 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
2851 if (GTK_WIDGET_MAPPED (widget))
2853 if (GTK_WIDGET_NO_WINDOW (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
2855 /* Invalidate union(old_allaction,widget->allocation) in widget->window
2857 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
2858 gdk_region_union_with_rect (invalidate, &old_allocation);
2860 gdk_window_invalidate_region (widget->window, invalidate, FALSE);
2861 gdk_region_destroy (invalidate);
2866 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
2868 /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
2870 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
2871 gdk_region_union_with_rect (invalidate, &old_allocation);
2873 gtk_widget_invalidate_widget_windows (widget, invalidate);
2874 gdk_region_destroy (invalidate);
2879 if ((size_changed || position_changed) && widget->parent &&
2880 GTK_WIDGET_REALIZED (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
2882 GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
2883 gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
2884 gdk_region_destroy (invalidate);
2889 * gtk_widget_common_ancestor:
2890 * @widget_a: a #GtkWidget
2891 * @widget_b: a #GtkWidget
2893 * Find the common ancestor of @widget_a and @widget_b that
2894 * is closest to the two widgets.
2896 * Return value: the closest common ancestor of @widget_a and
2897 * @widget_b or %NULL if @widget_a and @widget_b do not
2898 * share a common ancestor.
2901 gtk_widget_common_ancestor (GtkWidget *widget_a,
2902 GtkWidget *widget_b)
2904 GtkWidget *parent_a;
2905 GtkWidget *parent_b;
2909 parent_a = widget_a;
2910 while (parent_a->parent)
2912 parent_a = parent_a->parent;
2916 parent_b = widget_b;
2917 while (parent_b->parent)
2919 parent_b = parent_b->parent;
2923 if (parent_a != parent_b)
2926 while (depth_a > depth_b)
2928 widget_a = widget_a->parent;
2932 while (depth_b > depth_a)
2934 widget_b = widget_b->parent;
2938 while (widget_a != widget_b)
2940 widget_a = widget_a->parent;
2941 widget_b = widget_b->parent;
2948 * gtk_widget_translate_coordinates:
2949 * @src_widget: a #GtkWidget
2950 * @dest_widget: a #GtkWidget
2951 * @src_x: X position relative to @src_widget
2952 * @src_y: Y position relative to @src_widget
2953 * @dest_x: location to store X position relative to @dest_widget
2954 * @dest_y: location to store Y position relative to @dest_widget
2956 * Translate coordinates relative to @src_widget's allocation to coordinates
2957 * relative to @dest_widget's allocations. In order to perform this
2958 * operation, both widgets must be realized, and must share a common
2961 * Return value: %FALSE if either widget was not realized, or there
2962 * was no common ancestor. In this case, nothing is stored in
2963 * *@dest_x and *@dest_y. Otherwise %TRUE.
2966 gtk_widget_translate_coordinates (GtkWidget *src_widget,
2967 GtkWidget *dest_widget,
2973 GtkWidget *ancestor;
2976 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
2977 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
2979 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
2980 if (!ancestor || !GTK_WIDGET_REALIZED (src_widget) || !GTK_WIDGET_REALIZED (dest_widget))
2983 /* Translate from allocation relative to window relative */
2984 if (!GTK_WIDGET_NO_WINDOW (src_widget) && src_widget->parent)
2987 gdk_window_get_position (src_widget->window, &wx, &wy);
2989 src_x -= wx - src_widget->allocation.x;
2990 src_y -= wy - src_widget->allocation.y;
2994 src_x += src_widget->allocation.x;
2995 src_y += src_widget->allocation.y;
2998 /* Translate to the common ancestor */
2999 window = src_widget->window;
3000 while (window != ancestor->window)
3004 gdk_window_get_position (window, &dx, &dy);
3009 window = gdk_window_get_parent (window);
3011 if (!window) /* Handle GtkHandleBox */
3016 window = dest_widget->window;
3017 while (window != ancestor->window)
3021 gdk_window_get_position (window, &dx, &dy);
3026 window = gdk_window_get_parent (window);
3028 if (!window) /* Handle GtkHandleBox */
3032 /* Translate from window relative to allocation relative */
3033 if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent)
3036 gdk_window_get_position (dest_widget->window, &wx, &wy);
3038 src_x += wx - dest_widget->allocation.x;
3039 src_y += wy - dest_widget->allocation.y;
3043 src_x -= dest_widget->allocation.x;
3044 src_y -= dest_widget->allocation.y;
3056 gtk_widget_real_size_allocate (GtkWidget *widget,
3057 GtkAllocation *allocation)
3059 widget->allocation = *allocation;
3061 if (GTK_WIDGET_REALIZED (widget) &&
3062 !GTK_WIDGET_NO_WINDOW (widget))
3064 gdk_window_move_resize (widget->window,
3065 allocation->x, allocation->y,
3066 allocation->width, allocation->height);
3071 gtk_widget_real_can_activate_accel (GtkWidget *widget,
3074 /* widgets must be onscreen for accels to take effect */
3075 return GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_DRAWABLE (widget) && gdk_window_is_viewable (widget->window);
3079 * gtk_widget_can_activate_accel:
3080 * @widget: a #GtkWidget
3081 * @signal_id: the ID of a signal installed on @widget
3083 * Determines whether an accelerator that activates the signal
3084 * identified by @signal_id can currently be activated.
3085 * This is done by emitting the GtkWidget::can-activate-accel
3086 * signal on @widget; if the signal isn't overridden by a
3087 * handler or in a derived widget, then the default check is
3088 * that the widget must be sensitive, and the widget and all
3089 * its ancestors mapped.
3091 * Return value: %TRUE if the accelerator can be activated.
3096 gtk_widget_can_activate_accel (GtkWidget *widget,
3099 gboolean can_activate = FALSE;
3100 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3101 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
3102 return can_activate;
3111 closure_accel_activate (GClosure *closure,
3112 GValue *return_value,
3113 guint n_param_values,
3114 const GValue *param_values,
3115 gpointer invocation_hint,
3116 gpointer marshal_data)
3118 AccelClosure *aclosure = (AccelClosure*) closure;
3119 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
3122 g_signal_emit (closure->data, aclosure->signal_id, 0);
3124 /* whether accelerator was handled */
3125 g_value_set_boolean (return_value, can_activate);
3129 closures_destroy (gpointer data)
3131 GSList *slist, *closures = data;
3133 for (slist = closures; slist; slist = slist->next)
3135 g_closure_invalidate (slist->data);
3136 g_closure_unref (slist->data);
3138 g_slist_free (closures);
3142 widget_new_accel_closure (GtkWidget *widget,
3145 AccelClosure *aclosure;
3146 GClosure *closure = NULL;
3147 GSList *slist, *closures;
3149 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
3150 for (slist = closures; slist; slist = slist->next)
3151 if (!gtk_accel_group_from_accel_closure (slist->data))
3153 /* reuse this closure */
3154 closure = slist->data;
3159 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
3160 closures = g_slist_prepend (closures, g_closure_ref (closure));
3161 g_closure_sink (closure);
3162 g_closure_set_marshal (closure, closure_accel_activate);
3164 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
3166 aclosure = (AccelClosure*) closure;
3167 g_assert (closure->data == widget);
3168 g_assert (closure->marshal == closure_accel_activate);
3169 aclosure->signal_id = signal_id;
3175 * gtk_widget_add_accelerator
3176 * @widget: widget to install an accelerator on
3177 * @accel_signal: widget signal to emit on accelerator activation
3178 * @accel_group: accel group for this widget, added to its toplevel
3179 * @accel_key: GDK keyval of the accelerator
3180 * @accel_mods: modifier key combination of the accelerator
3181 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
3183 * Installs an accelerator for this @widget in @accel_group that causes
3184 * @accel_signal to be emitted if the accelerator is activated.
3185 * The @accel_group needs to be added to the widget's toplevel via
3186 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
3187 * Accelerators added through this function are not user changeable during
3188 * runtime. If you want to support accelerators that can be changed by the
3189 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
3190 * gtk_menu_item_set_accel_path() instead.
3193 gtk_widget_add_accelerator (GtkWidget *widget,
3194 const gchar *accel_signal,
3195 GtkAccelGroup *accel_group,
3197 GdkModifierType accel_mods,
3198 GtkAccelFlags accel_flags)
3203 g_return_if_fail (GTK_IS_WIDGET (widget));
3204 g_return_if_fail (accel_signal != NULL);
3205 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
3207 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
3208 if (!query.signal_id ||
3209 !(query.signal_flags & G_SIGNAL_ACTION) ||
3210 query.return_type != G_TYPE_NONE ||
3213 /* hmm, should be elaborate enough */
3214 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
3215 G_OBJECT_TYPE_NAME (widget), accel_signal);
3219 closure = widget_new_accel_closure (widget, query.signal_id);
3221 g_object_ref (widget);
3223 /* install the accelerator. since we don't map this onto an accel_path,
3224 * the accelerator will automatically be locked.
3226 gtk_accel_group_connect (accel_group,
3229 accel_flags | GTK_ACCEL_LOCKED,
3232 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3234 g_object_unref (widget);
3238 * gtk_widget_remove_accelerator:
3239 * @widget: widget to install an accelerator on
3240 * @accel_group: accel group for this widget
3241 * @accel_key: GDK keyval of the accelerator
3242 * @accel_mods: modifier key combination of the accelerator
3243 * @returns: whether an accelerator was installed and could be removed
3245 * Removes an accelerator from @widget, previously installed with
3246 * gtk_widget_add_accelerator().
3249 gtk_widget_remove_accelerator (GtkWidget *widget,
3250 GtkAccelGroup *accel_group,
3252 GdkModifierType accel_mods)
3254 GtkAccelGroupEntry *ag_entry;
3255 GList *slist, *clist;
3258 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3259 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
3261 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
3262 clist = gtk_widget_list_accel_closures (widget);
3263 for (slist = clist; slist; slist = slist->next)
3267 for (i = 0; i < n; i++)
3268 if (slist->data == (gpointer) ag_entry[i].closure)
3270 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
3272 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3274 g_list_free (clist);
3279 g_list_free (clist);
3281 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
3282 accel_key, accel_mods, accel_group,
3283 G_OBJECT_TYPE_NAME (widget), widget);
3289 * gtk_widget_list_accel_closures
3290 * @widget: widget to list accelerator closures for
3291 * @returns: a newly allocated #GList of closures
3293 * Lists the closures used by @widget for accelerator group connections
3294 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
3295 * The closures can be used to monitor accelerator changes on @widget,
3296 * by connecting to the ::accel_changed signal of the #GtkAccelGroup of a
3297 * closure which can be found out with gtk_accel_group_from_accel_closure().
3300 gtk_widget_list_accel_closures (GtkWidget *widget)
3303 GList *clist = NULL;
3305 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3307 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
3308 if (gtk_accel_group_from_accel_closure (slist->data))
3309 clist = g_list_prepend (clist, slist->data);
3316 GtkAccelGroup *accel_group;
3321 destroy_accel_path (gpointer data)
3323 AccelPath *apath = data;
3325 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
3327 /* closures_destroy takes care of unrefing the closure */
3328 g_object_unref (apath->accel_group);
3335 * gtk_widget_set_accel_path:
3336 * @widget: a #GtkWidget
3337 * @accel_path: path used to look up the accelerator
3338 * @accel_group: a #GtkAccelGroup.
3340 * Given an accelerator group, @accel_group, and an accelerator path,
3341 * @accel_path, sets up an accelerator in @accel_group so whenever the
3342 * key binding that is defined for @accel_path is pressed, @widget
3343 * will be activated. This removes any accelerators (for any
3344 * accelerator group) installed by previous calls to
3345 * gtk_widget_set_accel_path(). Associating accelerators with
3346 * paths allows them to be modified by the user and the modifications
3347 * to be saved for future use. (See gtk_accel_map_save().)
3349 * This function is a low level function that would most likely
3350 * be used by a menu creation system like #GtkItemFactory. If you
3351 * use #GtkItemFactory, setting up accelerator paths will be done
3354 * Even when you you aren't using #GtkItemFactory, if you only want to
3355 * set up accelerators on menu items gtk_menu_item_set_accel_path()
3356 * provides a somewhat more convenient interface.
3359 gtk_widget_set_accel_path (GtkWidget *widget,
3360 const gchar *accel_path,
3361 GtkAccelGroup *accel_group)
3365 g_return_if_fail (GTK_IS_WIDGET (widget));
3366 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
3370 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
3371 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
3373 gtk_accel_map_add_entry (accel_path, 0, 0);
3374 apath = g_new (AccelPath, 1);
3375 apath->widget = widget;
3376 apath->accel_group = g_object_ref (accel_group);
3377 apath->path_quark = g_quark_from_string (accel_path);
3378 apath->closure = widget_new_accel_closure (apath->widget, GTK_WIDGET_GET_CLASS (apath->widget)->activate_signal);
3383 /* also removes possible old settings */
3384 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
3387 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
3389 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3393 _gtk_widget_get_accel_path (GtkWidget *widget,
3398 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3400 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
3402 *locked = apath ? apath->accel_group->lock_count > 0 : TRUE;
3403 return apath ? g_quark_to_string (apath->path_quark) : NULL;
3407 gtk_widget_mnemonic_activate (GtkWidget *widget,
3408 gboolean group_cycling)
3412 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3414 group_cycling = group_cycling != FALSE;
3415 if (!GTK_WIDGET_IS_SENSITIVE (widget))
3418 g_signal_emit (widget,
3419 widget_signals[MNEMONIC_ACTIVATE],
3427 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
3428 gboolean group_cycling)
3430 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
3431 gtk_widget_activate (widget);
3432 else if (GTK_WIDGET_CAN_FOCUS (widget))
3433 gtk_widget_grab_focus (widget);
3436 g_warning ("widget `%s' isn't suitable for mnemonic activation",
3437 G_OBJECT_TYPE_NAME (widget));
3438 gdk_display_beep (gtk_widget_get_display (widget));
3444 gtk_widget_real_key_press_event (GtkWidget *widget,
3447 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
3451 gtk_widget_real_key_release_event (GtkWidget *widget,
3454 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
3458 gtk_widget_real_focus_in_event (GtkWidget *widget,
3459 GdkEventFocus *event)
3461 gtk_widget_queue_shallow_draw (widget);
3467 gtk_widget_real_focus_out_event (GtkWidget *widget,
3468 GdkEventFocus *event)
3470 gtk_widget_queue_shallow_draw (widget);
3475 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
3476 (event->type == GDK_FOCUS_CHANGE || GTK_WIDGET_REALIZED(widget))
3480 * @widget: a #GtkWidget
3481 * @event: a #GdkEvent
3483 * Rarely-used function. This function is used to emit
3484 * the event signals on a widget (those signals should never
3485 * be emitted without using this function to do so).
3486 * If you want to synthesize an event though, don't use this function;
3487 * instead, use gtk_main_do_event() so the event will behave as if
3488 * it were in the event queue. Don't synthesize expose events; instead,
3489 * use gdk_window_invalidate_rect() to invalidate a region of the
3492 * Return value: return from the event signal emission (%TRUE if the event was handled)
3495 gtk_widget_event (GtkWidget *widget,
3498 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
3499 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
3501 if (event->type == GDK_EXPOSE)
3503 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
3504 "the same effect, call gdk_window_invalidate_rect/region(), "
3505 "followed by gdk_window_process_updates().");
3509 return gtk_widget_event_internal (widget, event);
3514 * gtk_widget_send_expose:
3515 * @widget: a #GtkWidget
3516 * @event: a expose #GdkEvent
3518 * Very rarely-used function. This function is used to emit
3519 * an expose event signals on a widget. This function is not
3520 * normally used directly. The only time it is used is when
3521 * propagating an expose event to a child %NO_WINDOW widget, and
3522 * that is normally done using gtk_container_propagate_expose().
3524 * If you want to force an area of a window to be redrawn,
3525 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
3526 * To cause the redraw to be done immediately, follow that call
3527 * with a call to gdk_window_process_updates().
3529 * Return value: return from the event signal emission (%TRUE if the event was handled)
3532 gtk_widget_send_expose (GtkWidget *widget,
3535 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
3536 g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), TRUE);
3537 g_return_val_if_fail (event != NULL, TRUE);
3538 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
3540 if (event->type != GDK_EXPOSE)
3543 return gtk_widget_event_internal (widget, event);
3547 event_window_is_still_viewable (GdkEvent *event)
3549 /* Some programs, such as gnome-theme-manager, fake widgets
3550 * into exposing onto a pixmap by sending expose events with
3551 * event->window pointing to a pixmap
3553 if (GDK_IS_PIXMAP (event->any.window))
3554 return event->type == GDK_EXPOSE;
3556 /* Check that we think the event's window is viewable before
3557 * delivering the event, to prevent suprises. We do this here
3558 * at the last moment, since the event may have been queued
3559 * up behind other events, held over a recursive main loop, etc.
3561 switch (event->type)
3564 case GDK_MOTION_NOTIFY:
3565 case GDK_BUTTON_PRESS:
3566 case GDK_2BUTTON_PRESS:
3567 case GDK_3BUTTON_PRESS:
3569 case GDK_ENTER_NOTIFY:
3570 case GDK_PROXIMITY_IN:
3572 return event->any.window && gdk_window_is_viewable (event->any.window);
3575 /* The following events are the second half of paired events;
3576 * we always deliver them to deal with widgets that clean up
3577 * on the second half.
3579 case GDK_BUTTON_RELEASE:
3580 case GDK_KEY_RELEASE:
3581 case GDK_LEAVE_NOTIFY:
3582 case GDK_PROXIMITY_OUT:
3586 /* Remaining events would make sense on an not-viewable window,
3587 * or don't have an associated window.
3594 gtk_widget_event_internal (GtkWidget *widget,
3597 gboolean return_val = FALSE;
3599 /* We check only once for is-still-visible; if someone
3600 * hides the window in on of the signals on the widget,
3601 * they are responsible for returning TRUE to terminate
3604 if (!event_window_is_still_viewable (event))
3607 g_object_ref (widget);
3609 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
3610 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
3615 switch (event->type)
3620 case GDK_BUTTON_PRESS:
3621 case GDK_2BUTTON_PRESS:
3622 case GDK_3BUTTON_PRESS:
3623 signal_num = BUTTON_PRESS_EVENT;
3626 signal_num = SCROLL_EVENT;
3628 case GDK_BUTTON_RELEASE:
3629 signal_num = BUTTON_RELEASE_EVENT;
3631 case GDK_MOTION_NOTIFY:
3632 signal_num = MOTION_NOTIFY_EVENT;
3635 signal_num = DELETE_EVENT;
3638 signal_num = DESTROY_EVENT;
3641 signal_num = KEY_PRESS_EVENT;
3643 case GDK_KEY_RELEASE:
3644 signal_num = KEY_RELEASE_EVENT;
3646 case GDK_ENTER_NOTIFY:
3647 signal_num = ENTER_NOTIFY_EVENT;
3649 case GDK_LEAVE_NOTIFY:
3650 signal_num = LEAVE_NOTIFY_EVENT;
3652 case GDK_FOCUS_CHANGE:
3653 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
3656 signal_num = CONFIGURE_EVENT;
3659 signal_num = MAP_EVENT;
3662 signal_num = UNMAP_EVENT;
3664 case GDK_WINDOW_STATE:
3665 signal_num = WINDOW_STATE_EVENT;
3667 case GDK_PROPERTY_NOTIFY:
3668 signal_num = PROPERTY_NOTIFY_EVENT;
3670 case GDK_SELECTION_CLEAR:
3671 signal_num = SELECTION_CLEAR_EVENT;
3673 case GDK_SELECTION_REQUEST:
3674 signal_num = SELECTION_REQUEST_EVENT;
3676 case GDK_SELECTION_NOTIFY:
3677 signal_num = SELECTION_NOTIFY_EVENT;
3679 case GDK_PROXIMITY_IN:
3680 signal_num = PROXIMITY_IN_EVENT;
3682 case GDK_PROXIMITY_OUT:
3683 signal_num = PROXIMITY_OUT_EVENT;
3686 signal_num = NO_EXPOSE_EVENT;
3688 case GDK_CLIENT_EVENT:
3689 signal_num = CLIENT_EVENT;
3692 signal_num = EXPOSE_EVENT;
3694 case GDK_VISIBILITY_NOTIFY:
3695 signal_num = VISIBILITY_NOTIFY_EVENT;
3698 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
3702 if (signal_num != -1)
3703 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
3705 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
3706 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
3710 g_object_unref (widget);
3716 * gtk_widget_activate:
3717 * @widget: a #GtkWidget that's activatable
3719 * For widgets that can be "activated" (buttons, menu items, etc.)
3720 * this function activates them. Activation is what happens when you
3721 * press Enter on a widget during key navigation. If @widget isn't
3722 * activatable, the function returns %FALSE.
3724 * Return value: %TRUE if the widget was activatable
3727 gtk_widget_activate (GtkWidget *widget)
3729 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3731 if (WIDGET_CLASS (widget)->activate_signal)
3733 /* FIXME: we should eventually check the signals signature here */
3734 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
3743 * gtk_widget_set_scroll_adjustments:
3744 * @widget: a #GtkWidget
3745 * @hadjustment: an adjustment for horizontal scrolling, or %NULL
3746 * @vadjustment: an adjustment for vertical scrolling, or %NULL
3748 * For widgets that support scrolling, sets the scroll adjustments and
3749 * returns %TRUE. For widgets that don't support scrolling, does
3750 * nothing and returns %FALSE. Widgets that don't support scrolling
3751 * can be scrolled by placing them in a #GtkViewport, which does
3752 * support scrolling.
3754 * Return value: %TRUE if the widget supports scrolling
3757 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
3758 GtkAdjustment *hadjustment,
3759 GtkAdjustment *vadjustment)
3761 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3763 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
3765 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
3767 if (WIDGET_CLASS (widget)->set_scroll_adjustments_signal)
3769 /* FIXME: we should eventually check the signals signature here */
3770 g_signal_emit (widget,
3771 WIDGET_CLASS (widget)->set_scroll_adjustments_signal, 0,
3772 hadjustment, vadjustment);
3780 gtk_widget_reparent_subwindows (GtkWidget *widget,
3781 GdkWindow *new_window)
3783 if (GTK_WIDGET_NO_WINDOW (widget))
3785 GList *children = gdk_window_get_children (widget->window);
3788 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
3791 GdkWindow *window = tmp_list->data;
3793 gdk_window_get_user_data (window, (void **)&child);
3794 while (child && child != widget)
3795 child = child->parent;
3798 gdk_window_reparent (window, new_window, 0, 0);
3801 g_list_free (children);
3806 GList *tmp_list, *children;
3808 parent = gdk_window_get_parent (widget->window);
3811 gdk_window_reparent (widget->window, new_window, 0, 0);
3814 children = gdk_window_get_children (parent);
3816 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
3819 GdkWindow *window = tmp_list->data;
3821 gdk_window_get_user_data (window, (void **)&child);
3822 if (child == widget)
3823 gdk_window_reparent (window, new_window, 0, 0);
3826 g_list_free (children);
3832 gtk_widget_reparent_fixup_child (GtkWidget *widget,
3833 gpointer client_data)
3835 g_return_if_fail (client_data != NULL);
3837 if (GTK_WIDGET_NO_WINDOW (widget))
3840 g_object_unref (widget->window);
3841 widget->window = (GdkWindow*) client_data;
3843 g_object_ref (widget->window);
3845 if (GTK_IS_CONTAINER (widget))
3846 gtk_container_forall (GTK_CONTAINER (widget),
3847 gtk_widget_reparent_fixup_child,
3853 * gtk_widget_reparent:
3854 * @widget: a #GtkWidget
3855 * @new_parent: a #GtkContainer to move the widget into
3857 * Moves a widget from one #GtkContainer to another, handling reference
3858 * count issues to avoid destroying the widget.
3862 gtk_widget_reparent (GtkWidget *widget,
3863 GtkWidget *new_parent)
3865 g_return_if_fail (GTK_IS_WIDGET (widget));
3866 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
3867 g_return_if_fail (widget->parent != NULL);
3869 if (widget->parent != new_parent)
3871 /* First try to see if we can get away without unrealizing
3872 * the widget as we reparent it. if so we set a flag so
3873 * that gtk_widget_unparent doesn't unrealize widget
3875 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent))
3876 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
3878 g_object_ref (widget);
3879 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
3880 gtk_container_add (GTK_CONTAINER (new_parent), widget);
3881 g_object_unref (widget);
3883 if (GTK_WIDGET_IN_REPARENT (widget))
3885 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
3887 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
3888 gtk_widget_reparent_fixup_child (widget,
3889 gtk_widget_get_parent_window (widget));
3892 g_object_notify (G_OBJECT (widget), "parent");
3897 * gtk_widget_intersect:
3898 * @widget: a #GtkWidget
3899 * @area: a rectangle
3900 * @intersection: rectangle to store intersection of @widget and @area
3902 * Computes the intersection of a @widget's area and @area, storing
3903 * the intersection in @intersection, and returns %TRUE if there was
3904 * an intersection. @intersection may be %NULL if you're only
3905 * interested in whether there was an intersection.
3907 * Return value: %TRUE if there was an intersection
3910 gtk_widget_intersect (GtkWidget *widget,
3912 GdkRectangle *intersection)
3918 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3919 g_return_val_if_fail (area != NULL, FALSE);
3922 dest = intersection;
3926 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
3928 if (return_val && intersection && !GTK_WIDGET_NO_WINDOW (widget))
3930 intersection->x -= widget->allocation.x;
3931 intersection->y -= widget->allocation.y;
3938 * gtk_widget_region_intersect:
3939 * @widget: a #GtkWidget
3940 * @region: a #GdkRegion, in the same coordinate system as
3941 * @widget->allocation. That is, relative to @widget->window
3942 * for %NO_WINDOW widgets; relative to the parent window
3943 * of @widget->window for widgets with their own window.
3944 * @returns: A newly allocated region holding the intersection of @widget
3945 * and @region. The coordinates of the return value are
3946 * relative to @widget->window for %NO_WINDOW widgets, and
3947 * relative to the parent window of @widget->window for
3948 * widgets with their own window.
3950 * Computes the intersection of a @widget's area and @region, returning
3951 * the intersection. The result may be empty, use gdk_region_empty() to
3955 gtk_widget_region_intersect (GtkWidget *widget,
3961 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3962 g_return_val_if_fail (region != NULL, NULL);
3964 gtk_widget_get_draw_rectangle (widget, &rect);
3966 dest = gdk_region_rectangle (&rect);
3968 gdk_region_intersect (dest, region);
3974 * _gtk_widget_grab_notify:
3975 * @widget: a #GtkWidget
3976 * @was_grabbed: whether a grab is now in effect
3978 * Emits the signal "grab_notify" on @widget.
3983 _gtk_widget_grab_notify (GtkWidget *widget,
3984 gboolean was_grabbed)
3986 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
3990 * gtk_widget_grab_focus:
3991 * @widget: a #GtkWidget
3993 * Causes @widget to have the keyboard focus for the #GtkWindow it's
3994 * inside. @widget must be a focusable widget, such as a #GtkEntry;
3995 * something like #GtkFrame won't work. (More precisely, it must have the
3996 * %GTK_CAN_FOCUS flag set.)
4000 gtk_widget_grab_focus (GtkWidget *widget)
4002 g_return_if_fail (GTK_IS_WIDGET (widget));
4004 if (!GTK_WIDGET_IS_SENSITIVE (widget))
4007 g_object_ref (widget);
4008 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
4009 g_object_notify (G_OBJECT (widget), "has-focus");
4010 g_object_unref (widget);
4014 reset_focus_recurse (GtkWidget *widget,
4017 if (GTK_IS_CONTAINER (widget))
4019 GtkContainer *container;
4021 container = GTK_CONTAINER (widget);
4022 gtk_container_set_focus_child (container, NULL);
4024 gtk_container_foreach (container,
4025 reset_focus_recurse,
4031 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
4033 if (GTK_WIDGET_CAN_FOCUS (focus_widget))
4035 GtkWidget *toplevel;
4038 /* clear the current focus setting, break if the current widget
4039 * is the focus widget's parent, since containers above that will
4040 * be set by the next loop.
4042 toplevel = gtk_widget_get_toplevel (focus_widget);
4043 if (GTK_WIDGET_TOPLEVEL (toplevel))
4045 widget = GTK_WINDOW (toplevel)->focus_widget;
4047 if (widget == focus_widget)
4049 /* We call _gtk_window_internal_set_focus() here so that the
4050 * toplevel window can request the focus if necessary.
4051 * This is needed when the toplevel is a GtkPlug
4053 if (!GTK_WIDGET_HAS_FOCUS (widget))
4054 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
4061 while (widget->parent && widget->parent != focus_widget->parent)
4063 widget = widget->parent;
4064 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
4068 else if (toplevel != focus_widget)
4070 /* gtk_widget_grab_focus() operates on a tree without window...
4071 * actually, this is very questionable behaviour.
4074 gtk_container_foreach (GTK_CONTAINER (toplevel),
4075 reset_focus_recurse,
4079 /* now propagate the new focus up the widget tree and finally
4080 * set it on the window
4082 widget = focus_widget;
4083 while (widget->parent)
4085 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
4086 widget = widget->parent;
4088 if (GTK_IS_WINDOW (widget))
4089 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
4094 gtk_widget_real_show_help (GtkWidget *widget,
4095 GtkWidgetHelpType help_type)
4097 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
4099 _gtk_tooltips_toggle_keyboard_mode (widget);
4107 gtk_widget_real_focus (GtkWidget *widget,
4108 GtkDirectionType direction)
4110 if (!GTK_WIDGET_CAN_FOCUS (widget))
4113 if (!gtk_widget_is_focus (widget))
4115 gtk_widget_grab_focus (widget);
4123 * gtk_widget_is_focus:
4124 * @widget: a #GtkWidget
4126 * Determines if the widget is the focus widget within its
4127 * toplevel. (This does not mean that the %HAS_FOCUS flag is
4128 * necessarily set; %HAS_FOCUS will only be set if the
4129 * toplevel widget additionally has the global input focus.)
4131 * Return value: %TRUE if the widget is the focus widget.
4134 gtk_widget_is_focus (GtkWidget *widget)
4136 GtkWidget *toplevel;
4138 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4140 toplevel = gtk_widget_get_toplevel (widget);
4142 if (GTK_IS_WINDOW (toplevel))
4143 return widget == GTK_WINDOW (toplevel)->focus_widget;
4149 * gtk_widget_grab_default:
4150 * @widget: a #GtkWidget
4152 * Causes @widget to become the default widget. @widget must have the
4153 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
4154 * yourself by calling <literal>GTK_WIDGET_SET_FLAGS (@widget,
4155 * GTK_CAN_DEFAULT)</literal>. The default widget is activated when the user
4156 * presses Enter in a window. Default widgets must be activatable,
4157 * that is, gtk_widget_activate() should affect them.
4161 gtk_widget_grab_default (GtkWidget *widget)
4165 g_return_if_fail (GTK_IS_WIDGET (widget));
4166 g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget));
4168 window = gtk_widget_get_toplevel (widget);
4170 if (window && GTK_WIDGET_TOPLEVEL (window))
4171 gtk_window_set_default (GTK_WINDOW (window), widget);
4173 g_warning (G_STRLOC ": widget not within a GtkWindow");
4177 * gtk_widget_set_name:
4178 * @widget: a #GtkWidget
4179 * @name: name for the widget
4181 * Widgets can be named, which allows you to refer to them from a
4182 * gtkrc file. You can apply a style to widgets with a particular name
4183 * in the gtkrc file. See the documentation for gtkrc files (on the
4184 * same page as the docs for #GtkRcStyle).
4186 * Note that widget names are separated by periods in paths (see
4187 * gtk_widget_path()), so names with embedded periods may cause confusion.
4190 gtk_widget_set_name (GtkWidget *widget,
4195 g_return_if_fail (GTK_IS_WIDGET (widget));
4197 new_name = g_strdup (name);
4198 g_free (widget->name);
4199 widget->name = new_name;
4201 if (GTK_WIDGET_RC_STYLE (widget))
4202 gtk_widget_reset_rc_style (widget);
4204 g_object_notify (G_OBJECT (widget), "name");
4208 * gtk_widget_get_name:
4209 * @widget: a #GtkWidget
4211 * Retrieves the name of a widget. See gtk_widget_set_name() for the
4212 * significance of widget names.
4214 * Return value: name of the widget. This string is owned by GTK+ and
4215 * should not be modified or freed
4217 G_CONST_RETURN gchar*
4218 gtk_widget_get_name (GtkWidget *widget)
4220 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4223 return widget->name;
4224 return g_type_name (GTK_WIDGET_TYPE (widget));
4228 * gtk_widget_set_state:
4229 * @widget: a #GtkWidget
4230 * @state: new state for @widget
4232 * This function is for use in widget implementations. Sets the state
4233 * of a widget (insensitive, prelighted, etc.) Usually you should set
4234 * the state using wrapper functions such as gtk_widget_set_sensitive().
4238 gtk_widget_set_state (GtkWidget *widget,
4241 g_return_if_fail (GTK_IS_WIDGET (widget));
4243 if (state == GTK_WIDGET_STATE (widget))
4246 if (state == GTK_STATE_INSENSITIVE)
4247 gtk_widget_set_sensitive (widget, FALSE);
4253 data.state_restoration = FALSE;
4254 data.use_forall = FALSE;
4256 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
4258 data.parent_sensitive = TRUE;
4260 gtk_widget_propagate_state (widget, &data);
4262 if (GTK_WIDGET_DRAWABLE (widget))
4263 gtk_widget_queue_draw (widget);
4269 * gtk_widget_set_app_paintable:
4270 * @widget: a #GtkWidget
4271 * @app_paintable: %TRUE if the application will paint on the widget
4273 * Sets whether the application intends to draw on the widget in
4274 * an ::expose-event handler.
4276 * This is a hint to the widget and does not affect the behavior of
4277 * the GTK+ core; many widgets ignore this flag entirely. For widgets
4278 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
4279 * the effect is to suppress default themed drawing of the widget's
4280 * background. (Children of the widget will still be drawn.) The application
4281 * is then entirely responsible for drawing the widget background.
4284 gtk_widget_set_app_paintable (GtkWidget *widget,
4285 gboolean app_paintable)
4287 g_return_if_fail (GTK_IS_WIDGET (widget));
4289 app_paintable = (app_paintable != FALSE);
4291 if (GTK_WIDGET_APP_PAINTABLE (widget) != app_paintable)
4294 GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE);
4296 GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE);
4298 if (GTK_WIDGET_DRAWABLE (widget))
4299 gtk_widget_queue_draw (widget);
4301 g_object_notify (G_OBJECT (widget), "app-paintable");
4306 * gtk_widget_set_double_buffered:
4307 * @widget: a #GtkWidget
4308 * @double_buffered: %TRUE to double-buffer a widget
4310 * Widgets are double buffered by default; you can use this function
4311 * to turn off the buffering. "Double buffered" simply means that
4312 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
4313 * automatically around expose events sent to the
4314 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
4315 * window to an offscreen buffer, and gdk_window_end_paint() draws the
4316 * buffer to the screen. The result is that users see the window
4317 * update in one smooth step, and don't see individual graphics
4318 * primitives being rendered.
4320 * In very simple terms, double buffered widgets don't flicker,
4321 * so you would only use this function to turn off double buffering
4322 * if you had special needs and really knew what you were doing.
4326 gtk_widget_set_double_buffered (GtkWidget *widget,
4327 gboolean double_buffered)
4329 g_return_if_fail (GTK_IS_WIDGET (widget));
4331 if (double_buffered)
4332 GTK_WIDGET_SET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
4334 GTK_WIDGET_UNSET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
4338 * gtk_widget_set_redraw_on_allocate:
4339 * @widget: a #GtkWidget
4340 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
4341 * when it is allocated to a new size. Otherwise, only the
4342 * new portion of the widget will be redrawn.
4344 * Sets whether the entire widget is queued for drawing when its size
4345 * allocation changes. By default, this setting is %TRUE and
4346 * the entire widget is redrawn on every size change. If your widget
4347 * leaves the upper left unchanged when made bigger, turning this
4348 * setting on will improve performance.
4350 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
4351 * off all allocation on resizing: the widget will not even redraw if
4352 * its position changes; this is to allow containers that don't draw
4353 * anything to avoid excess invalidations. If you set this flag on a
4354 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
4355 * you are responsible for invalidating both the old and new allocation
4356 * of the widget when the widget is moved and responsible for invalidating
4357 * regions newly when the widget increases size.
4360 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
4361 gboolean redraw_on_allocate)
4363 g_return_if_fail (GTK_IS_WIDGET (widget));
4365 if (redraw_on_allocate)
4366 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
4368 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
4372 * gtk_widget_set_sensitive:
4373 * @widget: a #GtkWidget
4374 * @sensitive: %TRUE to make the widget sensitive
4376 * Sets the sensitivity of a widget. A widget is sensitive if the user
4377 * can interact with it. Insensitive widgets are "grayed out" and the
4378 * user can't interact with them. Insensitive widgets are known as
4379 * "inactive", "disabled", or "ghosted" in some other toolkits.
4383 gtk_widget_set_sensitive (GtkWidget *widget,
4388 g_return_if_fail (GTK_IS_WIDGET (widget));
4390 sensitive = (sensitive != FALSE);
4392 if (sensitive == (GTK_WIDGET_SENSITIVE (widget) != FALSE))
4397 GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE);
4398 data.state = GTK_WIDGET_SAVED_STATE (widget);
4402 GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE);
4403 data.state = GTK_WIDGET_STATE (widget);
4405 data.state_restoration = TRUE;
4406 data.use_forall = TRUE;
4409 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
4411 data.parent_sensitive = TRUE;
4413 gtk_widget_propagate_state (widget, &data);
4414 if (GTK_WIDGET_DRAWABLE (widget))
4415 gtk_widget_queue_draw (widget);
4417 g_object_notify (G_OBJECT (widget), "sensitive");
4421 * gtk_widget_set_parent:
4422 * @widget: a #GtkWidget
4423 * @parent: parent container
4425 * This function is useful only when implementing subclasses of #GtkContainer.
4426 * Sets the container as the parent of @widget, and takes care of
4427 * some details such as updating the state and style of the child
4428 * to reflect its new location. The opposite function is
4429 * gtk_widget_unparent().
4433 gtk_widget_set_parent (GtkWidget *widget,
4438 g_return_if_fail (GTK_IS_WIDGET (widget));
4439 g_return_if_fail (GTK_IS_WIDGET (parent));
4440 g_return_if_fail (widget != parent);
4441 if (widget->parent != NULL)
4443 g_warning ("Can't set a parent on widget which has a parent\n");
4446 if (GTK_WIDGET_TOPLEVEL (widget))
4448 g_warning ("Can't set a parent on a toplevel widget\n");
4452 /* keep this function in sync with gtk_menu_attach_to_widget()
4455 g_object_ref (widget);
4456 gtk_object_sink (GTK_OBJECT (widget));
4457 widget->parent = parent;
4459 if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
4460 data.state = GTK_WIDGET_STATE (parent);
4462 data.state = GTK_WIDGET_STATE (widget);
4463 data.state_restoration = FALSE;
4464 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (parent) != FALSE);
4465 data.use_forall = GTK_WIDGET_IS_SENSITIVE (parent) != GTK_WIDGET_IS_SENSITIVE (widget);
4467 gtk_widget_propagate_state (widget, &data);
4469 gtk_widget_reset_rc_styles (widget);
4471 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
4472 if (GTK_WIDGET_ANCHORED (widget->parent))
4473 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
4474 g_object_notify (G_OBJECT (widget), "parent");
4476 /* Enforce realized/mapped invariants
4478 if (GTK_WIDGET_REALIZED (widget->parent))
4479 gtk_widget_realize (widget);
4481 if (GTK_WIDGET_VISIBLE (widget->parent) &&
4482 GTK_WIDGET_VISIBLE (widget))
4484 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
4485 GTK_WIDGET_MAPPED (widget->parent))
4486 gtk_widget_map (widget);
4488 gtk_widget_queue_resize (widget);
4493 * gtk_widget_get_parent:
4494 * @widget: a #GtkWidget
4496 * Returns the parent container of @widget.
4498 * Return value: the parent container of @widget, or %NULL
4501 gtk_widget_get_parent (GtkWidget *widget)
4503 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4505 return widget->parent;
4508 /*****************************************
4510 * see docs/styles.txt
4511 *****************************************/
4514 * gtk_widget_set_style:
4515 * @widget: a #GtkWidget
4516 * @style: a #GtkStyle, or %NULL to remove the effect of a previous
4517 * gtk_widget_set_style() and go back to the default style
4519 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
4520 * want to use this function; it interacts badly with themes, because
4521 * themes work by replacing the #GtkStyle. Instead, use
4522 * gtk_widget_modify_style().
4526 gtk_widget_set_style (GtkWidget *widget,
4529 g_return_if_fail (GTK_IS_WIDGET (widget));
4533 gboolean initial_emission;
4535 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
4537 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
4538 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
4540 gtk_widget_set_style_internal (widget, style, initial_emission);
4544 if (GTK_WIDGET_USER_STYLE (widget))
4545 gtk_widget_reset_rc_style (widget);
4550 * gtk_widget_ensure_style:
4551 * @widget: a #GtkWidget
4553 * Ensures that @widget has a style (@widget->style). Not a very useful
4554 * function; most of the time, if you want the style, the widget is
4555 * realized, and realized widgets are guaranteed to have a style
4560 gtk_widget_ensure_style (GtkWidget *widget)
4562 g_return_if_fail (GTK_IS_WIDGET (widget));
4564 if (!GTK_WIDGET_USER_STYLE (widget) &&
4565 !GTK_WIDGET_RC_STYLE (widget))
4566 gtk_widget_reset_rc_style (widget);
4569 /* Look up the RC style for this widget, unsetting any user style that
4570 * may be in effect currently
4573 gtk_widget_reset_rc_style (GtkWidget *widget)
4575 GtkStyle *new_style = NULL;
4576 gboolean initial_emission;
4578 g_return_if_fail (GTK_IS_WIDGET (widget));
4580 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
4582 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
4583 GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
4585 if (gtk_widget_has_screen (widget))
4586 new_style = gtk_rc_get_style (widget);
4588 new_style = gtk_widget_get_default_style ();
4590 if (initial_emission || new_style != widget->style)
4591 gtk_widget_set_style_internal (widget, new_style, initial_emission);
4595 * gtk_widget_get_style:
4596 * @widget: a #GtkWidget
4598 * Simply an accessor function that returns @widget->style.
4600 * Return value: the widget's #GtkStyle
4603 gtk_widget_get_style (GtkWidget *widget)
4605 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4607 return widget->style;
4611 * gtk_widget_modify_style:
4612 * @widget: a #GtkWidget
4613 * @style: the #GtkRcStyle holding the style modifications
4615 * Modifies style values on the widget. Modifications made using this
4616 * technique take precedence over style values set via an RC file,
4617 * however, they will be overriden if a style is explicitely set on
4618 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
4619 * is designed so each field can either be set or unset, so it is
4620 * possible, using this function, to modify some style values and
4621 * leave the others unchanged.
4623 * Note that modifications made with this function are not cumulative
4624 * with previous calls to gtk_widget_modify_style() or with such
4625 * functions as gtk_widget_modify_fg(). If you wish to retain
4626 * previous values, you must first call gtk_widget_get_modifier_style(),
4627 * make your modifications to the returned style, then call
4628 * gtk_widget_modify_style() with that style. On the other hand,
4629 * if you first call gtk_widget_modify_style(), subsequent calls
4630 * to such functions gtk_widget_modify_fg() will have a cumulative
4631 * effect with the initial modifications.
4634 gtk_widget_modify_style (GtkWidget *widget,
4637 GtkRcStyle *old_style;
4639 g_return_if_fail (GTK_IS_WIDGET (widget));
4640 g_return_if_fail (GTK_IS_RC_STYLE (style));
4642 old_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
4644 g_object_set_qdata_full (G_OBJECT (widget),
4646 gtk_rc_style_copy (style),
4647 (GDestroyNotify) gtk_rc_style_unref);
4649 /* note that "style" may be invalid here if it was the old
4650 * modifier style and the only reference was our own.
4653 if (GTK_WIDGET_RC_STYLE (widget))
4654 gtk_widget_reset_rc_style (widget);
4658 * gtk_widget_get_modifier_style:
4659 * @widget: a #GtkWidget
4661 * Returns the current modifier style for the widget. (As set by
4662 * gtk_widget_modify_style().) If no style has previously set, a new
4663 * #GtkRcStyle will be created with all values unset, and set as the
4664 * modifier style for the widget. If you make changes to this rc
4665 * style, you must call gtk_widget_modify_style(), passing in the
4666 * returned rc style, to make sure that your changes take effect.
4668 * Caution: passing the style back to gtk_widget_modify_style() will
4669 * normally end up destroying it, because gtk_widget_modify_style() copies
4670 * the passed-in style and sets the copy as the new modifier style,
4671 * thus dropping any reference to the old modifier style. Add a reference
4672 * to the modifier style if you want to keep it alive.
4674 * Return value: the modifier style for the widget. This rc style is
4675 * owned by the widget. If you want to keep a pointer to value this
4676 * around, you must add a refcount using gtk_rc_style_ref().
4679 gtk_widget_get_modifier_style (GtkWidget *widget)
4681 GtkRcStyle *rc_style;
4683 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4685 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
4689 rc_style = gtk_rc_style_new ();
4690 g_object_set_qdata_full (G_OBJECT (widget),
4693 (GDestroyNotify) gtk_rc_style_unref);
4700 gtk_widget_modify_color_component (GtkWidget *widget,
4701 GtkRcFlags component,
4703 const GdkColor *color)
4705 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
4712 rc_style->fg[state] = *color;
4715 rc_style->bg[state] = *color;
4718 rc_style->text[state] = *color;
4721 rc_style->base[state] = *color;
4724 g_assert_not_reached();
4727 rc_style->color_flags[state] |= component;
4730 rc_style->color_flags[state] &= ~component;
4732 gtk_widget_modify_style (widget, rc_style);
4736 * gtk_widget_modify_fg:
4737 * @widget: a #GtkWidget.
4738 * @state: the state for which to set the foreground color.
4739 * @color: the color to assign (does not need to be allocated),
4740 * or %NULL to undo the effect of previous calls to
4741 * of gtk_widget_modify_fg().
4743 * Sets the foreground color for a widget in a particular state. All
4744 * other style values are left untouched. See also
4745 * gtk_widget_modify_style().
4748 gtk_widget_modify_fg (GtkWidget *widget,
4750 const GdkColor *color)
4752 g_return_if_fail (GTK_IS_WIDGET (widget));
4753 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4755 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
4759 * gtk_widget_modify_bg:
4760 * @widget: a #GtkWidget.
4761 * @state: the state for which to set the background color.
4762 * @color: the color to assign (does not need to be allocated),
4763 * or %NULL to undo the effect of previous calls to
4764 * of gtk_widget_modify_bg().
4766 * Sets the background color for a widget in a particular state. All
4767 * other style values are left untouched. See also
4768 * gtk_widget_modify_style().
4771 gtk_widget_modify_bg (GtkWidget *widget,
4773 const GdkColor *color)
4775 g_return_if_fail (GTK_IS_WIDGET (widget));
4776 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4778 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
4782 * gtk_widget_modify_text:
4783 * @widget: a #GtkWidget.
4784 * @state: the state for which to set the text color.
4785 * @color: the color to assign (does not need to be allocated),
4786 * or %NULL to undo the effect of previous calls to
4787 * of gtk_widget_modify_text().
4789 * Sets the text color for a widget in a particular state. All other
4790 * style values are left untouched. The text color is the foreground
4791 * color used along with the base color (see gtk_widget_modify_base())
4792 * for widgets such as #GtkEntry and #GtkTextView. See also
4793 * gtk_widget_modify_style().
4796 gtk_widget_modify_text (GtkWidget *widget,
4798 const GdkColor *color)
4800 g_return_if_fail (GTK_IS_WIDGET (widget));
4801 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4803 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
4807 * gtk_widget_modify_base:
4808 * @widget: a #GtkWidget.
4809 * @state: the state for which to set the base color.
4810 * @color: the color to assign (does not need to be allocated),
4811 * or %NULL to undo the effect of previous calls to
4812 * of gtk_widget_modify_base().
4814 * Sets the base color for a widget in a particular state.
4815 * All other style values are left untouched. The base color
4816 * is the background color used along with the text color
4817 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
4818 * and #GtkTextView. See also gtk_widget_modify_style().
4821 gtk_widget_modify_base (GtkWidget *widget,
4823 const GdkColor *color)
4825 g_return_if_fail (GTK_IS_WIDGET (widget));
4826 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4828 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
4832 * gtk_widget_modify_font:
4833 * @widget: a #GtkWidget
4834 * @font_desc: the font description to use, or %NULL to undo
4835 * the effect of previous calls to gtk_widget_modify_font().
4837 * Sets the font to use for a widget. All other style values are left
4838 * untouched. See also gtk_widget_modify_style().
4841 gtk_widget_modify_font (GtkWidget *widget,
4842 PangoFontDescription *font_desc)
4844 GtkRcStyle *rc_style;
4846 g_return_if_fail (GTK_IS_WIDGET (widget));
4848 rc_style = gtk_widget_get_modifier_style (widget);
4850 if (rc_style->font_desc)
4851 pango_font_description_free (rc_style->font_desc);
4854 rc_style->font_desc = pango_font_description_copy (font_desc);
4856 rc_style->font_desc = NULL;
4858 gtk_widget_modify_style (widget, rc_style);
4862 gtk_widget_direction_changed (GtkWidget *widget,
4863 GtkTextDirection previous_direction)
4865 gtk_widget_queue_resize (widget);
4869 gtk_widget_style_set (GtkWidget *widget,
4870 GtkStyle *previous_style)
4872 if (GTK_WIDGET_REALIZED (widget) &&
4873 !GTK_WIDGET_NO_WINDOW (widget))
4874 gtk_style_set_background (widget->style, widget->window, widget->state);
4878 gtk_widget_set_style_internal (GtkWidget *widget,
4880 gboolean initial_emission)
4882 g_object_ref (widget);
4883 g_object_freeze_notify (G_OBJECT (widget));
4885 if (widget->style != style || initial_emission)
4887 PangoContext *context = gtk_widget_peek_pango_context (widget);
4889 pango_context_set_font_description (context, style->font_desc);
4892 if (widget->style != style)
4894 GtkStyle *previous_style;
4896 if (GTK_WIDGET_REALIZED (widget))
4898 gtk_widget_reset_shapes (widget);
4899 gtk_style_detach (widget->style);
4902 previous_style = widget->style;
4903 widget->style = style;
4904 g_object_ref (widget->style);
4906 if (GTK_WIDGET_REALIZED (widget))
4907 widget->style = gtk_style_attach (widget->style, widget->window);
4909 g_signal_emit (widget,
4910 widget_signals[STYLE_SET],
4912 initial_emission ? NULL : previous_style);
4913 g_object_unref (previous_style);
4915 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
4916 gtk_widget_queue_resize (widget);
4918 else if (initial_emission)
4919 g_signal_emit (widget,
4920 widget_signals[STYLE_SET],
4923 g_object_notify (G_OBJECT (widget), "style");
4924 g_object_thaw_notify (G_OBJECT (widget));
4925 g_object_unref (widget);
4929 GtkWidget *previous_toplevel;
4930 GdkScreen *previous_screen;
4931 GdkScreen *new_screen;
4932 } HierarchyChangedInfo;
4935 do_screen_change (GtkWidget *widget,
4936 GdkScreen *old_screen,
4937 GdkScreen *new_screen)
4939 if (old_screen != new_screen)
4943 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
4945 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
4948 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
4953 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
4954 gpointer client_data)
4956 gboolean new_anchored;
4957 HierarchyChangedInfo *info = client_data;
4959 new_anchored = GTK_WIDGET_TOPLEVEL (widget) ||
4960 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
4962 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
4964 g_object_ref (widget);
4967 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
4969 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
4971 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
4972 do_screen_change (widget, info->previous_screen, info->new_screen);
4974 if (GTK_IS_CONTAINER (widget))
4975 gtk_container_forall (GTK_CONTAINER (widget),
4976 gtk_widget_propagate_hierarchy_changed_recurse,
4979 g_object_unref (widget);
4984 * _gtk_widget_propagate_hierarchy_changed:
4985 * @widget: a #GtkWidget
4986 * @previous_toplevel: Previous toplevel
4988 * Propagates changes in the anchored state to a widget and all
4989 * children, unsetting or setting the %ANCHORED flag, and
4990 * emitting ::hierarchy_changed.
4993 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
4994 GtkWidget *previous_toplevel)
4996 HierarchyChangedInfo info;
4998 info.previous_toplevel = previous_toplevel;
4999 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
5001 if (GTK_WIDGET_TOPLEVEL (widget) ||
5002 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
5003 info.new_screen = gtk_widget_get_screen (widget);
5005 info.new_screen = NULL;
5007 if (info.previous_screen)
5008 g_object_ref (info.previous_screen);
5009 if (previous_toplevel)
5010 g_object_ref (previous_toplevel);
5012 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
5014 if (previous_toplevel)
5015 g_object_unref (previous_toplevel);
5016 if (info.previous_screen)
5017 g_object_unref (info.previous_screen);
5021 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
5022 gpointer client_data)
5024 HierarchyChangedInfo *info = client_data;
5026 g_object_ref (widget);
5028 do_screen_change (widget, info->previous_screen, info->new_screen);
5030 if (GTK_IS_CONTAINER (widget))
5031 gtk_container_forall (GTK_CONTAINER (widget),
5032 gtk_widget_propagate_screen_changed_recurse,
5035 g_object_unref (widget);
5039 * _gtk_widget_propagate_screen_changed:
5040 * @widget: a #GtkWidget
5041 * @previous_screen: Previous screen
5043 * Propagates changes in the screen for a widget to all
5044 * children, emitting ::screen_changed.
5047 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
5048 GdkScreen *previous_screen)
5050 HierarchyChangedInfo info;
5052 info.previous_screen = previous_screen;
5053 info.new_screen = gtk_widget_get_screen (widget);
5055 if (previous_screen)
5056 g_object_ref (previous_screen);
5058 gtk_widget_propagate_screen_changed_recurse (widget, &info);
5060 if (previous_screen)
5061 g_object_unref (previous_screen);
5065 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
5067 if (GTK_WIDGET_RC_STYLE (widget))
5068 gtk_widget_reset_rc_style (widget);
5070 if (GTK_IS_CONTAINER (widget))
5071 gtk_container_forall (GTK_CONTAINER (widget),
5072 reset_rc_styles_recurse,
5077 gtk_widget_reset_rc_styles (GtkWidget *widget)
5079 g_return_if_fail (GTK_IS_WIDGET (widget));
5081 reset_rc_styles_recurse (widget, NULL);
5085 * gtk_widget_get_default_style:
5087 * Returns the default style used by all widgets initially.
5089 * Returns: the default style. This #GtkStyle object is owned by GTK+ and
5090 * should not be modified or freed.
5093 gtk_widget_get_default_style (void)
5095 if (!gtk_default_style)
5097 gtk_default_style = gtk_style_new ();
5098 g_object_ref (gtk_default_style);
5101 return gtk_default_style;
5104 static PangoContext *
5105 gtk_widget_peek_pango_context (GtkWidget *widget)
5107 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
5111 * gtk_widget_get_pango_context:
5112 * @widget: a #GtkWidget
5114 * Gets a #PangoContext with the appropriate colormap, font description
5115 * and base direction for this widget. Unlike the context returned
5116 * by gtk_widget_create_pango_context(), this context is owned by
5117 * the widget (it can be used until the screen for the widget changes
5118 * or the widget is removed from its toplevel), and will be updated to
5119 * match any changes to the widget's attributes.
5121 * If you create and keep a #PangoLayout using this context, you must
5122 * deal with changes to the context by calling pango_layout_context_changed()
5123 * on the layout in response to the ::style-set and ::direction-changed signals
5126 * Return value: the #PangoContext for the widget.
5129 gtk_widget_get_pango_context (GtkWidget *widget)
5131 PangoContext *context;
5133 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5135 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
5138 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
5139 g_object_set_qdata_full (G_OBJECT (widget),
5140 quark_pango_context,
5149 * gtk_widget_create_pango_context:
5150 * @widget: a #GtkWidget
5152 * Creates a new #PangoContext with the appropriate colormap,
5153 * font description, and base direction for drawing text for
5154 * this widget. See also gtk_widget_get_pango_context().
5156 * Return value: the new #PangoContext
5159 gtk_widget_create_pango_context (GtkWidget *widget)
5162 PangoContext *context;
5164 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5166 screen = gtk_widget_get_screen_unchecked (widget);
5169 GTK_NOTE (MULTIHEAD,
5170 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
5172 screen = gdk_screen_get_default ();
5175 context = gdk_pango_context_get_for_screen (screen);
5177 pango_context_set_base_dir (context,
5178 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
5179 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
5180 pango_context_set_font_description (context, widget->style->font_desc);
5181 pango_context_set_language (context, gtk_get_default_language ());
5187 * gtk_widget_create_pango_layout:
5188 * @widget: a #GtkWidget
5189 * @text: text to set on the layout (can be %NULL)
5191 * Creates a new #PangoLayout with the appropriate colormap,
5192 * font description, and base direction for drawing text for
5195 * If you keep a #PangoLayout created in this way around, in order
5196 * notify the layout of changes to the base direction or font of this
5197 * widget, you must call pango_layout_context_changed() in response to
5198 * the ::style-set and ::direction-changed signals for the widget.
5200 * Return value: the new #PangoLayout
5203 gtk_widget_create_pango_layout (GtkWidget *widget,
5206 PangoLayout *layout;
5207 PangoContext *context;
5209 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5211 context = gtk_widget_get_pango_context (widget);
5212 layout = pango_layout_new (context);
5215 pango_layout_set_text (layout, text, -1);
5221 * gtk_widget_render_icon:
5222 * @widget: a #GtkWidget
5223 * @stock_id: a stock ID
5224 * @size: a stock size. A size of (GtkIconSize)-1 means render at
5225 * the size of the source and don't scale (if there are multiple
5226 * source sizes, GTK+ picks one of the available sizes).
5227 * @detail: render detail to pass to theme engine
5229 * A convenience function that uses the theme engine and RC file
5230 * settings for @widget to look up @stock_id and render it to
5231 * a pixbuf. @stock_id should be a stock icon ID such as
5232 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
5233 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
5234 * identifies the widget or code doing the rendering, so that
5235 * theme engines can special-case rendering for that widget or code.
5237 * The pixels in the returned #GdkPixbuf are shared with the rest of
5238 * the application and should not be modified. The pixbuf should be freed
5239 * after use with g_object_unref().
5241 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
5244 gtk_widget_render_icon (GtkWidget *widget,
5245 const gchar *stock_id,
5247 const gchar *detail)
5249 GtkIconSet *icon_set;
5252 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5253 g_return_val_if_fail (stock_id != NULL, NULL);
5254 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
5256 gtk_widget_ensure_style (widget);
5258 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
5260 if (icon_set == NULL)
5263 retval = gtk_icon_set_render_icon (icon_set,
5265 gtk_widget_get_direction (widget),
5266 GTK_WIDGET_STATE (widget),
5275 * gtk_widget_set_parent_window:
5276 * @widget: a #GtkWidget.
5277 * @parent_window: the new parent window.
5279 * Sets a non default parent window for @widget.
5282 gtk_widget_set_parent_window (GtkWidget *widget,
5283 GdkWindow *parent_window)
5285 GdkWindow *old_parent_window;
5287 g_return_if_fail (GTK_IS_WIDGET (widget));
5289 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
5290 quark_parent_window);
5292 if (parent_window != old_parent_window)
5294 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
5296 if (old_parent_window)
5297 g_object_unref (old_parent_window);
5299 g_object_ref (parent_window);
5305 * gtk_widget_set_child_visible:
5306 * @widget: a #GtkWidget
5307 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
5309 * Sets whether @widget should be mapped along with its when its parent
5310 * is mapped and @widget has been shown with gtk_widget_show().
5312 * The child visibility can be set for widget before it is added to
5313 * a container with gtk_widget_set_parent(), to avoid mapping
5314 * children unnecessary before immediately unmapping them. However
5315 * it will be reset to its default state of %TRUE when the widget
5316 * is removed from a container.
5318 * Note that changing the child visibility of a widget does not
5319 * queue a resize on the widget. Most of the time, the size of
5320 * a widget is computed from all visible children, whether or
5321 * not they are mapped. If this is not the case, the container
5322 * can queue a resize itself.
5324 * This function is only useful for container implementations and
5325 * never should be called by an application.
5328 gtk_widget_set_child_visible (GtkWidget *widget,
5329 gboolean is_visible)
5331 g_return_if_fail (GTK_IS_WIDGET (widget));
5332 g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
5334 g_object_ref (widget);
5337 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
5340 GtkWidget *toplevel;
5342 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
5344 toplevel = gtk_widget_get_toplevel (widget);
5345 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
5346 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
5349 if (widget->parent && GTK_WIDGET_REALIZED (widget->parent))
5351 if (GTK_WIDGET_MAPPED (widget->parent) &&
5352 GTK_WIDGET_CHILD_VISIBLE (widget) &&
5353 GTK_WIDGET_VISIBLE (widget))
5354 gtk_widget_map (widget);
5356 gtk_widget_unmap (widget);
5359 g_object_unref (widget);
5363 * gtk_widget_get_child_visible:
5364 * @widget: a #GtkWidget
5366 * Gets the value set with gtk_widget_set_child_visible().
5367 * If you feel a need to use this function, your code probably
5368 * needs reorganization.
5370 * This function is only useful for container implementations and
5371 * never should be called by an application.
5373 * Return value: %TRUE if the widget is mapped with the parent.
5376 gtk_widget_get_child_visible (GtkWidget *widget)
5378 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5380 return GTK_WIDGET_CHILD_VISIBLE (widget);
5384 gtk_widget_get_screen_unchecked (GtkWidget *widget)
5386 GtkWidget *toplevel;
5388 toplevel = gtk_widget_get_toplevel (widget);
5390 if (GTK_WIDGET_TOPLEVEL (toplevel))
5392 if (GTK_IS_WINDOW (toplevel))
5393 return GTK_WINDOW (toplevel)->screen;
5394 else if (GTK_IS_INVISIBLE (toplevel))
5395 return GTK_INVISIBLE (widget)->screen;
5402 * gtk_widget_get_screen:
5403 * @widget: a #GtkWidget
5405 * Get the #GdkScreen from the toplevel window associated with
5406 * this widget. This function can only be called after the widget
5407 * has been added to a widget hierarchy with a #GtkWindow
5410 * In general, you should only create screen specific
5411 * resources when a widget has been realized, and you should
5412 * free those resources when the widget is unrealized.
5414 * Return value: the #GdkScreen for the toplevel for this widget.
5419 gtk_widget_get_screen (GtkWidget *widget)
5423 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5425 screen = gtk_widget_get_screen_unchecked (widget);
5432 g_warning (G_STRLOC ": Can't get associated screen"
5433 " for a widget unless it is inside a toplevel GtkWindow\n"
5434 " widget type is %s associated top level type is %s",
5435 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
5436 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
5438 return gdk_screen_get_default ();
5443 * gtk_widget_has_screen:
5444 * @widget: a #GtkWidget
5446 * Checks whether there is a #GdkScreen is associated with
5447 * this widget. All toplevel widgets have an associated
5448 * screen, and all widgets added into a heirarchy with a toplevel
5449 * window at the top.
5451 * Return value: %TRUE if there is a #GdkScreen associcated
5457 gtk_widget_has_screen (GtkWidget *widget)
5459 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5461 return (gtk_widget_get_screen_unchecked (widget) != NULL);
5465 * gtk_widget_get_display:
5466 * @widget: a #GtkWidget
5468 * Get the #GdkDisplay for the toplevel window associated with
5469 * this widget. This function can only be called after the widget
5470 * has been added to a widget hierarchy with a #GtkWindow at the top.
5472 * In general, you should only create display specific
5473 * resources when a widget has been realized, and you should
5474 * free those resources when the widget is unrealized.
5476 * Return value: the #GdkDisplay for the toplevel for this widget.
5481 gtk_widget_get_display (GtkWidget *widget)
5483 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5485 return gdk_screen_get_display (gtk_widget_get_screen (widget));
5489 * gtk_widget_get_root_window:
5490 * @widget: a #GtkWidget
5492 * Get the root window where this widget is located. This function can
5493 * only be called after the widget has been added to a widget
5494 * heirarchy with #GtkWindow at the top.
5496 * The root window is useful for such purposes as creating a popup
5497 * #GdkWindow associated with the window. In general, you should only
5498 * create display specific resources when a widget has been realized,
5499 * and you should free those resources when the widget is unrealized.
5501 * Return value: the #GdkWindow root window for the toplevel for this widget.
5506 gtk_widget_get_root_window (GtkWidget *widget)
5508 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5510 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
5514 * gtk_widget_get_parent_window:
5515 * @widget: a #GtkWidget.
5516 * @returns: the parent window of @widget.
5518 * Gets @widget's parent window.
5521 gtk_widget_get_parent_window (GtkWidget *widget)
5523 GdkWindow *parent_window;
5525 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5526 g_return_val_if_fail (widget->parent != NULL, NULL);
5528 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
5530 return (parent_window != NULL) ? parent_window : widget->parent->window;
5534 * gtk_widget_child_focus:
5535 * @widget: a #GtkWidget
5536 * @direction: direction of focus movement
5538 * This function is used by custom widget implementations; if you're
5539 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
5540 * to a particular widget, and gtk_container_set_focus_chain() to
5541 * change the focus tab order. So you may want to investigate those
5542 * functions instead.
5544 * gtk_widget_child_focus() is called by containers as the user moves
5545 * around the window using keyboard shortcuts. @direction indicates
5546 * what kind of motion is taking place (up, down, left, right, tab
5547 * forward, tab backward). gtk_widget_child_focus() invokes the
5548 * "focus" signal on #GtkWidget; widgets override the default handler
5549 * for this signal in order to implement appropriate focus behavior.
5551 * The "focus" default handler for a widget should return %TRUE if
5552 * moving in @direction left the focus on a focusable location inside
5553 * that widget, and %FALSE if moving in @direction moved the focus
5554 * outside the widget. If returning %TRUE, widgets normally
5555 * call gtk_widget_grab_focus() to place the focus accordingly;
5556 * if returning %FALSE, they don't modify the current focus location.
5558 * This function replaces gtk_container_focus() from GTK+ 1.2. It was
5559 * necessary to check that the child was visible, sensitive, and
5560 * focusable before calling
5561 * gtk_container_focus(). gtk_widget_child_focus() returns %FALSE if
5562 * the widget is not currently in a focusable state, so there's no
5563 * need for those checks.
5565 * Return value: %TRUE if focus ended up inside @widget
5568 gtk_widget_child_focus (GtkWidget *widget,
5569 GtkDirectionType direction)
5571 gboolean return_val;
5573 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5575 if (!GTK_WIDGET_VISIBLE (widget) ||
5576 !GTK_WIDGET_IS_SENSITIVE (widget))
5579 /* child widgets must set CAN_FOCUS, containers
5580 * don't have to though.
5582 if (!GTK_IS_CONTAINER (widget) &&
5583 !GTK_WIDGET_CAN_FOCUS (widget))
5586 g_signal_emit (widget,
5587 widget_signals[FOCUS],
5589 direction, &return_val);
5595 * gtk_widget_set_uposition:
5596 * @widget: a #GtkWidget
5597 * @x: x position; -1 to unset x; -2 to leave x unchanged
5598 * @y: y position; -1 to unset y; -2 to leave y unchanged
5601 * Sets the position of a widget. The funny "u" in the name comes from
5602 * the "user position" hint specified by the X Window System, and
5603 * exists for legacy reasons. This function doesn't work if a widget
5604 * is inside a container; it's only really useful on #GtkWindow.
5606 * Don't use this function to center dialogs over the main application
5607 * window; most window managers will do the centering on your behalf
5608 * if you call gtk_window_set_transient_for(), and it's really not
5609 * possible to get the centering to work correctly in all cases from
5610 * application code. But if you insist, use gtk_window_set_position()
5611 * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
5614 * Note that although @x and @y can be individually unset, the position
5615 * is not honoured unless both @x and @y are set.
5618 gtk_widget_set_uposition (GtkWidget *widget,
5622 /* FIXME this function is the only place that aux_info->x and
5623 * aux_info->y are even used I believe, and this function is
5624 * deprecated. Should be cleaned up.
5626 * (Actually, size_allocate uses them) -Yosh
5629 GtkWidgetAuxInfo *aux_info;
5631 g_return_if_fail (GTK_IS_WIDGET (widget));
5633 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
5638 aux_info->x_set = FALSE;
5641 aux_info->x_set = TRUE;
5649 aux_info->y_set = FALSE;
5652 aux_info->y_set = TRUE;
5657 if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
5658 _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
5660 if (GTK_WIDGET_VISIBLE (widget) && widget->parent)
5661 gtk_widget_size_allocate (widget, &widget->allocation);
5665 gtk_widget_set_usize_internal (GtkWidget *widget,
5669 GtkWidgetAuxInfo *aux_info;
5670 gboolean changed = FALSE;
5672 g_return_if_fail (GTK_IS_WIDGET (widget));
5674 g_object_freeze_notify (G_OBJECT (widget));
5676 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
5678 if (width > -2 && aux_info->width != width)
5680 g_object_notify (G_OBJECT (widget), "width-request");
5681 aux_info->width = width;
5684 if (height > -2 && aux_info->height != height)
5686 g_object_notify (G_OBJECT (widget), "height-request");
5687 aux_info->height = height;
5691 if (GTK_WIDGET_VISIBLE (widget) && changed)
5692 gtk_widget_queue_resize (widget);
5694 g_object_thaw_notify (G_OBJECT (widget));
5698 * gtk_widget_set_usize:
5699 * @widget: a #GtkWidget
5700 * @width: minimum width, or -1 to unset
5701 * @height: minimum height, or -1 to unset
5703 * Sets the minimum size of a widget; that is, the widget's size
5704 * request will be @width by @height. You can use this function to
5705 * force a widget to be either larger or smaller than it is. The
5706 * strange "usize" name dates from the early days of GTK+, and derives
5707 * from X Window System terminology. In many cases,
5708 * gtk_window_set_default_size() is a better choice for toplevel
5709 * windows than this function; setting the default size will still
5710 * allow users to shrink the window. Setting the usize will force them
5711 * to leave the window at least as large as the usize. When dealing
5712 * with window sizes, gtk_window_set_geometry_hints() can be a useful
5715 * Note the inherent danger of setting any fixed size - themes,
5716 * translations into other languages, different fonts, and user action
5717 * can all change the appropriate size for a given widget. So, it's
5718 * basically impossible to hardcode a size that will always be
5721 * @Deprecated: Use gtk_widget_set_size_request() instead.
5724 gtk_widget_set_usize (GtkWidget *widget,
5728 g_return_if_fail (GTK_IS_WIDGET (widget));
5730 gtk_widget_set_usize_internal (widget, width, height);
5734 * gtk_widget_set_size_request:
5735 * @widget: a #GtkWidget
5736 * @width: width @widget should request, or -1 to unset
5737 * @height: height @widget should request, or -1 to unset
5739 * Sets the minimum size of a widget; that is, the widget's size
5740 * request will be @width by @height. You can use this function to
5741 * force a widget to be either larger or smaller than it normally
5744 * In most cases, gtk_window_set_default_size() is a better choice for
5745 * toplevel windows than this function; setting the default size will
5746 * still allow users to shrink the window. Setting the size request
5747 * will force them to leave the window at least as large as the size
5748 * request. When dealing with window sizes,
5749 * gtk_window_set_geometry_hints() can be a useful function as well.
5751 * Note the inherent danger of setting any fixed size - themes,
5752 * translations into other languages, different fonts, and user action
5753 * can all change the appropriate size for a given widget. So, it's
5754 * basically impossible to hardcode a size that will always be
5757 * The size request of a widget is the smallest size a widget can
5758 * accept while still functioning well and drawing itself correctly.
5759 * However in some strange cases a widget may be allocated less than
5760 * its requested size, and in many cases a widget may be allocated more
5761 * space than it requested.
5763 * If the size request in a given direction is -1 (unset), then
5764 * the "natural" size request of the widget will be used instead.
5766 * Widgets can't actually be allocated a size less than 1 by 1, but
5767 * you can pass 0,0 to this function to mean "as small as possible."
5770 gtk_widget_set_size_request (GtkWidget *widget,
5774 g_return_if_fail (GTK_IS_WIDGET (widget));
5775 g_return_if_fail (width >= -1);
5776 g_return_if_fail (height >= -1);
5783 gtk_widget_set_usize_internal (widget, width, height);
5788 * gtk_widget_get_size_request:
5789 * @widget: a #GtkWidget
5790 * @width: return location for width, or %NULL
5791 * @height: return location for height, or %NULL
5793 * Gets the size request that was explicitly set for the widget using
5794 * gtk_widget_set_size_request(). A value of -1 stored in @width or
5795 * @height indicates that that dimension has not been set explicitly
5796 * and the natural requisition of the widget will be used intead. See
5797 * gtk_widget_set_size_request(). To get the size a widget will
5798 * actually use, call gtk_widget_size_request() instead of
5804 gtk_widget_get_size_request (GtkWidget *widget,
5808 GtkWidgetAuxInfo *aux_info;
5810 g_return_if_fail (GTK_IS_WIDGET (widget));
5812 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
5815 *width = aux_info ? aux_info->width : -1;
5818 *height = aux_info ? aux_info->height : -1;
5822 * gtk_widget_set_events:
5823 * @widget: a #GtkWidget
5824 * @events: event mask
5826 * Sets the event mask (see #GdkEventMask) for a widget. The event
5827 * mask determines which events a widget will receive. Keep in mind
5828 * that different widgets have different default event masks, and by
5829 * changing the event mask you may disrupt a widget's functionality,
5830 * so be careful. This function must be called while a widget is
5831 * unrealized. Consider gtk_widget_add_events() for widgets that are
5832 * already realized, or if you want to preserve the existing event
5833 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
5834 * to get events on those widgets, place them inside a #GtkEventBox
5835 * and receive events on the event box.
5839 gtk_widget_set_events (GtkWidget *widget,
5844 g_return_if_fail (GTK_IS_WIDGET (widget));
5845 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
5847 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
5852 eventp = g_new (gint, 1);
5855 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, eventp);
5860 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, NULL);
5863 g_object_notify (G_OBJECT (widget), "events");
5867 gtk_widget_add_events_internal (GtkWidget *widget,
5873 for (l = window_list; l != NULL; l = l->next)
5875 GdkWindow *window = l->data;
5878 gdk_window_get_user_data (window, &user_data);
5879 if (user_data == widget)
5883 gdk_window_set_events (window, gdk_window_get_events (window) | events);
5885 children = gdk_window_get_children (window);
5886 gtk_widget_add_events_internal (widget, events, children);
5887 g_list_free (children);
5893 * gtk_widget_add_events:
5894 * @widget: a #GtkWidget
5895 * @events: an event mask, see #GdkEventMask
5897 * Adds the events in the bitfield @events to the event mask for
5898 * @widget. See gtk_widget_set_events() for details.
5902 gtk_widget_add_events (GtkWidget *widget,
5907 g_return_if_fail (GTK_IS_WIDGET (widget));
5909 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
5915 eventp = g_new (gint, 1);
5920 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, eventp);
5925 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, NULL);
5928 if (GTK_WIDGET_REALIZED (widget))
5932 if (GTK_WIDGET_NO_WINDOW (widget))
5933 window_list = gdk_window_get_children (widget->window);
5935 window_list = g_list_prepend (NULL, widget->window);
5937 gtk_widget_add_events_internal (widget, events, window_list);
5939 g_list_free (window_list);
5942 g_object_notify (G_OBJECT (widget), "events");
5946 * gtk_widget_set_extension_events:
5947 * @widget: a #GtkWidget
5948 * @mode: bitfield of extension events to receive
5950 * Sets the extension events mask to @mode. See #GdkExtensionMode
5951 * and gdk_input_set_extension_events().
5955 gtk_widget_set_extension_events (GtkWidget *widget,
5956 GdkExtensionMode mode)
5958 GdkExtensionMode *modep;
5960 g_return_if_fail (GTK_IS_WIDGET (widget));
5962 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
5965 modep = g_new (GdkExtensionMode, 1);
5968 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode, modep);
5969 g_object_notify (G_OBJECT (widget), "extension-events");
5973 * gtk_widget_get_toplevel:
5974 * @widget: a #GtkWidget
5976 * This function returns the topmost widget in the container hierarchy
5977 * @widget is a part of. If @widget has no parent widgets, it will be
5978 * returned as the topmost widget. No reference will be added to the
5979 * returned widget; it should not be unreferenced.
5981 * Note the difference in behavior vs. gtk_widget_get_ancestor();
5982 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
5984 * %NULL if @widget wasn't inside a toplevel window, and if the
5985 * window was inside a #GtkWindow-derived widget which was in turn
5986 * inside the toplevel #GtkWindow. While the second case may
5987 * seem unlikely, it actually happens when a #GtkPlug is embedded
5988 * inside a #GtkSocket within the same application.
5990 * To reliably find the toplevel #GtkWindow, use
5991 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
5992 * is set on the result.
5993 * <informalexample><programlisting>
5994 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5995 * if (GTK_WIDGET_TOPLEVEL (toplevel))
5997 * [ Perform action on toplevel. ]
5999 * </programlisting></informalexample>
6001 * Return value: the topmost ancestor of @widget, or @widget itself if there's no ancestor.
6004 gtk_widget_get_toplevel (GtkWidget *widget)
6006 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6008 while (widget->parent)
6009 widget = widget->parent;
6015 * gtk_widget_get_ancestor:
6016 * @widget: a #GtkWidget
6017 * @widget_type: ancestor type
6019 * Gets the first ancestor of @widget with type @widget_type. For example,
6020 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets the
6021 * first #GtkBox that's
6022 * an ancestor of @widget. No reference will be added to the returned widget;
6023 * it should not be unreferenced. See note about checking for a toplevel
6024 * #GtkWindow in the docs for gtk_widget_get_toplevel().
6026 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
6027 * considers @widget to be an ancestor of itself.
6029 * Return value: the ancestor widget, or %NULL if not found
6032 gtk_widget_get_ancestor (GtkWidget *widget,
6035 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6037 while (widget && !g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))
6038 widget = widget->parent;
6040 if (!(widget && g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)))
6047 * gtk_widget_get_colormap:
6048 * @widget: a #GtkWidget
6050 * Gets the colormap that will be used to render @widget. No reference will
6051 * be added to the returned colormap; it should not be unreferenced.
6053 * Return value: the colormap used by @widget
6056 gtk_widget_get_colormap (GtkWidget *widget)
6058 GdkColormap *colormap;
6059 GtkWidget *tmp_widget;
6061 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6065 colormap = gdk_drawable_get_colormap (widget->window);
6066 /* If window was destroyed previously, we'll get NULL here */
6071 tmp_widget = widget;
6074 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
6078 tmp_widget= tmp_widget->parent;
6081 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
6085 * gtk_widget_get_visual:
6086 * @widget: a #GtkWidget
6088 * Gets the visual that will be used to render @widget.
6090 * Return value: the visual for @widget
6093 gtk_widget_get_visual (GtkWidget *widget)
6095 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6097 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
6101 * gtk_widget_get_settings:
6102 * @widget: a #GtkWidget
6104 * Gets the settings object holding the settings (global property
6105 * settings, RC file information, etc) used for this widget.
6107 * Note that this function can only be called when the #GtkWidget
6108 * is attached to a toplevel, since the settings object is specific
6109 * to a particular #GdkScreen.
6111 * Return value: the relevant #GtkSettings object
6114 gtk_widget_get_settings (GtkWidget *widget)
6116 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6118 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
6122 * gtk_widget_set_colormap:
6123 * @widget: a #GtkWidget
6124 * @colormap: a colormap
6126 * Sets the colormap for the widget to the given value. Widget must not
6127 * have been previously realized. This probably should only be used
6128 * from an <function>init()</function> function (i.e. from the constructor
6133 gtk_widget_set_colormap (GtkWidget *widget,
6134 GdkColormap *colormap)
6136 g_return_if_fail (GTK_IS_WIDGET (widget));
6137 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
6138 g_return_if_fail (GDK_IS_COLORMAP (colormap));
6140 g_object_ref (colormap);
6142 g_object_set_qdata_full (G_OBJECT (widget),
6149 * gtk_widget_get_events:
6150 * @widget: a #GtkWidget
6152 * Returns the event mask for the widget (a bitfield containing flags
6153 * from the #GdkEventMask enumeration). These are the events that the widget
6156 * Return value: event mask for @widget
6159 gtk_widget_get_events (GtkWidget *widget)
6163 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
6165 events = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
6173 * gtk_widget_get_extension_events:
6174 * @widget: a #GtkWidget
6176 * Retrieves the extension events the widget will receive; see
6177 * gdk_input_set_extension_events().
6179 * Return value: extension events for @widget
6182 gtk_widget_get_extension_events (GtkWidget *widget)
6184 GdkExtensionMode *mode;
6186 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
6188 mode = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
6196 * gtk_widget_get_pointer:
6197 * @widget: a #GtkWidget
6198 * @x: return location for the X coordinate, or %NULL
6199 * @y: return location for the Y coordinate, or %NULL
6201 * Obtains the location of the mouse pointer in widget coordinates.
6202 * Widget coordinates are a bit odd; for historical reasons, they are
6203 * defined as @widget->window coordinates for widgets that are not
6204 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
6205 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
6209 gtk_widget_get_pointer (GtkWidget *widget,
6213 g_return_if_fail (GTK_IS_WIDGET (widget));
6220 if (GTK_WIDGET_REALIZED (widget))
6222 gdk_window_get_pointer (widget->window, x, y, NULL);
6224 if (GTK_WIDGET_NO_WINDOW (widget))
6227 *x -= widget->allocation.x;
6229 *y -= widget->allocation.y;
6235 * gtk_widget_is_ancestor:
6236 * @widget: a #GtkWidget
6237 * @ancestor: another #GtkWidget
6239 * Determines whether @widget is somewhere inside @ancestor, possibly with
6240 * intermediate containers.
6242 * Return value: %TRUE if @ancestor contains @widget as a child, grandchild, great grandchild, etc.
6245 gtk_widget_is_ancestor (GtkWidget *widget,
6246 GtkWidget *ancestor)
6248 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6249 g_return_val_if_fail (ancestor != NULL, FALSE);
6253 if (widget->parent == ancestor)
6255 widget = widget->parent;
6261 static GQuark quark_composite_name = 0;
6264 * gtk_widget_set_composite_name:
6265 * @widget: a #GtkWidget.
6266 * @name: the name to set.
6268 * Sets a widgets composite name. The widget must be
6269 * a composite child of its parent; see gtk_widget_push_composite_child().
6272 gtk_widget_set_composite_name (GtkWidget *widget,
6275 g_return_if_fail (GTK_IS_WIDGET (widget));
6276 g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget));
6277 g_return_if_fail (name != NULL);
6279 if (!quark_composite_name)
6280 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
6282 g_object_set_qdata_full (G_OBJECT (widget),
6283 quark_composite_name,
6289 * gtk_widget_get_composite_name:
6290 * @widget: a #GtkWidget.
6291 * @returns: the composite name of @widget, or %NULL if @widget is not
6292 * a composite child. The string should not be freed when it is no
6295 * Obtains the composite name of a widget.
6298 gtk_widget_get_composite_name (GtkWidget *widget)
6300 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6302 if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent)
6303 return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
6310 * gtk_widget_push_composite_child:
6312 * Makes all newly-created widgets as composite children until
6313 * the corresponding gtk_widget_pop_composite_child() call.
6315 * A composite child is a child that's an implementation detail of the
6316 * container it's inside and should not be visible to people using the
6317 * container. Composite children aren't treated differently by GTK (but
6318 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
6319 * builders might want to treat them in a different way.
6321 * Here is a simple example:
6322 * <informalexample><programlisting>
6323 * gtk_widget_push_composite_child (<!-- -->);
6324 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
6325 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
6326 * gtk_widget_pop_composite_child (<!-- -->);
6327 * gtk_widget_set_parent (scrolled_window->hscrollbar,
6328 * GTK_WIDGET (scrolled_window));
6329 * g_object_ref (scrolled_window->hscrollbar);
6330 * </programlisting></informalexample>
6333 gtk_widget_push_composite_child (void)
6335 composite_child_stack++;
6339 * gtk_widget_pop_composite_child:
6341 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
6344 gtk_widget_pop_composite_child (void)
6346 if (composite_child_stack)
6347 composite_child_stack--;
6351 * gtk_widget_push_colormap:
6352 * @cmap: a #GdkColormap
6354 * Pushes @cmap onto a global stack of colormaps; the topmost
6355 * colormap on the stack will be used to create all widgets.
6356 * Remove @cmap with gtk_widget_pop_colormap(). There's little
6357 * reason to use this function.
6361 gtk_widget_push_colormap (GdkColormap *cmap)
6363 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
6365 colormap_stack = g_slist_prepend (colormap_stack, cmap);
6369 * gtk_widget_pop_colormap:
6371 * Removes a colormap pushed with gtk_widget_push_colormap().
6375 gtk_widget_pop_colormap (void)
6378 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
6382 * gtk_widget_set_default_colormap:
6383 * @colormap: a #GdkColormap
6385 * Sets the default colormap to use when creating widgets.
6386 * gtk_widget_push_colormap() is a better function to use if
6387 * you only want to affect a few widgets, rather than all widgets.
6390 gtk_widget_set_default_colormap (GdkColormap *colormap)
6392 g_return_if_fail (GDK_IS_COLORMAP (colormap));
6394 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
6399 * gtk_widget_get_default_colormap:
6401 * Obtains the default colormap used to create widgets.
6403 * Return value: default widget colormap
6406 gtk_widget_get_default_colormap (void)
6408 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
6412 * gtk_widget_get_default_visual:
6414 * Obtains the visual of the default colormap. Not really useful;
6415 * used to be useful before gdk_colormap_get_visual() existed.
6417 * Return value: visual of the default colormap
6420 gtk_widget_get_default_visual (void)
6422 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
6426 gtk_widget_emit_direction_changed (GtkWidget *widget,
6427 GtkTextDirection old_dir)
6429 PangoContext *context = gtk_widget_peek_pango_context (widget);
6432 pango_context_set_base_dir (context,
6433 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
6434 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
6436 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
6440 * gtk_widget_set_direction:
6441 * @widget: a #GtkWidget
6442 * @dir: the new direction
6444 * Sets the reading direction on a particular widget. This direction
6445 * controls the primary direction for widgets containing text,
6446 * and also the direction in which the children of a container are
6447 * packed. The ability to set the direction is present in order
6448 * so that correct localization into languages with right-to-left
6449 * reading directions can be done. Generally, applications will
6450 * let the default reading direction present, except for containers
6451 * where the containers are arranged in an order that is explicitely
6452 * visual rather than logical (such as buttons for text justification).
6454 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
6455 * set by gtk_widget_set_default_direction() will be used.
6458 gtk_widget_set_direction (GtkWidget *widget,
6459 GtkTextDirection dir)
6461 GtkTextDirection old_dir;
6463 g_return_if_fail (GTK_IS_WIDGET (widget));
6464 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
6466 old_dir = gtk_widget_get_direction (widget);
6468 if (dir == GTK_TEXT_DIR_NONE)
6469 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
6472 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
6473 if (dir == GTK_TEXT_DIR_LTR)
6474 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
6476 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
6479 if (old_dir != gtk_widget_get_direction (widget))
6480 gtk_widget_emit_direction_changed (widget, old_dir);
6484 * gtk_widget_get_direction:
6485 * @widget: a #GtkWidget
6487 * Gets the reading direction for a particular widget. See
6488 * gtk_widget_set_direction().
6490 * Return value: the reading direction for the widget.
6493 gtk_widget_get_direction (GtkWidget *widget)
6495 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
6497 if (GTK_WIDGET_DIRECTION_SET (widget))
6498 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
6500 return gtk_default_direction;
6504 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
6506 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
6508 g_object_ref (widget);
6510 if (!GTK_WIDGET_DIRECTION_SET (widget))
6511 gtk_widget_emit_direction_changed (widget, old_dir);
6513 if (GTK_IS_CONTAINER (widget))
6514 gtk_container_forall (GTK_CONTAINER (widget),
6515 gtk_widget_set_default_direction_recurse,
6518 g_object_unref (widget);
6522 * gtk_widget_set_default_direction:
6523 * @dir: the new default direction. This cannot be
6524 * %GTK_TEXT_DIR_NONE.
6526 * Sets the default reading direction for widgets where the
6527 * direction has not been explicitly set by gtk_widget_set_direction().
6530 gtk_widget_set_default_direction (GtkTextDirection dir)
6532 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
6534 if (dir != gtk_default_direction)
6536 GList *toplevels, *tmp_list;
6537 GtkTextDirection old_dir = gtk_default_direction;
6539 gtk_default_direction = dir;
6541 tmp_list = toplevels = gtk_window_list_toplevels ();
6542 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
6546 gtk_widget_set_default_direction_recurse (tmp_list->data,
6547 GUINT_TO_POINTER (old_dir));
6548 g_object_unref (tmp_list->data);
6549 tmp_list = tmp_list->next;
6552 g_list_free (toplevels);
6557 * gtk_widget_get_default_direction:
6559 * Obtains the current default reading direction. See
6560 * gtk_widget_set_default_direction().
6562 * Return value: the current default direction.
6565 gtk_widget_get_default_direction (void)
6567 return gtk_default_direction;
6571 gtk_widget_dispose (GObject *object)
6573 GtkWidget *widget = GTK_WIDGET (object);
6576 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
6577 else if (GTK_WIDGET_VISIBLE (widget))
6578 gtk_widget_hide (widget);
6580 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
6581 if (GTK_WIDGET_REALIZED (widget))
6582 gtk_widget_unrealize (widget);
6584 G_OBJECT_CLASS (parent_class)->dispose (object);
6588 gtk_widget_real_destroy (GtkObject *object)
6590 /* gtk_object_destroy() will already hold a refcount on object */
6591 GtkWidget *widget = GTK_WIDGET (object);
6593 /* wipe accelerator closures (keep order) */
6594 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
6595 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
6597 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
6598 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
6600 gtk_grab_remove (widget);
6602 g_object_unref (widget->style);
6603 widget->style = gtk_widget_get_default_style ();
6604 g_object_ref (widget->style);
6606 GTK_OBJECT_CLASS (parent_class)->destroy (object);
6610 gtk_widget_finalize (GObject *object)
6612 GtkWidget *widget = GTK_WIDGET (object);
6613 GtkWidgetAuxInfo *aux_info;
6615 GdkExtensionMode *mode;
6616 GtkAccessible *accessible;
6618 gtk_grab_remove (widget);
6620 g_object_unref (widget->style);
6621 widget->style = NULL;
6624 g_free (widget->name);
6626 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
6628 gtk_widget_aux_info_destroy (aux_info);
6630 events = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
6634 mode = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
6638 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
6640 g_object_unref (accessible);
6642 G_OBJECT_CLASS (parent_class)->finalize (object);
6645 /*****************************************
6646 * gtk_widget_real_map:
6651 *****************************************/
6654 gtk_widget_real_map (GtkWidget *widget)
6656 g_return_if_fail (GTK_WIDGET_REALIZED (widget) == TRUE);
6658 if (!GTK_WIDGET_MAPPED (widget))
6660 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
6662 if (!GTK_WIDGET_NO_WINDOW (widget))
6663 gdk_window_show (widget->window);
6667 /*****************************************
6668 * gtk_widget_real_unmap:
6673 *****************************************/
6676 gtk_widget_real_unmap (GtkWidget *widget)
6678 if (GTK_WIDGET_MAPPED (widget))
6680 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
6682 if (!GTK_WIDGET_NO_WINDOW (widget))
6683 gdk_window_hide (widget->window);
6687 /*****************************************
6688 * gtk_widget_real_realize:
6693 *****************************************/
6696 gtk_widget_real_realize (GtkWidget *widget)
6698 g_return_if_fail (GTK_WIDGET_NO_WINDOW (widget));
6700 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
6703 widget->window = gtk_widget_get_parent_window (widget);
6704 g_object_ref (widget->window);
6706 widget->style = gtk_style_attach (widget->style, widget->window);
6709 /*****************************************
6710 * gtk_widget_real_unrealize:
6715 *****************************************/
6718 gtk_widget_real_unrealize (GtkWidget *widget)
6720 if (GTK_WIDGET_MAPPED (widget))
6721 gtk_widget_real_unmap (widget);
6723 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
6725 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
6728 /* We must do unrealize child widget BEFORE container widget.
6729 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
6730 * So, unrealizing container widget bofore its children causes the problem
6731 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
6734 if (GTK_IS_CONTAINER (widget))
6735 gtk_container_forall (GTK_CONTAINER (widget),
6736 (GtkCallback) gtk_widget_unrealize,
6739 gtk_style_detach (widget->style);
6740 if (!GTK_WIDGET_NO_WINDOW (widget))
6742 gdk_window_set_user_data (widget->window, NULL);
6743 gdk_window_destroy (widget->window);
6744 widget->window = NULL;
6748 g_object_unref (widget->window);
6749 widget->window = NULL;
6752 gtk_selection_remove_all (widget);
6754 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
6758 gtk_widget_real_size_request (GtkWidget *widget,
6759 GtkRequisition *requisition)
6761 requisition->width = widget->requisition.width;
6762 requisition->height = widget->requisition.height;
6766 * _gtk_widget_peek_colormap:
6768 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
6770 * Return value: the currently pushed colormap, or %NULL if there is none.
6773 _gtk_widget_peek_colormap (void)
6776 return (GdkColormap*) colormap_stack->data;
6781 gtk_widget_propagate_state (GtkWidget *widget,
6786 /* don't call this function with state==GTK_STATE_INSENSITIVE,
6787 * parent_sensitive==TRUE on a sensitive widget
6790 old_state = GTK_WIDGET_STATE (widget);
6792 if (data->parent_sensitive)
6794 GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
6796 if (GTK_WIDGET_IS_SENSITIVE (widget))
6798 if (data->state_restoration)
6799 GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget);
6801 GTK_WIDGET_STATE (widget) = data->state;
6805 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
6806 if (!data->state_restoration &&
6807 data->state != GTK_STATE_INSENSITIVE)
6808 GTK_WIDGET_SAVED_STATE (widget) = data->state;
6813 GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
6814 if (!data->state_restoration)
6816 if (data->state != GTK_STATE_INSENSITIVE)
6817 GTK_WIDGET_SAVED_STATE (widget) = data->state;
6819 else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
6820 GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget);
6821 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
6824 if (gtk_widget_is_focus (widget) && !GTK_WIDGET_IS_SENSITIVE (widget))
6828 window = gtk_widget_get_toplevel (widget);
6829 if (window && GTK_WIDGET_TOPLEVEL (window))
6830 gtk_window_set_focus (GTK_WINDOW (window), NULL);
6833 if (old_state != GTK_WIDGET_STATE (widget))
6835 g_object_ref (widget);
6837 if (!GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_HAS_GRAB (widget))
6838 gtk_grab_remove (widget);
6840 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
6842 if (GTK_IS_CONTAINER (widget))
6844 data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE);
6845 data->state = GTK_WIDGET_STATE (widget);
6846 if (data->use_forall)
6847 gtk_container_forall (GTK_CONTAINER (widget),
6848 (GtkCallback) gtk_widget_propagate_state,
6851 gtk_container_foreach (GTK_CONTAINER (widget),
6852 (GtkCallback) gtk_widget_propagate_state,
6855 g_object_unref (widget);
6860 * _gtk_widget_get_aux_info:
6861 * @widget: a #GtkWidget
6862 * @create: if %TRUE, create the structure if it doesn't exist
6864 * Get the #GtkWidgetAuxInfo structure for the widget.
6866 * Return value: the #GtkAuxInfo structure for the widget, or
6867 * %NULL if @create is %FALSE and one doesn't already exist.
6870 _gtk_widget_get_aux_info (GtkWidget *widget,
6873 GtkWidgetAuxInfo *aux_info;
6875 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
6876 if (!aux_info && create)
6878 if (!aux_info_mem_chunk)
6879 aux_info_mem_chunk = g_mem_chunk_new ("widget aux info mem chunk",
6880 sizeof (GtkWidgetAuxInfo),
6881 1024, G_ALLOC_AND_FREE);
6882 aux_info = g_chunk_new (GtkWidgetAuxInfo, aux_info_mem_chunk);
6884 aux_info->width = -1;
6885 aux_info->height = -1;
6888 aux_info->x_set = FALSE;
6889 aux_info->y_set = FALSE;
6890 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
6896 /*****************************************
6897 * gtk_widget_aux_info_destroy:
6902 *****************************************/
6905 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
6907 g_mem_chunk_free (aux_info_mem_chunk, aux_info);
6911 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
6913 g_object_unref (info->shape_mask);
6918 * gtk_widget_shape_combine_mask:
6919 * @widget: a #GtkWidget.
6920 * @shape_mask: shape to be added, or %NULL to remove an existing shape.
6921 * @offset_x: X position of shape mask with respect to @window.
6922 * @offset_y: Y position of shape mask with respect to @window.
6924 * Sets a shape for this widget's GDK window. This allows for
6925 * transparent windows etc., see gdk_window_shape_combine_mask()
6926 * for more information.
6929 gtk_widget_shape_combine_mask (GtkWidget *widget,
6930 GdkBitmap *shape_mask,
6934 GtkWidgetShapeInfo* shape_info;
6936 g_return_if_fail (GTK_IS_WIDGET (widget));
6937 /* set_shape doesn't work on widgets without gdk window */
6938 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
6942 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
6945 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
6947 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
6951 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
6953 shape_info = g_new (GtkWidgetShapeInfo, 1);
6954 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
6955 (GDestroyNotify) gtk_widget_shape_info_destroy);
6957 shape_info->shape_mask = g_object_ref (shape_mask);
6958 shape_info->offset_x = offset_x;
6959 shape_info->offset_y = offset_y;
6961 /* set shape if widget has a gdk window allready.
6962 * otherwise the shape is scheduled to be set by gtk_widget_realize.
6965 gdk_window_shape_combine_mask (widget->window, shape_mask,
6966 offset_x, offset_y);
6971 gtk_reset_shapes_recurse (GtkWidget *widget,
6977 gdk_window_get_user_data (window, &data);
6981 gdk_window_shape_combine_mask (window, NULL, 0, 0);
6982 for (list = gdk_window_peek_children (window); list; list = list->next)
6983 gtk_reset_shapes_recurse (widget, list->data);
6987 * gtk_widget_reset_shapes:
6988 * @widget: a #GtkWidget.
6990 * Recursively resets the shape on this widget and its descendants.
6993 gtk_widget_reset_shapes (GtkWidget *widget)
6995 g_return_if_fail (GTK_IS_WIDGET (widget));
6996 g_return_if_fail (GTK_WIDGET_REALIZED (widget));
6998 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
6999 gtk_reset_shapes_recurse (widget, widget->window);
7004 * @widget: a #GtkWidget
7006 * Adds a reference to a widget. This function is exactly the same
7007 * as calling g_object_ref(), and exists mostly for historical
7008 * reasons. It can still be convenient to avoid casting a widget
7009 * to a #GObject, it saves a small amount of typing.
7011 * Return value: the widget that was referenced
7014 gtk_widget_ref (GtkWidget *widget)
7016 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7018 return (GtkWidget*) g_object_ref ((GObject*) widget);
7023 * @widget: a #GtkWidget
7025 * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
7029 gtk_widget_unref (GtkWidget *widget)
7031 g_return_if_fail (GTK_IS_WIDGET (widget));
7033 g_object_unref ((GObject*) widget);
7041 * gtk_widget_class_install_style_property_parser:
7042 * @klass: a #GtkWidgetClass
7043 * @pspec: the #GParamSpec for the style property
7044 * @parser: the parser for the style property
7046 * Installs a style property on a widget class.
7049 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
7051 GtkRcPropertyParser parser)
7053 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
7054 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
7055 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
7056 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
7058 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
7060 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
7061 G_OBJECT_CLASS_NAME (klass),
7066 g_param_spec_ref (pspec);
7067 g_param_spec_sink (pspec);
7068 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
7069 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
7073 * gtk_widget_class_install_style_property:
7074 * @klass: a #GtkWidgetClass
7075 * @pspec: the #GParamSpec for the property
7077 * Installs a style property on a widget class. The parser for the
7078 * style property is determined by the value type of @pspec.
7081 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
7084 GtkRcPropertyParser parser;
7086 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
7087 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
7089 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
7091 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
7095 * gtk_widget_class_find_style_property:
7096 * @klass: a #GtkWidgetClass
7097 * @property_name: the name of the style property to find
7098 * @returns: the #GParamSpec of the style property or %NULL if @class has no
7099 * style property with that name.
7101 * Finds a style property of a widget class by name.
7106 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
7107 const gchar *property_name)
7109 g_return_val_if_fail (property_name != NULL, NULL);
7111 return g_param_spec_pool_lookup (style_property_spec_pool,
7113 G_OBJECT_CLASS_TYPE (klass),
7118 * gtk_widget_class_list_style_properties:
7119 * @klass: a #GtkWidgetClass
7120 * @n_properties: location to return the number of style properties found
7121 * @returns: an newly allocated array of #GParamSpec*. The array must be freed with g_free().
7123 * Returns all style properties of a widget class.
7128 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
7129 guint *n_properties)
7131 GParamSpec **pspecs;
7134 pspecs = g_param_spec_pool_list (style_property_spec_pool,
7135 G_OBJECT_CLASS_TYPE (klass),
7144 * gtk_widget_style_get_property:
7145 * @widget: a #GtkWidget
7146 * @property_name: the name of a style property
7147 * @value: location to return the property value
7149 * Gets the value of a style property of @widget.
7152 gtk_widget_style_get_property (GtkWidget *widget,
7153 const gchar *property_name,
7158 g_return_if_fail (GTK_IS_WIDGET (widget));
7159 g_return_if_fail (property_name != NULL);
7160 g_return_if_fail (G_IS_VALUE (value));
7162 g_object_ref (widget);
7163 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
7165 G_OBJECT_TYPE (widget),
7168 g_warning ("%s: widget class `%s' has no property named `%s'",
7170 G_OBJECT_TYPE_NAME (widget),
7174 const GValue *peek_value;
7176 peek_value = _gtk_style_peek_property_value (widget->style,
7177 G_OBJECT_TYPE (widget),
7179 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
7181 /* auto-conversion of the caller's value type
7183 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
7184 g_value_copy (peek_value, value);
7185 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
7186 g_value_transform (peek_value, value);
7188 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
7190 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
7191 G_VALUE_TYPE_NAME (value));
7193 g_object_unref (widget);
7197 * gtk_widget_style_get_valist:
7198 * @widget: a #GtkWidget
7199 * @first_property_name: the name of the first property to get
7200 * @var_args: a <type>va_list</type> of pairs of property names and
7201 * locations to return the property values, starting with the location
7202 * for @first_property_name.
7204 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
7208 gtk_widget_style_get_valist (GtkWidget *widget,
7209 const gchar *first_property_name,
7214 g_return_if_fail (GTK_IS_WIDGET (widget));
7216 g_object_ref (widget);
7218 name = first_property_name;
7221 const GValue *peek_value;
7225 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
7227 G_OBJECT_TYPE (widget),
7231 g_warning ("%s: widget class `%s' has no property named `%s'",
7233 G_OBJECT_TYPE_NAME (widget),
7237 /* style pspecs are always readable so we can spare that check here */
7239 peek_value = _gtk_style_peek_property_value (widget->style,
7240 G_OBJECT_TYPE (widget),
7242 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
7243 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
7246 g_warning ("%s: %s", G_STRLOC, error);
7251 name = va_arg (var_args, gchar*);
7254 g_object_unref (widget);
7258 * gtk_widget_style_get:
7259 * @widget: a #GtkWidget
7260 * @first_property_name: the name of the first property to get
7261 * @Varargs: pairs of property names and locations to
7262 * return the property values, starting with the location for
7263 * @first_property_name, terminated by %NULL.
7265 * Gets the values of a multiple style properties of @widget.
7268 gtk_widget_style_get (GtkWidget *widget,
7269 const gchar *first_property_name,
7274 g_return_if_fail (GTK_IS_WIDGET (widget));
7276 va_start (var_args, first_property_name);
7277 gtk_widget_style_get_valist (widget, first_property_name, var_args);
7283 * @widget: a #GtkWidget
7284 * @path_length: location to store length of the path, or %NULL
7285 * @path: location to store allocated path string, or %NULL
7286 * @path_reversed: location to store allocated reverse path string, or %NULL
7288 * Obtains the full path to @widget. The path is simply the name of a
7289 * widget and all its parents in the container hierarchy, separated by
7290 * periods. The name of a widget comes from
7291 * gtk_widget_get_name(). Paths are used to apply styles to a widget
7292 * in gtkrc configuration files. Widget names are the type of the
7293 * widget by default (e.g. "GtkButton") or can be set to an
7294 * application-specific value with gtk_widget_set_name(). By setting
7295 * the name of a widget, you allow users or theme authors to apply
7296 * styles to that specific widget in their gtkrc
7297 * file. @path_reversed_p fills in the path in reverse order,
7298 * i.e. starting with @widget's name instead of starting with the name
7299 * of @widget's outermost ancestor.
7303 gtk_widget_path (GtkWidget *widget,
7306 gchar **path_reversed)
7308 static gchar *rev_path = NULL;
7309 static guint tmp_path_len = 0;
7312 g_return_if_fail (GTK_IS_WIDGET (widget));
7317 const gchar *string;
7322 string = gtk_widget_get_name (widget);
7323 l = strlen (string);
7324 while (tmp_path_len <= len + l + 1)
7326 tmp_path_len += INIT_PATH_SIZE;
7327 rev_path = g_realloc (rev_path, tmp_path_len);
7335 widget = widget->parent;
7338 rev_path[len++] = '.';
7340 rev_path[len++] = 0;
7345 *path_length = len - 1;
7347 *path_reversed = g_strdup (rev_path);
7350 *path = g_strdup (rev_path);
7351 g_strreverse (*path);
7356 * gtk_widget_class_path:
7357 * @widget: a #GtkWidget
7358 * @path_length: location to store the length of the class path, or %NULL
7359 * @path: location to store the class path as an allocated string, or %NULL
7360 * @path_reversed: location to store the reverse class path as an allocated string, or %NULL
7362 * Same as gtk_widget_path(), but always uses the name of a widget's type,
7363 * never uses a custom name set with gtk_widget_set_name().
7367 gtk_widget_class_path (GtkWidget *widget,
7370 gchar **path_reversed)
7372 static gchar *rev_path = NULL;
7373 static guint tmp_path_len = 0;
7376 g_return_if_fail (GTK_IS_WIDGET (widget));
7381 const gchar *string;
7386 string = g_type_name (GTK_WIDGET_TYPE (widget));
7387 l = strlen (string);
7388 while (tmp_path_len <= len + l + 1)
7390 tmp_path_len += INIT_PATH_SIZE;
7391 rev_path = g_realloc (rev_path, tmp_path_len);
7399 widget = widget->parent;
7402 rev_path[len++] = '.';
7404 rev_path[len++] = 0;
7409 *path_length = len - 1;
7411 *path_reversed = g_strdup (rev_path);
7414 *path = g_strdup (rev_path);
7415 g_strreverse (*path);
7420 * gtk_requisition_copy:
7421 * @requisition: a #GtkRequisition.
7422 * @returns: a copy of @requisition.
7424 * Copies a #GtkRequisition.
7427 gtk_requisition_copy (const GtkRequisition *requisition)
7429 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
7433 * gtk_requisition_free:
7434 * @requisition: a #GtkRequisition.
7436 * Frees a #GtkRequisition.
7439 gtk_requisition_free (GtkRequisition *requisition)
7441 g_free (requisition);
7445 gtk_requisition_get_type (void)
7447 static GType our_type = 0;
7450 our_type = g_boxed_type_register_static ("GtkRequisition",
7451 (GBoxedCopyFunc) gtk_requisition_copy,
7452 (GBoxedFreeFunc) gtk_requisition_free);
7458 * gtk_widget_get_accessible:
7459 * @widget: a #GtkWidget
7461 * Returns the accessible object that describes the widget to an
7462 * assistive technology.
7464 * If no accessibility library is loaded (i.e. no ATK implementation library is
7465 * loaded via <envar>GTK_MODULES</envar> or via another application library,
7466 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
7467 * if no class-specific #AtkObject implementation is available for the widget
7468 * instance in question, it will inherit an #AtkObject implementation from the
7469 * first ancestor class for which such an implementation is defined.
7471 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
7472 * library contains more information about accessible objects and their uses.
7474 * Returns: the #AtkObject associated with @widget
7477 gtk_widget_get_accessible (GtkWidget *widget)
7479 GtkWidgetClass *klass;
7481 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7483 klass = GTK_WIDGET_GET_CLASS (widget);
7485 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
7487 return klass->get_accessible (widget);
7491 gtk_widget_real_get_accessible (GtkWidget *widget)
7493 AtkObject* accessible;
7495 accessible = g_object_get_qdata (G_OBJECT (widget),
7496 quark_accessible_object);
7499 AtkObjectFactory *factory;
7500 AtkRegistry *default_registry;
7502 default_registry = atk_get_default_registry ();
7503 factory = atk_registry_get_factory (default_registry,
7504 G_TYPE_FROM_INSTANCE (widget));
7506 atk_object_factory_create_accessible (factory,
7508 g_object_set_qdata (G_OBJECT (widget),
7509 quark_accessible_object,
7516 * Initialize a AtkImplementorIface instance's virtual pointers as
7517 * appropriate to this implementor's class (GtkWidget).
7520 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
7522 iface->ref_accessible = gtk_widget_ref_accessible;
7526 gtk_widget_ref_accessible (AtkImplementor *implementor)
7528 AtkObject *accessible;
7530 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
7532 g_object_ref (accessible);
7537 * gtk_widget_get_clipboard:
7538 * @widget: a #GtkWidget
7539 * @selection: a #GdkAtom which identifies the clipboard
7540 * to use. %GDK_SELECTION_CLIPBOARD gives the
7541 * default clipboard. Another common value
7542 * is %GDK_SELECTION_PRIMARY, which gives
7543 * the primary X selection.
7545 * Returns the clipboard object for the given selection to
7546 * be used with @widget. @widget must have a #GdkDisplay
7547 * associated with it, so must be attached to a toplevel
7550 * Return value: the appropriate clipboard object. If no
7551 * clipboard already exists, a new one will
7552 * be created. Once a clipboard object has
7553 * been created, it is persistent for all time.
7558 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
7560 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7561 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
7563 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
7568 * gtk_widget_list_mnemonic_labels:
7569 * @widget: a #GtkWidget
7571 * Returns a newly allocated list of the widgets, normally labels, for
7572 * which this widget is a the target of a mnemonic (see for example,
7573 * gtk_label_set_mnemonic_widget()).
7575 * The widgets in the list are not individually referenced. If you
7576 * want to iterate through the list and perform actions involving
7577 * callbacks that might destroy the widgets, you
7578 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
7579 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
7580 * widgets afterwards.
7582 * Return value: the list of mnemonic labels; free this list
7583 * with g_list_free() when you are done with it.
7588 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
7593 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7595 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
7596 list = g_list_prepend (list, l->data);
7602 * gtk_widget_add_mnemonic_label:
7603 * @widget: a #GtkWidget
7604 * @label: a #GtkWidget that acts as a mnemonic label for @widget.
7606 * Adds a widget to the list of mnemonic labels for
7607 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
7608 * list of mnemonic labels for the widget is cleared when the
7609 * widget is destroyed, so the caller must make sure to update
7610 * its internal state at this point as well, by using a connection
7611 * to the ::destroy signal or a weak notifier.
7616 gtk_widget_add_mnemonic_label (GtkWidget *widget,
7619 GSList *old_list, *new_list;
7621 g_return_if_fail (GTK_IS_WIDGET (widget));
7622 g_return_if_fail (GTK_IS_WIDGET (label));
7624 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
7625 new_list = g_slist_prepend (old_list, label);
7627 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
7628 new_list, (GDestroyNotify) g_slist_free);
7632 * gtk_widget_remove_mnemonic_label:
7633 * @widget: a #GtkWidget
7634 * @label: a #GtkWidget that was previously set as a mnemnic label for
7635 * @widget with gtk_widget_add_mnemonic_label().
7637 * Removes a widget from the list of mnemonic labels for
7638 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
7639 * must have previously been added to the list with
7640 * gtk_widget_add_mnemonic_label().
7645 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
7648 GSList *old_list, *new_list;
7650 g_return_if_fail (GTK_IS_WIDGET (widget));
7651 g_return_if_fail (GTK_IS_WIDGET (label));
7653 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
7654 new_list = g_slist_remove (old_list, label);
7657 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
7658 new_list, (GDestroyNotify) g_slist_free);
7662 * gtk_widget_get_no_show_all:
7663 * @widget: a #GtkWidget
7665 * Returns the current value of the "no_show_all" property, which determines
7666 * whether calls to gtk_widget_show_all() and gtk_widget_hide_all()
7667 * will affect this widget.
7669 * Return value: the current value of the "no_show_all" property.
7674 gtk_widget_get_no_show_all (GtkWidget *widget)
7676 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7678 return (GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
7682 * gtk_widget_set_no_show_all:
7683 * @widget: a #GtkWidget
7684 * @no_show_all: the new value for the "no_show_all" property
7686 * Sets the "no_show_all" property, which determines whether calls to
7687 * gtk_widget_show_all() and gtk_widget_hide_all() will affect this widget.
7689 * This is mostly for use in constructing widget hierarchies with externally
7690 * controlled visibility, see #GtkUIManager.
7695 gtk_widget_set_no_show_all (GtkWidget *widget,
7696 gboolean no_show_all)
7698 g_return_if_fail (GTK_IS_WIDGET (widget));
7700 no_show_all = (no_show_all != FALSE);
7702 if (no_show_all == ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0))
7706 GTK_WIDGET_SET_FLAGS (widget, GTK_NO_SHOW_ALL);
7708 GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_SHOW_ALL);
7710 g_object_notify (G_OBJECT (widget), "no-show-all");
7713 #define __GTK_WIDGET_C__
7714 #include "gtkaliasdef.c"