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"
56 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
57 #define INIT_PATH_SIZE (512)
97 PROPERTY_NOTIFY_EVENT,
98 SELECTION_CLEAR_EVENT,
99 SELECTION_REQUEST_EVENT,
100 SELECTION_NOTIFY_EVENT,
115 VISIBILITY_NOTIFY_EVENT,
119 ACCEL_CLOSURES_CHANGED,
139 PROP_RECEIVES_DEFAULT,
140 PROP_COMPOSITE_CHILD,
143 PROP_EXTENSION_EVENTS,
147 typedef struct _GtkStateData GtkStateData;
152 guint state_restoration : 1;
153 guint parent_sensitive : 1;
154 guint use_forall : 1;
158 /* --- prototypes --- */
159 static void gtk_widget_class_init (GtkWidgetClass *klass);
160 static void gtk_widget_init (GtkWidget *widget);
161 static void gtk_widget_set_property (GObject *object,
165 static void gtk_widget_get_property (GObject *object,
169 static void gtk_widget_dispose (GObject *object);
170 static void gtk_widget_real_destroy (GtkObject *object);
171 static void gtk_widget_finalize (GObject *object);
172 static void gtk_widget_real_show (GtkWidget *widget);
173 static void gtk_widget_real_hide (GtkWidget *widget);
174 static void gtk_widget_real_map (GtkWidget *widget);
175 static void gtk_widget_real_unmap (GtkWidget *widget);
176 static void gtk_widget_real_realize (GtkWidget *widget);
177 static void gtk_widget_real_unrealize (GtkWidget *widget);
178 static void gtk_widget_real_size_request (GtkWidget *widget,
179 GtkRequisition *requisition);
180 static void gtk_widget_real_size_allocate (GtkWidget *widget,
181 GtkAllocation *allocation);
182 static void gtk_widget_style_set (GtkWidget *widget,
183 GtkStyle *previous_style);
184 static void gtk_widget_direction_changed (GtkWidget *widget,
185 GtkTextDirection previous_direction);
187 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
188 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
189 GtkWidgetHelpType help_type);
191 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
193 GParamSpec **pspecs);
194 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
196 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
198 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
199 GdkEventFocus *event);
200 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
201 GdkEventFocus *event);
202 static gboolean gtk_widget_real_focus (GtkWidget *widget,
203 GtkDirectionType direction);
204 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
205 static void gtk_widget_propagate_state (GtkWidget *widget,
207 static void gtk_widget_reset_rc_style (GtkWidget *widget);
208 static void gtk_widget_set_style_internal (GtkWidget *widget,
210 gboolean initial_emission);
211 static gint gtk_widget_event_internal (GtkWidget *widget,
213 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
214 gboolean group_cycling);
215 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
216 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
217 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
218 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
219 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
221 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
222 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
223 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
226 static void gtk_widget_set_usize_internal (GtkWidget *widget,
231 /* --- variables --- */
232 static gpointer parent_class = NULL;
233 static guint widget_signals[LAST_SIGNAL] = { 0 };
234 static GMemChunk *aux_info_mem_chunk = NULL;
235 static GtkStyle *gtk_default_style = NULL;
236 static GSList *colormap_stack = NULL;
237 static guint composite_child_stack = 0;
238 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
239 static GParamSpecPool *style_property_spec_pool = NULL;
241 static GQuark quark_property_parser = 0;
242 static GQuark quark_aux_info = 0;
243 static GQuark quark_accel_path = 0;
244 static GQuark quark_accel_closures = 0;
245 static GQuark quark_event_mask = 0;
246 static GQuark quark_extension_event_mode = 0;
247 static GQuark quark_parent_window = 0;
248 static GQuark quark_shape_info = 0;
249 static GQuark quark_colormap = 0;
250 static GQuark quark_pango_context = 0;
251 static GQuark quark_rc_style = 0;
252 static GQuark quark_accessible_object = 0;
253 static GQuark quark_mnemonic_labels = 0;
254 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
255 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
257 /* --- functions --- */
259 gtk_widget_get_type (void)
261 static GType widget_type = 0;
265 static const GTypeInfo widget_info =
267 sizeof (GtkWidgetClass),
268 NULL, /* base_init */
269 NULL, /* base_finalize */
270 (GClassInitFunc) gtk_widget_class_init,
271 NULL, /* class_finalize */
272 NULL, /* class_init */
275 (GInstanceInitFunc) gtk_widget_init,
276 NULL, /* value_table */
279 static const GInterfaceInfo accessibility_info =
281 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
282 (GInterfaceFinalizeFunc) NULL,
283 NULL /* interface data */
286 widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
287 &widget_info, G_TYPE_FLAG_ABSTRACT);
289 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
290 &accessibility_info) ;
298 child_property_notify_dispatcher (GObject *object,
302 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
306 gtk_widget_class_init (GtkWidgetClass *klass)
308 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
309 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
310 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
311 GtkBindingSet *binding_set;
313 parent_class = g_type_class_peek_parent (klass);
315 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
316 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
317 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
318 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
319 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
320 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
321 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
322 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
323 quark_colormap = g_quark_from_static_string ("gtk-colormap");
324 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
325 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
326 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
327 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
329 style_property_spec_pool = g_param_spec_pool_new (FALSE);
330 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
331 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
332 cpn_context.dispatcher = child_property_notify_dispatcher;
333 _gtk_widget_child_property_notify_context = &cpn_context;
335 gobject_class->dispose = gtk_widget_dispose;
336 gobject_class->finalize = gtk_widget_finalize;
337 gobject_class->set_property = gtk_widget_set_property;
338 gobject_class->get_property = gtk_widget_get_property;
340 object_class->destroy = gtk_widget_real_destroy;
342 klass->activate_signal = 0;
343 klass->set_scroll_adjustments_signal = 0;
344 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
345 klass->show = gtk_widget_real_show;
346 klass->show_all = gtk_widget_show;
347 klass->hide = gtk_widget_real_hide;
348 klass->hide_all = gtk_widget_hide;
349 klass->map = gtk_widget_real_map;
350 klass->unmap = gtk_widget_real_unmap;
351 klass->realize = gtk_widget_real_realize;
352 klass->unrealize = gtk_widget_real_unrealize;
353 klass->size_request = gtk_widget_real_size_request;
354 klass->size_allocate = gtk_widget_real_size_allocate;
355 klass->state_changed = NULL;
356 klass->parent_set = NULL;
357 klass->hierarchy_changed = NULL;
358 klass->style_set = gtk_widget_style_set;
359 klass->direction_changed = gtk_widget_direction_changed;
360 klass->grab_notify = NULL;
361 klass->child_notify = NULL;
362 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
363 klass->grab_focus = gtk_widget_real_grab_focus;
364 klass->focus = gtk_widget_real_focus;
366 klass->button_press_event = NULL;
367 klass->button_release_event = NULL;
368 klass->motion_notify_event = NULL;
369 klass->delete_event = NULL;
370 klass->destroy_event = NULL;
371 klass->expose_event = NULL;
372 klass->key_press_event = gtk_widget_real_key_press_event;
373 klass->key_release_event = gtk_widget_real_key_release_event;
374 klass->enter_notify_event = NULL;
375 klass->leave_notify_event = NULL;
376 klass->configure_event = NULL;
377 klass->focus_in_event = gtk_widget_real_focus_in_event;
378 klass->focus_out_event = gtk_widget_real_focus_out_event;
379 klass->map_event = NULL;
380 klass->unmap_event = NULL;
381 klass->window_state_event = NULL;
382 klass->property_notify_event = _gtk_selection_property_notify;
383 klass->selection_clear_event = gtk_selection_clear;
384 klass->selection_request_event = _gtk_selection_request;
385 klass->selection_notify_event = _gtk_selection_notify;
386 klass->selection_received = NULL;
387 klass->proximity_in_event = NULL;
388 klass->proximity_out_event = NULL;
389 klass->drag_begin = NULL;
390 klass->drag_end = NULL;
391 klass->drag_data_delete = NULL;
392 klass->drag_leave = NULL;
393 klass->drag_motion = NULL;
394 klass->drag_drop = NULL;
395 klass->drag_data_received = NULL;
396 klass->screen_changed = NULL;
397 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
399 klass->show_help = gtk_widget_real_show_help;
401 /* Accessibility support */
402 klass->get_accessible = gtk_widget_real_get_accessible;
404 klass->no_expose_event = NULL;
406 g_object_class_install_property (gobject_class,
408 g_param_spec_string ("name",
410 P_("The name of the widget"),
413 g_object_class_install_property (gobject_class,
415 g_param_spec_object ("parent",
417 P_("The parent widget of this widget. Must be a Container widget"),
421 g_object_class_install_property (gobject_class,
423 g_param_spec_int ("width_request",
425 P_("Override for width request of the widget, or -1 if natural request should be used"),
430 g_object_class_install_property (gobject_class,
432 g_param_spec_int ("height_request",
433 P_("Height request"),
434 P_("Override for height request of the widget, or -1 if natural request should be used"),
439 g_object_class_install_property (gobject_class,
441 g_param_spec_boolean ("visible",
443 P_("Whether the widget is visible"),
446 g_object_class_install_property (gobject_class,
448 g_param_spec_boolean ("sensitive",
450 P_("Whether the widget responds to input"),
453 g_object_class_install_property (gobject_class,
455 g_param_spec_boolean ("app_paintable",
456 P_("Application paintable"),
457 P_("Whether the application will paint directly on the widget"),
460 g_object_class_install_property (gobject_class,
462 g_param_spec_boolean ("can_focus",
464 P_("Whether the widget can accept the input focus"),
467 g_object_class_install_property (gobject_class,
469 g_param_spec_boolean ("has_focus",
471 P_("Whether the widget has the input focus"),
474 g_object_class_install_property (gobject_class,
476 g_param_spec_boolean ("is_focus",
478 P_("Whether the widget is the focus widget within the toplevel"),
481 g_object_class_install_property (gobject_class,
483 g_param_spec_boolean ("can_default",
485 P_("Whether the widget can be the default widget"),
488 g_object_class_install_property (gobject_class,
490 g_param_spec_boolean ("has_default",
492 P_("Whether the widget is the default widget"),
495 g_object_class_install_property (gobject_class,
496 PROP_RECEIVES_DEFAULT,
497 g_param_spec_boolean ("receives_default",
498 P_("Receives default"),
499 P_("If TRUE, the widget will receive the default action when it is focused"),
502 g_object_class_install_property (gobject_class,
503 PROP_COMPOSITE_CHILD,
504 g_param_spec_boolean ("composite_child",
505 P_("Composite child"),
506 P_("Whether the widget is part of a composite widget"),
509 g_object_class_install_property (gobject_class,
511 g_param_spec_object ("style",
513 P_("The style of the widget, which contains information about how it will look (colors etc)"),
516 g_object_class_install_property (gobject_class,
518 g_param_spec_flags ("events",
520 P_("The event mask that decides what kind of GdkEvents this widget gets"),
524 g_object_class_install_property (gobject_class,
525 PROP_EXTENSION_EVENTS,
526 g_param_spec_enum ("extension_events",
527 P_("Extension events"),
528 P_("The mask that decides what kind of extension events this widget gets"),
529 GDK_TYPE_EXTENSION_MODE,
530 GDK_EXTENSION_EVENTS_NONE,
532 g_object_class_install_property (gobject_class,
534 g_param_spec_boolean ("no_show_all",
536 P_("Whether gtk_widget_show_all() should not affect this widget"),
539 widget_signals[SHOW] =
540 g_signal_new ("show",
541 G_TYPE_FROM_CLASS (gobject_class),
543 G_STRUCT_OFFSET (GtkWidgetClass, show),
545 _gtk_marshal_VOID__VOID,
547 widget_signals[HIDE] =
548 g_signal_new ("hide",
549 G_TYPE_FROM_CLASS (gobject_class),
551 G_STRUCT_OFFSET (GtkWidgetClass, hide),
553 _gtk_marshal_VOID__VOID,
555 widget_signals[MAP] =
557 G_TYPE_FROM_CLASS (gobject_class),
559 G_STRUCT_OFFSET (GtkWidgetClass, map),
561 _gtk_marshal_VOID__VOID,
563 widget_signals[UNMAP] =
564 g_signal_new ("unmap",
565 G_TYPE_FROM_CLASS (gobject_class),
567 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
569 _gtk_marshal_VOID__VOID,
571 widget_signals[REALIZE] =
572 g_signal_new ("realize",
573 G_TYPE_FROM_CLASS (gobject_class),
575 G_STRUCT_OFFSET (GtkWidgetClass, realize),
577 _gtk_marshal_VOID__VOID,
579 widget_signals[UNREALIZE] =
580 g_signal_new ("unrealize",
581 G_TYPE_FROM_CLASS (gobject_class),
583 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
585 _gtk_marshal_VOID__VOID,
587 widget_signals[SIZE_REQUEST] =
588 g_signal_new ("size_request",
589 G_TYPE_FROM_CLASS (gobject_class),
591 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
593 _gtk_marshal_VOID__BOXED,
595 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
596 widget_signals[SIZE_ALLOCATE] =
597 g_signal_new ("size_allocate",
598 G_TYPE_FROM_CLASS (gobject_class),
600 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
602 _gtk_marshal_VOID__BOXED,
604 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
605 widget_signals[STATE_CHANGED] =
606 g_signal_new ("state_changed",
607 G_TYPE_FROM_CLASS (gobject_class),
609 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
611 _gtk_marshal_VOID__ENUM,
613 GTK_TYPE_STATE_TYPE);
614 widget_signals[PARENT_SET] =
615 g_signal_new ("parent_set",
616 G_TYPE_FROM_CLASS (gobject_class),
618 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
620 _gtk_marshal_VOID__OBJECT,
623 widget_signals[HIERARCHY_CHANGED] =
624 g_signal_new ("hierarchy_changed",
625 G_TYPE_FROM_CLASS (gobject_class),
627 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
629 _gtk_marshal_VOID__OBJECT,
632 widget_signals[STYLE_SET] =
633 g_signal_new ("style_set",
634 G_TYPE_FROM_CLASS (gobject_class),
636 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
638 _gtk_marshal_VOID__OBJECT,
641 widget_signals[DIRECTION_CHANGED] =
642 g_signal_new ("direction_changed",
643 G_TYPE_FROM_CLASS (gobject_class),
645 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
647 _gtk_marshal_VOID__ENUM,
649 GTK_TYPE_TEXT_DIRECTION);
650 widget_signals[GRAB_NOTIFY] =
651 g_signal_new ("grab_notify",
652 G_TYPE_FROM_CLASS (gobject_class),
654 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
656 _gtk_marshal_VOID__BOOLEAN,
661 * GtkWidget::child-notify:
662 * @widget: the object which received the signal.
663 * @pspec: the #GParamSpec of the changed child property.
665 * The ::child-notify signal is emitted for each child property that has
666 * changed on an object. The signal's detail holds the property name.
668 widget_signals[CHILD_NOTIFY] =
669 g_signal_new ("child_notify",
670 G_TYPE_FROM_CLASS (gobject_class),
671 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
672 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
674 g_cclosure_marshal_VOID__PARAM,
677 widget_signals[MNEMONIC_ACTIVATE] =
678 g_signal_new ("mnemonic_activate",
679 G_TYPE_FROM_CLASS (gobject_class),
681 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
682 _gtk_boolean_handled_accumulator, NULL,
683 _gtk_marshal_BOOLEAN__BOOLEAN,
686 widget_signals[GRAB_FOCUS] =
687 g_signal_new ("grab_focus",
688 G_TYPE_FROM_CLASS (gobject_class),
689 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
690 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
692 _gtk_marshal_VOID__VOID,
694 widget_signals[FOCUS] =
695 g_signal_new ("focus",
696 G_TYPE_FROM_CLASS (object_class),
698 G_STRUCT_OFFSET (GtkWidgetClass, focus),
699 _gtk_boolean_handled_accumulator, NULL,
700 _gtk_marshal_BOOLEAN__ENUM,
702 GTK_TYPE_DIRECTION_TYPE);
703 widget_signals[EVENT] =
704 g_signal_new ("event",
705 G_TYPE_FROM_CLASS (gobject_class),
707 G_STRUCT_OFFSET (GtkWidgetClass, event),
708 _gtk_boolean_handled_accumulator, NULL,
709 _gtk_marshal_BOOLEAN__BOXED,
711 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
712 widget_signals[EVENT_AFTER] =
713 g_signal_new ("event-after",
714 G_TYPE_FROM_CLASS (gobject_class),
718 _gtk_marshal_VOID__BOXED,
720 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
721 widget_signals[BUTTON_PRESS_EVENT] =
722 g_signal_new ("button_press_event",
723 G_TYPE_FROM_CLASS (gobject_class),
725 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
726 _gtk_boolean_handled_accumulator, NULL,
727 _gtk_marshal_BOOLEAN__BOXED,
729 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
730 widget_signals[BUTTON_RELEASE_EVENT] =
731 g_signal_new ("button_release_event",
732 G_TYPE_FROM_CLASS (gobject_class),
734 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
735 _gtk_boolean_handled_accumulator, NULL,
736 _gtk_marshal_BOOLEAN__BOXED,
738 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
739 widget_signals[SCROLL_EVENT] =
740 g_signal_new ("scroll_event",
741 G_TYPE_FROM_CLASS (gobject_class),
743 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
744 _gtk_boolean_handled_accumulator, NULL,
745 _gtk_marshal_BOOLEAN__BOXED,
747 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
748 widget_signals[MOTION_NOTIFY_EVENT] =
749 g_signal_new ("motion_notify_event",
750 G_TYPE_FROM_CLASS (gobject_class),
752 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
753 _gtk_boolean_handled_accumulator, NULL,
754 _gtk_marshal_BOOLEAN__BOXED,
756 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
757 widget_signals[DELETE_EVENT] =
758 g_signal_new ("delete_event",
759 G_TYPE_FROM_CLASS (gobject_class),
761 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
762 _gtk_boolean_handled_accumulator, NULL,
763 _gtk_marshal_BOOLEAN__BOXED,
765 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
766 widget_signals[DESTROY_EVENT] =
767 g_signal_new ("destroy_event",
768 G_TYPE_FROM_CLASS (gobject_class),
770 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
771 _gtk_boolean_handled_accumulator, NULL,
772 _gtk_marshal_BOOLEAN__BOXED,
774 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
775 widget_signals[EXPOSE_EVENT] =
776 g_signal_new ("expose_event",
777 G_TYPE_FROM_CLASS (gobject_class),
779 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
780 _gtk_boolean_handled_accumulator, NULL,
781 _gtk_marshal_BOOLEAN__BOXED,
783 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
784 widget_signals[KEY_PRESS_EVENT] =
785 g_signal_new ("key_press_event",
786 G_TYPE_FROM_CLASS (gobject_class),
788 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
789 _gtk_boolean_handled_accumulator, NULL,
790 _gtk_marshal_BOOLEAN__BOXED,
792 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
793 widget_signals[KEY_RELEASE_EVENT] =
794 g_signal_new ("key_release_event",
795 G_TYPE_FROM_CLASS (gobject_class),
797 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
798 _gtk_boolean_handled_accumulator, NULL,
799 _gtk_marshal_BOOLEAN__BOXED,
801 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
802 widget_signals[ENTER_NOTIFY_EVENT] =
803 g_signal_new ("enter_notify_event",
804 G_TYPE_FROM_CLASS (gobject_class),
806 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
807 _gtk_boolean_handled_accumulator, NULL,
808 _gtk_marshal_BOOLEAN__BOXED,
810 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
811 widget_signals[LEAVE_NOTIFY_EVENT] =
812 g_signal_new ("leave_notify_event",
813 G_TYPE_FROM_CLASS (gobject_class),
815 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
816 _gtk_boolean_handled_accumulator, NULL,
817 _gtk_marshal_BOOLEAN__BOXED,
819 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
820 widget_signals[CONFIGURE_EVENT] =
821 g_signal_new ("configure_event",
822 G_TYPE_FROM_CLASS (gobject_class),
824 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
825 _gtk_boolean_handled_accumulator, NULL,
826 _gtk_marshal_BOOLEAN__BOXED,
828 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
829 widget_signals[FOCUS_IN_EVENT] =
830 g_signal_new ("focus_in_event",
831 G_TYPE_FROM_CLASS (gobject_class),
833 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
834 _gtk_boolean_handled_accumulator, NULL,
835 _gtk_marshal_BOOLEAN__BOXED,
837 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
838 widget_signals[FOCUS_OUT_EVENT] =
839 g_signal_new ("focus_out_event",
840 G_TYPE_FROM_CLASS (gobject_class),
842 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
843 _gtk_boolean_handled_accumulator, NULL,
844 _gtk_marshal_BOOLEAN__BOXED,
846 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
847 widget_signals[MAP_EVENT] =
848 g_signal_new ("map_event",
849 G_TYPE_FROM_CLASS (gobject_class),
851 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
852 _gtk_boolean_handled_accumulator, NULL,
853 _gtk_marshal_BOOLEAN__BOXED,
855 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
856 widget_signals[UNMAP_EVENT] =
857 g_signal_new ("unmap_event",
858 G_TYPE_FROM_CLASS (gobject_class),
860 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
861 _gtk_boolean_handled_accumulator, NULL,
862 _gtk_marshal_BOOLEAN__BOXED,
864 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
865 widget_signals[PROPERTY_NOTIFY_EVENT] =
866 g_signal_new ("property_notify_event",
867 G_TYPE_FROM_CLASS (gobject_class),
869 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
870 _gtk_boolean_handled_accumulator, NULL,
871 _gtk_marshal_BOOLEAN__BOXED,
873 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
874 widget_signals[SELECTION_CLEAR_EVENT] =
875 g_signal_new ("selection_clear_event",
876 G_TYPE_FROM_CLASS (gobject_class),
878 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
879 _gtk_boolean_handled_accumulator, NULL,
880 _gtk_marshal_BOOLEAN__BOXED,
882 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
883 widget_signals[SELECTION_REQUEST_EVENT] =
884 g_signal_new ("selection_request_event",
885 G_TYPE_FROM_CLASS (gobject_class),
887 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
888 _gtk_boolean_handled_accumulator, NULL,
889 _gtk_marshal_BOOLEAN__BOXED,
891 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
892 widget_signals[SELECTION_NOTIFY_EVENT] =
893 g_signal_new ("selection_notify_event",
894 G_TYPE_FROM_CLASS (gobject_class),
896 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
897 _gtk_boolean_handled_accumulator, NULL,
898 _gtk_marshal_BOOLEAN__BOXED,
900 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
901 widget_signals[SELECTION_RECEIVED] =
902 g_signal_new ("selection_received",
903 G_TYPE_FROM_CLASS (gobject_class),
905 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
907 _gtk_marshal_VOID__BOXED_UINT,
909 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
911 widget_signals[SELECTION_GET] =
912 g_signal_new ("selection_get",
913 G_TYPE_FROM_CLASS (gobject_class),
915 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
917 _gtk_marshal_VOID__BOXED_UINT_UINT,
919 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
922 widget_signals[PROXIMITY_IN_EVENT] =
923 g_signal_new ("proximity_in_event",
924 G_TYPE_FROM_CLASS (gobject_class),
926 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
927 _gtk_boolean_handled_accumulator, NULL,
928 _gtk_marshal_BOOLEAN__BOXED,
930 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
931 widget_signals[PROXIMITY_OUT_EVENT] =
932 g_signal_new ("proximity_out_event",
933 G_TYPE_FROM_CLASS (gobject_class),
935 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
936 _gtk_boolean_handled_accumulator, NULL,
937 _gtk_marshal_BOOLEAN__BOXED,
939 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
942 * GtkWidget::drag-leave:
943 * @widget: the object which received the signal.
944 * @drag_context: the drag context
945 * @time: the timestamp of the motion event
947 * The ::drag-leave signal is emitted on the drop site when the cursor leaves the widget.
948 * A typical reason to connect to this signal is to undo things done in ::drag-motion, e.g.
949 * undo highlighting with gtk_drag_unhighlight()
951 widget_signals[DRAG_LEAVE] =
952 g_signal_new ("drag_leave",
953 G_TYPE_FROM_CLASS (gobject_class),
955 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
957 _gtk_marshal_VOID__OBJECT_UINT,
959 GDK_TYPE_DRAG_CONTEXT,
963 * GtkWidget::drag-begin:
964 * @widget: the object which received the signal.
965 * @drag_context: the drag context
967 * The ::drag-begin signal is emitted on the drag source when a drag is started.
968 * A typical reason to connect to this signal is to set up a custom drag icon with
969 * gtk_drag_source_set_icon().
971 widget_signals[DRAG_BEGIN] =
972 g_signal_new ("drag_begin",
973 G_TYPE_FROM_CLASS (gobject_class),
975 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
977 _gtk_marshal_VOID__OBJECT,
979 GDK_TYPE_DRAG_CONTEXT);
982 * GtkWidget::drag-end:
983 * @widget: the object which received the signal.
984 * @drag_context: the drag context
986 * The ::drag-end signal is emitted on the drag source when a drag is finished.
987 * A typical reason to connect to this signal is to undo things done in ::drag-begin.
989 widget_signals[DRAG_END] =
990 g_signal_new ("drag_end",
991 G_TYPE_FROM_CLASS (gobject_class),
993 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
995 _gtk_marshal_VOID__OBJECT,
997 GDK_TYPE_DRAG_CONTEXT);
1000 * GtkWidget::drag-data-delete:
1001 * @widget: the object which received the signal.
1002 * @drag_context: the drag context
1004 * The ::drag-data-delete signal is emitted on the drag source when a drag with the action
1005 * %GDK_ACTION_MOVE is successfully completed. The signal handler is responsible for deleting
1006 * the data that has been dropped. What "delete" means, depends on the context of the drag
1009 widget_signals[DRAG_DATA_DELETE] =
1010 g_signal_new ("drag_data_delete",
1011 G_TYPE_FROM_CLASS (gobject_class),
1013 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
1015 _gtk_marshal_VOID__OBJECT,
1017 GDK_TYPE_DRAG_CONTEXT);
1020 * GtkWidget::drag-motion:
1021 * @widget: the object which received the signal.
1022 * @drag_context: the drag context
1023 * @x: the x coordinate of the current cursor position
1024 * @y: the y coordinate of the current cursor position
1025 * @time: the timestamp of the motion event
1026 * @returns: whether the cursor position is in a drop zone
1028 * The ::drag-motion signal is emitted on the drop site when the user moves the cursor over
1029 * the widget during a drag. The signal handler must determine whether the cursor position is in
1030 * a drop zone or not. If it is not in a drop zone, it returns %FALSE and no further processing is
1031 * necessary. Otherwise, the handler returns %TRUE. In this case, the handler is responsible for
1032 * providing the necessary information for displaying feedback to the user, by calling
1033 * gdk_drag_status(). If the decision whether the drop will be accepted or rejected can't be made
1034 * based solely on the cursor position and the type of the data, the handler may inspect the dragged
1035 * data by calling gtk_drag_get_data() and defer the gdk_drag_status() call to the ::drag-data-received
1038 * Note that there is no ::drag-enter signal. The drag receiver has to keep track of whether
1039 * he has received any ::drag-motion signals since the last ::drag-leave and if not, treat the
1040 * ::drag-motion signal as an "enter" signal. Upon an "enter", the handler will typically highlight
1041 * the drop site with gtk_drag_highlight().
1043 * <informalexample><programlisting>
1045 * drag_motion (GtkWidget *widget,
1046 * GdkDragContext *context,
1053 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1055 * if (!private_data->drag_highlight)
1057 * private_data->drag_highlight = 1;
1058 * gtk_drag_highlight (widget);
1061 * target = gtk_drag_dest_find_target (widget, context, NULL);
1062 * if (target == GDK_NONE)
1063 * gdk_drag_status (context, 0, time);
1066 * private_data->pending_status = context->suggested_action;
1067 * gtk_drag_get_data (widget, context, target, time);
1074 * drag_data_received (GtkWidget *widget,
1075 * GdkDragContext *context,
1078 * GtkSelectionData *selection_data,
1082 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1084 * if (private_data->suggested_action)
1086 * private_data->suggested_action = 0;
1088 * /<!-- -->* We are getting this data due to a request in drag_motion,
1089 * * rather than due to a request in drag_drop, so we are just
1090 * * supposed to call gdk_drag_status(<!-- -->), not actually paste in the data.
1092 * str = gtk_selection_data_get_text (selection_data);
1093 * if (!data_is_acceptable (str))
1094 * gdk_drag_status (context, 0, time);
1096 * gdk_drag_status (context, private_data->suggested_action, time);
1100 * /<!-- -->* accept the drop *<!-- -->/
1103 * </programlisting></informalexample>
1105 widget_signals[DRAG_MOTION] =
1106 g_signal_new ("drag_motion",
1107 G_TYPE_FROM_CLASS (gobject_class),
1109 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
1110 _gtk_boolean_handled_accumulator, NULL,
1111 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1113 GDK_TYPE_DRAG_CONTEXT,
1119 * GtkWidget::drag-drop:
1120 * @widget: the object which received the signal.
1121 * @drag_context: the drag context
1122 * @x: the x coordinate of the current cursor position
1123 * @y: the y coordinate of the current cursor position
1124 * @time: the timestamp of the motion event
1125 * @returns: whether the cursor position is in a drop zone
1127 * The ::drag-drop signal is emitted on the drop site when the user drops the data
1128 * onto the widget. The signal handler must determine whether the cursor position is in
1129 * a drop zone or not. If it is not in a drop zone, it returns %FALSE and no further
1130 * processing is necessary. Otherwise, the handler returns %TRUE. In this case, the handler
1131 * must ensure that gtk_drag_finish() is called to let the source know that the drop is done.
1132 * The call to gtk_drag_finish() can be done either directly or in a ::drag-data-received handler
1133 * which gets triggered by calling gtk_drop_get_data() to receive the data for one or more of the
1134 * supported targets.
1136 widget_signals[DRAG_DROP] =
1137 g_signal_new ("drag_drop",
1138 G_TYPE_FROM_CLASS (gobject_class),
1140 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
1141 _gtk_boolean_handled_accumulator, NULL,
1142 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1144 GDK_TYPE_DRAG_CONTEXT,
1150 * GtkWidget::drag-data-get:
1151 * @widget: the object which received the signal.
1152 * @drag_context: the drag context
1153 * @data: the #GtkSelectionData to be filled with the dragged data
1154 * @info: the info that has been registered with the target in the #GtkTargetList.
1155 * @time: the timestamp at which the data was requested
1157 * The ::drag-data-get signal is emitted on the drag source when the drop site requests
1158 * the data which is dragged. It is the responsibility of the signal handler to fill @data
1159 * with the data in the format which is indicated by @info. See gtk_selection_data_set() and
1160 * gtk_selection_data_set_text().
1162 widget_signals[DRAG_DATA_GET] =
1163 g_signal_new ("drag_data_get",
1164 G_TYPE_FROM_CLASS (gobject_class),
1166 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
1168 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
1170 GDK_TYPE_DRAG_CONTEXT,
1171 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1176 * GtkWidget::drag-data-received:
1177 * @widget: the object which received the signal.
1178 * @drag_context: the drag context
1179 * @x: where the drop happened
1180 * @y: where the drop happened
1181 * @data: the received data
1182 * @info: the info that has been registered with the target in the #GtkTargetList.
1183 * @time: the timestamp at which the data was received
1185 * The ::drag-data-received signal is emitted on the drop site when the dragged data has been
1186 * received. If the data was received in order to determine whether the drop will be accepted,
1187 * the handler is expected to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
1188 * If the data was received in response to a ::drag-drop signal (and this is the last target to be
1189 * received), the handler for this signal is expected to process the received data and then call
1190 * gtk_drag_finish(), setting the @success parameter depending on whether the data was processed
1193 * The handler may inspect and modify @drag_context->action before calling gtk_drag_finish(),
1194 * e.g. to implement %GDK_ACTION_ASK as shown in the following example:
1195 * <informalexample><programlisting>
1197 * drag_data_received (GtkWidget *widget,
1198 * GdkDragContext *drag_context,
1201 * GtkSelectionData *data,
1205 * if ((data->length >= 0) && (data->format == 8))
1207 * if (drag_context->action == GDK_ACTION_ASK)
1209 * GtkWidget *dialog;
1212 * dialog = gtk_message_dialog_new (NULL,
1213 * GTK_DIALOG_MODAL |
1214 * GTK_DIALOG_DESTROY_WITH_PARENT,
1216 * GTK_BUTTONS_YES_NO,
1217 * "Move the data ?\n");
1218 * response = gtk_dialog_run (GTK_DIALOG (dialog));
1219 * gtk_widget_destroy (dialog);
1221 * if (response == GTK_RESPONSE_YES)
1222 * drag_context->action = GDK_ACTION_MOVE;
1224 * drag_context->action = GDK_ACTION_COPY;
1227 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
1231 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
1233 * </programlisting></informalexample>
1235 widget_signals[DRAG_DATA_RECEIVED] =
1236 g_signal_new ("drag_data_received",
1237 G_TYPE_FROM_CLASS (gobject_class),
1239 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
1241 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
1243 GDK_TYPE_DRAG_CONTEXT,
1246 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1249 widget_signals[VISIBILITY_NOTIFY_EVENT] =
1250 g_signal_new ("visibility_notify_event",
1251 G_TYPE_FROM_CLASS (gobject_class),
1253 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
1254 _gtk_boolean_handled_accumulator, NULL,
1255 _gtk_marshal_BOOLEAN__BOXED,
1257 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1258 widget_signals[CLIENT_EVENT] =
1259 g_signal_new ("client_event",
1260 G_TYPE_FROM_CLASS (gobject_class),
1262 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
1263 _gtk_boolean_handled_accumulator, NULL,
1264 _gtk_marshal_BOOLEAN__BOXED,
1266 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1267 widget_signals[NO_EXPOSE_EVENT] =
1268 g_signal_new ("no_expose_event",
1269 G_TYPE_FROM_CLASS (gobject_class),
1271 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
1272 _gtk_boolean_handled_accumulator, NULL,
1273 _gtk_marshal_BOOLEAN__BOXED,
1275 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1276 widget_signals[WINDOW_STATE_EVENT] =
1277 g_signal_new ("window_state_event",
1278 G_TYPE_FROM_CLASS (gobject_class),
1280 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
1281 _gtk_boolean_handled_accumulator, NULL,
1282 _gtk_marshal_BOOLEAN__BOXED,
1284 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1286 * GtkWidget::popup-menu
1287 * @widget: the object which received the signal
1288 * @returns: TRUE if a menu was activated
1290 * This signal gets emitted whenever a widget should pop up a context-sensitive
1291 * menu. This usually happens through the standard key binding mechanism; by
1292 * pressing a certain key while a widget is focused, the user can cause the
1293 * widget to pop up a menu. For example, the #GtkEntry widget creates a menu
1294 * with clipboard commands. See <xref linkend="checklist-popup-menu"/> for an
1295 * example of how to use this signal.
1297 widget_signals[POPUP_MENU] =
1298 g_signal_new ("popup_menu",
1299 G_TYPE_FROM_CLASS (gobject_class),
1300 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1301 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
1302 _gtk_boolean_handled_accumulator, NULL,
1303 _gtk_marshal_BOOLEAN__VOID,
1305 widget_signals[SHOW_HELP] =
1306 g_signal_new ("show_help",
1307 G_TYPE_FROM_CLASS (gobject_class),
1308 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1309 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
1310 _gtk_boolean_handled_accumulator, NULL,
1311 _gtk_marshal_BOOLEAN__ENUM,
1313 GTK_TYPE_WIDGET_HELP_TYPE);
1314 widget_signals[ACCEL_CLOSURES_CHANGED] =
1315 g_signal_new ("accel_closures_changed",
1316 G_TYPE_FROM_CLASS (gobject_class),
1320 _gtk_marshal_NONE__NONE,
1322 widget_signals[SCREEN_CHANGED] =
1323 g_signal_new ("screen_changed",
1324 G_TYPE_FROM_CLASS (gobject_class),
1326 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
1328 _gtk_marshal_VOID__OBJECT,
1332 * GtkWidget::can-activate-accel:
1333 * @widget: the object which received the signal
1334 * @signal_id: the ID of a signal installed on @widget
1335 * @returns: %TRUE if the signal can be activated.
1337 * Determines whether an accelerator that activates the signal
1338 * identified by @signal_id can currently be activated.
1339 * This signal is present to allow applications and derived
1340 * widgets to override the default #GtkWidget handling
1341 * for determining whether an accelerator can be activated.
1343 widget_signals[CAN_ACTIVATE_ACCEL] =
1344 g_signal_new ("can_activate_accel",
1345 G_TYPE_FROM_CLASS (gobject_class),
1347 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
1348 _gtk_boolean_handled_accumulator, NULL,
1349 _gtk_marshal_BOOLEAN__UINT,
1350 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
1352 binding_set = gtk_binding_set_by_class (klass);
1353 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
1355 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
1358 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
1360 GTK_TYPE_WIDGET_HELP_TYPE,
1361 GTK_WIDGET_HELP_TOOLTIP);
1362 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
1364 GTK_TYPE_WIDGET_HELP_TYPE,
1365 GTK_WIDGET_HELP_TOOLTIP);
1366 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
1368 GTK_TYPE_WIDGET_HELP_TYPE,
1369 GTK_WIDGET_HELP_WHATS_THIS);
1370 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
1372 GTK_TYPE_WIDGET_HELP_TYPE,
1373 GTK_WIDGET_HELP_WHATS_THIS);
1375 gtk_widget_class_install_style_property (klass,
1376 g_param_spec_boolean ("interior_focus",
1377 P_("Interior Focus"),
1378 P_("Whether to draw the focus indicator inside widgets"),
1382 gtk_widget_class_install_style_property (klass,
1383 g_param_spec_int ("focus-line-width",
1384 P_("Focus linewidth"),
1385 P_("Width, in pixels, of the focus indicator line"),
1387 G_PARAM_READWRITE));
1389 gtk_widget_class_install_style_property (klass,
1390 g_param_spec_string ("focus-line-pattern",
1391 P_("Focus line dash pattern"),
1392 P_("Dash pattern used to draw the focus indicator"),
1394 G_PARAM_READWRITE));
1395 gtk_widget_class_install_style_property (klass,
1396 g_param_spec_int ("focus-padding",
1397 P_("Focus padding"),
1398 P_("Width, in pixels, between focus indicator and the widget 'box'"),
1400 G_PARAM_READWRITE));
1401 gtk_widget_class_install_style_property (klass,
1402 g_param_spec_boxed ("cursor-color",
1404 P_("Color with which to draw insertion cursor"),
1407 gtk_widget_class_install_style_property (klass,
1408 g_param_spec_boxed ("secondary-cursor-color",
1409 P_("Secondary cursor color"),
1410 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
1413 gtk_widget_class_install_style_property (klass,
1414 g_param_spec_float ("cursor-aspect-ratio",
1415 P_("Cursor line aspect ratio"),
1416 P_("Aspect ratio with which to draw insertion cursor"),
1422 gtk_widget_set_property (GObject *object,
1424 const GValue *value,
1427 GtkWidget *widget = GTK_WIDGET (object);
1431 guint32 saved_flags;
1434 gtk_widget_set_name (widget, g_value_get_string (value));
1437 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
1439 case PROP_WIDTH_REQUEST:
1440 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
1442 case PROP_HEIGHT_REQUEST:
1443 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
1446 if (g_value_get_boolean (value))
1447 gtk_widget_show (widget);
1449 gtk_widget_hide (widget);
1451 case PROP_SENSITIVE:
1452 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
1454 case PROP_APP_PAINTABLE:
1455 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
1457 case PROP_CAN_FOCUS:
1458 saved_flags = GTK_WIDGET_FLAGS (widget);
1459 if (g_value_get_boolean (value))
1460 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
1462 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
1463 if (saved_flags != GTK_WIDGET_FLAGS (widget))
1464 gtk_widget_queue_resize (widget);
1466 case PROP_HAS_FOCUS:
1467 if (g_value_get_boolean (value))
1468 gtk_widget_grab_focus (widget);
1471 if (g_value_get_boolean (value))
1472 gtk_widget_grab_focus (widget);
1474 case PROP_CAN_DEFAULT:
1475 saved_flags = GTK_WIDGET_FLAGS (widget);
1476 if (g_value_get_boolean (value))
1477 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
1479 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT);
1480 if (saved_flags != GTK_WIDGET_FLAGS (widget))
1481 gtk_widget_queue_resize (widget);
1483 case PROP_HAS_DEFAULT:
1484 if (g_value_get_boolean (value))
1485 gtk_widget_grab_default (widget);
1487 case PROP_RECEIVES_DEFAULT:
1488 if (g_value_get_boolean (value))
1489 GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1491 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1494 gtk_widget_set_style (widget, g_value_get_object (value));
1497 if (!GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget))
1498 gtk_widget_set_events (widget, g_value_get_flags (value));
1500 case PROP_EXTENSION_EVENTS:
1501 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
1503 case PROP_NO_SHOW_ALL:
1504 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
1512 gtk_widget_get_property (GObject *object,
1517 GtkWidget *widget = GTK_WIDGET (object);
1522 GdkExtensionMode *modep;
1526 g_value_set_string (value, widget->name);
1528 g_value_set_string (value, "");
1532 g_value_set_object (value, widget->parent);
1534 g_value_set_object (value, NULL);
1536 case PROP_WIDTH_REQUEST:
1539 gtk_widget_get_size_request (widget, &w, NULL);
1540 g_value_set_int (value, w);
1543 case PROP_HEIGHT_REQUEST:
1546 gtk_widget_get_size_request (widget, NULL, &h);
1547 g_value_set_int (value, h);
1551 g_value_set_boolean (value, (GTK_WIDGET_VISIBLE (widget) != FALSE));
1553 case PROP_SENSITIVE:
1554 g_value_set_boolean (value, (GTK_WIDGET_SENSITIVE (widget) != FALSE));
1556 case PROP_APP_PAINTABLE:
1557 g_value_set_boolean (value, (GTK_WIDGET_APP_PAINTABLE (widget) != FALSE));
1559 case PROP_CAN_FOCUS:
1560 g_value_set_boolean (value, (GTK_WIDGET_CAN_FOCUS (widget) != FALSE));
1562 case PROP_HAS_FOCUS:
1563 g_value_set_boolean (value, (GTK_WIDGET_HAS_FOCUS (widget) != FALSE));
1566 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
1568 case PROP_CAN_DEFAULT:
1569 g_value_set_boolean (value, (GTK_WIDGET_CAN_DEFAULT (widget) != FALSE));
1571 case PROP_HAS_DEFAULT:
1572 g_value_set_boolean (value, (GTK_WIDGET_HAS_DEFAULT (widget) != FALSE));
1574 case PROP_RECEIVES_DEFAULT:
1575 g_value_set_boolean (value, (GTK_WIDGET_RECEIVES_DEFAULT (widget) != FALSE));
1577 case PROP_COMPOSITE_CHILD:
1578 g_value_set_boolean (value, (GTK_WIDGET_COMPOSITE_CHILD (widget) != FALSE));
1581 g_value_set_object (value, gtk_widget_get_style (widget));
1584 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
1586 g_value_set_flags (value, 0);
1588 g_value_set_flags (value, *eventp);
1590 case PROP_EXTENSION_EVENTS:
1591 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
1593 g_value_set_enum (value, 0);
1595 g_value_set_enum (value, (GdkExtensionMode) *modep);
1597 case PROP_NO_SHOW_ALL:
1598 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
1601 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1607 gtk_widget_init (GtkWidget *widget)
1609 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
1610 widget->state = GTK_STATE_NORMAL;
1611 widget->saved_state = GTK_STATE_NORMAL;
1612 widget->name = NULL;
1613 widget->requisition.width = 0;
1614 widget->requisition.height = 0;
1615 widget->allocation.x = -1;
1616 widget->allocation.y = -1;
1617 widget->allocation.width = 1;
1618 widget->allocation.height = 1;
1619 widget->window = NULL;
1620 widget->parent = NULL;
1622 GTK_WIDGET_SET_FLAGS (widget,
1624 GTK_PARENT_SENSITIVE |
1625 (composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
1626 GTK_DOUBLE_BUFFERED);
1628 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
1629 GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
1630 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
1632 widget->style = gtk_widget_get_default_style ();
1633 g_object_ref (widget->style);
1638 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
1640 GParamSpec **pspecs)
1642 GtkWidget *container = widget->parent;
1645 for (i = 0; widget->parent == container && i < n_pspecs; i++)
1646 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
1650 * gtk_widget_freeze_child_notify:
1651 * @widget: a #GtkWidget
1653 * Stops emission of "child-notify" signals on @widget. The signals are
1654 * queued until gtk_widget_thaw_child_notify() is called on @widget.
1656 * This is the analogue of g_object_freeze_notify() for child properties.
1659 gtk_widget_freeze_child_notify (GtkWidget *widget)
1661 g_return_if_fail (GTK_IS_WIDGET (widget));
1663 if (!G_OBJECT (widget)->ref_count)
1666 g_object_ref (widget);
1667 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1668 g_object_unref (widget);
1672 * gtk_widget_child_notify:
1673 * @widget: a #GtkWidget
1674 * @child_property: the name of a child property installed on the
1675 * class of @widget<!-- -->'s parent.
1677 * Emits a "child-notify" signal for the
1678 * <link linkend="child-properties">child property</link> @child_property
1681 * This is the analogue of g_object_notify() for child properties.
1684 gtk_widget_child_notify (GtkWidget *widget,
1685 const gchar *child_property)
1689 g_return_if_fail (GTK_IS_WIDGET (widget));
1690 g_return_if_fail (child_property != NULL);
1691 if (!G_OBJECT (widget)->ref_count || !widget->parent)
1694 g_object_ref (widget);
1695 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
1697 G_OBJECT_TYPE (widget->parent),
1700 g_warning ("%s: container class `%s' has no child property named `%s'",
1702 G_OBJECT_TYPE_NAME (widget->parent),
1706 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1708 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
1709 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1711 g_object_unref (widget);
1715 * gtk_widget_thaw_child_notify:
1716 * @widget: a #GtkWidget
1718 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
1719 * This causes all queued "child-notify" signals on @widget to be emitted.
1722 gtk_widget_thaw_child_notify (GtkWidget *widget)
1724 GObjectNotifyQueue *nqueue;
1726 g_return_if_fail (GTK_IS_WIDGET (widget));
1728 if (!G_OBJECT (widget)->ref_count)
1731 g_object_ref (widget);
1732 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1733 if (!nqueue || !nqueue->freeze_count)
1734 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
1735 G_OBJECT_TYPE_NAME (widget), widget);
1737 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1738 g_object_unref (widget);
1744 * @type: type ID of the widget to create
1745 * @first_property_name: name of first property to set
1746 * @Varargs: value of first property, followed by more properties, %NULL-terminated
1748 * This is a convenience function for creating a widget and setting
1749 * its properties in one go. For example you might write:
1750 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
1751 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
1752 * g_object_new(), but returns a widget so you don't have to
1753 * cast the object yourself.
1755 * Return value: a new #GtkWidget of type @widget_type
1758 gtk_widget_new (GType type,
1759 const gchar *first_property_name,
1765 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
1767 va_start (var_args, first_property_name);
1768 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
1776 * @widget: a #GtkWidget
1777 * @first_property_name: name of first property to set
1778 * @Varargs: value of first property, followed by more properties, %NULL-terminated
1780 * Like g_object_set() - there's no reason to use this instead of
1784 gtk_widget_set (GtkWidget *widget,
1785 const gchar *first_property_name,
1790 g_return_if_fail (GTK_IS_WIDGET (widget));
1792 va_start (var_args, first_property_name);
1793 g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
1798 gtk_widget_queue_draw_child (GtkWidget *widget)
1802 parent = widget->parent;
1803 if (parent && GTK_WIDGET_DRAWABLE (parent))
1804 gtk_widget_queue_draw_area (parent,
1805 widget->allocation.x,
1806 widget->allocation.y,
1807 widget->allocation.width,
1808 widget->allocation.height);
1812 * gtk_widget_unparent:
1813 * @widget: a #GtkWidget
1815 * This function is only for use in widget implementations.
1816 * Should be called by implementations of the remove method
1817 * on #GtkContainer, to dissociate a child from the container.
1820 gtk_widget_unparent (GtkWidget *widget)
1822 GObjectNotifyQueue *nqueue;
1823 GtkWidget *toplevel;
1824 GtkWidget *old_parent;
1826 g_return_if_fail (GTK_IS_WIDGET (widget));
1827 if (widget->parent == NULL)
1830 /* keep this function in sync with gtk_menu_detach()
1833 g_object_freeze_notify (G_OBJECT (widget));
1834 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1836 toplevel = gtk_widget_get_toplevel (widget);
1837 if (GTK_WIDGET_TOPLEVEL (toplevel))
1838 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
1840 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
1841 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
1843 /* If we are unanchoring the child, we save around the toplevel
1844 * to emit hierarchy changed
1846 if (GTK_WIDGET_ANCHORED (widget->parent))
1847 g_object_ref (toplevel);
1851 gtk_widget_queue_draw_child (widget);
1853 /* Reset the width and height here, to force reallocation if we
1854 * get added back to a new parent. This won't work if our new
1855 * allocation is smaller than 1x1 and we actually want a size of 1x1...
1856 * (would 0x0 be OK here?)
1858 widget->allocation.width = 1;
1859 widget->allocation.height = 1;
1861 if (GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_IN_REPARENT (widget))
1862 gtk_widget_unrealize (widget);
1864 /* Removing a widget from a container restores the child visible
1865 * flag to the default state, so it doesn't affect the child
1866 * in the next parent.
1868 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
1870 old_parent = widget->parent;
1871 widget->parent = NULL;
1872 gtk_widget_set_parent_window (widget, NULL);
1873 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
1876 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
1877 g_object_unref (toplevel);
1880 g_object_notify (G_OBJECT (widget), "parent");
1881 g_object_thaw_notify (G_OBJECT (widget));
1882 if (!widget->parent)
1883 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
1884 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1885 g_object_unref (widget);
1889 * gtk_widget_destroy:
1890 * @widget: a #GtkWidget
1892 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
1893 * you don't have to cast the widget to #GtkObject. When a widget is
1894 * destroyed, it will break any references it holds to other objects.
1895 * If the widget is inside a container, the widget will be removed
1896 * from the container. If the widget is a toplevel (derived from
1897 * #GtkWindow), it will be removed from the list of toplevels, and the
1898 * reference GTK+ holds to it will be removed. Removing a
1899 * widget from its container or the list of toplevels results in the
1900 * widget being finalized, unless you've added additional references
1901 * to the widget with g_object_ref().
1903 * In most cases, only toplevel widgets (windows) require explicit
1904 * destruction, because when you destroy a toplevel its children will
1905 * be destroyed as well.
1909 gtk_widget_destroy (GtkWidget *widget)
1911 g_return_if_fail (GTK_IS_WIDGET (widget));
1913 gtk_object_destroy ((GtkObject*) widget);
1917 * gtk_widget_destroyed:
1918 * @widget: a #GtkWidget
1919 * @widget_pointer: address of a variable that contains @widget
1921 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
1922 * %NULL. It's intended to be used as a callback connected to the
1923 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
1924 * as a signal handler, and pass the address of your widget variable
1925 * as user data. Then when the widget is destroyed, the variable will
1926 * be set to %NULL. Useful for example to avoid multiple copies
1927 * of the same dialog.
1931 gtk_widget_destroyed (GtkWidget *widget,
1932 GtkWidget **widget_pointer)
1934 /* Don't make any assumptions about the
1936 * Even check widget_pointer.
1939 *widget_pointer = NULL;
1944 * @widget: a #GtkWidget
1946 * Flags a widget to be displayed. Any widget that isn't shown will
1947 * not appear on the screen. If you want to show all the widgets in a
1948 * container, it's easier to call gtk_widget_show_all() on the
1949 * container, instead of individually showing the widgets.
1951 * Remember that you have to show the containers containing a widget,
1952 * in addition to the widget itself, before it will appear onscreen.
1954 * When a toplevel container is shown, it is immediately realized and
1955 * mapped; other shown widgets are realized and mapped when their
1956 * toplevel container is realized and mapped.
1960 gtk_widget_show (GtkWidget *widget)
1962 if (!GTK_WIDGET_VISIBLE (widget))
1964 g_object_ref (widget);
1965 if (!GTK_WIDGET_TOPLEVEL (widget))
1966 gtk_widget_queue_resize (widget);
1967 g_signal_emit (widget, widget_signals[SHOW], 0);
1968 g_object_notify (G_OBJECT (widget), "visible");
1969 g_object_unref (widget);
1974 gtk_widget_real_show (GtkWidget *widget)
1976 if (!GTK_WIDGET_VISIBLE (widget))
1978 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
1980 if (widget->parent &&
1981 GTK_WIDGET_MAPPED (widget->parent) &&
1982 GTK_WIDGET_CHILD_VISIBLE (widget) &&
1983 !GTK_WIDGET_MAPPED (widget))
1984 gtk_widget_map (widget);
1989 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
1992 g_signal_handlers_disconnect_by_func (widget,
1993 gtk_widget_show_map_callback,
1998 * gtk_widget_show_now:
1999 * @widget: a #GtkWidget
2001 * Shows a widget. If the widget is an unmapped toplevel widget
2002 * (i.e. a #GtkWindow that has not yet been shown), enter the main
2003 * loop and wait for the window to actually be mapped. Be careful;
2004 * because the main loop is running, anything can happen during
2008 gtk_widget_show_now (GtkWidget *widget)
2012 g_return_if_fail (GTK_IS_WIDGET (widget));
2014 /* make sure we will get event */
2015 if (!GTK_WIDGET_MAPPED (widget) &&
2016 GTK_WIDGET_TOPLEVEL (widget))
2018 gtk_widget_show (widget);
2020 g_signal_connect (widget, "map_event",
2021 G_CALLBACK (gtk_widget_show_map_callback),
2025 gtk_main_iteration ();
2028 gtk_widget_show (widget);
2033 * @widget: a #GtkWidget
2035 * Reverses the effects of gtk_widget_show(), causing the widget to be
2036 * hidden (invisible to the user).
2039 gtk_widget_hide (GtkWidget *widget)
2041 g_return_if_fail (GTK_IS_WIDGET (widget));
2043 if (GTK_WIDGET_VISIBLE (widget))
2045 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
2047 g_object_ref (widget);
2048 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
2049 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
2051 g_signal_emit (widget, widget_signals[HIDE], 0);
2052 if (!GTK_WIDGET_TOPLEVEL (widget))
2053 gtk_widget_queue_resize (widget);
2054 g_object_notify (G_OBJECT (widget), "visible");
2055 g_object_unref (widget);
2060 gtk_widget_real_hide (GtkWidget *widget)
2062 if (GTK_WIDGET_VISIBLE (widget))
2064 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
2066 if (GTK_WIDGET_MAPPED (widget))
2067 gtk_widget_unmap (widget);
2072 * gtk_widget_hide_on_delete:
2073 * @widget: a #GtkWidget
2075 * Utility function; intended to be connected to the "delete_event"
2076 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
2077 * argument, then returns %TRUE. If connected to "delete_event", the
2078 * result is that clicking the close button for a window (on the
2079 * window frame, top right corner usually) will hide but not destroy
2080 * the window. By default, GTK+ destroys windows when "delete_event"
2083 * Return value: %TRUE
2086 gtk_widget_hide_on_delete (GtkWidget *widget)
2088 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2090 gtk_widget_hide (widget);
2096 * gtk_widget_show_all:
2097 * @widget: a #GtkWidget
2099 * Recursively shows a widget, and any child widgets (if the widget is
2103 gtk_widget_show_all (GtkWidget *widget)
2105 GtkWidgetClass *class;
2107 g_return_if_fail (GTK_IS_WIDGET (widget));
2109 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
2112 class = GTK_WIDGET_GET_CLASS (widget);
2114 if (class->show_all)
2115 class->show_all (widget);
2119 * gtk_widget_hide_all:
2120 * @widget: a #GtkWidget
2122 * Recursively hides a widget and any child widgets.
2125 gtk_widget_hide_all (GtkWidget *widget)
2127 GtkWidgetClass *class;
2129 g_return_if_fail (GTK_IS_WIDGET (widget));
2131 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
2134 class = GTK_WIDGET_GET_CLASS (widget);
2136 if (class->hide_all)
2137 class->hide_all (widget);
2142 * @widget: a #GtkWidget
2144 * This function is only for use in widget implementations. Causes
2145 * a widget to be mapped if it isn't already.
2149 gtk_widget_map (GtkWidget *widget)
2151 g_return_if_fail (GTK_IS_WIDGET (widget));
2152 g_return_if_fail (GTK_WIDGET_VISIBLE (widget));
2153 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
2155 if (!GTK_WIDGET_MAPPED (widget))
2157 if (!GTK_WIDGET_REALIZED (widget))
2158 gtk_widget_realize (widget);
2160 g_signal_emit (widget, widget_signals[MAP], 0);
2162 if (GTK_WIDGET_NO_WINDOW (widget))
2163 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
2169 * @widget: a #GtkWidget
2171 * This function is only for use in widget implementations. Causes
2172 * a widget to be unmapped if it's currently mapped.
2176 gtk_widget_unmap (GtkWidget *widget)
2178 g_return_if_fail (GTK_IS_WIDGET (widget));
2180 if (GTK_WIDGET_MAPPED (widget))
2182 if (GTK_WIDGET_NO_WINDOW (widget))
2183 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
2184 g_signal_emit (widget, widget_signals[UNMAP], 0);
2189 * gtk_widget_realize:
2190 * @widget: a #GtkWidget
2192 * Creates the GDK (windowing system) resources associated with a
2193 * widget. For example, @widget->window will be created when a widget
2194 * is realized. Normally realization happens implicitly; if you show
2195 * a widget and all its parent containers, then the widget will be
2196 * realized and mapped automatically.
2198 * Realizing a widget requires all
2199 * the widget's parent widgets to be realized; calling
2200 * gtk_widget_realize() realizes the widget's parents in addition to
2201 * @widget itself. If a widget is not yet inside a toplevel window
2202 * when you realize it, bad things will happen.
2204 * This function is primarily used in widget implementations, and
2205 * isn't very useful otherwise. Many times when you think you might
2206 * need it, a better approach is to connect to a signal that will be
2207 * called after the widget is realized automatically, such as
2208 * "expose_event". Or simply g_signal_connect_after() to the
2213 gtk_widget_realize (GtkWidget *widget)
2216 GdkExtensionMode mode;
2217 GtkWidgetShapeInfo *shape_info;
2219 g_return_if_fail (GTK_IS_WIDGET (widget));
2220 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
2221 GTK_IS_INVISIBLE (widget));
2223 if (!GTK_WIDGET_REALIZED (widget))
2226 if (GTK_IS_CONTAINER (widget) && !GTK_WIDGET_NO_WINDOW (widget))
2227 g_message ("gtk_widget_realize(%s)", g_type_name (GTK_WIDGET_TYPE (widget)));
2230 if (widget->parent == NULL &&
2231 !GTK_WIDGET_TOPLEVEL (widget))
2232 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
2233 "inside a toplevel window is not going to work very well. "
2234 "Widgets must be inside a toplevel container before realizing them.");
2236 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
2237 gtk_widget_realize (widget->parent);
2239 gtk_widget_ensure_style (widget);
2241 g_signal_emit (widget, widget_signals[REALIZE], 0);
2243 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
2245 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
2246 gdk_window_shape_combine_mask (widget->window,
2247 shape_info->shape_mask,
2248 shape_info->offset_x,
2249 shape_info->offset_y);
2252 if (!GTK_WIDGET_NO_WINDOW (widget))
2254 mode = gtk_widget_get_extension_events (widget);
2255 if (mode != GDK_EXTENSION_EVENTS_NONE)
2257 events = gtk_widget_get_events (widget);
2258 gdk_input_set_extension_events (widget->window, events, mode);
2266 * gtk_widget_unrealize:
2267 * @widget: a #GtkWidget
2269 * This function is only useful in widget implementations.
2270 * Causes a widget to be unrealized (frees all GDK resources
2271 * associated with the widget, such as @widget->window).
2275 gtk_widget_unrealize (GtkWidget *widget)
2277 g_return_if_fail (GTK_IS_WIDGET (widget));
2279 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
2280 gtk_widget_shape_combine_mask (widget, NULL, -1, -1);
2282 if (GTK_WIDGET_REALIZED (widget))
2284 g_object_ref (widget);
2285 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
2286 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
2287 g_object_unref (widget);
2291 /*****************************************
2293 *****************************************/
2296 * gtk_widget_queue_draw_area:
2297 * @widget: a #GtkWidget
2298 * @x: x coordinate of upper-left corner of rectangle to redraw
2299 * @y: y coordinate of upper-left corner of rectangle to redraw
2300 * @width: width of region to draw
2301 * @height: height of region to draw
2303 * Invalidates the rectangular area of @widget defined by @x, @y,
2304 * @width and @height by calling gdk_window_invalidate_rect() on the
2305 * widget's window and all its child windows. Once the main loop
2306 * becomes idle (after the current batch of events has been processed,
2307 * roughly), the window will receive expose events for the union of
2308 * all regions that have been invalidated.
2310 * Normally you would only use this function in widget
2311 * implementations. You might also use it, or
2312 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
2313 * #GtkDrawingArea or some portion thereof.
2315 * Frequently you can just call gdk_window_invalidate_rect() or
2316 * gdk_window_invalidate_region() instead of this function. Those
2317 * functions will invalidate only a single window, instead of the
2318 * widget and all its children.
2320 * The advantage of adding to the invalidated region compared to
2321 * simply drawing immediately is efficiency; using an invalid region
2322 * ensures that you only have to redraw one time.
2326 gtk_widget_queue_draw_area (GtkWidget *widget,
2332 GdkRectangle invalid_rect;
2335 g_return_if_fail (GTK_IS_WIDGET (widget));
2337 if (!GTK_WIDGET_REALIZED (widget))
2340 /* Just return if the widget or one of its ancestors isn't mapped */
2341 for (w = widget; w != NULL; w = w->parent)
2342 if (!GTK_WIDGET_MAPPED (w))
2345 /* Find the correct widget */
2347 if (!GTK_WIDGET_NO_WINDOW (widget))
2351 /* Translate widget relative to window-relative */
2353 gint wx, wy, wwidth, wheight;
2355 gdk_window_get_position (widget->window, &wx, &wy);
2356 x -= wx - widget->allocation.x;
2357 y -= wy - widget->allocation.y;
2359 gdk_drawable_get_size (widget->window, &wwidth, &wheight);
2361 if (x + width <= 0 || y + height <= 0 ||
2362 x >= wwidth || y >= wheight)
2373 if (x + width > wwidth)
2375 if (y + height > wheight)
2376 height = wheight - y;
2382 invalid_rect.width = width;
2383 invalid_rect.height = height;
2385 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
2389 * gtk_widget_queue_draw:
2390 * @widget: a #GtkWidget
2392 * Equivalent to calling gtk_widget_queue_draw_area() for the
2393 * entire area of a widget.
2397 gtk_widget_queue_draw (GtkWidget *widget)
2399 g_return_if_fail (GTK_IS_WIDGET (widget));
2401 if (widget->allocation.width || widget->allocation.height)
2403 if (GTK_WIDGET_NO_WINDOW (widget))
2404 gtk_widget_queue_draw_area (widget, widget->allocation.x,
2405 widget->allocation.y,
2406 widget->allocation.width,
2407 widget->allocation.height);
2409 gtk_widget_queue_draw_area (widget, 0, 0,
2410 widget->allocation.width,
2411 widget->allocation.height);
2415 /* Invalidates the given area (allocation-relative-coordinates)
2416 * in all of the widget's windows
2419 * gtk_widget_queue_clear_area:
2420 * @widget: a #GtkWidget
2421 * @x: x coordinate of upper-left corner of rectangle to redraw
2422 * @y: y coordinate of upper-left corner of rectangle to redraw
2423 * @width: width of region to draw
2424 * @height: height of region to draw
2426 * This function is no longer different from
2427 * gtk_widget_queue_draw_area(), though it once was. Now it just calls
2428 * gtk_widget_queue_draw_area(). Originally
2429 * gtk_widget_queue_clear_area() would force a redraw of the
2430 * background for %GTK_NO_WINDOW widgets, and
2431 * gtk_widget_queue_draw_area() would not. Now both functions ensure
2432 * the background will be redrawn.
2434 * @Deprecated: Use gtk_widget_queue_draw_area() instead.
2437 gtk_widget_queue_clear_area (GtkWidget *widget,
2443 g_return_if_fail (GTK_IS_WIDGET (widget));
2445 gtk_widget_queue_draw_area (widget, x, y, width, height);
2449 * gtk_widget_queue_clear:
2450 * @widget: a #GtkWidget
2452 * This function does the same as gtk_widget_queue_draw().
2454 * @Deprecated: Use gtk_widget_queue_draw() instead.
2457 gtk_widget_queue_clear (GtkWidget *widget)
2459 g_return_if_fail (GTK_IS_WIDGET (widget));
2461 gtk_widget_queue_draw (widget);
2465 * gtk_widget_queue_resize:
2466 * @widget: a #GtkWidget
2468 * This function is only for use in widget implementations.
2469 * Flags a widget to have its size renegotiated; should
2470 * be called when a widget for some reason has a new size request.
2471 * For example, when you change the text in a #GtkLabel, #GtkLabel
2472 * queues a resize to ensure there's enough space for the new text.
2475 gtk_widget_queue_resize (GtkWidget *widget)
2477 g_return_if_fail (GTK_IS_WIDGET (widget));
2479 if (GTK_WIDGET_REALIZED (widget))
2480 gtk_widget_queue_shallow_draw (widget);
2482 _gtk_size_group_queue_resize (widget);
2486 * gtk_widget_queue_resize_no_redraw:
2487 * @widget: a #GtkWidget
2489 * This function works like gtk_widget_queue_resize(), except that the
2490 * widget is not invalidated.
2495 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
2497 g_return_if_fail (GTK_IS_WIDGET (widget));
2499 _gtk_size_group_queue_resize (widget);
2504 * @widget: a #GtkWidget
2505 * @area: area to draw
2507 * In GTK+ 1.2, this function would immediately render the
2508 * region @area of a widget, by invoking the virtual draw method of a
2509 * widget. In GTK+ 2.0, the draw method is gone, and instead
2510 * gtk_widget_draw() simply invalidates the specified region of the
2511 * widget, then updates the invalid region of the widget immediately.
2512 * Usually you don't want to update the region immediately for
2513 * performance reasons, so in general gtk_widget_queue_draw_area() is
2514 * a better choice if you want to draw a region of a widget.
2518 gtk_widget_draw (GtkWidget *widget,
2521 g_return_if_fail (GTK_IS_WIDGET (widget));
2523 if (GTK_WIDGET_DRAWABLE (widget))
2526 gtk_widget_queue_draw_area (widget,
2528 area->width, area->height);
2530 gtk_widget_queue_draw (widget);
2532 gdk_window_process_updates (widget->window, TRUE);
2537 * gtk_widget_size_request:
2538 * @widget: a #GtkWidget
2539 * @requisition: a #GtkRequisition to be filled in
2541 * This function is typically used when implementing a #GtkContainer
2542 * subclass. Obtains the preferred size of a widget. The container
2543 * uses this information to arrange its child widgets and decide what
2544 * size allocations to give them with gtk_widget_size_allocate().
2546 * You can also call this function from an application, with some
2547 * caveats. Most notably, getting a size request requires the widget
2548 * to be associated with a screen, because font information may be
2549 * needed. Multihead-aware applications should keep this in mind.
2551 * Also remember that the size request is not necessarily the size
2552 * a widget will actually be allocated.
2554 * See also gtk_widget_get_child_requisition().
2557 gtk_widget_size_request (GtkWidget *widget,
2558 GtkRequisition *requisition)
2560 g_return_if_fail (GTK_IS_WIDGET (widget));
2562 #ifdef G_ENABLE_DEBUG
2563 if (requisition == &widget->requisition)
2564 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.");
2565 #endif /* G_ENABLE_DEBUG */
2567 _gtk_size_group_compute_requisition (widget, requisition);
2571 * gtk_widget_get_child_requisition:
2572 * @widget: a #GtkWidget
2573 * @requisition: a #GtkRequisition to be filled in
2575 * This function is only for use in widget implementations. Obtains
2576 * @widget->requisition, unless someone has forced a particular
2577 * geometry on the widget (e.g. with gtk_widget_set_usize()), in which
2578 * case it returns that geometry instead of the widget's requisition.
2580 * This function differs from gtk_widget_size_request() in that
2581 * it retrieves the last size request value from @widget->requisition,
2582 * while gtk_widget_size_request() actually calls the "size_request" method
2583 * on @widget to compute the size request and fill in @widget->requisition,
2584 * and only then returns @widget->requisition.
2586 * Because this function does not call the "size_request" method, it
2587 * can only be used when you know that @widget->requisition is
2588 * up-to-date, that is, gtk_widget_size_request() has been called
2589 * since the last time a resize was queued. In general, only container
2590 * implementations have this information; applications should use
2591 * gtk_widget_size_request().
2594 gtk_widget_get_child_requisition (GtkWidget *widget,
2595 GtkRequisition *requisition)
2597 _gtk_size_group_get_child_requisition (widget, requisition);
2601 invalidate_predicate (GdkWindow *window,
2606 gdk_window_get_user_data (window, &user_data);
2608 return (user_data == data);
2611 /* Invalidate @region in widget->window and all children
2612 * of widget->window owned by widget. @region is in the
2613 * same coordinates as widget->allocation and will be
2614 * modified by this call.
2617 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
2620 if (!GTK_WIDGET_REALIZED (widget))
2623 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
2627 gdk_window_get_position (widget->window, &x, &y);
2628 gdk_region_offset (region, -x, -y);
2631 gdk_window_invalidate_maybe_recurse (widget->window, region,
2632 invalidate_predicate, widget);
2636 * gtk_widget_queue_shallow_draw:
2637 * @widget: a #GtkWidget
2639 * Like gtk_widget_queue_draw(), but only windows owned
2640 * by @widget are invalidated.
2643 gtk_widget_queue_shallow_draw (GtkWidget *widget)
2647 g_return_if_fail (GTK_IS_WIDGET (widget));
2649 region = gdk_region_rectangle (&widget->allocation);
2650 gtk_widget_invalidate_widget_windows (widget, region);
2651 gdk_region_destroy (region);
2655 * gtk_widget_size_allocate:
2656 * @widget: a #GtkWidget
2657 * @allocation: position and size to be allocated to @widget
2659 * This function is only used by #GtkContainer subclasses, to assign a size
2660 * and position to their child widgets.
2664 gtk_widget_size_allocate (GtkWidget *widget,
2665 GtkAllocation *allocation)
2667 GtkWidgetAuxInfo *aux_info;
2668 GdkRectangle real_allocation;
2669 GdkRectangle old_allocation;
2670 gboolean alloc_needed;
2671 gboolean size_changed;
2672 gboolean position_changed;
2674 g_return_if_fail (GTK_IS_WIDGET (widget));
2676 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
2677 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
2679 old_allocation = widget->allocation;
2680 real_allocation = *allocation;
2681 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
2685 if (aux_info->x_set)
2686 real_allocation.x = aux_info->x;
2687 if (aux_info->y_set)
2688 real_allocation.y = aux_info->y;
2691 if (real_allocation.width < 0 || real_allocation.height < 0)
2693 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
2694 real_allocation.width,
2695 real_allocation.height);
2698 real_allocation.width = MAX (real_allocation.width, 1);
2699 real_allocation.height = MAX (real_allocation.height, 1);
2701 size_changed = (old_allocation.width != real_allocation.width ||
2702 old_allocation.height != real_allocation.height);
2703 position_changed = (old_allocation.x != real_allocation.x ||
2704 old_allocation.y != real_allocation.y);
2706 if (!alloc_needed && !size_changed && !position_changed)
2709 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
2711 if (GTK_WIDGET_MAPPED (widget))
2713 if (GTK_WIDGET_NO_WINDOW (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
2715 /* Invalidate union(old_allaction,widget->allocation) in widget->window
2717 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
2718 gdk_region_union_with_rect (invalidate, &old_allocation);
2720 gdk_window_invalidate_region (widget->window, invalidate, FALSE);
2721 gdk_region_destroy (invalidate);
2726 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
2728 /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
2730 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
2731 gdk_region_union_with_rect (invalidate, &old_allocation);
2733 gtk_widget_invalidate_widget_windows (widget, invalidate);
2734 gdk_region_destroy (invalidate);
2739 if ((size_changed || position_changed) && widget->parent &&
2740 GTK_WIDGET_REALIZED (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
2742 GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
2743 gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
2744 gdk_region_destroy (invalidate);
2749 * gtk_widget_common_ancestor:
2750 * @widget_a: a #GtkWidget
2751 * @widget_b: a #GtkWidget
2753 * Find the common ancestor of @widget_a and @widget_b that
2754 * is closest to the two widgets.
2756 * Return value: the closest common ancestor of @widget_a and
2757 * @widget_b or %NULL if @widget_a and @widget_b do not
2758 * share a common ancestor.
2761 gtk_widget_common_ancestor (GtkWidget *widget_a,
2762 GtkWidget *widget_b)
2764 GtkWidget *parent_a;
2765 GtkWidget *parent_b;
2769 parent_a = widget_a;
2770 while (parent_a->parent)
2772 parent_a = parent_a->parent;
2776 parent_b = widget_b;
2777 while (parent_b->parent)
2779 parent_b = parent_b->parent;
2783 if (parent_a != parent_b)
2786 while (depth_a > depth_b)
2788 widget_a = widget_a->parent;
2792 while (depth_b > depth_a)
2794 widget_b = widget_b->parent;
2798 while (widget_a != widget_b)
2800 widget_a = widget_a->parent;
2801 widget_b = widget_b->parent;
2808 * gtk_widget_translate_coordinates:
2809 * @src_widget: a #GtkWidget
2810 * @dest_widget: a #GtkWidget
2811 * @src_x: X position relative to @src_widget
2812 * @src_y: Y position relative to @src_widget
2813 * @dest_x: location to store X position relative to @dest_widget
2814 * @dest_y: location to store Y position relative to @dest_widget
2816 * Translate coordinates relative to @src_widget's allocation to coordinates
2817 * relative to @dest_widget's allocations. In order to perform this
2818 * operation, both widgets must be realized, and must share a common
2821 * Return value: %FALSE if either widget was not realized, or there
2822 * was no common ancestor. In this case, nothing is stored in
2823 * *@dest_x and *@dest_y. Otherwise %TRUE.
2826 gtk_widget_translate_coordinates (GtkWidget *src_widget,
2827 GtkWidget *dest_widget,
2833 GtkWidget *ancestor;
2836 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
2837 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
2839 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
2840 if (!ancestor || !GTK_WIDGET_REALIZED (src_widget) || !GTK_WIDGET_REALIZED (dest_widget))
2843 /* Translate from allocation relative to window relative */
2844 if (!GTK_WIDGET_NO_WINDOW (src_widget) && src_widget->parent)
2847 gdk_window_get_position (src_widget->window, &wx, &wy);
2849 src_x -= wx - src_widget->allocation.x;
2850 src_y -= wy - src_widget->allocation.y;
2854 src_x += src_widget->allocation.x;
2855 src_y += src_widget->allocation.y;
2858 /* Translate to the common ancestor */
2859 window = src_widget->window;
2860 while (window != ancestor->window)
2864 gdk_window_get_position (window, &dx, &dy);
2869 window = gdk_window_get_parent (window);
2871 if (!window) /* Handle GtkHandleBox */
2876 window = dest_widget->window;
2877 while (window != ancestor->window)
2881 gdk_window_get_position (window, &dx, &dy);
2886 window = gdk_window_get_parent (window);
2888 if (!window) /* Handle GtkHandleBox */
2892 /* Translate from window relative to allocation relative */
2893 if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent)
2896 gdk_window_get_position (dest_widget->window, &wx, &wy);
2898 src_x += wx - dest_widget->allocation.x;
2899 src_y += wy - dest_widget->allocation.y;
2903 src_x -= dest_widget->allocation.x;
2904 src_y -= dest_widget->allocation.y;
2916 gtk_widget_real_size_allocate (GtkWidget *widget,
2917 GtkAllocation *allocation)
2919 widget->allocation = *allocation;
2921 if (GTK_WIDGET_REALIZED (widget) &&
2922 !GTK_WIDGET_NO_WINDOW (widget))
2924 gdk_window_move_resize (widget->window,
2925 allocation->x, allocation->y,
2926 allocation->width, allocation->height);
2931 gtk_widget_real_can_activate_accel (GtkWidget *widget,
2934 /* widgets must be onscreen for accels to take effect */
2935 return GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_DRAWABLE (widget) && gdk_window_is_viewable (widget->window);
2939 * gtk_widget_can_activate_accel:
2940 * @widget: a #GtkWidget
2941 * @signal_id: the ID of a signal installed on @widget
2943 * Determines whether an accelerator that activates the signal
2944 * identified by @signal_id can currently be activated.
2945 * This is done by emitting the GtkWidget::can-activate-accel
2946 * signal on @widget; if the signal isn't overridden by a
2947 * handler or in a derived widget, then the default check is
2948 * that the widget must be sensitive, and the widget and all
2949 * its ancestors mapped.
2951 * Return value: %TRUE if the accelerator can be activated.
2956 gtk_widget_can_activate_accel (GtkWidget *widget,
2959 gboolean can_activate = FALSE;
2960 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2961 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
2962 return can_activate;
2971 closure_accel_activate (GClosure *closure,
2972 GValue *return_value,
2973 guint n_param_values,
2974 const GValue *param_values,
2975 gpointer invocation_hint,
2976 gpointer marshal_data)
2978 AccelClosure *aclosure = (AccelClosure*) closure;
2979 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
2982 g_signal_emit (closure->data, aclosure->signal_id, 0);
2984 /* whether accelerator was handled */
2985 g_value_set_boolean (return_value, can_activate);
2989 closures_destroy (gpointer data)
2991 GSList *slist, *closures = data;
2993 for (slist = closures; slist; slist = slist->next)
2995 g_closure_invalidate (slist->data);
2996 g_closure_unref (slist->data);
2998 g_slist_free (closures);
3002 widget_new_accel_closure (GtkWidget *widget,
3005 AccelClosure *aclosure;
3006 GClosure *closure = NULL;
3007 GSList *slist, *closures;
3009 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
3010 for (slist = closures; slist; slist = slist->next)
3011 if (!gtk_accel_group_from_accel_closure (slist->data))
3013 /* reuse this closure */
3014 closure = slist->data;
3019 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
3020 closures = g_slist_prepend (closures, g_closure_ref (closure));
3021 g_closure_sink (closure);
3022 g_closure_set_marshal (closure, closure_accel_activate);
3024 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
3026 aclosure = (AccelClosure*) closure;
3027 g_assert (closure->data == widget);
3028 g_assert (closure->marshal == closure_accel_activate);
3029 aclosure->signal_id = signal_id;
3035 * gtk_widget_add_accelerator
3036 * @widget: widget to install an accelerator on
3037 * @accel_signal: widget signal to emit on accelerator activation
3038 * @accel_group: accel group for this widget, added to its toplevel
3039 * @accel_key: GDK keyval of the accelerator
3040 * @accel_mods: modifier key combination of the accelerator
3041 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
3043 * Installs an accelerator for this @widget in @accel_group that causes
3044 * @accel_signal to be emitted if the accelerator is activated.
3045 * The @accel_group needs to be added to the widget's toplevel via
3046 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
3047 * Accelerators added through this function are not user changeable during
3048 * runtime. If you want to support accelerators that can be changed by the
3049 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
3050 * gtk_menu_item_set_accel_path() instead.
3053 gtk_widget_add_accelerator (GtkWidget *widget,
3054 const gchar *accel_signal,
3055 GtkAccelGroup *accel_group,
3057 GdkModifierType accel_mods,
3058 GtkAccelFlags accel_flags)
3063 g_return_if_fail (GTK_IS_WIDGET (widget));
3064 g_return_if_fail (accel_signal != NULL);
3065 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
3067 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
3068 if (!query.signal_id ||
3069 !(query.signal_flags & G_SIGNAL_ACTION) ||
3070 query.return_type != G_TYPE_NONE ||
3073 /* hmm, should be elaborate enough */
3074 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
3075 G_OBJECT_TYPE_NAME (widget), accel_signal);
3079 closure = widget_new_accel_closure (widget, query.signal_id);
3081 g_object_ref (widget);
3083 /* install the accelerator. since we don't map this onto an accel_path,
3084 * the accelerator will automatically be locked.
3086 gtk_accel_group_connect (accel_group,
3089 accel_flags | GTK_ACCEL_LOCKED,
3092 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3094 g_object_unref (widget);
3098 * gtk_widget_remove_accelerator:
3099 * @widget: widget to install an accelerator on
3100 * @accel_group: accel group for this widget
3101 * @accel_key: GDK keyval of the accelerator
3102 * @accel_mods: modifier key combination of the accelerator
3103 * @returns: whether an accelerator was installed and could be removed
3105 * Removes an accelerator from @widget, previously installed with
3106 * gtk_widget_add_accelerator().
3109 gtk_widget_remove_accelerator (GtkWidget *widget,
3110 GtkAccelGroup *accel_group,
3112 GdkModifierType accel_mods)
3114 GtkAccelGroupEntry *ag_entry;
3115 GList *slist, *clist;
3118 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3119 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
3121 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
3122 clist = gtk_widget_list_accel_closures (widget);
3123 for (slist = clist; slist; slist = slist->next)
3127 for (i = 0; i < n; i++)
3128 if (slist->data == (gpointer) ag_entry[i].closure)
3130 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
3132 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3134 g_list_free (clist);
3139 g_list_free (clist);
3141 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
3142 accel_key, accel_mods, accel_group,
3143 G_OBJECT_TYPE_NAME (widget), widget);
3149 * gtk_widget_list_accel_closures
3150 * @widget: widget to list accelerator closures for
3151 * @returns: a newly allocated #GList of closures
3153 * Lists the closures used by @widget for accelerator group connections
3154 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
3155 * The closures can be used to monitor accelerator changes on @widget,
3156 * by connecting to the ::accel_changed signal of the #GtkAccelGroup of a
3157 * closure which can be found out with gtk_accel_group_from_accel_closure().
3160 gtk_widget_list_accel_closures (GtkWidget *widget)
3163 GList *clist = NULL;
3165 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3167 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
3168 if (gtk_accel_group_from_accel_closure (slist->data))
3169 clist = g_list_prepend (clist, slist->data);
3176 GtkAccelGroup *accel_group;
3181 destroy_accel_path (gpointer data)
3183 AccelPath *apath = data;
3185 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
3187 /* closures_destroy takes care of unrefing the closure */
3188 g_object_unref (apath->accel_group);
3195 * gtk_widget_set_accel_path:
3196 * @widget: a #GtkWidget
3197 * @accel_path: path used to look up the the accelerator
3198 * @accel_group: a #GtkAccelGroup.
3200 * Given an accelerator group, @accel_group, and an accelerator path,
3201 * @accel_path, sets up an accelerator in @accel_group so whenever the
3202 * key binding that is defined for @accel_path is pressed, @widget
3203 * will be activated. This removes any accelerators (for any
3204 * accelerator group) installed by previous calls to
3205 * gtk_widget_set_accel_path(). Associating accelerators with
3206 * paths allows them to be modified by the user and the modifications
3207 * to be saved for future use. (See gtk_accel_map_save().)
3209 * This function is a low level function that would most likely
3210 * be used by a menu creation system like #GtkItemFactory. If you
3211 * use #GtkItemFactory, setting up accelerator paths will be done
3214 * Even when you you aren't using #GtkItemFactory, if you only want to
3215 * set up accelerators on menu items gtk_menu_item_set_accel_path()
3216 * provides a somewhat more convenient interface.
3219 gtk_widget_set_accel_path (GtkWidget *widget,
3220 const gchar *accel_path,
3221 GtkAccelGroup *accel_group)
3225 g_return_if_fail (GTK_IS_WIDGET (widget));
3226 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
3230 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
3231 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
3233 gtk_accel_map_add_entry (accel_path, 0, 0);
3234 apath = g_new (AccelPath, 1);
3235 apath->widget = widget;
3236 apath->accel_group = g_object_ref (accel_group);
3237 apath->path_quark = g_quark_from_string (accel_path);
3238 apath->closure = widget_new_accel_closure (apath->widget, GTK_WIDGET_GET_CLASS (apath->widget)->activate_signal);
3243 /* also removes possible old settings */
3244 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
3247 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
3249 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3253 _gtk_widget_get_accel_path (GtkWidget *widget,
3258 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3260 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
3262 *locked = apath ? apath->accel_group->lock_count > 0 : TRUE;
3263 return apath ? g_quark_to_string (apath->path_quark) : NULL;
3267 gtk_widget_mnemonic_activate (GtkWidget *widget,
3268 gboolean group_cycling)
3272 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3274 group_cycling = group_cycling != FALSE;
3275 if (!GTK_WIDGET_IS_SENSITIVE (widget))
3278 g_signal_emit (widget,
3279 widget_signals[MNEMONIC_ACTIVATE],
3287 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
3288 gboolean group_cycling)
3290 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
3291 gtk_widget_activate (widget);
3292 else if (GTK_WIDGET_CAN_FOCUS (widget))
3293 gtk_widget_grab_focus (widget);
3296 g_warning ("widget `%s' isn't suitable for mnemonic activation",
3297 G_OBJECT_TYPE_NAME (widget));
3298 gdk_display_beep (gtk_widget_get_display (widget));
3304 gtk_widget_real_key_press_event (GtkWidget *widget,
3307 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
3311 gtk_widget_real_key_release_event (GtkWidget *widget,
3314 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
3318 gtk_widget_real_focus_in_event (GtkWidget *widget,
3319 GdkEventFocus *event)
3321 gtk_widget_queue_shallow_draw (widget);
3327 gtk_widget_real_focus_out_event (GtkWidget *widget,
3328 GdkEventFocus *event)
3330 gtk_widget_queue_shallow_draw (widget);
3335 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
3336 (event->type == GDK_FOCUS_CHANGE || GTK_WIDGET_REALIZED(widget))
3340 * @widget: a #GtkWidget
3341 * @event: a #GdkEvent
3343 * Rarely-used function. This function is used to emit
3344 * the event signals on a widget (those signals should never
3345 * be emitted without using this function to do so).
3346 * If you want to synthesize an event though, don't use this function;
3347 * instead, use gtk_main_do_event() so the event will behave as if
3348 * it were in the event queue. Don't synthesize expose events; instead,
3349 * use gdk_window_invalidate_rect() to invalidate a region of the
3352 * Return value: return from the event signal emission (%TRUE if the event was handled)
3355 gtk_widget_event (GtkWidget *widget,
3358 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
3359 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
3361 if (event->type == GDK_EXPOSE)
3363 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
3364 "the same effect, call gdk_window_invalidate_rect/region(), "
3365 "followed by gdk_window_process_updates().");
3369 return gtk_widget_event_internal (widget, event);
3374 * gtk_widget_send_expose:
3375 * @widget: a #GtkWidget
3376 * @event: a expose #GdkEvent
3378 * Very rarely-used function. This function is used to emit
3379 * an expose event signals on a widget. This function is not
3380 * normally used directly. The only time it is used is when
3381 * propagating an expose event to a child %NO_WINDOW widget, and
3382 * that is normally done using gtk_container_propagate_expose().
3384 * If you want to force an area of a window to be redrawn,
3385 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
3386 * To cause the redraw to be done immediately, follow that call
3387 * with a call to gdk_window_process_updates().
3389 * Return value: return from the event signal emission (%TRUE if the event was handled)
3392 gtk_widget_send_expose (GtkWidget *widget,
3395 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
3396 g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), TRUE);
3397 g_return_val_if_fail (event != NULL, TRUE);
3398 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
3400 if (event->type != GDK_EXPOSE)
3403 return gtk_widget_event_internal (widget, event);
3407 event_window_is_still_viewable (GdkEvent *event)
3409 /* Some programs, such as gnome-theme-manager, fake widgets
3410 * into exposing onto a pixmap by sending expose events with
3411 * event->window pointing to a pixmap
3413 if (GDK_IS_PIXMAP (event->any.window))
3414 return event->type == GDK_EXPOSE;
3416 /* Check that we think the event's window is viewable before
3417 * delivering the event, to prevent suprises. We do this here
3418 * at the last moment, since the event may have been queued
3419 * up behind other events, held over a recursive main loop, etc.
3421 switch (event->type)
3424 case GDK_MOTION_NOTIFY:
3425 case GDK_BUTTON_PRESS:
3426 case GDK_2BUTTON_PRESS:
3427 case GDK_3BUTTON_PRESS:
3429 case GDK_ENTER_NOTIFY:
3430 case GDK_PROXIMITY_IN:
3432 return event->any.window && gdk_window_is_viewable (event->any.window);
3435 /* The following events are the second half of paired events;
3436 * we always deliver them to deal with widgets that clean up
3437 * on the second half.
3439 case GDK_BUTTON_RELEASE:
3440 case GDK_KEY_RELEASE:
3441 case GDK_LEAVE_NOTIFY:
3442 case GDK_PROXIMITY_OUT:
3446 /* Remaining events would make sense on an not-viewable window,
3447 * or don't have an associated window.
3454 gtk_widget_event_internal (GtkWidget *widget,
3457 gboolean return_val = FALSE;
3459 /* We check only once for is-still-visible; if someone
3460 * hides the window in on of the signals on the widget,
3461 * they are responsible for returning TRUE to terminate
3464 if (!event_window_is_still_viewable (event))
3467 g_object_ref (widget);
3469 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
3470 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
3475 switch (event->type)
3480 case GDK_BUTTON_PRESS:
3481 case GDK_2BUTTON_PRESS:
3482 case GDK_3BUTTON_PRESS:
3483 signal_num = BUTTON_PRESS_EVENT;
3486 signal_num = SCROLL_EVENT;
3488 case GDK_BUTTON_RELEASE:
3489 signal_num = BUTTON_RELEASE_EVENT;
3491 case GDK_MOTION_NOTIFY:
3492 signal_num = MOTION_NOTIFY_EVENT;
3495 signal_num = DELETE_EVENT;
3498 signal_num = DESTROY_EVENT;
3501 signal_num = KEY_PRESS_EVENT;
3503 case GDK_KEY_RELEASE:
3504 signal_num = KEY_RELEASE_EVENT;
3506 case GDK_ENTER_NOTIFY:
3507 signal_num = ENTER_NOTIFY_EVENT;
3509 case GDK_LEAVE_NOTIFY:
3510 signal_num = LEAVE_NOTIFY_EVENT;
3512 case GDK_FOCUS_CHANGE:
3513 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
3516 signal_num = CONFIGURE_EVENT;
3519 signal_num = MAP_EVENT;
3522 signal_num = UNMAP_EVENT;
3524 case GDK_WINDOW_STATE:
3525 signal_num = WINDOW_STATE_EVENT;
3527 case GDK_PROPERTY_NOTIFY:
3528 signal_num = PROPERTY_NOTIFY_EVENT;
3530 case GDK_SELECTION_CLEAR:
3531 signal_num = SELECTION_CLEAR_EVENT;
3533 case GDK_SELECTION_REQUEST:
3534 signal_num = SELECTION_REQUEST_EVENT;
3536 case GDK_SELECTION_NOTIFY:
3537 signal_num = SELECTION_NOTIFY_EVENT;
3539 case GDK_PROXIMITY_IN:
3540 signal_num = PROXIMITY_IN_EVENT;
3542 case GDK_PROXIMITY_OUT:
3543 signal_num = PROXIMITY_OUT_EVENT;
3546 signal_num = NO_EXPOSE_EVENT;
3548 case GDK_CLIENT_EVENT:
3549 signal_num = CLIENT_EVENT;
3552 signal_num = EXPOSE_EVENT;
3554 case GDK_VISIBILITY_NOTIFY:
3555 signal_num = VISIBILITY_NOTIFY_EVENT;
3558 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
3562 if (signal_num != -1)
3563 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
3565 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
3566 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
3570 g_object_unref (widget);
3576 * gtk_widget_activate:
3577 * @widget: a #GtkWidget that's activatable
3579 * For widgets that can be "activated" (buttons, menu items, etc.)
3580 * this function activates them. Activation is what happens when you
3581 * press Enter on a widget during key navigation. If @widget isn't
3582 * activatable, the function returns %FALSE.
3584 * Return value: %TRUE if the widget was activatable
3587 gtk_widget_activate (GtkWidget *widget)
3589 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3591 if (WIDGET_CLASS (widget)->activate_signal)
3593 /* FIXME: we should eventually check the signals signature here */
3594 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
3603 * gtk_widget_set_scroll_adjustments:
3604 * @widget: a #GtkWidget
3605 * @hadjustment: an adjustment for horizontal scrolling, or %NULL
3606 * @vadjustment: an adjustment for vertical scrolling, or %NULL
3608 * For widgets that support scrolling, sets the scroll adjustments and
3609 * returns %TRUE. For widgets that don't support scrolling, does
3610 * nothing and returns %FALSE. Widgets that don't support scrolling
3611 * can be scrolled by placing them in a #GtkViewport, which does
3612 * support scrolling.
3614 * Return value: %TRUE if the widget supports scrolling
3617 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
3618 GtkAdjustment *hadjustment,
3619 GtkAdjustment *vadjustment)
3621 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3623 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
3625 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
3627 if (WIDGET_CLASS (widget)->set_scroll_adjustments_signal)
3629 /* FIXME: we should eventually check the signals signature here */
3630 g_signal_emit (widget,
3631 WIDGET_CLASS (widget)->set_scroll_adjustments_signal, 0,
3632 hadjustment, vadjustment);
3640 gtk_widget_reparent_subwindows (GtkWidget *widget,
3641 GdkWindow *new_window)
3643 if (GTK_WIDGET_NO_WINDOW (widget))
3645 GList *children = gdk_window_get_children (widget->window);
3648 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
3651 GdkWindow *window = tmp_list->data;
3653 gdk_window_get_user_data (window, (void **)&child);
3654 while (child && child != widget)
3655 child = child->parent;
3658 gdk_window_reparent (window, new_window, 0, 0);
3661 g_list_free (children);
3664 gdk_window_reparent (widget->window, new_window, 0, 0);
3668 gtk_widget_reparent_fixup_child (GtkWidget *widget,
3669 gpointer client_data)
3671 g_return_if_fail (client_data != NULL);
3673 if (GTK_WIDGET_NO_WINDOW (widget))
3676 g_object_unref (widget->window);
3677 widget->window = (GdkWindow*) client_data;
3679 g_object_ref (widget->window);
3681 if (GTK_IS_CONTAINER (widget))
3682 gtk_container_forall (GTK_CONTAINER (widget),
3683 gtk_widget_reparent_fixup_child,
3689 * gtk_widget_reparent:
3690 * @widget: a #GtkWidget
3691 * @new_parent: a #GtkContainer to move the widget into
3693 * Moves a widget from one #GtkContainer to another, handling reference
3694 * count issues to avoid destroying the widget.
3698 gtk_widget_reparent (GtkWidget *widget,
3699 GtkWidget *new_parent)
3701 g_return_if_fail (GTK_IS_WIDGET (widget));
3702 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
3703 g_return_if_fail (widget->parent != NULL);
3705 if (widget->parent != new_parent)
3707 /* First try to see if we can get away without unrealizing
3708 * the widget as we reparent it. if so we set a flag so
3709 * that gtk_widget_unparent doesn't unrealize widget
3711 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent))
3712 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
3714 g_object_ref (widget);
3715 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
3716 gtk_container_add (GTK_CONTAINER (new_parent), widget);
3717 g_object_unref (widget);
3719 if (GTK_WIDGET_IN_REPARENT (widget))
3721 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
3723 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
3724 gtk_widget_reparent_fixup_child (widget,
3725 gtk_widget_get_parent_window (widget));
3728 g_object_notify (G_OBJECT (widget), "parent");
3733 * gtk_widget_intersect:
3734 * @widget: a #GtkWidget
3735 * @area: a rectangle
3736 * @intersection: rectangle to store intersection of @widget and @area
3738 * Computes the intersection of a @widget's area and @area, storing
3739 * the intersection in @intersection, and returns %TRUE if there was
3740 * an intersection. @intersection may be %NULL if you're only
3741 * interested in whether there was an intersection.
3743 * Return value: %TRUE if there was an intersection
3746 gtk_widget_intersect (GtkWidget *widget,
3748 GdkRectangle *intersection)
3754 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3755 g_return_val_if_fail (area != NULL, FALSE);
3758 dest = intersection;
3762 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
3764 if (return_val && intersection && !GTK_WIDGET_NO_WINDOW (widget))
3766 intersection->x -= widget->allocation.x;
3767 intersection->y -= widget->allocation.y;
3774 * gtk_widget_region_intersect:
3775 * @widget: a #GtkWidget
3776 * @region: a #GdkRegion, in the same coordinate system as
3777 * @widget->allocation. That is, relative to @widget->window
3778 * for %NO_WINDOW widgets; relative to the parent window
3779 * of @widget->window for widgets with their own window.
3780 * @returns: A newly allocated region holding the intersection of @widget
3781 * and @region. The coordinates of the return value are
3782 * relative to @widget->window for %NO_WINDOW widgets, and
3783 * relative to the parent window of @widget->window for
3784 * widgets with their own window.
3786 * Computes the intersection of a @widget's area and @region, returning
3787 * the intersection. The result may be empty, use gdk_region_empty() to
3791 gtk_widget_region_intersect (GtkWidget *widget,
3796 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3797 g_return_val_if_fail (region != NULL, NULL);
3799 dest = gdk_region_rectangle (&widget->allocation);
3801 gdk_region_intersect (dest, region);
3807 * gtk_widget_grab_focus:
3808 * @widget: a #GtkWidget
3810 * Causes @widget to have the keyboard focus for the #GtkWindow it's
3811 * inside. @widget must be a focusable widget, such as a #GtkEntry;
3812 * something like #GtkFrame won't work. (More precisely, it must have the
3813 * %GTK_CAN_FOCUS flag set.)
3817 gtk_widget_grab_focus (GtkWidget *widget)
3819 g_return_if_fail (GTK_IS_WIDGET (widget));
3821 if (!GTK_WIDGET_IS_SENSITIVE (widget))
3824 g_object_ref (widget);
3825 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
3826 g_object_notify (G_OBJECT (widget), "has_focus");
3827 g_object_unref (widget);
3831 reset_focus_recurse (GtkWidget *widget,
3834 if (GTK_IS_CONTAINER (widget))
3836 GtkContainer *container;
3838 container = GTK_CONTAINER (widget);
3839 gtk_container_set_focus_child (container, NULL);
3841 gtk_container_foreach (container,
3842 reset_focus_recurse,
3848 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
3850 if (GTK_WIDGET_CAN_FOCUS (focus_widget))
3852 GtkWidget *toplevel;
3855 /* clear the current focus setting, break if the current widget
3856 * is the focus widget's parent, since containers above that will
3857 * be set by the next loop.
3859 toplevel = gtk_widget_get_toplevel (focus_widget);
3860 if (GTK_WIDGET_TOPLEVEL (toplevel))
3862 widget = GTK_WINDOW (toplevel)->focus_widget;
3864 if (widget == focus_widget)
3866 /* We call _gtk_window_internal_set_focus() here so that the
3867 * toplevel window can request the focus if necessary.
3868 * This is needed when the toplevel is a GtkPlug
3870 if (!GTK_WIDGET_HAS_FOCUS (widget))
3871 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
3878 while (widget->parent && widget->parent != focus_widget->parent)
3880 widget = widget->parent;
3881 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
3885 else if (toplevel != focus_widget)
3887 /* gtk_widget_grab_focus() operates on a tree without window...
3888 * actually, this is very questionable behaviour.
3891 gtk_container_foreach (GTK_CONTAINER (toplevel),
3892 reset_focus_recurse,
3896 /* now propagate the new focus up the widget tree and finally
3897 * set it on the window
3899 widget = focus_widget;
3900 while (widget->parent)
3902 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
3903 widget = widget->parent;
3905 if (GTK_IS_WINDOW (widget))
3906 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
3911 gtk_widget_real_show_help (GtkWidget *widget,
3912 GtkWidgetHelpType help_type)
3914 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
3916 _gtk_tooltips_toggle_keyboard_mode (widget);
3924 gtk_widget_real_focus (GtkWidget *widget,
3925 GtkDirectionType direction)
3927 if (!GTK_WIDGET_CAN_FOCUS (widget))
3930 if (!gtk_widget_is_focus (widget))
3932 gtk_widget_grab_focus (widget);
3940 * gtk_widget_is_focus:
3941 * @widget: a #GtkWidget
3943 * Determines if the widget is the focus widget within its
3944 * toplevel. (This does not mean that the %HAS_FOCUS flag is
3945 * necessarily set; %HAS_FOCUS will only be set if the
3946 * toplevel widget additionally has the global input focus.)
3948 * Return value: %TRUE if the widget is the focus widget.
3951 gtk_widget_is_focus (GtkWidget *widget)
3953 GtkWidget *toplevel;
3955 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3957 toplevel = gtk_widget_get_toplevel (widget);
3959 if (GTK_IS_WINDOW (toplevel))
3960 return widget == GTK_WINDOW (toplevel)->focus_widget;
3966 * gtk_widget_grab_default:
3967 * @widget: a #GtkWidget
3969 * Causes @widget to become the default widget. @widget must have the
3970 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
3971 * yourself by calling <literal>GTK_WIDGET_SET_FLAGS (@widget,
3972 * GTK_CAN_DEFAULT)</literal>. The default widget is activated when the user
3973 * presses Enter in a window. Default widgets must be activatable,
3974 * that is, gtk_widget_activate() should affect them.
3978 gtk_widget_grab_default (GtkWidget *widget)
3982 g_return_if_fail (GTK_IS_WIDGET (widget));
3983 g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget));
3985 window = gtk_widget_get_toplevel (widget);
3987 if (window && GTK_WIDGET_TOPLEVEL (window))
3988 gtk_window_set_default (GTK_WINDOW (window), widget);
3990 g_warning (G_STRLOC ": widget not within a GtkWindow");
3994 * gtk_widget_set_name:
3995 * @widget: a #GtkWidget
3996 * @name: name for the widget
3998 * Widgets can be named, which allows you to refer to them from a
3999 * gtkrc file. You can apply a style to widgets with a particular name
4000 * in the gtkrc file. See the documentation for gtkrc files (on the
4001 * same page as the docs for #GtkRcStyle).
4003 * Note that widget names are separated by periods in paths (see
4004 * gtk_widget_path()), so names with embedded periods may cause confusion.
4007 gtk_widget_set_name (GtkWidget *widget,
4012 g_return_if_fail (GTK_IS_WIDGET (widget));
4014 new_name = g_strdup (name);
4015 g_free (widget->name);
4016 widget->name = new_name;
4018 if (GTK_WIDGET_RC_STYLE (widget))
4019 gtk_widget_reset_rc_style (widget);
4021 g_object_notify (G_OBJECT (widget), "name");
4025 * gtk_widget_get_name:
4026 * @widget: a #GtkWidget
4028 * Retrieves the name of a widget. See gtk_widget_set_name() for the
4029 * significance of widget names.
4031 * Return value: name of the widget. This string is owned by GTK+ and
4032 * should not be modified or freed
4034 G_CONST_RETURN gchar*
4035 gtk_widget_get_name (GtkWidget *widget)
4037 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4040 return widget->name;
4041 return g_type_name (GTK_WIDGET_TYPE (widget));
4045 * gtk_widget_set_state:
4046 * @widget: a #GtkWidget
4047 * @state: new state for @widget
4049 * This function is for use in widget implementations. Sets the state
4050 * of a widget (insensitive, prelighted, etc.) Usually you should set
4051 * the state using wrapper functions such as gtk_widget_set_sensitive().
4055 gtk_widget_set_state (GtkWidget *widget,
4058 g_return_if_fail (GTK_IS_WIDGET (widget));
4060 if (state == GTK_WIDGET_STATE (widget))
4063 if (state == GTK_STATE_INSENSITIVE)
4064 gtk_widget_set_sensitive (widget, FALSE);
4070 data.state_restoration = FALSE;
4071 data.use_forall = FALSE;
4073 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
4075 data.parent_sensitive = TRUE;
4077 gtk_widget_propagate_state (widget, &data);
4079 if (GTK_WIDGET_DRAWABLE (widget))
4080 gtk_widget_queue_draw (widget);
4085 gtk_widget_set_app_paintable (GtkWidget *widget,
4086 gboolean app_paintable)
4088 g_return_if_fail (GTK_IS_WIDGET (widget));
4090 app_paintable = (app_paintable != FALSE);
4092 if (GTK_WIDGET_APP_PAINTABLE (widget) != app_paintable)
4095 GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE);
4097 GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE);
4099 if (GTK_WIDGET_DRAWABLE (widget))
4100 gtk_widget_queue_draw (widget);
4102 g_object_notify (G_OBJECT (widget), "app_paintable");
4107 * gtk_widget_set_double_buffered:
4108 * @widget: a #GtkWidget
4109 * @double_buffered: %TRUE to double-buffer a widget
4111 * Widgets are double buffered by default; you can use this function
4112 * to turn off the buffering. "Double buffered" simply means that
4113 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
4114 * automatically around expose events sent to the
4115 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
4116 * window to an offscreen buffer, and gdk_window_end_paint() draws the
4117 * buffer to the screen. The result is that users see the window
4118 * update in one smooth step, and don't see individual graphics
4119 * primitives being rendered.
4121 * In very simple terms, double buffered widgets don't flicker,
4122 * so you would only use this function to turn off double buffering
4123 * if you had special needs and really knew what you were doing.
4127 gtk_widget_set_double_buffered (GtkWidget *widget,
4128 gboolean double_buffered)
4130 g_return_if_fail (GTK_IS_WIDGET (widget));
4132 if (double_buffered)
4133 GTK_WIDGET_SET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
4135 GTK_WIDGET_UNSET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
4139 * gtk_widget_set_redraw_on_allocate:
4140 * @widget: a #GtkWidget
4141 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
4142 * when it is allocated to a new size. Otherwise, only the
4143 * new portion of the widget will be redrawn.
4145 * Sets whether a when a widgets size allocation changes, the entire
4146 * widget is queued for drawing. By default, this setting is %TRUE and
4147 * the entire widget is redrawn on every size change. If your widget
4148 * leaves the upper left unchanged when made bigger, turning this
4149 * setting on will improve performance.
4151 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
4152 * off all allocation on resizing: the widget will not even redraw if
4153 * its position changes; this is to allow containers that don't draw
4154 * anything to avoid excess invalidations. If you set this flag on a
4155 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
4156 * you are responsible for invalidating both the old and new allocation
4157 * of the widget when the widget is moved and responsible for invalidating
4158 * regions newly when the widget increases size.
4161 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
4162 gboolean redraw_on_allocate)
4164 g_return_if_fail (GTK_IS_WIDGET (widget));
4166 if (redraw_on_allocate)
4167 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
4169 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
4173 * gtk_widget_set_sensitive:
4174 * @widget: a #GtkWidget
4175 * @sensitive: %TRUE to make the widget sensitive
4177 * Sets the sensitivity of a widget. A widget is sensitive if the user
4178 * can interact with it. Insensitive widgets are "grayed out" and the
4179 * user can't interact with them. Insensitive widgets are known as
4180 * "inactive", "disabled", or "ghosted" in some other toolkits.
4184 gtk_widget_set_sensitive (GtkWidget *widget,
4189 g_return_if_fail (GTK_IS_WIDGET (widget));
4191 sensitive = (sensitive != FALSE);
4193 if (sensitive == (GTK_WIDGET_SENSITIVE (widget) != FALSE))
4198 GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE);
4199 data.state = GTK_WIDGET_SAVED_STATE (widget);
4203 GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE);
4204 data.state = GTK_WIDGET_STATE (widget);
4206 data.state_restoration = TRUE;
4207 data.use_forall = TRUE;
4210 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
4212 data.parent_sensitive = TRUE;
4214 gtk_widget_propagate_state (widget, &data);
4215 if (GTK_WIDGET_DRAWABLE (widget))
4216 gtk_widget_queue_draw (widget);
4218 g_object_notify (G_OBJECT (widget), "sensitive");
4222 * gtk_widget_set_parent:
4223 * @widget: a #GtkWidget
4224 * @parent: parent container
4226 * This function is useful only when implementing subclasses of #GtkContainer.
4227 * Sets the container as the parent of @widget, and takes care of
4228 * some details such as updating the state and style of the child
4229 * to reflect its new location. The opposite function is
4230 * gtk_widget_unparent().
4234 gtk_widget_set_parent (GtkWidget *widget,
4239 g_return_if_fail (GTK_IS_WIDGET (widget));
4240 g_return_if_fail (widget->parent == NULL);
4241 g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
4242 g_return_if_fail (GTK_IS_WIDGET (parent));
4243 g_return_if_fail (widget != parent);
4245 /* keep this function in sync with gtk_menu_attach_to_widget()
4248 g_object_ref (widget);
4249 gtk_object_sink (GTK_OBJECT (widget));
4250 widget->parent = parent;
4252 if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
4253 data.state = GTK_WIDGET_STATE (parent);
4255 data.state = GTK_WIDGET_STATE (widget);
4256 data.state_restoration = FALSE;
4257 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (parent) != FALSE);
4258 data.use_forall = GTK_WIDGET_IS_SENSITIVE (parent) != GTK_WIDGET_IS_SENSITIVE (widget);
4260 gtk_widget_propagate_state (widget, &data);
4262 gtk_widget_reset_rc_styles (widget);
4264 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
4265 if (GTK_WIDGET_ANCHORED (widget->parent))
4266 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
4267 g_object_notify (G_OBJECT (widget), "parent");
4269 /* Enforce realized/mapped invariants
4271 if (GTK_WIDGET_REALIZED (widget->parent))
4272 gtk_widget_realize (widget);
4274 if (GTK_WIDGET_VISIBLE (widget->parent) &&
4275 GTK_WIDGET_VISIBLE (widget))
4277 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
4278 GTK_WIDGET_MAPPED (widget->parent))
4279 gtk_widget_map (widget);
4281 gtk_widget_queue_resize (widget);
4286 * gtk_widget_get_parent:
4287 * @widget: a #GtkWidget
4289 * Returns the parent container of @widget.
4291 * Return value: the parent container of @widget, or %NULL
4294 gtk_widget_get_parent (GtkWidget *widget)
4296 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4298 return widget->parent;
4301 /*****************************************
4303 * see docs/styles.txt
4304 *****************************************/
4307 * gtk_widget_set_style:
4308 * @widget: a #GtkWidget
4309 * @style: a #GtkStyle, or %NULL to remove the effect of a previous
4310 * gtk_widget_set_style() and go back to the default style
4312 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
4313 * want to use this function; it interacts badly with themes, because
4314 * themes work by replacing the #GtkStyle. Instead, use
4315 * gtk_widget_modify_style().
4319 gtk_widget_set_style (GtkWidget *widget,
4322 g_return_if_fail (GTK_IS_WIDGET (widget));
4326 gboolean initial_emission;
4328 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
4330 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
4331 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
4333 gtk_widget_set_style_internal (widget, style, initial_emission);
4337 if (GTK_WIDGET_USER_STYLE (widget))
4338 gtk_widget_reset_rc_style (widget);
4343 * gtk_widget_ensure_style:
4344 * @widget: a #GtkWidget
4346 * Ensures that @widget has a style (@widget->style). Not a very useful
4347 * function; most of the time, if you want the style, the widget is
4348 * realized, and realized widgets are guaranteed to have a style
4353 gtk_widget_ensure_style (GtkWidget *widget)
4355 g_return_if_fail (GTK_IS_WIDGET (widget));
4357 if (!GTK_WIDGET_USER_STYLE (widget) &&
4358 !GTK_WIDGET_RC_STYLE (widget))
4359 gtk_widget_reset_rc_style (widget);
4362 /* Look up the RC style for this widget, unsetting any user style that
4363 * may be in effect currently
4366 gtk_widget_reset_rc_style (GtkWidget *widget)
4368 GtkStyle *new_style = NULL;
4369 gboolean initial_emission;
4371 g_return_if_fail (GTK_IS_WIDGET (widget));
4373 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
4375 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
4376 GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
4378 if (gtk_widget_has_screen (widget))
4379 new_style = gtk_rc_get_style (widget);
4381 new_style = gtk_widget_get_default_style ();
4383 if (initial_emission || new_style != widget->style)
4384 gtk_widget_set_style_internal (widget, new_style, initial_emission);
4388 * gtk_widget_get_style:
4389 * @widget: a #GtkWidget
4391 * Simply an accessor function that returns @widget->style.
4393 * Return value: the widget's #GtkStyle
4396 gtk_widget_get_style (GtkWidget *widget)
4398 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4400 return widget->style;
4404 * gtk_widget_modify_style:
4405 * @widget: a #GtkWidget
4406 * @style: the #GtkRcStyle holding the style modifications
4408 * Modifies style values on the widget. Modifications made using this
4409 * technique take precedence over style values set via an RC file,
4410 * however, they will be overriden if a style is explicitely set on
4411 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
4412 * is designed so each field can either be set or unset, so it is
4413 * possible, using this function, to modify some style values and
4414 * leave the others unchanged.
4416 * Note that modifications made with this function are not cumulative
4417 * with previous calls to gtk_widget_modify_style() or with such
4418 * functions as gtk_widget_modify_fg(). If you wish to retain
4419 * previous values, you must first call gtk_widget_get_modifier_style(),
4420 * make your modifications to the returned style, then call
4421 * gtk_widget_modify_style() with that style. On the other hand,
4422 * if you first call gtk_widget_modify_style(), subsequent calls
4423 * to such functions gtk_widget_modify_fg() will have a cumulative
4424 * effect with the initial modifications.
4427 gtk_widget_modify_style (GtkWidget *widget,
4430 GtkRcStyle *old_style;
4432 g_return_if_fail (GTK_IS_WIDGET (widget));
4433 g_return_if_fail (GTK_IS_RC_STYLE (style));
4435 old_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
4437 g_object_set_qdata_full (G_OBJECT (widget),
4439 gtk_rc_style_copy (style),
4440 (GDestroyNotify) gtk_rc_style_unref);
4442 /* note that "style" may be invalid here if it was the old
4443 * modifier style and the only reference was our own.
4446 if (GTK_WIDGET_RC_STYLE (widget))
4447 gtk_widget_reset_rc_style (widget);
4451 * gtk_widget_get_modifier_style:
4452 * @widget: a #GtkWidget
4454 * Returns the current modifier style for the widget. (As set by
4455 * gtk_widget_modify_style().) If no style has previously set, a new
4456 * #GtkRcStyle will be created with all values unset, and set as the
4457 * modifier style for the widget. If you make changes to this rc
4458 * style, you must call gtk_widget_modify_style(), passing in the
4459 * returned rc style, to make sure that your changes take effect.
4461 * Caution: passing the style back to gtk_widget_modify_style() will
4462 * normally end up destroying it, because gtk_widget_modify_style() copies
4463 * the passed-in style and sets the copy as the new modifier style,
4464 * thus dropping any reference to the old modifier style. Add a reference
4465 * to the modifier style if you want to keep it alive.
4467 * Return value: the modifier style for the widget. This rc style is
4468 * owned by the widget. If you want to keep a pointer to value this
4469 * around, you must add a refcount using gtk_rc_style_ref().
4472 gtk_widget_get_modifier_style (GtkWidget *widget)
4474 GtkRcStyle *rc_style;
4476 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4478 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
4482 rc_style = gtk_rc_style_new ();
4483 g_object_set_qdata_full (G_OBJECT (widget),
4486 (GDestroyNotify) gtk_rc_style_unref);
4493 gtk_widget_modify_color_component (GtkWidget *widget,
4494 GtkRcFlags component,
4496 const GdkColor *color)
4498 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
4505 rc_style->fg[state] = *color;
4508 rc_style->bg[state] = *color;
4511 rc_style->text[state] = *color;
4514 rc_style->base[state] = *color;
4517 g_assert_not_reached();
4520 rc_style->color_flags[state] |= component;
4523 rc_style->color_flags[state] &= ~component;
4525 gtk_widget_modify_style (widget, rc_style);
4529 * gtk_widget_modify_fg:
4530 * @widget: a #GtkWidget.
4531 * @state: the state for which to set the foreground color.
4532 * @color: the color to assign (does not need to be allocated),
4533 * or %NULL to undo the effect of previous calls to
4534 * of gtk_widget_modify_fg().
4536 * Sets the foreground color for a widget in a particular state. All
4537 * other style values are left untouched. See also
4538 * gtk_widget_modify_style().
4541 gtk_widget_modify_fg (GtkWidget *widget,
4543 const GdkColor *color)
4545 g_return_if_fail (GTK_IS_WIDGET (widget));
4546 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4548 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
4552 * gtk_widget_modify_bg:
4553 * @widget: a #GtkWidget.
4554 * @state: the state for which to set the background color.
4555 * @color: the color to assign (does not need to be allocated),
4556 * or %NULL to undo the effect of previous calls to
4557 * of gtk_widget_modify_bg().
4559 * Sets the background color for a widget in a particular state. All
4560 * other style values are left untouched. See also
4561 * gtk_widget_modify_style().
4564 gtk_widget_modify_bg (GtkWidget *widget,
4566 const GdkColor *color)
4568 g_return_if_fail (GTK_IS_WIDGET (widget));
4569 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4571 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
4575 * gtk_widget_modify_text:
4576 * @widget: a #GtkWidget.
4577 * @state: the state for which to set the text color.
4578 * @color: the color to assign (does not need to be allocated),
4579 * or %NULL to undo the effect of previous calls to
4580 * of gtk_widget_modify_text().
4582 * Sets the text color for a widget in a particular state. All other
4583 * style values are left untouched. The text color is the foreground
4584 * color used along with the base color (see gtk_widget_modify_base())
4585 * for widgets such as #GtkEntry and #GtkTextView. See also
4586 * gtk_widget_modify_style().
4589 gtk_widget_modify_text (GtkWidget *widget,
4591 const GdkColor *color)
4593 g_return_if_fail (GTK_IS_WIDGET (widget));
4594 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4596 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
4600 * gtk_widget_modify_base:
4601 * @widget: a #GtkWidget.
4602 * @state: the state for which to set the base color.
4603 * @color: the color to assign (does not need to be allocated),
4604 * or %NULL to undo the effect of previous calls to
4605 * of gtk_widget_modify_base().
4607 * Sets the base color for a widget in a particular state.
4608 * All other style values are left untouched. The base color
4609 * is the background color used along with the text color
4610 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
4611 * and #GtkTextView. See also gtk_widget_modify_style().
4614 gtk_widget_modify_base (GtkWidget *widget,
4616 const GdkColor *color)
4618 g_return_if_fail (GTK_IS_WIDGET (widget));
4619 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4621 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
4625 * gtk_widget_modify_font:
4626 * @widget: a #GtkWidget
4627 * @font_desc: the font description to use, or %NULL to undo
4628 * the effect of previous calls to gtk_widget_modify_font().
4630 * Sets the font to use for a widget. All other style values are left
4631 * untouched. See also gtk_widget_modify_style().
4634 gtk_widget_modify_font (GtkWidget *widget,
4635 PangoFontDescription *font_desc)
4637 GtkRcStyle *rc_style;
4639 g_return_if_fail (GTK_IS_WIDGET (widget));
4641 rc_style = gtk_widget_get_modifier_style (widget);
4643 if (rc_style->font_desc)
4644 pango_font_description_free (rc_style->font_desc);
4647 rc_style->font_desc = pango_font_description_copy (font_desc);
4649 rc_style->font_desc = NULL;
4651 gtk_widget_modify_style (widget, rc_style);
4655 gtk_widget_direction_changed (GtkWidget *widget,
4656 GtkTextDirection previous_direction)
4658 gtk_widget_queue_resize (widget);
4662 gtk_widget_style_set (GtkWidget *widget,
4663 GtkStyle *previous_style)
4665 if (GTK_WIDGET_REALIZED (widget) &&
4666 !GTK_WIDGET_NO_WINDOW (widget))
4667 gtk_style_set_background (widget->style, widget->window, widget->state);
4671 gtk_widget_set_style_internal (GtkWidget *widget,
4673 gboolean initial_emission)
4675 g_object_ref (widget);
4676 g_object_freeze_notify (G_OBJECT (widget));
4678 if (widget->style != style || initial_emission)
4680 PangoContext *context = gtk_widget_peek_pango_context (widget);
4682 pango_context_set_font_description (context, style->font_desc);
4685 if (widget->style != style)
4687 GtkStyle *previous_style;
4689 if (GTK_WIDGET_REALIZED (widget))
4691 gtk_widget_reset_shapes (widget);
4692 gtk_style_detach (widget->style);
4695 previous_style = widget->style;
4696 widget->style = style;
4697 g_object_ref (widget->style);
4699 if (GTK_WIDGET_REALIZED (widget))
4700 widget->style = gtk_style_attach (widget->style, widget->window);
4702 g_signal_emit (widget,
4703 widget_signals[STYLE_SET],
4705 initial_emission ? NULL : previous_style);
4706 g_object_unref (previous_style);
4708 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
4709 gtk_widget_queue_resize (widget);
4711 else if (initial_emission)
4712 g_signal_emit (widget,
4713 widget_signals[STYLE_SET],
4716 g_object_notify (G_OBJECT (widget), "style");
4717 g_object_thaw_notify (G_OBJECT (widget));
4718 g_object_unref (widget);
4722 GtkWidget *previous_toplevel;
4723 GdkScreen *previous_screen;
4724 GdkScreen *new_screen;
4725 } HierarchyChangedInfo;
4728 do_screen_change (GtkWidget *widget,
4729 GdkScreen *old_screen,
4730 GdkScreen *new_screen)
4732 if (old_screen != new_screen)
4736 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
4738 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
4741 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
4746 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
4747 gpointer client_data)
4749 gboolean new_anchored;
4750 HierarchyChangedInfo *info = client_data;
4752 new_anchored = GTK_WIDGET_TOPLEVEL (widget) ||
4753 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
4755 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
4757 g_object_ref (widget);
4760 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
4762 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
4764 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
4765 do_screen_change (widget, info->previous_screen, info->new_screen);
4767 if (GTK_IS_CONTAINER (widget))
4768 gtk_container_forall (GTK_CONTAINER (widget),
4769 gtk_widget_propagate_hierarchy_changed_recurse,
4772 g_object_unref (widget);
4777 * _gtk_widget_propagate_hierarchy_changed:
4778 * @widget: a #GtkWidget
4779 * @previous_toplevel: Previous toplevel
4781 * Propagates changes in the anchored state to a widget and all
4782 * children, unsetting or setting the %ANCHORED flag, and
4783 * emitting ::hierarchy_changed.
4786 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
4787 GtkWidget *previous_toplevel)
4789 HierarchyChangedInfo info;
4791 info.previous_toplevel = previous_toplevel;
4792 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
4794 if (GTK_WIDGET_TOPLEVEL (widget) ||
4795 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
4796 info.new_screen = gtk_widget_get_screen (widget);
4798 info.new_screen = NULL;
4800 if (info.previous_screen)
4801 g_object_ref (info.previous_screen);
4802 if (previous_toplevel)
4803 g_object_ref (previous_toplevel);
4805 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
4807 if (previous_toplevel)
4808 g_object_unref (previous_toplevel);
4809 if (info.previous_screen)
4810 g_object_unref (info.previous_screen);
4814 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
4815 gpointer client_data)
4817 HierarchyChangedInfo *info = client_data;
4819 g_object_ref (widget);
4821 do_screen_change (widget, info->previous_screen, info->new_screen);
4823 if (GTK_IS_CONTAINER (widget))
4824 gtk_container_forall (GTK_CONTAINER (widget),
4825 gtk_widget_propagate_screen_changed_recurse,
4828 g_object_unref (widget);
4832 * _gtk_widget_propagate_screen_changed:
4833 * @widget: a #GtkWidget
4834 * @previous_screen: Previous screen
4836 * Propagates changes in the screen for a widget to all
4837 * children, emitting ::screen_changed.
4840 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
4841 GdkScreen *previous_screen)
4843 HierarchyChangedInfo info;
4845 info.previous_screen = previous_screen;
4846 info.new_screen = gtk_widget_get_screen (widget);
4848 if (previous_screen)
4849 g_object_ref (previous_screen);
4851 gtk_widget_propagate_screen_changed_recurse (widget, &info);
4853 if (previous_screen)
4854 g_object_unref (previous_screen);
4858 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
4860 if (GTK_WIDGET_RC_STYLE (widget))
4861 gtk_widget_reset_rc_style (widget);
4863 if (GTK_IS_CONTAINER (widget))
4864 gtk_container_forall (GTK_CONTAINER (widget),
4865 reset_rc_styles_recurse,
4870 gtk_widget_reset_rc_styles (GtkWidget *widget)
4872 g_return_if_fail (GTK_IS_WIDGET (widget));
4874 reset_rc_styles_recurse (widget, NULL);
4878 * gtk_widget_get_default_style:
4880 * Returns the default style used by all widgets initially.
4882 * Returns: the default style. This #GtkStyle object is owned by GTK+ and
4883 * should not be modified or freed.
4886 gtk_widget_get_default_style (void)
4888 if (!gtk_default_style)
4890 gtk_default_style = gtk_style_new ();
4891 g_object_ref (gtk_default_style);
4894 return gtk_default_style;
4897 static PangoContext *
4898 gtk_widget_peek_pango_context (GtkWidget *widget)
4900 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
4904 * gtk_widget_get_pango_context:
4905 * @widget: a #GtkWidget
4907 * Gets a #PangoContext with the appropriate colormap, font description
4908 * and base direction for this widget. Unlike the context returned
4909 * by gtk_widget_create_pango_context(), this context is owned by
4910 * the widget (it can be used until the screen for the widget changes
4911 * or the widget is removed from its toplevel), and will be updated to
4912 * match any changes to the widget's attributes.
4914 * If you create and keep a #PangoLayout using this context, you must
4915 * deal with changes to the context by calling pango_layout_context_changed()
4916 * on the layout in response to the ::style-set and ::direction-changed signals
4919 * Return value: the #PangoContext for the widget.
4922 gtk_widget_get_pango_context (GtkWidget *widget)
4924 PangoContext *context;
4926 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4928 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
4931 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
4932 g_object_set_qdata_full (G_OBJECT (widget),
4933 quark_pango_context,
4942 * gtk_widget_create_pango_context:
4943 * @widget: a #GtkWidget
4945 * Creates a new #PangoContext with the appropriate colormap,
4946 * font description, and base direction for drawing text for
4947 * this widget. See also gtk_widget_get_pango_context().
4949 * Return value: the new #PangoContext
4952 gtk_widget_create_pango_context (GtkWidget *widget)
4955 PangoContext *context;
4957 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4959 screen = gtk_widget_get_screen_unchecked (widget);
4962 GTK_NOTE (MULTIHEAD,
4963 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
4965 screen = gdk_screen_get_default ();
4968 context = gdk_pango_context_get_for_screen (screen);
4970 gdk_pango_context_set_colormap (context, gtk_widget_get_colormap (widget));
4971 pango_context_set_base_dir (context,
4972 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
4973 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
4974 pango_context_set_font_description (context, widget->style->font_desc);
4975 pango_context_set_language (context, gtk_get_default_language ());
4981 * gtk_widget_create_pango_layout:
4982 * @widget: a #GtkWidget
4983 * @text: text to set on the layout (can be %NULL)
4985 * Creates a new #PangoLayout with the appropriate colormap,
4986 * font description, and base direction for drawing text for
4989 * If you keep a #PangoLayout created in this way around, in order
4990 * notify the layout of changes to the base direction or font of this
4991 * widget, you must call pango_layout_context_changed() in response to
4992 * the ::style-set and ::direction-changed signals for the widget.
4994 * Return value: the new #PangoLayout
4997 gtk_widget_create_pango_layout (GtkWidget *widget,
5000 PangoLayout *layout;
5001 PangoContext *context;
5003 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5005 context = gtk_widget_get_pango_context (widget);
5006 layout = pango_layout_new (context);
5009 pango_layout_set_text (layout, text, -1);
5015 * gtk_widget_render_icon:
5016 * @widget: a #GtkWidget
5017 * @stock_id: a stock ID
5018 * @size: a stock size
5019 * @detail: render detail to pass to theme engine
5021 * A convenience function that uses the theme engine and RC file
5022 * settings for @widget to look up @stock_id and render it to
5023 * a pixbuf. @stock_id should be a stock icon ID such as
5024 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
5025 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
5026 * identifies the widget or code doing the rendering, so that
5027 * theme engines can special-case rendering for that widget or code.
5029 * The pixels in the returned #GdkPixbuf are shared with the rest of
5030 * the application and should not be modified. The pixbuf should be freed
5031 * after use with g_object_unref().
5033 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
5036 gtk_widget_render_icon (GtkWidget *widget,
5037 const gchar *stock_id,
5039 const gchar *detail)
5041 GtkIconSet *icon_set;
5044 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5045 g_return_val_if_fail (stock_id != NULL, NULL);
5046 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID, NULL);
5048 gtk_widget_ensure_style (widget);
5050 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
5052 if (icon_set == NULL)
5055 retval = gtk_icon_set_render_icon (icon_set,
5057 gtk_widget_get_direction (widget),
5058 GTK_WIDGET_STATE (widget),
5067 * gtk_widget_set_parent_window:
5068 * @widget: a #GtkWidget.
5069 * @parent_window: the new parent window.
5071 * Sets a non default parent window for @widget.
5074 gtk_widget_set_parent_window (GtkWidget *widget,
5075 GdkWindow *parent_window)
5077 GdkWindow *old_parent_window;
5079 g_return_if_fail (GTK_IS_WIDGET (widget));
5081 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
5082 quark_parent_window);
5084 if (parent_window != old_parent_window)
5086 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
5088 if (old_parent_window)
5089 g_object_unref (old_parent_window);
5091 g_object_ref (parent_window);
5097 * gtk_widget_set_child_visible:
5098 * @widget: a #GtkWidget
5099 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
5101 * Sets whether @widget should be mapped along with its when its parent
5102 * is mapped and @widget has been shown with gtk_widget_show().
5104 * The child visibility can be set for widget before it is added to
5105 * a container with gtk_widget_set_parent(), to avoid mapping
5106 * children unnecessary before immediately unmapping them. However
5107 * it will be reset to its default state of %TRUE when the widget
5108 * is removed from a container.
5110 * Note that changing the child visibility of a widget does not
5111 * queue a resize on the widget. Most of the time, the size of
5112 * a widget is computed from all visible children, whether or
5113 * not they are mapped. If this is not the case, the container
5114 * can queue a resize itself.
5116 * This function is only useful for container implementations and
5117 * never should be called by an application.
5120 gtk_widget_set_child_visible (GtkWidget *widget,
5121 gboolean is_visible)
5123 g_return_if_fail (GTK_IS_WIDGET (widget));
5124 g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
5126 g_object_ref (widget);
5129 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
5132 GtkWidget *toplevel;
5134 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
5136 toplevel = gtk_widget_get_toplevel (widget);
5137 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
5138 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
5141 if (widget->parent && GTK_WIDGET_REALIZED (widget->parent))
5143 if (GTK_WIDGET_MAPPED (widget->parent) &&
5144 GTK_WIDGET_CHILD_VISIBLE (widget) &&
5145 GTK_WIDGET_VISIBLE (widget))
5146 gtk_widget_map (widget);
5148 gtk_widget_unmap (widget);
5151 g_object_unref (widget);
5155 * gtk_widget_get_child_visible:
5156 * @widget: a #GtkWidget
5158 * Gets the value set with gtk_widget_set_child_visible().
5159 * If you feel a need to use this function, your code probably
5160 * needs reorganization.
5162 * This function is only useful for container implementations and
5163 * never should be called by an application.
5165 * Return value: %TRUE if the widget is mapped with the parent.
5168 gtk_widget_get_child_visible (GtkWidget *widget)
5170 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5172 return GTK_WIDGET_CHILD_VISIBLE (widget);
5176 gtk_widget_get_screen_unchecked (GtkWidget *widget)
5178 GtkWidget *toplevel;
5180 toplevel = gtk_widget_get_toplevel (widget);
5182 if (GTK_WIDGET_TOPLEVEL (toplevel))
5184 if (GTK_IS_WINDOW (toplevel))
5185 return GTK_WINDOW (toplevel)->screen;
5186 else if (GTK_IS_INVISIBLE (toplevel))
5187 return GTK_INVISIBLE (widget)->screen;
5194 * gtk_widget_get_screen:
5195 * @widget: a #GtkWidget
5197 * Get the #GdkScreen from the toplevel window associated with
5198 * this widget. This function can only be called after the widget
5199 * has been added to a widget hierarchy with a #GtkWindow
5202 * In general, you should only create screen specific
5203 * resources when a widget has been realized, and you should
5204 * free those resources when the widget is unrealized.
5206 * Return value: the #GdkScreen for the toplevel for this widget.
5211 gtk_widget_get_screen (GtkWidget *widget)
5215 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5217 screen = gtk_widget_get_screen_unchecked (widget);
5224 g_warning (G_STRLOC ": Can't get associated screen"
5225 " for a widget unless it is inside a toplevel GtkWindow\n"
5226 " widget type is %s associated top level type is %s",
5227 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
5228 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
5230 return gdk_screen_get_default ();
5235 * gtk_widget_has_screen:
5236 * @widget: a #GtkWidget
5238 * Checks whether there is a #GdkScreen is associated with
5239 * this widget. All toplevel widgets have an associated
5240 * screen, and all widgets added into a heirarchy with a toplevel
5241 * window at the top.
5243 * Return value: %TRUE if there is a #GdkScreen associcated
5249 gtk_widget_has_screen (GtkWidget *widget)
5251 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5253 return (gtk_widget_get_screen_unchecked (widget) != NULL);
5257 * gtk_widget_get_display:
5258 * @widget: a #GtkWidget
5260 * Get the #GdkDisplay for the toplevel window associated with
5261 * this widget. This function can only be called after the widget
5262 * has been added to a widget hierarchy with a #GtkWindow at the top.
5264 * In general, you should only create display specific
5265 * resources when a widget has been realized, and you should
5266 * free those resources when the widget is unrealized.
5268 * Return value: the #GdkDisplay for the toplevel for this widget.
5273 gtk_widget_get_display (GtkWidget *widget)
5275 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5277 return gdk_screen_get_display (gtk_widget_get_screen (widget));
5281 * gtk_widget_get_root_window:
5282 * @widget: a #GtkWidget
5284 * Get the root window where this widget is located. This function can
5285 * only be called after the widget has been added to a widget
5286 * heirarchy with #GtkWindow at the top.
5288 * The root window is useful for such purposes as creating a popup
5289 * #GdkWindow associated with the window. In general, you should only
5290 * create display specific resources when a widget has been realized,
5291 * and you should free those resources when the widget is unrealized.
5293 * Return value: the #GdkWindow root window for the toplevel for this widget.
5298 gtk_widget_get_root_window (GtkWidget *widget)
5300 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5302 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
5306 * gtk_widget_get_parent_window:
5307 * @widget: a #GtkWidget.
5308 * @returns: the parent window of @widget.
5310 * Gets @widget's parent window.
5313 gtk_widget_get_parent_window (GtkWidget *widget)
5315 GdkWindow *parent_window;
5317 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5318 g_return_val_if_fail (widget->parent != NULL, NULL);
5320 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
5322 return (parent_window != NULL) ? parent_window : widget->parent->window;
5326 * gtk_widget_child_focus:
5327 * @widget: a #GtkWidget
5328 * @direction: direction of focus movement
5330 * This function is used by custom widget implementations; if you're
5331 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
5332 * to a particular widget, and gtk_container_set_focus_chain() to
5333 * change the focus tab order. So you may want to investigate those
5334 * functions instead.
5336 * gtk_widget_child_focus() is called by containers as the user moves
5337 * around the window using keyboard shortcuts. @direction indicates
5338 * what kind of motion is taking place (up, down, left, right, tab
5339 * forward, tab backward). gtk_widget_child_focus() invokes the
5340 * "focus" signal on #GtkWidget; widgets override the default handler
5341 * for this signal in order to implement appropriate focus behavior.
5343 * The "focus" default handler for a widget should return %TRUE if
5344 * moving in @direction left the focus on a focusable location inside
5345 * that widget, and %FALSE if moving in @direction moved the focus
5346 * outside the widget. If returning %TRUE, widgets normally
5347 * call gtk_widget_grab_focus() to place the focus accordingly;
5348 * if returning %FALSE, they don't modify the current focus location.
5350 * This function replaces gtk_container_focus() from GTK+ 1.2. It was
5351 * necessary to check that the child was visible, sensitive, and
5352 * focusable before calling
5353 * gtk_container_focus(). gtk_widget_child_focus() returns %FALSE if
5354 * the widget is not currently in a focusable state, so there's no
5355 * need for those checks.
5357 * Return value: %TRUE if focus ended up inside @widget
5360 gtk_widget_child_focus (GtkWidget *widget,
5361 GtkDirectionType direction)
5363 gboolean return_val;
5365 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5367 if (!GTK_WIDGET_VISIBLE (widget) ||
5368 !GTK_WIDGET_IS_SENSITIVE (widget))
5371 /* child widgets must set CAN_FOCUS, containers
5372 * don't have to though.
5374 if (!GTK_IS_CONTAINER (widget) &&
5375 !GTK_WIDGET_CAN_FOCUS (widget))
5378 g_signal_emit (widget,
5379 widget_signals[FOCUS],
5381 direction, &return_val);
5387 * gtk_widget_set_uposition:
5388 * @widget: a #GtkWidget
5389 * @x: x position; -1 to unset x; -2 to leave x unchanged
5390 * @y: y position; -1 to unset y; -2 to leave y unchanged
5393 * Sets the position of a widget. The funny "u" in the name comes from
5394 * the "user position" hint specified by the X Window System, and
5395 * exists for legacy reasons. This function doesn't work if a widget
5396 * is inside a container; it's only really useful on #GtkWindow.
5398 * Don't use this function to center dialogs over the main application
5399 * window; most window managers will do the centering on your behalf
5400 * if you call gtk_window_set_transient_for(), and it's really not
5401 * possible to get the centering to work correctly in all cases from
5402 * application code. But if you insist, use gtk_window_set_position()
5403 * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
5406 * Note that although @x and @y can be individually unset, the position
5407 * is not honoured unless both @x and @y are set.
5410 gtk_widget_set_uposition (GtkWidget *widget,
5414 /* FIXME this function is the only place that aux_info->x and
5415 * aux_info->y are even used I believe, and this function is
5416 * deprecated. Should be cleaned up.
5418 * (Actually, size_allocate uses them) -Yosh
5421 GtkWidgetAuxInfo *aux_info;
5423 g_return_if_fail (GTK_IS_WIDGET (widget));
5425 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
5430 aux_info->x_set = FALSE;
5433 aux_info->x_set = TRUE;
5441 aux_info->y_set = FALSE;
5444 aux_info->y_set = TRUE;
5449 if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
5450 _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
5452 if (GTK_WIDGET_VISIBLE (widget) && widget->parent)
5453 gtk_widget_size_allocate (widget, &widget->allocation);
5457 gtk_widget_set_usize_internal (GtkWidget *widget,
5461 GtkWidgetAuxInfo *aux_info;
5463 g_return_if_fail (GTK_IS_WIDGET (widget));
5465 g_object_freeze_notify (G_OBJECT (widget));
5467 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
5471 g_object_notify (G_OBJECT (widget), "width_request");
5472 aux_info->width = width;
5476 g_object_notify (G_OBJECT (widget), "height_request");
5477 aux_info->height = height;
5480 if (GTK_WIDGET_VISIBLE (widget))
5481 gtk_widget_queue_resize (widget);
5483 g_object_thaw_notify (G_OBJECT (widget));
5487 * gtk_widget_set_usize:
5488 * @widget: a #GtkWidget
5489 * @width: minimum width, or -1 to unset
5490 * @height: minimum height, or -1 to unset
5492 * Sets the minimum size of a widget; that is, the widget's size
5493 * request will be @width by @height. You can use this function to
5494 * force a widget to be either larger or smaller than it is. The
5495 * strange "usize" name dates from the early days of GTK+, and derives
5496 * from X Window System terminology. In many cases,
5497 * gtk_window_set_default_size() is a better choice for toplevel
5498 * windows than this function; setting the default size will still
5499 * allow users to shrink the window. Setting the usize will force them
5500 * to leave the window at least as large as the usize. When dealing
5501 * with window sizes, gtk_window_set_geometry_hints() can be a useful
5504 * Note the inherent danger of setting any fixed size - themes,
5505 * translations into other languages, different fonts, and user action
5506 * can all change the appropriate size for a given widget. So, it's
5507 * basically impossible to hardcode a size that will always be
5510 * @Deprecated: Use gtk_widget_set_size_request() instead.
5513 gtk_widget_set_usize (GtkWidget *widget,
5517 g_return_if_fail (GTK_IS_WIDGET (widget));
5519 gtk_widget_set_usize_internal (widget, width, height);
5523 * gtk_widget_set_size_request:
5524 * @widget: a #GtkWidget
5525 * @width: width @widget should request, or -1 to unset
5526 * @height: height @widget should request, or -1 to unset
5528 * Sets the minimum size of a widget; that is, the widget's size
5529 * request will be @width by @height. You can use this function to
5530 * force a widget to be either larger or smaller than it normally
5533 * In most cases, gtk_window_set_default_size() is a better choice for
5534 * toplevel windows than this function; setting the default size will
5535 * still allow users to shrink the window. Setting the size request
5536 * will force them to leave the window at least as large as the size
5537 * request. When dealing with window sizes,
5538 * gtk_window_set_geometry_hints() can be a useful function as well.
5540 * Note the inherent danger of setting any fixed size - themes,
5541 * translations into other languages, different fonts, and user action
5542 * can all change the appropriate size for a given widget. So, it's
5543 * basically impossible to hardcode a size that will always be
5546 * The size request of a widget is the smallest size a widget can
5547 * accept while still functioning well and drawing itself correctly.
5548 * However in some strange cases a widget may be allocated less than
5549 * its requested size, and in many cases a widget may be allocated more
5550 * space than it requested.
5552 * If the size request in a given direction is -1 (unset), then
5553 * the "natural" size request of the widget will be used instead.
5555 * Widgets can't actually be allocated a size less than 1 by 1, but
5556 * you can pass 0,0 to this function to mean "as small as possible."
5559 gtk_widget_set_size_request (GtkWidget *widget,
5563 g_return_if_fail (GTK_IS_WIDGET (widget));
5564 g_return_if_fail (width >= -1);
5565 g_return_if_fail (height >= -1);
5572 gtk_widget_set_usize_internal (widget, width, height);
5577 * gtk_widget_get_size_request:
5578 * @widget: a #GtkWidget
5579 * @width: return location for width, or %NULL
5580 * @height: return location for height, or %NULL
5582 * Gets the size request that was explicitly set for the widget using
5583 * gtk_widget_set_size_request(). A value of -1 stored in @width or
5584 * @height indicates that that dimension has not been set explicitly
5585 * and the natural requisition of the widget will be used intead. See
5586 * gtk_widget_set_size_request(). To get the size a widget will
5587 * actually use, call gtk_widget_size_request() instead of
5593 gtk_widget_get_size_request (GtkWidget *widget,
5597 GtkWidgetAuxInfo *aux_info;
5599 g_return_if_fail (GTK_IS_WIDGET (widget));
5601 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
5604 *width = aux_info ? aux_info->width : -1;
5607 *height = aux_info ? aux_info->height : -1;
5611 * gtk_widget_set_events:
5612 * @widget: a #GtkWidget
5613 * @events: event mask
5615 * Sets the event mask (see #GdkEventMask) for a widget. The event
5616 * mask determines which events a widget will receive. Keep in mind
5617 * that different widgets have different default event masks, and by
5618 * changing the event mask you may disrupt a widget's functionality,
5619 * so be careful. This function must be called while a widget is
5620 * unrealized. Consider gtk_widget_add_events() for widgets that are
5621 * already realized, or if you want to preserve the existing event
5622 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
5623 * to get events on those widgets, place them inside a #GtkEventBox
5624 * and receive events on the event box.
5628 gtk_widget_set_events (GtkWidget *widget,
5633 g_return_if_fail (GTK_IS_WIDGET (widget));
5634 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
5636 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
5641 eventp = g_new (gint, 1);
5644 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, eventp);
5649 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, NULL);
5652 g_object_notify (G_OBJECT (widget), "events");
5656 * gtk_widget_add_events:
5657 * @widget: a #GtkWidget
5658 * @events: an event mask, see #GdkEventMask
5660 * Adds the events in the bitfield @events to the event mask for
5661 * @widget. See gtk_widget_set_events() for details.
5665 gtk_widget_add_events (GtkWidget *widget,
5670 g_return_if_fail (GTK_IS_WIDGET (widget));
5672 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
5678 eventp = g_new (gint, 1);
5683 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, eventp);
5688 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, NULL);
5691 if (GTK_WIDGET_REALIZED (widget))
5693 if (GTK_WIDGET_NO_WINDOW (widget))
5695 GList *children = gdk_window_get_children (widget->window);
5696 GList *tmp_list = children;
5700 GdkWindow *window = tmp_list->data;
5703 gdk_window_get_user_data (window, &user_data);
5704 if (user_data == widget)
5705 gdk_window_set_events (window, gdk_window_get_events (window) | events);
5706 tmp_list = tmp_list->next;
5709 g_list_free (children);
5713 gdk_window_set_events (widget->window, gdk_window_get_events (widget->window) | events);
5717 g_object_notify (G_OBJECT (widget), "events");
5721 * gtk_widget_set_extension_events:
5722 * @widget: a #GtkWidget
5723 * @mode: bitfield of extension events to receive
5725 * Sets the extension events mask to @mode. See #GdkExtensionMode
5726 * and gdk_input_set_extension_events().
5730 gtk_widget_set_extension_events (GtkWidget *widget,
5731 GdkExtensionMode mode)
5733 GdkExtensionMode *modep;
5735 g_return_if_fail (GTK_IS_WIDGET (widget));
5737 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
5740 modep = g_new (GdkExtensionMode, 1);
5743 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode, modep);
5744 g_object_notify (G_OBJECT (widget), "extension_events");
5748 * gtk_widget_get_toplevel:
5749 * @widget: a #GtkWidget
5751 * This function returns the topmost widget in the container hierarchy
5752 * @widget is a part of. If @widget has no parent widgets, it will be
5753 * returned as the topmost widget. No reference will be added to the
5754 * returned widget; it should not be unreferenced.
5756 * Note the difference in behavior vs. gtk_widget_get_ancestor();
5757 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
5759 * %NULL if @widget wasn't inside a toplevel window, and if the
5760 * window was inside a #GtkWindow-derived widget which was in turn
5761 * inside the toplevel #GtkWindow. While the second case may
5762 * seem unlikely, it actually happens when a #GtkPlug is embedded
5763 * inside a #GtkSocket within the same application.
5765 * To reliably find the toplevel #GtkWindow, use
5766 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
5767 * is set on the result.
5768 * <informalexample><programlisting>
5769 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5770 * if (GTK_WIDGET_TOPLEVEL (toplevel))
5772 * [ Perform action on toplevel. ]
5774 * </programlisting></informalexample>
5776 * Return value: the topmost ancestor of @widget, or @widget itself if there's no ancestor.
5779 gtk_widget_get_toplevel (GtkWidget *widget)
5781 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5783 while (widget->parent)
5784 widget = widget->parent;
5790 * gtk_widget_get_ancestor:
5791 * @widget: a #GtkWidget
5792 * @widget_type: ancestor type
5794 * Gets the first ancestor of @widget with type @widget_type. For example,
5795 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets the
5796 * first #GtkBox that's
5797 * an ancestor of @widget. No reference will be added to the returned widget;
5798 * it should not be unreferenced. See note about checking for a toplevel
5799 * #GtkWindow in the docs for gtk_widget_get_toplevel().
5801 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
5802 * considers @widget to be an ancestor of itself.
5804 * Return value: the ancestor widget, or %NULL if not found
5807 gtk_widget_get_ancestor (GtkWidget *widget,
5810 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5812 while (widget && !g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))
5813 widget = widget->parent;
5815 if (!(widget && g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)))
5822 * gtk_widget_get_colormap:
5823 * @widget: a #GtkWidget
5825 * Gets the colormap that will be used to render @widget. No reference will
5826 * be added to the returned colormap; it should not be unreferenced.
5828 * Return value: the colormap used by @widget
5831 gtk_widget_get_colormap (GtkWidget *widget)
5833 GdkColormap *colormap;
5834 GtkWidget *tmp_widget;
5836 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5840 colormap = gdk_drawable_get_colormap (widget->window);
5841 /* If window was destroyed previously, we'll get NULL here */
5846 tmp_widget = widget;
5849 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
5853 tmp_widget= tmp_widget->parent;
5856 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
5860 * gtk_widget_get_visual:
5861 * @widget: a #GtkWidget
5863 * Gets the visual that will be used to render @widget.
5865 * Return value: the visual for @widget
5868 gtk_widget_get_visual (GtkWidget *widget)
5870 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5872 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
5876 * gtk_widget_get_settings:
5877 * @widget: a #GtkWidget
5879 * Gets the settings object holding the settings (global property
5880 * settings, RC file information, etc) used for this widget.
5882 * Note that this function can only be called when the #GtkWidget
5883 * is attached to a toplevel, since the settings object is specific
5884 * to a particular #GdkScreen.
5886 * Return value: the relevant #GtkSettings object
5889 gtk_widget_get_settings (GtkWidget *widget)
5891 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5893 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
5897 * gtk_widget_set_colormap:
5898 * @widget: a #GtkWidget
5899 * @colormap: a colormap
5901 * Sets the colormap for the widget to the given value. Widget must not
5902 * have been previously realized. This probably should only be used
5903 * from an <function>init()</function> function (i.e. from the constructor
5908 gtk_widget_set_colormap (GtkWidget *widget,
5909 GdkColormap *colormap)
5911 g_return_if_fail (GTK_IS_WIDGET (widget));
5912 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
5913 g_return_if_fail (GDK_IS_COLORMAP (colormap));
5915 g_object_ref (colormap);
5917 g_object_set_qdata_full (G_OBJECT (widget),
5924 * gtk_widget_get_events:
5925 * @widget: a #GtkWidget
5927 * Returns the event mask for the widget (a bitfield containing flags
5928 * from the #GdkEventMask enumeration). These are the events that the widget
5931 * Return value: event mask for @widget
5934 gtk_widget_get_events (GtkWidget *widget)
5938 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
5940 events = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
5948 * gtk_widget_get_extension_events:
5949 * @widget: a #GtkWidget
5951 * Retrieves the extension events the widget will receive; see
5952 * gdk_input_set_extension_events().
5954 * Return value: extension events for @widget
5957 gtk_widget_get_extension_events (GtkWidget *widget)
5959 GdkExtensionMode *mode;
5961 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
5963 mode = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
5971 * gtk_widget_get_pointer:
5972 * @widget: a #GtkWidget
5973 * @x: return location for the X coordinate, or %NULL
5974 * @y: return location for the Y coordinate, or %NULL
5976 * Obtains the location of the mouse pointer in widget coordinates.
5977 * Widget coordinates are a bit odd; for historical reasons, they are
5978 * defined as @widget->window coordinates for widgets that are not
5979 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
5980 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
5984 gtk_widget_get_pointer (GtkWidget *widget,
5988 g_return_if_fail (GTK_IS_WIDGET (widget));
5995 if (GTK_WIDGET_REALIZED (widget))
5997 gdk_window_get_pointer (widget->window, x, y, NULL);
5999 if (GTK_WIDGET_NO_WINDOW (widget))
6002 *x -= widget->allocation.x;
6004 *y -= widget->allocation.y;
6010 * gtk_widget_is_ancestor:
6011 * @widget: a #GtkWidget
6012 * @ancestor: another #GtkWidget
6014 * Determines whether @widget is somewhere inside @ancestor, possibly with
6015 * intermediate containers.
6017 * Return value: %TRUE if @ancestor contains @widget as a child, grandchild, great grandchild, etc.
6020 gtk_widget_is_ancestor (GtkWidget *widget,
6021 GtkWidget *ancestor)
6023 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6024 g_return_val_if_fail (ancestor != NULL, FALSE);
6028 if (widget->parent == ancestor)
6030 widget = widget->parent;
6036 static GQuark quark_composite_name = 0;
6039 * gtk_widget_set_composite_name:
6040 * @widget: a #GtkWidget.
6041 * @name: the name to set.
6043 * Sets a widgets composite name. The widget must be
6044 * a composite child of its parent; see gtk_widget_push_composite_child().
6047 gtk_widget_set_composite_name (GtkWidget *widget,
6050 g_return_if_fail (GTK_IS_WIDGET (widget));
6051 g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget));
6052 g_return_if_fail (name != NULL);
6054 if (!quark_composite_name)
6055 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
6057 g_object_set_qdata_full (G_OBJECT (widget),
6058 quark_composite_name,
6064 * gtk_widget_get_composite_name:
6065 * @widget: a #GtkWidget.
6066 * @returns: the composite name of @widget, or %NULL if @widget is not
6067 * a composite child. The string should not be freed when it is no
6070 * Obtains the composite name of a widget.
6073 gtk_widget_get_composite_name (GtkWidget *widget)
6075 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6077 if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent)
6078 return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
6085 * gtk_widget_push_composite_child:
6087 * Makes all newly-created widgets as composite children until
6088 * the corresponding gtk_widget_pop_composite_child() call.
6090 * A composite child is a child that's an implementation detail of the
6091 * container it's inside and should not be visible to people using the
6092 * container. Composite children aren't treated differently by GTK (but
6093 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
6094 * builders might want to treat them in a different way.
6096 * Here is a simple example:
6097 * <informalexample><programlisting>
6098 * gtk_widget_push_composite_child (<!-- -->);
6099 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
6100 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
6101 * gtk_widget_pop_composite_child (<!-- -->);
6102 * gtk_widget_set_parent (scrolled_window->hscrollbar,
6103 * GTK_WIDGET (scrolled_window));
6104 * g_object_ref (scrolled_window->hscrollbar);
6105 * </programlisting></informalexample>
6108 gtk_widget_push_composite_child (void)
6110 composite_child_stack++;
6114 * gtk_widget_pop_composite_child:
6116 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
6119 gtk_widget_pop_composite_child (void)
6121 if (composite_child_stack)
6122 composite_child_stack--;
6126 * gtk_widget_push_colormap:
6127 * @cmap: a #GdkColormap
6129 * Pushes @cmap onto a global stack of colormaps; the topmost
6130 * colormap on the stack will be used to create all widgets.
6131 * Remove @cmap with gtk_widget_pop_colormap(). There's little
6132 * reason to use this function.
6136 gtk_widget_push_colormap (GdkColormap *cmap)
6138 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
6140 colormap_stack = g_slist_prepend (colormap_stack, cmap);
6144 * gtk_widget_pop_colormap:
6146 * Removes a colormap pushed with gtk_widget_push_colormap().
6150 gtk_widget_pop_colormap (void)
6153 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
6157 * gtk_widget_set_default_colormap:
6158 * @colormap: a #GdkColormap
6160 * Sets the default colormap to use when creating widgets.
6161 * gtk_widget_push_colormap() is a better function to use if
6162 * you only want to affect a few widgets, rather than all widgets.
6165 gtk_widget_set_default_colormap (GdkColormap *colormap)
6167 g_return_if_fail (GDK_IS_COLORMAP (colormap));
6169 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
6174 * gtk_widget_get_default_colormap:
6176 * Obtains the default colormap used to create widgets.
6178 * Return value: default widget colormap
6181 gtk_widget_get_default_colormap (void)
6183 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
6187 * gtk_widget_get_default_visual:
6189 * Obtains the visual of the default colormap. Not really useful;
6190 * used to be useful before gdk_colormap_get_visual() existed.
6192 * Return value: visual of the default colormap
6195 gtk_widget_get_default_visual (void)
6197 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
6201 gtk_widget_emit_direction_changed (GtkWidget *widget,
6202 GtkTextDirection old_dir)
6204 PangoContext *context = gtk_widget_peek_pango_context (widget);
6207 pango_context_set_base_dir (context,
6208 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
6209 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
6211 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
6215 * gtk_widget_set_direction:
6216 * @widget: a #GtkWidget
6217 * @dir: the new direction
6219 * Sets the reading direction on a particular widget. This direction
6220 * controls the primary direction for widgets containing text,
6221 * and also the direction in which the children of a container are
6222 * packed. The ability to set the direction is present in order
6223 * so that correct localization into languages with right-to-left
6224 * reading directions can be done. Generally, applications will
6225 * let the default reading direction present, except for containers
6226 * where the containers are arranged in an order that is explicitely
6227 * visual rather than logical (such as buttons for text justification).
6229 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
6230 * set by gtk_widget_set_default_direction() will be used.
6233 gtk_widget_set_direction (GtkWidget *widget,
6234 GtkTextDirection dir)
6236 GtkTextDirection old_dir;
6238 g_return_if_fail (GTK_IS_WIDGET (widget));
6239 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
6241 old_dir = gtk_widget_get_direction (widget);
6243 if (dir == GTK_TEXT_DIR_NONE)
6244 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
6247 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
6248 if (dir == GTK_TEXT_DIR_LTR)
6249 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
6251 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
6254 if (old_dir != gtk_widget_get_direction (widget))
6255 gtk_widget_emit_direction_changed (widget, old_dir);
6259 * gtk_widget_get_direction:
6260 * @widget: a #GtkWidget
6262 * Gets the reading direction for a particular widget. See
6263 * gtk_widget_set_direction().
6265 * Return value: the reading direction for the widget.
6268 gtk_widget_get_direction (GtkWidget *widget)
6270 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
6272 if (GTK_WIDGET_DIRECTION_SET (widget))
6273 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
6275 return gtk_default_direction;
6279 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
6281 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
6283 g_object_ref (widget);
6285 if (!GTK_WIDGET_DIRECTION_SET (widget))
6286 gtk_widget_emit_direction_changed (widget, old_dir);
6288 if (GTK_IS_CONTAINER (widget))
6289 gtk_container_forall (GTK_CONTAINER (widget),
6290 gtk_widget_set_default_direction_recurse,
6293 g_object_unref (widget);
6297 * gtk_widget_set_default_direction:
6298 * @dir: the new default direction. This cannot be
6299 * %GTK_TEXT_DIR_NONE.
6301 * Sets the default reading direction for widgets where the
6302 * direction has not been explicitly set by gtk_widget_set_direction().
6305 gtk_widget_set_default_direction (GtkTextDirection dir)
6307 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
6309 if (dir != gtk_default_direction)
6311 GList *toplevels, *tmp_list;
6312 GtkTextDirection old_dir = gtk_default_direction;
6314 gtk_default_direction = dir;
6316 tmp_list = toplevels = gtk_window_list_toplevels ();
6317 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
6321 gtk_widget_set_default_direction_recurse (tmp_list->data,
6322 GUINT_TO_POINTER (old_dir));
6323 g_object_unref (tmp_list->data);
6324 tmp_list = tmp_list->next;
6327 g_list_free (toplevels);
6332 * gtk_widget_get_default_direction:
6334 * Obtains the current default reading direction. See
6335 * gtk_widget_set_default_direction().
6337 * Return value: the current default direction.
6340 gtk_widget_get_default_direction (void)
6342 return gtk_default_direction;
6346 gtk_widget_dispose (GObject *object)
6348 GtkWidget *widget = GTK_WIDGET (object);
6351 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
6353 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
6354 if (GTK_WIDGET_REALIZED (widget))
6355 gtk_widget_unrealize (widget);
6357 G_OBJECT_CLASS (parent_class)->dispose (object);
6361 gtk_widget_real_destroy (GtkObject *object)
6363 /* gtk_object_destroy() will already hold a refcount on object */
6364 GtkWidget *widget = GTK_WIDGET (object);
6366 /* wipe accelerator closures (keep order) */
6367 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
6368 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
6370 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
6371 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
6373 gtk_grab_remove (widget);
6375 g_object_unref (widget->style);
6376 widget->style = gtk_widget_get_default_style ();
6377 g_object_ref (widget->style);
6379 GTK_OBJECT_CLASS (parent_class)->destroy (object);
6383 gtk_widget_finalize (GObject *object)
6385 GtkWidget *widget = GTK_WIDGET (object);
6386 GtkWidgetAuxInfo *aux_info;
6388 GdkExtensionMode *mode;
6389 GtkAccessible *accessible;
6391 gtk_grab_remove (widget);
6393 g_object_unref (widget->style);
6394 widget->style = NULL;
6397 g_free (widget->name);
6399 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
6401 gtk_widget_aux_info_destroy (aux_info);
6403 events = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
6407 mode = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
6411 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
6413 g_object_unref (accessible);
6415 G_OBJECT_CLASS (parent_class)->finalize (object);
6418 /*****************************************
6419 * gtk_widget_real_map:
6424 *****************************************/
6427 gtk_widget_real_map (GtkWidget *widget)
6429 g_return_if_fail (GTK_WIDGET_REALIZED (widget) == TRUE);
6431 if (!GTK_WIDGET_MAPPED (widget))
6433 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
6435 if (!GTK_WIDGET_NO_WINDOW (widget))
6436 gdk_window_show (widget->window);
6440 /*****************************************
6441 * gtk_widget_real_unmap:
6446 *****************************************/
6449 gtk_widget_real_unmap (GtkWidget *widget)
6451 if (GTK_WIDGET_MAPPED (widget))
6453 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
6455 if (!GTK_WIDGET_NO_WINDOW (widget))
6456 gdk_window_hide (widget->window);
6460 /*****************************************
6461 * gtk_widget_real_realize:
6466 *****************************************/
6469 gtk_widget_real_realize (GtkWidget *widget)
6471 g_return_if_fail (GTK_WIDGET_NO_WINDOW (widget));
6473 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
6476 widget->window = gtk_widget_get_parent_window (widget);
6477 g_object_ref (widget->window);
6479 widget->style = gtk_style_attach (widget->style, widget->window);
6482 /*****************************************
6483 * gtk_widget_real_unrealize:
6488 *****************************************/
6491 gtk_widget_real_unrealize (GtkWidget *widget)
6493 if (GTK_WIDGET_MAPPED (widget))
6494 gtk_widget_real_unmap (widget);
6496 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
6498 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
6501 /* We must do unrealize child widget BEFORE container widget.
6502 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
6503 * So, unrealizing container widget bofore its children causes the problem
6504 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
6507 if (GTK_IS_CONTAINER (widget))
6508 gtk_container_forall (GTK_CONTAINER (widget),
6509 (GtkCallback) gtk_widget_unrealize,
6512 gtk_style_detach (widget->style);
6513 if (!GTK_WIDGET_NO_WINDOW (widget))
6515 gdk_window_set_user_data (widget->window, NULL);
6516 gdk_window_destroy (widget->window);
6517 widget->window = NULL;
6521 g_object_unref (widget->window);
6522 widget->window = NULL;
6525 gtk_selection_remove_all (widget);
6527 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
6531 gtk_widget_real_size_request (GtkWidget *widget,
6532 GtkRequisition *requisition)
6534 requisition->width = widget->requisition.width;
6535 requisition->height = widget->requisition.height;
6539 * _gtk_widget_peek_colormap:
6541 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
6543 * Return value: the currently pushed colormap, or %NULL if there is none.
6546 _gtk_widget_peek_colormap (void)
6549 return (GdkColormap*) colormap_stack->data;
6554 gtk_widget_propagate_state (GtkWidget *widget,
6559 /* don't call this function with state==GTK_STATE_INSENSITIVE,
6560 * parent_sensitive==TRUE on a sensitive widget
6563 old_state = GTK_WIDGET_STATE (widget);
6565 if (data->parent_sensitive)
6567 GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
6569 if (GTK_WIDGET_IS_SENSITIVE (widget))
6571 if (data->state_restoration)
6572 GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget);
6574 GTK_WIDGET_STATE (widget) = data->state;
6578 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
6579 if (!data->state_restoration &&
6580 data->state != GTK_STATE_INSENSITIVE)
6581 GTK_WIDGET_SAVED_STATE (widget) = data->state;
6586 GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
6587 if (!data->state_restoration)
6589 if (data->state != GTK_STATE_INSENSITIVE)
6590 GTK_WIDGET_SAVED_STATE (widget) = data->state;
6592 else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
6593 GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget);
6594 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
6597 if (gtk_widget_is_focus (widget) && !GTK_WIDGET_IS_SENSITIVE (widget))
6601 window = gtk_widget_get_toplevel (widget);
6602 if (window && GTK_WIDGET_TOPLEVEL (window))
6603 gtk_window_set_focus (GTK_WINDOW (window), NULL);
6606 if (old_state != GTK_WIDGET_STATE (widget))
6608 g_object_ref (widget);
6610 if (!GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_HAS_GRAB (widget))
6611 gtk_grab_remove (widget);
6613 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
6615 if (GTK_IS_CONTAINER (widget))
6617 data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE);
6618 data->state = GTK_WIDGET_STATE (widget);
6619 if (data->use_forall)
6620 gtk_container_forall (GTK_CONTAINER (widget),
6621 (GtkCallback) gtk_widget_propagate_state,
6624 gtk_container_foreach (GTK_CONTAINER (widget),
6625 (GtkCallback) gtk_widget_propagate_state,
6628 g_object_unref (widget);
6633 * _gtk_widget_get_aux_info:
6634 * @widget: a #GtkWidget
6635 * @create: if %TRUE, create the structure if it doesn't exist
6637 * Get the #GtkWidgetAuxInfo structure for the widget.
6639 * Return value: the #GtkAuxInfo structure for the widget, or
6640 * %NULL if @create is %FALSE and one doesn't already exist.
6643 _gtk_widget_get_aux_info (GtkWidget *widget,
6646 GtkWidgetAuxInfo *aux_info;
6648 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
6649 if (!aux_info && create)
6651 if (!aux_info_mem_chunk)
6652 aux_info_mem_chunk = g_mem_chunk_new ("widget aux info mem chunk",
6653 sizeof (GtkWidgetAuxInfo),
6654 1024, G_ALLOC_AND_FREE);
6655 aux_info = g_chunk_new (GtkWidgetAuxInfo, aux_info_mem_chunk);
6657 aux_info->width = -1;
6658 aux_info->height = -1;
6661 aux_info->x_set = FALSE;
6662 aux_info->y_set = FALSE;
6663 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
6669 /*****************************************
6670 * gtk_widget_aux_info_destroy:
6675 *****************************************/
6678 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
6680 g_mem_chunk_free (aux_info_mem_chunk, aux_info);
6684 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
6686 g_object_unref (info->shape_mask);
6691 * gtk_widget_shape_combine_mask:
6692 * @widget: a #GtkWidget.
6693 * @shape_mask: shape to be added, or %NULL to remove an existing shape.
6694 * @offset_x: X position of shape mask with respect to @window.
6695 * @offset_y: Y position of shape mask with respect to @window.
6697 * Sets a shape for this widget's GDK window. This allows for
6698 * transparent windows etc., see gdk_window_shape_combine_mask()
6699 * for more information.
6702 gtk_widget_shape_combine_mask (GtkWidget *widget,
6703 GdkBitmap *shape_mask,
6707 GtkWidgetShapeInfo* shape_info;
6709 g_return_if_fail (GTK_IS_WIDGET (widget));
6710 /* set_shape doesn't work on widgets without gdk window */
6711 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
6715 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
6718 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
6720 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
6724 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
6726 shape_info = g_new (GtkWidgetShapeInfo, 1);
6727 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
6728 (GDestroyNotify) gtk_widget_shape_info_destroy);
6730 shape_info->shape_mask = g_object_ref (shape_mask);
6731 shape_info->offset_x = offset_x;
6732 shape_info->offset_y = offset_y;
6734 /* set shape if widget has a gdk window allready.
6735 * otherwise the shape is scheduled to be set by gtk_widget_realize.
6738 gdk_window_shape_combine_mask (widget->window, shape_mask,
6739 offset_x, offset_y);
6744 gtk_reset_shapes_recurse (GtkWidget *widget,
6750 gdk_window_get_user_data (window, &data);
6754 gdk_window_shape_combine_mask (window, NULL, 0, 0);
6755 for (list = gdk_window_peek_children (window); list; list = list->next)
6756 gtk_reset_shapes_recurse (widget, list->data);
6760 * gtk_widget_reset_shapes:
6761 * @widget: a #GtkWidget.
6763 * Recursively resets the shape on this widget and its descendants.
6766 gtk_widget_reset_shapes (GtkWidget *widget)
6768 g_return_if_fail (GTK_IS_WIDGET (widget));
6769 g_return_if_fail (GTK_WIDGET_REALIZED (widget));
6771 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
6772 gtk_reset_shapes_recurse (widget, widget->window);
6777 * @widget: a #GtkWidget
6779 * Adds a reference to a widget. This function is exactly the same
6780 * as calling g_object_ref(), and exists mostly for historical
6781 * reasons. It can still be convenient to avoid casting a widget
6782 * to a #GObject, it saves a small amount of typing.
6784 * Return value: the widget that was referenced
6787 gtk_widget_ref (GtkWidget *widget)
6789 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6791 return (GtkWidget*) g_object_ref ((GObject*) widget);
6796 * @widget: a #GtkWidget
6798 * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
6802 gtk_widget_unref (GtkWidget *widget)
6804 g_return_if_fail (GTK_IS_WIDGET (widget));
6806 g_object_unref ((GObject*) widget);
6814 * gtk_widget_class_install_style_property_parser:
6815 * @klass: a #GtkWidgetClass
6816 * @pspec: the #GParamSpec for the style property
6817 * @parser: the parser for the style property
6819 * Installs a style property on a widget class.
6822 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
6824 GtkRcPropertyParser parser)
6826 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
6827 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
6828 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
6829 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
6831 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
6833 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
6834 G_OBJECT_CLASS_NAME (klass),
6839 g_param_spec_ref (pspec);
6840 g_param_spec_sink (pspec);
6841 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
6842 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
6846 * gtk_widget_class_install_style_property:
6847 * @klass: a #GtkWidgetClass
6848 * @pspec: the #GParamSpec for the property
6850 * Installs a style property on a widget class. The parser for the
6851 * style property is determined by the value type of @pspec.
6854 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
6857 GtkRcPropertyParser parser;
6859 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
6860 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
6862 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
6864 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
6868 * gtk_widget_class_find_style_property:
6869 * @klass: a #GtkWidgetClass
6870 * @property_name: the name of the style property to find
6871 * @returns: the #GParamSpec of the style property or %NULL if @class has no
6872 * style property with that name.
6874 * Finds a style property of a widget class by name.
6879 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
6880 const gchar *property_name)
6882 g_return_val_if_fail (property_name != NULL, NULL);
6884 return g_param_spec_pool_lookup (style_property_spec_pool,
6886 G_OBJECT_CLASS_TYPE (klass),
6891 * gtk_widget_class_list_style_properties:
6892 * @klass: a #GtkWidgetClass
6893 * @n_properties: location to return the number of style properties found
6894 * @returns: an newly allocated array of #GParamSpec*. The array must be freed with g_free().
6896 * Returns all style properties of a widget class.
6901 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
6902 guint *n_properties)
6904 GParamSpec **pspecs;
6907 pspecs = g_param_spec_pool_list (style_property_spec_pool,
6908 G_OBJECT_CLASS_TYPE (klass),
6917 * gtk_widget_style_get_property:
6918 * @widget: a #GtkWidget
6919 * @property_name: the name of a style property
6920 * @value: location to return the property value
6922 * Gets the value of a style property of @widget.
6925 gtk_widget_style_get_property (GtkWidget *widget,
6926 const gchar *property_name,
6931 g_return_if_fail (GTK_IS_WIDGET (widget));
6932 g_return_if_fail (property_name != NULL);
6933 g_return_if_fail (G_IS_VALUE (value));
6935 g_object_ref (widget);
6936 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
6938 G_OBJECT_TYPE (widget),
6941 g_warning ("%s: widget class `%s' has no property named `%s'",
6943 G_OBJECT_TYPE_NAME (widget),
6947 const GValue *peek_value;
6949 peek_value = _gtk_style_peek_property_value (widget->style,
6950 G_OBJECT_TYPE (widget),
6952 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
6954 /* auto-conversion of the caller's value type
6956 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
6957 g_value_copy (peek_value, value);
6958 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
6959 g_value_transform (peek_value, value);
6961 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
6963 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
6964 G_VALUE_TYPE_NAME (value));
6966 g_object_unref (widget);
6970 * gtk_widget_style_get_valist:
6971 * @widget: a #GtkWidget
6972 * @first_property_name: the name of the first property to get
6973 * @var_args: a <type>va_list</type> of pairs of property names and
6974 * locations to return the property values, starting with the location
6975 * for @first_property_name.
6977 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
6981 gtk_widget_style_get_valist (GtkWidget *widget,
6982 const gchar *first_property_name,
6987 g_return_if_fail (GTK_IS_WIDGET (widget));
6989 g_object_ref (widget);
6991 name = first_property_name;
6994 const GValue *peek_value;
6998 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
7000 G_OBJECT_TYPE (widget),
7004 g_warning ("%s: widget class `%s' has no property named `%s'",
7006 G_OBJECT_TYPE_NAME (widget),
7010 /* style pspecs are always readable so we can spare that check here */
7012 peek_value = _gtk_style_peek_property_value (widget->style,
7013 G_OBJECT_TYPE (widget),
7015 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
7016 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
7019 g_warning ("%s: %s", G_STRLOC, error);
7024 name = va_arg (var_args, gchar*);
7027 g_object_unref (widget);
7031 * gtk_widget_style_get:
7032 * @widget: a #GtkWidget
7033 * @first_property_name: the name of the first property to get
7034 * @Varargs: pairs of property names and locations to
7035 * return the property values, starting with the location for
7036 * @first_property_name, terminated by %NULL.
7038 * Gets the values of a multiple style properties of @widget.
7041 gtk_widget_style_get (GtkWidget *widget,
7042 const gchar *first_property_name,
7047 g_return_if_fail (GTK_IS_WIDGET (widget));
7049 va_start (var_args, first_property_name);
7050 gtk_widget_style_get_valist (widget, first_property_name, var_args);
7056 * @widget: a #GtkWidget
7057 * @path_length: location to store length of the path, or %NULL
7058 * @path: location to store allocated path string, or %NULL
7059 * @path_reversed: location to store allocated reverse path string, or %NULL
7061 * Obtains the full path to @widget. The path is simply the name of a
7062 * widget and all its parents in the container hierarchy, separated by
7063 * periods. The name of a widget comes from
7064 * gtk_widget_get_name(). Paths are used to apply styles to a widget
7065 * in gtkrc configuration files. Widget names are the type of the
7066 * widget by default (e.g. "GtkButton") or can be set to an
7067 * application-specific value with gtk_widget_set_name(). By setting
7068 * the name of a widget, you allow users or theme authors to apply
7069 * styles to that specific widget in their gtkrc
7070 * file. @path_reversed_p fills in the path in reverse order,
7071 * i.e. starting with @widget's name instead of starting with the name
7072 * of @widget's outermost ancestor.
7076 gtk_widget_path (GtkWidget *widget,
7079 gchar **path_reversed)
7081 static gchar *rev_path = NULL;
7082 static guint tmp_path_len = 0;
7085 g_return_if_fail (GTK_IS_WIDGET (widget));
7090 const gchar *string;
7095 string = gtk_widget_get_name (widget);
7096 l = strlen (string);
7097 while (tmp_path_len <= len + l + 1)
7099 tmp_path_len += INIT_PATH_SIZE;
7100 rev_path = g_realloc (rev_path, tmp_path_len);
7108 widget = widget->parent;
7111 rev_path[len++] = '.';
7113 rev_path[len++] = 0;
7118 *path_length = len - 1;
7120 *path_reversed = g_strdup (rev_path);
7123 *path = g_strdup (rev_path);
7124 g_strreverse (*path);
7129 * gtk_widget_class_path:
7130 * @widget: a #GtkWidget
7131 * @path_length: location to store the length of the class path, or %NULL
7132 * @path: location to store the class path as an allocated string, or %NULL
7133 * @path_reversed: location to store the reverse class path as an allocated string, or %NULL
7135 * Same as gtk_widget_path(), but always uses the name of a widget's type,
7136 * never uses a custom name set with gtk_widget_set_name().
7140 gtk_widget_class_path (GtkWidget *widget,
7143 gchar **path_reversed)
7145 static gchar *rev_path = NULL;
7146 static guint tmp_path_len = 0;
7149 g_return_if_fail (GTK_IS_WIDGET (widget));
7154 const gchar *string;
7159 string = g_type_name (GTK_WIDGET_TYPE (widget));
7160 l = strlen (string);
7161 while (tmp_path_len <= len + l + 1)
7163 tmp_path_len += INIT_PATH_SIZE;
7164 rev_path = g_realloc (rev_path, tmp_path_len);
7172 widget = widget->parent;
7175 rev_path[len++] = '.';
7177 rev_path[len++] = 0;
7182 *path_length = len - 1;
7184 *path_reversed = g_strdup (rev_path);
7187 *path = g_strdup (rev_path);
7188 g_strreverse (*path);
7193 * gtk_requisition_copy:
7194 * @requisition: a #GtkRequisition.
7195 * @returns: a copy of @requisition.
7197 * Copies a #GtkRequisition.
7200 gtk_requisition_copy (const GtkRequisition *requisition)
7202 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
7206 * gtk_requisition_free:
7207 * @requisition: a #GtkRequisition.
7209 * Frees a #GtkRequisition.
7212 gtk_requisition_free (GtkRequisition *requisition)
7214 g_free (requisition);
7218 gtk_requisition_get_type (void)
7220 static GType our_type = 0;
7223 our_type = g_boxed_type_register_static ("GtkRequisition",
7224 (GBoxedCopyFunc) gtk_requisition_copy,
7225 (GBoxedFreeFunc) gtk_requisition_free);
7231 gtk_widget_get_accessible (GtkWidget *widget)
7233 GtkWidgetClass *klass;
7235 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7237 klass = GTK_WIDGET_GET_CLASS (widget);
7239 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
7241 return klass->get_accessible (widget);
7245 gtk_widget_real_get_accessible (GtkWidget *widget)
7247 AtkObject* accessible;
7249 accessible = g_object_get_qdata (G_OBJECT (widget),
7250 quark_accessible_object);
7253 AtkObjectFactory *factory;
7254 AtkRegistry *default_registry;
7256 default_registry = atk_get_default_registry ();
7257 factory = atk_registry_get_factory (default_registry,
7258 G_TYPE_FROM_INSTANCE (widget));
7260 atk_object_factory_create_accessible (factory,
7262 g_object_set_qdata (G_OBJECT (widget),
7263 quark_accessible_object,
7270 * Initialize a AtkImplementorIface instance's virtual pointers as
7271 * appropriate to this implementor's class (GtkWidget).
7274 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
7276 iface->ref_accessible = gtk_widget_ref_accessible;
7280 gtk_widget_ref_accessible (AtkImplementor *implementor)
7282 AtkObject *accessible;
7284 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
7286 g_object_ref (accessible);
7291 * gtk_widget_get_clipboard:
7292 * @widget: a #GtkWidget
7293 * @selection: a #GdkAtom which identifies the clipboard
7294 * to use. %GDK_SELECTION_CLIPBOARD gives the
7295 * default clipboard. Another common value
7296 * is %GDK_SELECTION_PRIMARY, which gives
7297 * the primary X selection.
7299 * Returns the clipboard object for the given selection to
7300 * be used with @widget. @widget must have a #GdkDisplay
7301 * associated with it, so must be attached to a toplevel
7304 * Return value: the appropriate clipboard object. If no
7305 * clipboard already exists, a new one will
7306 * be created. Once a clipboard object has
7307 * been created, it is persistent for all time.
7312 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
7314 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7315 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
7317 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
7322 * gtk_widget_list_mnemonic_labels:
7323 * @widget: a #GtkWidget
7325 * Returns a newly allocated list of the widgets, normally labels, for
7326 * which this widget is a the target of a mnemonic (see for example,
7327 * gtk_label_set_mnemonic_widget()).
7329 * The widgets in the list are not individually referenced. If you
7330 * want to iterate through the list and perform actions involving
7331 * callbacks that might destroy the widgets, you
7332 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
7333 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
7334 * widgets afterwards.
7336 * Return value: the list of mnemonic labels; free this list
7337 * with g_list_free() when you are done with it.
7342 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
7347 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7349 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
7350 list = g_list_prepend (list, l->data);
7356 * gtk_widget_add_mnemonic_label:
7357 * @widget: a #GtkWidget
7358 * @label: a #GtkWidget that acts as a mnemonic label for @widget.
7360 * Adds a widget to the list of mnemonic labels for
7361 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
7362 * list of mnemonic labels for the widget is cleared when the
7363 * widget is destroyed, so the caller must make sure to update
7364 * it's internal state at this point as well, by using a connection
7365 * to the ::destroy signal or a weak notifier.
7370 gtk_widget_add_mnemonic_label (GtkWidget *widget,
7373 GSList *old_list, *new_list;
7375 g_return_if_fail (GTK_IS_WIDGET (widget));
7376 g_return_if_fail (GTK_IS_WIDGET (label));
7378 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
7379 new_list = g_slist_prepend (old_list, label);
7381 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
7382 new_list, (GDestroyNotify) g_slist_free);
7386 * gtk_widget_remove_mnemonic_label:
7387 * @widget: a #GtkWidget
7388 * @label: a #GtkWidget that was previously set as a mnemnic label for
7389 * @widget with gtk_widget_add_mnemonic_label().
7391 * Removes a widget from the list of mnemonic labels for
7392 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
7393 * must have previously been added to the list with
7394 * gtk_widget_add_mnemonic_label().
7399 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
7402 GSList *old_list, *new_list;
7404 g_return_if_fail (GTK_IS_WIDGET (widget));
7405 g_return_if_fail (GTK_IS_WIDGET (label));
7407 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
7408 new_list = g_slist_remove (old_list, label);
7411 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
7412 new_list, (GDestroyNotify) g_slist_free);
7416 * gtk_widget_get_no_show_all:
7417 * @widget: a #GtkWidget
7419 * Returns the current value of the "no_show_all" property, which determines
7420 * whether calls to gtk_widget_show_all() and gtk_widget_hide_all()
7421 * will affect this widget.
7423 * Return value: the current value of the "no_show_all" property.
7428 gtk_widget_get_no_show_all (GtkWidget *widget)
7430 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7432 return (GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
7436 * gtk_widget_set_no_show_all:
7437 * @widget: a #GtkWidget
7438 * @no_show_all: the new value for the "no_show_all" property
7440 * Sets the "no_show_all" property, which determines whether calls to
7441 * gtk_widget_show_all() and gtk_widget_hide_all() will affect this widget.
7443 * This is mostly for use in constructing widget hierarchies with externally
7444 * controlled visibility, see #GtkUIManager.
7449 gtk_widget_set_no_show_all (GtkWidget *widget,
7450 gboolean no_show_all)
7452 g_return_if_fail (GTK_IS_WIDGET (widget));
7454 no_show_all = (no_show_all != FALSE);
7456 if (no_show_all == ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0))
7460 GTK_WIDGET_SET_FLAGS (widget, GTK_NO_SHOW_ALL);
7462 GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_SHOW_ALL);
7464 g_object_notify (G_OBJECT (widget), "no_show_all");