1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include "gtkcontainer.h"
32 #include "gtkaccelmap.h"
33 #include "gtkclipboard.h"
34 #include "gtkiconfactory.h"
37 #include "gtkmarshalers.h"
39 #include "gtkselection.h"
40 #include "gtksettings.h"
41 #include "gtksizegroup.h"
42 #include "gtkwidget.h"
43 #include "gtkwindow.h"
44 #include "gtkbindings.h"
45 #include "gtkprivate.h"
47 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
48 #include <gobject/gvaluecollector.h>
49 #include <gobject/gobjectnotifyqueue.c>
50 #include "gdk/gdkkeysyms.h"
52 #include "gtkaccessible.h"
53 #include "gtktooltips.h"
54 #include "gtkinvisible.h"
57 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
58 #define INIT_PATH_SIZE (512)
98 PROPERTY_NOTIFY_EVENT,
99 SELECTION_CLEAR_EVENT,
100 SELECTION_REQUEST_EVENT,
101 SELECTION_NOTIFY_EVENT,
116 VISIBILITY_NOTIFY_EVENT,
120 ACCEL_CLOSURES_CHANGED,
141 PROP_RECEIVES_DEFAULT,
142 PROP_COMPOSITE_CHILD,
145 PROP_EXTENSION_EVENTS,
149 typedef struct _GtkStateData GtkStateData;
154 guint state_restoration : 1;
155 guint parent_sensitive : 1;
156 guint use_forall : 1;
160 /* --- prototypes --- */
161 static void gtk_widget_class_init (GtkWidgetClass *klass);
162 static void gtk_widget_init (GtkWidget *widget);
163 static void gtk_widget_set_property (GObject *object,
167 static void gtk_widget_get_property (GObject *object,
171 static void gtk_widget_dispose (GObject *object);
172 static void gtk_widget_real_destroy (GtkObject *object);
173 static void gtk_widget_finalize (GObject *object);
174 static void gtk_widget_real_show (GtkWidget *widget);
175 static void gtk_widget_real_hide (GtkWidget *widget);
176 static void gtk_widget_real_map (GtkWidget *widget);
177 static void gtk_widget_real_unmap (GtkWidget *widget);
178 static void gtk_widget_real_realize (GtkWidget *widget);
179 static void gtk_widget_real_unrealize (GtkWidget *widget);
180 static void gtk_widget_real_size_request (GtkWidget *widget,
181 GtkRequisition *requisition);
182 static void gtk_widget_real_size_allocate (GtkWidget *widget,
183 GtkAllocation *allocation);
184 static void gtk_widget_style_set (GtkWidget *widget,
185 GtkStyle *previous_style);
186 static void gtk_widget_direction_changed (GtkWidget *widget,
187 GtkTextDirection previous_direction);
189 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
190 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
191 GtkWidgetHelpType help_type);
193 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
195 GParamSpec **pspecs);
196 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
198 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
200 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
201 GdkEventFocus *event);
202 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
203 GdkEventFocus *event);
204 static gboolean gtk_widget_real_focus (GtkWidget *widget,
205 GtkDirectionType direction);
206 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
207 static void gtk_widget_update_pango_context (GtkWidget *widget);
208 static void gtk_widget_propagate_state (GtkWidget *widget,
210 static void gtk_widget_reset_rc_style (GtkWidget *widget);
211 static void gtk_widget_set_style_internal (GtkWidget *widget,
213 gboolean initial_emission);
214 static gint gtk_widget_event_internal (GtkWidget *widget,
216 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
217 gboolean group_cycling);
218 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
219 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
220 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
221 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
222 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
224 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
225 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
226 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
229 static void gtk_widget_set_usize_internal (GtkWidget *widget,
232 static void gtk_widget_get_draw_rectangle (GtkWidget *widget,
236 /* --- variables --- */
237 static gpointer parent_class = NULL;
238 static guint widget_signals[LAST_SIGNAL] = { 0 };
239 static GMemChunk *aux_info_mem_chunk = NULL;
240 static GtkStyle *gtk_default_style = NULL;
241 static GSList *colormap_stack = NULL;
242 static guint composite_child_stack = 0;
243 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
244 static GParamSpecPool *style_property_spec_pool = NULL;
246 static GQuark quark_property_parser = 0;
247 static GQuark quark_aux_info = 0;
248 static GQuark quark_accel_path = 0;
249 static GQuark quark_accel_closures = 0;
250 static GQuark quark_event_mask = 0;
251 static GQuark quark_extension_event_mode = 0;
252 static GQuark quark_parent_window = 0;
253 static GQuark quark_shape_info = 0;
254 static GQuark quark_colormap = 0;
255 static GQuark quark_pango_context = 0;
256 static GQuark quark_rc_style = 0;
257 static GQuark quark_accessible_object = 0;
258 static GQuark quark_mnemonic_labels = 0;
259 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
260 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
262 /* --- functions --- */
264 gtk_widget_get_type (void)
266 static GType widget_type = 0;
270 static const GTypeInfo widget_info =
272 sizeof (GtkWidgetClass),
273 NULL, /* base_init */
274 NULL, /* base_finalize */
275 (GClassInitFunc) gtk_widget_class_init,
276 NULL, /* class_finalize */
277 NULL, /* class_init */
280 (GInstanceInitFunc) gtk_widget_init,
281 NULL, /* value_table */
284 static const GInterfaceInfo accessibility_info =
286 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
287 (GInterfaceFinalizeFunc) NULL,
288 NULL /* interface data */
291 widget_type = g_type_register_static (GTK_TYPE_OBJECT, I_("GtkWidget"),
292 &widget_info, G_TYPE_FLAG_ABSTRACT);
294 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
295 &accessibility_info) ;
303 child_property_notify_dispatcher (GObject *object,
307 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
311 gtk_widget_class_init (GtkWidgetClass *klass)
313 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
314 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
315 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
316 GtkBindingSet *binding_set;
318 parent_class = g_type_class_peek_parent (klass);
320 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
321 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
322 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
323 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
324 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
325 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
326 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
327 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
328 quark_colormap = g_quark_from_static_string ("gtk-colormap");
329 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
330 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
331 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
332 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
334 style_property_spec_pool = g_param_spec_pool_new (FALSE);
335 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
336 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
337 cpn_context.dispatcher = child_property_notify_dispatcher;
338 _gtk_widget_child_property_notify_context = &cpn_context;
340 gobject_class->dispose = gtk_widget_dispose;
341 gobject_class->finalize = gtk_widget_finalize;
342 gobject_class->set_property = gtk_widget_set_property;
343 gobject_class->get_property = gtk_widget_get_property;
345 object_class->destroy = gtk_widget_real_destroy;
347 klass->activate_signal = 0;
348 klass->set_scroll_adjustments_signal = 0;
349 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
350 klass->show = gtk_widget_real_show;
351 klass->show_all = gtk_widget_show;
352 klass->hide = gtk_widget_real_hide;
353 klass->hide_all = gtk_widget_hide;
354 klass->map = gtk_widget_real_map;
355 klass->unmap = gtk_widget_real_unmap;
356 klass->realize = gtk_widget_real_realize;
357 klass->unrealize = gtk_widget_real_unrealize;
358 klass->size_request = gtk_widget_real_size_request;
359 klass->size_allocate = gtk_widget_real_size_allocate;
360 klass->state_changed = NULL;
361 klass->parent_set = NULL;
362 klass->hierarchy_changed = NULL;
363 klass->style_set = gtk_widget_style_set;
364 klass->direction_changed = gtk_widget_direction_changed;
365 klass->grab_notify = NULL;
366 klass->child_notify = NULL;
367 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
368 klass->grab_focus = gtk_widget_real_grab_focus;
369 klass->focus = gtk_widget_real_focus;
371 klass->button_press_event = NULL;
372 klass->button_release_event = NULL;
373 klass->motion_notify_event = NULL;
374 klass->delete_event = NULL;
375 klass->destroy_event = NULL;
376 klass->expose_event = NULL;
377 klass->key_press_event = gtk_widget_real_key_press_event;
378 klass->key_release_event = gtk_widget_real_key_release_event;
379 klass->enter_notify_event = NULL;
380 klass->leave_notify_event = NULL;
381 klass->configure_event = NULL;
382 klass->focus_in_event = gtk_widget_real_focus_in_event;
383 klass->focus_out_event = gtk_widget_real_focus_out_event;
384 klass->map_event = NULL;
385 klass->unmap_event = NULL;
386 klass->window_state_event = NULL;
387 klass->property_notify_event = _gtk_selection_property_notify;
388 klass->selection_clear_event = gtk_selection_clear;
389 klass->selection_request_event = _gtk_selection_request;
390 klass->selection_notify_event = _gtk_selection_notify;
391 klass->selection_received = NULL;
392 klass->proximity_in_event = NULL;
393 klass->proximity_out_event = NULL;
394 klass->drag_begin = NULL;
395 klass->drag_end = NULL;
396 klass->drag_data_delete = NULL;
397 klass->drag_leave = NULL;
398 klass->drag_motion = NULL;
399 klass->drag_drop = NULL;
400 klass->drag_data_received = NULL;
401 klass->screen_changed = NULL;
402 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
403 klass->grab_broken_event = NULL;
405 klass->show_help = gtk_widget_real_show_help;
407 /* Accessibility support */
408 klass->get_accessible = gtk_widget_real_get_accessible;
410 klass->no_expose_event = NULL;
412 g_object_class_install_property (gobject_class,
414 g_param_spec_string ("name",
416 P_("The name of the widget"),
418 GTK_PARAM_READWRITE));
419 g_object_class_install_property (gobject_class,
421 g_param_spec_object ("parent",
423 P_("The parent widget of this widget. Must be a Container widget"),
425 GTK_PARAM_READWRITE));
427 g_object_class_install_property (gobject_class,
429 g_param_spec_int ("width-request",
431 P_("Override for width request of the widget, or -1 if natural request should be used"),
435 GTK_PARAM_READWRITE));
436 g_object_class_install_property (gobject_class,
438 g_param_spec_int ("height-request",
439 P_("Height request"),
440 P_("Override for height request of the widget, or -1 if natural request should be used"),
444 GTK_PARAM_READWRITE));
445 g_object_class_install_property (gobject_class,
447 g_param_spec_boolean ("visible",
449 P_("Whether the widget is visible"),
451 GTK_PARAM_READWRITE));
452 g_object_class_install_property (gobject_class,
454 g_param_spec_boolean ("sensitive",
456 P_("Whether the widget responds to input"),
458 GTK_PARAM_READWRITE));
459 g_object_class_install_property (gobject_class,
461 g_param_spec_boolean ("app-paintable",
462 P_("Application paintable"),
463 P_("Whether the application will paint directly on the widget"),
465 GTK_PARAM_READWRITE));
466 g_object_class_install_property (gobject_class,
468 g_param_spec_boolean ("can-focus",
470 P_("Whether the widget can accept the input focus"),
472 GTK_PARAM_READWRITE));
473 g_object_class_install_property (gobject_class,
475 g_param_spec_boolean ("has-focus",
477 P_("Whether the widget has the input focus"),
479 GTK_PARAM_READWRITE));
480 g_object_class_install_property (gobject_class,
482 g_param_spec_boolean ("is-focus",
484 P_("Whether the widget is the focus widget within the toplevel"),
486 GTK_PARAM_READWRITE));
487 g_object_class_install_property (gobject_class,
489 g_param_spec_boolean ("can-default",
491 P_("Whether the widget can be the default widget"),
493 GTK_PARAM_READWRITE));
494 g_object_class_install_property (gobject_class,
496 g_param_spec_boolean ("has-default",
498 P_("Whether the widget is the default widget"),
500 GTK_PARAM_READWRITE));
501 g_object_class_install_property (gobject_class,
502 PROP_RECEIVES_DEFAULT,
503 g_param_spec_boolean ("receives-default",
504 P_("Receives default"),
505 P_("If TRUE, the widget will receive the default action when it is focused"),
507 GTK_PARAM_READWRITE));
508 g_object_class_install_property (gobject_class,
509 PROP_COMPOSITE_CHILD,
510 g_param_spec_boolean ("composite-child",
511 P_("Composite child"),
512 P_("Whether the widget is part of a composite widget"),
514 GTK_PARAM_READABLE));
515 g_object_class_install_property (gobject_class,
517 g_param_spec_object ("style",
519 P_("The style of the widget, which contains information about how it will look (colors etc)"),
521 GTK_PARAM_READWRITE));
522 g_object_class_install_property (gobject_class,
524 g_param_spec_flags ("events",
526 P_("The event mask that decides what kind of GdkEvents this widget gets"),
529 GTK_PARAM_READWRITE));
530 g_object_class_install_property (gobject_class,
531 PROP_EXTENSION_EVENTS,
532 g_param_spec_enum ("extension-events",
533 P_("Extension events"),
534 P_("The mask that decides what kind of extension events this widget gets"),
535 GDK_TYPE_EXTENSION_MODE,
536 GDK_EXTENSION_EVENTS_NONE,
537 GTK_PARAM_READWRITE));
538 g_object_class_install_property (gobject_class,
540 g_param_spec_boolean ("no-show-all",
542 P_("Whether gtk_widget_show_all() should not affect this widget"),
544 GTK_PARAM_READWRITE));
545 widget_signals[SHOW] =
546 g_signal_new (I_("show"),
547 G_TYPE_FROM_CLASS (gobject_class),
549 G_STRUCT_OFFSET (GtkWidgetClass, show),
551 _gtk_marshal_VOID__VOID,
553 widget_signals[HIDE] =
554 g_signal_new (I_("hide"),
555 G_TYPE_FROM_CLASS (gobject_class),
557 G_STRUCT_OFFSET (GtkWidgetClass, hide),
559 _gtk_marshal_VOID__VOID,
561 widget_signals[MAP] =
562 g_signal_new (I_("map"),
563 G_TYPE_FROM_CLASS (gobject_class),
565 G_STRUCT_OFFSET (GtkWidgetClass, map),
567 _gtk_marshal_VOID__VOID,
569 widget_signals[UNMAP] =
570 g_signal_new (I_("unmap"),
571 G_TYPE_FROM_CLASS (gobject_class),
573 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
575 _gtk_marshal_VOID__VOID,
577 widget_signals[REALIZE] =
578 g_signal_new (I_("realize"),
579 G_TYPE_FROM_CLASS (gobject_class),
581 G_STRUCT_OFFSET (GtkWidgetClass, realize),
583 _gtk_marshal_VOID__VOID,
585 widget_signals[UNREALIZE] =
586 g_signal_new (I_("unrealize"),
587 G_TYPE_FROM_CLASS (gobject_class),
589 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
591 _gtk_marshal_VOID__VOID,
593 widget_signals[SIZE_REQUEST] =
594 g_signal_new (I_("size_request"),
595 G_TYPE_FROM_CLASS (gobject_class),
597 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
599 _gtk_marshal_VOID__BOXED,
601 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
602 widget_signals[SIZE_ALLOCATE] =
603 g_signal_new (I_("size_allocate"),
604 G_TYPE_FROM_CLASS (gobject_class),
606 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
608 _gtk_marshal_VOID__BOXED,
610 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
611 widget_signals[STATE_CHANGED] =
612 g_signal_new (I_("state_changed"),
613 G_TYPE_FROM_CLASS (gobject_class),
615 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
617 _gtk_marshal_VOID__ENUM,
619 GTK_TYPE_STATE_TYPE);
620 widget_signals[PARENT_SET] =
621 g_signal_new (I_("parent_set"),
622 G_TYPE_FROM_CLASS (gobject_class),
624 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
626 _gtk_marshal_VOID__OBJECT,
629 widget_signals[HIERARCHY_CHANGED] =
630 g_signal_new (I_("hierarchy_changed"),
631 G_TYPE_FROM_CLASS (gobject_class),
633 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
635 _gtk_marshal_VOID__OBJECT,
639 * GtkWidget::style-set:
640 * @widget: the object on which the signal is emitted
641 * @previous_style: the previous style, or %NULL if the widget
642 * just got its initial style
644 * The style-set signal is emitted when a new style has been set
645 * on a widget. Note that style-modifying functions like
646 * gtk_widget_modify_base() also cause this signal to be emitted.
648 widget_signals[STYLE_SET] =
649 g_signal_new (I_("style_set"),
650 G_TYPE_FROM_CLASS (gobject_class),
652 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
654 _gtk_marshal_VOID__OBJECT,
657 widget_signals[DIRECTION_CHANGED] =
658 g_signal_new (I_("direction_changed"),
659 G_TYPE_FROM_CLASS (gobject_class),
661 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
663 _gtk_marshal_VOID__ENUM,
665 GTK_TYPE_TEXT_DIRECTION);
666 widget_signals[GRAB_NOTIFY] =
667 g_signal_new (I_("grab_notify"),
668 G_TYPE_FROM_CLASS (gobject_class),
670 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
672 _gtk_marshal_VOID__BOOLEAN,
677 * GtkWidget::child-notify:
678 * @widget: the object which received the signal.
679 * @pspec: the #GParamSpec of the changed child property.
681 * The ::child-notify signal is emitted for each child property that has
682 * changed on an object. The signal's detail holds the property name.
684 widget_signals[CHILD_NOTIFY] =
685 g_signal_new (I_("child_notify"),
686 G_TYPE_FROM_CLASS (gobject_class),
687 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
688 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
690 g_cclosure_marshal_VOID__PARAM,
693 widget_signals[MNEMONIC_ACTIVATE] =
694 g_signal_new (I_("mnemonic_activate"),
695 G_TYPE_FROM_CLASS (gobject_class),
697 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
698 _gtk_boolean_handled_accumulator, NULL,
699 _gtk_marshal_BOOLEAN__BOOLEAN,
702 widget_signals[GRAB_FOCUS] =
703 g_signal_new (I_("grab_focus"),
704 G_TYPE_FROM_CLASS (gobject_class),
705 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
706 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
708 _gtk_marshal_VOID__VOID,
710 widget_signals[FOCUS] =
711 g_signal_new (I_("focus"),
712 G_TYPE_FROM_CLASS (object_class),
714 G_STRUCT_OFFSET (GtkWidgetClass, focus),
715 _gtk_boolean_handled_accumulator, NULL,
716 _gtk_marshal_BOOLEAN__ENUM,
718 GTK_TYPE_DIRECTION_TYPE);
719 widget_signals[EVENT] =
720 g_signal_new (I_("event"),
721 G_TYPE_FROM_CLASS (gobject_class),
723 G_STRUCT_OFFSET (GtkWidgetClass, event),
724 _gtk_boolean_handled_accumulator, NULL,
725 _gtk_marshal_BOOLEAN__BOXED,
727 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
728 widget_signals[EVENT_AFTER] =
729 g_signal_new (I_("event-after"),
730 G_TYPE_FROM_CLASS (gobject_class),
734 _gtk_marshal_VOID__BOXED,
736 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
737 widget_signals[BUTTON_PRESS_EVENT] =
738 g_signal_new (I_("button_press_event"),
739 G_TYPE_FROM_CLASS (gobject_class),
741 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
742 _gtk_boolean_handled_accumulator, NULL,
743 _gtk_marshal_BOOLEAN__BOXED,
745 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
746 widget_signals[BUTTON_RELEASE_EVENT] =
747 g_signal_new (I_("button_release_event"),
748 G_TYPE_FROM_CLASS (gobject_class),
750 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
751 _gtk_boolean_handled_accumulator, NULL,
752 _gtk_marshal_BOOLEAN__BOXED,
754 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
755 widget_signals[SCROLL_EVENT] =
756 g_signal_new (I_("scroll_event"),
757 G_TYPE_FROM_CLASS (gobject_class),
759 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
760 _gtk_boolean_handled_accumulator, NULL,
761 _gtk_marshal_BOOLEAN__BOXED,
763 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
764 widget_signals[MOTION_NOTIFY_EVENT] =
765 g_signal_new (I_("motion_notify_event"),
766 G_TYPE_FROM_CLASS (gobject_class),
768 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
769 _gtk_boolean_handled_accumulator, NULL,
770 _gtk_marshal_BOOLEAN__BOXED,
772 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
775 * GtkWidget::delete-event:
776 * @widget: the object which received the signal.
777 * @event: the event which triggered this signal
779 * The ::delete-event signal is emitted if a user requests that
780 * a toplevel window is closed. The default handler for this signal
781 * destroys the window. Connecting gtk_widget_hide_on_delete() to
782 * this signal will cause the window to be hidden instead, so that
783 * it can later be shown again without reconstructing it.
785 * Returns: %TRUE to stop other handlers from being invoked for the event.
786 * %FALSE to propagate the event further.
788 widget_signals[DELETE_EVENT] =
789 g_signal_new (I_("delete_event"),
790 G_TYPE_FROM_CLASS (gobject_class),
792 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
793 _gtk_boolean_handled_accumulator, NULL,
794 _gtk_marshal_BOOLEAN__BOXED,
796 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
799 * GtkWidget::destroy-event:
800 * @widget: the object which received the signal.
801 * @event: the event which triggered this signal
803 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
804 * You rarely get this signal, because most widgets disconnect themselves
805 * from their window before they destroy it, so no widget owns the
806 * window at destroy time.
808 * Returns: %TRUE to stop other handlers from being invoked for the event.
809 * %FALSE to propagate the event further.
811 widget_signals[DESTROY_EVENT] =
812 g_signal_new (I_("destroy_event"),
813 G_TYPE_FROM_CLASS (gobject_class),
815 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
816 _gtk_boolean_handled_accumulator, NULL,
817 _gtk_marshal_BOOLEAN__BOXED,
819 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
820 widget_signals[EXPOSE_EVENT] =
821 g_signal_new (I_("expose_event"),
822 G_TYPE_FROM_CLASS (gobject_class),
824 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
825 _gtk_boolean_handled_accumulator, NULL,
826 _gtk_marshal_BOOLEAN__BOXED,
828 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
829 widget_signals[KEY_PRESS_EVENT] =
830 g_signal_new (I_("key_press_event"),
831 G_TYPE_FROM_CLASS (gobject_class),
833 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
834 _gtk_boolean_handled_accumulator, NULL,
835 _gtk_marshal_BOOLEAN__BOXED,
837 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
838 widget_signals[KEY_RELEASE_EVENT] =
839 g_signal_new (I_("key_release_event"),
840 G_TYPE_FROM_CLASS (gobject_class),
842 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
843 _gtk_boolean_handled_accumulator, NULL,
844 _gtk_marshal_BOOLEAN__BOXED,
846 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
847 widget_signals[ENTER_NOTIFY_EVENT] =
848 g_signal_new (I_("enter_notify_event"),
849 G_TYPE_FROM_CLASS (gobject_class),
851 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
852 _gtk_boolean_handled_accumulator, NULL,
853 _gtk_marshal_BOOLEAN__BOXED,
855 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
856 widget_signals[LEAVE_NOTIFY_EVENT] =
857 g_signal_new (I_("leave_notify_event"),
858 G_TYPE_FROM_CLASS (gobject_class),
860 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
861 _gtk_boolean_handled_accumulator, NULL,
862 _gtk_marshal_BOOLEAN__BOXED,
864 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
865 widget_signals[CONFIGURE_EVENT] =
866 g_signal_new (I_("configure_event"),
867 G_TYPE_FROM_CLASS (gobject_class),
869 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
870 _gtk_boolean_handled_accumulator, NULL,
871 _gtk_marshal_BOOLEAN__BOXED,
873 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
874 widget_signals[FOCUS_IN_EVENT] =
875 g_signal_new (I_("focus_in_event"),
876 G_TYPE_FROM_CLASS (gobject_class),
878 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
879 _gtk_boolean_handled_accumulator, NULL,
880 _gtk_marshal_BOOLEAN__BOXED,
882 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
883 widget_signals[FOCUS_OUT_EVENT] =
884 g_signal_new (I_("focus_out_event"),
885 G_TYPE_FROM_CLASS (gobject_class),
887 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
888 _gtk_boolean_handled_accumulator, NULL,
889 _gtk_marshal_BOOLEAN__BOXED,
891 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
892 widget_signals[MAP_EVENT] =
893 g_signal_new (I_("map_event"),
894 G_TYPE_FROM_CLASS (gobject_class),
896 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
897 _gtk_boolean_handled_accumulator, NULL,
898 _gtk_marshal_BOOLEAN__BOXED,
900 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
901 widget_signals[UNMAP_EVENT] =
902 g_signal_new (I_("unmap_event"),
903 G_TYPE_FROM_CLASS (gobject_class),
905 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
906 _gtk_boolean_handled_accumulator, NULL,
907 _gtk_marshal_BOOLEAN__BOXED,
909 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
910 widget_signals[PROPERTY_NOTIFY_EVENT] =
911 g_signal_new (I_("property_notify_event"),
912 G_TYPE_FROM_CLASS (gobject_class),
914 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
915 _gtk_boolean_handled_accumulator, NULL,
916 _gtk_marshal_BOOLEAN__BOXED,
918 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
919 widget_signals[SELECTION_CLEAR_EVENT] =
920 g_signal_new (I_("selection_clear_event"),
921 G_TYPE_FROM_CLASS (gobject_class),
923 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
924 _gtk_boolean_handled_accumulator, NULL,
925 _gtk_marshal_BOOLEAN__BOXED,
927 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
928 widget_signals[SELECTION_REQUEST_EVENT] =
929 g_signal_new (I_("selection_request_event"),
930 G_TYPE_FROM_CLASS (gobject_class),
932 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
933 _gtk_boolean_handled_accumulator, NULL,
934 _gtk_marshal_BOOLEAN__BOXED,
936 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
937 widget_signals[SELECTION_NOTIFY_EVENT] =
938 g_signal_new (I_("selection_notify_event"),
939 G_TYPE_FROM_CLASS (gobject_class),
941 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
942 _gtk_boolean_handled_accumulator, NULL,
943 _gtk_marshal_BOOLEAN__BOXED,
945 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
946 widget_signals[SELECTION_RECEIVED] =
947 g_signal_new (I_("selection_received"),
948 G_TYPE_FROM_CLASS (gobject_class),
950 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
952 _gtk_marshal_VOID__BOXED_UINT,
954 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
956 widget_signals[SELECTION_GET] =
957 g_signal_new (I_("selection_get"),
958 G_TYPE_FROM_CLASS (gobject_class),
960 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
962 _gtk_marshal_VOID__BOXED_UINT_UINT,
964 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
967 widget_signals[PROXIMITY_IN_EVENT] =
968 g_signal_new (I_("proximity_in_event"),
969 G_TYPE_FROM_CLASS (gobject_class),
971 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
972 _gtk_boolean_handled_accumulator, NULL,
973 _gtk_marshal_BOOLEAN__BOXED,
975 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
976 widget_signals[PROXIMITY_OUT_EVENT] =
977 g_signal_new (I_("proximity_out_event"),
978 G_TYPE_FROM_CLASS (gobject_class),
980 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
981 _gtk_boolean_handled_accumulator, NULL,
982 _gtk_marshal_BOOLEAN__BOXED,
984 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
987 * GtkWidget::drag-leave:
988 * @widget: the object which received the signal.
989 * @drag_context: the drag context
990 * @time: the timestamp of the motion event
992 * The ::drag-leave signal is emitted on the drop site when the cursor leaves the widget.
993 * A typical reason to connect to this signal is to undo things done in ::drag-motion, e.g.
994 * undo highlighting with gtk_drag_unhighlight()
996 widget_signals[DRAG_LEAVE] =
997 g_signal_new (I_("drag_leave"),
998 G_TYPE_FROM_CLASS (gobject_class),
1000 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
1002 _gtk_marshal_VOID__OBJECT_UINT,
1004 GDK_TYPE_DRAG_CONTEXT,
1008 * GtkWidget::drag-begin:
1009 * @widget: the object which received the signal.
1010 * @drag_context: the drag context
1012 * The ::drag-begin signal is emitted on the drag source when a drag is started.
1013 * A typical reason to connect to this signal is to set up a custom drag icon with
1014 * gtk_drag_source_set_icon().
1016 widget_signals[DRAG_BEGIN] =
1017 g_signal_new (I_("drag_begin"),
1018 G_TYPE_FROM_CLASS (gobject_class),
1020 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
1022 _gtk_marshal_VOID__OBJECT,
1024 GDK_TYPE_DRAG_CONTEXT);
1027 * GtkWidget::drag-end:
1028 * @widget: the object which received the signal.
1029 * @drag_context: the drag context
1031 * The ::drag-end signal is emitted on the drag source when a drag is finished.
1032 * A typical reason to connect to this signal is to undo things done in ::drag-begin.
1034 widget_signals[DRAG_END] =
1035 g_signal_new (I_("drag_end"),
1036 G_TYPE_FROM_CLASS (gobject_class),
1038 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
1040 _gtk_marshal_VOID__OBJECT,
1042 GDK_TYPE_DRAG_CONTEXT);
1045 * GtkWidget::drag-data-delete:
1046 * @widget: the object which received the signal.
1047 * @drag_context: the drag context
1049 * The ::drag-data-delete signal is emitted on the drag source when a drag with the action
1050 * %GDK_ACTION_MOVE is successfully completed. The signal handler is responsible for deleting
1051 * the data that has been dropped. What "delete" means, depends on the context of the drag
1054 widget_signals[DRAG_DATA_DELETE] =
1055 g_signal_new (I_("drag_data_delete"),
1056 G_TYPE_FROM_CLASS (gobject_class),
1058 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
1060 _gtk_marshal_VOID__OBJECT,
1062 GDK_TYPE_DRAG_CONTEXT);
1065 * GtkWidget::drag-motion:
1066 * @widget: the object which received the signal.
1067 * @drag_context: the drag context
1068 * @x: the x coordinate of the current cursor position
1069 * @y: the y coordinate of the current cursor position
1070 * @time: the timestamp of the motion event
1071 * @returns: whether the cursor position is in a drop zone
1073 * The ::drag-motion signal is emitted on the drop site when the user moves the cursor over
1074 * the widget during a drag. The signal handler must determine whether the cursor position is in
1075 * a drop zone or not. If it is not in a drop zone, it returns %FALSE and no further processing is
1076 * necessary. Otherwise, the handler returns %TRUE. In this case, the handler is responsible for
1077 * providing the necessary information for displaying feedback to the user, by calling
1078 * gdk_drag_status(). If the decision whether the drop will be accepted or rejected can't be made
1079 * based solely on the cursor position and the type of the data, the handler may inspect the dragged
1080 * data by calling gtk_drag_get_data() and defer the gdk_drag_status() call to the ::drag-data-received
1083 * Note that there is no ::drag-enter signal. The drag receiver has to keep track of whether
1084 * he has received any ::drag-motion signals since the last ::drag-leave and if not, treat the
1085 * ::drag-motion signal as an "enter" signal. Upon an "enter", the handler will typically highlight
1086 * the drop site with gtk_drag_highlight().
1088 * <informalexample><programlisting>
1090 * drag_motion (GtkWidget *widget,
1091 * GdkDragContext *context,
1098 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1100 * if (!private_data->drag_highlight)
1102 * private_data->drag_highlight = 1;
1103 * gtk_drag_highlight (widget);
1106 * target = gtk_drag_dest_find_target (widget, context, NULL);
1107 * if (target == GDK_NONE)
1108 * gdk_drag_status (context, 0, time);
1111 * private_data->pending_status = context->suggested_action;
1112 * gtk_drag_get_data (widget, context, target, time);
1119 * drag_data_received (GtkWidget *widget,
1120 * GdkDragContext *context,
1123 * GtkSelectionData *selection_data,
1127 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1129 * if (private_data->suggested_action)
1131 * private_data->suggested_action = 0;
1133 * /<!-- -->* We are getting this data due to a request in drag_motion,
1134 * * rather than due to a request in drag_drop, so we are just
1135 * * supposed to call gdk_drag_status(<!-- -->), not actually paste in the data.
1137 * str = gtk_selection_data_get_text (selection_data);
1138 * if (!data_is_acceptable (str))
1139 * gdk_drag_status (context, 0, time);
1141 * gdk_drag_status (context, private_data->suggested_action, time);
1145 * /<!-- -->* accept the drop *<!-- -->/
1148 * </programlisting></informalexample>
1150 widget_signals[DRAG_MOTION] =
1151 g_signal_new (I_("drag_motion"),
1152 G_TYPE_FROM_CLASS (gobject_class),
1154 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
1155 _gtk_boolean_handled_accumulator, NULL,
1156 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1158 GDK_TYPE_DRAG_CONTEXT,
1164 * GtkWidget::drag-drop:
1165 * @widget: the object which received the signal.
1166 * @drag_context: the drag context
1167 * @x: the x coordinate of the current cursor position
1168 * @y: the y coordinate of the current cursor position
1169 * @time: the timestamp of the motion event
1170 * @returns: whether the cursor position is in a drop zone
1172 * The ::drag-drop signal is emitted on the drop site when the user drops the data
1173 * onto the widget. The signal handler must determine whether the cursor position is in
1174 * a drop zone or not. If it is not in a drop zone, it returns %FALSE and no further
1175 * processing is necessary. Otherwise, the handler returns %TRUE. In this case, the handler
1176 * must ensure that gtk_drag_finish() is called to let the source know that the drop is done.
1177 * The call to gtk_drag_finish() can be done either directly or in a ::drag-data-received handler
1178 * which gets triggered by calling gtk_drop_get_data() to receive the data for one or more of the
1179 * supported targets.
1181 widget_signals[DRAG_DROP] =
1182 g_signal_new (I_("drag_drop"),
1183 G_TYPE_FROM_CLASS (gobject_class),
1185 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
1186 _gtk_boolean_handled_accumulator, NULL,
1187 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1189 GDK_TYPE_DRAG_CONTEXT,
1195 * GtkWidget::drag-data-get:
1196 * @widget: the object which received the signal.
1197 * @drag_context: the drag context
1198 * @data: the #GtkSelectionData to be filled with the dragged data
1199 * @info: the info that has been registered with the target in the #GtkTargetList.
1200 * @time: the timestamp at which the data was requested
1202 * The ::drag-data-get signal is emitted on the drag source when the drop site requests
1203 * the data which is dragged. It is the responsibility of the signal handler to fill @data
1204 * with the data in the format which is indicated by @info. See gtk_selection_data_set() and
1205 * gtk_selection_data_set_text().
1207 widget_signals[DRAG_DATA_GET] =
1208 g_signal_new (I_("drag_data_get"),
1209 G_TYPE_FROM_CLASS (gobject_class),
1211 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
1213 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
1215 GDK_TYPE_DRAG_CONTEXT,
1216 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1221 * GtkWidget::drag-data-received:
1222 * @widget: the object which received the signal.
1223 * @drag_context: the drag context
1224 * @x: where the drop happened
1225 * @y: where the drop happened
1226 * @data: the received data
1227 * @info: the info that has been registered with the target in the #GtkTargetList.
1228 * @time: the timestamp at which the data was received
1230 * The ::drag-data-received signal is emitted on the drop site when the dragged data has been
1231 * received. If the data was received in order to determine whether the drop will be accepted,
1232 * the handler is expected to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
1233 * If the data was received in response to a ::drag-drop signal (and this is the last target to be
1234 * received), the handler for this signal is expected to process the received data and then call
1235 * gtk_drag_finish(), setting the @success parameter depending on whether the data was processed
1238 * The handler may inspect and modify @drag_context->action before calling gtk_drag_finish(),
1239 * e.g. to implement %GDK_ACTION_ASK as shown in the following example:
1240 * <informalexample><programlisting>
1242 * drag_data_received (GtkWidget *widget,
1243 * GdkDragContext *drag_context,
1246 * GtkSelectionData *data,
1250 * if ((data->length >= 0) && (data->format == 8))
1252 * if (drag_context->action == GDK_ACTION_ASK)
1254 * GtkWidget *dialog;
1257 * dialog = gtk_message_dialog_new (NULL,
1258 * GTK_DIALOG_MODAL |
1259 * GTK_DIALOG_DESTROY_WITH_PARENT,
1261 * GTK_BUTTONS_YES_NO,
1262 * "Move the data ?\n");
1263 * response = gtk_dialog_run (GTK_DIALOG (dialog));
1264 * gtk_widget_destroy (dialog);
1266 * if (response == GTK_RESPONSE_YES)
1267 * drag_context->action = GDK_ACTION_MOVE;
1269 * drag_context->action = GDK_ACTION_COPY;
1272 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
1276 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
1278 * </programlisting></informalexample>
1280 widget_signals[DRAG_DATA_RECEIVED] =
1281 g_signal_new (I_("drag_data_received"),
1282 G_TYPE_FROM_CLASS (gobject_class),
1284 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
1286 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
1288 GDK_TYPE_DRAG_CONTEXT,
1291 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1294 widget_signals[VISIBILITY_NOTIFY_EVENT] =
1295 g_signal_new (I_("visibility_notify_event"),
1296 G_TYPE_FROM_CLASS (gobject_class),
1298 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
1299 _gtk_boolean_handled_accumulator, NULL,
1300 _gtk_marshal_BOOLEAN__BOXED,
1302 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1303 widget_signals[CLIENT_EVENT] =
1304 g_signal_new (I_("client_event"),
1305 G_TYPE_FROM_CLASS (gobject_class),
1307 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
1308 _gtk_boolean_handled_accumulator, NULL,
1309 _gtk_marshal_BOOLEAN__BOXED,
1311 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1312 widget_signals[NO_EXPOSE_EVENT] =
1313 g_signal_new (I_("no_expose_event"),
1314 G_TYPE_FROM_CLASS (gobject_class),
1316 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
1317 _gtk_boolean_handled_accumulator, NULL,
1318 _gtk_marshal_BOOLEAN__BOXED,
1320 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1321 widget_signals[WINDOW_STATE_EVENT] =
1322 g_signal_new (I_("window_state_event"),
1323 G_TYPE_FROM_CLASS (gobject_class),
1325 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
1326 _gtk_boolean_handled_accumulator, NULL,
1327 _gtk_marshal_BOOLEAN__BOXED,
1329 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1331 * GtkWidget::grab-broken:
1332 * @widget: the object which received the signal
1333 * @event: the #GdkEventGrabBroken event
1335 * Emitted when a pointer or keyboard grab on a window belonging
1336 * to @widget gets broken.
1338 * On X11, this happens when the grab window becomes unviewable
1339 * (i.e. it or one of its ancestors is unmapped), or if the same
1340 * application grabs the pointer or keyboard again.
1342 * Returns: %TRUE to stop other handlers from being invoked for the event.
1343 * %FALSE to propagate the event further.
1347 widget_signals[GRAB_BROKEN] =
1348 g_signal_new (I_("grab_broken_event"),
1349 G_TYPE_FROM_CLASS (gobject_class),
1351 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
1352 _gtk_boolean_handled_accumulator, NULL,
1353 _gtk_marshal_BOOLEAN__BOXED,
1355 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1357 * GtkWidget::popup-menu
1358 * @widget: the object which received the signal
1359 * @returns: TRUE if a menu was activated
1361 * This signal gets emitted whenever a widget should pop up a context-sensitive
1362 * menu. This usually happens through the standard key binding mechanism; by
1363 * pressing a certain key while a widget is focused, the user can cause the
1364 * widget to pop up a menu. For example, the #GtkEntry widget creates a menu
1365 * with clipboard commands. See <xref linkend="checklist-popup-menu"/> for an
1366 * example of how to use this signal.
1368 widget_signals[POPUP_MENU] =
1369 g_signal_new (I_("popup_menu"),
1370 G_TYPE_FROM_CLASS (gobject_class),
1371 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1372 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
1373 _gtk_boolean_handled_accumulator, NULL,
1374 _gtk_marshal_BOOLEAN__VOID,
1376 widget_signals[SHOW_HELP] =
1377 g_signal_new (I_("show_help"),
1378 G_TYPE_FROM_CLASS (gobject_class),
1379 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1380 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
1381 _gtk_boolean_handled_accumulator, NULL,
1382 _gtk_marshal_BOOLEAN__ENUM,
1384 GTK_TYPE_WIDGET_HELP_TYPE);
1385 widget_signals[ACCEL_CLOSURES_CHANGED] =
1386 g_signal_new (I_("accel_closures_changed"),
1387 G_TYPE_FROM_CLASS (gobject_class),
1391 _gtk_marshal_NONE__NONE,
1393 widget_signals[SCREEN_CHANGED] =
1394 g_signal_new (I_("screen_changed"),
1395 G_TYPE_FROM_CLASS (gobject_class),
1397 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
1399 _gtk_marshal_VOID__OBJECT,
1403 * GtkWidget::can-activate-accel:
1404 * @widget: the object which received the signal
1405 * @signal_id: the ID of a signal installed on @widget
1406 * @returns: %TRUE if the signal can be activated.
1408 * Determines whether an accelerator that activates the signal
1409 * identified by @signal_id can currently be activated.
1410 * This signal is present to allow applications and derived
1411 * widgets to override the default #GtkWidget handling
1412 * for determining whether an accelerator can be activated.
1414 widget_signals[CAN_ACTIVATE_ACCEL] =
1415 g_signal_new (I_("can_activate_accel"),
1416 G_TYPE_FROM_CLASS (gobject_class),
1418 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
1419 _gtk_boolean_handled_accumulator, NULL,
1420 _gtk_marshal_BOOLEAN__UINT,
1421 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
1423 binding_set = gtk_binding_set_by_class (klass);
1424 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
1426 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
1429 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
1431 GTK_TYPE_WIDGET_HELP_TYPE,
1432 GTK_WIDGET_HELP_TOOLTIP);
1433 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
1435 GTK_TYPE_WIDGET_HELP_TYPE,
1436 GTK_WIDGET_HELP_TOOLTIP);
1437 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
1439 GTK_TYPE_WIDGET_HELP_TYPE,
1440 GTK_WIDGET_HELP_WHATS_THIS);
1441 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
1443 GTK_TYPE_WIDGET_HELP_TYPE,
1444 GTK_WIDGET_HELP_WHATS_THIS);
1446 gtk_widget_class_install_style_property (klass,
1447 g_param_spec_boolean ("interior-focus",
1448 P_("Interior Focus"),
1449 P_("Whether to draw the focus indicator inside widgets"),
1451 GTK_PARAM_READABLE));
1453 gtk_widget_class_install_style_property (klass,
1454 g_param_spec_int ("focus-line-width",
1455 P_("Focus linewidth"),
1456 P_("Width, in pixels, of the focus indicator line"),
1458 GTK_PARAM_READABLE));
1460 gtk_widget_class_install_style_property (klass,
1461 g_param_spec_string ("focus-line-pattern",
1462 P_("Focus line dash pattern"),
1463 P_("Dash pattern used to draw the focus indicator"),
1465 GTK_PARAM_READABLE));
1466 gtk_widget_class_install_style_property (klass,
1467 g_param_spec_int ("focus-padding",
1468 P_("Focus padding"),
1469 P_("Width, in pixels, between focus indicator and the widget 'box'"),
1471 GTK_PARAM_READABLE));
1472 gtk_widget_class_install_style_property (klass,
1473 g_param_spec_boxed ("cursor-color",
1475 P_("Color with which to draw insertion cursor"),
1477 GTK_PARAM_READABLE));
1478 gtk_widget_class_install_style_property (klass,
1479 g_param_spec_boxed ("secondary-cursor-color",
1480 P_("Secondary cursor color"),
1481 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
1483 GTK_PARAM_READABLE));
1484 gtk_widget_class_install_style_property (klass,
1485 g_param_spec_float ("cursor-aspect-ratio",
1486 P_("Cursor line aspect ratio"),
1487 P_("Aspect ratio with which to draw insertion cursor"),
1489 GTK_PARAM_READABLE));
1490 gtk_widget_class_install_style_property (klass,
1491 g_param_spec_boxed ("draw-border",
1493 P_("Size of areas outside the widget's allocation to draw"),
1495 GTK_PARAM_READABLE));
1499 gtk_widget_set_property (GObject *object,
1501 const GValue *value,
1504 GtkWidget *widget = GTK_WIDGET (object);
1508 guint32 saved_flags;
1511 gtk_widget_set_name (widget, g_value_get_string (value));
1514 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
1516 case PROP_WIDTH_REQUEST:
1517 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
1519 case PROP_HEIGHT_REQUEST:
1520 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
1523 if (g_value_get_boolean (value))
1524 gtk_widget_show (widget);
1526 gtk_widget_hide (widget);
1528 case PROP_SENSITIVE:
1529 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
1531 case PROP_APP_PAINTABLE:
1532 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
1534 case PROP_CAN_FOCUS:
1535 saved_flags = GTK_WIDGET_FLAGS (widget);
1536 if (g_value_get_boolean (value))
1537 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
1539 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
1540 if (saved_flags != GTK_WIDGET_FLAGS (widget))
1541 gtk_widget_queue_resize (widget);
1543 case PROP_HAS_FOCUS:
1544 if (g_value_get_boolean (value))
1545 gtk_widget_grab_focus (widget);
1548 if (g_value_get_boolean (value))
1549 gtk_widget_grab_focus (widget);
1551 case PROP_CAN_DEFAULT:
1552 saved_flags = GTK_WIDGET_FLAGS (widget);
1553 if (g_value_get_boolean (value))
1554 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
1556 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT);
1557 if (saved_flags != GTK_WIDGET_FLAGS (widget))
1558 gtk_widget_queue_resize (widget);
1560 case PROP_HAS_DEFAULT:
1561 if (g_value_get_boolean (value))
1562 gtk_widget_grab_default (widget);
1564 case PROP_RECEIVES_DEFAULT:
1565 if (g_value_get_boolean (value))
1566 GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1568 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1571 gtk_widget_set_style (widget, g_value_get_object (value));
1574 if (!GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget))
1575 gtk_widget_set_events (widget, g_value_get_flags (value));
1577 case PROP_EXTENSION_EVENTS:
1578 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
1580 case PROP_NO_SHOW_ALL:
1581 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
1589 gtk_widget_get_property (GObject *object,
1594 GtkWidget *widget = GTK_WIDGET (object);
1599 GdkExtensionMode *modep;
1603 g_value_set_string (value, widget->name);
1605 g_value_set_string (value, "");
1609 g_value_set_object (value, widget->parent);
1611 g_value_set_object (value, NULL);
1613 case PROP_WIDTH_REQUEST:
1616 gtk_widget_get_size_request (widget, &w, NULL);
1617 g_value_set_int (value, w);
1620 case PROP_HEIGHT_REQUEST:
1623 gtk_widget_get_size_request (widget, NULL, &h);
1624 g_value_set_int (value, h);
1628 g_value_set_boolean (value, (GTK_WIDGET_VISIBLE (widget) != FALSE));
1630 case PROP_SENSITIVE:
1631 g_value_set_boolean (value, (GTK_WIDGET_SENSITIVE (widget) != FALSE));
1633 case PROP_APP_PAINTABLE:
1634 g_value_set_boolean (value, (GTK_WIDGET_APP_PAINTABLE (widget) != FALSE));
1636 case PROP_CAN_FOCUS:
1637 g_value_set_boolean (value, (GTK_WIDGET_CAN_FOCUS (widget) != FALSE));
1639 case PROP_HAS_FOCUS:
1640 g_value_set_boolean (value, (GTK_WIDGET_HAS_FOCUS (widget) != FALSE));
1643 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
1645 case PROP_CAN_DEFAULT:
1646 g_value_set_boolean (value, (GTK_WIDGET_CAN_DEFAULT (widget) != FALSE));
1648 case PROP_HAS_DEFAULT:
1649 g_value_set_boolean (value, (GTK_WIDGET_HAS_DEFAULT (widget) != FALSE));
1651 case PROP_RECEIVES_DEFAULT:
1652 g_value_set_boolean (value, (GTK_WIDGET_RECEIVES_DEFAULT (widget) != FALSE));
1654 case PROP_COMPOSITE_CHILD:
1655 g_value_set_boolean (value, (GTK_WIDGET_COMPOSITE_CHILD (widget) != FALSE));
1658 g_value_set_object (value, gtk_widget_get_style (widget));
1661 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
1663 g_value_set_flags (value, 0);
1665 g_value_set_flags (value, *eventp);
1667 case PROP_EXTENSION_EVENTS:
1668 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
1670 g_value_set_enum (value, 0);
1672 g_value_set_enum (value, (GdkExtensionMode) *modep);
1674 case PROP_NO_SHOW_ALL:
1675 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
1678 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1684 gtk_widget_init (GtkWidget *widget)
1686 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
1687 widget->state = GTK_STATE_NORMAL;
1688 widget->saved_state = GTK_STATE_NORMAL;
1689 widget->name = NULL;
1690 widget->requisition.width = 0;
1691 widget->requisition.height = 0;
1692 widget->allocation.x = -1;
1693 widget->allocation.y = -1;
1694 widget->allocation.width = 1;
1695 widget->allocation.height = 1;
1696 widget->window = NULL;
1697 widget->parent = NULL;
1699 GTK_WIDGET_SET_FLAGS (widget,
1701 GTK_PARENT_SENSITIVE |
1702 (composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
1703 GTK_DOUBLE_BUFFERED);
1705 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
1706 GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
1707 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
1709 widget->style = gtk_widget_get_default_style ();
1710 g_object_ref (widget->style);
1715 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
1717 GParamSpec **pspecs)
1719 GtkWidget *container = widget->parent;
1722 for (i = 0; widget->parent == container && i < n_pspecs; i++)
1723 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
1727 * gtk_widget_freeze_child_notify:
1728 * @widget: a #GtkWidget
1730 * Stops emission of "child-notify" signals on @widget. The signals are
1731 * queued until gtk_widget_thaw_child_notify() is called on @widget.
1733 * This is the analogue of g_object_freeze_notify() for child properties.
1736 gtk_widget_freeze_child_notify (GtkWidget *widget)
1738 g_return_if_fail (GTK_IS_WIDGET (widget));
1740 if (!G_OBJECT (widget)->ref_count)
1743 g_object_ref (widget);
1744 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1745 g_object_unref (widget);
1749 * gtk_widget_child_notify:
1750 * @widget: a #GtkWidget
1751 * @child_property: the name of a child property installed on the
1752 * class of @widget<!-- -->'s parent.
1754 * Emits a "child-notify" signal for the
1755 * <link linkend="child-properties">child property</link> @child_property
1758 * This is the analogue of g_object_notify() for child properties.
1761 gtk_widget_child_notify (GtkWidget *widget,
1762 const gchar *child_property)
1766 g_return_if_fail (GTK_IS_WIDGET (widget));
1767 g_return_if_fail (child_property != NULL);
1768 if (!G_OBJECT (widget)->ref_count || !widget->parent)
1771 g_object_ref (widget);
1772 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
1774 G_OBJECT_TYPE (widget->parent),
1777 g_warning ("%s: container class `%s' has no child property named `%s'",
1779 G_OBJECT_TYPE_NAME (widget->parent),
1783 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1785 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
1786 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1788 g_object_unref (widget);
1792 * gtk_widget_thaw_child_notify:
1793 * @widget: a #GtkWidget
1795 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
1796 * This causes all queued "child-notify" signals on @widget to be emitted.
1799 gtk_widget_thaw_child_notify (GtkWidget *widget)
1801 GObjectNotifyQueue *nqueue;
1803 g_return_if_fail (GTK_IS_WIDGET (widget));
1805 if (!G_OBJECT (widget)->ref_count)
1808 g_object_ref (widget);
1809 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1810 if (!nqueue || !nqueue->freeze_count)
1811 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
1812 G_OBJECT_TYPE_NAME (widget), widget);
1814 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1815 g_object_unref (widget);
1821 * @type: type ID of the widget to create
1822 * @first_property_name: name of first property to set
1823 * @Varargs: value of first property, followed by more properties, %NULL-terminated
1825 * This is a convenience function for creating a widget and setting
1826 * its properties in one go. For example you might write:
1827 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
1828 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
1829 * g_object_new(), but returns a widget so you don't have to
1830 * cast the object yourself.
1832 * Return value: a new #GtkWidget of type @widget_type
1835 gtk_widget_new (GType type,
1836 const gchar *first_property_name,
1842 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
1844 va_start (var_args, first_property_name);
1845 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
1853 * @widget: a #GtkWidget
1854 * @first_property_name: name of first property to set
1855 * @Varargs: value of first property, followed by more properties, %NULL-terminated
1857 * Like g_object_set() - there's no reason to use this instead of
1861 gtk_widget_set (GtkWidget *widget,
1862 const gchar *first_property_name,
1867 g_return_if_fail (GTK_IS_WIDGET (widget));
1869 va_start (var_args, first_property_name);
1870 g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
1875 gtk_widget_queue_draw_child (GtkWidget *widget)
1879 parent = widget->parent;
1880 if (parent && GTK_WIDGET_DRAWABLE (parent))
1881 gtk_widget_queue_draw_area (parent,
1882 widget->allocation.x,
1883 widget->allocation.y,
1884 widget->allocation.width,
1885 widget->allocation.height);
1889 * gtk_widget_unparent:
1890 * @widget: a #GtkWidget
1892 * This function is only for use in widget implementations.
1893 * Should be called by implementations of the remove method
1894 * on #GtkContainer, to dissociate a child from the container.
1897 gtk_widget_unparent (GtkWidget *widget)
1899 GObjectNotifyQueue *nqueue;
1900 GtkWidget *toplevel;
1901 GtkWidget *old_parent;
1903 g_return_if_fail (GTK_IS_WIDGET (widget));
1904 if (widget->parent == NULL)
1907 /* keep this function in sync with gtk_menu_detach()
1910 g_object_freeze_notify (G_OBJECT (widget));
1911 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1913 toplevel = gtk_widget_get_toplevel (widget);
1914 if (GTK_WIDGET_TOPLEVEL (toplevel))
1915 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
1917 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
1918 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
1920 /* If we are unanchoring the child, we save around the toplevel
1921 * to emit hierarchy changed
1923 if (GTK_WIDGET_ANCHORED (widget->parent))
1924 g_object_ref (toplevel);
1928 gtk_widget_queue_draw_child (widget);
1930 /* Reset the width and height here, to force reallocation if we
1931 * get added back to a new parent. This won't work if our new
1932 * allocation is smaller than 1x1 and we actually want a size of 1x1...
1933 * (would 0x0 be OK here?)
1935 widget->allocation.width = 1;
1936 widget->allocation.height = 1;
1938 if (GTK_WIDGET_REALIZED (widget))
1940 if (GTK_WIDGET_IN_REPARENT (widget))
1941 gtk_widget_unmap (widget);
1943 gtk_widget_unrealize (widget);
1946 /* Removing a widget from a container restores the child visible
1947 * flag to the default state, so it doesn't affect the child
1948 * in the next parent.
1950 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
1952 old_parent = widget->parent;
1953 widget->parent = NULL;
1954 gtk_widget_set_parent_window (widget, NULL);
1955 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
1958 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
1959 g_object_unref (toplevel);
1962 g_object_notify (G_OBJECT (widget), "parent");
1963 g_object_thaw_notify (G_OBJECT (widget));
1964 if (!widget->parent)
1965 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
1966 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1967 g_object_unref (widget);
1971 * gtk_widget_destroy:
1972 * @widget: a #GtkWidget
1974 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
1975 * you don't have to cast the widget to #GtkObject. When a widget is
1976 * destroyed, it will break any references it holds to other objects.
1977 * If the widget is inside a container, the widget will be removed
1978 * from the container. If the widget is a toplevel (derived from
1979 * #GtkWindow), it will be removed from the list of toplevels, and the
1980 * reference GTK+ holds to it will be removed. Removing a
1981 * widget from its container or the list of toplevels results in the
1982 * widget being finalized, unless you've added additional references
1983 * to the widget with g_object_ref().
1985 * In most cases, only toplevel widgets (windows) require explicit
1986 * destruction, because when you destroy a toplevel its children will
1987 * be destroyed as well.
1991 gtk_widget_destroy (GtkWidget *widget)
1993 g_return_if_fail (GTK_IS_WIDGET (widget));
1995 gtk_object_destroy ((GtkObject*) widget);
1999 * gtk_widget_destroyed:
2000 * @widget: a #GtkWidget
2001 * @widget_pointer: address of a variable that contains @widget
2003 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
2004 * %NULL. It's intended to be used as a callback connected to the
2005 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
2006 * as a signal handler, and pass the address of your widget variable
2007 * as user data. Then when the widget is destroyed, the variable will
2008 * be set to %NULL. Useful for example to avoid multiple copies
2009 * of the same dialog.
2013 gtk_widget_destroyed (GtkWidget *widget,
2014 GtkWidget **widget_pointer)
2016 /* Don't make any assumptions about the
2018 * Even check widget_pointer.
2021 *widget_pointer = NULL;
2026 * @widget: a #GtkWidget
2028 * Flags a widget to be displayed. Any widget that isn't shown will
2029 * not appear on the screen. If you want to show all the widgets in a
2030 * container, it's easier to call gtk_widget_show_all() on the
2031 * container, instead of individually showing the widgets.
2033 * Remember that you have to show the containers containing a widget,
2034 * in addition to the widget itself, before it will appear onscreen.
2036 * When a toplevel container is shown, it is immediately realized and
2037 * mapped; other shown widgets are realized and mapped when their
2038 * toplevel container is realized and mapped.
2042 gtk_widget_show (GtkWidget *widget)
2044 if (!GTK_WIDGET_VISIBLE (widget))
2046 g_object_ref (widget);
2047 if (!GTK_WIDGET_TOPLEVEL (widget))
2048 gtk_widget_queue_resize (widget);
2049 g_signal_emit (widget, widget_signals[SHOW], 0);
2050 g_object_notify (G_OBJECT (widget), "visible");
2051 g_object_unref (widget);
2056 gtk_widget_real_show (GtkWidget *widget)
2058 if (!GTK_WIDGET_VISIBLE (widget))
2060 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
2062 if (widget->parent &&
2063 GTK_WIDGET_MAPPED (widget->parent) &&
2064 GTK_WIDGET_CHILD_VISIBLE (widget) &&
2065 !GTK_WIDGET_MAPPED (widget))
2066 gtk_widget_map (widget);
2071 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
2074 g_signal_handlers_disconnect_by_func (widget,
2075 gtk_widget_show_map_callback,
2080 * gtk_widget_show_now:
2081 * @widget: a #GtkWidget
2083 * Shows a widget. If the widget is an unmapped toplevel widget
2084 * (i.e. a #GtkWindow that has not yet been shown), enter the main
2085 * loop and wait for the window to actually be mapped. Be careful;
2086 * because the main loop is running, anything can happen during
2090 gtk_widget_show_now (GtkWidget *widget)
2094 g_return_if_fail (GTK_IS_WIDGET (widget));
2096 /* make sure we will get event */
2097 if (!GTK_WIDGET_MAPPED (widget) &&
2098 GTK_WIDGET_TOPLEVEL (widget))
2100 gtk_widget_show (widget);
2102 g_signal_connect (widget, "map_event",
2103 G_CALLBACK (gtk_widget_show_map_callback),
2107 gtk_main_iteration ();
2110 gtk_widget_show (widget);
2115 * @widget: a #GtkWidget
2117 * Reverses the effects of gtk_widget_show(), causing the widget to be
2118 * hidden (invisible to the user).
2121 gtk_widget_hide (GtkWidget *widget)
2123 g_return_if_fail (GTK_IS_WIDGET (widget));
2125 if (GTK_WIDGET_VISIBLE (widget))
2127 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
2129 g_object_ref (widget);
2130 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
2131 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
2133 g_signal_emit (widget, widget_signals[HIDE], 0);
2134 if (!GTK_WIDGET_TOPLEVEL (widget))
2135 gtk_widget_queue_resize (widget);
2136 g_object_notify (G_OBJECT (widget), "visible");
2137 g_object_unref (widget);
2142 gtk_widget_real_hide (GtkWidget *widget)
2144 if (GTK_WIDGET_VISIBLE (widget))
2146 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
2148 if (GTK_WIDGET_MAPPED (widget))
2149 gtk_widget_unmap (widget);
2154 * gtk_widget_hide_on_delete:
2155 * @widget: a #GtkWidget
2157 * Utility function; intended to be connected to the "delete_event"
2158 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
2159 * argument, then returns %TRUE. If connected to "delete_event", the
2160 * result is that clicking the close button for a window (on the
2161 * window frame, top right corner usually) will hide but not destroy
2162 * the window. By default, GTK+ destroys windows when "delete_event"
2165 * Return value: %TRUE
2168 gtk_widget_hide_on_delete (GtkWidget *widget)
2170 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2172 gtk_widget_hide (widget);
2178 * gtk_widget_show_all:
2179 * @widget: a #GtkWidget
2181 * Recursively shows a widget, and any child widgets (if the widget is
2185 gtk_widget_show_all (GtkWidget *widget)
2187 GtkWidgetClass *class;
2189 g_return_if_fail (GTK_IS_WIDGET (widget));
2191 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
2194 class = GTK_WIDGET_GET_CLASS (widget);
2196 if (class->show_all)
2197 class->show_all (widget);
2201 * gtk_widget_hide_all:
2202 * @widget: a #GtkWidget
2204 * Recursively hides a widget and any child widgets.
2207 gtk_widget_hide_all (GtkWidget *widget)
2209 GtkWidgetClass *class;
2211 g_return_if_fail (GTK_IS_WIDGET (widget));
2213 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
2216 class = GTK_WIDGET_GET_CLASS (widget);
2218 if (class->hide_all)
2219 class->hide_all (widget);
2224 * @widget: a #GtkWidget
2226 * This function is only for use in widget implementations. Causes
2227 * a widget to be mapped if it isn't already.
2231 gtk_widget_map (GtkWidget *widget)
2233 g_return_if_fail (GTK_IS_WIDGET (widget));
2234 g_return_if_fail (GTK_WIDGET_VISIBLE (widget));
2235 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
2237 if (!GTK_WIDGET_MAPPED (widget))
2239 if (!GTK_WIDGET_REALIZED (widget))
2240 gtk_widget_realize (widget);
2242 g_signal_emit (widget, widget_signals[MAP], 0);
2244 if (GTK_WIDGET_NO_WINDOW (widget))
2245 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
2251 * @widget: a #GtkWidget
2253 * This function is only for use in widget implementations. Causes
2254 * a widget to be unmapped if it's currently mapped.
2258 gtk_widget_unmap (GtkWidget *widget)
2260 g_return_if_fail (GTK_IS_WIDGET (widget));
2262 if (GTK_WIDGET_MAPPED (widget))
2264 if (GTK_WIDGET_NO_WINDOW (widget))
2265 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
2266 g_signal_emit (widget, widget_signals[UNMAP], 0);
2271 * gtk_widget_realize:
2272 * @widget: a #GtkWidget
2274 * Creates the GDK (windowing system) resources associated with a
2275 * widget. For example, @widget->window will be created when a widget
2276 * is realized. Normally realization happens implicitly; if you show
2277 * a widget and all its parent containers, then the widget will be
2278 * realized and mapped automatically.
2280 * Realizing a widget requires all
2281 * the widget's parent widgets to be realized; calling
2282 * gtk_widget_realize() realizes the widget's parents in addition to
2283 * @widget itself. If a widget is not yet inside a toplevel window
2284 * when you realize it, bad things will happen.
2286 * This function is primarily used in widget implementations, and
2287 * isn't very useful otherwise. Many times when you think you might
2288 * need it, a better approach is to connect to a signal that will be
2289 * called after the widget is realized automatically, such as
2290 * "expose_event". Or simply g_signal_connect_after() to the
2295 gtk_widget_realize (GtkWidget *widget)
2298 GdkExtensionMode mode;
2299 GtkWidgetShapeInfo *shape_info;
2301 g_return_if_fail (GTK_IS_WIDGET (widget));
2302 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
2303 GTK_IS_INVISIBLE (widget));
2305 if (!GTK_WIDGET_REALIZED (widget))
2308 if (GTK_IS_CONTAINER (widget) && !GTK_WIDGET_NO_WINDOW (widget))
2309 g_message ("gtk_widget_realize(%s)", g_type_name (GTK_WIDGET_TYPE (widget)));
2312 if (widget->parent == NULL &&
2313 !GTK_WIDGET_TOPLEVEL (widget))
2314 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
2315 "inside a toplevel window is not going to work very well. "
2316 "Widgets must be inside a toplevel container before realizing them.");
2318 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
2319 gtk_widget_realize (widget->parent);
2321 gtk_widget_ensure_style (widget);
2323 g_signal_emit (widget, widget_signals[REALIZE], 0);
2325 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
2327 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
2328 gdk_window_shape_combine_mask (widget->window,
2329 shape_info->shape_mask,
2330 shape_info->offset_x,
2331 shape_info->offset_y);
2334 if (!GTK_WIDGET_NO_WINDOW (widget))
2336 mode = gtk_widget_get_extension_events (widget);
2337 if (mode != GDK_EXTENSION_EVENTS_NONE)
2339 events = gtk_widget_get_events (widget);
2340 gdk_input_set_extension_events (widget->window, events, mode);
2348 * gtk_widget_unrealize:
2349 * @widget: a #GtkWidget
2351 * This function is only useful in widget implementations.
2352 * Causes a widget to be unrealized (frees all GDK resources
2353 * associated with the widget, such as @widget->window).
2357 gtk_widget_unrealize (GtkWidget *widget)
2359 g_return_if_fail (GTK_IS_WIDGET (widget));
2361 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
2362 gtk_widget_shape_combine_mask (widget, NULL, -1, -1);
2364 if (GTK_WIDGET_REALIZED (widget))
2366 g_object_ref (widget);
2367 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
2368 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
2369 g_object_unref (widget);
2373 /*****************************************
2375 *****************************************/
2378 * gtk_widget_queue_draw_area:
2379 * @widget: a #GtkWidget
2380 * @x: x coordinate of upper-left corner of rectangle to redraw
2381 * @y: y coordinate of upper-left corner of rectangle to redraw
2382 * @width: width of region to draw
2383 * @height: height of region to draw
2385 * Invalidates the rectangular area of @widget defined by @x, @y,
2386 * @width and @height by calling gdk_window_invalidate_rect() on the
2387 * widget's window and all its child windows. Once the main loop
2388 * becomes idle (after the current batch of events has been processed,
2389 * roughly), the window will receive expose events for the union of
2390 * all regions that have been invalidated.
2392 * Normally you would only use this function in widget
2393 * implementations. You might also use it, or
2394 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
2395 * #GtkDrawingArea or some portion thereof.
2397 * Frequently you can just call gdk_window_invalidate_rect() or
2398 * gdk_window_invalidate_region() instead of this function. Those
2399 * functions will invalidate only a single window, instead of the
2400 * widget and all its children.
2402 * The advantage of adding to the invalidated region compared to
2403 * simply drawing immediately is efficiency; using an invalid region
2404 * ensures that you only have to redraw one time.
2408 gtk_widget_queue_draw_area (GtkWidget *widget,
2414 GdkRectangle invalid_rect;
2417 g_return_if_fail (GTK_IS_WIDGET (widget));
2419 if (!GTK_WIDGET_REALIZED (widget))
2422 /* Just return if the widget or one of its ancestors isn't mapped */
2423 for (w = widget; w != NULL; w = w->parent)
2424 if (!GTK_WIDGET_MAPPED (w))
2427 /* Find the correct widget */
2429 if (!GTK_WIDGET_NO_WINDOW (widget))
2433 /* Translate widget relative to window-relative */
2435 gint wx, wy, wwidth, wheight;
2437 gdk_window_get_position (widget->window, &wx, &wy);
2438 x -= wx - widget->allocation.x;
2439 y -= wy - widget->allocation.y;
2441 gdk_drawable_get_size (widget->window, &wwidth, &wheight);
2443 if (x + width <= 0 || y + height <= 0 ||
2444 x >= wwidth || y >= wheight)
2455 if (x + width > wwidth)
2457 if (y + height > wheight)
2458 height = wheight - y;
2464 invalid_rect.width = width;
2465 invalid_rect.height = height;
2467 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
2471 widget_add_child_draw_rectangle (GtkWidget *widget,
2474 GdkRectangle child_rect;
2476 if (!GTK_WIDGET_MAPPED (widget) ||
2477 widget->window != widget->parent->window)
2480 gtk_widget_get_draw_rectangle (widget, &child_rect);
2481 gdk_rectangle_union (rect, &child_rect, rect);
2485 gtk_widget_get_draw_rectangle (GtkWidget *widget,
2488 if (GTK_WIDGET_NO_WINDOW (widget))
2490 GtkBorder *draw_border = NULL;
2492 *rect = widget->allocation;
2494 gtk_widget_style_get (widget,
2495 "draw-border", &draw_border,
2499 rect->x -= draw_border->top;
2500 rect->y -= draw_border->left;
2501 rect->width += draw_border->left + draw_border->right;
2502 rect->height += draw_border->top + draw_border->bottom;
2505 if (GTK_IS_CONTAINER (widget))
2506 gtk_container_forall (GTK_CONTAINER (widget),
2507 (GtkCallback)widget_add_child_draw_rectangle,
2514 rect->width = widget->allocation.width;
2515 rect->height = widget->allocation.height;
2520 * gtk_widget_queue_draw:
2521 * @widget: a #GtkWidget
2523 * Equivalent to calling gtk_widget_queue_draw_area() for the
2524 * entire area of a widget.
2528 gtk_widget_queue_draw (GtkWidget *widget)
2532 g_return_if_fail (GTK_IS_WIDGET (widget));
2534 gtk_widget_get_draw_rectangle (widget, &rect);
2536 gtk_widget_queue_draw_area (widget,
2538 rect.width, rect.height);
2541 /* Invalidates the given area (allocation-relative-coordinates)
2542 * in all of the widget's windows
2545 * gtk_widget_queue_clear_area:
2546 * @widget: a #GtkWidget
2547 * @x: x coordinate of upper-left corner of rectangle to redraw
2548 * @y: y coordinate of upper-left corner of rectangle to redraw
2549 * @width: width of region to draw
2550 * @height: height of region to draw
2552 * This function is no longer different from
2553 * gtk_widget_queue_draw_area(), though it once was. Now it just calls
2554 * gtk_widget_queue_draw_area(). Originally
2555 * gtk_widget_queue_clear_area() would force a redraw of the
2556 * background for %GTK_NO_WINDOW widgets, and
2557 * gtk_widget_queue_draw_area() would not. Now both functions ensure
2558 * the background will be redrawn.
2560 * @Deprecated: Use gtk_widget_queue_draw_area() instead.
2563 gtk_widget_queue_clear_area (GtkWidget *widget,
2569 g_return_if_fail (GTK_IS_WIDGET (widget));
2571 gtk_widget_queue_draw_area (widget, x, y, width, height);
2575 * gtk_widget_queue_clear:
2576 * @widget: a #GtkWidget
2578 * This function does the same as gtk_widget_queue_draw().
2580 * @Deprecated: Use gtk_widget_queue_draw() instead.
2583 gtk_widget_queue_clear (GtkWidget *widget)
2585 g_return_if_fail (GTK_IS_WIDGET (widget));
2587 gtk_widget_queue_draw (widget);
2591 * gtk_widget_queue_resize:
2592 * @widget: a #GtkWidget
2594 * This function is only for use in widget implementations.
2595 * Flags a widget to have its size renegotiated; should
2596 * be called when a widget for some reason has a new size request.
2597 * For example, when you change the text in a #GtkLabel, #GtkLabel
2598 * queues a resize to ensure there's enough space for the new text.
2601 gtk_widget_queue_resize (GtkWidget *widget)
2603 g_return_if_fail (GTK_IS_WIDGET (widget));
2605 if (GTK_WIDGET_REALIZED (widget))
2606 gtk_widget_queue_shallow_draw (widget);
2608 _gtk_size_group_queue_resize (widget);
2612 * gtk_widget_queue_resize_no_redraw:
2613 * @widget: a #GtkWidget
2615 * This function works like gtk_widget_queue_resize(), except that the
2616 * widget is not invalidated.
2621 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
2623 g_return_if_fail (GTK_IS_WIDGET (widget));
2625 _gtk_size_group_queue_resize (widget);
2630 * @widget: a #GtkWidget
2631 * @area: area to draw
2633 * In GTK+ 1.2, this function would immediately render the
2634 * region @area of a widget, by invoking the virtual draw method of a
2635 * widget. In GTK+ 2.0, the draw method is gone, and instead
2636 * gtk_widget_draw() simply invalidates the specified region of the
2637 * widget, then updates the invalid region of the widget immediately.
2638 * Usually you don't want to update the region immediately for
2639 * performance reasons, so in general gtk_widget_queue_draw_area() is
2640 * a better choice if you want to draw a region of a widget.
2644 gtk_widget_draw (GtkWidget *widget,
2647 g_return_if_fail (GTK_IS_WIDGET (widget));
2649 if (GTK_WIDGET_DRAWABLE (widget))
2652 gtk_widget_queue_draw_area (widget,
2654 area->width, area->height);
2656 gtk_widget_queue_draw (widget);
2658 gdk_window_process_updates (widget->window, TRUE);
2663 * gtk_widget_size_request:
2664 * @widget: a #GtkWidget
2665 * @requisition: a #GtkRequisition to be filled in
2667 * This function is typically used when implementing a #GtkContainer
2668 * subclass. Obtains the preferred size of a widget. The container
2669 * uses this information to arrange its child widgets and decide what
2670 * size allocations to give them with gtk_widget_size_allocate().
2672 * You can also call this function from an application, with some
2673 * caveats. Most notably, getting a size request requires the widget
2674 * to be associated with a screen, because font information may be
2675 * needed. Multihead-aware applications should keep this in mind.
2677 * Also remember that the size request is not necessarily the size
2678 * a widget will actually be allocated.
2680 * See also gtk_widget_get_child_requisition().
2683 gtk_widget_size_request (GtkWidget *widget,
2684 GtkRequisition *requisition)
2686 g_return_if_fail (GTK_IS_WIDGET (widget));
2688 #ifdef G_ENABLE_DEBUG
2689 if (requisition == &widget->requisition)
2690 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.");
2691 #endif /* G_ENABLE_DEBUG */
2693 _gtk_size_group_compute_requisition (widget, requisition);
2697 * gtk_widget_get_child_requisition:
2698 * @widget: a #GtkWidget
2699 * @requisition: a #GtkRequisition to be filled in
2701 * This function is only for use in widget implementations. Obtains
2702 * @widget->requisition, unless someone has forced a particular
2703 * geometry on the widget (e.g. with gtk_widget_set_usize()), in which
2704 * case it returns that geometry instead of the widget's requisition.
2706 * This function differs from gtk_widget_size_request() in that
2707 * it retrieves the last size request value from @widget->requisition,
2708 * while gtk_widget_size_request() actually calls the "size_request" method
2709 * on @widget to compute the size request and fill in @widget->requisition,
2710 * and only then returns @widget->requisition.
2712 * Because this function does not call the "size_request" method, it
2713 * can only be used when you know that @widget->requisition is
2714 * up-to-date, that is, gtk_widget_size_request() has been called
2715 * since the last time a resize was queued. In general, only container
2716 * implementations have this information; applications should use
2717 * gtk_widget_size_request().
2720 gtk_widget_get_child_requisition (GtkWidget *widget,
2721 GtkRequisition *requisition)
2723 _gtk_size_group_get_child_requisition (widget, requisition);
2727 invalidate_predicate (GdkWindow *window,
2732 gdk_window_get_user_data (window, &user_data);
2734 return (user_data == data);
2737 /* Invalidate @region in widget->window and all children
2738 * of widget->window owned by widget. @region is in the
2739 * same coordinates as widget->allocation and will be
2740 * modified by this call.
2743 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
2746 if (!GTK_WIDGET_REALIZED (widget))
2749 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
2753 gdk_window_get_position (widget->window, &x, &y);
2754 gdk_region_offset (region, -x, -y);
2757 gdk_window_invalidate_maybe_recurse (widget->window, region,
2758 invalidate_predicate, widget);
2762 * gtk_widget_queue_shallow_draw:
2763 * @widget: a #GtkWidget
2765 * Like gtk_widget_queue_draw(), but only windows owned
2766 * by @widget are invalidated.
2769 gtk_widget_queue_shallow_draw (GtkWidget *widget)
2774 g_return_if_fail (GTK_IS_WIDGET (widget));
2776 if (!GTK_WIDGET_REALIZED (widget))
2779 gtk_widget_get_draw_rectangle (widget, &rect);
2781 /* get_draw_rectangle() gives us window coordinates, we
2782 * need to convert to the coordinates that widget->allocation
2785 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
2789 gdk_window_get_position (widget->window, &wx, &wy);
2795 region = gdk_region_rectangle (&rect);
2796 gtk_widget_invalidate_widget_windows (widget, region);
2797 gdk_region_destroy (region);
2801 * gtk_widget_size_allocate:
2802 * @widget: a #GtkWidget
2803 * @allocation: position and size to be allocated to @widget
2805 * This function is only used by #GtkContainer subclasses, to assign a size
2806 * and position to their child widgets.
2810 gtk_widget_size_allocate (GtkWidget *widget,
2811 GtkAllocation *allocation)
2813 GtkWidgetAuxInfo *aux_info;
2814 GdkRectangle real_allocation;
2815 GdkRectangle old_allocation;
2816 gboolean alloc_needed;
2817 gboolean size_changed;
2818 gboolean position_changed;
2820 g_return_if_fail (GTK_IS_WIDGET (widget));
2822 #ifdef G_ENABLE_DEBUG
2823 if (gtk_debug_flags & GTK_DEBUG_GEOMETRY)
2834 parent = gtk_widget_get_parent (parent);
2837 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
2838 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
2839 2 * depth, " ", name,
2840 allocation->width, allocation->height);
2842 #endif /* G_ENABLE_DEBUG */
2844 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
2845 if (!GTK_WIDGET_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
2846 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
2848 old_allocation = widget->allocation;
2849 real_allocation = *allocation;
2850 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
2854 if (aux_info->x_set)
2855 real_allocation.x = aux_info->x;
2856 if (aux_info->y_set)
2857 real_allocation.y = aux_info->y;
2860 if (real_allocation.width < 0 || real_allocation.height < 0)
2862 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
2863 real_allocation.width,
2864 real_allocation.height);
2867 real_allocation.width = MAX (real_allocation.width, 1);
2868 real_allocation.height = MAX (real_allocation.height, 1);
2870 size_changed = (old_allocation.width != real_allocation.width ||
2871 old_allocation.height != real_allocation.height);
2872 position_changed = (old_allocation.x != real_allocation.x ||
2873 old_allocation.y != real_allocation.y);
2875 if (!alloc_needed && !size_changed && !position_changed)
2878 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
2880 if (GTK_WIDGET_MAPPED (widget))
2882 if (GTK_WIDGET_NO_WINDOW (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
2884 /* Invalidate union(old_allaction,widget->allocation) in widget->window
2886 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
2887 gdk_region_union_with_rect (invalidate, &old_allocation);
2889 gdk_window_invalidate_region (widget->window, invalidate, FALSE);
2890 gdk_region_destroy (invalidate);
2895 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
2897 /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
2899 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
2900 gdk_region_union_with_rect (invalidate, &old_allocation);
2902 gtk_widget_invalidate_widget_windows (widget, invalidate);
2903 gdk_region_destroy (invalidate);
2908 if ((size_changed || position_changed) && widget->parent &&
2909 GTK_WIDGET_REALIZED (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
2911 GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
2912 gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
2913 gdk_region_destroy (invalidate);
2918 * gtk_widget_common_ancestor:
2919 * @widget_a: a #GtkWidget
2920 * @widget_b: a #GtkWidget
2922 * Find the common ancestor of @widget_a and @widget_b that
2923 * is closest to the two widgets.
2925 * Return value: the closest common ancestor of @widget_a and
2926 * @widget_b or %NULL if @widget_a and @widget_b do not
2927 * share a common ancestor.
2930 gtk_widget_common_ancestor (GtkWidget *widget_a,
2931 GtkWidget *widget_b)
2933 GtkWidget *parent_a;
2934 GtkWidget *parent_b;
2938 parent_a = widget_a;
2939 while (parent_a->parent)
2941 parent_a = parent_a->parent;
2945 parent_b = widget_b;
2946 while (parent_b->parent)
2948 parent_b = parent_b->parent;
2952 if (parent_a != parent_b)
2955 while (depth_a > depth_b)
2957 widget_a = widget_a->parent;
2961 while (depth_b > depth_a)
2963 widget_b = widget_b->parent;
2967 while (widget_a != widget_b)
2969 widget_a = widget_a->parent;
2970 widget_b = widget_b->parent;
2977 * gtk_widget_translate_coordinates:
2978 * @src_widget: a #GtkWidget
2979 * @dest_widget: a #GtkWidget
2980 * @src_x: X position relative to @src_widget
2981 * @src_y: Y position relative to @src_widget
2982 * @dest_x: location to store X position relative to @dest_widget
2983 * @dest_y: location to store Y position relative to @dest_widget
2985 * Translate coordinates relative to @src_widget's allocation to coordinates
2986 * relative to @dest_widget's allocations. In order to perform this
2987 * operation, both widgets must be realized, and must share a common
2990 * Return value: %FALSE if either widget was not realized, or there
2991 * was no common ancestor. In this case, nothing is stored in
2992 * *@dest_x and *@dest_y. Otherwise %TRUE.
2995 gtk_widget_translate_coordinates (GtkWidget *src_widget,
2996 GtkWidget *dest_widget,
3002 GtkWidget *ancestor;
3005 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
3006 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
3008 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
3009 if (!ancestor || !GTK_WIDGET_REALIZED (src_widget) || !GTK_WIDGET_REALIZED (dest_widget))
3012 /* Translate from allocation relative to window relative */
3013 if (!GTK_WIDGET_NO_WINDOW (src_widget) && src_widget->parent)
3016 gdk_window_get_position (src_widget->window, &wx, &wy);
3018 src_x -= wx - src_widget->allocation.x;
3019 src_y -= wy - src_widget->allocation.y;
3023 src_x += src_widget->allocation.x;
3024 src_y += src_widget->allocation.y;
3027 /* Translate to the common ancestor */
3028 window = src_widget->window;
3029 while (window != ancestor->window)
3033 gdk_window_get_position (window, &dx, &dy);
3038 window = gdk_window_get_parent (window);
3040 if (!window) /* Handle GtkHandleBox */
3045 window = dest_widget->window;
3046 while (window != ancestor->window)
3050 gdk_window_get_position (window, &dx, &dy);
3055 window = gdk_window_get_parent (window);
3057 if (!window) /* Handle GtkHandleBox */
3061 /* Translate from window relative to allocation relative */
3062 if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent)
3065 gdk_window_get_position (dest_widget->window, &wx, &wy);
3067 src_x += wx - dest_widget->allocation.x;
3068 src_y += wy - dest_widget->allocation.y;
3072 src_x -= dest_widget->allocation.x;
3073 src_y -= dest_widget->allocation.y;
3085 gtk_widget_real_size_allocate (GtkWidget *widget,
3086 GtkAllocation *allocation)
3088 widget->allocation = *allocation;
3090 if (GTK_WIDGET_REALIZED (widget) &&
3091 !GTK_WIDGET_NO_WINDOW (widget))
3093 gdk_window_move_resize (widget->window,
3094 allocation->x, allocation->y,
3095 allocation->width, allocation->height);
3100 gtk_widget_real_can_activate_accel (GtkWidget *widget,
3103 /* widgets must be onscreen for accels to take effect */
3104 return GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_DRAWABLE (widget) && gdk_window_is_viewable (widget->window);
3108 * gtk_widget_can_activate_accel:
3109 * @widget: a #GtkWidget
3110 * @signal_id: the ID of a signal installed on @widget
3112 * Determines whether an accelerator that activates the signal
3113 * identified by @signal_id can currently be activated.
3114 * This is done by emitting the GtkWidget::can-activate-accel
3115 * signal on @widget; if the signal isn't overridden by a
3116 * handler or in a derived widget, then the default check is
3117 * that the widget must be sensitive, and the widget and all
3118 * its ancestors mapped.
3120 * Return value: %TRUE if the accelerator can be activated.
3125 gtk_widget_can_activate_accel (GtkWidget *widget,
3128 gboolean can_activate = FALSE;
3129 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3130 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
3131 return can_activate;
3140 closure_accel_activate (GClosure *closure,
3141 GValue *return_value,
3142 guint n_param_values,
3143 const GValue *param_values,
3144 gpointer invocation_hint,
3145 gpointer marshal_data)
3147 AccelClosure *aclosure = (AccelClosure*) closure;
3148 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
3151 g_signal_emit (closure->data, aclosure->signal_id, 0);
3153 /* whether accelerator was handled */
3154 g_value_set_boolean (return_value, can_activate);
3158 closures_destroy (gpointer data)
3160 GSList *slist, *closures = data;
3162 for (slist = closures; slist; slist = slist->next)
3164 g_closure_invalidate (slist->data);
3165 g_closure_unref (slist->data);
3167 g_slist_free (closures);
3171 widget_new_accel_closure (GtkWidget *widget,
3174 AccelClosure *aclosure;
3175 GClosure *closure = NULL;
3176 GSList *slist, *closures;
3178 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
3179 for (slist = closures; slist; slist = slist->next)
3180 if (!gtk_accel_group_from_accel_closure (slist->data))
3182 /* reuse this closure */
3183 closure = slist->data;
3188 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
3189 closures = g_slist_prepend (closures, g_closure_ref (closure));
3190 g_closure_sink (closure);
3191 g_closure_set_marshal (closure, closure_accel_activate);
3193 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
3195 aclosure = (AccelClosure*) closure;
3196 g_assert (closure->data == widget);
3197 g_assert (closure->marshal == closure_accel_activate);
3198 aclosure->signal_id = signal_id;
3204 * gtk_widget_add_accelerator
3205 * @widget: widget to install an accelerator on
3206 * @accel_signal: widget signal to emit on accelerator activation
3207 * @accel_group: accel group for this widget, added to its toplevel
3208 * @accel_key: GDK keyval of the accelerator
3209 * @accel_mods: modifier key combination of the accelerator
3210 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
3212 * Installs an accelerator for this @widget in @accel_group that causes
3213 * @accel_signal to be emitted if the accelerator is activated.
3214 * The @accel_group needs to be added to the widget's toplevel via
3215 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
3216 * Accelerators added through this function are not user changeable during
3217 * runtime. If you want to support accelerators that can be changed by the
3218 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
3219 * gtk_menu_item_set_accel_path() instead.
3222 gtk_widget_add_accelerator (GtkWidget *widget,
3223 const gchar *accel_signal,
3224 GtkAccelGroup *accel_group,
3226 GdkModifierType accel_mods,
3227 GtkAccelFlags accel_flags)
3232 g_return_if_fail (GTK_IS_WIDGET (widget));
3233 g_return_if_fail (accel_signal != NULL);
3234 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
3236 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
3237 if (!query.signal_id ||
3238 !(query.signal_flags & G_SIGNAL_ACTION) ||
3239 query.return_type != G_TYPE_NONE ||
3242 /* hmm, should be elaborate enough */
3243 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
3244 G_OBJECT_TYPE_NAME (widget), accel_signal);
3248 closure = widget_new_accel_closure (widget, query.signal_id);
3250 g_object_ref (widget);
3252 /* install the accelerator. since we don't map this onto an accel_path,
3253 * the accelerator will automatically be locked.
3255 gtk_accel_group_connect (accel_group,
3258 accel_flags | GTK_ACCEL_LOCKED,
3261 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3263 g_object_unref (widget);
3267 * gtk_widget_remove_accelerator:
3268 * @widget: widget to install an accelerator on
3269 * @accel_group: accel group for this widget
3270 * @accel_key: GDK keyval of the accelerator
3271 * @accel_mods: modifier key combination of the accelerator
3272 * @returns: whether an accelerator was installed and could be removed
3274 * Removes an accelerator from @widget, previously installed with
3275 * gtk_widget_add_accelerator().
3278 gtk_widget_remove_accelerator (GtkWidget *widget,
3279 GtkAccelGroup *accel_group,
3281 GdkModifierType accel_mods)
3283 GtkAccelGroupEntry *ag_entry;
3284 GList *slist, *clist;
3287 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3288 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
3290 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
3291 clist = gtk_widget_list_accel_closures (widget);
3292 for (slist = clist; slist; slist = slist->next)
3296 for (i = 0; i < n; i++)
3297 if (slist->data == (gpointer) ag_entry[i].closure)
3299 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
3301 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3303 g_list_free (clist);
3308 g_list_free (clist);
3310 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
3311 accel_key, accel_mods, accel_group,
3312 G_OBJECT_TYPE_NAME (widget), widget);
3318 * gtk_widget_list_accel_closures
3319 * @widget: widget to list accelerator closures for
3320 * @returns: a newly allocated #GList of closures
3322 * Lists the closures used by @widget for accelerator group connections
3323 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
3324 * The closures can be used to monitor accelerator changes on @widget,
3325 * by connecting to the ::accel_changed signal of the #GtkAccelGroup of a
3326 * closure which can be found out with gtk_accel_group_from_accel_closure().
3329 gtk_widget_list_accel_closures (GtkWidget *widget)
3332 GList *clist = NULL;
3334 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3336 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
3337 if (gtk_accel_group_from_accel_closure (slist->data))
3338 clist = g_list_prepend (clist, slist->data);
3345 GtkAccelGroup *accel_group;
3350 destroy_accel_path (gpointer data)
3352 AccelPath *apath = data;
3354 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
3356 /* closures_destroy takes care of unrefing the closure */
3357 g_object_unref (apath->accel_group);
3364 * gtk_widget_set_accel_path:
3365 * @widget: a #GtkWidget
3366 * @accel_path: path used to look up the accelerator
3367 * @accel_group: a #GtkAccelGroup.
3369 * Given an accelerator group, @accel_group, and an accelerator path,
3370 * @accel_path, sets up an accelerator in @accel_group so whenever the
3371 * key binding that is defined for @accel_path is pressed, @widget
3372 * will be activated. This removes any accelerators (for any
3373 * accelerator group) installed by previous calls to
3374 * gtk_widget_set_accel_path(). Associating accelerators with
3375 * paths allows them to be modified by the user and the modifications
3376 * to be saved for future use. (See gtk_accel_map_save().)
3378 * This function is a low level function that would most likely
3379 * be used by a menu creation system like #GtkItemFactory. If you
3380 * use #GtkItemFactory, setting up accelerator paths will be done
3383 * Even when you you aren't using #GtkItemFactory, if you only want to
3384 * set up accelerators on menu items gtk_menu_item_set_accel_path()
3385 * provides a somewhat more convenient interface.
3388 gtk_widget_set_accel_path (GtkWidget *widget,
3389 const gchar *accel_path,
3390 GtkAccelGroup *accel_group)
3394 g_return_if_fail (GTK_IS_WIDGET (widget));
3395 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
3399 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
3400 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
3402 gtk_accel_map_add_entry (accel_path, 0, 0);
3403 apath = g_new (AccelPath, 1);
3404 apath->widget = widget;
3405 apath->accel_group = g_object_ref (accel_group);
3406 apath->path_quark = g_quark_from_string (accel_path);
3407 apath->closure = widget_new_accel_closure (apath->widget, GTK_WIDGET_GET_CLASS (apath->widget)->activate_signal);
3412 /* also removes possible old settings */
3413 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
3416 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
3418 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3422 _gtk_widget_get_accel_path (GtkWidget *widget,
3427 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3429 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
3431 *locked = apath ? apath->accel_group->lock_count > 0 : TRUE;
3432 return apath ? g_quark_to_string (apath->path_quark) : NULL;
3436 gtk_widget_mnemonic_activate (GtkWidget *widget,
3437 gboolean group_cycling)
3441 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3443 group_cycling = group_cycling != FALSE;
3444 if (!GTK_WIDGET_IS_SENSITIVE (widget))
3447 g_signal_emit (widget,
3448 widget_signals[MNEMONIC_ACTIVATE],
3456 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
3457 gboolean group_cycling)
3459 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
3460 gtk_widget_activate (widget);
3461 else if (GTK_WIDGET_CAN_FOCUS (widget))
3462 gtk_widget_grab_focus (widget);
3465 g_warning ("widget `%s' isn't suitable for mnemonic activation",
3466 G_OBJECT_TYPE_NAME (widget));
3467 gdk_display_beep (gtk_widget_get_display (widget));
3473 gtk_widget_real_key_press_event (GtkWidget *widget,
3476 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
3480 gtk_widget_real_key_release_event (GtkWidget *widget,
3483 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
3487 gtk_widget_real_focus_in_event (GtkWidget *widget,
3488 GdkEventFocus *event)
3490 gtk_widget_queue_shallow_draw (widget);
3496 gtk_widget_real_focus_out_event (GtkWidget *widget,
3497 GdkEventFocus *event)
3499 gtk_widget_queue_shallow_draw (widget);
3504 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
3505 (event->type == GDK_FOCUS_CHANGE || GTK_WIDGET_REALIZED(widget))
3509 * @widget: a #GtkWidget
3510 * @event: a #GdkEvent
3512 * Rarely-used function. This function is used to emit
3513 * the event signals on a widget (those signals should never
3514 * be emitted without using this function to do so).
3515 * If you want to synthesize an event though, don't use this function;
3516 * instead, use gtk_main_do_event() so the event will behave as if
3517 * it were in the event queue. Don't synthesize expose events; instead,
3518 * use gdk_window_invalidate_rect() to invalidate a region of the
3521 * Return value: return from the event signal emission (%TRUE if the event was handled)
3524 gtk_widget_event (GtkWidget *widget,
3527 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
3528 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
3530 if (event->type == GDK_EXPOSE)
3532 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
3533 "the same effect, call gdk_window_invalidate_rect/region(), "
3534 "followed by gdk_window_process_updates().");
3538 return gtk_widget_event_internal (widget, event);
3543 * gtk_widget_send_expose:
3544 * @widget: a #GtkWidget
3545 * @event: a expose #GdkEvent
3547 * Very rarely-used function. This function is used to emit
3548 * an expose event signals on a widget. This function is not
3549 * normally used directly. The only time it is used is when
3550 * propagating an expose event to a child %NO_WINDOW widget, and
3551 * that is normally done using gtk_container_propagate_expose().
3553 * If you want to force an area of a window to be redrawn,
3554 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
3555 * To cause the redraw to be done immediately, follow that call
3556 * with a call to gdk_window_process_updates().
3558 * Return value: return from the event signal emission (%TRUE if the event was handled)
3561 gtk_widget_send_expose (GtkWidget *widget,
3564 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
3565 g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), TRUE);
3566 g_return_val_if_fail (event != NULL, TRUE);
3567 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
3569 if (event->type != GDK_EXPOSE)
3572 return gtk_widget_event_internal (widget, event);
3576 event_window_is_still_viewable (GdkEvent *event)
3578 /* Some programs, such as gnome-theme-manager, fake widgets
3579 * into exposing onto a pixmap by sending expose events with
3580 * event->window pointing to a pixmap
3582 if (GDK_IS_PIXMAP (event->any.window))
3583 return event->type == GDK_EXPOSE;
3585 /* Check that we think the event's window is viewable before
3586 * delivering the event, to prevent suprises. We do this here
3587 * at the last moment, since the event may have been queued
3588 * up behind other events, held over a recursive main loop, etc.
3590 switch (event->type)
3593 case GDK_MOTION_NOTIFY:
3594 case GDK_BUTTON_PRESS:
3595 case GDK_2BUTTON_PRESS:
3596 case GDK_3BUTTON_PRESS:
3598 case GDK_ENTER_NOTIFY:
3599 case GDK_PROXIMITY_IN:
3601 return event->any.window && gdk_window_is_viewable (event->any.window);
3604 /* The following events are the second half of paired events;
3605 * we always deliver them to deal with widgets that clean up
3606 * on the second half.
3608 case GDK_BUTTON_RELEASE:
3609 case GDK_KEY_RELEASE:
3610 case GDK_LEAVE_NOTIFY:
3611 case GDK_PROXIMITY_OUT:
3615 /* Remaining events would make sense on an not-viewable window,
3616 * or don't have an associated window.
3623 gtk_widget_event_internal (GtkWidget *widget,
3626 gboolean return_val = FALSE;
3628 /* We check only once for is-still-visible; if someone
3629 * hides the window in on of the signals on the widget,
3630 * they are responsible for returning TRUE to terminate
3633 if (!event_window_is_still_viewable (event))
3636 g_object_ref (widget);
3638 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
3639 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
3644 switch (event->type)
3649 case GDK_BUTTON_PRESS:
3650 case GDK_2BUTTON_PRESS:
3651 case GDK_3BUTTON_PRESS:
3652 signal_num = BUTTON_PRESS_EVENT;
3655 signal_num = SCROLL_EVENT;
3657 case GDK_BUTTON_RELEASE:
3658 signal_num = BUTTON_RELEASE_EVENT;
3660 case GDK_MOTION_NOTIFY:
3661 signal_num = MOTION_NOTIFY_EVENT;
3664 signal_num = DELETE_EVENT;
3667 signal_num = DESTROY_EVENT;
3670 signal_num = KEY_PRESS_EVENT;
3672 case GDK_KEY_RELEASE:
3673 signal_num = KEY_RELEASE_EVENT;
3675 case GDK_ENTER_NOTIFY:
3676 signal_num = ENTER_NOTIFY_EVENT;
3678 case GDK_LEAVE_NOTIFY:
3679 signal_num = LEAVE_NOTIFY_EVENT;
3681 case GDK_FOCUS_CHANGE:
3682 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
3685 signal_num = CONFIGURE_EVENT;
3688 signal_num = MAP_EVENT;
3691 signal_num = UNMAP_EVENT;
3693 case GDK_WINDOW_STATE:
3694 signal_num = WINDOW_STATE_EVENT;
3696 case GDK_PROPERTY_NOTIFY:
3697 signal_num = PROPERTY_NOTIFY_EVENT;
3699 case GDK_SELECTION_CLEAR:
3700 signal_num = SELECTION_CLEAR_EVENT;
3702 case GDK_SELECTION_REQUEST:
3703 signal_num = SELECTION_REQUEST_EVENT;
3705 case GDK_SELECTION_NOTIFY:
3706 signal_num = SELECTION_NOTIFY_EVENT;
3708 case GDK_PROXIMITY_IN:
3709 signal_num = PROXIMITY_IN_EVENT;
3711 case GDK_PROXIMITY_OUT:
3712 signal_num = PROXIMITY_OUT_EVENT;
3715 signal_num = NO_EXPOSE_EVENT;
3717 case GDK_CLIENT_EVENT:
3718 signal_num = CLIENT_EVENT;
3721 signal_num = EXPOSE_EVENT;
3723 case GDK_VISIBILITY_NOTIFY:
3724 signal_num = VISIBILITY_NOTIFY_EVENT;
3726 case GDK_GRAB_BROKEN:
3727 signal_num = GRAB_BROKEN;
3730 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
3734 if (signal_num != -1)
3735 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
3737 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
3738 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
3742 g_object_unref (widget);
3748 * gtk_widget_activate:
3749 * @widget: a #GtkWidget that's activatable
3751 * For widgets that can be "activated" (buttons, menu items, etc.)
3752 * this function activates them. Activation is what happens when you
3753 * press Enter on a widget during key navigation. If @widget isn't
3754 * activatable, the function returns %FALSE.
3756 * Return value: %TRUE if the widget was activatable
3759 gtk_widget_activate (GtkWidget *widget)
3761 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3763 if (WIDGET_CLASS (widget)->activate_signal)
3765 /* FIXME: we should eventually check the signals signature here */
3766 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
3775 * gtk_widget_set_scroll_adjustments:
3776 * @widget: a #GtkWidget
3777 * @hadjustment: an adjustment for horizontal scrolling, or %NULL
3778 * @vadjustment: an adjustment for vertical scrolling, or %NULL
3780 * For widgets that support scrolling, sets the scroll adjustments and
3781 * returns %TRUE. For widgets that don't support scrolling, does
3782 * nothing and returns %FALSE. Widgets that don't support scrolling
3783 * can be scrolled by placing them in a #GtkViewport, which does
3784 * support scrolling.
3786 * Return value: %TRUE if the widget supports scrolling
3789 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
3790 GtkAdjustment *hadjustment,
3791 GtkAdjustment *vadjustment)
3793 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3795 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
3797 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
3799 if (WIDGET_CLASS (widget)->set_scroll_adjustments_signal)
3801 /* FIXME: we should eventually check the signals signature here */
3802 g_signal_emit (widget,
3803 WIDGET_CLASS (widget)->set_scroll_adjustments_signal, 0,
3804 hadjustment, vadjustment);
3812 gtk_widget_reparent_subwindows (GtkWidget *widget,
3813 GdkWindow *new_window)
3815 if (GTK_WIDGET_NO_WINDOW (widget))
3817 GList *children = gdk_window_get_children (widget->window);
3820 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
3823 GdkWindow *window = tmp_list->data;
3825 gdk_window_get_user_data (window, (void **)&child);
3826 while (child && child != widget)
3827 child = child->parent;
3830 gdk_window_reparent (window, new_window, 0, 0);
3833 g_list_free (children);
3838 GList *tmp_list, *children;
3840 parent = gdk_window_get_parent (widget->window);
3843 gdk_window_reparent (widget->window, new_window, 0, 0);
3846 children = gdk_window_get_children (parent);
3848 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
3851 GdkWindow *window = tmp_list->data;
3853 gdk_window_get_user_data (window, (void **)&child);
3854 if (child == widget)
3855 gdk_window_reparent (window, new_window, 0, 0);
3858 g_list_free (children);
3864 gtk_widget_reparent_fixup_child (GtkWidget *widget,
3865 gpointer client_data)
3867 g_return_if_fail (client_data != NULL);
3869 if (GTK_WIDGET_NO_WINDOW (widget))
3872 g_object_unref (widget->window);
3873 widget->window = (GdkWindow*) client_data;
3875 g_object_ref (widget->window);
3877 if (GTK_IS_CONTAINER (widget))
3878 gtk_container_forall (GTK_CONTAINER (widget),
3879 gtk_widget_reparent_fixup_child,
3885 * gtk_widget_reparent:
3886 * @widget: a #GtkWidget
3887 * @new_parent: a #GtkContainer to move the widget into
3889 * Moves a widget from one #GtkContainer to another, handling reference
3890 * count issues to avoid destroying the widget.
3894 gtk_widget_reparent (GtkWidget *widget,
3895 GtkWidget *new_parent)
3897 g_return_if_fail (GTK_IS_WIDGET (widget));
3898 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
3899 g_return_if_fail (widget->parent != NULL);
3901 if (widget->parent != new_parent)
3903 /* First try to see if we can get away without unrealizing
3904 * the widget as we reparent it. if so we set a flag so
3905 * that gtk_widget_unparent doesn't unrealize widget
3907 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent))
3908 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
3910 g_object_ref (widget);
3911 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
3912 gtk_container_add (GTK_CONTAINER (new_parent), widget);
3913 g_object_unref (widget);
3915 if (GTK_WIDGET_IN_REPARENT (widget))
3917 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
3919 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
3920 gtk_widget_reparent_fixup_child (widget,
3921 gtk_widget_get_parent_window (widget));
3924 g_object_notify (G_OBJECT (widget), "parent");
3929 * gtk_widget_intersect:
3930 * @widget: a #GtkWidget
3931 * @area: a rectangle
3932 * @intersection: rectangle to store intersection of @widget and @area
3934 * Computes the intersection of a @widget's area and @area, storing
3935 * the intersection in @intersection, and returns %TRUE if there was
3936 * an intersection. @intersection may be %NULL if you're only
3937 * interested in whether there was an intersection.
3939 * Return value: %TRUE if there was an intersection
3942 gtk_widget_intersect (GtkWidget *widget,
3944 GdkRectangle *intersection)
3950 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3951 g_return_val_if_fail (area != NULL, FALSE);
3954 dest = intersection;
3958 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
3960 if (return_val && intersection && !GTK_WIDGET_NO_WINDOW (widget))
3962 intersection->x -= widget->allocation.x;
3963 intersection->y -= widget->allocation.y;
3970 * gtk_widget_region_intersect:
3971 * @widget: a #GtkWidget
3972 * @region: a #GdkRegion, in the same coordinate system as
3973 * @widget->allocation. That is, relative to @widget->window
3974 * for %NO_WINDOW widgets; relative to the parent window
3975 * of @widget->window for widgets with their own window.
3976 * @returns: A newly allocated region holding the intersection of @widget
3977 * and @region. The coordinates of the return value are
3978 * relative to @widget->window for %NO_WINDOW widgets, and
3979 * relative to the parent window of @widget->window for
3980 * widgets with their own window.
3982 * Computes the intersection of a @widget's area and @region, returning
3983 * the intersection. The result may be empty, use gdk_region_empty() to
3987 gtk_widget_region_intersect (GtkWidget *widget,
3993 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3994 g_return_val_if_fail (region != NULL, NULL);
3996 gtk_widget_get_draw_rectangle (widget, &rect);
3998 dest = gdk_region_rectangle (&rect);
4000 gdk_region_intersect (dest, region);
4006 * _gtk_widget_grab_notify:
4007 * @widget: a #GtkWidget
4008 * @was_grabbed: whether a grab is now in effect
4010 * Emits the signal "grab_notify" on @widget.
4015 _gtk_widget_grab_notify (GtkWidget *widget,
4016 gboolean was_grabbed)
4018 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
4022 * gtk_widget_grab_focus:
4023 * @widget: a #GtkWidget
4025 * Causes @widget to have the keyboard focus for the #GtkWindow it's
4026 * inside. @widget must be a focusable widget, such as a #GtkEntry;
4027 * something like #GtkFrame won't work. (More precisely, it must have the
4028 * %GTK_CAN_FOCUS flag set.)
4032 gtk_widget_grab_focus (GtkWidget *widget)
4034 g_return_if_fail (GTK_IS_WIDGET (widget));
4036 if (!GTK_WIDGET_IS_SENSITIVE (widget))
4039 g_object_ref (widget);
4040 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
4041 g_object_notify (G_OBJECT (widget), "has-focus");
4042 g_object_unref (widget);
4046 reset_focus_recurse (GtkWidget *widget,
4049 if (GTK_IS_CONTAINER (widget))
4051 GtkContainer *container;
4053 container = GTK_CONTAINER (widget);
4054 gtk_container_set_focus_child (container, NULL);
4056 gtk_container_foreach (container,
4057 reset_focus_recurse,
4063 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
4065 if (GTK_WIDGET_CAN_FOCUS (focus_widget))
4067 GtkWidget *toplevel;
4070 /* clear the current focus setting, break if the current widget
4071 * is the focus widget's parent, since containers above that will
4072 * be set by the next loop.
4074 toplevel = gtk_widget_get_toplevel (focus_widget);
4075 if (GTK_WIDGET_TOPLEVEL (toplevel))
4077 widget = GTK_WINDOW (toplevel)->focus_widget;
4079 if (widget == focus_widget)
4081 /* We call _gtk_window_internal_set_focus() here so that the
4082 * toplevel window can request the focus if necessary.
4083 * This is needed when the toplevel is a GtkPlug
4085 if (!GTK_WIDGET_HAS_FOCUS (widget))
4086 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
4093 while (widget->parent && widget->parent != focus_widget->parent)
4095 widget = widget->parent;
4096 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
4100 else if (toplevel != focus_widget)
4102 /* gtk_widget_grab_focus() operates on a tree without window...
4103 * actually, this is very questionable behaviour.
4106 gtk_container_foreach (GTK_CONTAINER (toplevel),
4107 reset_focus_recurse,
4111 /* now propagate the new focus up the widget tree and finally
4112 * set it on the window
4114 widget = focus_widget;
4115 while (widget->parent)
4117 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
4118 widget = widget->parent;
4120 if (GTK_IS_WINDOW (widget))
4121 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
4126 gtk_widget_real_show_help (GtkWidget *widget,
4127 GtkWidgetHelpType help_type)
4129 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
4131 _gtk_tooltips_toggle_keyboard_mode (widget);
4139 gtk_widget_real_focus (GtkWidget *widget,
4140 GtkDirectionType direction)
4142 if (!GTK_WIDGET_CAN_FOCUS (widget))
4145 if (!gtk_widget_is_focus (widget))
4147 gtk_widget_grab_focus (widget);
4155 * gtk_widget_is_focus:
4156 * @widget: a #GtkWidget
4158 * Determines if the widget is the focus widget within its
4159 * toplevel. (This does not mean that the %HAS_FOCUS flag is
4160 * necessarily set; %HAS_FOCUS will only be set if the
4161 * toplevel widget additionally has the global input focus.)
4163 * Return value: %TRUE if the widget is the focus widget.
4166 gtk_widget_is_focus (GtkWidget *widget)
4168 GtkWidget *toplevel;
4170 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4172 toplevel = gtk_widget_get_toplevel (widget);
4174 if (GTK_IS_WINDOW (toplevel))
4175 return widget == GTK_WINDOW (toplevel)->focus_widget;
4181 * gtk_widget_grab_default:
4182 * @widget: a #GtkWidget
4184 * Causes @widget to become the default widget. @widget must have the
4185 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
4186 * yourself by calling <literal>GTK_WIDGET_SET_FLAGS (@widget,
4187 * GTK_CAN_DEFAULT)</literal>. The default widget is activated when the user
4188 * presses Enter in a window. Default widgets must be activatable,
4189 * that is, gtk_widget_activate() should affect them.
4193 gtk_widget_grab_default (GtkWidget *widget)
4197 g_return_if_fail (GTK_IS_WIDGET (widget));
4198 g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget));
4200 window = gtk_widget_get_toplevel (widget);
4202 if (window && GTK_WIDGET_TOPLEVEL (window))
4203 gtk_window_set_default (GTK_WINDOW (window), widget);
4205 g_warning (G_STRLOC ": widget not within a GtkWindow");
4209 * gtk_widget_set_name:
4210 * @widget: a #GtkWidget
4211 * @name: name for the widget
4213 * Widgets can be named, which allows you to refer to them from a
4214 * gtkrc file. You can apply a style to widgets with a particular name
4215 * in the gtkrc file. See the documentation for gtkrc files (on the
4216 * same page as the docs for #GtkRcStyle).
4218 * Note that widget names are separated by periods in paths (see
4219 * gtk_widget_path()), so names with embedded periods may cause confusion.
4222 gtk_widget_set_name (GtkWidget *widget,
4227 g_return_if_fail (GTK_IS_WIDGET (widget));
4229 new_name = g_strdup (name);
4230 g_free (widget->name);
4231 widget->name = new_name;
4233 if (GTK_WIDGET_RC_STYLE (widget))
4234 gtk_widget_reset_rc_style (widget);
4236 g_object_notify (G_OBJECT (widget), "name");
4240 * gtk_widget_get_name:
4241 * @widget: a #GtkWidget
4243 * Retrieves the name of a widget. See gtk_widget_set_name() for the
4244 * significance of widget names.
4246 * Return value: name of the widget. This string is owned by GTK+ and
4247 * should not be modified or freed
4249 G_CONST_RETURN gchar*
4250 gtk_widget_get_name (GtkWidget *widget)
4252 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4255 return widget->name;
4256 return g_type_name (GTK_WIDGET_TYPE (widget));
4260 * gtk_widget_set_state:
4261 * @widget: a #GtkWidget
4262 * @state: new state for @widget
4264 * This function is for use in widget implementations. Sets the state
4265 * of a widget (insensitive, prelighted, etc.) Usually you should set
4266 * the state using wrapper functions such as gtk_widget_set_sensitive().
4270 gtk_widget_set_state (GtkWidget *widget,
4273 g_return_if_fail (GTK_IS_WIDGET (widget));
4275 if (state == GTK_WIDGET_STATE (widget))
4278 if (state == GTK_STATE_INSENSITIVE)
4279 gtk_widget_set_sensitive (widget, FALSE);
4285 data.state_restoration = FALSE;
4286 data.use_forall = FALSE;
4288 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
4290 data.parent_sensitive = TRUE;
4292 gtk_widget_propagate_state (widget, &data);
4294 if (GTK_WIDGET_DRAWABLE (widget))
4295 gtk_widget_queue_draw (widget);
4301 * gtk_widget_set_app_paintable:
4302 * @widget: a #GtkWidget
4303 * @app_paintable: %TRUE if the application will paint on the widget
4305 * Sets whether the application intends to draw on the widget in
4306 * an ::expose-event handler.
4308 * This is a hint to the widget and does not affect the behavior of
4309 * the GTK+ core; many widgets ignore this flag entirely. For widgets
4310 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
4311 * the effect is to suppress default themed drawing of the widget's
4312 * background. (Children of the widget will still be drawn.) The application
4313 * is then entirely responsible for drawing the widget background.
4316 gtk_widget_set_app_paintable (GtkWidget *widget,
4317 gboolean app_paintable)
4319 g_return_if_fail (GTK_IS_WIDGET (widget));
4321 app_paintable = (app_paintable != FALSE);
4323 if (GTK_WIDGET_APP_PAINTABLE (widget) != app_paintable)
4326 GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE);
4328 GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE);
4330 if (GTK_WIDGET_DRAWABLE (widget))
4331 gtk_widget_queue_draw (widget);
4333 g_object_notify (G_OBJECT (widget), "app-paintable");
4338 * gtk_widget_set_double_buffered:
4339 * @widget: a #GtkWidget
4340 * @double_buffered: %TRUE to double-buffer a widget
4342 * Widgets are double buffered by default; you can use this function
4343 * to turn off the buffering. "Double buffered" simply means that
4344 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
4345 * automatically around expose events sent to the
4346 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
4347 * window to an offscreen buffer, and gdk_window_end_paint() draws the
4348 * buffer to the screen. The result is that users see the window
4349 * update in one smooth step, and don't see individual graphics
4350 * primitives being rendered.
4352 * In very simple terms, double buffered widgets don't flicker,
4353 * so you would only use this function to turn off double buffering
4354 * if you had special needs and really knew what you were doing.
4356 * Note: if you turn off double-buffering, you have to handle
4357 * expose events, since even the clearing to the background color or
4358 * pixmap will not happen automatically (as it is done in
4359 * gdk_window_begin_paint()).
4363 gtk_widget_set_double_buffered (GtkWidget *widget,
4364 gboolean double_buffered)
4366 g_return_if_fail (GTK_IS_WIDGET (widget));
4368 if (double_buffered)
4369 GTK_WIDGET_SET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
4371 GTK_WIDGET_UNSET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
4375 * gtk_widget_set_redraw_on_allocate:
4376 * @widget: a #GtkWidget
4377 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
4378 * when it is allocated to a new size. Otherwise, only the
4379 * new portion of the widget will be redrawn.
4381 * Sets whether the entire widget is queued for drawing when its size
4382 * allocation changes. By default, this setting is %TRUE and
4383 * the entire widget is redrawn on every size change. If your widget
4384 * leaves the upper left unchanged when made bigger, turning this
4385 * setting on will improve performance.
4387 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
4388 * off all allocation on resizing: the widget will not even redraw if
4389 * its position changes; this is to allow containers that don't draw
4390 * anything to avoid excess invalidations. If you set this flag on a
4391 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
4392 * you are responsible for invalidating both the old and new allocation
4393 * of the widget when the widget is moved and responsible for invalidating
4394 * regions newly when the widget increases size.
4397 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
4398 gboolean redraw_on_allocate)
4400 g_return_if_fail (GTK_IS_WIDGET (widget));
4402 if (redraw_on_allocate)
4403 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
4405 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
4409 * gtk_widget_set_sensitive:
4410 * @widget: a #GtkWidget
4411 * @sensitive: %TRUE to make the widget sensitive
4413 * Sets the sensitivity of a widget. A widget is sensitive if the user
4414 * can interact with it. Insensitive widgets are "grayed out" and the
4415 * user can't interact with them. Insensitive widgets are known as
4416 * "inactive", "disabled", or "ghosted" in some other toolkits.
4420 gtk_widget_set_sensitive (GtkWidget *widget,
4425 g_return_if_fail (GTK_IS_WIDGET (widget));
4427 sensitive = (sensitive != FALSE);
4429 if (sensitive == (GTK_WIDGET_SENSITIVE (widget) != FALSE))
4434 GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE);
4435 data.state = GTK_WIDGET_SAVED_STATE (widget);
4439 GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE);
4440 data.state = GTK_WIDGET_STATE (widget);
4442 data.state_restoration = TRUE;
4443 data.use_forall = TRUE;
4446 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
4448 data.parent_sensitive = TRUE;
4450 gtk_widget_propagate_state (widget, &data);
4451 if (GTK_WIDGET_DRAWABLE (widget))
4452 gtk_widget_queue_draw (widget);
4454 g_object_notify (G_OBJECT (widget), "sensitive");
4458 * gtk_widget_set_parent:
4459 * @widget: a #GtkWidget
4460 * @parent: parent container
4462 * This function is useful only when implementing subclasses of #GtkContainer.
4463 * Sets the container as the parent of @widget, and takes care of
4464 * some details such as updating the state and style of the child
4465 * to reflect its new location. The opposite function is
4466 * gtk_widget_unparent().
4470 gtk_widget_set_parent (GtkWidget *widget,
4475 g_return_if_fail (GTK_IS_WIDGET (widget));
4476 g_return_if_fail (GTK_IS_WIDGET (parent));
4477 g_return_if_fail (widget != parent);
4478 if (widget->parent != NULL)
4480 g_warning ("Can't set a parent on widget which has a parent\n");
4483 if (GTK_WIDGET_TOPLEVEL (widget))
4485 g_warning ("Can't set a parent on a toplevel widget\n");
4489 /* keep this function in sync with gtk_menu_attach_to_widget()
4492 g_object_ref (widget);
4493 gtk_object_sink (GTK_OBJECT (widget));
4494 widget->parent = parent;
4496 if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
4497 data.state = GTK_WIDGET_STATE (parent);
4499 data.state = GTK_WIDGET_STATE (widget);
4500 data.state_restoration = FALSE;
4501 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (parent) != FALSE);
4502 data.use_forall = GTK_WIDGET_IS_SENSITIVE (parent) != GTK_WIDGET_IS_SENSITIVE (widget);
4504 gtk_widget_propagate_state (widget, &data);
4506 gtk_widget_reset_rc_styles (widget);
4508 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
4509 if (GTK_WIDGET_ANCHORED (widget->parent))
4510 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
4511 g_object_notify (G_OBJECT (widget), "parent");
4513 /* Enforce realized/mapped invariants
4515 if (GTK_WIDGET_REALIZED (widget->parent))
4516 gtk_widget_realize (widget);
4518 if (GTK_WIDGET_VISIBLE (widget->parent) &&
4519 GTK_WIDGET_VISIBLE (widget))
4521 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
4522 GTK_WIDGET_MAPPED (widget->parent))
4523 gtk_widget_map (widget);
4525 gtk_widget_queue_resize (widget);
4530 * gtk_widget_get_parent:
4531 * @widget: a #GtkWidget
4533 * Returns the parent container of @widget.
4535 * Return value: the parent container of @widget, or %NULL
4538 gtk_widget_get_parent (GtkWidget *widget)
4540 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4542 return widget->parent;
4545 /*****************************************
4547 * see docs/styles.txt
4548 *****************************************/
4551 * gtk_widget_set_style:
4552 * @widget: a #GtkWidget
4553 * @style: a #GtkStyle, or %NULL to remove the effect of a previous
4554 * gtk_widget_set_style() and go back to the default style
4556 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
4557 * want to use this function; it interacts badly with themes, because
4558 * themes work by replacing the #GtkStyle. Instead, use
4559 * gtk_widget_modify_style().
4563 gtk_widget_set_style (GtkWidget *widget,
4566 g_return_if_fail (GTK_IS_WIDGET (widget));
4570 gboolean initial_emission;
4572 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
4574 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
4575 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
4577 gtk_widget_set_style_internal (widget, style, initial_emission);
4581 if (GTK_WIDGET_USER_STYLE (widget))
4582 gtk_widget_reset_rc_style (widget);
4587 * gtk_widget_ensure_style:
4588 * @widget: a #GtkWidget
4590 * Ensures that @widget has a style (@widget->style). Not a very useful
4591 * function; most of the time, if you want the style, the widget is
4592 * realized, and realized widgets are guaranteed to have a style
4597 gtk_widget_ensure_style (GtkWidget *widget)
4599 g_return_if_fail (GTK_IS_WIDGET (widget));
4601 if (!GTK_WIDGET_USER_STYLE (widget) &&
4602 !GTK_WIDGET_RC_STYLE (widget))
4603 gtk_widget_reset_rc_style (widget);
4606 /* Look up the RC style for this widget, unsetting any user style that
4607 * may be in effect currently
4610 gtk_widget_reset_rc_style (GtkWidget *widget)
4612 GtkStyle *new_style = NULL;
4613 gboolean initial_emission;
4615 g_return_if_fail (GTK_IS_WIDGET (widget));
4617 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
4619 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
4620 GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
4622 if (gtk_widget_has_screen (widget))
4623 new_style = gtk_rc_get_style (widget);
4625 new_style = gtk_widget_get_default_style ();
4627 if (initial_emission || new_style != widget->style)
4628 gtk_widget_set_style_internal (widget, new_style, initial_emission);
4632 * gtk_widget_get_style:
4633 * @widget: a #GtkWidget
4635 * Simply an accessor function that returns @widget->style.
4637 * Return value: the widget's #GtkStyle
4640 gtk_widget_get_style (GtkWidget *widget)
4642 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4644 return widget->style;
4648 * gtk_widget_modify_style:
4649 * @widget: a #GtkWidget
4650 * @style: the #GtkRcStyle holding the style modifications
4652 * Modifies style values on the widget. Modifications made using this
4653 * technique take precedence over style values set via an RC file,
4654 * however, they will be overriden if a style is explicitely set on
4655 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
4656 * is designed so each field can either be set or unset, so it is
4657 * possible, using this function, to modify some style values and
4658 * leave the others unchanged.
4660 * Note that modifications made with this function are not cumulative
4661 * with previous calls to gtk_widget_modify_style() or with such
4662 * functions as gtk_widget_modify_fg(). If you wish to retain
4663 * previous values, you must first call gtk_widget_get_modifier_style(),
4664 * make your modifications to the returned style, then call
4665 * gtk_widget_modify_style() with that style. On the other hand,
4666 * if you first call gtk_widget_modify_style(), subsequent calls
4667 * to such functions gtk_widget_modify_fg() will have a cumulative
4668 * effect with the initial modifications.
4671 gtk_widget_modify_style (GtkWidget *widget,
4674 GtkRcStyle *old_style;
4676 g_return_if_fail (GTK_IS_WIDGET (widget));
4677 g_return_if_fail (GTK_IS_RC_STYLE (style));
4679 old_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
4681 g_object_set_qdata_full (G_OBJECT (widget),
4683 gtk_rc_style_copy (style),
4684 (GDestroyNotify) gtk_rc_style_unref);
4686 /* note that "style" may be invalid here if it was the old
4687 * modifier style and the only reference was our own.
4690 if (GTK_WIDGET_RC_STYLE (widget))
4691 gtk_widget_reset_rc_style (widget);
4695 * gtk_widget_get_modifier_style:
4696 * @widget: a #GtkWidget
4698 * Returns the current modifier style for the widget. (As set by
4699 * gtk_widget_modify_style().) If no style has previously set, a new
4700 * #GtkRcStyle will be created with all values unset, and set as the
4701 * modifier style for the widget. If you make changes to this rc
4702 * style, you must call gtk_widget_modify_style(), passing in the
4703 * returned rc style, to make sure that your changes take effect.
4705 * Caution: passing the style back to gtk_widget_modify_style() will
4706 * normally end up destroying it, because gtk_widget_modify_style() copies
4707 * the passed-in style and sets the copy as the new modifier style,
4708 * thus dropping any reference to the old modifier style. Add a reference
4709 * to the modifier style if you want to keep it alive.
4711 * Return value: the modifier style for the widget. This rc style is
4712 * owned by the widget. If you want to keep a pointer to value this
4713 * around, you must add a refcount using gtk_rc_style_ref().
4716 gtk_widget_get_modifier_style (GtkWidget *widget)
4718 GtkRcStyle *rc_style;
4720 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4722 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
4726 rc_style = gtk_rc_style_new ();
4727 g_object_set_qdata_full (G_OBJECT (widget),
4730 (GDestroyNotify) gtk_rc_style_unref);
4737 gtk_widget_modify_color_component (GtkWidget *widget,
4738 GtkRcFlags component,
4740 const GdkColor *color)
4742 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
4749 rc_style->fg[state] = *color;
4752 rc_style->bg[state] = *color;
4755 rc_style->text[state] = *color;
4758 rc_style->base[state] = *color;
4761 g_assert_not_reached();
4764 rc_style->color_flags[state] |= component;
4767 rc_style->color_flags[state] &= ~component;
4769 gtk_widget_modify_style (widget, rc_style);
4773 * gtk_widget_modify_fg:
4774 * @widget: a #GtkWidget.
4775 * @state: the state for which to set the foreground color.
4776 * @color: the color to assign (does not need to be allocated),
4777 * or %NULL to undo the effect of previous calls to
4778 * of gtk_widget_modify_fg().
4780 * Sets the foreground color for a widget in a particular state. All
4781 * other style values are left untouched. See also
4782 * gtk_widget_modify_style().
4785 gtk_widget_modify_fg (GtkWidget *widget,
4787 const GdkColor *color)
4789 g_return_if_fail (GTK_IS_WIDGET (widget));
4790 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4792 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
4796 * gtk_widget_modify_bg:
4797 * @widget: a #GtkWidget.
4798 * @state: the state for which to set the background color.
4799 * @color: the color to assign (does not need to be allocated),
4800 * or %NULL to undo the effect of previous calls to
4801 * of gtk_widget_modify_bg().
4803 * Sets the background color for a widget in a particular state. All
4804 * other style values are left untouched. See also
4805 * gtk_widget_modify_style().
4807 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
4808 * draw on their parent container's window and thus may not draw any background
4809 * themselves. This is the case for e.g. #GtkLabel. To modify the background
4810 * of such widgets, you have to set the background color on their parent; if you want
4811 * to set the background of a rectangular area around a label, try placing the
4812 * label in a #GtkEventBox widget and setting the background color on that.
4815 gtk_widget_modify_bg (GtkWidget *widget,
4817 const GdkColor *color)
4819 g_return_if_fail (GTK_IS_WIDGET (widget));
4820 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4822 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
4826 * gtk_widget_modify_text:
4827 * @widget: a #GtkWidget.
4828 * @state: the state for which to set the text color.
4829 * @color: the color to assign (does not need to be allocated),
4830 * or %NULL to undo the effect of previous calls to
4831 * of gtk_widget_modify_text().
4833 * Sets the text color for a widget in a particular state. All other
4834 * style values are left untouched. The text color is the foreground
4835 * color used along with the base color (see gtk_widget_modify_base())
4836 * for widgets such as #GtkEntry and #GtkTextView. See also
4837 * gtk_widget_modify_style().
4840 gtk_widget_modify_text (GtkWidget *widget,
4842 const GdkColor *color)
4844 g_return_if_fail (GTK_IS_WIDGET (widget));
4845 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4847 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
4851 * gtk_widget_modify_base:
4852 * @widget: a #GtkWidget.
4853 * @state: the state for which to set the base color.
4854 * @color: the color to assign (does not need to be allocated),
4855 * or %NULL to undo the effect of previous calls to
4856 * of gtk_widget_modify_base().
4858 * Sets the base color for a widget in a particular state.
4859 * All other style values are left untouched. The base color
4860 * is the background color used along with the text color
4861 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
4862 * and #GtkTextView. See also gtk_widget_modify_style().
4864 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
4865 * draw on their parent container's window and thus may not draw any background
4866 * themselves. This is the case for e.g. #GtkLabel. To modify the background
4867 * of such widgets, you have to set the base color on their parent; if you want
4868 * to set the background of a rectangular area around a label, try placing the
4869 * label in a #GtkEventBox widget and setting the base color on that.
4872 gtk_widget_modify_base (GtkWidget *widget,
4874 const GdkColor *color)
4876 g_return_if_fail (GTK_IS_WIDGET (widget));
4877 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4879 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
4883 * gtk_widget_modify_font:
4884 * @widget: a #GtkWidget
4885 * @font_desc: the font description to use, or %NULL to undo
4886 * the effect of previous calls to gtk_widget_modify_font().
4888 * Sets the font to use for a widget. All other style values are left
4889 * untouched. See also gtk_widget_modify_style().
4892 gtk_widget_modify_font (GtkWidget *widget,
4893 PangoFontDescription *font_desc)
4895 GtkRcStyle *rc_style;
4897 g_return_if_fail (GTK_IS_WIDGET (widget));
4899 rc_style = gtk_widget_get_modifier_style (widget);
4901 if (rc_style->font_desc)
4902 pango_font_description_free (rc_style->font_desc);
4905 rc_style->font_desc = pango_font_description_copy (font_desc);
4907 rc_style->font_desc = NULL;
4909 gtk_widget_modify_style (widget, rc_style);
4913 gtk_widget_direction_changed (GtkWidget *widget,
4914 GtkTextDirection previous_direction)
4916 gtk_widget_queue_resize (widget);
4920 gtk_widget_style_set (GtkWidget *widget,
4921 GtkStyle *previous_style)
4923 if (GTK_WIDGET_REALIZED (widget) &&
4924 !GTK_WIDGET_NO_WINDOW (widget))
4925 gtk_style_set_background (widget->style, widget->window, widget->state);
4929 gtk_widget_set_style_internal (GtkWidget *widget,
4931 gboolean initial_emission)
4933 g_object_ref (widget);
4934 g_object_freeze_notify (G_OBJECT (widget));
4936 if (widget->style != style)
4938 GtkStyle *previous_style;
4940 if (GTK_WIDGET_REALIZED (widget))
4942 gtk_widget_reset_shapes (widget);
4943 gtk_style_detach (widget->style);
4946 previous_style = widget->style;
4947 widget->style = style;
4948 g_object_ref (widget->style);
4950 if (GTK_WIDGET_REALIZED (widget))
4951 widget->style = gtk_style_attach (widget->style, widget->window);
4953 gtk_widget_update_pango_context (widget);
4954 g_signal_emit (widget,
4955 widget_signals[STYLE_SET],
4957 initial_emission ? NULL : previous_style);
4958 g_object_unref (previous_style);
4960 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
4961 gtk_widget_queue_resize (widget);
4963 else if (initial_emission)
4965 gtk_widget_update_pango_context (widget);
4966 g_signal_emit (widget,
4967 widget_signals[STYLE_SET],
4971 g_object_notify (G_OBJECT (widget), "style");
4972 g_object_thaw_notify (G_OBJECT (widget));
4973 g_object_unref (widget);
4977 GtkWidget *previous_toplevel;
4978 GdkScreen *previous_screen;
4979 GdkScreen *new_screen;
4980 } HierarchyChangedInfo;
4983 do_screen_change (GtkWidget *widget,
4984 GdkScreen *old_screen,
4985 GdkScreen *new_screen)
4987 if (old_screen != new_screen)
4991 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
4993 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
4996 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
5001 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
5002 gpointer client_data)
5004 gboolean new_anchored;
5005 HierarchyChangedInfo *info = client_data;
5007 new_anchored = GTK_WIDGET_TOPLEVEL (widget) ||
5008 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
5010 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
5012 g_object_ref (widget);
5015 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
5017 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
5019 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
5020 do_screen_change (widget, info->previous_screen, info->new_screen);
5022 if (GTK_IS_CONTAINER (widget))
5023 gtk_container_forall (GTK_CONTAINER (widget),
5024 gtk_widget_propagate_hierarchy_changed_recurse,
5027 g_object_unref (widget);
5032 * _gtk_widget_propagate_hierarchy_changed:
5033 * @widget: a #GtkWidget
5034 * @previous_toplevel: Previous toplevel
5036 * Propagates changes in the anchored state to a widget and all
5037 * children, unsetting or setting the %ANCHORED flag, and
5038 * emitting ::hierarchy_changed.
5041 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
5042 GtkWidget *previous_toplevel)
5044 HierarchyChangedInfo info;
5046 info.previous_toplevel = previous_toplevel;
5047 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
5049 if (GTK_WIDGET_TOPLEVEL (widget) ||
5050 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
5051 info.new_screen = gtk_widget_get_screen (widget);
5053 info.new_screen = NULL;
5055 if (info.previous_screen)
5056 g_object_ref (info.previous_screen);
5057 if (previous_toplevel)
5058 g_object_ref (previous_toplevel);
5060 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
5062 if (previous_toplevel)
5063 g_object_unref (previous_toplevel);
5064 if (info.previous_screen)
5065 g_object_unref (info.previous_screen);
5069 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
5070 gpointer client_data)
5072 HierarchyChangedInfo *info = client_data;
5074 g_object_ref (widget);
5076 do_screen_change (widget, info->previous_screen, info->new_screen);
5078 if (GTK_IS_CONTAINER (widget))
5079 gtk_container_forall (GTK_CONTAINER (widget),
5080 gtk_widget_propagate_screen_changed_recurse,
5083 g_object_unref (widget);
5087 * _gtk_widget_propagate_screen_changed:
5088 * @widget: a #GtkWidget
5089 * @previous_screen: Previous screen
5091 * Propagates changes in the screen for a widget to all
5092 * children, emitting ::screen_changed.
5095 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
5096 GdkScreen *previous_screen)
5098 HierarchyChangedInfo info;
5100 info.previous_screen = previous_screen;
5101 info.new_screen = gtk_widget_get_screen (widget);
5103 if (previous_screen)
5104 g_object_ref (previous_screen);
5106 gtk_widget_propagate_screen_changed_recurse (widget, &info);
5108 if (previous_screen)
5109 g_object_unref (previous_screen);
5113 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
5115 if (GTK_WIDGET_RC_STYLE (widget))
5116 gtk_widget_reset_rc_style (widget);
5118 if (GTK_IS_CONTAINER (widget))
5119 gtk_container_forall (GTK_CONTAINER (widget),
5120 reset_rc_styles_recurse,
5125 gtk_widget_reset_rc_styles (GtkWidget *widget)
5127 g_return_if_fail (GTK_IS_WIDGET (widget));
5129 reset_rc_styles_recurse (widget, NULL);
5133 * gtk_widget_get_default_style:
5135 * Returns the default style used by all widgets initially.
5137 * Returns: the default style. This #GtkStyle object is owned by GTK+ and
5138 * should not be modified or freed.
5141 gtk_widget_get_default_style (void)
5143 if (!gtk_default_style)
5145 gtk_default_style = gtk_style_new ();
5146 g_object_ref (gtk_default_style);
5149 return gtk_default_style;
5152 static PangoContext *
5153 gtk_widget_peek_pango_context (GtkWidget *widget)
5155 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
5159 * gtk_widget_get_pango_context:
5160 * @widget: a #GtkWidget
5162 * Gets a #PangoContext with the appropriate colormap, font description
5163 * and base direction for this widget. Unlike the context returned
5164 * by gtk_widget_create_pango_context(), this context is owned by
5165 * the widget (it can be used until the screen for the widget changes
5166 * or the widget is removed from its toplevel), and will be updated to
5167 * match any changes to the widget's attributes.
5169 * If you create and keep a #PangoLayout using this context, you must
5170 * deal with changes to the context by calling pango_layout_context_changed()
5171 * on the layout in response to the ::style-set and ::direction-changed signals
5174 * Return value: the #PangoContext for the widget.
5177 gtk_widget_get_pango_context (GtkWidget *widget)
5179 PangoContext *context;
5181 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5183 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
5186 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
5187 g_object_set_qdata_full (G_OBJECT (widget),
5188 quark_pango_context,
5197 update_pango_context (GtkWidget *widget,
5198 PangoContext *context)
5200 pango_context_set_font_description (context, widget->style->font_desc);
5201 pango_context_set_base_dir (context,
5202 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
5203 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
5207 gtk_widget_update_pango_context (GtkWidget *widget)
5209 PangoContext *context = gtk_widget_peek_pango_context (widget);
5215 update_pango_context (widget, context);
5217 screen = gtk_widget_get_screen_unchecked (widget);
5220 pango_cairo_context_set_resolution (context,
5221 gdk_screen_get_resolution (screen));
5222 pango_cairo_context_set_font_options (context,
5223 gdk_screen_get_font_options (screen));
5229 * gtk_widget_create_pango_context:
5230 * @widget: a #GtkWidget
5232 * Creates a new #PangoContext with the appropriate colormap,
5233 * font description, and base direction for drawing text for
5234 * this widget. See also gtk_widget_get_pango_context().
5236 * Return value: the new #PangoContext
5239 gtk_widget_create_pango_context (GtkWidget *widget)
5242 PangoContext *context;
5244 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5246 screen = gtk_widget_get_screen_unchecked (widget);
5249 GTK_NOTE (MULTIHEAD,
5250 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
5252 screen = gdk_screen_get_default ();
5255 context = gdk_pango_context_get_for_screen (screen);
5257 update_pango_context (widget, context);
5258 pango_context_set_language (context, gtk_get_default_language ());
5264 * gtk_widget_create_pango_layout:
5265 * @widget: a #GtkWidget
5266 * @text: text to set on the layout (can be %NULL)
5268 * Creates a new #PangoLayout with the appropriate colormap,
5269 * font description, and base direction for drawing text for
5272 * If you keep a #PangoLayout created in this way around, in order
5273 * notify the layout of changes to the base direction or font of this
5274 * widget, you must call pango_layout_context_changed() in response to
5275 * the ::style-set and ::direction-changed signals for the widget.
5277 * Return value: the new #PangoLayout
5280 gtk_widget_create_pango_layout (GtkWidget *widget,
5283 PangoLayout *layout;
5284 PangoContext *context;
5286 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5288 context = gtk_widget_get_pango_context (widget);
5289 layout = pango_layout_new (context);
5292 pango_layout_set_text (layout, text, -1);
5298 * gtk_widget_render_icon:
5299 * @widget: a #GtkWidget
5300 * @stock_id: a stock ID
5301 * @size: a stock size. A size of (GtkIconSize)-1 means render at
5302 * the size of the source and don't scale (if there are multiple
5303 * source sizes, GTK+ picks one of the available sizes).
5304 * @detail: render detail to pass to theme engine
5306 * A convenience function that uses the theme engine and RC file
5307 * settings for @widget to look up @stock_id and render it to
5308 * a pixbuf. @stock_id should be a stock icon ID such as
5309 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
5310 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
5311 * identifies the widget or code doing the rendering, so that
5312 * theme engines can special-case rendering for that widget or code.
5314 * The pixels in the returned #GdkPixbuf are shared with the rest of
5315 * the application and should not be modified. The pixbuf should be freed
5316 * after use with g_object_unref().
5318 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
5321 gtk_widget_render_icon (GtkWidget *widget,
5322 const gchar *stock_id,
5324 const gchar *detail)
5326 GtkIconSet *icon_set;
5329 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5330 g_return_val_if_fail (stock_id != NULL, NULL);
5331 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
5333 gtk_widget_ensure_style (widget);
5335 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
5337 if (icon_set == NULL)
5340 retval = gtk_icon_set_render_icon (icon_set,
5342 gtk_widget_get_direction (widget),
5343 GTK_WIDGET_STATE (widget),
5352 * gtk_widget_set_parent_window:
5353 * @widget: a #GtkWidget.
5354 * @parent_window: the new parent window.
5356 * Sets a non default parent window for @widget.
5359 gtk_widget_set_parent_window (GtkWidget *widget,
5360 GdkWindow *parent_window)
5362 GdkWindow *old_parent_window;
5364 g_return_if_fail (GTK_IS_WIDGET (widget));
5366 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
5367 quark_parent_window);
5369 if (parent_window != old_parent_window)
5371 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
5373 if (old_parent_window)
5374 g_object_unref (old_parent_window);
5376 g_object_ref (parent_window);
5382 * gtk_widget_set_child_visible:
5383 * @widget: a #GtkWidget
5384 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
5386 * Sets whether @widget should be mapped along with its when its parent
5387 * is mapped and @widget has been shown with gtk_widget_show().
5389 * The child visibility can be set for widget before it is added to
5390 * a container with gtk_widget_set_parent(), to avoid mapping
5391 * children unnecessary before immediately unmapping them. However
5392 * it will be reset to its default state of %TRUE when the widget
5393 * is removed from a container.
5395 * Note that changing the child visibility of a widget does not
5396 * queue a resize on the widget. Most of the time, the size of
5397 * a widget is computed from all visible children, whether or
5398 * not they are mapped. If this is not the case, the container
5399 * can queue a resize itself.
5401 * This function is only useful for container implementations and
5402 * never should be called by an application.
5405 gtk_widget_set_child_visible (GtkWidget *widget,
5406 gboolean is_visible)
5408 g_return_if_fail (GTK_IS_WIDGET (widget));
5409 g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
5411 g_object_ref (widget);
5414 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
5417 GtkWidget *toplevel;
5419 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
5421 toplevel = gtk_widget_get_toplevel (widget);
5422 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
5423 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
5426 if (widget->parent && GTK_WIDGET_REALIZED (widget->parent))
5428 if (GTK_WIDGET_MAPPED (widget->parent) &&
5429 GTK_WIDGET_CHILD_VISIBLE (widget) &&
5430 GTK_WIDGET_VISIBLE (widget))
5431 gtk_widget_map (widget);
5433 gtk_widget_unmap (widget);
5436 g_object_unref (widget);
5440 * gtk_widget_get_child_visible:
5441 * @widget: a #GtkWidget
5443 * Gets the value set with gtk_widget_set_child_visible().
5444 * If you feel a need to use this function, your code probably
5445 * needs reorganization.
5447 * This function is only useful for container implementations and
5448 * never should be called by an application.
5450 * Return value: %TRUE if the widget is mapped with the parent.
5453 gtk_widget_get_child_visible (GtkWidget *widget)
5455 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5457 return GTK_WIDGET_CHILD_VISIBLE (widget);
5461 gtk_widget_get_screen_unchecked (GtkWidget *widget)
5463 GtkWidget *toplevel;
5465 toplevel = gtk_widget_get_toplevel (widget);
5467 if (GTK_WIDGET_TOPLEVEL (toplevel))
5469 if (GTK_IS_WINDOW (toplevel))
5470 return GTK_WINDOW (toplevel)->screen;
5471 else if (GTK_IS_INVISIBLE (toplevel))
5472 return GTK_INVISIBLE (widget)->screen;
5479 * gtk_widget_get_screen:
5480 * @widget: a #GtkWidget
5482 * Get the #GdkScreen from the toplevel window associated with
5483 * this widget. This function can only be called after the widget
5484 * has been added to a widget hierarchy with a #GtkWindow
5487 * In general, you should only create screen specific
5488 * resources when a widget has been realized, and you should
5489 * free those resources when the widget is unrealized.
5491 * Return value: the #GdkScreen for the toplevel for this widget.
5496 gtk_widget_get_screen (GtkWidget *widget)
5500 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5502 screen = gtk_widget_get_screen_unchecked (widget);
5509 g_warning (G_STRLOC ": Can't get associated screen"
5510 " for a widget unless it is inside a toplevel GtkWindow\n"
5511 " widget type is %s associated top level type is %s",
5512 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
5513 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
5515 return gdk_screen_get_default ();
5520 * gtk_widget_has_screen:
5521 * @widget: a #GtkWidget
5523 * Checks whether there is a #GdkScreen is associated with
5524 * this widget. All toplevel widgets have an associated
5525 * screen, and all widgets added into a heirarchy with a toplevel
5526 * window at the top.
5528 * Return value: %TRUE if there is a #GdkScreen associcated
5534 gtk_widget_has_screen (GtkWidget *widget)
5536 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5538 return (gtk_widget_get_screen_unchecked (widget) != NULL);
5542 * gtk_widget_get_display:
5543 * @widget: a #GtkWidget
5545 * Get the #GdkDisplay for the toplevel window associated with
5546 * this widget. This function can only be called after the widget
5547 * has been added to a widget hierarchy with a #GtkWindow at the top.
5549 * In general, you should only create display specific
5550 * resources when a widget has been realized, and you should
5551 * free those resources when the widget is unrealized.
5553 * Return value: the #GdkDisplay for the toplevel for this widget.
5558 gtk_widget_get_display (GtkWidget *widget)
5560 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5562 return gdk_screen_get_display (gtk_widget_get_screen (widget));
5566 * gtk_widget_get_root_window:
5567 * @widget: a #GtkWidget
5569 * Get the root window where this widget is located. This function can
5570 * only be called after the widget has been added to a widget
5571 * heirarchy with #GtkWindow at the top.
5573 * The root window is useful for such purposes as creating a popup
5574 * #GdkWindow associated with the window. In general, you should only
5575 * create display specific resources when a widget has been realized,
5576 * and you should free those resources when the widget is unrealized.
5578 * Return value: the #GdkWindow root window for the toplevel for this widget.
5583 gtk_widget_get_root_window (GtkWidget *widget)
5585 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5587 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
5591 * gtk_widget_get_parent_window:
5592 * @widget: a #GtkWidget.
5593 * @returns: the parent window of @widget.
5595 * Gets @widget's parent window.
5598 gtk_widget_get_parent_window (GtkWidget *widget)
5600 GdkWindow *parent_window;
5602 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5603 g_return_val_if_fail (widget->parent != NULL, NULL);
5605 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
5607 return (parent_window != NULL) ? parent_window : widget->parent->window;
5611 * gtk_widget_child_focus:
5612 * @widget: a #GtkWidget
5613 * @direction: direction of focus movement
5615 * This function is used by custom widget implementations; if you're
5616 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
5617 * to a particular widget, and gtk_container_set_focus_chain() to
5618 * change the focus tab order. So you may want to investigate those
5619 * functions instead.
5621 * gtk_widget_child_focus() is called by containers as the user moves
5622 * around the window using keyboard shortcuts. @direction indicates
5623 * what kind of motion is taking place (up, down, left, right, tab
5624 * forward, tab backward). gtk_widget_child_focus() invokes the
5625 * "focus" signal on #GtkWidget; widgets override the default handler
5626 * for this signal in order to implement appropriate focus behavior.
5628 * The "focus" default handler for a widget should return %TRUE if
5629 * moving in @direction left the focus on a focusable location inside
5630 * that widget, and %FALSE if moving in @direction moved the focus
5631 * outside the widget. If returning %TRUE, widgets normally
5632 * call gtk_widget_grab_focus() to place the focus accordingly;
5633 * if returning %FALSE, they don't modify the current focus location.
5635 * This function replaces gtk_container_focus() from GTK+ 1.2. It was
5636 * necessary to check that the child was visible, sensitive, and
5637 * focusable before calling
5638 * gtk_container_focus(). gtk_widget_child_focus() returns %FALSE if
5639 * the widget is not currently in a focusable state, so there's no
5640 * need for those checks.
5642 * Return value: %TRUE if focus ended up inside @widget
5645 gtk_widget_child_focus (GtkWidget *widget,
5646 GtkDirectionType direction)
5648 gboolean return_val;
5650 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5652 if (!GTK_WIDGET_VISIBLE (widget) ||
5653 !GTK_WIDGET_IS_SENSITIVE (widget))
5656 /* child widgets must set CAN_FOCUS, containers
5657 * don't have to though.
5659 if (!GTK_IS_CONTAINER (widget) &&
5660 !GTK_WIDGET_CAN_FOCUS (widget))
5663 g_signal_emit (widget,
5664 widget_signals[FOCUS],
5666 direction, &return_val);
5672 * gtk_widget_set_uposition:
5673 * @widget: a #GtkWidget
5674 * @x: x position; -1 to unset x; -2 to leave x unchanged
5675 * @y: y position; -1 to unset y; -2 to leave y unchanged
5678 * Sets the position of a widget. The funny "u" in the name comes from
5679 * the "user position" hint specified by the X Window System, and
5680 * exists for legacy reasons. This function doesn't work if a widget
5681 * is inside a container; it's only really useful on #GtkWindow.
5683 * Don't use this function to center dialogs over the main application
5684 * window; most window managers will do the centering on your behalf
5685 * if you call gtk_window_set_transient_for(), and it's really not
5686 * possible to get the centering to work correctly in all cases from
5687 * application code. But if you insist, use gtk_window_set_position()
5688 * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
5691 * Note that although @x and @y can be individually unset, the position
5692 * is not honoured unless both @x and @y are set.
5695 gtk_widget_set_uposition (GtkWidget *widget,
5699 /* FIXME this function is the only place that aux_info->x and
5700 * aux_info->y are even used I believe, and this function is
5701 * deprecated. Should be cleaned up.
5703 * (Actually, size_allocate uses them) -Yosh
5706 GtkWidgetAuxInfo *aux_info;
5708 g_return_if_fail (GTK_IS_WIDGET (widget));
5710 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
5715 aux_info->x_set = FALSE;
5718 aux_info->x_set = TRUE;
5726 aux_info->y_set = FALSE;
5729 aux_info->y_set = TRUE;
5734 if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
5735 _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
5737 if (GTK_WIDGET_VISIBLE (widget) && widget->parent)
5738 gtk_widget_size_allocate (widget, &widget->allocation);
5742 gtk_widget_set_usize_internal (GtkWidget *widget,
5746 GtkWidgetAuxInfo *aux_info;
5747 gboolean changed = FALSE;
5749 g_return_if_fail (GTK_IS_WIDGET (widget));
5751 g_object_freeze_notify (G_OBJECT (widget));
5753 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
5755 if (width > -2 && aux_info->width != width)
5757 g_object_notify (G_OBJECT (widget), "width-request");
5758 aux_info->width = width;
5761 if (height > -2 && aux_info->height != height)
5763 g_object_notify (G_OBJECT (widget), "height-request");
5764 aux_info->height = height;
5768 if (GTK_WIDGET_VISIBLE (widget) && changed)
5769 gtk_widget_queue_resize (widget);
5771 g_object_thaw_notify (G_OBJECT (widget));
5775 * gtk_widget_set_usize:
5776 * @widget: a #GtkWidget
5777 * @width: minimum width, or -1 to unset
5778 * @height: minimum height, or -1 to unset
5780 * Sets the minimum size of a widget; that is, the widget's size
5781 * request will be @width by @height. You can use this function to
5782 * force a widget to be either larger or smaller than it is. The
5783 * strange "usize" name dates from the early days of GTK+, and derives
5784 * from X Window System terminology. In many cases,
5785 * gtk_window_set_default_size() is a better choice for toplevel
5786 * windows than this function; setting the default size will still
5787 * allow users to shrink the window. Setting the usize will force them
5788 * to leave the window at least as large as the usize. When dealing
5789 * with window sizes, gtk_window_set_geometry_hints() can be a useful
5792 * Note the inherent danger of setting any fixed size - themes,
5793 * translations into other languages, different fonts, and user action
5794 * can all change the appropriate size for a given widget. So, it's
5795 * basically impossible to hardcode a size that will always be
5798 * @Deprecated: Use gtk_widget_set_size_request() instead.
5801 gtk_widget_set_usize (GtkWidget *widget,
5805 g_return_if_fail (GTK_IS_WIDGET (widget));
5807 gtk_widget_set_usize_internal (widget, width, height);
5811 * gtk_widget_set_size_request:
5812 * @widget: a #GtkWidget
5813 * @width: width @widget should request, or -1 to unset
5814 * @height: height @widget should request, or -1 to unset
5816 * Sets the minimum size of a widget; that is, the widget's size
5817 * request will be @width by @height. You can use this function to
5818 * force a widget to be either larger or smaller than it normally
5821 * In most cases, gtk_window_set_default_size() is a better choice for
5822 * toplevel windows than this function; setting the default size will
5823 * still allow users to shrink the window. Setting the size request
5824 * will force them to leave the window at least as large as the size
5825 * request. When dealing with window sizes,
5826 * gtk_window_set_geometry_hints() can be a useful function as well.
5828 * Note the inherent danger of setting any fixed size - themes,
5829 * translations into other languages, different fonts, and user action
5830 * can all change the appropriate size for a given widget. So, it's
5831 * basically impossible to hardcode a size that will always be
5834 * The size request of a widget is the smallest size a widget can
5835 * accept while still functioning well and drawing itself correctly.
5836 * However in some strange cases a widget may be allocated less than
5837 * its requested size, and in many cases a widget may be allocated more
5838 * space than it requested.
5840 * If the size request in a given direction is -1 (unset), then
5841 * the "natural" size request of the widget will be used instead.
5843 * Widgets can't actually be allocated a size less than 1 by 1, but
5844 * you can pass 0,0 to this function to mean "as small as possible."
5847 gtk_widget_set_size_request (GtkWidget *widget,
5851 g_return_if_fail (GTK_IS_WIDGET (widget));
5852 g_return_if_fail (width >= -1);
5853 g_return_if_fail (height >= -1);
5860 gtk_widget_set_usize_internal (widget, width, height);
5865 * gtk_widget_get_size_request:
5866 * @widget: a #GtkWidget
5867 * @width: return location for width, or %NULL
5868 * @height: return location for height, or %NULL
5870 * Gets the size request that was explicitly set for the widget using
5871 * gtk_widget_set_size_request(). A value of -1 stored in @width or
5872 * @height indicates that that dimension has not been set explicitly
5873 * and the natural requisition of the widget will be used intead. See
5874 * gtk_widget_set_size_request(). To get the size a widget will
5875 * actually use, call gtk_widget_size_request() instead of
5881 gtk_widget_get_size_request (GtkWidget *widget,
5885 GtkWidgetAuxInfo *aux_info;
5887 g_return_if_fail (GTK_IS_WIDGET (widget));
5889 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
5892 *width = aux_info ? aux_info->width : -1;
5895 *height = aux_info ? aux_info->height : -1;
5899 * gtk_widget_set_events:
5900 * @widget: a #GtkWidget
5901 * @events: event mask
5903 * Sets the event mask (see #GdkEventMask) for a widget. The event
5904 * mask determines which events a widget will receive. Keep in mind
5905 * that different widgets have different default event masks, and by
5906 * changing the event mask you may disrupt a widget's functionality,
5907 * so be careful. This function must be called while a widget is
5908 * unrealized. Consider gtk_widget_add_events() for widgets that are
5909 * already realized, or if you want to preserve the existing event
5910 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
5911 * to get events on those widgets, place them inside a #GtkEventBox
5912 * and receive events on the event box.
5916 gtk_widget_set_events (GtkWidget *widget,
5921 g_return_if_fail (GTK_IS_WIDGET (widget));
5922 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
5924 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
5929 eventp = g_new (gint, 1);
5932 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, eventp);
5937 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, NULL);
5940 g_object_notify (G_OBJECT (widget), "events");
5944 gtk_widget_add_events_internal (GtkWidget *widget,
5950 for (l = window_list; l != NULL; l = l->next)
5952 GdkWindow *window = l->data;
5955 gdk_window_get_user_data (window, &user_data);
5956 if (user_data == widget)
5960 gdk_window_set_events (window, gdk_window_get_events (window) | events);
5962 children = gdk_window_get_children (window);
5963 gtk_widget_add_events_internal (widget, events, children);
5964 g_list_free (children);
5970 * gtk_widget_add_events:
5971 * @widget: a #GtkWidget
5972 * @events: an event mask, see #GdkEventMask
5974 * Adds the events in the bitfield @events to the event mask for
5975 * @widget. See gtk_widget_set_events() for details.
5979 gtk_widget_add_events (GtkWidget *widget,
5984 g_return_if_fail (GTK_IS_WIDGET (widget));
5986 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
5992 eventp = g_new (gint, 1);
5997 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, eventp);
6002 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, NULL);
6005 if (GTK_WIDGET_REALIZED (widget))
6009 if (GTK_WIDGET_NO_WINDOW (widget))
6010 window_list = gdk_window_get_children (widget->window);
6012 window_list = g_list_prepend (NULL, widget->window);
6014 gtk_widget_add_events_internal (widget, events, window_list);
6016 g_list_free (window_list);
6019 g_object_notify (G_OBJECT (widget), "events");
6023 * gtk_widget_set_extension_events:
6024 * @widget: a #GtkWidget
6025 * @mode: bitfield of extension events to receive
6027 * Sets the extension events mask to @mode. See #GdkExtensionMode
6028 * and gdk_input_set_extension_events().
6032 gtk_widget_set_extension_events (GtkWidget *widget,
6033 GdkExtensionMode mode)
6035 GdkExtensionMode *modep;
6037 g_return_if_fail (GTK_IS_WIDGET (widget));
6039 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
6042 modep = g_new (GdkExtensionMode, 1);
6045 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode, modep);
6046 g_object_notify (G_OBJECT (widget), "extension-events");
6050 * gtk_widget_get_toplevel:
6051 * @widget: a #GtkWidget
6053 * This function returns the topmost widget in the container hierarchy
6054 * @widget is a part of. If @widget has no parent widgets, it will be
6055 * returned as the topmost widget. No reference will be added to the
6056 * returned widget; it should not be unreferenced.
6058 * Note the difference in behavior vs. gtk_widget_get_ancestor();
6059 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
6061 * %NULL if @widget wasn't inside a toplevel window, and if the
6062 * window was inside a #GtkWindow-derived widget which was in turn
6063 * inside the toplevel #GtkWindow. While the second case may
6064 * seem unlikely, it actually happens when a #GtkPlug is embedded
6065 * inside a #GtkSocket within the same application.
6067 * To reliably find the toplevel #GtkWindow, use
6068 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
6069 * is set on the result.
6070 * <informalexample><programlisting>
6071 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6072 * if (GTK_WIDGET_TOPLEVEL (toplevel))
6074 * [ Perform action on toplevel. ]
6076 * </programlisting></informalexample>
6078 * Return value: the topmost ancestor of @widget, or @widget itself if there's no ancestor.
6081 gtk_widget_get_toplevel (GtkWidget *widget)
6083 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6085 while (widget->parent)
6086 widget = widget->parent;
6092 * gtk_widget_get_ancestor:
6093 * @widget: a #GtkWidget
6094 * @widget_type: ancestor type
6096 * Gets the first ancestor of @widget with type @widget_type. For example,
6097 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets the
6098 * first #GtkBox that's
6099 * an ancestor of @widget. No reference will be added to the returned widget;
6100 * it should not be unreferenced. See note about checking for a toplevel
6101 * #GtkWindow in the docs for gtk_widget_get_toplevel().
6103 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
6104 * considers @widget to be an ancestor of itself.
6106 * Return value: the ancestor widget, or %NULL if not found
6109 gtk_widget_get_ancestor (GtkWidget *widget,
6112 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6114 while (widget && !g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))
6115 widget = widget->parent;
6117 if (!(widget && g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)))
6124 * gtk_widget_get_colormap:
6125 * @widget: a #GtkWidget
6127 * Gets the colormap that will be used to render @widget. No reference will
6128 * be added to the returned colormap; it should not be unreferenced.
6130 * Return value: the colormap used by @widget
6133 gtk_widget_get_colormap (GtkWidget *widget)
6135 GdkColormap *colormap;
6136 GtkWidget *tmp_widget;
6138 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6142 colormap = gdk_drawable_get_colormap (widget->window);
6143 /* If window was destroyed previously, we'll get NULL here */
6148 tmp_widget = widget;
6151 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
6155 tmp_widget= tmp_widget->parent;
6158 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
6162 * gtk_widget_get_visual:
6163 * @widget: a #GtkWidget
6165 * Gets the visual that will be used to render @widget.
6167 * Return value: the visual for @widget
6170 gtk_widget_get_visual (GtkWidget *widget)
6172 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6174 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
6178 * gtk_widget_get_settings:
6179 * @widget: a #GtkWidget
6181 * Gets the settings object holding the settings (global property
6182 * settings, RC file information, etc) used for this widget.
6184 * Note that this function can only be called when the #GtkWidget
6185 * is attached to a toplevel, since the settings object is specific
6186 * to a particular #GdkScreen.
6188 * Return value: the relevant #GtkSettings object
6191 gtk_widget_get_settings (GtkWidget *widget)
6193 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6195 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
6199 * gtk_widget_set_colormap:
6200 * @widget: a #GtkWidget
6201 * @colormap: a colormap
6203 * Sets the colormap for the widget to the given value. Widget must not
6204 * have been previously realized. This probably should only be used
6205 * from an <function>init()</function> function (i.e. from the constructor
6210 gtk_widget_set_colormap (GtkWidget *widget,
6211 GdkColormap *colormap)
6213 g_return_if_fail (GTK_IS_WIDGET (widget));
6214 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
6215 g_return_if_fail (GDK_IS_COLORMAP (colormap));
6217 g_object_ref (colormap);
6219 g_object_set_qdata_full (G_OBJECT (widget),
6226 * gtk_widget_get_events:
6227 * @widget: a #GtkWidget
6229 * Returns the event mask for the widget (a bitfield containing flags
6230 * from the #GdkEventMask enumeration). These are the events that the widget
6233 * Return value: event mask for @widget
6236 gtk_widget_get_events (GtkWidget *widget)
6240 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
6242 events = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
6250 * gtk_widget_get_extension_events:
6251 * @widget: a #GtkWidget
6253 * Retrieves the extension events the widget will receive; see
6254 * gdk_input_set_extension_events().
6256 * Return value: extension events for @widget
6259 gtk_widget_get_extension_events (GtkWidget *widget)
6261 GdkExtensionMode *mode;
6263 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
6265 mode = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
6273 * gtk_widget_get_pointer:
6274 * @widget: a #GtkWidget
6275 * @x: return location for the X coordinate, or %NULL
6276 * @y: return location for the Y coordinate, or %NULL
6278 * Obtains the location of the mouse pointer in widget coordinates.
6279 * Widget coordinates are a bit odd; for historical reasons, they are
6280 * defined as @widget->window coordinates for widgets that are not
6281 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
6282 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
6286 gtk_widget_get_pointer (GtkWidget *widget,
6290 g_return_if_fail (GTK_IS_WIDGET (widget));
6297 if (GTK_WIDGET_REALIZED (widget))
6299 gdk_window_get_pointer (widget->window, x, y, NULL);
6301 if (GTK_WIDGET_NO_WINDOW (widget))
6304 *x -= widget->allocation.x;
6306 *y -= widget->allocation.y;
6312 * gtk_widget_is_ancestor:
6313 * @widget: a #GtkWidget
6314 * @ancestor: another #GtkWidget
6316 * Determines whether @widget is somewhere inside @ancestor, possibly with
6317 * intermediate containers.
6319 * Return value: %TRUE if @ancestor contains @widget as a child, grandchild, great grandchild, etc.
6322 gtk_widget_is_ancestor (GtkWidget *widget,
6323 GtkWidget *ancestor)
6325 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6326 g_return_val_if_fail (ancestor != NULL, FALSE);
6330 if (widget->parent == ancestor)
6332 widget = widget->parent;
6338 static GQuark quark_composite_name = 0;
6341 * gtk_widget_set_composite_name:
6342 * @widget: a #GtkWidget.
6343 * @name: the name to set.
6345 * Sets a widgets composite name. The widget must be
6346 * a composite child of its parent; see gtk_widget_push_composite_child().
6349 gtk_widget_set_composite_name (GtkWidget *widget,
6352 g_return_if_fail (GTK_IS_WIDGET (widget));
6353 g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget));
6354 g_return_if_fail (name != NULL);
6356 if (!quark_composite_name)
6357 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
6359 g_object_set_qdata_full (G_OBJECT (widget),
6360 quark_composite_name,
6366 * gtk_widget_get_composite_name:
6367 * @widget: a #GtkWidget.
6368 * @returns: the composite name of @widget, or %NULL if @widget is not
6369 * a composite child. The string should not be freed when it is no
6372 * Obtains the composite name of a widget.
6375 gtk_widget_get_composite_name (GtkWidget *widget)
6377 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6379 if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent)
6380 return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
6387 * gtk_widget_push_composite_child:
6389 * Makes all newly-created widgets as composite children until
6390 * the corresponding gtk_widget_pop_composite_child() call.
6392 * A composite child is a child that's an implementation detail of the
6393 * container it's inside and should not be visible to people using the
6394 * container. Composite children aren't treated differently by GTK (but
6395 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
6396 * builders might want to treat them in a different way.
6398 * Here is a simple example:
6399 * <informalexample><programlisting>
6400 * gtk_widget_push_composite_child (<!-- -->);
6401 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
6402 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
6403 * gtk_widget_pop_composite_child (<!-- -->);
6404 * gtk_widget_set_parent (scrolled_window->hscrollbar,
6405 * GTK_WIDGET (scrolled_window));
6406 * g_object_ref (scrolled_window->hscrollbar);
6407 * </programlisting></informalexample>
6410 gtk_widget_push_composite_child (void)
6412 composite_child_stack++;
6416 * gtk_widget_pop_composite_child:
6418 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
6421 gtk_widget_pop_composite_child (void)
6423 if (composite_child_stack)
6424 composite_child_stack--;
6428 * gtk_widget_push_colormap:
6429 * @cmap: a #GdkColormap
6431 * Pushes @cmap onto a global stack of colormaps; the topmost
6432 * colormap on the stack will be used to create all widgets.
6433 * Remove @cmap with gtk_widget_pop_colormap(). There's little
6434 * reason to use this function.
6438 gtk_widget_push_colormap (GdkColormap *cmap)
6440 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
6442 colormap_stack = g_slist_prepend (colormap_stack, cmap);
6446 * gtk_widget_pop_colormap:
6448 * Removes a colormap pushed with gtk_widget_push_colormap().
6452 gtk_widget_pop_colormap (void)
6455 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
6459 * gtk_widget_set_default_colormap:
6460 * @colormap: a #GdkColormap
6462 * Sets the default colormap to use when creating widgets.
6463 * gtk_widget_push_colormap() is a better function to use if
6464 * you only want to affect a few widgets, rather than all widgets.
6467 gtk_widget_set_default_colormap (GdkColormap *colormap)
6469 g_return_if_fail (GDK_IS_COLORMAP (colormap));
6471 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
6476 * gtk_widget_get_default_colormap:
6478 * Obtains the default colormap used to create widgets.
6480 * Return value: default widget colormap
6483 gtk_widget_get_default_colormap (void)
6485 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
6489 * gtk_widget_get_default_visual:
6491 * Obtains the visual of the default colormap. Not really useful;
6492 * used to be useful before gdk_colormap_get_visual() existed.
6494 * Return value: visual of the default colormap
6497 gtk_widget_get_default_visual (void)
6499 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
6503 gtk_widget_emit_direction_changed (GtkWidget *widget,
6504 GtkTextDirection old_dir)
6506 gtk_widget_update_pango_context (widget);
6508 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
6512 * gtk_widget_set_direction:
6513 * @widget: a #GtkWidget
6514 * @dir: the new direction
6516 * Sets the reading direction on a particular widget. This direction
6517 * controls the primary direction for widgets containing text,
6518 * and also the direction in which the children of a container are
6519 * packed. The ability to set the direction is present in order
6520 * so that correct localization into languages with right-to-left
6521 * reading directions can be done. Generally, applications will
6522 * let the default reading direction present, except for containers
6523 * where the containers are arranged in an order that is explicitely
6524 * visual rather than logical (such as buttons for text justification).
6526 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
6527 * set by gtk_widget_set_default_direction() will be used.
6530 gtk_widget_set_direction (GtkWidget *widget,
6531 GtkTextDirection dir)
6533 GtkTextDirection old_dir;
6535 g_return_if_fail (GTK_IS_WIDGET (widget));
6536 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
6538 old_dir = gtk_widget_get_direction (widget);
6540 if (dir == GTK_TEXT_DIR_NONE)
6541 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
6544 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
6545 if (dir == GTK_TEXT_DIR_LTR)
6546 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
6548 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
6551 if (old_dir != gtk_widget_get_direction (widget))
6552 gtk_widget_emit_direction_changed (widget, old_dir);
6556 * gtk_widget_get_direction:
6557 * @widget: a #GtkWidget
6559 * Gets the reading direction for a particular widget. See
6560 * gtk_widget_set_direction().
6562 * Return value: the reading direction for the widget.
6565 gtk_widget_get_direction (GtkWidget *widget)
6567 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
6569 if (GTK_WIDGET_DIRECTION_SET (widget))
6570 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
6572 return gtk_default_direction;
6576 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
6578 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
6580 g_object_ref (widget);
6582 if (!GTK_WIDGET_DIRECTION_SET (widget))
6583 gtk_widget_emit_direction_changed (widget, old_dir);
6585 if (GTK_IS_CONTAINER (widget))
6586 gtk_container_forall (GTK_CONTAINER (widget),
6587 gtk_widget_set_default_direction_recurse,
6590 g_object_unref (widget);
6594 * gtk_widget_set_default_direction:
6595 * @dir: the new default direction. This cannot be
6596 * %GTK_TEXT_DIR_NONE.
6598 * Sets the default reading direction for widgets where the
6599 * direction has not been explicitly set by gtk_widget_set_direction().
6602 gtk_widget_set_default_direction (GtkTextDirection dir)
6604 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
6606 if (dir != gtk_default_direction)
6608 GList *toplevels, *tmp_list;
6609 GtkTextDirection old_dir = gtk_default_direction;
6611 gtk_default_direction = dir;
6613 tmp_list = toplevels = gtk_window_list_toplevels ();
6614 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
6618 gtk_widget_set_default_direction_recurse (tmp_list->data,
6619 GUINT_TO_POINTER (old_dir));
6620 g_object_unref (tmp_list->data);
6621 tmp_list = tmp_list->next;
6624 g_list_free (toplevels);
6629 * gtk_widget_get_default_direction:
6631 * Obtains the current default reading direction. See
6632 * gtk_widget_set_default_direction().
6634 * Return value: the current default direction.
6637 gtk_widget_get_default_direction (void)
6639 return gtk_default_direction;
6643 gtk_widget_dispose (GObject *object)
6645 GtkWidget *widget = GTK_WIDGET (object);
6648 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
6649 else if (GTK_WIDGET_VISIBLE (widget))
6650 gtk_widget_hide (widget);
6652 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
6653 if (GTK_WIDGET_REALIZED (widget))
6654 gtk_widget_unrealize (widget);
6656 G_OBJECT_CLASS (parent_class)->dispose (object);
6660 gtk_widget_real_destroy (GtkObject *object)
6662 /* gtk_object_destroy() will already hold a refcount on object */
6663 GtkWidget *widget = GTK_WIDGET (object);
6665 /* wipe accelerator closures (keep order) */
6666 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
6667 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
6669 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
6670 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
6672 gtk_grab_remove (widget);
6674 g_object_unref (widget->style);
6675 widget->style = gtk_widget_get_default_style ();
6676 g_object_ref (widget->style);
6678 GTK_OBJECT_CLASS (parent_class)->destroy (object);
6682 gtk_widget_finalize (GObject *object)
6684 GtkWidget *widget = GTK_WIDGET (object);
6685 GtkWidgetAuxInfo *aux_info;
6687 GdkExtensionMode *mode;
6688 GtkAccessible *accessible;
6690 gtk_grab_remove (widget);
6692 g_object_unref (widget->style);
6693 widget->style = NULL;
6696 g_free (widget->name);
6698 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
6700 gtk_widget_aux_info_destroy (aux_info);
6702 events = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
6706 mode = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
6710 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
6712 g_object_unref (accessible);
6714 G_OBJECT_CLASS (parent_class)->finalize (object);
6717 /*****************************************
6718 * gtk_widget_real_map:
6723 *****************************************/
6726 gtk_widget_real_map (GtkWidget *widget)
6728 g_return_if_fail (GTK_WIDGET_REALIZED (widget) == TRUE);
6730 if (!GTK_WIDGET_MAPPED (widget))
6732 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
6734 if (!GTK_WIDGET_NO_WINDOW (widget))
6735 gdk_window_show (widget->window);
6739 /*****************************************
6740 * gtk_widget_real_unmap:
6745 *****************************************/
6748 gtk_widget_real_unmap (GtkWidget *widget)
6750 if (GTK_WIDGET_MAPPED (widget))
6752 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
6754 if (!GTK_WIDGET_NO_WINDOW (widget))
6755 gdk_window_hide (widget->window);
6759 /*****************************************
6760 * gtk_widget_real_realize:
6765 *****************************************/
6768 gtk_widget_real_realize (GtkWidget *widget)
6770 g_return_if_fail (GTK_WIDGET_NO_WINDOW (widget));
6772 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
6775 widget->window = gtk_widget_get_parent_window (widget);
6776 g_object_ref (widget->window);
6778 widget->style = gtk_style_attach (widget->style, widget->window);
6781 /*****************************************
6782 * gtk_widget_real_unrealize:
6787 *****************************************/
6790 gtk_widget_real_unrealize (GtkWidget *widget)
6792 if (GTK_WIDGET_MAPPED (widget))
6793 gtk_widget_real_unmap (widget);
6795 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
6797 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
6800 /* We must do unrealize child widget BEFORE container widget.
6801 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
6802 * So, unrealizing container widget bofore its children causes the problem
6803 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
6806 if (GTK_IS_CONTAINER (widget))
6807 gtk_container_forall (GTK_CONTAINER (widget),
6808 (GtkCallback) gtk_widget_unrealize,
6811 gtk_style_detach (widget->style);
6812 if (!GTK_WIDGET_NO_WINDOW (widget))
6814 gdk_window_set_user_data (widget->window, NULL);
6815 gdk_window_destroy (widget->window);
6816 widget->window = NULL;
6820 g_object_unref (widget->window);
6821 widget->window = NULL;
6824 gtk_selection_remove_all (widget);
6826 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
6830 gtk_widget_real_size_request (GtkWidget *widget,
6831 GtkRequisition *requisition)
6833 requisition->width = widget->requisition.width;
6834 requisition->height = widget->requisition.height;
6838 * _gtk_widget_peek_colormap:
6840 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
6842 * Return value: the currently pushed colormap, or %NULL if there is none.
6845 _gtk_widget_peek_colormap (void)
6848 return (GdkColormap*) colormap_stack->data;
6853 gtk_widget_propagate_state (GtkWidget *widget,
6858 /* don't call this function with state==GTK_STATE_INSENSITIVE,
6859 * parent_sensitive==TRUE on a sensitive widget
6862 old_state = GTK_WIDGET_STATE (widget);
6864 if (data->parent_sensitive)
6866 GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
6868 if (GTK_WIDGET_IS_SENSITIVE (widget))
6870 if (data->state_restoration)
6871 GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget);
6873 GTK_WIDGET_STATE (widget) = data->state;
6877 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
6878 if (!data->state_restoration &&
6879 data->state != GTK_STATE_INSENSITIVE)
6880 GTK_WIDGET_SAVED_STATE (widget) = data->state;
6885 GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
6886 if (!data->state_restoration)
6888 if (data->state != GTK_STATE_INSENSITIVE)
6889 GTK_WIDGET_SAVED_STATE (widget) = data->state;
6891 else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
6892 GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget);
6893 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
6896 if (gtk_widget_is_focus (widget) && !GTK_WIDGET_IS_SENSITIVE (widget))
6900 window = gtk_widget_get_toplevel (widget);
6901 if (window && GTK_WIDGET_TOPLEVEL (window))
6902 gtk_window_set_focus (GTK_WINDOW (window), NULL);
6905 if (old_state != GTK_WIDGET_STATE (widget))
6907 g_object_ref (widget);
6909 if (!GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_HAS_GRAB (widget))
6910 gtk_grab_remove (widget);
6912 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
6914 if (GTK_IS_CONTAINER (widget))
6916 data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE);
6917 data->state = GTK_WIDGET_STATE (widget);
6918 if (data->use_forall)
6919 gtk_container_forall (GTK_CONTAINER (widget),
6920 (GtkCallback) gtk_widget_propagate_state,
6923 gtk_container_foreach (GTK_CONTAINER (widget),
6924 (GtkCallback) gtk_widget_propagate_state,
6927 g_object_unref (widget);
6932 * _gtk_widget_get_aux_info:
6933 * @widget: a #GtkWidget
6934 * @create: if %TRUE, create the structure if it doesn't exist
6936 * Get the #GtkWidgetAuxInfo structure for the widget.
6938 * Return value: the #GtkAuxInfo structure for the widget, or
6939 * %NULL if @create is %FALSE and one doesn't already exist.
6942 _gtk_widget_get_aux_info (GtkWidget *widget,
6945 GtkWidgetAuxInfo *aux_info;
6947 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
6948 if (!aux_info && create)
6950 if (!aux_info_mem_chunk)
6951 aux_info_mem_chunk = g_mem_chunk_new ("widget aux info mem chunk",
6952 sizeof (GtkWidgetAuxInfo),
6953 1024, G_ALLOC_AND_FREE);
6954 aux_info = g_chunk_new (GtkWidgetAuxInfo, aux_info_mem_chunk);
6956 aux_info->width = -1;
6957 aux_info->height = -1;
6960 aux_info->x_set = FALSE;
6961 aux_info->y_set = FALSE;
6962 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
6968 /*****************************************
6969 * gtk_widget_aux_info_destroy:
6974 *****************************************/
6977 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
6979 g_mem_chunk_free (aux_info_mem_chunk, aux_info);
6983 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
6985 g_object_unref (info->shape_mask);
6990 * gtk_widget_shape_combine_mask:
6991 * @widget: a #GtkWidget.
6992 * @shape_mask: shape to be added, or %NULL to remove an existing shape.
6993 * @offset_x: X position of shape mask with respect to @window.
6994 * @offset_y: Y position of shape mask with respect to @window.
6996 * Sets a shape for this widget's GDK window. This allows for
6997 * transparent windows etc., see gdk_window_shape_combine_mask()
6998 * for more information.
7001 gtk_widget_shape_combine_mask (GtkWidget *widget,
7002 GdkBitmap *shape_mask,
7006 GtkWidgetShapeInfo* shape_info;
7008 g_return_if_fail (GTK_IS_WIDGET (widget));
7009 /* set_shape doesn't work on widgets without gdk window */
7010 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
7014 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
7017 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
7019 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
7023 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
7025 shape_info = g_new (GtkWidgetShapeInfo, 1);
7026 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
7027 (GDestroyNotify) gtk_widget_shape_info_destroy);
7029 shape_info->shape_mask = g_object_ref (shape_mask);
7030 shape_info->offset_x = offset_x;
7031 shape_info->offset_y = offset_y;
7033 /* set shape if widget has a gdk window allready.
7034 * otherwise the shape is scheduled to be set by gtk_widget_realize.
7037 gdk_window_shape_combine_mask (widget->window, shape_mask,
7038 offset_x, offset_y);
7043 gtk_reset_shapes_recurse (GtkWidget *widget,
7049 gdk_window_get_user_data (window, &data);
7053 gdk_window_shape_combine_mask (window, NULL, 0, 0);
7054 for (list = gdk_window_peek_children (window); list; list = list->next)
7055 gtk_reset_shapes_recurse (widget, list->data);
7059 * gtk_widget_reset_shapes:
7060 * @widget: a #GtkWidget.
7062 * Recursively resets the shape on this widget and its descendants.
7065 gtk_widget_reset_shapes (GtkWidget *widget)
7067 g_return_if_fail (GTK_IS_WIDGET (widget));
7068 g_return_if_fail (GTK_WIDGET_REALIZED (widget));
7070 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
7071 gtk_reset_shapes_recurse (widget, widget->window);
7076 * @widget: a #GtkWidget
7078 * Adds a reference to a widget. This function is exactly the same
7079 * as calling g_object_ref(), and exists mostly for historical
7080 * reasons. It can still be convenient to avoid casting a widget
7081 * to a #GObject, it saves a small amount of typing.
7083 * Return value: the widget that was referenced
7086 gtk_widget_ref (GtkWidget *widget)
7088 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7090 return (GtkWidget*) g_object_ref ((GObject*) widget);
7095 * @widget: a #GtkWidget
7097 * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
7101 gtk_widget_unref (GtkWidget *widget)
7103 g_return_if_fail (GTK_IS_WIDGET (widget));
7105 g_object_unref ((GObject*) widget);
7113 * gtk_widget_class_install_style_property_parser:
7114 * @klass: a #GtkWidgetClass
7115 * @pspec: the #GParamSpec for the style property
7116 * @parser: the parser for the style property
7118 * Installs a style property on a widget class.
7121 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
7123 GtkRcPropertyParser parser)
7125 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
7126 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
7127 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
7128 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
7130 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
7132 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
7133 G_OBJECT_CLASS_NAME (klass),
7138 g_param_spec_ref (pspec);
7139 g_param_spec_sink (pspec);
7140 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
7141 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
7145 * gtk_widget_class_install_style_property:
7146 * @klass: a #GtkWidgetClass
7147 * @pspec: the #GParamSpec for the property
7149 * Installs a style property on a widget class. The parser for the
7150 * style property is determined by the value type of @pspec.
7153 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
7156 GtkRcPropertyParser parser;
7158 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
7159 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
7161 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
7163 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
7167 * gtk_widget_class_find_style_property:
7168 * @klass: a #GtkWidgetClass
7169 * @property_name: the name of the style property to find
7170 * @returns: the #GParamSpec of the style property or %NULL if @class has no
7171 * style property with that name.
7173 * Finds a style property of a widget class by name.
7178 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
7179 const gchar *property_name)
7181 g_return_val_if_fail (property_name != NULL, NULL);
7183 return g_param_spec_pool_lookup (style_property_spec_pool,
7185 G_OBJECT_CLASS_TYPE (klass),
7190 * gtk_widget_class_list_style_properties:
7191 * @klass: a #GtkWidgetClass
7192 * @n_properties: location to return the number of style properties found
7193 * @returns: an newly allocated array of #GParamSpec*. The array must be freed with g_free().
7195 * Returns all style properties of a widget class.
7200 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
7201 guint *n_properties)
7203 GParamSpec **pspecs;
7206 pspecs = g_param_spec_pool_list (style_property_spec_pool,
7207 G_OBJECT_CLASS_TYPE (klass),
7216 * gtk_widget_style_get_property:
7217 * @widget: a #GtkWidget
7218 * @property_name: the name of a style property
7219 * @value: location to return the property value
7221 * Gets the value of a style property of @widget.
7224 gtk_widget_style_get_property (GtkWidget *widget,
7225 const gchar *property_name,
7230 g_return_if_fail (GTK_IS_WIDGET (widget));
7231 g_return_if_fail (property_name != NULL);
7232 g_return_if_fail (G_IS_VALUE (value));
7234 g_object_ref (widget);
7235 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
7237 G_OBJECT_TYPE (widget),
7240 g_warning ("%s: widget class `%s' has no property named `%s'",
7242 G_OBJECT_TYPE_NAME (widget),
7246 const GValue *peek_value;
7248 peek_value = _gtk_style_peek_property_value (widget->style,
7249 G_OBJECT_TYPE (widget),
7251 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
7253 /* auto-conversion of the caller's value type
7255 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
7256 g_value_copy (peek_value, value);
7257 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
7258 g_value_transform (peek_value, value);
7260 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
7262 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
7263 G_VALUE_TYPE_NAME (value));
7265 g_object_unref (widget);
7269 * gtk_widget_style_get_valist:
7270 * @widget: a #GtkWidget
7271 * @first_property_name: the name of the first property to get
7272 * @var_args: a <type>va_list</type> of pairs of property names and
7273 * locations to return the property values, starting with the location
7274 * for @first_property_name.
7276 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
7280 gtk_widget_style_get_valist (GtkWidget *widget,
7281 const gchar *first_property_name,
7286 g_return_if_fail (GTK_IS_WIDGET (widget));
7288 g_object_ref (widget);
7290 name = first_property_name;
7293 const GValue *peek_value;
7297 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
7299 G_OBJECT_TYPE (widget),
7303 g_warning ("%s: widget class `%s' has no property named `%s'",
7305 G_OBJECT_TYPE_NAME (widget),
7309 /* style pspecs are always readable so we can spare that check here */
7311 peek_value = _gtk_style_peek_property_value (widget->style,
7312 G_OBJECT_TYPE (widget),
7314 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
7315 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
7318 g_warning ("%s: %s", G_STRLOC, error);
7323 name = va_arg (var_args, gchar*);
7326 g_object_unref (widget);
7330 * gtk_widget_style_get:
7331 * @widget: a #GtkWidget
7332 * @first_property_name: the name of the first property to get
7333 * @Varargs: pairs of property names and locations to
7334 * return the property values, starting with the location for
7335 * @first_property_name, terminated by %NULL.
7337 * Gets the values of a multiple style properties of @widget.
7340 gtk_widget_style_get (GtkWidget *widget,
7341 const gchar *first_property_name,
7346 g_return_if_fail (GTK_IS_WIDGET (widget));
7348 va_start (var_args, first_property_name);
7349 gtk_widget_style_get_valist (widget, first_property_name, var_args);
7355 * @widget: a #GtkWidget
7356 * @path_length: location to store length of the path, or %NULL
7357 * @path: location to store allocated path string, or %NULL
7358 * @path_reversed: location to store allocated reverse path string, or %NULL
7360 * Obtains the full path to @widget. The path is simply the name of a
7361 * widget and all its parents in the container hierarchy, separated by
7362 * periods. The name of a widget comes from
7363 * gtk_widget_get_name(). Paths are used to apply styles to a widget
7364 * in gtkrc configuration files. Widget names are the type of the
7365 * widget by default (e.g. "GtkButton") or can be set to an
7366 * application-specific value with gtk_widget_set_name(). By setting
7367 * the name of a widget, you allow users or theme authors to apply
7368 * styles to that specific widget in their gtkrc
7369 * file. @path_reversed_p fills in the path in reverse order,
7370 * i.e. starting with @widget's name instead of starting with the name
7371 * of @widget's outermost ancestor.
7375 gtk_widget_path (GtkWidget *widget,
7378 gchar **path_reversed)
7380 static gchar *rev_path = NULL;
7381 static guint tmp_path_len = 0;
7384 g_return_if_fail (GTK_IS_WIDGET (widget));
7389 const gchar *string;
7394 string = gtk_widget_get_name (widget);
7395 l = strlen (string);
7396 while (tmp_path_len <= len + l + 1)
7398 tmp_path_len += INIT_PATH_SIZE;
7399 rev_path = g_realloc (rev_path, tmp_path_len);
7407 widget = widget->parent;
7410 rev_path[len++] = '.';
7412 rev_path[len++] = 0;
7417 *path_length = len - 1;
7419 *path_reversed = g_strdup (rev_path);
7422 *path = g_strdup (rev_path);
7423 g_strreverse (*path);
7428 * gtk_widget_class_path:
7429 * @widget: a #GtkWidget
7430 * @path_length: location to store the length of the class path, or %NULL
7431 * @path: location to store the class path as an allocated string, or %NULL
7432 * @path_reversed: location to store the reverse class path as an allocated string, or %NULL
7434 * Same as gtk_widget_path(), but always uses the name of a widget's type,
7435 * never uses a custom name set with gtk_widget_set_name().
7439 gtk_widget_class_path (GtkWidget *widget,
7442 gchar **path_reversed)
7444 static gchar *rev_path = NULL;
7445 static guint tmp_path_len = 0;
7448 g_return_if_fail (GTK_IS_WIDGET (widget));
7453 const gchar *string;
7458 string = g_type_name (GTK_WIDGET_TYPE (widget));
7459 l = strlen (string);
7460 while (tmp_path_len <= len + l + 1)
7462 tmp_path_len += INIT_PATH_SIZE;
7463 rev_path = g_realloc (rev_path, tmp_path_len);
7471 widget = widget->parent;
7474 rev_path[len++] = '.';
7476 rev_path[len++] = 0;
7481 *path_length = len - 1;
7483 *path_reversed = g_strdup (rev_path);
7486 *path = g_strdup (rev_path);
7487 g_strreverse (*path);
7492 * gtk_requisition_copy:
7493 * @requisition: a #GtkRequisition.
7494 * @returns: a copy of @requisition.
7496 * Copies a #GtkRequisition.
7499 gtk_requisition_copy (const GtkRequisition *requisition)
7501 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
7505 * gtk_requisition_free:
7506 * @requisition: a #GtkRequisition.
7508 * Frees a #GtkRequisition.
7511 gtk_requisition_free (GtkRequisition *requisition)
7513 g_free (requisition);
7517 gtk_requisition_get_type (void)
7519 static GType our_type = 0;
7522 our_type = g_boxed_type_register_static (I_("GtkRequisition"),
7523 (GBoxedCopyFunc) gtk_requisition_copy,
7524 (GBoxedFreeFunc) gtk_requisition_free);
7530 * gtk_widget_get_accessible:
7531 * @widget: a #GtkWidget
7533 * Returns the accessible object that describes the widget to an
7534 * assistive technology.
7536 * If no accessibility library is loaded (i.e. no ATK implementation library is
7537 * loaded via <envar>GTK_MODULES</envar> or via another application library,
7538 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
7539 * if no class-specific #AtkObject implementation is available for the widget
7540 * instance in question, it will inherit an #AtkObject implementation from the
7541 * first ancestor class for which such an implementation is defined.
7543 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
7544 * library contains more information about accessible objects and their uses.
7546 * Returns: the #AtkObject associated with @widget
7549 gtk_widget_get_accessible (GtkWidget *widget)
7551 GtkWidgetClass *klass;
7553 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7555 klass = GTK_WIDGET_GET_CLASS (widget);
7557 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
7559 return klass->get_accessible (widget);
7563 gtk_widget_real_get_accessible (GtkWidget *widget)
7565 AtkObject* accessible;
7567 accessible = g_object_get_qdata (G_OBJECT (widget),
7568 quark_accessible_object);
7571 AtkObjectFactory *factory;
7572 AtkRegistry *default_registry;
7574 default_registry = atk_get_default_registry ();
7575 factory = atk_registry_get_factory (default_registry,
7576 G_TYPE_FROM_INSTANCE (widget));
7578 atk_object_factory_create_accessible (factory,
7580 g_object_set_qdata (G_OBJECT (widget),
7581 quark_accessible_object,
7588 * Initialize a AtkImplementorIface instance's virtual pointers as
7589 * appropriate to this implementor's class (GtkWidget).
7592 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
7594 iface->ref_accessible = gtk_widget_ref_accessible;
7598 gtk_widget_ref_accessible (AtkImplementor *implementor)
7600 AtkObject *accessible;
7602 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
7604 g_object_ref (accessible);
7609 * gtk_widget_get_clipboard:
7610 * @widget: a #GtkWidget
7611 * @selection: a #GdkAtom which identifies the clipboard
7612 * to use. %GDK_SELECTION_CLIPBOARD gives the
7613 * default clipboard. Another common value
7614 * is %GDK_SELECTION_PRIMARY, which gives
7615 * the primary X selection.
7617 * Returns the clipboard object for the given selection to
7618 * be used with @widget. @widget must have a #GdkDisplay
7619 * associated with it, so must be attached to a toplevel
7622 * Return value: the appropriate clipboard object. If no
7623 * clipboard already exists, a new one will
7624 * be created. Once a clipboard object has
7625 * been created, it is persistent for all time.
7630 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
7632 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7633 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
7635 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
7640 * gtk_widget_list_mnemonic_labels:
7641 * @widget: a #GtkWidget
7643 * Returns a newly allocated list of the widgets, normally labels, for
7644 * which this widget is a the target of a mnemonic (see for example,
7645 * gtk_label_set_mnemonic_widget()).
7647 * The widgets in the list are not individually referenced. If you
7648 * want to iterate through the list and perform actions involving
7649 * callbacks that might destroy the widgets, you
7650 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
7651 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
7652 * widgets afterwards.
7654 * Return value: the list of mnemonic labels; free this list
7655 * with g_list_free() when you are done with it.
7660 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
7665 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7667 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
7668 list = g_list_prepend (list, l->data);
7674 * gtk_widget_add_mnemonic_label:
7675 * @widget: a #GtkWidget
7676 * @label: a #GtkWidget that acts as a mnemonic label for @widget.
7678 * Adds a widget to the list of mnemonic labels for
7679 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
7680 * list of mnemonic labels for the widget is cleared when the
7681 * widget is destroyed, so the caller must make sure to update
7682 * its internal state at this point as well, by using a connection
7683 * to the ::destroy signal or a weak notifier.
7688 gtk_widget_add_mnemonic_label (GtkWidget *widget,
7691 GSList *old_list, *new_list;
7693 g_return_if_fail (GTK_IS_WIDGET (widget));
7694 g_return_if_fail (GTK_IS_WIDGET (label));
7696 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
7697 new_list = g_slist_prepend (old_list, label);
7699 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
7700 new_list, (GDestroyNotify) g_slist_free);
7704 * gtk_widget_remove_mnemonic_label:
7705 * @widget: a #GtkWidget
7706 * @label: a #GtkWidget that was previously set as a mnemnic label for
7707 * @widget with gtk_widget_add_mnemonic_label().
7709 * Removes a widget from the list of mnemonic labels for
7710 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
7711 * must have previously been added to the list with
7712 * gtk_widget_add_mnemonic_label().
7717 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
7720 GSList *old_list, *new_list;
7722 g_return_if_fail (GTK_IS_WIDGET (widget));
7723 g_return_if_fail (GTK_IS_WIDGET (label));
7725 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
7726 new_list = g_slist_remove (old_list, label);
7729 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
7730 new_list, (GDestroyNotify) g_slist_free);
7734 * gtk_widget_get_no_show_all:
7735 * @widget: a #GtkWidget
7737 * Returns the current value of the "no_show_all" property, which determines
7738 * whether calls to gtk_widget_show_all() and gtk_widget_hide_all()
7739 * will affect this widget.
7741 * Return value: the current value of the "no_show_all" property.
7746 gtk_widget_get_no_show_all (GtkWidget *widget)
7748 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7750 return (GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
7754 * gtk_widget_set_no_show_all:
7755 * @widget: a #GtkWidget
7756 * @no_show_all: the new value for the "no_show_all" property
7758 * Sets the "no_show_all" property, which determines whether calls to
7759 * gtk_widget_show_all() and gtk_widget_hide_all() will affect this widget.
7761 * This is mostly for use in constructing widget hierarchies with externally
7762 * controlled visibility, see #GtkUIManager.
7767 gtk_widget_set_no_show_all (GtkWidget *widget,
7768 gboolean no_show_all)
7770 g_return_if_fail (GTK_IS_WIDGET (widget));
7772 no_show_all = (no_show_all != FALSE);
7774 if (no_show_all == ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0))
7778 GTK_WIDGET_SET_FLAGS (widget, GTK_NO_SHOW_ALL);
7780 GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_SHOW_ALL);
7782 g_object_notify (G_OBJECT (widget), "no-show-all");
7785 #define __GTK_WIDGET_C__
7786 #include "gtkaliasdef.c"