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,
141 PROP_RECEIVES_DEFAULT,
142 PROP_COMPOSITE_CHILD,
145 PROP_EXTENSION_EVENTS,
149 typedef struct _GtkStateData GtkStateData;
154 guint state_restoration : 1;
155 guint parent_sensitive : 1;
156 guint use_forall : 1;
160 /* --- prototypes --- */
161 static void gtk_widget_class_init (GtkWidgetClass *klass);
162 static void gtk_widget_init (GtkWidget *widget);
163 static void gtk_widget_set_property (GObject *object,
167 static void gtk_widget_get_property (GObject *object,
171 static void gtk_widget_dispose (GObject *object);
172 static void gtk_widget_real_destroy (GtkObject *object);
173 static void gtk_widget_finalize (GObject *object);
174 static void gtk_widget_real_show (GtkWidget *widget);
175 static void gtk_widget_real_hide (GtkWidget *widget);
176 static void gtk_widget_real_map (GtkWidget *widget);
177 static void gtk_widget_real_unmap (GtkWidget *widget);
178 static void gtk_widget_real_realize (GtkWidget *widget);
179 static void gtk_widget_real_unrealize (GtkWidget *widget);
180 static void gtk_widget_real_size_request (GtkWidget *widget,
181 GtkRequisition *requisition);
182 static void gtk_widget_real_size_allocate (GtkWidget *widget,
183 GtkAllocation *allocation);
184 static void gtk_widget_style_set (GtkWidget *widget,
185 GtkStyle *previous_style);
186 static void gtk_widget_direction_changed (GtkWidget *widget,
187 GtkTextDirection previous_direction);
189 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
190 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
191 GtkWidgetHelpType help_type);
193 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
195 GParamSpec **pspecs);
196 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
198 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
200 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
201 GdkEventFocus *event);
202 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
203 GdkEventFocus *event);
204 static gboolean gtk_widget_real_focus (GtkWidget *widget,
205 GtkDirectionType direction);
206 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
207 static void gtk_widget_propagate_state (GtkWidget *widget,
209 static void gtk_widget_reset_rc_style (GtkWidget *widget);
210 static void gtk_widget_set_style_internal (GtkWidget *widget,
212 gboolean initial_emission);
213 static gint gtk_widget_event_internal (GtkWidget *widget,
215 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
216 gboolean group_cycling);
217 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
218 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
219 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
220 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
221 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
223 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
224 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
225 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
228 static void gtk_widget_set_usize_internal (GtkWidget *widget,
231 static void gtk_widget_get_draw_rectangle (GtkWidget *widget,
235 /* --- variables --- */
236 static gpointer parent_class = NULL;
237 static guint widget_signals[LAST_SIGNAL] = { 0 };
238 static GMemChunk *aux_info_mem_chunk = NULL;
239 static GtkStyle *gtk_default_style = NULL;
240 static GSList *colormap_stack = NULL;
241 static guint composite_child_stack = 0;
242 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
243 static GParamSpecPool *style_property_spec_pool = NULL;
245 static GQuark quark_property_parser = 0;
246 static GQuark quark_aux_info = 0;
247 static GQuark quark_accel_path = 0;
248 static GQuark quark_accel_closures = 0;
249 static GQuark quark_event_mask = 0;
250 static GQuark quark_extension_event_mode = 0;
251 static GQuark quark_parent_window = 0;
252 static GQuark quark_shape_info = 0;
253 static GQuark quark_colormap = 0;
254 static GQuark quark_pango_context = 0;
255 static GQuark quark_rc_style = 0;
256 static GQuark quark_accessible_object = 0;
257 static GQuark quark_mnemonic_labels = 0;
258 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
259 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
261 /* --- functions --- */
263 gtk_widget_get_type (void)
265 static GType widget_type = 0;
269 static const GTypeInfo widget_info =
271 sizeof (GtkWidgetClass),
272 NULL, /* base_init */
273 NULL, /* base_finalize */
274 (GClassInitFunc) gtk_widget_class_init,
275 NULL, /* class_finalize */
276 NULL, /* class_init */
279 (GInstanceInitFunc) gtk_widget_init,
280 NULL, /* value_table */
283 static const GInterfaceInfo accessibility_info =
285 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
286 (GInterfaceFinalizeFunc) NULL,
287 NULL /* interface data */
290 widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
291 &widget_info, G_TYPE_FLAG_ABSTRACT);
293 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
294 &accessibility_info) ;
302 child_property_notify_dispatcher (GObject *object,
306 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
310 gtk_widget_class_init (GtkWidgetClass *klass)
312 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
313 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
314 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
315 GtkBindingSet *binding_set;
317 parent_class = g_type_class_peek_parent (klass);
319 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
320 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
321 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
322 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
323 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
324 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
325 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
326 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
327 quark_colormap = g_quark_from_static_string ("gtk-colormap");
328 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
329 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
330 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
331 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
333 style_property_spec_pool = g_param_spec_pool_new (FALSE);
334 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
335 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
336 cpn_context.dispatcher = child_property_notify_dispatcher;
337 _gtk_widget_child_property_notify_context = &cpn_context;
339 gobject_class->dispose = gtk_widget_dispose;
340 gobject_class->finalize = gtk_widget_finalize;
341 gobject_class->set_property = gtk_widget_set_property;
342 gobject_class->get_property = gtk_widget_get_property;
344 object_class->destroy = gtk_widget_real_destroy;
346 klass->activate_signal = 0;
347 klass->set_scroll_adjustments_signal = 0;
348 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
349 klass->show = gtk_widget_real_show;
350 klass->show_all = gtk_widget_show;
351 klass->hide = gtk_widget_real_hide;
352 klass->hide_all = gtk_widget_hide;
353 klass->map = gtk_widget_real_map;
354 klass->unmap = gtk_widget_real_unmap;
355 klass->realize = gtk_widget_real_realize;
356 klass->unrealize = gtk_widget_real_unrealize;
357 klass->size_request = gtk_widget_real_size_request;
358 klass->size_allocate = gtk_widget_real_size_allocate;
359 klass->state_changed = NULL;
360 klass->parent_set = NULL;
361 klass->hierarchy_changed = NULL;
362 klass->style_set = gtk_widget_style_set;
363 klass->direction_changed = gtk_widget_direction_changed;
364 klass->grab_notify = NULL;
365 klass->child_notify = NULL;
366 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
367 klass->grab_focus = gtk_widget_real_grab_focus;
368 klass->focus = gtk_widget_real_focus;
370 klass->button_press_event = NULL;
371 klass->button_release_event = NULL;
372 klass->motion_notify_event = NULL;
373 klass->delete_event = NULL;
374 klass->destroy_event = NULL;
375 klass->expose_event = NULL;
376 klass->key_press_event = gtk_widget_real_key_press_event;
377 klass->key_release_event = gtk_widget_real_key_release_event;
378 klass->enter_notify_event = NULL;
379 klass->leave_notify_event = NULL;
380 klass->configure_event = NULL;
381 klass->focus_in_event = gtk_widget_real_focus_in_event;
382 klass->focus_out_event = gtk_widget_real_focus_out_event;
383 klass->map_event = NULL;
384 klass->unmap_event = NULL;
385 klass->window_state_event = NULL;
386 klass->property_notify_event = _gtk_selection_property_notify;
387 klass->selection_clear_event = gtk_selection_clear;
388 klass->selection_request_event = _gtk_selection_request;
389 klass->selection_notify_event = _gtk_selection_notify;
390 klass->selection_received = NULL;
391 klass->proximity_in_event = NULL;
392 klass->proximity_out_event = NULL;
393 klass->drag_begin = NULL;
394 klass->drag_end = NULL;
395 klass->drag_data_delete = NULL;
396 klass->drag_leave = NULL;
397 klass->drag_motion = NULL;
398 klass->drag_drop = NULL;
399 klass->drag_data_received = NULL;
400 klass->screen_changed = NULL;
401 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
402 klass->grab_broken_event = NULL;
404 klass->show_help = gtk_widget_real_show_help;
406 /* Accessibility support */
407 klass->get_accessible = gtk_widget_real_get_accessible;
409 klass->no_expose_event = NULL;
411 g_object_class_install_property (gobject_class,
413 g_param_spec_string ("name",
415 P_("The name of the widget"),
417 GTK_PARAM_READWRITE));
418 g_object_class_install_property (gobject_class,
420 g_param_spec_object ("parent",
422 P_("The parent widget of this widget. Must be a Container widget"),
424 GTK_PARAM_READWRITE));
426 g_object_class_install_property (gobject_class,
428 g_param_spec_int ("width-request",
430 P_("Override for width request of the widget, or -1 if natural request should be used"),
434 GTK_PARAM_READWRITE));
435 g_object_class_install_property (gobject_class,
437 g_param_spec_int ("height-request",
438 P_("Height request"),
439 P_("Override for height request of the widget, or -1 if natural request should be used"),
443 GTK_PARAM_READWRITE));
444 g_object_class_install_property (gobject_class,
446 g_param_spec_boolean ("visible",
448 P_("Whether the widget is visible"),
450 GTK_PARAM_READWRITE));
451 g_object_class_install_property (gobject_class,
453 g_param_spec_boolean ("sensitive",
455 P_("Whether the widget responds to input"),
457 GTK_PARAM_READWRITE));
458 g_object_class_install_property (gobject_class,
460 g_param_spec_boolean ("app-paintable",
461 P_("Application paintable"),
462 P_("Whether the application will paint directly on the widget"),
464 GTK_PARAM_READWRITE));
465 g_object_class_install_property (gobject_class,
467 g_param_spec_boolean ("can-focus",
469 P_("Whether the widget can accept the input focus"),
471 GTK_PARAM_READWRITE));
472 g_object_class_install_property (gobject_class,
474 g_param_spec_boolean ("has-focus",
476 P_("Whether the widget has the input focus"),
478 GTK_PARAM_READWRITE));
479 g_object_class_install_property (gobject_class,
481 g_param_spec_boolean ("is-focus",
483 P_("Whether the widget is the focus widget within the toplevel"),
485 GTK_PARAM_READWRITE));
486 g_object_class_install_property (gobject_class,
488 g_param_spec_boolean ("can-default",
490 P_("Whether the widget can be the default widget"),
492 GTK_PARAM_READWRITE));
493 g_object_class_install_property (gobject_class,
495 g_param_spec_boolean ("has-default",
497 P_("Whether the widget is the default widget"),
499 GTK_PARAM_READWRITE));
500 g_object_class_install_property (gobject_class,
501 PROP_RECEIVES_DEFAULT,
502 g_param_spec_boolean ("receives-default",
503 P_("Receives default"),
504 P_("If TRUE, the widget will receive the default action when it is focused"),
506 GTK_PARAM_READWRITE));
507 g_object_class_install_property (gobject_class,
508 PROP_COMPOSITE_CHILD,
509 g_param_spec_boolean ("composite-child",
510 P_("Composite child"),
511 P_("Whether the widget is part of a composite widget"),
513 GTK_PARAM_READABLE));
514 g_object_class_install_property (gobject_class,
516 g_param_spec_object ("style",
518 P_("The style of the widget, which contains information about how it will look (colors etc)"),
520 GTK_PARAM_READWRITE));
521 g_object_class_install_property (gobject_class,
523 g_param_spec_flags ("events",
525 P_("The event mask that decides what kind of GdkEvents this widget gets"),
528 GTK_PARAM_READWRITE));
529 g_object_class_install_property (gobject_class,
530 PROP_EXTENSION_EVENTS,
531 g_param_spec_enum ("extension-events",
532 P_("Extension events"),
533 P_("The mask that decides what kind of extension events this widget gets"),
534 GDK_TYPE_EXTENSION_MODE,
535 GDK_EXTENSION_EVENTS_NONE,
536 GTK_PARAM_READWRITE));
537 g_object_class_install_property (gobject_class,
539 g_param_spec_boolean ("no-show-all",
541 P_("Whether gtk_widget_show_all() should not affect this widget"),
543 GTK_PARAM_READWRITE));
544 widget_signals[SHOW] =
545 g_signal_new ("show",
546 G_TYPE_FROM_CLASS (gobject_class),
548 G_STRUCT_OFFSET (GtkWidgetClass, show),
550 _gtk_marshal_VOID__VOID,
552 widget_signals[HIDE] =
553 g_signal_new ("hide",
554 G_TYPE_FROM_CLASS (gobject_class),
556 G_STRUCT_OFFSET (GtkWidgetClass, hide),
558 _gtk_marshal_VOID__VOID,
560 widget_signals[MAP] =
562 G_TYPE_FROM_CLASS (gobject_class),
564 G_STRUCT_OFFSET (GtkWidgetClass, map),
566 _gtk_marshal_VOID__VOID,
568 widget_signals[UNMAP] =
569 g_signal_new ("unmap",
570 G_TYPE_FROM_CLASS (gobject_class),
572 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
574 _gtk_marshal_VOID__VOID,
576 widget_signals[REALIZE] =
577 g_signal_new ("realize",
578 G_TYPE_FROM_CLASS (gobject_class),
580 G_STRUCT_OFFSET (GtkWidgetClass, realize),
582 _gtk_marshal_VOID__VOID,
584 widget_signals[UNREALIZE] =
585 g_signal_new ("unrealize",
586 G_TYPE_FROM_CLASS (gobject_class),
588 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
590 _gtk_marshal_VOID__VOID,
592 widget_signals[SIZE_REQUEST] =
593 g_signal_new ("size_request",
594 G_TYPE_FROM_CLASS (gobject_class),
596 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
598 _gtk_marshal_VOID__BOXED,
600 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
601 widget_signals[SIZE_ALLOCATE] =
602 g_signal_new ("size_allocate",
603 G_TYPE_FROM_CLASS (gobject_class),
605 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
607 _gtk_marshal_VOID__BOXED,
609 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
610 widget_signals[STATE_CHANGED] =
611 g_signal_new ("state_changed",
612 G_TYPE_FROM_CLASS (gobject_class),
614 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
616 _gtk_marshal_VOID__ENUM,
618 GTK_TYPE_STATE_TYPE);
619 widget_signals[PARENT_SET] =
620 g_signal_new ("parent_set",
621 G_TYPE_FROM_CLASS (gobject_class),
623 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
625 _gtk_marshal_VOID__OBJECT,
628 widget_signals[HIERARCHY_CHANGED] =
629 g_signal_new ("hierarchy_changed",
630 G_TYPE_FROM_CLASS (gobject_class),
632 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
634 _gtk_marshal_VOID__OBJECT,
638 * GtkWidget::style-set:
639 * @widget: the object on which the signal is emitted
640 * @previous_style: the previous style, or %NULL if the widget
641 * just got its initial style
643 * The style-set signal is emitted when a new style has been set
644 * on a widget. Note that style-modifying functions like
645 * gtk_widget_modify_base() also cause this signal to be emitted.
647 widget_signals[STYLE_SET] =
648 g_signal_new ("style_set",
649 G_TYPE_FROM_CLASS (gobject_class),
651 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
653 _gtk_marshal_VOID__OBJECT,
656 widget_signals[DIRECTION_CHANGED] =
657 g_signal_new ("direction_changed",
658 G_TYPE_FROM_CLASS (gobject_class),
660 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
662 _gtk_marshal_VOID__ENUM,
664 GTK_TYPE_TEXT_DIRECTION);
665 widget_signals[GRAB_NOTIFY] =
666 g_signal_new ("grab_notify",
667 G_TYPE_FROM_CLASS (gobject_class),
669 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
671 _gtk_marshal_VOID__BOOLEAN,
676 * GtkWidget::child-notify:
677 * @widget: the object which received the signal.
678 * @pspec: the #GParamSpec of the changed child property.
680 * The ::child-notify signal is emitted for each child property that has
681 * changed on an object. The signal's detail holds the property name.
683 widget_signals[CHILD_NOTIFY] =
684 g_signal_new ("child_notify",
685 G_TYPE_FROM_CLASS (gobject_class),
686 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
687 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
689 g_cclosure_marshal_VOID__PARAM,
692 widget_signals[MNEMONIC_ACTIVATE] =
693 g_signal_new ("mnemonic_activate",
694 G_TYPE_FROM_CLASS (gobject_class),
696 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
697 _gtk_boolean_handled_accumulator, NULL,
698 _gtk_marshal_BOOLEAN__BOOLEAN,
701 widget_signals[GRAB_FOCUS] =
702 g_signal_new ("grab_focus",
703 G_TYPE_FROM_CLASS (gobject_class),
704 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
705 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
707 _gtk_marshal_VOID__VOID,
709 widget_signals[FOCUS] =
710 g_signal_new ("focus",
711 G_TYPE_FROM_CLASS (object_class),
713 G_STRUCT_OFFSET (GtkWidgetClass, focus),
714 _gtk_boolean_handled_accumulator, NULL,
715 _gtk_marshal_BOOLEAN__ENUM,
717 GTK_TYPE_DIRECTION_TYPE);
718 widget_signals[EVENT] =
719 g_signal_new ("event",
720 G_TYPE_FROM_CLASS (gobject_class),
722 G_STRUCT_OFFSET (GtkWidgetClass, event),
723 _gtk_boolean_handled_accumulator, NULL,
724 _gtk_marshal_BOOLEAN__BOXED,
726 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
727 widget_signals[EVENT_AFTER] =
728 g_signal_new ("event-after",
729 G_TYPE_FROM_CLASS (gobject_class),
733 _gtk_marshal_VOID__BOXED,
735 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
736 widget_signals[BUTTON_PRESS_EVENT] =
737 g_signal_new ("button_press_event",
738 G_TYPE_FROM_CLASS (gobject_class),
740 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
741 _gtk_boolean_handled_accumulator, NULL,
742 _gtk_marshal_BOOLEAN__BOXED,
744 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
745 widget_signals[BUTTON_RELEASE_EVENT] =
746 g_signal_new ("button_release_event",
747 G_TYPE_FROM_CLASS (gobject_class),
749 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
750 _gtk_boolean_handled_accumulator, NULL,
751 _gtk_marshal_BOOLEAN__BOXED,
753 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
754 widget_signals[SCROLL_EVENT] =
755 g_signal_new ("scroll_event",
756 G_TYPE_FROM_CLASS (gobject_class),
758 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
759 _gtk_boolean_handled_accumulator, NULL,
760 _gtk_marshal_BOOLEAN__BOXED,
762 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
763 widget_signals[MOTION_NOTIFY_EVENT] =
764 g_signal_new ("motion_notify_event",
765 G_TYPE_FROM_CLASS (gobject_class),
767 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
768 _gtk_boolean_handled_accumulator, NULL,
769 _gtk_marshal_BOOLEAN__BOXED,
771 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
774 * GtkWidget::delete-event:
775 * @widget: the object which received the signal.
776 * @event: the event which triggered this signal
778 * The ::delete-event signal is emitted if a user requests that
779 * a toplevel window is closed. The default handler for this signal
780 * destroys the window. Connecting gtk_widget_hide_on_delete() to
781 * this signal will cause the window to be hidden instead, so that
782 * it can later be shown again without reconstructing it.
784 * Returns: %TRUE to stop other handlers from being invoked for the event.
785 * %FALSE to propagate the event further.
787 widget_signals[DELETE_EVENT] =
788 g_signal_new ("delete_event",
789 G_TYPE_FROM_CLASS (gobject_class),
791 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
792 _gtk_boolean_handled_accumulator, NULL,
793 _gtk_marshal_BOOLEAN__BOXED,
795 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
798 * GtkWidget::destroy-event:
799 * @widget: the object which received the signal.
800 * @event: the event which triggered this signal
802 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
803 * You rarely get this signal, because most widgets disconnect themselves
804 * from their window before they destroy it, so no widget owns the
805 * window at destroy time.
807 * Returns: %TRUE to stop other handlers from being invoked for the event.
808 * %FALSE to propagate the event further.
810 widget_signals[DESTROY_EVENT] =
811 g_signal_new ("destroy_event",
812 G_TYPE_FROM_CLASS (gobject_class),
814 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
815 _gtk_boolean_handled_accumulator, NULL,
816 _gtk_marshal_BOOLEAN__BOXED,
818 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
819 widget_signals[EXPOSE_EVENT] =
820 g_signal_new ("expose_event",
821 G_TYPE_FROM_CLASS (gobject_class),
823 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
824 _gtk_boolean_handled_accumulator, NULL,
825 _gtk_marshal_BOOLEAN__BOXED,
827 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
828 widget_signals[KEY_PRESS_EVENT] =
829 g_signal_new ("key_press_event",
830 G_TYPE_FROM_CLASS (gobject_class),
832 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
833 _gtk_boolean_handled_accumulator, NULL,
834 _gtk_marshal_BOOLEAN__BOXED,
836 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
837 widget_signals[KEY_RELEASE_EVENT] =
838 g_signal_new ("key_release_event",
839 G_TYPE_FROM_CLASS (gobject_class),
841 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
842 _gtk_boolean_handled_accumulator, NULL,
843 _gtk_marshal_BOOLEAN__BOXED,
845 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
846 widget_signals[ENTER_NOTIFY_EVENT] =
847 g_signal_new ("enter_notify_event",
848 G_TYPE_FROM_CLASS (gobject_class),
850 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
851 _gtk_boolean_handled_accumulator, NULL,
852 _gtk_marshal_BOOLEAN__BOXED,
854 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
855 widget_signals[LEAVE_NOTIFY_EVENT] =
856 g_signal_new ("leave_notify_event",
857 G_TYPE_FROM_CLASS (gobject_class),
859 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
860 _gtk_boolean_handled_accumulator, NULL,
861 _gtk_marshal_BOOLEAN__BOXED,
863 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
864 widget_signals[CONFIGURE_EVENT] =
865 g_signal_new ("configure_event",
866 G_TYPE_FROM_CLASS (gobject_class),
868 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
869 _gtk_boolean_handled_accumulator, NULL,
870 _gtk_marshal_BOOLEAN__BOXED,
872 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
873 widget_signals[FOCUS_IN_EVENT] =
874 g_signal_new ("focus_in_event",
875 G_TYPE_FROM_CLASS (gobject_class),
877 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
878 _gtk_boolean_handled_accumulator, NULL,
879 _gtk_marshal_BOOLEAN__BOXED,
881 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
882 widget_signals[FOCUS_OUT_EVENT] =
883 g_signal_new ("focus_out_event",
884 G_TYPE_FROM_CLASS (gobject_class),
886 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
887 _gtk_boolean_handled_accumulator, NULL,
888 _gtk_marshal_BOOLEAN__BOXED,
890 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
891 widget_signals[MAP_EVENT] =
892 g_signal_new ("map_event",
893 G_TYPE_FROM_CLASS (gobject_class),
895 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
896 _gtk_boolean_handled_accumulator, NULL,
897 _gtk_marshal_BOOLEAN__BOXED,
899 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
900 widget_signals[UNMAP_EVENT] =
901 g_signal_new ("unmap_event",
902 G_TYPE_FROM_CLASS (gobject_class),
904 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
905 _gtk_boolean_handled_accumulator, NULL,
906 _gtk_marshal_BOOLEAN__BOXED,
908 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
909 widget_signals[PROPERTY_NOTIFY_EVENT] =
910 g_signal_new ("property_notify_event",
911 G_TYPE_FROM_CLASS (gobject_class),
913 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
914 _gtk_boolean_handled_accumulator, NULL,
915 _gtk_marshal_BOOLEAN__BOXED,
917 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
918 widget_signals[SELECTION_CLEAR_EVENT] =
919 g_signal_new ("selection_clear_event",
920 G_TYPE_FROM_CLASS (gobject_class),
922 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
923 _gtk_boolean_handled_accumulator, NULL,
924 _gtk_marshal_BOOLEAN__BOXED,
926 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
927 widget_signals[SELECTION_REQUEST_EVENT] =
928 g_signal_new ("selection_request_event",
929 G_TYPE_FROM_CLASS (gobject_class),
931 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
932 _gtk_boolean_handled_accumulator, NULL,
933 _gtk_marshal_BOOLEAN__BOXED,
935 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
936 widget_signals[SELECTION_NOTIFY_EVENT] =
937 g_signal_new ("selection_notify_event",
938 G_TYPE_FROM_CLASS (gobject_class),
940 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
941 _gtk_boolean_handled_accumulator, NULL,
942 _gtk_marshal_BOOLEAN__BOXED,
944 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
945 widget_signals[SELECTION_RECEIVED] =
946 g_signal_new ("selection_received",
947 G_TYPE_FROM_CLASS (gobject_class),
949 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
951 _gtk_marshal_VOID__BOXED_UINT,
953 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
955 widget_signals[SELECTION_GET] =
956 g_signal_new ("selection_get",
957 G_TYPE_FROM_CLASS (gobject_class),
959 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
961 _gtk_marshal_VOID__BOXED_UINT_UINT,
963 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
966 widget_signals[PROXIMITY_IN_EVENT] =
967 g_signal_new ("proximity_in_event",
968 G_TYPE_FROM_CLASS (gobject_class),
970 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
971 _gtk_boolean_handled_accumulator, NULL,
972 _gtk_marshal_BOOLEAN__BOXED,
974 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
975 widget_signals[PROXIMITY_OUT_EVENT] =
976 g_signal_new ("proximity_out_event",
977 G_TYPE_FROM_CLASS (gobject_class),
979 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
980 _gtk_boolean_handled_accumulator, NULL,
981 _gtk_marshal_BOOLEAN__BOXED,
983 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
986 * GtkWidget::drag-leave:
987 * @widget: the object which received the signal.
988 * @drag_context: the drag context
989 * @time: the timestamp of the motion event
991 * The ::drag-leave signal is emitted on the drop site when the cursor leaves the widget.
992 * A typical reason to connect to this signal is to undo things done in ::drag-motion, e.g.
993 * undo highlighting with gtk_drag_unhighlight()
995 widget_signals[DRAG_LEAVE] =
996 g_signal_new ("drag_leave",
997 G_TYPE_FROM_CLASS (gobject_class),
999 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
1001 _gtk_marshal_VOID__OBJECT_UINT,
1003 GDK_TYPE_DRAG_CONTEXT,
1007 * GtkWidget::drag-begin:
1008 * @widget: the object which received the signal.
1009 * @drag_context: the drag context
1011 * The ::drag-begin signal is emitted on the drag source when a drag is started.
1012 * A typical reason to connect to this signal is to set up a custom drag icon with
1013 * gtk_drag_source_set_icon().
1015 widget_signals[DRAG_BEGIN] =
1016 g_signal_new ("drag_begin",
1017 G_TYPE_FROM_CLASS (gobject_class),
1019 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
1021 _gtk_marshal_VOID__OBJECT,
1023 GDK_TYPE_DRAG_CONTEXT);
1026 * GtkWidget::drag-end:
1027 * @widget: the object which received the signal.
1028 * @drag_context: the drag context
1030 * The ::drag-end signal is emitted on the drag source when a drag is finished.
1031 * A typical reason to connect to this signal is to undo things done in ::drag-begin.
1033 widget_signals[DRAG_END] =
1034 g_signal_new ("drag_end",
1035 G_TYPE_FROM_CLASS (gobject_class),
1037 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
1039 _gtk_marshal_VOID__OBJECT,
1041 GDK_TYPE_DRAG_CONTEXT);
1044 * GtkWidget::drag-data-delete:
1045 * @widget: the object which received the signal.
1046 * @drag_context: the drag context
1048 * The ::drag-data-delete signal is emitted on the drag source when a drag with the action
1049 * %GDK_ACTION_MOVE is successfully completed. The signal handler is responsible for deleting
1050 * the data that has been dropped. What "delete" means, depends on the context of the drag
1053 widget_signals[DRAG_DATA_DELETE] =
1054 g_signal_new ("drag_data_delete",
1055 G_TYPE_FROM_CLASS (gobject_class),
1057 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
1059 _gtk_marshal_VOID__OBJECT,
1061 GDK_TYPE_DRAG_CONTEXT);
1064 * GtkWidget::drag-motion:
1065 * @widget: the object which received the signal.
1066 * @drag_context: the drag context
1067 * @x: the x coordinate of the current cursor position
1068 * @y: the y coordinate of the current cursor position
1069 * @time: the timestamp of the motion event
1070 * @returns: whether the cursor position is in a drop zone
1072 * The ::drag-motion signal is emitted on the drop site when the user moves the cursor over
1073 * the widget during a drag. The signal handler must determine whether the cursor position is in
1074 * a drop zone or not. If it is not in a drop zone, it returns %FALSE and no further processing is
1075 * necessary. Otherwise, the handler returns %TRUE. In this case, the handler is responsible for
1076 * providing the necessary information for displaying feedback to the user, by calling
1077 * gdk_drag_status(). If the decision whether the drop will be accepted or rejected can't be made
1078 * based solely on the cursor position and the type of the data, the handler may inspect the dragged
1079 * data by calling gtk_drag_get_data() and defer the gdk_drag_status() call to the ::drag-data-received
1082 * Note that there is no ::drag-enter signal. The drag receiver has to keep track of whether
1083 * he has received any ::drag-motion signals since the last ::drag-leave and if not, treat the
1084 * ::drag-motion signal as an "enter" signal. Upon an "enter", the handler will typically highlight
1085 * the drop site with gtk_drag_highlight().
1087 * <informalexample><programlisting>
1089 * drag_motion (GtkWidget *widget,
1090 * GdkDragContext *context,
1097 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1099 * if (!private_data->drag_highlight)
1101 * private_data->drag_highlight = 1;
1102 * gtk_drag_highlight (widget);
1105 * target = gtk_drag_dest_find_target (widget, context, NULL);
1106 * if (target == GDK_NONE)
1107 * gdk_drag_status (context, 0, time);
1110 * private_data->pending_status = context->suggested_action;
1111 * gtk_drag_get_data (widget, context, target, time);
1118 * drag_data_received (GtkWidget *widget,
1119 * GdkDragContext *context,
1122 * GtkSelectionData *selection_data,
1126 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1128 * if (private_data->suggested_action)
1130 * private_data->suggested_action = 0;
1132 * /<!-- -->* We are getting this data due to a request in drag_motion,
1133 * * rather than due to a request in drag_drop, so we are just
1134 * * supposed to call gdk_drag_status(<!-- -->), not actually paste in the data.
1136 * str = gtk_selection_data_get_text (selection_data);
1137 * if (!data_is_acceptable (str))
1138 * gdk_drag_status (context, 0, time);
1140 * gdk_drag_status (context, private_data->suggested_action, time);
1144 * /<!-- -->* accept the drop *<!-- -->/
1147 * </programlisting></informalexample>
1149 widget_signals[DRAG_MOTION] =
1150 g_signal_new ("drag_motion",
1151 G_TYPE_FROM_CLASS (gobject_class),
1153 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
1154 _gtk_boolean_handled_accumulator, NULL,
1155 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1157 GDK_TYPE_DRAG_CONTEXT,
1163 * GtkWidget::drag-drop:
1164 * @widget: the object which received the signal.
1165 * @drag_context: the drag context
1166 * @x: the x coordinate of the current cursor position
1167 * @y: the y coordinate of the current cursor position
1168 * @time: the timestamp of the motion event
1169 * @returns: whether the cursor position is in a drop zone
1171 * The ::drag-drop signal is emitted on the drop site when the user drops the data
1172 * onto the widget. The signal handler must determine whether the cursor position is in
1173 * a drop zone or not. If it is not in a drop zone, it returns %FALSE and no further
1174 * processing is necessary. Otherwise, the handler returns %TRUE. In this case, the handler
1175 * must ensure that gtk_drag_finish() is called to let the source know that the drop is done.
1176 * The call to gtk_drag_finish() can be done either directly or in a ::drag-data-received handler
1177 * which gets triggered by calling gtk_drop_get_data() to receive the data for one or more of the
1178 * supported targets.
1180 widget_signals[DRAG_DROP] =
1181 g_signal_new ("drag_drop",
1182 G_TYPE_FROM_CLASS (gobject_class),
1184 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
1185 _gtk_boolean_handled_accumulator, NULL,
1186 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1188 GDK_TYPE_DRAG_CONTEXT,
1194 * GtkWidget::drag-data-get:
1195 * @widget: the object which received the signal.
1196 * @drag_context: the drag context
1197 * @data: the #GtkSelectionData to be filled with the dragged data
1198 * @info: the info that has been registered with the target in the #GtkTargetList.
1199 * @time: the timestamp at which the data was requested
1201 * The ::drag-data-get signal is emitted on the drag source when the drop site requests
1202 * the data which is dragged. It is the responsibility of the signal handler to fill @data
1203 * with the data in the format which is indicated by @info. See gtk_selection_data_set() and
1204 * gtk_selection_data_set_text().
1206 widget_signals[DRAG_DATA_GET] =
1207 g_signal_new ("drag_data_get",
1208 G_TYPE_FROM_CLASS (gobject_class),
1210 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
1212 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
1214 GDK_TYPE_DRAG_CONTEXT,
1215 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1220 * GtkWidget::drag-data-received:
1221 * @widget: the object which received the signal.
1222 * @drag_context: the drag context
1223 * @x: where the drop happened
1224 * @y: where the drop happened
1225 * @data: the received data
1226 * @info: the info that has been registered with the target in the #GtkTargetList.
1227 * @time: the timestamp at which the data was received
1229 * The ::drag-data-received signal is emitted on the drop site when the dragged data has been
1230 * received. If the data was received in order to determine whether the drop will be accepted,
1231 * the handler is expected to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
1232 * If the data was received in response to a ::drag-drop signal (and this is the last target to be
1233 * received), the handler for this signal is expected to process the received data and then call
1234 * gtk_drag_finish(), setting the @success parameter depending on whether the data was processed
1237 * The handler may inspect and modify @drag_context->action before calling gtk_drag_finish(),
1238 * e.g. to implement %GDK_ACTION_ASK as shown in the following example:
1239 * <informalexample><programlisting>
1241 * drag_data_received (GtkWidget *widget,
1242 * GdkDragContext *drag_context,
1245 * GtkSelectionData *data,
1249 * if ((data->length >= 0) && (data->format == 8))
1251 * if (drag_context->action == GDK_ACTION_ASK)
1253 * GtkWidget *dialog;
1256 * dialog = gtk_message_dialog_new (NULL,
1257 * GTK_DIALOG_MODAL |
1258 * GTK_DIALOG_DESTROY_WITH_PARENT,
1260 * GTK_BUTTONS_YES_NO,
1261 * "Move the data ?\n");
1262 * response = gtk_dialog_run (GTK_DIALOG (dialog));
1263 * gtk_widget_destroy (dialog);
1265 * if (response == GTK_RESPONSE_YES)
1266 * drag_context->action = GDK_ACTION_MOVE;
1268 * drag_context->action = GDK_ACTION_COPY;
1271 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
1275 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
1277 * </programlisting></informalexample>
1279 widget_signals[DRAG_DATA_RECEIVED] =
1280 g_signal_new ("drag_data_received",
1281 G_TYPE_FROM_CLASS (gobject_class),
1283 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
1285 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
1287 GDK_TYPE_DRAG_CONTEXT,
1290 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1293 widget_signals[VISIBILITY_NOTIFY_EVENT] =
1294 g_signal_new ("visibility_notify_event",
1295 G_TYPE_FROM_CLASS (gobject_class),
1297 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
1298 _gtk_boolean_handled_accumulator, NULL,
1299 _gtk_marshal_BOOLEAN__BOXED,
1301 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1302 widget_signals[CLIENT_EVENT] =
1303 g_signal_new ("client_event",
1304 G_TYPE_FROM_CLASS (gobject_class),
1306 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
1307 _gtk_boolean_handled_accumulator, NULL,
1308 _gtk_marshal_BOOLEAN__BOXED,
1310 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1311 widget_signals[NO_EXPOSE_EVENT] =
1312 g_signal_new ("no_expose_event",
1313 G_TYPE_FROM_CLASS (gobject_class),
1315 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
1316 _gtk_boolean_handled_accumulator, NULL,
1317 _gtk_marshal_BOOLEAN__BOXED,
1319 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1320 widget_signals[WINDOW_STATE_EVENT] =
1321 g_signal_new ("window_state_event",
1322 G_TYPE_FROM_CLASS (gobject_class),
1324 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
1325 _gtk_boolean_handled_accumulator, NULL,
1326 _gtk_marshal_BOOLEAN__BOXED,
1328 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1330 * GtkWidget::grab-broken:
1331 * @widget: the object which received the signal
1332 * @event: the #GdkEventGrabBroken event
1334 * Emitted when a pointer or keyboard grab on a window belonging
1335 * to @widget gets broken.
1337 * On X11, this happens when the grab window becomes unviewable
1338 * (i.e. it or one of its ancestors is unmapped), or if the same
1339 * application grabs the pointer or keyboard again.
1341 * Returns: %TRUE to stop other handlers from being invoked for the event.
1342 * %FALSE to propagate the event further.
1346 widget_signals[GRAB_BROKEN] =
1347 g_signal_new ("grab_broken_event",
1348 G_TYPE_FROM_CLASS (gobject_class),
1350 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
1351 _gtk_boolean_handled_accumulator, NULL,
1352 _gtk_marshal_BOOLEAN__BOXED,
1354 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1356 * GtkWidget::popup-menu
1357 * @widget: the object which received the signal
1358 * @returns: TRUE if a menu was activated
1360 * This signal gets emitted whenever a widget should pop up a context-sensitive
1361 * menu. This usually happens through the standard key binding mechanism; by
1362 * pressing a certain key while a widget is focused, the user can cause the
1363 * widget to pop up a menu. For example, the #GtkEntry widget creates a menu
1364 * with clipboard commands. See <xref linkend="checklist-popup-menu"/> for an
1365 * example of how to use this signal.
1367 widget_signals[POPUP_MENU] =
1368 g_signal_new ("popup_menu",
1369 G_TYPE_FROM_CLASS (gobject_class),
1370 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1371 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
1372 _gtk_boolean_handled_accumulator, NULL,
1373 _gtk_marshal_BOOLEAN__VOID,
1375 widget_signals[SHOW_HELP] =
1376 g_signal_new ("show_help",
1377 G_TYPE_FROM_CLASS (gobject_class),
1378 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1379 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
1380 _gtk_boolean_handled_accumulator, NULL,
1381 _gtk_marshal_BOOLEAN__ENUM,
1383 GTK_TYPE_WIDGET_HELP_TYPE);
1384 widget_signals[ACCEL_CLOSURES_CHANGED] =
1385 g_signal_new ("accel_closures_changed",
1386 G_TYPE_FROM_CLASS (gobject_class),
1390 _gtk_marshal_NONE__NONE,
1392 widget_signals[SCREEN_CHANGED] =
1393 g_signal_new ("screen_changed",
1394 G_TYPE_FROM_CLASS (gobject_class),
1396 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
1398 _gtk_marshal_VOID__OBJECT,
1402 * GtkWidget::can-activate-accel:
1403 * @widget: the object which received the signal
1404 * @signal_id: the ID of a signal installed on @widget
1405 * @returns: %TRUE if the signal can be activated.
1407 * Determines whether an accelerator that activates the signal
1408 * identified by @signal_id can currently be activated.
1409 * This signal is present to allow applications and derived
1410 * widgets to override the default #GtkWidget handling
1411 * for determining whether an accelerator can be activated.
1413 widget_signals[CAN_ACTIVATE_ACCEL] =
1414 g_signal_new ("can_activate_accel",
1415 G_TYPE_FROM_CLASS (gobject_class),
1417 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
1418 _gtk_boolean_handled_accumulator, NULL,
1419 _gtk_marshal_BOOLEAN__UINT,
1420 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
1422 binding_set = gtk_binding_set_by_class (klass);
1423 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
1425 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
1428 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
1430 GTK_TYPE_WIDGET_HELP_TYPE,
1431 GTK_WIDGET_HELP_TOOLTIP);
1432 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
1434 GTK_TYPE_WIDGET_HELP_TYPE,
1435 GTK_WIDGET_HELP_TOOLTIP);
1436 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
1438 GTK_TYPE_WIDGET_HELP_TYPE,
1439 GTK_WIDGET_HELP_WHATS_THIS);
1440 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
1442 GTK_TYPE_WIDGET_HELP_TYPE,
1443 GTK_WIDGET_HELP_WHATS_THIS);
1445 gtk_widget_class_install_style_property (klass,
1446 g_param_spec_boolean ("interior-focus",
1447 P_("Interior Focus"),
1448 P_("Whether to draw the focus indicator inside widgets"),
1450 GTK_PARAM_READABLE));
1452 gtk_widget_class_install_style_property (klass,
1453 g_param_spec_int ("focus-line-width",
1454 P_("Focus linewidth"),
1455 P_("Width, in pixels, of the focus indicator line"),
1457 GTK_PARAM_READABLE));
1459 gtk_widget_class_install_style_property (klass,
1460 g_param_spec_string ("focus-line-pattern",
1461 P_("Focus line dash pattern"),
1462 P_("Dash pattern used to draw the focus indicator"),
1464 GTK_PARAM_READABLE));
1465 gtk_widget_class_install_style_property (klass,
1466 g_param_spec_int ("focus-padding",
1467 P_("Focus padding"),
1468 P_("Width, in pixels, between focus indicator and the widget 'box'"),
1470 GTK_PARAM_READABLE));
1471 gtk_widget_class_install_style_property (klass,
1472 g_param_spec_boxed ("cursor-color",
1474 P_("Color with which to draw insertion cursor"),
1476 GTK_PARAM_READABLE));
1477 gtk_widget_class_install_style_property (klass,
1478 g_param_spec_boxed ("secondary-cursor-color",
1479 P_("Secondary cursor color"),
1480 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
1482 GTK_PARAM_READABLE));
1483 gtk_widget_class_install_style_property (klass,
1484 g_param_spec_float ("cursor-aspect-ratio",
1485 P_("Cursor line aspect ratio"),
1486 P_("Aspect ratio with which to draw insertion cursor"),
1488 GTK_PARAM_READABLE));
1489 gtk_widget_class_install_style_property (klass,
1490 g_param_spec_boxed ("draw-border",
1492 P_("Size of areas outside the widget's allocation to draw"),
1494 GTK_PARAM_READABLE));
1498 gtk_widget_set_property (GObject *object,
1500 const GValue *value,
1503 GtkWidget *widget = GTK_WIDGET (object);
1507 guint32 saved_flags;
1510 gtk_widget_set_name (widget, g_value_get_string (value));
1513 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
1515 case PROP_WIDTH_REQUEST:
1516 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
1518 case PROP_HEIGHT_REQUEST:
1519 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
1522 if (g_value_get_boolean (value))
1523 gtk_widget_show (widget);
1525 gtk_widget_hide (widget);
1527 case PROP_SENSITIVE:
1528 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
1530 case PROP_APP_PAINTABLE:
1531 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
1533 case PROP_CAN_FOCUS:
1534 saved_flags = GTK_WIDGET_FLAGS (widget);
1535 if (g_value_get_boolean (value))
1536 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
1538 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
1539 if (saved_flags != GTK_WIDGET_FLAGS (widget))
1540 gtk_widget_queue_resize (widget);
1542 case PROP_HAS_FOCUS:
1543 if (g_value_get_boolean (value))
1544 gtk_widget_grab_focus (widget);
1547 if (g_value_get_boolean (value))
1548 gtk_widget_grab_focus (widget);
1550 case PROP_CAN_DEFAULT:
1551 saved_flags = GTK_WIDGET_FLAGS (widget);
1552 if (g_value_get_boolean (value))
1553 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
1555 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT);
1556 if (saved_flags != GTK_WIDGET_FLAGS (widget))
1557 gtk_widget_queue_resize (widget);
1559 case PROP_HAS_DEFAULT:
1560 if (g_value_get_boolean (value))
1561 gtk_widget_grab_default (widget);
1563 case PROP_RECEIVES_DEFAULT:
1564 if (g_value_get_boolean (value))
1565 GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1567 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1570 gtk_widget_set_style (widget, g_value_get_object (value));
1573 if (!GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget))
1574 gtk_widget_set_events (widget, g_value_get_flags (value));
1576 case PROP_EXTENSION_EVENTS:
1577 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
1579 case PROP_NO_SHOW_ALL:
1580 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
1588 gtk_widget_get_property (GObject *object,
1593 GtkWidget *widget = GTK_WIDGET (object);
1598 GdkExtensionMode *modep;
1602 g_value_set_string (value, widget->name);
1604 g_value_set_string (value, "");
1608 g_value_set_object (value, widget->parent);
1610 g_value_set_object (value, NULL);
1612 case PROP_WIDTH_REQUEST:
1615 gtk_widget_get_size_request (widget, &w, NULL);
1616 g_value_set_int (value, w);
1619 case PROP_HEIGHT_REQUEST:
1622 gtk_widget_get_size_request (widget, NULL, &h);
1623 g_value_set_int (value, h);
1627 g_value_set_boolean (value, (GTK_WIDGET_VISIBLE (widget) != FALSE));
1629 case PROP_SENSITIVE:
1630 g_value_set_boolean (value, (GTK_WIDGET_SENSITIVE (widget) != FALSE));
1632 case PROP_APP_PAINTABLE:
1633 g_value_set_boolean (value, (GTK_WIDGET_APP_PAINTABLE (widget) != FALSE));
1635 case PROP_CAN_FOCUS:
1636 g_value_set_boolean (value, (GTK_WIDGET_CAN_FOCUS (widget) != FALSE));
1638 case PROP_HAS_FOCUS:
1639 g_value_set_boolean (value, (GTK_WIDGET_HAS_FOCUS (widget) != FALSE));
1642 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
1644 case PROP_CAN_DEFAULT:
1645 g_value_set_boolean (value, (GTK_WIDGET_CAN_DEFAULT (widget) != FALSE));
1647 case PROP_HAS_DEFAULT:
1648 g_value_set_boolean (value, (GTK_WIDGET_HAS_DEFAULT (widget) != FALSE));
1650 case PROP_RECEIVES_DEFAULT:
1651 g_value_set_boolean (value, (GTK_WIDGET_RECEIVES_DEFAULT (widget) != FALSE));
1653 case PROP_COMPOSITE_CHILD:
1654 g_value_set_boolean (value, (GTK_WIDGET_COMPOSITE_CHILD (widget) != FALSE));
1657 g_value_set_object (value, gtk_widget_get_style (widget));
1660 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
1662 g_value_set_flags (value, 0);
1664 g_value_set_flags (value, *eventp);
1666 case PROP_EXTENSION_EVENTS:
1667 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
1669 g_value_set_enum (value, 0);
1671 g_value_set_enum (value, (GdkExtensionMode) *modep);
1673 case PROP_NO_SHOW_ALL:
1674 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
1677 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1683 gtk_widget_init (GtkWidget *widget)
1685 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
1686 widget->state = GTK_STATE_NORMAL;
1687 widget->saved_state = GTK_STATE_NORMAL;
1688 widget->name = NULL;
1689 widget->requisition.width = 0;
1690 widget->requisition.height = 0;
1691 widget->allocation.x = -1;
1692 widget->allocation.y = -1;
1693 widget->allocation.width = 1;
1694 widget->allocation.height = 1;
1695 widget->window = NULL;
1696 widget->parent = NULL;
1698 GTK_WIDGET_SET_FLAGS (widget,
1700 GTK_PARENT_SENSITIVE |
1701 (composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
1702 GTK_DOUBLE_BUFFERED);
1704 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
1705 GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
1706 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
1708 widget->style = gtk_widget_get_default_style ();
1709 g_object_ref (widget->style);
1714 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
1716 GParamSpec **pspecs)
1718 GtkWidget *container = widget->parent;
1721 for (i = 0; widget->parent == container && i < n_pspecs; i++)
1722 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
1726 * gtk_widget_freeze_child_notify:
1727 * @widget: a #GtkWidget
1729 * Stops emission of "child-notify" signals on @widget. The signals are
1730 * queued until gtk_widget_thaw_child_notify() is called on @widget.
1732 * This is the analogue of g_object_freeze_notify() for child properties.
1735 gtk_widget_freeze_child_notify (GtkWidget *widget)
1737 g_return_if_fail (GTK_IS_WIDGET (widget));
1739 if (!G_OBJECT (widget)->ref_count)
1742 g_object_ref (widget);
1743 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1744 g_object_unref (widget);
1748 * gtk_widget_child_notify:
1749 * @widget: a #GtkWidget
1750 * @child_property: the name of a child property installed on the
1751 * class of @widget<!-- -->'s parent.
1753 * Emits a "child-notify" signal for the
1754 * <link linkend="child-properties">child property</link> @child_property
1757 * This is the analogue of g_object_notify() for child properties.
1760 gtk_widget_child_notify (GtkWidget *widget,
1761 const gchar *child_property)
1765 g_return_if_fail (GTK_IS_WIDGET (widget));
1766 g_return_if_fail (child_property != NULL);
1767 if (!G_OBJECT (widget)->ref_count || !widget->parent)
1770 g_object_ref (widget);
1771 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
1773 G_OBJECT_TYPE (widget->parent),
1776 g_warning ("%s: container class `%s' has no child property named `%s'",
1778 G_OBJECT_TYPE_NAME (widget->parent),
1782 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1784 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
1785 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1787 g_object_unref (widget);
1791 * gtk_widget_thaw_child_notify:
1792 * @widget: a #GtkWidget
1794 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
1795 * This causes all queued "child-notify" signals on @widget to be emitted.
1798 gtk_widget_thaw_child_notify (GtkWidget *widget)
1800 GObjectNotifyQueue *nqueue;
1802 g_return_if_fail (GTK_IS_WIDGET (widget));
1804 if (!G_OBJECT (widget)->ref_count)
1807 g_object_ref (widget);
1808 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1809 if (!nqueue || !nqueue->freeze_count)
1810 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
1811 G_OBJECT_TYPE_NAME (widget), widget);
1813 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1814 g_object_unref (widget);
1820 * @type: type ID of the widget to create
1821 * @first_property_name: name of first property to set
1822 * @Varargs: value of first property, followed by more properties, %NULL-terminated
1824 * This is a convenience function for creating a widget and setting
1825 * its properties in one go. For example you might write:
1826 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
1827 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
1828 * g_object_new(), but returns a widget so you don't have to
1829 * cast the object yourself.
1831 * Return value: a new #GtkWidget of type @widget_type
1834 gtk_widget_new (GType type,
1835 const gchar *first_property_name,
1841 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
1843 va_start (var_args, first_property_name);
1844 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
1852 * @widget: a #GtkWidget
1853 * @first_property_name: name of first property to set
1854 * @Varargs: value of first property, followed by more properties, %NULL-terminated
1856 * Like g_object_set() - there's no reason to use this instead of
1860 gtk_widget_set (GtkWidget *widget,
1861 const gchar *first_property_name,
1866 g_return_if_fail (GTK_IS_WIDGET (widget));
1868 va_start (var_args, first_property_name);
1869 g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
1874 gtk_widget_queue_draw_child (GtkWidget *widget)
1878 parent = widget->parent;
1879 if (parent && GTK_WIDGET_DRAWABLE (parent))
1880 gtk_widget_queue_draw_area (parent,
1881 widget->allocation.x,
1882 widget->allocation.y,
1883 widget->allocation.width,
1884 widget->allocation.height);
1888 * gtk_widget_unparent:
1889 * @widget: a #GtkWidget
1891 * This function is only for use in widget implementations.
1892 * Should be called by implementations of the remove method
1893 * on #GtkContainer, to dissociate a child from the container.
1896 gtk_widget_unparent (GtkWidget *widget)
1898 GObjectNotifyQueue *nqueue;
1899 GtkWidget *toplevel;
1900 GtkWidget *old_parent;
1902 g_return_if_fail (GTK_IS_WIDGET (widget));
1903 if (widget->parent == NULL)
1906 /* keep this function in sync with gtk_menu_detach()
1909 g_object_freeze_notify (G_OBJECT (widget));
1910 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1912 toplevel = gtk_widget_get_toplevel (widget);
1913 if (GTK_WIDGET_TOPLEVEL (toplevel))
1914 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
1916 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
1917 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
1919 /* If we are unanchoring the child, we save around the toplevel
1920 * to emit hierarchy changed
1922 if (GTK_WIDGET_ANCHORED (widget->parent))
1923 g_object_ref (toplevel);
1927 gtk_widget_queue_draw_child (widget);
1929 /* Reset the width and height here, to force reallocation if we
1930 * get added back to a new parent. This won't work if our new
1931 * allocation is smaller than 1x1 and we actually want a size of 1x1...
1932 * (would 0x0 be OK here?)
1934 widget->allocation.width = 1;
1935 widget->allocation.height = 1;
1937 if (GTK_WIDGET_REALIZED (widget))
1939 if (GTK_WIDGET_IN_REPARENT (widget))
1940 gtk_widget_unmap (widget);
1942 gtk_widget_unrealize (widget);
1945 /* Removing a widget from a container restores the child visible
1946 * flag to the default state, so it doesn't affect the child
1947 * in the next parent.
1949 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
1951 old_parent = widget->parent;
1952 widget->parent = NULL;
1953 gtk_widget_set_parent_window (widget, NULL);
1954 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
1957 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
1958 g_object_unref (toplevel);
1961 g_object_notify (G_OBJECT (widget), "parent");
1962 g_object_thaw_notify (G_OBJECT (widget));
1963 if (!widget->parent)
1964 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
1965 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1966 g_object_unref (widget);
1970 * gtk_widget_destroy:
1971 * @widget: a #GtkWidget
1973 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
1974 * you don't have to cast the widget to #GtkObject. When a widget is
1975 * destroyed, it will break any references it holds to other objects.
1976 * If the widget is inside a container, the widget will be removed
1977 * from the container. If the widget is a toplevel (derived from
1978 * #GtkWindow), it will be removed from the list of toplevels, and the
1979 * reference GTK+ holds to it will be removed. Removing a
1980 * widget from its container or the list of toplevels results in the
1981 * widget being finalized, unless you've added additional references
1982 * to the widget with g_object_ref().
1984 * In most cases, only toplevel widgets (windows) require explicit
1985 * destruction, because when you destroy a toplevel its children will
1986 * be destroyed as well.
1990 gtk_widget_destroy (GtkWidget *widget)
1992 g_return_if_fail (GTK_IS_WIDGET (widget));
1994 gtk_object_destroy ((GtkObject*) widget);
1998 * gtk_widget_destroyed:
1999 * @widget: a #GtkWidget
2000 * @widget_pointer: address of a variable that contains @widget
2002 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
2003 * %NULL. It's intended to be used as a callback connected to the
2004 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
2005 * as a signal handler, and pass the address of your widget variable
2006 * as user data. Then when the widget is destroyed, the variable will
2007 * be set to %NULL. Useful for example to avoid multiple copies
2008 * of the same dialog.
2012 gtk_widget_destroyed (GtkWidget *widget,
2013 GtkWidget **widget_pointer)
2015 /* Don't make any assumptions about the
2017 * Even check widget_pointer.
2020 *widget_pointer = NULL;
2025 * @widget: a #GtkWidget
2027 * Flags a widget to be displayed. Any widget that isn't shown will
2028 * not appear on the screen. If you want to show all the widgets in a
2029 * container, it's easier to call gtk_widget_show_all() on the
2030 * container, instead of individually showing the widgets.
2032 * Remember that you have to show the containers containing a widget,
2033 * in addition to the widget itself, before it will appear onscreen.
2035 * When a toplevel container is shown, it is immediately realized and
2036 * mapped; other shown widgets are realized and mapped when their
2037 * toplevel container is realized and mapped.
2041 gtk_widget_show (GtkWidget *widget)
2043 if (!GTK_WIDGET_VISIBLE (widget))
2045 g_object_ref (widget);
2046 if (!GTK_WIDGET_TOPLEVEL (widget))
2047 gtk_widget_queue_resize (widget);
2048 g_signal_emit (widget, widget_signals[SHOW], 0);
2049 g_object_notify (G_OBJECT (widget), "visible");
2050 g_object_unref (widget);
2055 gtk_widget_real_show (GtkWidget *widget)
2057 if (!GTK_WIDGET_VISIBLE (widget))
2059 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
2061 if (widget->parent &&
2062 GTK_WIDGET_MAPPED (widget->parent) &&
2063 GTK_WIDGET_CHILD_VISIBLE (widget) &&
2064 !GTK_WIDGET_MAPPED (widget))
2065 gtk_widget_map (widget);
2070 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
2073 g_signal_handlers_disconnect_by_func (widget,
2074 gtk_widget_show_map_callback,
2079 * gtk_widget_show_now:
2080 * @widget: a #GtkWidget
2082 * Shows a widget. If the widget is an unmapped toplevel widget
2083 * (i.e. a #GtkWindow that has not yet been shown), enter the main
2084 * loop and wait for the window to actually be mapped. Be careful;
2085 * because the main loop is running, anything can happen during
2089 gtk_widget_show_now (GtkWidget *widget)
2093 g_return_if_fail (GTK_IS_WIDGET (widget));
2095 /* make sure we will get event */
2096 if (!GTK_WIDGET_MAPPED (widget) &&
2097 GTK_WIDGET_TOPLEVEL (widget))
2099 gtk_widget_show (widget);
2101 g_signal_connect (widget, "map_event",
2102 G_CALLBACK (gtk_widget_show_map_callback),
2106 gtk_main_iteration ();
2109 gtk_widget_show (widget);
2114 * @widget: a #GtkWidget
2116 * Reverses the effects of gtk_widget_show(), causing the widget to be
2117 * hidden (invisible to the user).
2120 gtk_widget_hide (GtkWidget *widget)
2122 g_return_if_fail (GTK_IS_WIDGET (widget));
2124 if (GTK_WIDGET_VISIBLE (widget))
2126 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
2128 g_object_ref (widget);
2129 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
2130 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
2132 g_signal_emit (widget, widget_signals[HIDE], 0);
2133 if (!GTK_WIDGET_TOPLEVEL (widget))
2134 gtk_widget_queue_resize (widget);
2135 g_object_notify (G_OBJECT (widget), "visible");
2136 g_object_unref (widget);
2141 gtk_widget_real_hide (GtkWidget *widget)
2143 if (GTK_WIDGET_VISIBLE (widget))
2145 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
2147 if (GTK_WIDGET_MAPPED (widget))
2148 gtk_widget_unmap (widget);
2153 * gtk_widget_hide_on_delete:
2154 * @widget: a #GtkWidget
2156 * Utility function; intended to be connected to the "delete_event"
2157 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
2158 * argument, then returns %TRUE. If connected to "delete_event", the
2159 * result is that clicking the close button for a window (on the
2160 * window frame, top right corner usually) will hide but not destroy
2161 * the window. By default, GTK+ destroys windows when "delete_event"
2164 * Return value: %TRUE
2167 gtk_widget_hide_on_delete (GtkWidget *widget)
2169 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2171 gtk_widget_hide (widget);
2177 * gtk_widget_show_all:
2178 * @widget: a #GtkWidget
2180 * Recursively shows a widget, and any child widgets (if the widget is
2184 gtk_widget_show_all (GtkWidget *widget)
2186 GtkWidgetClass *class;
2188 g_return_if_fail (GTK_IS_WIDGET (widget));
2190 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
2193 class = GTK_WIDGET_GET_CLASS (widget);
2195 if (class->show_all)
2196 class->show_all (widget);
2200 * gtk_widget_hide_all:
2201 * @widget: a #GtkWidget
2203 * Recursively hides a widget and any child widgets.
2206 gtk_widget_hide_all (GtkWidget *widget)
2208 GtkWidgetClass *class;
2210 g_return_if_fail (GTK_IS_WIDGET (widget));
2212 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
2215 class = GTK_WIDGET_GET_CLASS (widget);
2217 if (class->hide_all)
2218 class->hide_all (widget);
2223 * @widget: a #GtkWidget
2225 * This function is only for use in widget implementations. Causes
2226 * a widget to be mapped if it isn't already.
2230 gtk_widget_map (GtkWidget *widget)
2232 g_return_if_fail (GTK_IS_WIDGET (widget));
2233 g_return_if_fail (GTK_WIDGET_VISIBLE (widget));
2234 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
2236 if (!GTK_WIDGET_MAPPED (widget))
2238 if (!GTK_WIDGET_REALIZED (widget))
2239 gtk_widget_realize (widget);
2241 g_signal_emit (widget, widget_signals[MAP], 0);
2243 if (GTK_WIDGET_NO_WINDOW (widget))
2244 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
2250 * @widget: a #GtkWidget
2252 * This function is only for use in widget implementations. Causes
2253 * a widget to be unmapped if it's currently mapped.
2257 gtk_widget_unmap (GtkWidget *widget)
2259 g_return_if_fail (GTK_IS_WIDGET (widget));
2261 if (GTK_WIDGET_MAPPED (widget))
2263 if (GTK_WIDGET_NO_WINDOW (widget))
2264 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
2265 g_signal_emit (widget, widget_signals[UNMAP], 0);
2270 * gtk_widget_realize:
2271 * @widget: a #GtkWidget
2273 * Creates the GDK (windowing system) resources associated with a
2274 * widget. For example, @widget->window will be created when a widget
2275 * is realized. Normally realization happens implicitly; if you show
2276 * a widget and all its parent containers, then the widget will be
2277 * realized and mapped automatically.
2279 * Realizing a widget requires all
2280 * the widget's parent widgets to be realized; calling
2281 * gtk_widget_realize() realizes the widget's parents in addition to
2282 * @widget itself. If a widget is not yet inside a toplevel window
2283 * when you realize it, bad things will happen.
2285 * This function is primarily used in widget implementations, and
2286 * isn't very useful otherwise. Many times when you think you might
2287 * need it, a better approach is to connect to a signal that will be
2288 * called after the widget is realized automatically, such as
2289 * "expose_event". Or simply g_signal_connect_after() to the
2294 gtk_widget_realize (GtkWidget *widget)
2297 GdkExtensionMode mode;
2298 GtkWidgetShapeInfo *shape_info;
2300 g_return_if_fail (GTK_IS_WIDGET (widget));
2301 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
2302 GTK_IS_INVISIBLE (widget));
2304 if (!GTK_WIDGET_REALIZED (widget))
2307 if (GTK_IS_CONTAINER (widget) && !GTK_WIDGET_NO_WINDOW (widget))
2308 g_message ("gtk_widget_realize(%s)", g_type_name (GTK_WIDGET_TYPE (widget)));
2311 if (widget->parent == NULL &&
2312 !GTK_WIDGET_TOPLEVEL (widget))
2313 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
2314 "inside a toplevel window is not going to work very well. "
2315 "Widgets must be inside a toplevel container before realizing them.");
2317 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
2318 gtk_widget_realize (widget->parent);
2320 gtk_widget_ensure_style (widget);
2322 g_signal_emit (widget, widget_signals[REALIZE], 0);
2324 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
2326 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
2327 gdk_window_shape_combine_mask (widget->window,
2328 shape_info->shape_mask,
2329 shape_info->offset_x,
2330 shape_info->offset_y);
2333 if (!GTK_WIDGET_NO_WINDOW (widget))
2335 mode = gtk_widget_get_extension_events (widget);
2336 if (mode != GDK_EXTENSION_EVENTS_NONE)
2338 events = gtk_widget_get_events (widget);
2339 gdk_input_set_extension_events (widget->window, events, mode);
2347 check_window (gpointer window,
2352 gdk_window_get_user_data (GDK_WINDOW (window), &data);
2355 g_warning ("Faulty widget implementation: unrealize failed to clear window");
2359 * gtk_widget_unrealize:
2360 * @widget: a #GtkWidget
2362 * This function is only useful in widget implementations.
2363 * Causes a widget to be unrealized (frees all GDK resources
2364 * associated with the widget, such as @widget->window).
2368 gtk_widget_unrealize (GtkWidget *widget)
2370 g_return_if_fail (GTK_IS_WIDGET (widget));
2372 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
2373 gtk_widget_shape_combine_mask (widget, NULL, -1, -1);
2375 if (GTK_WIDGET_REALIZED (widget))
2377 g_object_ref (widget);
2378 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
2379 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
2380 g_object_unref (widget);
2383 #ifdef GDK_WINDOWING_X11
2384 gdk_x11_display_foreach_window (gtk_widget_get_display (widget),
2385 check_window, widget);
2389 /*****************************************
2391 *****************************************/
2394 * gtk_widget_queue_draw_area:
2395 * @widget: a #GtkWidget
2396 * @x: x coordinate of upper-left corner of rectangle to redraw
2397 * @y: y coordinate of upper-left corner of rectangle to redraw
2398 * @width: width of region to draw
2399 * @height: height of region to draw
2401 * Invalidates the rectangular area of @widget defined by @x, @y,
2402 * @width and @height by calling gdk_window_invalidate_rect() on the
2403 * widget's window and all its child windows. Once the main loop
2404 * becomes idle (after the current batch of events has been processed,
2405 * roughly), the window will receive expose events for the union of
2406 * all regions that have been invalidated.
2408 * Normally you would only use this function in widget
2409 * implementations. You might also use it, or
2410 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
2411 * #GtkDrawingArea or some portion thereof.
2413 * Frequently you can just call gdk_window_invalidate_rect() or
2414 * gdk_window_invalidate_region() instead of this function. Those
2415 * functions will invalidate only a single window, instead of the
2416 * widget and all its children.
2418 * The advantage of adding to the invalidated region compared to
2419 * simply drawing immediately is efficiency; using an invalid region
2420 * ensures that you only have to redraw one time.
2424 gtk_widget_queue_draw_area (GtkWidget *widget,
2430 GdkRectangle invalid_rect;
2433 g_return_if_fail (GTK_IS_WIDGET (widget));
2435 if (!GTK_WIDGET_REALIZED (widget))
2438 /* Just return if the widget or one of its ancestors isn't mapped */
2439 for (w = widget; w != NULL; w = w->parent)
2440 if (!GTK_WIDGET_MAPPED (w))
2443 /* Find the correct widget */
2445 if (!GTK_WIDGET_NO_WINDOW (widget))
2449 /* Translate widget relative to window-relative */
2451 gint wx, wy, wwidth, wheight;
2453 gdk_window_get_position (widget->window, &wx, &wy);
2454 x -= wx - widget->allocation.x;
2455 y -= wy - widget->allocation.y;
2457 gdk_drawable_get_size (widget->window, &wwidth, &wheight);
2459 if (x + width <= 0 || y + height <= 0 ||
2460 x >= wwidth || y >= wheight)
2471 if (x + width > wwidth)
2473 if (y + height > wheight)
2474 height = wheight - y;
2480 invalid_rect.width = width;
2481 invalid_rect.height = height;
2483 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
2487 widget_add_child_draw_rectangle (GtkWidget *widget,
2490 GdkRectangle child_rect;
2492 if (!GTK_WIDGET_MAPPED (widget) ||
2493 widget->window != widget->parent->window)
2496 gtk_widget_get_draw_rectangle (widget, &child_rect);
2497 gdk_rectangle_union (rect, &child_rect, rect);
2501 gtk_widget_get_draw_rectangle (GtkWidget *widget,
2504 if (GTK_WIDGET_NO_WINDOW (widget))
2506 GtkBorder *draw_border = NULL;
2508 *rect = widget->allocation;
2510 gtk_widget_style_get (widget,
2511 "draw-border", &draw_border,
2515 rect->x -= draw_border->top;
2516 rect->y -= draw_border->left;
2517 rect->width += draw_border->left + draw_border->right;
2518 rect->height += draw_border->top + draw_border->bottom;
2521 if (GTK_IS_CONTAINER (widget))
2522 gtk_container_forall (GTK_CONTAINER (widget),
2523 (GtkCallback)widget_add_child_draw_rectangle,
2530 rect->width = widget->allocation.width;
2531 rect->height = widget->allocation.height;
2536 * gtk_widget_queue_draw:
2537 * @widget: a #GtkWidget
2539 * Equivalent to calling gtk_widget_queue_draw_area() for the
2540 * entire area of a widget.
2544 gtk_widget_queue_draw (GtkWidget *widget)
2548 g_return_if_fail (GTK_IS_WIDGET (widget));
2550 gtk_widget_get_draw_rectangle (widget, &rect);
2552 gtk_widget_queue_draw_area (widget,
2554 rect.width, rect.height);
2557 /* Invalidates the given area (allocation-relative-coordinates)
2558 * in all of the widget's windows
2561 * gtk_widget_queue_clear_area:
2562 * @widget: a #GtkWidget
2563 * @x: x coordinate of upper-left corner of rectangle to redraw
2564 * @y: y coordinate of upper-left corner of rectangle to redraw
2565 * @width: width of region to draw
2566 * @height: height of region to draw
2568 * This function is no longer different from
2569 * gtk_widget_queue_draw_area(), though it once was. Now it just calls
2570 * gtk_widget_queue_draw_area(). Originally
2571 * gtk_widget_queue_clear_area() would force a redraw of the
2572 * background for %GTK_NO_WINDOW widgets, and
2573 * gtk_widget_queue_draw_area() would not. Now both functions ensure
2574 * the background will be redrawn.
2576 * @Deprecated: Use gtk_widget_queue_draw_area() instead.
2579 gtk_widget_queue_clear_area (GtkWidget *widget,
2585 g_return_if_fail (GTK_IS_WIDGET (widget));
2587 gtk_widget_queue_draw_area (widget, x, y, width, height);
2591 * gtk_widget_queue_clear:
2592 * @widget: a #GtkWidget
2594 * This function does the same as gtk_widget_queue_draw().
2596 * @Deprecated: Use gtk_widget_queue_draw() instead.
2599 gtk_widget_queue_clear (GtkWidget *widget)
2601 g_return_if_fail (GTK_IS_WIDGET (widget));
2603 gtk_widget_queue_draw (widget);
2607 * gtk_widget_queue_resize:
2608 * @widget: a #GtkWidget
2610 * This function is only for use in widget implementations.
2611 * Flags a widget to have its size renegotiated; should
2612 * be called when a widget for some reason has a new size request.
2613 * For example, when you change the text in a #GtkLabel, #GtkLabel
2614 * queues a resize to ensure there's enough space for the new text.
2617 gtk_widget_queue_resize (GtkWidget *widget)
2619 g_return_if_fail (GTK_IS_WIDGET (widget));
2621 if (GTK_WIDGET_REALIZED (widget))
2622 gtk_widget_queue_shallow_draw (widget);
2624 _gtk_size_group_queue_resize (widget);
2628 * gtk_widget_queue_resize_no_redraw:
2629 * @widget: a #GtkWidget
2631 * This function works like gtk_widget_queue_resize(), except that the
2632 * widget is not invalidated.
2637 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
2639 g_return_if_fail (GTK_IS_WIDGET (widget));
2641 _gtk_size_group_queue_resize (widget);
2646 * @widget: a #GtkWidget
2647 * @area: area to draw
2649 * In GTK+ 1.2, this function would immediately render the
2650 * region @area of a widget, by invoking the virtual draw method of a
2651 * widget. In GTK+ 2.0, the draw method is gone, and instead
2652 * gtk_widget_draw() simply invalidates the specified region of the
2653 * widget, then updates the invalid region of the widget immediately.
2654 * Usually you don't want to update the region immediately for
2655 * performance reasons, so in general gtk_widget_queue_draw_area() is
2656 * a better choice if you want to draw a region of a widget.
2660 gtk_widget_draw (GtkWidget *widget,
2663 g_return_if_fail (GTK_IS_WIDGET (widget));
2665 if (GTK_WIDGET_DRAWABLE (widget))
2668 gtk_widget_queue_draw_area (widget,
2670 area->width, area->height);
2672 gtk_widget_queue_draw (widget);
2674 gdk_window_process_updates (widget->window, TRUE);
2679 * gtk_widget_size_request:
2680 * @widget: a #GtkWidget
2681 * @requisition: a #GtkRequisition to be filled in
2683 * This function is typically used when implementing a #GtkContainer
2684 * subclass. Obtains the preferred size of a widget. The container
2685 * uses this information to arrange its child widgets and decide what
2686 * size allocations to give them with gtk_widget_size_allocate().
2688 * You can also call this function from an application, with some
2689 * caveats. Most notably, getting a size request requires the widget
2690 * to be associated with a screen, because font information may be
2691 * needed. Multihead-aware applications should keep this in mind.
2693 * Also remember that the size request is not necessarily the size
2694 * a widget will actually be allocated.
2696 * See also gtk_widget_get_child_requisition().
2699 gtk_widget_size_request (GtkWidget *widget,
2700 GtkRequisition *requisition)
2702 g_return_if_fail (GTK_IS_WIDGET (widget));
2704 #ifdef G_ENABLE_DEBUG
2705 if (requisition == &widget->requisition)
2706 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.");
2707 #endif /* G_ENABLE_DEBUG */
2709 _gtk_size_group_compute_requisition (widget, requisition);
2713 * gtk_widget_get_child_requisition:
2714 * @widget: a #GtkWidget
2715 * @requisition: a #GtkRequisition to be filled in
2717 * This function is only for use in widget implementations. Obtains
2718 * @widget->requisition, unless someone has forced a particular
2719 * geometry on the widget (e.g. with gtk_widget_set_usize()), in which
2720 * case it returns that geometry instead of the widget's requisition.
2722 * This function differs from gtk_widget_size_request() in that
2723 * it retrieves the last size request value from @widget->requisition,
2724 * while gtk_widget_size_request() actually calls the "size_request" method
2725 * on @widget to compute the size request and fill in @widget->requisition,
2726 * and only then returns @widget->requisition.
2728 * Because this function does not call the "size_request" method, it
2729 * can only be used when you know that @widget->requisition is
2730 * up-to-date, that is, gtk_widget_size_request() has been called
2731 * since the last time a resize was queued. In general, only container
2732 * implementations have this information; applications should use
2733 * gtk_widget_size_request().
2736 gtk_widget_get_child_requisition (GtkWidget *widget,
2737 GtkRequisition *requisition)
2739 _gtk_size_group_get_child_requisition (widget, requisition);
2743 invalidate_predicate (GdkWindow *window,
2748 gdk_window_get_user_data (window, &user_data);
2750 return (user_data == data);
2753 /* Invalidate @region in widget->window and all children
2754 * of widget->window owned by widget. @region is in the
2755 * same coordinates as widget->allocation and will be
2756 * modified by this call.
2759 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
2762 if (!GTK_WIDGET_REALIZED (widget))
2765 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
2769 gdk_window_get_position (widget->window, &x, &y);
2770 gdk_region_offset (region, -x, -y);
2773 gdk_window_invalidate_maybe_recurse (widget->window, region,
2774 invalidate_predicate, widget);
2778 * gtk_widget_queue_shallow_draw:
2779 * @widget: a #GtkWidget
2781 * Like gtk_widget_queue_draw(), but only windows owned
2782 * by @widget are invalidated.
2785 gtk_widget_queue_shallow_draw (GtkWidget *widget)
2790 g_return_if_fail (GTK_IS_WIDGET (widget));
2792 if (!GTK_WIDGET_REALIZED (widget))
2795 gtk_widget_get_draw_rectangle (widget, &rect);
2797 /* get_draw_rectangle() gives us window coordinates, we
2798 * need to convert to the coordinates that widget->allocation
2801 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
2805 gdk_window_get_position (widget->window, &wx, &wy);
2811 region = gdk_region_rectangle (&rect);
2812 gtk_widget_invalidate_widget_windows (widget, region);
2813 gdk_region_destroy (region);
2817 * gtk_widget_size_allocate:
2818 * @widget: a #GtkWidget
2819 * @allocation: position and size to be allocated to @widget
2821 * This function is only used by #GtkContainer subclasses, to assign a size
2822 * and position to their child widgets.
2826 gtk_widget_size_allocate (GtkWidget *widget,
2827 GtkAllocation *allocation)
2829 GtkWidgetAuxInfo *aux_info;
2830 GdkRectangle real_allocation;
2831 GdkRectangle old_allocation;
2832 gboolean alloc_needed;
2833 gboolean size_changed;
2834 gboolean position_changed;
2836 g_return_if_fail (GTK_IS_WIDGET (widget));
2838 #ifdef G_ENABLE_DEBUG
2839 if (gtk_debug_flags & GTK_DEBUG_GEOMETRY)
2850 parent = gtk_widget_get_parent (parent);
2853 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
2854 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
2855 2 * depth, " ", name,
2856 allocation->width, allocation->height);
2858 #endif /* G_ENABLE_DEBUG */
2860 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
2861 if (!GTK_WIDGET_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
2862 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
2864 old_allocation = widget->allocation;
2865 real_allocation = *allocation;
2866 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
2870 if (aux_info->x_set)
2871 real_allocation.x = aux_info->x;
2872 if (aux_info->y_set)
2873 real_allocation.y = aux_info->y;
2876 if (real_allocation.width < 0 || real_allocation.height < 0)
2878 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
2879 real_allocation.width,
2880 real_allocation.height);
2883 real_allocation.width = MAX (real_allocation.width, 1);
2884 real_allocation.height = MAX (real_allocation.height, 1);
2886 size_changed = (old_allocation.width != real_allocation.width ||
2887 old_allocation.height != real_allocation.height);
2888 position_changed = (old_allocation.x != real_allocation.x ||
2889 old_allocation.y != real_allocation.y);
2891 if (!alloc_needed && !size_changed && !position_changed)
2894 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
2896 if (GTK_WIDGET_MAPPED (widget))
2898 if (GTK_WIDGET_NO_WINDOW (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
2900 /* Invalidate union(old_allaction,widget->allocation) in widget->window
2902 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
2903 gdk_region_union_with_rect (invalidate, &old_allocation);
2905 gdk_window_invalidate_region (widget->window, invalidate, FALSE);
2906 gdk_region_destroy (invalidate);
2911 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
2913 /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
2915 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
2916 gdk_region_union_with_rect (invalidate, &old_allocation);
2918 gtk_widget_invalidate_widget_windows (widget, invalidate);
2919 gdk_region_destroy (invalidate);
2924 if ((size_changed || position_changed) && widget->parent &&
2925 GTK_WIDGET_REALIZED (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
2927 GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
2928 gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
2929 gdk_region_destroy (invalidate);
2934 * gtk_widget_common_ancestor:
2935 * @widget_a: a #GtkWidget
2936 * @widget_b: a #GtkWidget
2938 * Find the common ancestor of @widget_a and @widget_b that
2939 * is closest to the two widgets.
2941 * Return value: the closest common ancestor of @widget_a and
2942 * @widget_b or %NULL if @widget_a and @widget_b do not
2943 * share a common ancestor.
2946 gtk_widget_common_ancestor (GtkWidget *widget_a,
2947 GtkWidget *widget_b)
2949 GtkWidget *parent_a;
2950 GtkWidget *parent_b;
2954 parent_a = widget_a;
2955 while (parent_a->parent)
2957 parent_a = parent_a->parent;
2961 parent_b = widget_b;
2962 while (parent_b->parent)
2964 parent_b = parent_b->parent;
2968 if (parent_a != parent_b)
2971 while (depth_a > depth_b)
2973 widget_a = widget_a->parent;
2977 while (depth_b > depth_a)
2979 widget_b = widget_b->parent;
2983 while (widget_a != widget_b)
2985 widget_a = widget_a->parent;
2986 widget_b = widget_b->parent;
2993 * gtk_widget_translate_coordinates:
2994 * @src_widget: a #GtkWidget
2995 * @dest_widget: a #GtkWidget
2996 * @src_x: X position relative to @src_widget
2997 * @src_y: Y position relative to @src_widget
2998 * @dest_x: location to store X position relative to @dest_widget
2999 * @dest_y: location to store Y position relative to @dest_widget
3001 * Translate coordinates relative to @src_widget's allocation to coordinates
3002 * relative to @dest_widget's allocations. In order to perform this
3003 * operation, both widgets must be realized, and must share a common
3006 * Return value: %FALSE if either widget was not realized, or there
3007 * was no common ancestor. In this case, nothing is stored in
3008 * *@dest_x and *@dest_y. Otherwise %TRUE.
3011 gtk_widget_translate_coordinates (GtkWidget *src_widget,
3012 GtkWidget *dest_widget,
3018 GtkWidget *ancestor;
3021 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
3022 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
3024 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
3025 if (!ancestor || !GTK_WIDGET_REALIZED (src_widget) || !GTK_WIDGET_REALIZED (dest_widget))
3028 /* Translate from allocation relative to window relative */
3029 if (!GTK_WIDGET_NO_WINDOW (src_widget) && src_widget->parent)
3032 gdk_window_get_position (src_widget->window, &wx, &wy);
3034 src_x -= wx - src_widget->allocation.x;
3035 src_y -= wy - src_widget->allocation.y;
3039 src_x += src_widget->allocation.x;
3040 src_y += src_widget->allocation.y;
3043 /* Translate to the common ancestor */
3044 window = src_widget->window;
3045 while (window != ancestor->window)
3049 gdk_window_get_position (window, &dx, &dy);
3054 window = gdk_window_get_parent (window);
3056 if (!window) /* Handle GtkHandleBox */
3061 window = dest_widget->window;
3062 while (window != ancestor->window)
3066 gdk_window_get_position (window, &dx, &dy);
3071 window = gdk_window_get_parent (window);
3073 if (!window) /* Handle GtkHandleBox */
3077 /* Translate from window relative to allocation relative */
3078 if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent)
3081 gdk_window_get_position (dest_widget->window, &wx, &wy);
3083 src_x += wx - dest_widget->allocation.x;
3084 src_y += wy - dest_widget->allocation.y;
3088 src_x -= dest_widget->allocation.x;
3089 src_y -= dest_widget->allocation.y;
3101 gtk_widget_real_size_allocate (GtkWidget *widget,
3102 GtkAllocation *allocation)
3104 widget->allocation = *allocation;
3106 if (GTK_WIDGET_REALIZED (widget) &&
3107 !GTK_WIDGET_NO_WINDOW (widget))
3109 gdk_window_move_resize (widget->window,
3110 allocation->x, allocation->y,
3111 allocation->width, allocation->height);
3116 gtk_widget_real_can_activate_accel (GtkWidget *widget,
3119 /* widgets must be onscreen for accels to take effect */
3120 return GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_DRAWABLE (widget) && gdk_window_is_viewable (widget->window);
3124 * gtk_widget_can_activate_accel:
3125 * @widget: a #GtkWidget
3126 * @signal_id: the ID of a signal installed on @widget
3128 * Determines whether an accelerator that activates the signal
3129 * identified by @signal_id can currently be activated.
3130 * This is done by emitting the GtkWidget::can-activate-accel
3131 * signal on @widget; if the signal isn't overridden by a
3132 * handler or in a derived widget, then the default check is
3133 * that the widget must be sensitive, and the widget and all
3134 * its ancestors mapped.
3136 * Return value: %TRUE if the accelerator can be activated.
3141 gtk_widget_can_activate_accel (GtkWidget *widget,
3144 gboolean can_activate = FALSE;
3145 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3146 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
3147 return can_activate;
3156 closure_accel_activate (GClosure *closure,
3157 GValue *return_value,
3158 guint n_param_values,
3159 const GValue *param_values,
3160 gpointer invocation_hint,
3161 gpointer marshal_data)
3163 AccelClosure *aclosure = (AccelClosure*) closure;
3164 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
3167 g_signal_emit (closure->data, aclosure->signal_id, 0);
3169 /* whether accelerator was handled */
3170 g_value_set_boolean (return_value, can_activate);
3174 closures_destroy (gpointer data)
3176 GSList *slist, *closures = data;
3178 for (slist = closures; slist; slist = slist->next)
3180 g_closure_invalidate (slist->data);
3181 g_closure_unref (slist->data);
3183 g_slist_free (closures);
3187 widget_new_accel_closure (GtkWidget *widget,
3190 AccelClosure *aclosure;
3191 GClosure *closure = NULL;
3192 GSList *slist, *closures;
3194 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
3195 for (slist = closures; slist; slist = slist->next)
3196 if (!gtk_accel_group_from_accel_closure (slist->data))
3198 /* reuse this closure */
3199 closure = slist->data;
3204 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
3205 closures = g_slist_prepend (closures, g_closure_ref (closure));
3206 g_closure_sink (closure);
3207 g_closure_set_marshal (closure, closure_accel_activate);
3209 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
3211 aclosure = (AccelClosure*) closure;
3212 g_assert (closure->data == widget);
3213 g_assert (closure->marshal == closure_accel_activate);
3214 aclosure->signal_id = signal_id;
3220 * gtk_widget_add_accelerator
3221 * @widget: widget to install an accelerator on
3222 * @accel_signal: widget signal to emit on accelerator activation
3223 * @accel_group: accel group for this widget, added to its toplevel
3224 * @accel_key: GDK keyval of the accelerator
3225 * @accel_mods: modifier key combination of the accelerator
3226 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
3228 * Installs an accelerator for this @widget in @accel_group that causes
3229 * @accel_signal to be emitted if the accelerator is activated.
3230 * The @accel_group needs to be added to the widget's toplevel via
3231 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
3232 * Accelerators added through this function are not user changeable during
3233 * runtime. If you want to support accelerators that can be changed by the
3234 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
3235 * gtk_menu_item_set_accel_path() instead.
3238 gtk_widget_add_accelerator (GtkWidget *widget,
3239 const gchar *accel_signal,
3240 GtkAccelGroup *accel_group,
3242 GdkModifierType accel_mods,
3243 GtkAccelFlags accel_flags)
3248 g_return_if_fail (GTK_IS_WIDGET (widget));
3249 g_return_if_fail (accel_signal != NULL);
3250 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
3252 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
3253 if (!query.signal_id ||
3254 !(query.signal_flags & G_SIGNAL_ACTION) ||
3255 query.return_type != G_TYPE_NONE ||
3258 /* hmm, should be elaborate enough */
3259 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
3260 G_OBJECT_TYPE_NAME (widget), accel_signal);
3264 closure = widget_new_accel_closure (widget, query.signal_id);
3266 g_object_ref (widget);
3268 /* install the accelerator. since we don't map this onto an accel_path,
3269 * the accelerator will automatically be locked.
3271 gtk_accel_group_connect (accel_group,
3274 accel_flags | GTK_ACCEL_LOCKED,
3277 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3279 g_object_unref (widget);
3283 * gtk_widget_remove_accelerator:
3284 * @widget: widget to install an accelerator on
3285 * @accel_group: accel group for this widget
3286 * @accel_key: GDK keyval of the accelerator
3287 * @accel_mods: modifier key combination of the accelerator
3288 * @returns: whether an accelerator was installed and could be removed
3290 * Removes an accelerator from @widget, previously installed with
3291 * gtk_widget_add_accelerator().
3294 gtk_widget_remove_accelerator (GtkWidget *widget,
3295 GtkAccelGroup *accel_group,
3297 GdkModifierType accel_mods)
3299 GtkAccelGroupEntry *ag_entry;
3300 GList *slist, *clist;
3303 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3304 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
3306 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
3307 clist = gtk_widget_list_accel_closures (widget);
3308 for (slist = clist; slist; slist = slist->next)
3312 for (i = 0; i < n; i++)
3313 if (slist->data == (gpointer) ag_entry[i].closure)
3315 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
3317 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3319 g_list_free (clist);
3324 g_list_free (clist);
3326 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
3327 accel_key, accel_mods, accel_group,
3328 G_OBJECT_TYPE_NAME (widget), widget);
3334 * gtk_widget_list_accel_closures
3335 * @widget: widget to list accelerator closures for
3336 * @returns: a newly allocated #GList of closures
3338 * Lists the closures used by @widget for accelerator group connections
3339 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
3340 * The closures can be used to monitor accelerator changes on @widget,
3341 * by connecting to the ::accel_changed signal of the #GtkAccelGroup of a
3342 * closure which can be found out with gtk_accel_group_from_accel_closure().
3345 gtk_widget_list_accel_closures (GtkWidget *widget)
3348 GList *clist = NULL;
3350 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3352 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
3353 if (gtk_accel_group_from_accel_closure (slist->data))
3354 clist = g_list_prepend (clist, slist->data);
3361 GtkAccelGroup *accel_group;
3366 destroy_accel_path (gpointer data)
3368 AccelPath *apath = data;
3370 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
3372 /* closures_destroy takes care of unrefing the closure */
3373 g_object_unref (apath->accel_group);
3380 * gtk_widget_set_accel_path:
3381 * @widget: a #GtkWidget
3382 * @accel_path: path used to look up the accelerator
3383 * @accel_group: a #GtkAccelGroup.
3385 * Given an accelerator group, @accel_group, and an accelerator path,
3386 * @accel_path, sets up an accelerator in @accel_group so whenever the
3387 * key binding that is defined for @accel_path is pressed, @widget
3388 * will be activated. This removes any accelerators (for any
3389 * accelerator group) installed by previous calls to
3390 * gtk_widget_set_accel_path(). Associating accelerators with
3391 * paths allows them to be modified by the user and the modifications
3392 * to be saved for future use. (See gtk_accel_map_save().)
3394 * This function is a low level function that would most likely
3395 * be used by a menu creation system like #GtkItemFactory. If you
3396 * use #GtkItemFactory, setting up accelerator paths will be done
3399 * Even when you you aren't using #GtkItemFactory, if you only want to
3400 * set up accelerators on menu items gtk_menu_item_set_accel_path()
3401 * provides a somewhat more convenient interface.
3404 gtk_widget_set_accel_path (GtkWidget *widget,
3405 const gchar *accel_path,
3406 GtkAccelGroup *accel_group)
3410 g_return_if_fail (GTK_IS_WIDGET (widget));
3411 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
3415 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
3416 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
3418 gtk_accel_map_add_entry (accel_path, 0, 0);
3419 apath = g_new (AccelPath, 1);
3420 apath->widget = widget;
3421 apath->accel_group = g_object_ref (accel_group);
3422 apath->path_quark = g_quark_from_string (accel_path);
3423 apath->closure = widget_new_accel_closure (apath->widget, GTK_WIDGET_GET_CLASS (apath->widget)->activate_signal);
3428 /* also removes possible old settings */
3429 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
3432 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
3434 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3438 _gtk_widget_get_accel_path (GtkWidget *widget,
3443 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3445 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
3447 *locked = apath ? apath->accel_group->lock_count > 0 : TRUE;
3448 return apath ? g_quark_to_string (apath->path_quark) : NULL;
3452 gtk_widget_mnemonic_activate (GtkWidget *widget,
3453 gboolean group_cycling)
3457 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3459 group_cycling = group_cycling != FALSE;
3460 if (!GTK_WIDGET_IS_SENSITIVE (widget))
3463 g_signal_emit (widget,
3464 widget_signals[MNEMONIC_ACTIVATE],
3472 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
3473 gboolean group_cycling)
3475 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
3476 gtk_widget_activate (widget);
3477 else if (GTK_WIDGET_CAN_FOCUS (widget))
3478 gtk_widget_grab_focus (widget);
3481 g_warning ("widget `%s' isn't suitable for mnemonic activation",
3482 G_OBJECT_TYPE_NAME (widget));
3483 gdk_display_beep (gtk_widget_get_display (widget));
3489 gtk_widget_real_key_press_event (GtkWidget *widget,
3492 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
3496 gtk_widget_real_key_release_event (GtkWidget *widget,
3499 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
3503 gtk_widget_real_focus_in_event (GtkWidget *widget,
3504 GdkEventFocus *event)
3506 gtk_widget_queue_shallow_draw (widget);
3512 gtk_widget_real_focus_out_event (GtkWidget *widget,
3513 GdkEventFocus *event)
3515 gtk_widget_queue_shallow_draw (widget);
3520 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
3521 (event->type == GDK_FOCUS_CHANGE || GTK_WIDGET_REALIZED(widget))
3525 * @widget: a #GtkWidget
3526 * @event: a #GdkEvent
3528 * Rarely-used function. This function is used to emit
3529 * the event signals on a widget (those signals should never
3530 * be emitted without using this function to do so).
3531 * If you want to synthesize an event though, don't use this function;
3532 * instead, use gtk_main_do_event() so the event will behave as if
3533 * it were in the event queue. Don't synthesize expose events; instead,
3534 * use gdk_window_invalidate_rect() to invalidate a region of the
3537 * Return value: return from the event signal emission (%TRUE if the event was handled)
3540 gtk_widget_event (GtkWidget *widget,
3543 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
3544 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
3546 if (event->type == GDK_EXPOSE)
3548 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
3549 "the same effect, call gdk_window_invalidate_rect/region(), "
3550 "followed by gdk_window_process_updates().");
3554 return gtk_widget_event_internal (widget, event);
3559 * gtk_widget_send_expose:
3560 * @widget: a #GtkWidget
3561 * @event: a expose #GdkEvent
3563 * Very rarely-used function. This function is used to emit
3564 * an expose event signals on a widget. This function is not
3565 * normally used directly. The only time it is used is when
3566 * propagating an expose event to a child %NO_WINDOW widget, and
3567 * that is normally done using gtk_container_propagate_expose().
3569 * If you want to force an area of a window to be redrawn,
3570 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
3571 * To cause the redraw to be done immediately, follow that call
3572 * with a call to gdk_window_process_updates().
3574 * Return value: return from the event signal emission (%TRUE if the event was handled)
3577 gtk_widget_send_expose (GtkWidget *widget,
3580 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
3581 g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), TRUE);
3582 g_return_val_if_fail (event != NULL, TRUE);
3583 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
3585 if (event->type != GDK_EXPOSE)
3588 return gtk_widget_event_internal (widget, event);
3592 event_window_is_still_viewable (GdkEvent *event)
3594 /* Some programs, such as gnome-theme-manager, fake widgets
3595 * into exposing onto a pixmap by sending expose events with
3596 * event->window pointing to a pixmap
3598 if (GDK_IS_PIXMAP (event->any.window))
3599 return event->type == GDK_EXPOSE;
3601 /* Check that we think the event's window is viewable before
3602 * delivering the event, to prevent suprises. We do this here
3603 * at the last moment, since the event may have been queued
3604 * up behind other events, held over a recursive main loop, etc.
3606 switch (event->type)
3609 case GDK_MOTION_NOTIFY:
3610 case GDK_BUTTON_PRESS:
3611 case GDK_2BUTTON_PRESS:
3612 case GDK_3BUTTON_PRESS:
3614 case GDK_ENTER_NOTIFY:
3615 case GDK_PROXIMITY_IN:
3617 return event->any.window && gdk_window_is_viewable (event->any.window);
3620 /* The following events are the second half of paired events;
3621 * we always deliver them to deal with widgets that clean up
3622 * on the second half.
3624 case GDK_BUTTON_RELEASE:
3625 case GDK_KEY_RELEASE:
3626 case GDK_LEAVE_NOTIFY:
3627 case GDK_PROXIMITY_OUT:
3631 /* Remaining events would make sense on an not-viewable window,
3632 * or don't have an associated window.
3639 gtk_widget_event_internal (GtkWidget *widget,
3642 gboolean return_val = FALSE;
3644 /* We check only once for is-still-visible; if someone
3645 * hides the window in on of the signals on the widget,
3646 * they are responsible for returning TRUE to terminate
3649 if (!event_window_is_still_viewable (event))
3652 g_object_ref (widget);
3654 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
3655 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
3660 switch (event->type)
3665 case GDK_BUTTON_PRESS:
3666 case GDK_2BUTTON_PRESS:
3667 case GDK_3BUTTON_PRESS:
3668 signal_num = BUTTON_PRESS_EVENT;
3671 signal_num = SCROLL_EVENT;
3673 case GDK_BUTTON_RELEASE:
3674 signal_num = BUTTON_RELEASE_EVENT;
3676 case GDK_MOTION_NOTIFY:
3677 signal_num = MOTION_NOTIFY_EVENT;
3680 signal_num = DELETE_EVENT;
3683 signal_num = DESTROY_EVENT;
3686 signal_num = KEY_PRESS_EVENT;
3688 case GDK_KEY_RELEASE:
3689 signal_num = KEY_RELEASE_EVENT;
3691 case GDK_ENTER_NOTIFY:
3692 signal_num = ENTER_NOTIFY_EVENT;
3694 case GDK_LEAVE_NOTIFY:
3695 signal_num = LEAVE_NOTIFY_EVENT;
3697 case GDK_FOCUS_CHANGE:
3698 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
3701 signal_num = CONFIGURE_EVENT;
3704 signal_num = MAP_EVENT;
3707 signal_num = UNMAP_EVENT;
3709 case GDK_WINDOW_STATE:
3710 signal_num = WINDOW_STATE_EVENT;
3712 case GDK_PROPERTY_NOTIFY:
3713 signal_num = PROPERTY_NOTIFY_EVENT;
3715 case GDK_SELECTION_CLEAR:
3716 signal_num = SELECTION_CLEAR_EVENT;
3718 case GDK_SELECTION_REQUEST:
3719 signal_num = SELECTION_REQUEST_EVENT;
3721 case GDK_SELECTION_NOTIFY:
3722 signal_num = SELECTION_NOTIFY_EVENT;
3724 case GDK_PROXIMITY_IN:
3725 signal_num = PROXIMITY_IN_EVENT;
3727 case GDK_PROXIMITY_OUT:
3728 signal_num = PROXIMITY_OUT_EVENT;
3731 signal_num = NO_EXPOSE_EVENT;
3733 case GDK_CLIENT_EVENT:
3734 signal_num = CLIENT_EVENT;
3737 signal_num = EXPOSE_EVENT;
3739 case GDK_VISIBILITY_NOTIFY:
3740 signal_num = VISIBILITY_NOTIFY_EVENT;
3742 case GDK_GRAB_BROKEN:
3743 signal_num = GRAB_BROKEN;
3746 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
3750 if (signal_num != -1)
3751 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
3753 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
3754 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
3758 g_object_unref (widget);
3764 * gtk_widget_activate:
3765 * @widget: a #GtkWidget that's activatable
3767 * For widgets that can be "activated" (buttons, menu items, etc.)
3768 * this function activates them. Activation is what happens when you
3769 * press Enter on a widget during key navigation. If @widget isn't
3770 * activatable, the function returns %FALSE.
3772 * Return value: %TRUE if the widget was activatable
3775 gtk_widget_activate (GtkWidget *widget)
3777 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3779 if (WIDGET_CLASS (widget)->activate_signal)
3781 /* FIXME: we should eventually check the signals signature here */
3782 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
3791 * gtk_widget_set_scroll_adjustments:
3792 * @widget: a #GtkWidget
3793 * @hadjustment: an adjustment for horizontal scrolling, or %NULL
3794 * @vadjustment: an adjustment for vertical scrolling, or %NULL
3796 * For widgets that support scrolling, sets the scroll adjustments and
3797 * returns %TRUE. For widgets that don't support scrolling, does
3798 * nothing and returns %FALSE. Widgets that don't support scrolling
3799 * can be scrolled by placing them in a #GtkViewport, which does
3800 * support scrolling.
3802 * Return value: %TRUE if the widget supports scrolling
3805 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
3806 GtkAdjustment *hadjustment,
3807 GtkAdjustment *vadjustment)
3809 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3811 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
3813 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
3815 if (WIDGET_CLASS (widget)->set_scroll_adjustments_signal)
3817 /* FIXME: we should eventually check the signals signature here */
3818 g_signal_emit (widget,
3819 WIDGET_CLASS (widget)->set_scroll_adjustments_signal, 0,
3820 hadjustment, vadjustment);
3828 gtk_widget_reparent_subwindows (GtkWidget *widget,
3829 GdkWindow *new_window)
3831 if (GTK_WIDGET_NO_WINDOW (widget))
3833 GList *children = gdk_window_get_children (widget->window);
3836 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
3839 GdkWindow *window = tmp_list->data;
3841 gdk_window_get_user_data (window, (void **)&child);
3842 while (child && child != widget)
3843 child = child->parent;
3846 gdk_window_reparent (window, new_window, 0, 0);
3849 g_list_free (children);
3854 GList *tmp_list, *children;
3856 parent = gdk_window_get_parent (widget->window);
3859 gdk_window_reparent (widget->window, new_window, 0, 0);
3862 children = gdk_window_get_children (parent);
3864 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
3867 GdkWindow *window = tmp_list->data;
3869 gdk_window_get_user_data (window, (void **)&child);
3870 if (child == widget)
3871 gdk_window_reparent (window, new_window, 0, 0);
3874 g_list_free (children);
3880 gtk_widget_reparent_fixup_child (GtkWidget *widget,
3881 gpointer client_data)
3883 g_return_if_fail (client_data != NULL);
3885 if (GTK_WIDGET_NO_WINDOW (widget))
3888 g_object_unref (widget->window);
3889 widget->window = (GdkWindow*) client_data;
3891 g_object_ref (widget->window);
3893 if (GTK_IS_CONTAINER (widget))
3894 gtk_container_forall (GTK_CONTAINER (widget),
3895 gtk_widget_reparent_fixup_child,
3901 * gtk_widget_reparent:
3902 * @widget: a #GtkWidget
3903 * @new_parent: a #GtkContainer to move the widget into
3905 * Moves a widget from one #GtkContainer to another, handling reference
3906 * count issues to avoid destroying the widget.
3910 gtk_widget_reparent (GtkWidget *widget,
3911 GtkWidget *new_parent)
3913 g_return_if_fail (GTK_IS_WIDGET (widget));
3914 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
3915 g_return_if_fail (widget->parent != NULL);
3917 if (widget->parent != new_parent)
3919 /* First try to see if we can get away without unrealizing
3920 * the widget as we reparent it. if so we set a flag so
3921 * that gtk_widget_unparent doesn't unrealize widget
3923 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent))
3924 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
3926 g_object_ref (widget);
3927 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
3928 gtk_container_add (GTK_CONTAINER (new_parent), widget);
3929 g_object_unref (widget);
3931 if (GTK_WIDGET_IN_REPARENT (widget))
3933 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
3935 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
3936 gtk_widget_reparent_fixup_child (widget,
3937 gtk_widget_get_parent_window (widget));
3940 g_object_notify (G_OBJECT (widget), "parent");
3945 * gtk_widget_intersect:
3946 * @widget: a #GtkWidget
3947 * @area: a rectangle
3948 * @intersection: rectangle to store intersection of @widget and @area
3950 * Computes the intersection of a @widget's area and @area, storing
3951 * the intersection in @intersection, and returns %TRUE if there was
3952 * an intersection. @intersection may be %NULL if you're only
3953 * interested in whether there was an intersection.
3955 * Return value: %TRUE if there was an intersection
3958 gtk_widget_intersect (GtkWidget *widget,
3960 GdkRectangle *intersection)
3966 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3967 g_return_val_if_fail (area != NULL, FALSE);
3970 dest = intersection;
3974 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
3976 if (return_val && intersection && !GTK_WIDGET_NO_WINDOW (widget))
3978 intersection->x -= widget->allocation.x;
3979 intersection->y -= widget->allocation.y;
3986 * gtk_widget_region_intersect:
3987 * @widget: a #GtkWidget
3988 * @region: a #GdkRegion, in the same coordinate system as
3989 * @widget->allocation. That is, relative to @widget->window
3990 * for %NO_WINDOW widgets; relative to the parent window
3991 * of @widget->window for widgets with their own window.
3992 * @returns: A newly allocated region holding the intersection of @widget
3993 * and @region. The coordinates of the return value are
3994 * relative to @widget->window for %NO_WINDOW widgets, and
3995 * relative to the parent window of @widget->window for
3996 * widgets with their own window.
3998 * Computes the intersection of a @widget's area and @region, returning
3999 * the intersection. The result may be empty, use gdk_region_empty() to
4003 gtk_widget_region_intersect (GtkWidget *widget,
4009 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4010 g_return_val_if_fail (region != NULL, NULL);
4012 gtk_widget_get_draw_rectangle (widget, &rect);
4014 dest = gdk_region_rectangle (&rect);
4016 gdk_region_intersect (dest, region);
4022 * _gtk_widget_grab_notify:
4023 * @widget: a #GtkWidget
4024 * @was_grabbed: whether a grab is now in effect
4026 * Emits the signal "grab_notify" on @widget.
4031 _gtk_widget_grab_notify (GtkWidget *widget,
4032 gboolean was_grabbed)
4034 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
4038 * gtk_widget_grab_focus:
4039 * @widget: a #GtkWidget
4041 * Causes @widget to have the keyboard focus for the #GtkWindow it's
4042 * inside. @widget must be a focusable widget, such as a #GtkEntry;
4043 * something like #GtkFrame won't work. (More precisely, it must have the
4044 * %GTK_CAN_FOCUS flag set.)
4048 gtk_widget_grab_focus (GtkWidget *widget)
4050 g_return_if_fail (GTK_IS_WIDGET (widget));
4052 if (!GTK_WIDGET_IS_SENSITIVE (widget))
4055 g_object_ref (widget);
4056 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
4057 g_object_notify (G_OBJECT (widget), "has-focus");
4058 g_object_unref (widget);
4062 reset_focus_recurse (GtkWidget *widget,
4065 if (GTK_IS_CONTAINER (widget))
4067 GtkContainer *container;
4069 container = GTK_CONTAINER (widget);
4070 gtk_container_set_focus_child (container, NULL);
4072 gtk_container_foreach (container,
4073 reset_focus_recurse,
4079 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
4081 if (GTK_WIDGET_CAN_FOCUS (focus_widget))
4083 GtkWidget *toplevel;
4086 /* clear the current focus setting, break if the current widget
4087 * is the focus widget's parent, since containers above that will
4088 * be set by the next loop.
4090 toplevel = gtk_widget_get_toplevel (focus_widget);
4091 if (GTK_WIDGET_TOPLEVEL (toplevel))
4093 widget = GTK_WINDOW (toplevel)->focus_widget;
4095 if (widget == focus_widget)
4097 /* We call _gtk_window_internal_set_focus() here so that the
4098 * toplevel window can request the focus if necessary.
4099 * This is needed when the toplevel is a GtkPlug
4101 if (!GTK_WIDGET_HAS_FOCUS (widget))
4102 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
4109 while (widget->parent && widget->parent != focus_widget->parent)
4111 widget = widget->parent;
4112 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
4116 else if (toplevel != focus_widget)
4118 /* gtk_widget_grab_focus() operates on a tree without window...
4119 * actually, this is very questionable behaviour.
4122 gtk_container_foreach (GTK_CONTAINER (toplevel),
4123 reset_focus_recurse,
4127 /* now propagate the new focus up the widget tree and finally
4128 * set it on the window
4130 widget = focus_widget;
4131 while (widget->parent)
4133 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
4134 widget = widget->parent;
4136 if (GTK_IS_WINDOW (widget))
4137 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
4142 gtk_widget_real_show_help (GtkWidget *widget,
4143 GtkWidgetHelpType help_type)
4145 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
4147 _gtk_tooltips_toggle_keyboard_mode (widget);
4155 gtk_widget_real_focus (GtkWidget *widget,
4156 GtkDirectionType direction)
4158 if (!GTK_WIDGET_CAN_FOCUS (widget))
4161 if (!gtk_widget_is_focus (widget))
4163 gtk_widget_grab_focus (widget);
4171 * gtk_widget_is_focus:
4172 * @widget: a #GtkWidget
4174 * Determines if the widget is the focus widget within its
4175 * toplevel. (This does not mean that the %HAS_FOCUS flag is
4176 * necessarily set; %HAS_FOCUS will only be set if the
4177 * toplevel widget additionally has the global input focus.)
4179 * Return value: %TRUE if the widget is the focus widget.
4182 gtk_widget_is_focus (GtkWidget *widget)
4184 GtkWidget *toplevel;
4186 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4188 toplevel = gtk_widget_get_toplevel (widget);
4190 if (GTK_IS_WINDOW (toplevel))
4191 return widget == GTK_WINDOW (toplevel)->focus_widget;
4197 * gtk_widget_grab_default:
4198 * @widget: a #GtkWidget
4200 * Causes @widget to become the default widget. @widget must have the
4201 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
4202 * yourself by calling <literal>GTK_WIDGET_SET_FLAGS (@widget,
4203 * GTK_CAN_DEFAULT)</literal>. The default widget is activated when the user
4204 * presses Enter in a window. Default widgets must be activatable,
4205 * that is, gtk_widget_activate() should affect them.
4209 gtk_widget_grab_default (GtkWidget *widget)
4213 g_return_if_fail (GTK_IS_WIDGET (widget));
4214 g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget));
4216 window = gtk_widget_get_toplevel (widget);
4218 if (window && GTK_WIDGET_TOPLEVEL (window))
4219 gtk_window_set_default (GTK_WINDOW (window), widget);
4221 g_warning (G_STRLOC ": widget not within a GtkWindow");
4225 * gtk_widget_set_name:
4226 * @widget: a #GtkWidget
4227 * @name: name for the widget
4229 * Widgets can be named, which allows you to refer to them from a
4230 * gtkrc file. You can apply a style to widgets with a particular name
4231 * in the gtkrc file. See the documentation for gtkrc files (on the
4232 * same page as the docs for #GtkRcStyle).
4234 * Note that widget names are separated by periods in paths (see
4235 * gtk_widget_path()), so names with embedded periods may cause confusion.
4238 gtk_widget_set_name (GtkWidget *widget,
4243 g_return_if_fail (GTK_IS_WIDGET (widget));
4245 new_name = g_strdup (name);
4246 g_free (widget->name);
4247 widget->name = new_name;
4249 if (GTK_WIDGET_RC_STYLE (widget))
4250 gtk_widget_reset_rc_style (widget);
4252 g_object_notify (G_OBJECT (widget), "name");
4256 * gtk_widget_get_name:
4257 * @widget: a #GtkWidget
4259 * Retrieves the name of a widget. See gtk_widget_set_name() for the
4260 * significance of widget names.
4262 * Return value: name of the widget. This string is owned by GTK+ and
4263 * should not be modified or freed
4265 G_CONST_RETURN gchar*
4266 gtk_widget_get_name (GtkWidget *widget)
4268 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4271 return widget->name;
4272 return g_type_name (GTK_WIDGET_TYPE (widget));
4276 * gtk_widget_set_state:
4277 * @widget: a #GtkWidget
4278 * @state: new state for @widget
4280 * This function is for use in widget implementations. Sets the state
4281 * of a widget (insensitive, prelighted, etc.) Usually you should set
4282 * the state using wrapper functions such as gtk_widget_set_sensitive().
4286 gtk_widget_set_state (GtkWidget *widget,
4289 g_return_if_fail (GTK_IS_WIDGET (widget));
4291 if (state == GTK_WIDGET_STATE (widget))
4294 if (state == GTK_STATE_INSENSITIVE)
4295 gtk_widget_set_sensitive (widget, FALSE);
4301 data.state_restoration = FALSE;
4302 data.use_forall = FALSE;
4304 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
4306 data.parent_sensitive = TRUE;
4308 gtk_widget_propagate_state (widget, &data);
4310 if (GTK_WIDGET_DRAWABLE (widget))
4311 gtk_widget_queue_draw (widget);
4317 * gtk_widget_set_app_paintable:
4318 * @widget: a #GtkWidget
4319 * @app_paintable: %TRUE if the application will paint on the widget
4321 * Sets whether the application intends to draw on the widget in
4322 * an ::expose-event handler.
4324 * This is a hint to the widget and does not affect the behavior of
4325 * the GTK+ core; many widgets ignore this flag entirely. For widgets
4326 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
4327 * the effect is to suppress default themed drawing of the widget's
4328 * background. (Children of the widget will still be drawn.) The application
4329 * is then entirely responsible for drawing the widget background.
4332 gtk_widget_set_app_paintable (GtkWidget *widget,
4333 gboolean app_paintable)
4335 g_return_if_fail (GTK_IS_WIDGET (widget));
4337 app_paintable = (app_paintable != FALSE);
4339 if (GTK_WIDGET_APP_PAINTABLE (widget) != app_paintable)
4342 GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE);
4344 GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE);
4346 if (GTK_WIDGET_DRAWABLE (widget))
4347 gtk_widget_queue_draw (widget);
4349 g_object_notify (G_OBJECT (widget), "app-paintable");
4354 * gtk_widget_set_double_buffered:
4355 * @widget: a #GtkWidget
4356 * @double_buffered: %TRUE to double-buffer a widget
4358 * Widgets are double buffered by default; you can use this function
4359 * to turn off the buffering. "Double buffered" simply means that
4360 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
4361 * automatically around expose events sent to the
4362 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
4363 * window to an offscreen buffer, and gdk_window_end_paint() draws the
4364 * buffer to the screen. The result is that users see the window
4365 * update in one smooth step, and don't see individual graphics
4366 * primitives being rendered.
4368 * In very simple terms, double buffered widgets don't flicker,
4369 * so you would only use this function to turn off double buffering
4370 * if you had special needs and really knew what you were doing.
4372 * Note: if you turn off double-buffering, you have to handle
4373 * expose events, since even the clearing to the background color or
4374 * pixmap will not happen automatically (as it is done in
4375 * gdk_window_begin_paint()).
4379 gtk_widget_set_double_buffered (GtkWidget *widget,
4380 gboolean double_buffered)
4382 g_return_if_fail (GTK_IS_WIDGET (widget));
4384 if (double_buffered)
4385 GTK_WIDGET_SET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
4387 GTK_WIDGET_UNSET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
4391 * gtk_widget_set_redraw_on_allocate:
4392 * @widget: a #GtkWidget
4393 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
4394 * when it is allocated to a new size. Otherwise, only the
4395 * new portion of the widget will be redrawn.
4397 * Sets whether the entire widget is queued for drawing when its size
4398 * allocation changes. By default, this setting is %TRUE and
4399 * the entire widget is redrawn on every size change. If your widget
4400 * leaves the upper left unchanged when made bigger, turning this
4401 * setting on will improve performance.
4403 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
4404 * off all allocation on resizing: the widget will not even redraw if
4405 * its position changes; this is to allow containers that don't draw
4406 * anything to avoid excess invalidations. If you set this flag on a
4407 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
4408 * you are responsible for invalidating both the old and new allocation
4409 * of the widget when the widget is moved and responsible for invalidating
4410 * regions newly when the widget increases size.
4413 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
4414 gboolean redraw_on_allocate)
4416 g_return_if_fail (GTK_IS_WIDGET (widget));
4418 if (redraw_on_allocate)
4419 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
4421 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
4425 * gtk_widget_set_sensitive:
4426 * @widget: a #GtkWidget
4427 * @sensitive: %TRUE to make the widget sensitive
4429 * Sets the sensitivity of a widget. A widget is sensitive if the user
4430 * can interact with it. Insensitive widgets are "grayed out" and the
4431 * user can't interact with them. Insensitive widgets are known as
4432 * "inactive", "disabled", or "ghosted" in some other toolkits.
4436 gtk_widget_set_sensitive (GtkWidget *widget,
4441 g_return_if_fail (GTK_IS_WIDGET (widget));
4443 sensitive = (sensitive != FALSE);
4445 if (sensitive == (GTK_WIDGET_SENSITIVE (widget) != FALSE))
4450 GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE);
4451 data.state = GTK_WIDGET_SAVED_STATE (widget);
4455 GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE);
4456 data.state = GTK_WIDGET_STATE (widget);
4458 data.state_restoration = TRUE;
4459 data.use_forall = TRUE;
4462 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
4464 data.parent_sensitive = TRUE;
4466 gtk_widget_propagate_state (widget, &data);
4467 if (GTK_WIDGET_DRAWABLE (widget))
4468 gtk_widget_queue_draw (widget);
4470 g_object_notify (G_OBJECT (widget), "sensitive");
4474 * gtk_widget_set_parent:
4475 * @widget: a #GtkWidget
4476 * @parent: parent container
4478 * This function is useful only when implementing subclasses of #GtkContainer.
4479 * Sets the container as the parent of @widget, and takes care of
4480 * some details such as updating the state and style of the child
4481 * to reflect its new location. The opposite function is
4482 * gtk_widget_unparent().
4486 gtk_widget_set_parent (GtkWidget *widget,
4491 g_return_if_fail (GTK_IS_WIDGET (widget));
4492 g_return_if_fail (GTK_IS_WIDGET (parent));
4493 g_return_if_fail (widget != parent);
4494 if (widget->parent != NULL)
4496 g_warning ("Can't set a parent on widget which has a parent\n");
4499 if (GTK_WIDGET_TOPLEVEL (widget))
4501 g_warning ("Can't set a parent on a toplevel widget\n");
4505 /* keep this function in sync with gtk_menu_attach_to_widget()
4508 g_object_ref (widget);
4509 gtk_object_sink (GTK_OBJECT (widget));
4510 widget->parent = parent;
4512 if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
4513 data.state = GTK_WIDGET_STATE (parent);
4515 data.state = GTK_WIDGET_STATE (widget);
4516 data.state_restoration = FALSE;
4517 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (parent) != FALSE);
4518 data.use_forall = GTK_WIDGET_IS_SENSITIVE (parent) != GTK_WIDGET_IS_SENSITIVE (widget);
4520 gtk_widget_propagate_state (widget, &data);
4522 gtk_widget_reset_rc_styles (widget);
4524 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
4525 if (GTK_WIDGET_ANCHORED (widget->parent))
4526 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
4527 g_object_notify (G_OBJECT (widget), "parent");
4529 /* Enforce realized/mapped invariants
4531 if (GTK_WIDGET_REALIZED (widget->parent))
4532 gtk_widget_realize (widget);
4534 if (GTK_WIDGET_VISIBLE (widget->parent) &&
4535 GTK_WIDGET_VISIBLE (widget))
4537 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
4538 GTK_WIDGET_MAPPED (widget->parent))
4539 gtk_widget_map (widget);
4541 gtk_widget_queue_resize (widget);
4546 * gtk_widget_get_parent:
4547 * @widget: a #GtkWidget
4549 * Returns the parent container of @widget.
4551 * Return value: the parent container of @widget, or %NULL
4554 gtk_widget_get_parent (GtkWidget *widget)
4556 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4558 return widget->parent;
4561 /*****************************************
4563 * see docs/styles.txt
4564 *****************************************/
4567 * gtk_widget_set_style:
4568 * @widget: a #GtkWidget
4569 * @style: a #GtkStyle, or %NULL to remove the effect of a previous
4570 * gtk_widget_set_style() and go back to the default style
4572 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
4573 * want to use this function; it interacts badly with themes, because
4574 * themes work by replacing the #GtkStyle. Instead, use
4575 * gtk_widget_modify_style().
4579 gtk_widget_set_style (GtkWidget *widget,
4582 g_return_if_fail (GTK_IS_WIDGET (widget));
4586 gboolean initial_emission;
4588 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
4590 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
4591 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
4593 gtk_widget_set_style_internal (widget, style, initial_emission);
4597 if (GTK_WIDGET_USER_STYLE (widget))
4598 gtk_widget_reset_rc_style (widget);
4603 * gtk_widget_ensure_style:
4604 * @widget: a #GtkWidget
4606 * Ensures that @widget has a style (@widget->style). Not a very useful
4607 * function; most of the time, if you want the style, the widget is
4608 * realized, and realized widgets are guaranteed to have a style
4613 gtk_widget_ensure_style (GtkWidget *widget)
4615 g_return_if_fail (GTK_IS_WIDGET (widget));
4617 if (!GTK_WIDGET_USER_STYLE (widget) &&
4618 !GTK_WIDGET_RC_STYLE (widget))
4619 gtk_widget_reset_rc_style (widget);
4622 /* Look up the RC style for this widget, unsetting any user style that
4623 * may be in effect currently
4626 gtk_widget_reset_rc_style (GtkWidget *widget)
4628 GtkStyle *new_style = NULL;
4629 gboolean initial_emission;
4631 g_return_if_fail (GTK_IS_WIDGET (widget));
4633 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
4635 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
4636 GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
4638 if (gtk_widget_has_screen (widget))
4639 new_style = gtk_rc_get_style (widget);
4641 new_style = gtk_widget_get_default_style ();
4643 if (initial_emission || new_style != widget->style)
4644 gtk_widget_set_style_internal (widget, new_style, initial_emission);
4648 * gtk_widget_get_style:
4649 * @widget: a #GtkWidget
4651 * Simply an accessor function that returns @widget->style.
4653 * Return value: the widget's #GtkStyle
4656 gtk_widget_get_style (GtkWidget *widget)
4658 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4660 return widget->style;
4664 * gtk_widget_modify_style:
4665 * @widget: a #GtkWidget
4666 * @style: the #GtkRcStyle holding the style modifications
4668 * Modifies style values on the widget. Modifications made using this
4669 * technique take precedence over style values set via an RC file,
4670 * however, they will be overriden if a style is explicitely set on
4671 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
4672 * is designed so each field can either be set or unset, so it is
4673 * possible, using this function, to modify some style values and
4674 * leave the others unchanged.
4676 * Note that modifications made with this function are not cumulative
4677 * with previous calls to gtk_widget_modify_style() or with such
4678 * functions as gtk_widget_modify_fg(). If you wish to retain
4679 * previous values, you must first call gtk_widget_get_modifier_style(),
4680 * make your modifications to the returned style, then call
4681 * gtk_widget_modify_style() with that style. On the other hand,
4682 * if you first call gtk_widget_modify_style(), subsequent calls
4683 * to such functions gtk_widget_modify_fg() will have a cumulative
4684 * effect with the initial modifications.
4687 gtk_widget_modify_style (GtkWidget *widget,
4690 GtkRcStyle *old_style;
4692 g_return_if_fail (GTK_IS_WIDGET (widget));
4693 g_return_if_fail (GTK_IS_RC_STYLE (style));
4695 old_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
4697 g_object_set_qdata_full (G_OBJECT (widget),
4699 gtk_rc_style_copy (style),
4700 (GDestroyNotify) gtk_rc_style_unref);
4702 /* note that "style" may be invalid here if it was the old
4703 * modifier style and the only reference was our own.
4706 if (GTK_WIDGET_RC_STYLE (widget))
4707 gtk_widget_reset_rc_style (widget);
4711 * gtk_widget_get_modifier_style:
4712 * @widget: a #GtkWidget
4714 * Returns the current modifier style for the widget. (As set by
4715 * gtk_widget_modify_style().) If no style has previously set, a new
4716 * #GtkRcStyle will be created with all values unset, and set as the
4717 * modifier style for the widget. If you make changes to this rc
4718 * style, you must call gtk_widget_modify_style(), passing in the
4719 * returned rc style, to make sure that your changes take effect.
4721 * Caution: passing the style back to gtk_widget_modify_style() will
4722 * normally end up destroying it, because gtk_widget_modify_style() copies
4723 * the passed-in style and sets the copy as the new modifier style,
4724 * thus dropping any reference to the old modifier style. Add a reference
4725 * to the modifier style if you want to keep it alive.
4727 * Return value: the modifier style for the widget. This rc style is
4728 * owned by the widget. If you want to keep a pointer to value this
4729 * around, you must add a refcount using gtk_rc_style_ref().
4732 gtk_widget_get_modifier_style (GtkWidget *widget)
4734 GtkRcStyle *rc_style;
4736 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4738 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
4742 rc_style = gtk_rc_style_new ();
4743 g_object_set_qdata_full (G_OBJECT (widget),
4746 (GDestroyNotify) gtk_rc_style_unref);
4753 gtk_widget_modify_color_component (GtkWidget *widget,
4754 GtkRcFlags component,
4756 const GdkColor *color)
4758 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
4765 rc_style->fg[state] = *color;
4768 rc_style->bg[state] = *color;
4771 rc_style->text[state] = *color;
4774 rc_style->base[state] = *color;
4777 g_assert_not_reached();
4780 rc_style->color_flags[state] |= component;
4783 rc_style->color_flags[state] &= ~component;
4785 gtk_widget_modify_style (widget, rc_style);
4789 * gtk_widget_modify_fg:
4790 * @widget: a #GtkWidget.
4791 * @state: the state for which to set the foreground color.
4792 * @color: the color to assign (does not need to be allocated),
4793 * or %NULL to undo the effect of previous calls to
4794 * of gtk_widget_modify_fg().
4796 * Sets the foreground color for a widget in a particular state. All
4797 * other style values are left untouched. See also
4798 * gtk_widget_modify_style().
4801 gtk_widget_modify_fg (GtkWidget *widget,
4803 const GdkColor *color)
4805 g_return_if_fail (GTK_IS_WIDGET (widget));
4806 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4808 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
4812 * gtk_widget_modify_bg:
4813 * @widget: a #GtkWidget.
4814 * @state: the state for which to set the background color.
4815 * @color: the color to assign (does not need to be allocated),
4816 * or %NULL to undo the effect of previous calls to
4817 * of gtk_widget_modify_bg().
4819 * Sets the background color for a widget in a particular state. All
4820 * other style values are left untouched. See also
4821 * gtk_widget_modify_style().
4823 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
4824 * draw on their parent container's window and thus may not draw any background
4825 * themselves. This is the case for e.g. #GtkLabel. To modify the background
4826 * of such widgets, you have to set the background color on their parent; if you want
4827 * to set the background of a rectangular area around a label, try placing the
4828 * label in a #GtkEventBox widget and setting the background color on that.
4831 gtk_widget_modify_bg (GtkWidget *widget,
4833 const GdkColor *color)
4835 g_return_if_fail (GTK_IS_WIDGET (widget));
4836 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4838 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
4842 * gtk_widget_modify_text:
4843 * @widget: a #GtkWidget.
4844 * @state: the state for which to set the text color.
4845 * @color: the color to assign (does not need to be allocated),
4846 * or %NULL to undo the effect of previous calls to
4847 * of gtk_widget_modify_text().
4849 * Sets the text color for a widget in a particular state. All other
4850 * style values are left untouched. The text color is the foreground
4851 * color used along with the base color (see gtk_widget_modify_base())
4852 * for widgets such as #GtkEntry and #GtkTextView. See also
4853 * gtk_widget_modify_style().
4856 gtk_widget_modify_text (GtkWidget *widget,
4858 const GdkColor *color)
4860 g_return_if_fail (GTK_IS_WIDGET (widget));
4861 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4863 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
4867 * gtk_widget_modify_base:
4868 * @widget: a #GtkWidget.
4869 * @state: the state for which to set the base color.
4870 * @color: the color to assign (does not need to be allocated),
4871 * or %NULL to undo the effect of previous calls to
4872 * of gtk_widget_modify_base().
4874 * Sets the base color for a widget in a particular state.
4875 * All other style values are left untouched. The base color
4876 * is the background color used along with the text color
4877 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
4878 * and #GtkTextView. See also gtk_widget_modify_style().
4880 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
4881 * draw on their parent container's window and thus may not draw any background
4882 * themselves. This is the case for e.g. #GtkLabel. To modify the background
4883 * of such widgets, you have to set the base color on their parent; if you want
4884 * to set the background of a rectangular area around a label, try placing the
4885 * label in a #GtkEventBox widget and setting the base color on that.
4888 gtk_widget_modify_base (GtkWidget *widget,
4890 const GdkColor *color)
4892 g_return_if_fail (GTK_IS_WIDGET (widget));
4893 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4895 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
4899 * gtk_widget_modify_font:
4900 * @widget: a #GtkWidget
4901 * @font_desc: the font description to use, or %NULL to undo
4902 * the effect of previous calls to gtk_widget_modify_font().
4904 * Sets the font to use for a widget. All other style values are left
4905 * untouched. See also gtk_widget_modify_style().
4908 gtk_widget_modify_font (GtkWidget *widget,
4909 PangoFontDescription *font_desc)
4911 GtkRcStyle *rc_style;
4913 g_return_if_fail (GTK_IS_WIDGET (widget));
4915 rc_style = gtk_widget_get_modifier_style (widget);
4917 if (rc_style->font_desc)
4918 pango_font_description_free (rc_style->font_desc);
4921 rc_style->font_desc = pango_font_description_copy (font_desc);
4923 rc_style->font_desc = NULL;
4925 gtk_widget_modify_style (widget, rc_style);
4929 gtk_widget_direction_changed (GtkWidget *widget,
4930 GtkTextDirection previous_direction)
4932 gtk_widget_queue_resize (widget);
4936 gtk_widget_style_set (GtkWidget *widget,
4937 GtkStyle *previous_style)
4939 if (GTK_WIDGET_REALIZED (widget) &&
4940 !GTK_WIDGET_NO_WINDOW (widget))
4941 gtk_style_set_background (widget->style, widget->window, widget->state);
4945 gtk_widget_set_style_internal (GtkWidget *widget,
4947 gboolean initial_emission)
4949 g_object_ref (widget);
4950 g_object_freeze_notify (G_OBJECT (widget));
4952 if (widget->style != style || initial_emission)
4954 PangoContext *context = gtk_widget_peek_pango_context (widget);
4956 pango_context_set_font_description (context, style->font_desc);
4959 if (widget->style != style)
4961 GtkStyle *previous_style;
4963 if (GTK_WIDGET_REALIZED (widget))
4965 gtk_widget_reset_shapes (widget);
4966 gtk_style_detach (widget->style);
4969 previous_style = widget->style;
4970 widget->style = style;
4971 g_object_ref (widget->style);
4973 if (GTK_WIDGET_REALIZED (widget))
4974 widget->style = gtk_style_attach (widget->style, widget->window);
4976 g_signal_emit (widget,
4977 widget_signals[STYLE_SET],
4979 initial_emission ? NULL : previous_style);
4980 g_object_unref (previous_style);
4982 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
4983 gtk_widget_queue_resize (widget);
4985 else if (initial_emission)
4986 g_signal_emit (widget,
4987 widget_signals[STYLE_SET],
4990 g_object_notify (G_OBJECT (widget), "style");
4991 g_object_thaw_notify (G_OBJECT (widget));
4992 g_object_unref (widget);
4996 GtkWidget *previous_toplevel;
4997 GdkScreen *previous_screen;
4998 GdkScreen *new_screen;
4999 } HierarchyChangedInfo;
5002 do_screen_change (GtkWidget *widget,
5003 GdkScreen *old_screen,
5004 GdkScreen *new_screen)
5006 if (old_screen != new_screen)
5010 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
5012 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
5015 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
5020 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
5021 gpointer client_data)
5023 gboolean new_anchored;
5024 HierarchyChangedInfo *info = client_data;
5026 new_anchored = GTK_WIDGET_TOPLEVEL (widget) ||
5027 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
5029 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
5031 g_object_ref (widget);
5034 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
5036 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
5038 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
5039 do_screen_change (widget, info->previous_screen, info->new_screen);
5041 if (GTK_IS_CONTAINER (widget))
5042 gtk_container_forall (GTK_CONTAINER (widget),
5043 gtk_widget_propagate_hierarchy_changed_recurse,
5046 g_object_unref (widget);
5051 * _gtk_widget_propagate_hierarchy_changed:
5052 * @widget: a #GtkWidget
5053 * @previous_toplevel: Previous toplevel
5055 * Propagates changes in the anchored state to a widget and all
5056 * children, unsetting or setting the %ANCHORED flag, and
5057 * emitting ::hierarchy_changed.
5060 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
5061 GtkWidget *previous_toplevel)
5063 HierarchyChangedInfo info;
5065 info.previous_toplevel = previous_toplevel;
5066 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
5068 if (GTK_WIDGET_TOPLEVEL (widget) ||
5069 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
5070 info.new_screen = gtk_widget_get_screen (widget);
5072 info.new_screen = NULL;
5074 if (info.previous_screen)
5075 g_object_ref (info.previous_screen);
5076 if (previous_toplevel)
5077 g_object_ref (previous_toplevel);
5079 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
5081 if (previous_toplevel)
5082 g_object_unref (previous_toplevel);
5083 if (info.previous_screen)
5084 g_object_unref (info.previous_screen);
5088 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
5089 gpointer client_data)
5091 HierarchyChangedInfo *info = client_data;
5093 g_object_ref (widget);
5095 do_screen_change (widget, info->previous_screen, info->new_screen);
5097 if (GTK_IS_CONTAINER (widget))
5098 gtk_container_forall (GTK_CONTAINER (widget),
5099 gtk_widget_propagate_screen_changed_recurse,
5102 g_object_unref (widget);
5106 * _gtk_widget_propagate_screen_changed:
5107 * @widget: a #GtkWidget
5108 * @previous_screen: Previous screen
5110 * Propagates changes in the screen for a widget to all
5111 * children, emitting ::screen_changed.
5114 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
5115 GdkScreen *previous_screen)
5117 HierarchyChangedInfo info;
5119 info.previous_screen = previous_screen;
5120 info.new_screen = gtk_widget_get_screen (widget);
5122 if (previous_screen)
5123 g_object_ref (previous_screen);
5125 gtk_widget_propagate_screen_changed_recurse (widget, &info);
5127 if (previous_screen)
5128 g_object_unref (previous_screen);
5132 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
5134 if (GTK_WIDGET_RC_STYLE (widget))
5135 gtk_widget_reset_rc_style (widget);
5137 if (GTK_IS_CONTAINER (widget))
5138 gtk_container_forall (GTK_CONTAINER (widget),
5139 reset_rc_styles_recurse,
5144 gtk_widget_reset_rc_styles (GtkWidget *widget)
5146 g_return_if_fail (GTK_IS_WIDGET (widget));
5148 reset_rc_styles_recurse (widget, NULL);
5152 * gtk_widget_get_default_style:
5154 * Returns the default style used by all widgets initially.
5156 * Returns: the default style. This #GtkStyle object is owned by GTK+ and
5157 * should not be modified or freed.
5160 gtk_widget_get_default_style (void)
5162 if (!gtk_default_style)
5164 gtk_default_style = gtk_style_new ();
5165 g_object_ref (gtk_default_style);
5168 return gtk_default_style;
5171 static PangoContext *
5172 gtk_widget_peek_pango_context (GtkWidget *widget)
5174 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
5178 * gtk_widget_get_pango_context:
5179 * @widget: a #GtkWidget
5181 * Gets a #PangoContext with the appropriate colormap, font description
5182 * and base direction for this widget. Unlike the context returned
5183 * by gtk_widget_create_pango_context(), this context is owned by
5184 * the widget (it can be used until the screen for the widget changes
5185 * or the widget is removed from its toplevel), and will be updated to
5186 * match any changes to the widget's attributes.
5188 * If you create and keep a #PangoLayout using this context, you must
5189 * deal with changes to the context by calling pango_layout_context_changed()
5190 * on the layout in response to the ::style-set and ::direction-changed signals
5193 * Return value: the #PangoContext for the widget.
5196 gtk_widget_get_pango_context (GtkWidget *widget)
5198 PangoContext *context;
5200 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5202 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
5205 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
5206 g_object_set_qdata_full (G_OBJECT (widget),
5207 quark_pango_context,
5216 * gtk_widget_create_pango_context:
5217 * @widget: a #GtkWidget
5219 * Creates a new #PangoContext with the appropriate colormap,
5220 * font description, and base direction for drawing text for
5221 * this widget. See also gtk_widget_get_pango_context().
5223 * Return value: the new #PangoContext
5226 gtk_widget_create_pango_context (GtkWidget *widget)
5229 PangoContext *context;
5231 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5233 screen = gtk_widget_get_screen_unchecked (widget);
5236 GTK_NOTE (MULTIHEAD,
5237 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
5239 screen = gdk_screen_get_default ();
5242 context = gdk_pango_context_get_for_screen (screen);
5244 pango_context_set_base_dir (context,
5245 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
5246 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
5247 pango_context_set_font_description (context, widget->style->font_desc);
5248 pango_context_set_language (context, gtk_get_default_language ());
5254 * gtk_widget_create_pango_layout:
5255 * @widget: a #GtkWidget
5256 * @text: text to set on the layout (can be %NULL)
5258 * Creates a new #PangoLayout with the appropriate colormap,
5259 * font description, and base direction for drawing text for
5262 * If you keep a #PangoLayout created in this way around, in order
5263 * notify the layout of changes to the base direction or font of this
5264 * widget, you must call pango_layout_context_changed() in response to
5265 * the ::style-set and ::direction-changed signals for the widget.
5267 * Return value: the new #PangoLayout
5270 gtk_widget_create_pango_layout (GtkWidget *widget,
5273 PangoLayout *layout;
5274 PangoContext *context;
5276 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5278 context = gtk_widget_get_pango_context (widget);
5279 layout = pango_layout_new (context);
5282 pango_layout_set_text (layout, text, -1);
5288 * gtk_widget_render_icon:
5289 * @widget: a #GtkWidget
5290 * @stock_id: a stock ID
5291 * @size: a stock size. A size of (GtkIconSize)-1 means render at
5292 * the size of the source and don't scale (if there are multiple
5293 * source sizes, GTK+ picks one of the available sizes).
5294 * @detail: render detail to pass to theme engine
5296 * A convenience function that uses the theme engine and RC file
5297 * settings for @widget to look up @stock_id and render it to
5298 * a pixbuf. @stock_id should be a stock icon ID such as
5299 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
5300 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
5301 * identifies the widget or code doing the rendering, so that
5302 * theme engines can special-case rendering for that widget or code.
5304 * The pixels in the returned #GdkPixbuf are shared with the rest of
5305 * the application and should not be modified. The pixbuf should be freed
5306 * after use with g_object_unref().
5308 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
5311 gtk_widget_render_icon (GtkWidget *widget,
5312 const gchar *stock_id,
5314 const gchar *detail)
5316 GtkIconSet *icon_set;
5319 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5320 g_return_val_if_fail (stock_id != NULL, NULL);
5321 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
5323 gtk_widget_ensure_style (widget);
5325 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
5327 if (icon_set == NULL)
5330 retval = gtk_icon_set_render_icon (icon_set,
5332 gtk_widget_get_direction (widget),
5333 GTK_WIDGET_STATE (widget),
5342 * gtk_widget_set_parent_window:
5343 * @widget: a #GtkWidget.
5344 * @parent_window: the new parent window.
5346 * Sets a non default parent window for @widget.
5349 gtk_widget_set_parent_window (GtkWidget *widget,
5350 GdkWindow *parent_window)
5352 GdkWindow *old_parent_window;
5354 g_return_if_fail (GTK_IS_WIDGET (widget));
5356 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
5357 quark_parent_window);
5359 if (parent_window != old_parent_window)
5361 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
5363 if (old_parent_window)
5364 g_object_unref (old_parent_window);
5366 g_object_ref (parent_window);
5372 * gtk_widget_set_child_visible:
5373 * @widget: a #GtkWidget
5374 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
5376 * Sets whether @widget should be mapped along with its when its parent
5377 * is mapped and @widget has been shown with gtk_widget_show().
5379 * The child visibility can be set for widget before it is added to
5380 * a container with gtk_widget_set_parent(), to avoid mapping
5381 * children unnecessary before immediately unmapping them. However
5382 * it will be reset to its default state of %TRUE when the widget
5383 * is removed from a container.
5385 * Note that changing the child visibility of a widget does not
5386 * queue a resize on the widget. Most of the time, the size of
5387 * a widget is computed from all visible children, whether or
5388 * not they are mapped. If this is not the case, the container
5389 * can queue a resize itself.
5391 * This function is only useful for container implementations and
5392 * never should be called by an application.
5395 gtk_widget_set_child_visible (GtkWidget *widget,
5396 gboolean is_visible)
5398 g_return_if_fail (GTK_IS_WIDGET (widget));
5399 g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
5401 g_object_ref (widget);
5404 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
5407 GtkWidget *toplevel;
5409 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
5411 toplevel = gtk_widget_get_toplevel (widget);
5412 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
5413 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
5416 if (widget->parent && GTK_WIDGET_REALIZED (widget->parent))
5418 if (GTK_WIDGET_MAPPED (widget->parent) &&
5419 GTK_WIDGET_CHILD_VISIBLE (widget) &&
5420 GTK_WIDGET_VISIBLE (widget))
5421 gtk_widget_map (widget);
5423 gtk_widget_unmap (widget);
5426 g_object_unref (widget);
5430 * gtk_widget_get_child_visible:
5431 * @widget: a #GtkWidget
5433 * Gets the value set with gtk_widget_set_child_visible().
5434 * If you feel a need to use this function, your code probably
5435 * needs reorganization.
5437 * This function is only useful for container implementations and
5438 * never should be called by an application.
5440 * Return value: %TRUE if the widget is mapped with the parent.
5443 gtk_widget_get_child_visible (GtkWidget *widget)
5445 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5447 return GTK_WIDGET_CHILD_VISIBLE (widget);
5451 gtk_widget_get_screen_unchecked (GtkWidget *widget)
5453 GtkWidget *toplevel;
5455 toplevel = gtk_widget_get_toplevel (widget);
5457 if (GTK_WIDGET_TOPLEVEL (toplevel))
5459 if (GTK_IS_WINDOW (toplevel))
5460 return GTK_WINDOW (toplevel)->screen;
5461 else if (GTK_IS_INVISIBLE (toplevel))
5462 return GTK_INVISIBLE (widget)->screen;
5469 * gtk_widget_get_screen:
5470 * @widget: a #GtkWidget
5472 * Get the #GdkScreen from the toplevel window associated with
5473 * this widget. This function can only be called after the widget
5474 * has been added to a widget hierarchy with a #GtkWindow
5477 * In general, you should only create screen specific
5478 * resources when a widget has been realized, and you should
5479 * free those resources when the widget is unrealized.
5481 * Return value: the #GdkScreen for the toplevel for this widget.
5486 gtk_widget_get_screen (GtkWidget *widget)
5490 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5492 screen = gtk_widget_get_screen_unchecked (widget);
5499 g_warning (G_STRLOC ": Can't get associated screen"
5500 " for a widget unless it is inside a toplevel GtkWindow\n"
5501 " widget type is %s associated top level type is %s",
5502 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
5503 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
5505 return gdk_screen_get_default ();
5510 * gtk_widget_has_screen:
5511 * @widget: a #GtkWidget
5513 * Checks whether there is a #GdkScreen is associated with
5514 * this widget. All toplevel widgets have an associated
5515 * screen, and all widgets added into a heirarchy with a toplevel
5516 * window at the top.
5518 * Return value: %TRUE if there is a #GdkScreen associcated
5524 gtk_widget_has_screen (GtkWidget *widget)
5526 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5528 return (gtk_widget_get_screen_unchecked (widget) != NULL);
5532 * gtk_widget_get_display:
5533 * @widget: a #GtkWidget
5535 * Get the #GdkDisplay for the toplevel window associated with
5536 * this widget. This function can only be called after the widget
5537 * has been added to a widget hierarchy with a #GtkWindow at the top.
5539 * In general, you should only create display specific
5540 * resources when a widget has been realized, and you should
5541 * free those resources when the widget is unrealized.
5543 * Return value: the #GdkDisplay for the toplevel for this widget.
5548 gtk_widget_get_display (GtkWidget *widget)
5550 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5552 return gdk_screen_get_display (gtk_widget_get_screen (widget));
5556 * gtk_widget_get_root_window:
5557 * @widget: a #GtkWidget
5559 * Get the root window where this widget is located. This function can
5560 * only be called after the widget has been added to a widget
5561 * heirarchy with #GtkWindow at the top.
5563 * The root window is useful for such purposes as creating a popup
5564 * #GdkWindow associated with the window. In general, you should only
5565 * create display specific resources when a widget has been realized,
5566 * and you should free those resources when the widget is unrealized.
5568 * Return value: the #GdkWindow root window for the toplevel for this widget.
5573 gtk_widget_get_root_window (GtkWidget *widget)
5575 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5577 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
5581 * gtk_widget_get_parent_window:
5582 * @widget: a #GtkWidget.
5583 * @returns: the parent window of @widget.
5585 * Gets @widget's parent window.
5588 gtk_widget_get_parent_window (GtkWidget *widget)
5590 GdkWindow *parent_window;
5592 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5593 g_return_val_if_fail (widget->parent != NULL, NULL);
5595 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
5597 return (parent_window != NULL) ? parent_window : widget->parent->window;
5601 * gtk_widget_child_focus:
5602 * @widget: a #GtkWidget
5603 * @direction: direction of focus movement
5605 * This function is used by custom widget implementations; if you're
5606 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
5607 * to a particular widget, and gtk_container_set_focus_chain() to
5608 * change the focus tab order. So you may want to investigate those
5609 * functions instead.
5611 * gtk_widget_child_focus() is called by containers as the user moves
5612 * around the window using keyboard shortcuts. @direction indicates
5613 * what kind of motion is taking place (up, down, left, right, tab
5614 * forward, tab backward). gtk_widget_child_focus() invokes the
5615 * "focus" signal on #GtkWidget; widgets override the default handler
5616 * for this signal in order to implement appropriate focus behavior.
5618 * The "focus" default handler for a widget should return %TRUE if
5619 * moving in @direction left the focus on a focusable location inside
5620 * that widget, and %FALSE if moving in @direction moved the focus
5621 * outside the widget. If returning %TRUE, widgets normally
5622 * call gtk_widget_grab_focus() to place the focus accordingly;
5623 * if returning %FALSE, they don't modify the current focus location.
5625 * This function replaces gtk_container_focus() from GTK+ 1.2. It was
5626 * necessary to check that the child was visible, sensitive, and
5627 * focusable before calling
5628 * gtk_container_focus(). gtk_widget_child_focus() returns %FALSE if
5629 * the widget is not currently in a focusable state, so there's no
5630 * need for those checks.
5632 * Return value: %TRUE if focus ended up inside @widget
5635 gtk_widget_child_focus (GtkWidget *widget,
5636 GtkDirectionType direction)
5638 gboolean return_val;
5640 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5642 if (!GTK_WIDGET_VISIBLE (widget) ||
5643 !GTK_WIDGET_IS_SENSITIVE (widget))
5646 /* child widgets must set CAN_FOCUS, containers
5647 * don't have to though.
5649 if (!GTK_IS_CONTAINER (widget) &&
5650 !GTK_WIDGET_CAN_FOCUS (widget))
5653 g_signal_emit (widget,
5654 widget_signals[FOCUS],
5656 direction, &return_val);
5662 * gtk_widget_set_uposition:
5663 * @widget: a #GtkWidget
5664 * @x: x position; -1 to unset x; -2 to leave x unchanged
5665 * @y: y position; -1 to unset y; -2 to leave y unchanged
5668 * Sets the position of a widget. The funny "u" in the name comes from
5669 * the "user position" hint specified by the X Window System, and
5670 * exists for legacy reasons. This function doesn't work if a widget
5671 * is inside a container; it's only really useful on #GtkWindow.
5673 * Don't use this function to center dialogs over the main application
5674 * window; most window managers will do the centering on your behalf
5675 * if you call gtk_window_set_transient_for(), and it's really not
5676 * possible to get the centering to work correctly in all cases from
5677 * application code. But if you insist, use gtk_window_set_position()
5678 * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
5681 * Note that although @x and @y can be individually unset, the position
5682 * is not honoured unless both @x and @y are set.
5685 gtk_widget_set_uposition (GtkWidget *widget,
5689 /* FIXME this function is the only place that aux_info->x and
5690 * aux_info->y are even used I believe, and this function is
5691 * deprecated. Should be cleaned up.
5693 * (Actually, size_allocate uses them) -Yosh
5696 GtkWidgetAuxInfo *aux_info;
5698 g_return_if_fail (GTK_IS_WIDGET (widget));
5700 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
5705 aux_info->x_set = FALSE;
5708 aux_info->x_set = TRUE;
5716 aux_info->y_set = FALSE;
5719 aux_info->y_set = TRUE;
5724 if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
5725 _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
5727 if (GTK_WIDGET_VISIBLE (widget) && widget->parent)
5728 gtk_widget_size_allocate (widget, &widget->allocation);
5732 gtk_widget_set_usize_internal (GtkWidget *widget,
5736 GtkWidgetAuxInfo *aux_info;
5737 gboolean changed = FALSE;
5739 g_return_if_fail (GTK_IS_WIDGET (widget));
5741 g_object_freeze_notify (G_OBJECT (widget));
5743 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
5745 if (width > -2 && aux_info->width != width)
5747 g_object_notify (G_OBJECT (widget), "width-request");
5748 aux_info->width = width;
5751 if (height > -2 && aux_info->height != height)
5753 g_object_notify (G_OBJECT (widget), "height-request");
5754 aux_info->height = height;
5758 if (GTK_WIDGET_VISIBLE (widget) && changed)
5759 gtk_widget_queue_resize (widget);
5761 g_object_thaw_notify (G_OBJECT (widget));
5765 * gtk_widget_set_usize:
5766 * @widget: a #GtkWidget
5767 * @width: minimum width, or -1 to unset
5768 * @height: minimum height, or -1 to unset
5770 * Sets the minimum size of a widget; that is, the widget's size
5771 * request will be @width by @height. You can use this function to
5772 * force a widget to be either larger or smaller than it is. The
5773 * strange "usize" name dates from the early days of GTK+, and derives
5774 * from X Window System terminology. In many cases,
5775 * gtk_window_set_default_size() is a better choice for toplevel
5776 * windows than this function; setting the default size will still
5777 * allow users to shrink the window. Setting the usize will force them
5778 * to leave the window at least as large as the usize. When dealing
5779 * with window sizes, gtk_window_set_geometry_hints() can be a useful
5782 * Note the inherent danger of setting any fixed size - themes,
5783 * translations into other languages, different fonts, and user action
5784 * can all change the appropriate size for a given widget. So, it's
5785 * basically impossible to hardcode a size that will always be
5788 * @Deprecated: Use gtk_widget_set_size_request() instead.
5791 gtk_widget_set_usize (GtkWidget *widget,
5795 g_return_if_fail (GTK_IS_WIDGET (widget));
5797 gtk_widget_set_usize_internal (widget, width, height);
5801 * gtk_widget_set_size_request:
5802 * @widget: a #GtkWidget
5803 * @width: width @widget should request, or -1 to unset
5804 * @height: height @widget should request, or -1 to unset
5806 * Sets the minimum size of a widget; that is, the widget's size
5807 * request will be @width by @height. You can use this function to
5808 * force a widget to be either larger or smaller than it normally
5811 * In most cases, gtk_window_set_default_size() is a better choice for
5812 * toplevel windows than this function; setting the default size will
5813 * still allow users to shrink the window. Setting the size request
5814 * will force them to leave the window at least as large as the size
5815 * request. When dealing with window sizes,
5816 * gtk_window_set_geometry_hints() can be a useful function as well.
5818 * Note the inherent danger of setting any fixed size - themes,
5819 * translations into other languages, different fonts, and user action
5820 * can all change the appropriate size for a given widget. So, it's
5821 * basically impossible to hardcode a size that will always be
5824 * The size request of a widget is the smallest size a widget can
5825 * accept while still functioning well and drawing itself correctly.
5826 * However in some strange cases a widget may be allocated less than
5827 * its requested size, and in many cases a widget may be allocated more
5828 * space than it requested.
5830 * If the size request in a given direction is -1 (unset), then
5831 * the "natural" size request of the widget will be used instead.
5833 * Widgets can't actually be allocated a size less than 1 by 1, but
5834 * you can pass 0,0 to this function to mean "as small as possible."
5837 gtk_widget_set_size_request (GtkWidget *widget,
5841 g_return_if_fail (GTK_IS_WIDGET (widget));
5842 g_return_if_fail (width >= -1);
5843 g_return_if_fail (height >= -1);
5850 gtk_widget_set_usize_internal (widget, width, height);
5855 * gtk_widget_get_size_request:
5856 * @widget: a #GtkWidget
5857 * @width: return location for width, or %NULL
5858 * @height: return location for height, or %NULL
5860 * Gets the size request that was explicitly set for the widget using
5861 * gtk_widget_set_size_request(). A value of -1 stored in @width or
5862 * @height indicates that that dimension has not been set explicitly
5863 * and the natural requisition of the widget will be used intead. See
5864 * gtk_widget_set_size_request(). To get the size a widget will
5865 * actually use, call gtk_widget_size_request() instead of
5871 gtk_widget_get_size_request (GtkWidget *widget,
5875 GtkWidgetAuxInfo *aux_info;
5877 g_return_if_fail (GTK_IS_WIDGET (widget));
5879 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
5882 *width = aux_info ? aux_info->width : -1;
5885 *height = aux_info ? aux_info->height : -1;
5889 * gtk_widget_set_events:
5890 * @widget: a #GtkWidget
5891 * @events: event mask
5893 * Sets the event mask (see #GdkEventMask) for a widget. The event
5894 * mask determines which events a widget will receive. Keep in mind
5895 * that different widgets have different default event masks, and by
5896 * changing the event mask you may disrupt a widget's functionality,
5897 * so be careful. This function must be called while a widget is
5898 * unrealized. Consider gtk_widget_add_events() for widgets that are
5899 * already realized, or if you want to preserve the existing event
5900 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
5901 * to get events on those widgets, place them inside a #GtkEventBox
5902 * and receive events on the event box.
5906 gtk_widget_set_events (GtkWidget *widget,
5911 g_return_if_fail (GTK_IS_WIDGET (widget));
5912 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
5914 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
5919 eventp = g_new (gint, 1);
5922 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, eventp);
5927 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, NULL);
5930 g_object_notify (G_OBJECT (widget), "events");
5934 gtk_widget_add_events_internal (GtkWidget *widget,
5940 for (l = window_list; l != NULL; l = l->next)
5942 GdkWindow *window = l->data;
5945 gdk_window_get_user_data (window, &user_data);
5946 if (user_data == widget)
5950 gdk_window_set_events (window, gdk_window_get_events (window) | events);
5952 children = gdk_window_get_children (window);
5953 gtk_widget_add_events_internal (widget, events, children);
5954 g_list_free (children);
5960 * gtk_widget_add_events:
5961 * @widget: a #GtkWidget
5962 * @events: an event mask, see #GdkEventMask
5964 * Adds the events in the bitfield @events to the event mask for
5965 * @widget. See gtk_widget_set_events() for details.
5969 gtk_widget_add_events (GtkWidget *widget,
5974 g_return_if_fail (GTK_IS_WIDGET (widget));
5976 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
5982 eventp = g_new (gint, 1);
5987 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, eventp);
5992 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, NULL);
5995 if (GTK_WIDGET_REALIZED (widget))
5999 if (GTK_WIDGET_NO_WINDOW (widget))
6000 window_list = gdk_window_get_children (widget->window);
6002 window_list = g_list_prepend (NULL, widget->window);
6004 gtk_widget_add_events_internal (widget, events, window_list);
6006 g_list_free (window_list);
6009 g_object_notify (G_OBJECT (widget), "events");
6013 * gtk_widget_set_extension_events:
6014 * @widget: a #GtkWidget
6015 * @mode: bitfield of extension events to receive
6017 * Sets the extension events mask to @mode. See #GdkExtensionMode
6018 * and gdk_input_set_extension_events().
6022 gtk_widget_set_extension_events (GtkWidget *widget,
6023 GdkExtensionMode mode)
6025 GdkExtensionMode *modep;
6027 g_return_if_fail (GTK_IS_WIDGET (widget));
6029 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
6032 modep = g_new (GdkExtensionMode, 1);
6035 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode, modep);
6036 g_object_notify (G_OBJECT (widget), "extension-events");
6040 * gtk_widget_get_toplevel:
6041 * @widget: a #GtkWidget
6043 * This function returns the topmost widget in the container hierarchy
6044 * @widget is a part of. If @widget has no parent widgets, it will be
6045 * returned as the topmost widget. No reference will be added to the
6046 * returned widget; it should not be unreferenced.
6048 * Note the difference in behavior vs. gtk_widget_get_ancestor();
6049 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
6051 * %NULL if @widget wasn't inside a toplevel window, and if the
6052 * window was inside a #GtkWindow-derived widget which was in turn
6053 * inside the toplevel #GtkWindow. While the second case may
6054 * seem unlikely, it actually happens when a #GtkPlug is embedded
6055 * inside a #GtkSocket within the same application.
6057 * To reliably find the toplevel #GtkWindow, use
6058 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
6059 * is set on the result.
6060 * <informalexample><programlisting>
6061 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6062 * if (GTK_WIDGET_TOPLEVEL (toplevel))
6064 * [ Perform action on toplevel. ]
6066 * </programlisting></informalexample>
6068 * Return value: the topmost ancestor of @widget, or @widget itself if there's no ancestor.
6071 gtk_widget_get_toplevel (GtkWidget *widget)
6073 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6075 while (widget->parent)
6076 widget = widget->parent;
6082 * gtk_widget_get_ancestor:
6083 * @widget: a #GtkWidget
6084 * @widget_type: ancestor type
6086 * Gets the first ancestor of @widget with type @widget_type. For example,
6087 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets the
6088 * first #GtkBox that's
6089 * an ancestor of @widget. No reference will be added to the returned widget;
6090 * it should not be unreferenced. See note about checking for a toplevel
6091 * #GtkWindow in the docs for gtk_widget_get_toplevel().
6093 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
6094 * considers @widget to be an ancestor of itself.
6096 * Return value: the ancestor widget, or %NULL if not found
6099 gtk_widget_get_ancestor (GtkWidget *widget,
6102 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6104 while (widget && !g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))
6105 widget = widget->parent;
6107 if (!(widget && g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)))
6114 * gtk_widget_get_colormap:
6115 * @widget: a #GtkWidget
6117 * Gets the colormap that will be used to render @widget. No reference will
6118 * be added to the returned colormap; it should not be unreferenced.
6120 * Return value: the colormap used by @widget
6123 gtk_widget_get_colormap (GtkWidget *widget)
6125 GdkColormap *colormap;
6126 GtkWidget *tmp_widget;
6128 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6132 colormap = gdk_drawable_get_colormap (widget->window);
6133 /* If window was destroyed previously, we'll get NULL here */
6138 tmp_widget = widget;
6141 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
6145 tmp_widget= tmp_widget->parent;
6148 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
6152 * gtk_widget_get_visual:
6153 * @widget: a #GtkWidget
6155 * Gets the visual that will be used to render @widget.
6157 * Return value: the visual for @widget
6160 gtk_widget_get_visual (GtkWidget *widget)
6162 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6164 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
6168 * gtk_widget_get_settings:
6169 * @widget: a #GtkWidget
6171 * Gets the settings object holding the settings (global property
6172 * settings, RC file information, etc) used for this widget.
6174 * Note that this function can only be called when the #GtkWidget
6175 * is attached to a toplevel, since the settings object is specific
6176 * to a particular #GdkScreen.
6178 * Return value: the relevant #GtkSettings object
6181 gtk_widget_get_settings (GtkWidget *widget)
6183 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6185 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
6189 * gtk_widget_set_colormap:
6190 * @widget: a #GtkWidget
6191 * @colormap: a colormap
6193 * Sets the colormap for the widget to the given value. Widget must not
6194 * have been previously realized. This probably should only be used
6195 * from an <function>init()</function> function (i.e. from the constructor
6200 gtk_widget_set_colormap (GtkWidget *widget,
6201 GdkColormap *colormap)
6203 g_return_if_fail (GTK_IS_WIDGET (widget));
6204 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
6205 g_return_if_fail (GDK_IS_COLORMAP (colormap));
6207 g_object_ref (colormap);
6209 g_object_set_qdata_full (G_OBJECT (widget),
6216 * gtk_widget_get_events:
6217 * @widget: a #GtkWidget
6219 * Returns the event mask for the widget (a bitfield containing flags
6220 * from the #GdkEventMask enumeration). These are the events that the widget
6223 * Return value: event mask for @widget
6226 gtk_widget_get_events (GtkWidget *widget)
6230 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
6232 events = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
6240 * gtk_widget_get_extension_events:
6241 * @widget: a #GtkWidget
6243 * Retrieves the extension events the widget will receive; see
6244 * gdk_input_set_extension_events().
6246 * Return value: extension events for @widget
6249 gtk_widget_get_extension_events (GtkWidget *widget)
6251 GdkExtensionMode *mode;
6253 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
6255 mode = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
6263 * gtk_widget_get_pointer:
6264 * @widget: a #GtkWidget
6265 * @x: return location for the X coordinate, or %NULL
6266 * @y: return location for the Y coordinate, or %NULL
6268 * Obtains the location of the mouse pointer in widget coordinates.
6269 * Widget coordinates are a bit odd; for historical reasons, they are
6270 * defined as @widget->window coordinates for widgets that are not
6271 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
6272 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
6276 gtk_widget_get_pointer (GtkWidget *widget,
6280 g_return_if_fail (GTK_IS_WIDGET (widget));
6287 if (GTK_WIDGET_REALIZED (widget))
6289 gdk_window_get_pointer (widget->window, x, y, NULL);
6291 if (GTK_WIDGET_NO_WINDOW (widget))
6294 *x -= widget->allocation.x;
6296 *y -= widget->allocation.y;
6302 * gtk_widget_is_ancestor:
6303 * @widget: a #GtkWidget
6304 * @ancestor: another #GtkWidget
6306 * Determines whether @widget is somewhere inside @ancestor, possibly with
6307 * intermediate containers.
6309 * Return value: %TRUE if @ancestor contains @widget as a child, grandchild, great grandchild, etc.
6312 gtk_widget_is_ancestor (GtkWidget *widget,
6313 GtkWidget *ancestor)
6315 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6316 g_return_val_if_fail (ancestor != NULL, FALSE);
6320 if (widget->parent == ancestor)
6322 widget = widget->parent;
6328 static GQuark quark_composite_name = 0;
6331 * gtk_widget_set_composite_name:
6332 * @widget: a #GtkWidget.
6333 * @name: the name to set.
6335 * Sets a widgets composite name. The widget must be
6336 * a composite child of its parent; see gtk_widget_push_composite_child().
6339 gtk_widget_set_composite_name (GtkWidget *widget,
6342 g_return_if_fail (GTK_IS_WIDGET (widget));
6343 g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget));
6344 g_return_if_fail (name != NULL);
6346 if (!quark_composite_name)
6347 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
6349 g_object_set_qdata_full (G_OBJECT (widget),
6350 quark_composite_name,
6356 * gtk_widget_get_composite_name:
6357 * @widget: a #GtkWidget.
6358 * @returns: the composite name of @widget, or %NULL if @widget is not
6359 * a composite child. The string should not be freed when it is no
6362 * Obtains the composite name of a widget.
6365 gtk_widget_get_composite_name (GtkWidget *widget)
6367 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6369 if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent)
6370 return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
6377 * gtk_widget_push_composite_child:
6379 * Makes all newly-created widgets as composite children until
6380 * the corresponding gtk_widget_pop_composite_child() call.
6382 * A composite child is a child that's an implementation detail of the
6383 * container it's inside and should not be visible to people using the
6384 * container. Composite children aren't treated differently by GTK (but
6385 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
6386 * builders might want to treat them in a different way.
6388 * Here is a simple example:
6389 * <informalexample><programlisting>
6390 * gtk_widget_push_composite_child (<!-- -->);
6391 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
6392 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
6393 * gtk_widget_pop_composite_child (<!-- -->);
6394 * gtk_widget_set_parent (scrolled_window->hscrollbar,
6395 * GTK_WIDGET (scrolled_window));
6396 * g_object_ref (scrolled_window->hscrollbar);
6397 * </programlisting></informalexample>
6400 gtk_widget_push_composite_child (void)
6402 composite_child_stack++;
6406 * gtk_widget_pop_composite_child:
6408 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
6411 gtk_widget_pop_composite_child (void)
6413 if (composite_child_stack)
6414 composite_child_stack--;
6418 * gtk_widget_push_colormap:
6419 * @cmap: a #GdkColormap
6421 * Pushes @cmap onto a global stack of colormaps; the topmost
6422 * colormap on the stack will be used to create all widgets.
6423 * Remove @cmap with gtk_widget_pop_colormap(). There's little
6424 * reason to use this function.
6428 gtk_widget_push_colormap (GdkColormap *cmap)
6430 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
6432 colormap_stack = g_slist_prepend (colormap_stack, cmap);
6436 * gtk_widget_pop_colormap:
6438 * Removes a colormap pushed with gtk_widget_push_colormap().
6442 gtk_widget_pop_colormap (void)
6445 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
6449 * gtk_widget_set_default_colormap:
6450 * @colormap: a #GdkColormap
6452 * Sets the default colormap to use when creating widgets.
6453 * gtk_widget_push_colormap() is a better function to use if
6454 * you only want to affect a few widgets, rather than all widgets.
6457 gtk_widget_set_default_colormap (GdkColormap *colormap)
6459 g_return_if_fail (GDK_IS_COLORMAP (colormap));
6461 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
6466 * gtk_widget_get_default_colormap:
6468 * Obtains the default colormap used to create widgets.
6470 * Return value: default widget colormap
6473 gtk_widget_get_default_colormap (void)
6475 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
6479 * gtk_widget_get_default_visual:
6481 * Obtains the visual of the default colormap. Not really useful;
6482 * used to be useful before gdk_colormap_get_visual() existed.
6484 * Return value: visual of the default colormap
6487 gtk_widget_get_default_visual (void)
6489 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
6493 gtk_widget_emit_direction_changed (GtkWidget *widget,
6494 GtkTextDirection old_dir)
6496 PangoContext *context = gtk_widget_peek_pango_context (widget);
6499 pango_context_set_base_dir (context,
6500 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
6501 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
6503 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
6507 * gtk_widget_set_direction:
6508 * @widget: a #GtkWidget
6509 * @dir: the new direction
6511 * Sets the reading direction on a particular widget. This direction
6512 * controls the primary direction for widgets containing text,
6513 * and also the direction in which the children of a container are
6514 * packed. The ability to set the direction is present in order
6515 * so that correct localization into languages with right-to-left
6516 * reading directions can be done. Generally, applications will
6517 * let the default reading direction present, except for containers
6518 * where the containers are arranged in an order that is explicitely
6519 * visual rather than logical (such as buttons for text justification).
6521 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
6522 * set by gtk_widget_set_default_direction() will be used.
6525 gtk_widget_set_direction (GtkWidget *widget,
6526 GtkTextDirection dir)
6528 GtkTextDirection old_dir;
6530 g_return_if_fail (GTK_IS_WIDGET (widget));
6531 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
6533 old_dir = gtk_widget_get_direction (widget);
6535 if (dir == GTK_TEXT_DIR_NONE)
6536 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
6539 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
6540 if (dir == GTK_TEXT_DIR_LTR)
6541 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
6543 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
6546 if (old_dir != gtk_widget_get_direction (widget))
6547 gtk_widget_emit_direction_changed (widget, old_dir);
6551 * gtk_widget_get_direction:
6552 * @widget: a #GtkWidget
6554 * Gets the reading direction for a particular widget. See
6555 * gtk_widget_set_direction().
6557 * Return value: the reading direction for the widget.
6560 gtk_widget_get_direction (GtkWidget *widget)
6562 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
6564 if (GTK_WIDGET_DIRECTION_SET (widget))
6565 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
6567 return gtk_default_direction;
6571 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
6573 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
6575 g_object_ref (widget);
6577 if (!GTK_WIDGET_DIRECTION_SET (widget))
6578 gtk_widget_emit_direction_changed (widget, old_dir);
6580 if (GTK_IS_CONTAINER (widget))
6581 gtk_container_forall (GTK_CONTAINER (widget),
6582 gtk_widget_set_default_direction_recurse,
6585 g_object_unref (widget);
6589 * gtk_widget_set_default_direction:
6590 * @dir: the new default direction. This cannot be
6591 * %GTK_TEXT_DIR_NONE.
6593 * Sets the default reading direction for widgets where the
6594 * direction has not been explicitly set by gtk_widget_set_direction().
6597 gtk_widget_set_default_direction (GtkTextDirection dir)
6599 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
6601 if (dir != gtk_default_direction)
6603 GList *toplevels, *tmp_list;
6604 GtkTextDirection old_dir = gtk_default_direction;
6606 gtk_default_direction = dir;
6608 tmp_list = toplevels = gtk_window_list_toplevels ();
6609 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
6613 gtk_widget_set_default_direction_recurse (tmp_list->data,
6614 GUINT_TO_POINTER (old_dir));
6615 g_object_unref (tmp_list->data);
6616 tmp_list = tmp_list->next;
6619 g_list_free (toplevels);
6624 * gtk_widget_get_default_direction:
6626 * Obtains the current default reading direction. See
6627 * gtk_widget_set_default_direction().
6629 * Return value: the current default direction.
6632 gtk_widget_get_default_direction (void)
6634 return gtk_default_direction;
6638 gtk_widget_dispose (GObject *object)
6640 GtkWidget *widget = GTK_WIDGET (object);
6643 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
6644 else if (GTK_WIDGET_VISIBLE (widget))
6645 gtk_widget_hide (widget);
6647 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
6648 if (GTK_WIDGET_REALIZED (widget))
6649 gtk_widget_unrealize (widget);
6651 G_OBJECT_CLASS (parent_class)->dispose (object);
6655 gtk_widget_real_destroy (GtkObject *object)
6657 /* gtk_object_destroy() will already hold a refcount on object */
6658 GtkWidget *widget = GTK_WIDGET (object);
6660 /* wipe accelerator closures (keep order) */
6661 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
6662 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
6664 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
6665 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
6667 gtk_grab_remove (widget);
6669 g_object_unref (widget->style);
6670 widget->style = gtk_widget_get_default_style ();
6671 g_object_ref (widget->style);
6673 GTK_OBJECT_CLASS (parent_class)->destroy (object);
6677 gtk_widget_finalize (GObject *object)
6679 GtkWidget *widget = GTK_WIDGET (object);
6680 GtkWidgetAuxInfo *aux_info;
6682 GdkExtensionMode *mode;
6683 GtkAccessible *accessible;
6685 gtk_grab_remove (widget);
6687 g_object_unref (widget->style);
6688 widget->style = NULL;
6691 g_free (widget->name);
6693 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
6695 gtk_widget_aux_info_destroy (aux_info);
6697 events = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
6701 mode = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
6705 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
6707 g_object_unref (accessible);
6709 G_OBJECT_CLASS (parent_class)->finalize (object);
6712 /*****************************************
6713 * gtk_widget_real_map:
6718 *****************************************/
6721 gtk_widget_real_map (GtkWidget *widget)
6723 g_return_if_fail (GTK_WIDGET_REALIZED (widget) == TRUE);
6725 if (!GTK_WIDGET_MAPPED (widget))
6727 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
6729 if (!GTK_WIDGET_NO_WINDOW (widget))
6730 gdk_window_show (widget->window);
6734 /*****************************************
6735 * gtk_widget_real_unmap:
6740 *****************************************/
6743 gtk_widget_real_unmap (GtkWidget *widget)
6745 if (GTK_WIDGET_MAPPED (widget))
6747 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
6749 if (!GTK_WIDGET_NO_WINDOW (widget))
6750 gdk_window_hide (widget->window);
6754 /*****************************************
6755 * gtk_widget_real_realize:
6760 *****************************************/
6763 gtk_widget_real_realize (GtkWidget *widget)
6765 g_return_if_fail (GTK_WIDGET_NO_WINDOW (widget));
6767 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
6770 widget->window = gtk_widget_get_parent_window (widget);
6771 g_object_ref (widget->window);
6773 widget->style = gtk_style_attach (widget->style, widget->window);
6776 /*****************************************
6777 * gtk_widget_real_unrealize:
6782 *****************************************/
6785 gtk_widget_real_unrealize (GtkWidget *widget)
6787 if (GTK_WIDGET_MAPPED (widget))
6788 gtk_widget_real_unmap (widget);
6790 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
6792 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
6795 /* We must do unrealize child widget BEFORE container widget.
6796 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
6797 * So, unrealizing container widget bofore its children causes the problem
6798 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
6801 if (GTK_IS_CONTAINER (widget))
6802 gtk_container_forall (GTK_CONTAINER (widget),
6803 (GtkCallback) gtk_widget_unrealize,
6806 gtk_style_detach (widget->style);
6807 if (!GTK_WIDGET_NO_WINDOW (widget))
6809 gdk_window_set_user_data (widget->window, NULL);
6810 gdk_window_destroy (widget->window);
6811 widget->window = NULL;
6815 g_object_unref (widget->window);
6816 widget->window = NULL;
6819 gtk_selection_remove_all (widget);
6821 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
6825 gtk_widget_real_size_request (GtkWidget *widget,
6826 GtkRequisition *requisition)
6828 requisition->width = widget->requisition.width;
6829 requisition->height = widget->requisition.height;
6833 * _gtk_widget_peek_colormap:
6835 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
6837 * Return value: the currently pushed colormap, or %NULL if there is none.
6840 _gtk_widget_peek_colormap (void)
6843 return (GdkColormap*) colormap_stack->data;
6848 gtk_widget_propagate_state (GtkWidget *widget,
6853 /* don't call this function with state==GTK_STATE_INSENSITIVE,
6854 * parent_sensitive==TRUE on a sensitive widget
6857 old_state = GTK_WIDGET_STATE (widget);
6859 if (data->parent_sensitive)
6861 GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
6863 if (GTK_WIDGET_IS_SENSITIVE (widget))
6865 if (data->state_restoration)
6866 GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget);
6868 GTK_WIDGET_STATE (widget) = data->state;
6872 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
6873 if (!data->state_restoration &&
6874 data->state != GTK_STATE_INSENSITIVE)
6875 GTK_WIDGET_SAVED_STATE (widget) = data->state;
6880 GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
6881 if (!data->state_restoration)
6883 if (data->state != GTK_STATE_INSENSITIVE)
6884 GTK_WIDGET_SAVED_STATE (widget) = data->state;
6886 else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
6887 GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget);
6888 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
6891 if (gtk_widget_is_focus (widget) && !GTK_WIDGET_IS_SENSITIVE (widget))
6895 window = gtk_widget_get_toplevel (widget);
6896 if (window && GTK_WIDGET_TOPLEVEL (window))
6897 gtk_window_set_focus (GTK_WINDOW (window), NULL);
6900 if (old_state != GTK_WIDGET_STATE (widget))
6902 g_object_ref (widget);
6904 if (!GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_HAS_GRAB (widget))
6905 gtk_grab_remove (widget);
6907 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
6909 if (GTK_IS_CONTAINER (widget))
6911 data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE);
6912 data->state = GTK_WIDGET_STATE (widget);
6913 if (data->use_forall)
6914 gtk_container_forall (GTK_CONTAINER (widget),
6915 (GtkCallback) gtk_widget_propagate_state,
6918 gtk_container_foreach (GTK_CONTAINER (widget),
6919 (GtkCallback) gtk_widget_propagate_state,
6922 g_object_unref (widget);
6927 * _gtk_widget_get_aux_info:
6928 * @widget: a #GtkWidget
6929 * @create: if %TRUE, create the structure if it doesn't exist
6931 * Get the #GtkWidgetAuxInfo structure for the widget.
6933 * Return value: the #GtkAuxInfo structure for the widget, or
6934 * %NULL if @create is %FALSE and one doesn't already exist.
6937 _gtk_widget_get_aux_info (GtkWidget *widget,
6940 GtkWidgetAuxInfo *aux_info;
6942 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
6943 if (!aux_info && create)
6945 if (!aux_info_mem_chunk)
6946 aux_info_mem_chunk = g_mem_chunk_new ("widget aux info mem chunk",
6947 sizeof (GtkWidgetAuxInfo),
6948 1024, G_ALLOC_AND_FREE);
6949 aux_info = g_chunk_new (GtkWidgetAuxInfo, aux_info_mem_chunk);
6951 aux_info->width = -1;
6952 aux_info->height = -1;
6955 aux_info->x_set = FALSE;
6956 aux_info->y_set = FALSE;
6957 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
6963 /*****************************************
6964 * gtk_widget_aux_info_destroy:
6969 *****************************************/
6972 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
6974 g_mem_chunk_free (aux_info_mem_chunk, aux_info);
6978 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
6980 g_object_unref (info->shape_mask);
6985 * gtk_widget_shape_combine_mask:
6986 * @widget: a #GtkWidget.
6987 * @shape_mask: shape to be added, or %NULL to remove an existing shape.
6988 * @offset_x: X position of shape mask with respect to @window.
6989 * @offset_y: Y position of shape mask with respect to @window.
6991 * Sets a shape for this widget's GDK window. This allows for
6992 * transparent windows etc., see gdk_window_shape_combine_mask()
6993 * for more information.
6996 gtk_widget_shape_combine_mask (GtkWidget *widget,
6997 GdkBitmap *shape_mask,
7001 GtkWidgetShapeInfo* shape_info;
7003 g_return_if_fail (GTK_IS_WIDGET (widget));
7004 /* set_shape doesn't work on widgets without gdk window */
7005 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
7009 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
7012 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
7014 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
7018 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
7020 shape_info = g_new (GtkWidgetShapeInfo, 1);
7021 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
7022 (GDestroyNotify) gtk_widget_shape_info_destroy);
7024 shape_info->shape_mask = g_object_ref (shape_mask);
7025 shape_info->offset_x = offset_x;
7026 shape_info->offset_y = offset_y;
7028 /* set shape if widget has a gdk window allready.
7029 * otherwise the shape is scheduled to be set by gtk_widget_realize.
7032 gdk_window_shape_combine_mask (widget->window, shape_mask,
7033 offset_x, offset_y);
7038 gtk_reset_shapes_recurse (GtkWidget *widget,
7044 gdk_window_get_user_data (window, &data);
7048 gdk_window_shape_combine_mask (window, NULL, 0, 0);
7049 for (list = gdk_window_peek_children (window); list; list = list->next)
7050 gtk_reset_shapes_recurse (widget, list->data);
7054 * gtk_widget_reset_shapes:
7055 * @widget: a #GtkWidget.
7057 * Recursively resets the shape on this widget and its descendants.
7060 gtk_widget_reset_shapes (GtkWidget *widget)
7062 g_return_if_fail (GTK_IS_WIDGET (widget));
7063 g_return_if_fail (GTK_WIDGET_REALIZED (widget));
7065 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
7066 gtk_reset_shapes_recurse (widget, widget->window);
7071 * @widget: a #GtkWidget
7073 * Adds a reference to a widget. This function is exactly the same
7074 * as calling g_object_ref(), and exists mostly for historical
7075 * reasons. It can still be convenient to avoid casting a widget
7076 * to a #GObject, it saves a small amount of typing.
7078 * Return value: the widget that was referenced
7081 gtk_widget_ref (GtkWidget *widget)
7083 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7085 return (GtkWidget*) g_object_ref ((GObject*) widget);
7090 * @widget: a #GtkWidget
7092 * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
7096 gtk_widget_unref (GtkWidget *widget)
7098 g_return_if_fail (GTK_IS_WIDGET (widget));
7100 g_object_unref ((GObject*) widget);
7108 * gtk_widget_class_install_style_property_parser:
7109 * @klass: a #GtkWidgetClass
7110 * @pspec: the #GParamSpec for the style property
7111 * @parser: the parser for the style property
7113 * Installs a style property on a widget class.
7116 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
7118 GtkRcPropertyParser parser)
7120 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
7121 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
7122 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
7123 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
7125 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
7127 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
7128 G_OBJECT_CLASS_NAME (klass),
7133 g_param_spec_ref (pspec);
7134 g_param_spec_sink (pspec);
7135 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
7136 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
7140 * gtk_widget_class_install_style_property:
7141 * @klass: a #GtkWidgetClass
7142 * @pspec: the #GParamSpec for the property
7144 * Installs a style property on a widget class. The parser for the
7145 * style property is determined by the value type of @pspec.
7148 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
7151 GtkRcPropertyParser parser;
7153 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
7154 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
7156 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
7158 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
7162 * gtk_widget_class_find_style_property:
7163 * @klass: a #GtkWidgetClass
7164 * @property_name: the name of the style property to find
7165 * @returns: the #GParamSpec of the style property or %NULL if @class has no
7166 * style property with that name.
7168 * Finds a style property of a widget class by name.
7173 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
7174 const gchar *property_name)
7176 g_return_val_if_fail (property_name != NULL, NULL);
7178 return g_param_spec_pool_lookup (style_property_spec_pool,
7180 G_OBJECT_CLASS_TYPE (klass),
7185 * gtk_widget_class_list_style_properties:
7186 * @klass: a #GtkWidgetClass
7187 * @n_properties: location to return the number of style properties found
7188 * @returns: an newly allocated array of #GParamSpec*. The array must be freed with g_free().
7190 * Returns all style properties of a widget class.
7195 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
7196 guint *n_properties)
7198 GParamSpec **pspecs;
7201 pspecs = g_param_spec_pool_list (style_property_spec_pool,
7202 G_OBJECT_CLASS_TYPE (klass),
7211 * gtk_widget_style_get_property:
7212 * @widget: a #GtkWidget
7213 * @property_name: the name of a style property
7214 * @value: location to return the property value
7216 * Gets the value of a style property of @widget.
7219 gtk_widget_style_get_property (GtkWidget *widget,
7220 const gchar *property_name,
7225 g_return_if_fail (GTK_IS_WIDGET (widget));
7226 g_return_if_fail (property_name != NULL);
7227 g_return_if_fail (G_IS_VALUE (value));
7229 g_object_ref (widget);
7230 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
7232 G_OBJECT_TYPE (widget),
7235 g_warning ("%s: widget class `%s' has no property named `%s'",
7237 G_OBJECT_TYPE_NAME (widget),
7241 const GValue *peek_value;
7243 peek_value = _gtk_style_peek_property_value (widget->style,
7244 G_OBJECT_TYPE (widget),
7246 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
7248 /* auto-conversion of the caller's value type
7250 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
7251 g_value_copy (peek_value, value);
7252 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
7253 g_value_transform (peek_value, value);
7255 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
7257 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
7258 G_VALUE_TYPE_NAME (value));
7260 g_object_unref (widget);
7264 * gtk_widget_style_get_valist:
7265 * @widget: a #GtkWidget
7266 * @first_property_name: the name of the first property to get
7267 * @var_args: a <type>va_list</type> of pairs of property names and
7268 * locations to return the property values, starting with the location
7269 * for @first_property_name.
7271 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
7275 gtk_widget_style_get_valist (GtkWidget *widget,
7276 const gchar *first_property_name,
7281 g_return_if_fail (GTK_IS_WIDGET (widget));
7283 g_object_ref (widget);
7285 name = first_property_name;
7288 const GValue *peek_value;
7292 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
7294 G_OBJECT_TYPE (widget),
7298 g_warning ("%s: widget class `%s' has no property named `%s'",
7300 G_OBJECT_TYPE_NAME (widget),
7304 /* style pspecs are always readable so we can spare that check here */
7306 peek_value = _gtk_style_peek_property_value (widget->style,
7307 G_OBJECT_TYPE (widget),
7309 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
7310 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
7313 g_warning ("%s: %s", G_STRLOC, error);
7318 name = va_arg (var_args, gchar*);
7321 g_object_unref (widget);
7325 * gtk_widget_style_get:
7326 * @widget: a #GtkWidget
7327 * @first_property_name: the name of the first property to get
7328 * @Varargs: pairs of property names and locations to
7329 * return the property values, starting with the location for
7330 * @first_property_name, terminated by %NULL.
7332 * Gets the values of a multiple style properties of @widget.
7335 gtk_widget_style_get (GtkWidget *widget,
7336 const gchar *first_property_name,
7341 g_return_if_fail (GTK_IS_WIDGET (widget));
7343 va_start (var_args, first_property_name);
7344 gtk_widget_style_get_valist (widget, first_property_name, var_args);
7350 * @widget: a #GtkWidget
7351 * @path_length: location to store length of the path, or %NULL
7352 * @path: location to store allocated path string, or %NULL
7353 * @path_reversed: location to store allocated reverse path string, or %NULL
7355 * Obtains the full path to @widget. The path is simply the name of a
7356 * widget and all its parents in the container hierarchy, separated by
7357 * periods. The name of a widget comes from
7358 * gtk_widget_get_name(). Paths are used to apply styles to a widget
7359 * in gtkrc configuration files. Widget names are the type of the
7360 * widget by default (e.g. "GtkButton") or can be set to an
7361 * application-specific value with gtk_widget_set_name(). By setting
7362 * the name of a widget, you allow users or theme authors to apply
7363 * styles to that specific widget in their gtkrc
7364 * file. @path_reversed_p fills in the path in reverse order,
7365 * i.e. starting with @widget's name instead of starting with the name
7366 * of @widget's outermost ancestor.
7370 gtk_widget_path (GtkWidget *widget,
7373 gchar **path_reversed)
7375 static gchar *rev_path = NULL;
7376 static guint tmp_path_len = 0;
7379 g_return_if_fail (GTK_IS_WIDGET (widget));
7384 const gchar *string;
7389 string = gtk_widget_get_name (widget);
7390 l = strlen (string);
7391 while (tmp_path_len <= len + l + 1)
7393 tmp_path_len += INIT_PATH_SIZE;
7394 rev_path = g_realloc (rev_path, tmp_path_len);
7402 widget = widget->parent;
7405 rev_path[len++] = '.';
7407 rev_path[len++] = 0;
7412 *path_length = len - 1;
7414 *path_reversed = g_strdup (rev_path);
7417 *path = g_strdup (rev_path);
7418 g_strreverse (*path);
7423 * gtk_widget_class_path:
7424 * @widget: a #GtkWidget
7425 * @path_length: location to store the length of the class path, or %NULL
7426 * @path: location to store the class path as an allocated string, or %NULL
7427 * @path_reversed: location to store the reverse class path as an allocated string, or %NULL
7429 * Same as gtk_widget_path(), but always uses the name of a widget's type,
7430 * never uses a custom name set with gtk_widget_set_name().
7434 gtk_widget_class_path (GtkWidget *widget,
7437 gchar **path_reversed)
7439 static gchar *rev_path = NULL;
7440 static guint tmp_path_len = 0;
7443 g_return_if_fail (GTK_IS_WIDGET (widget));
7448 const gchar *string;
7453 string = g_type_name (GTK_WIDGET_TYPE (widget));
7454 l = strlen (string);
7455 while (tmp_path_len <= len + l + 1)
7457 tmp_path_len += INIT_PATH_SIZE;
7458 rev_path = g_realloc (rev_path, tmp_path_len);
7466 widget = widget->parent;
7469 rev_path[len++] = '.';
7471 rev_path[len++] = 0;
7476 *path_length = len - 1;
7478 *path_reversed = g_strdup (rev_path);
7481 *path = g_strdup (rev_path);
7482 g_strreverse (*path);
7487 * gtk_requisition_copy:
7488 * @requisition: a #GtkRequisition.
7489 * @returns: a copy of @requisition.
7491 * Copies a #GtkRequisition.
7494 gtk_requisition_copy (const GtkRequisition *requisition)
7496 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
7500 * gtk_requisition_free:
7501 * @requisition: a #GtkRequisition.
7503 * Frees a #GtkRequisition.
7506 gtk_requisition_free (GtkRequisition *requisition)
7508 g_free (requisition);
7512 gtk_requisition_get_type (void)
7514 static GType our_type = 0;
7517 our_type = g_boxed_type_register_static ("GtkRequisition",
7518 (GBoxedCopyFunc) gtk_requisition_copy,
7519 (GBoxedFreeFunc) gtk_requisition_free);
7525 * gtk_widget_get_accessible:
7526 * @widget: a #GtkWidget
7528 * Returns the accessible object that describes the widget to an
7529 * assistive technology.
7531 * If no accessibility library is loaded (i.e. no ATK implementation library is
7532 * loaded via <envar>GTK_MODULES</envar> or via another application library,
7533 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
7534 * if no class-specific #AtkObject implementation is available for the widget
7535 * instance in question, it will inherit an #AtkObject implementation from the
7536 * first ancestor class for which such an implementation is defined.
7538 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
7539 * library contains more information about accessible objects and their uses.
7541 * Returns: the #AtkObject associated with @widget
7544 gtk_widget_get_accessible (GtkWidget *widget)
7546 GtkWidgetClass *klass;
7548 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7550 klass = GTK_WIDGET_GET_CLASS (widget);
7552 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
7554 return klass->get_accessible (widget);
7558 gtk_widget_real_get_accessible (GtkWidget *widget)
7560 AtkObject* accessible;
7562 accessible = g_object_get_qdata (G_OBJECT (widget),
7563 quark_accessible_object);
7566 AtkObjectFactory *factory;
7567 AtkRegistry *default_registry;
7569 default_registry = atk_get_default_registry ();
7570 factory = atk_registry_get_factory (default_registry,
7571 G_TYPE_FROM_INSTANCE (widget));
7573 atk_object_factory_create_accessible (factory,
7575 g_object_set_qdata (G_OBJECT (widget),
7576 quark_accessible_object,
7583 * Initialize a AtkImplementorIface instance's virtual pointers as
7584 * appropriate to this implementor's class (GtkWidget).
7587 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
7589 iface->ref_accessible = gtk_widget_ref_accessible;
7593 gtk_widget_ref_accessible (AtkImplementor *implementor)
7595 AtkObject *accessible;
7597 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
7599 g_object_ref (accessible);
7604 * gtk_widget_get_clipboard:
7605 * @widget: a #GtkWidget
7606 * @selection: a #GdkAtom which identifies the clipboard
7607 * to use. %GDK_SELECTION_CLIPBOARD gives the
7608 * default clipboard. Another common value
7609 * is %GDK_SELECTION_PRIMARY, which gives
7610 * the primary X selection.
7612 * Returns the clipboard object for the given selection to
7613 * be used with @widget. @widget must have a #GdkDisplay
7614 * associated with it, so must be attached to a toplevel
7617 * Return value: the appropriate clipboard object. If no
7618 * clipboard already exists, a new one will
7619 * be created. Once a clipboard object has
7620 * been created, it is persistent for all time.
7625 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
7627 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7628 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
7630 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
7635 * gtk_widget_list_mnemonic_labels:
7636 * @widget: a #GtkWidget
7638 * Returns a newly allocated list of the widgets, normally labels, for
7639 * which this widget is a the target of a mnemonic (see for example,
7640 * gtk_label_set_mnemonic_widget()).
7642 * The widgets in the list are not individually referenced. If you
7643 * want to iterate through the list and perform actions involving
7644 * callbacks that might destroy the widgets, you
7645 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
7646 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
7647 * widgets afterwards.
7649 * Return value: the list of mnemonic labels; free this list
7650 * with g_list_free() when you are done with it.
7655 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
7660 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7662 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
7663 list = g_list_prepend (list, l->data);
7669 * gtk_widget_add_mnemonic_label:
7670 * @widget: a #GtkWidget
7671 * @label: a #GtkWidget that acts as a mnemonic label for @widget.
7673 * Adds a widget to the list of mnemonic labels for
7674 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
7675 * list of mnemonic labels for the widget is cleared when the
7676 * widget is destroyed, so the caller must make sure to update
7677 * its internal state at this point as well, by using a connection
7678 * to the ::destroy signal or a weak notifier.
7683 gtk_widget_add_mnemonic_label (GtkWidget *widget,
7686 GSList *old_list, *new_list;
7688 g_return_if_fail (GTK_IS_WIDGET (widget));
7689 g_return_if_fail (GTK_IS_WIDGET (label));
7691 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
7692 new_list = g_slist_prepend (old_list, label);
7694 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
7695 new_list, (GDestroyNotify) g_slist_free);
7699 * gtk_widget_remove_mnemonic_label:
7700 * @widget: a #GtkWidget
7701 * @label: a #GtkWidget that was previously set as a mnemnic label for
7702 * @widget with gtk_widget_add_mnemonic_label().
7704 * Removes a widget from the list of mnemonic labels for
7705 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
7706 * must have previously been added to the list with
7707 * gtk_widget_add_mnemonic_label().
7712 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
7715 GSList *old_list, *new_list;
7717 g_return_if_fail (GTK_IS_WIDGET (widget));
7718 g_return_if_fail (GTK_IS_WIDGET (label));
7720 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
7721 new_list = g_slist_remove (old_list, label);
7724 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
7725 new_list, (GDestroyNotify) g_slist_free);
7729 * gtk_widget_get_no_show_all:
7730 * @widget: a #GtkWidget
7732 * Returns the current value of the "no_show_all" property, which determines
7733 * whether calls to gtk_widget_show_all() and gtk_widget_hide_all()
7734 * will affect this widget.
7736 * Return value: the current value of the "no_show_all" property.
7741 gtk_widget_get_no_show_all (GtkWidget *widget)
7743 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7745 return (GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
7749 * gtk_widget_set_no_show_all:
7750 * @widget: a #GtkWidget
7751 * @no_show_all: the new value for the "no_show_all" property
7753 * Sets the "no_show_all" property, which determines whether calls to
7754 * gtk_widget_show_all() and gtk_widget_hide_all() will affect this widget.
7756 * This is mostly for use in constructing widget hierarchies with externally
7757 * controlled visibility, see #GtkUIManager.
7762 gtk_widget_set_no_show_all (GtkWidget *widget,
7763 gboolean no_show_all)
7765 g_return_if_fail (GTK_IS_WIDGET (widget));
7767 no_show_all = (no_show_all != FALSE);
7769 if (no_show_all == ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0))
7773 GTK_WIDGET_SET_FLAGS (widget, GTK_NO_SHOW_ALL);
7775 GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_SHOW_ALL);
7777 g_object_notify (G_OBJECT (widget), "no-show-all");
7780 #define __GTK_WIDGET_C__
7781 #include "gtkaliasdef.c"