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 GtkStyle *gtk_default_style = NULL;
240 static GSList *colormap_stack = NULL;
241 static guint composite_child_stack = 0;
242 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
243 static GParamSpecPool *style_property_spec_pool = NULL;
245 static GQuark quark_property_parser = 0;
246 static GQuark quark_aux_info = 0;
247 static GQuark quark_accel_path = 0;
248 static GQuark quark_accel_closures = 0;
249 static GQuark quark_event_mask = 0;
250 static GQuark quark_extension_event_mode = 0;
251 static GQuark quark_parent_window = 0;
252 static GQuark quark_shape_info = 0;
253 static GQuark quark_input_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_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
329 quark_colormap = g_quark_from_static_string ("gtk-colormap");
330 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
331 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
332 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
333 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
335 style_property_spec_pool = g_param_spec_pool_new (FALSE);
336 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
337 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
338 cpn_context.dispatcher = child_property_notify_dispatcher;
339 _gtk_widget_child_property_notify_context = &cpn_context;
341 gobject_class->dispose = gtk_widget_dispose;
342 gobject_class->finalize = gtk_widget_finalize;
343 gobject_class->set_property = gtk_widget_set_property;
344 gobject_class->get_property = gtk_widget_get_property;
346 object_class->destroy = gtk_widget_real_destroy;
348 klass->activate_signal = 0;
349 klass->set_scroll_adjustments_signal = 0;
350 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
351 klass->show = gtk_widget_real_show;
352 klass->show_all = gtk_widget_show;
353 klass->hide = gtk_widget_real_hide;
354 klass->hide_all = gtk_widget_hide;
355 klass->map = gtk_widget_real_map;
356 klass->unmap = gtk_widget_real_unmap;
357 klass->realize = gtk_widget_real_realize;
358 klass->unrealize = gtk_widget_real_unrealize;
359 klass->size_request = gtk_widget_real_size_request;
360 klass->size_allocate = gtk_widget_real_size_allocate;
361 klass->state_changed = NULL;
362 klass->parent_set = NULL;
363 klass->hierarchy_changed = NULL;
364 klass->style_set = gtk_widget_style_set;
365 klass->direction_changed = gtk_widget_direction_changed;
366 klass->grab_notify = NULL;
367 klass->child_notify = NULL;
368 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
369 klass->grab_focus = gtk_widget_real_grab_focus;
370 klass->focus = gtk_widget_real_focus;
372 klass->button_press_event = NULL;
373 klass->button_release_event = NULL;
374 klass->motion_notify_event = NULL;
375 klass->delete_event = NULL;
376 klass->destroy_event = NULL;
377 klass->expose_event = NULL;
378 klass->key_press_event = gtk_widget_real_key_press_event;
379 klass->key_release_event = gtk_widget_real_key_release_event;
380 klass->enter_notify_event = NULL;
381 klass->leave_notify_event = NULL;
382 klass->configure_event = NULL;
383 klass->focus_in_event = gtk_widget_real_focus_in_event;
384 klass->focus_out_event = gtk_widget_real_focus_out_event;
385 klass->map_event = NULL;
386 klass->unmap_event = NULL;
387 klass->window_state_event = NULL;
388 klass->property_notify_event = _gtk_selection_property_notify;
389 klass->selection_clear_event = gtk_selection_clear;
390 klass->selection_request_event = _gtk_selection_request;
391 klass->selection_notify_event = _gtk_selection_notify;
392 klass->selection_received = NULL;
393 klass->proximity_in_event = NULL;
394 klass->proximity_out_event = NULL;
395 klass->drag_begin = NULL;
396 klass->drag_end = NULL;
397 klass->drag_data_delete = NULL;
398 klass->drag_leave = NULL;
399 klass->drag_motion = NULL;
400 klass->drag_drop = NULL;
401 klass->drag_data_received = NULL;
402 klass->screen_changed = NULL;
403 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
404 klass->grab_broken_event = NULL;
406 klass->show_help = gtk_widget_real_show_help;
408 /* Accessibility support */
409 klass->get_accessible = gtk_widget_real_get_accessible;
411 klass->no_expose_event = NULL;
413 g_object_class_install_property (gobject_class,
415 g_param_spec_string ("name",
417 P_("The name of the widget"),
419 GTK_PARAM_READWRITE));
420 g_object_class_install_property (gobject_class,
422 g_param_spec_object ("parent",
424 P_("The parent widget of this widget. Must be a Container widget"),
426 GTK_PARAM_READWRITE));
428 g_object_class_install_property (gobject_class,
430 g_param_spec_int ("width-request",
432 P_("Override for width request of the widget, or -1 if natural request should be used"),
436 GTK_PARAM_READWRITE));
437 g_object_class_install_property (gobject_class,
439 g_param_spec_int ("height-request",
440 P_("Height request"),
441 P_("Override for height request of the widget, or -1 if natural request should be used"),
445 GTK_PARAM_READWRITE));
446 g_object_class_install_property (gobject_class,
448 g_param_spec_boolean ("visible",
450 P_("Whether the widget is visible"),
452 GTK_PARAM_READWRITE));
453 g_object_class_install_property (gobject_class,
455 g_param_spec_boolean ("sensitive",
457 P_("Whether the widget responds to input"),
459 GTK_PARAM_READWRITE));
460 g_object_class_install_property (gobject_class,
462 g_param_spec_boolean ("app-paintable",
463 P_("Application paintable"),
464 P_("Whether the application will paint directly on the widget"),
466 GTK_PARAM_READWRITE));
467 g_object_class_install_property (gobject_class,
469 g_param_spec_boolean ("can-focus",
471 P_("Whether the widget can accept the input focus"),
473 GTK_PARAM_READWRITE));
474 g_object_class_install_property (gobject_class,
476 g_param_spec_boolean ("has-focus",
478 P_("Whether the widget has the input focus"),
480 GTK_PARAM_READWRITE));
481 g_object_class_install_property (gobject_class,
483 g_param_spec_boolean ("is-focus",
485 P_("Whether the widget is the focus widget within the toplevel"),
487 GTK_PARAM_READWRITE));
488 g_object_class_install_property (gobject_class,
490 g_param_spec_boolean ("can-default",
492 P_("Whether the widget can be the default widget"),
494 GTK_PARAM_READWRITE));
495 g_object_class_install_property (gobject_class,
497 g_param_spec_boolean ("has-default",
499 P_("Whether the widget is the default widget"),
501 GTK_PARAM_READWRITE));
502 g_object_class_install_property (gobject_class,
503 PROP_RECEIVES_DEFAULT,
504 g_param_spec_boolean ("receives-default",
505 P_("Receives default"),
506 P_("If TRUE, the widget will receive the default action when it is focused"),
508 GTK_PARAM_READWRITE));
509 g_object_class_install_property (gobject_class,
510 PROP_COMPOSITE_CHILD,
511 g_param_spec_boolean ("composite-child",
512 P_("Composite child"),
513 P_("Whether the widget is part of a composite widget"),
515 GTK_PARAM_READABLE));
516 g_object_class_install_property (gobject_class,
518 g_param_spec_object ("style",
520 P_("The style of the widget, which contains information about how it will look (colors etc)"),
522 GTK_PARAM_READWRITE));
523 g_object_class_install_property (gobject_class,
525 g_param_spec_flags ("events",
527 P_("The event mask that decides what kind of GdkEvents this widget gets"),
530 GTK_PARAM_READWRITE));
531 g_object_class_install_property (gobject_class,
532 PROP_EXTENSION_EVENTS,
533 g_param_spec_enum ("extension-events",
534 P_("Extension events"),
535 P_("The mask that decides what kind of extension events this widget gets"),
536 GDK_TYPE_EXTENSION_MODE,
537 GDK_EXTENSION_EVENTS_NONE,
538 GTK_PARAM_READWRITE));
539 g_object_class_install_property (gobject_class,
541 g_param_spec_boolean ("no-show-all",
543 P_("Whether gtk_widget_show_all() should not affect this widget"),
545 GTK_PARAM_READWRITE));
546 widget_signals[SHOW] =
547 g_signal_new (I_("show"),
548 G_TYPE_FROM_CLASS (gobject_class),
550 G_STRUCT_OFFSET (GtkWidgetClass, show),
552 _gtk_marshal_VOID__VOID,
554 widget_signals[HIDE] =
555 g_signal_new (I_("hide"),
556 G_TYPE_FROM_CLASS (gobject_class),
558 G_STRUCT_OFFSET (GtkWidgetClass, hide),
560 _gtk_marshal_VOID__VOID,
562 widget_signals[MAP] =
563 g_signal_new (I_("map"),
564 G_TYPE_FROM_CLASS (gobject_class),
566 G_STRUCT_OFFSET (GtkWidgetClass, map),
568 _gtk_marshal_VOID__VOID,
570 widget_signals[UNMAP] =
571 g_signal_new (I_("unmap"),
572 G_TYPE_FROM_CLASS (gobject_class),
574 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
576 _gtk_marshal_VOID__VOID,
578 widget_signals[REALIZE] =
579 g_signal_new (I_("realize"),
580 G_TYPE_FROM_CLASS (gobject_class),
582 G_STRUCT_OFFSET (GtkWidgetClass, realize),
584 _gtk_marshal_VOID__VOID,
586 widget_signals[UNREALIZE] =
587 g_signal_new (I_("unrealize"),
588 G_TYPE_FROM_CLASS (gobject_class),
590 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
592 _gtk_marshal_VOID__VOID,
594 widget_signals[SIZE_REQUEST] =
595 g_signal_new (I_("size_request"),
596 G_TYPE_FROM_CLASS (gobject_class),
598 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
600 _gtk_marshal_VOID__BOXED,
602 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
603 widget_signals[SIZE_ALLOCATE] =
604 g_signal_new (I_("size_allocate"),
605 G_TYPE_FROM_CLASS (gobject_class),
607 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
609 _gtk_marshal_VOID__BOXED,
611 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
612 widget_signals[STATE_CHANGED] =
613 g_signal_new (I_("state_changed"),
614 G_TYPE_FROM_CLASS (gobject_class),
616 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
618 _gtk_marshal_VOID__ENUM,
620 GTK_TYPE_STATE_TYPE);
621 widget_signals[PARENT_SET] =
622 g_signal_new (I_("parent_set"),
623 G_TYPE_FROM_CLASS (gobject_class),
625 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
627 _gtk_marshal_VOID__OBJECT,
630 widget_signals[HIERARCHY_CHANGED] =
631 g_signal_new (I_("hierarchy_changed"),
632 G_TYPE_FROM_CLASS (gobject_class),
634 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
636 _gtk_marshal_VOID__OBJECT,
640 * GtkWidget::style-set:
641 * @widget: the object on which the signal is emitted
642 * @previous_style: the previous style, or %NULL if the widget
643 * just got its initial style
645 * The style-set signal is emitted when a new style has been set
646 * on a widget. Note that style-modifying functions like
647 * gtk_widget_modify_base() also cause this signal to be emitted.
649 widget_signals[STYLE_SET] =
650 g_signal_new (I_("style_set"),
651 G_TYPE_FROM_CLASS (gobject_class),
653 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
655 _gtk_marshal_VOID__OBJECT,
658 widget_signals[DIRECTION_CHANGED] =
659 g_signal_new (I_("direction_changed"),
660 G_TYPE_FROM_CLASS (gobject_class),
662 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
664 _gtk_marshal_VOID__ENUM,
666 GTK_TYPE_TEXT_DIRECTION);
667 widget_signals[GRAB_NOTIFY] =
668 g_signal_new (I_("grab_notify"),
669 G_TYPE_FROM_CLASS (gobject_class),
671 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
673 _gtk_marshal_VOID__BOOLEAN,
678 * GtkWidget::child-notify:
679 * @widget: the object which received the signal.
680 * @pspec: the #GParamSpec of the changed child property.
682 * The ::child-notify signal is emitted for each child property that has
683 * changed on an object. The signal's detail holds the property name.
685 widget_signals[CHILD_NOTIFY] =
686 g_signal_new (I_("child_notify"),
687 G_TYPE_FROM_CLASS (gobject_class),
688 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
689 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
691 g_cclosure_marshal_VOID__PARAM,
694 widget_signals[MNEMONIC_ACTIVATE] =
695 g_signal_new (I_("mnemonic_activate"),
696 G_TYPE_FROM_CLASS (gobject_class),
698 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
699 _gtk_boolean_handled_accumulator, NULL,
700 _gtk_marshal_BOOLEAN__BOOLEAN,
703 widget_signals[GRAB_FOCUS] =
704 g_signal_new (I_("grab_focus"),
705 G_TYPE_FROM_CLASS (gobject_class),
706 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
707 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
709 _gtk_marshal_VOID__VOID,
711 widget_signals[FOCUS] =
712 g_signal_new (I_("focus"),
713 G_TYPE_FROM_CLASS (object_class),
715 G_STRUCT_OFFSET (GtkWidgetClass, focus),
716 _gtk_boolean_handled_accumulator, NULL,
717 _gtk_marshal_BOOLEAN__ENUM,
719 GTK_TYPE_DIRECTION_TYPE);
720 widget_signals[EVENT] =
721 g_signal_new (I_("event"),
722 G_TYPE_FROM_CLASS (gobject_class),
724 G_STRUCT_OFFSET (GtkWidgetClass, event),
725 _gtk_boolean_handled_accumulator, NULL,
726 _gtk_marshal_BOOLEAN__BOXED,
728 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
729 widget_signals[EVENT_AFTER] =
730 g_signal_new (I_("event-after"),
731 G_TYPE_FROM_CLASS (gobject_class),
735 _gtk_marshal_VOID__BOXED,
737 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
738 widget_signals[BUTTON_PRESS_EVENT] =
739 g_signal_new (I_("button_press_event"),
740 G_TYPE_FROM_CLASS (gobject_class),
742 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
743 _gtk_boolean_handled_accumulator, NULL,
744 _gtk_marshal_BOOLEAN__BOXED,
746 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
747 widget_signals[BUTTON_RELEASE_EVENT] =
748 g_signal_new (I_("button_release_event"),
749 G_TYPE_FROM_CLASS (gobject_class),
751 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
752 _gtk_boolean_handled_accumulator, NULL,
753 _gtk_marshal_BOOLEAN__BOXED,
755 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
756 widget_signals[SCROLL_EVENT] =
757 g_signal_new (I_("scroll_event"),
758 G_TYPE_FROM_CLASS (gobject_class),
760 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
761 _gtk_boolean_handled_accumulator, NULL,
762 _gtk_marshal_BOOLEAN__BOXED,
764 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
765 widget_signals[MOTION_NOTIFY_EVENT] =
766 g_signal_new (I_("motion_notify_event"),
767 G_TYPE_FROM_CLASS (gobject_class),
769 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
770 _gtk_boolean_handled_accumulator, NULL,
771 _gtk_marshal_BOOLEAN__BOXED,
773 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
776 * GtkWidget::delete-event:
777 * @widget: the object which received the signal.
778 * @event: the event which triggered this signal
780 * The ::delete-event signal is emitted if a user requests that
781 * a toplevel window is closed. The default handler for this signal
782 * destroys the window. Connecting gtk_widget_hide_on_delete() to
783 * this signal will cause the window to be hidden instead, so that
784 * it can later be shown again without reconstructing it.
786 * Returns: %TRUE to stop other handlers from being invoked for the event.
787 * %FALSE to propagate the event further.
789 widget_signals[DELETE_EVENT] =
790 g_signal_new (I_("delete_event"),
791 G_TYPE_FROM_CLASS (gobject_class),
793 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
794 _gtk_boolean_handled_accumulator, NULL,
795 _gtk_marshal_BOOLEAN__BOXED,
797 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
800 * GtkWidget::destroy-event:
801 * @widget: the object which received the signal.
802 * @event: the event which triggered this signal
804 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
805 * You rarely get this signal, because most widgets disconnect themselves
806 * from their window before they destroy it, so no widget owns the
807 * window at destroy time.
809 * Returns: %TRUE to stop other handlers from being invoked for the event.
810 * %FALSE to propagate the event further.
812 widget_signals[DESTROY_EVENT] =
813 g_signal_new (I_("destroy_event"),
814 G_TYPE_FROM_CLASS (gobject_class),
816 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
817 _gtk_boolean_handled_accumulator, NULL,
818 _gtk_marshal_BOOLEAN__BOXED,
820 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
821 widget_signals[EXPOSE_EVENT] =
822 g_signal_new (I_("expose_event"),
823 G_TYPE_FROM_CLASS (gobject_class),
825 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
826 _gtk_boolean_handled_accumulator, NULL,
827 _gtk_marshal_BOOLEAN__BOXED,
829 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
830 widget_signals[KEY_PRESS_EVENT] =
831 g_signal_new (I_("key_press_event"),
832 G_TYPE_FROM_CLASS (gobject_class),
834 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
835 _gtk_boolean_handled_accumulator, NULL,
836 _gtk_marshal_BOOLEAN__BOXED,
838 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
839 widget_signals[KEY_RELEASE_EVENT] =
840 g_signal_new (I_("key_release_event"),
841 G_TYPE_FROM_CLASS (gobject_class),
843 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
844 _gtk_boolean_handled_accumulator, NULL,
845 _gtk_marshal_BOOLEAN__BOXED,
847 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
848 widget_signals[ENTER_NOTIFY_EVENT] =
849 g_signal_new (I_("enter_notify_event"),
850 G_TYPE_FROM_CLASS (gobject_class),
852 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
853 _gtk_boolean_handled_accumulator, NULL,
854 _gtk_marshal_BOOLEAN__BOXED,
856 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
857 widget_signals[LEAVE_NOTIFY_EVENT] =
858 g_signal_new (I_("leave_notify_event"),
859 G_TYPE_FROM_CLASS (gobject_class),
861 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
862 _gtk_boolean_handled_accumulator, NULL,
863 _gtk_marshal_BOOLEAN__BOXED,
865 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
866 widget_signals[CONFIGURE_EVENT] =
867 g_signal_new (I_("configure_event"),
868 G_TYPE_FROM_CLASS (gobject_class),
870 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
871 _gtk_boolean_handled_accumulator, NULL,
872 _gtk_marshal_BOOLEAN__BOXED,
874 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
875 widget_signals[FOCUS_IN_EVENT] =
876 g_signal_new (I_("focus_in_event"),
877 G_TYPE_FROM_CLASS (gobject_class),
879 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
880 _gtk_boolean_handled_accumulator, NULL,
881 _gtk_marshal_BOOLEAN__BOXED,
883 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
884 widget_signals[FOCUS_OUT_EVENT] =
885 g_signal_new (I_("focus_out_event"),
886 G_TYPE_FROM_CLASS (gobject_class),
888 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
889 _gtk_boolean_handled_accumulator, NULL,
890 _gtk_marshal_BOOLEAN__BOXED,
892 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
893 widget_signals[MAP_EVENT] =
894 g_signal_new (I_("map_event"),
895 G_TYPE_FROM_CLASS (gobject_class),
897 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
898 _gtk_boolean_handled_accumulator, NULL,
899 _gtk_marshal_BOOLEAN__BOXED,
901 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
902 widget_signals[UNMAP_EVENT] =
903 g_signal_new (I_("unmap_event"),
904 G_TYPE_FROM_CLASS (gobject_class),
906 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
907 _gtk_boolean_handled_accumulator, NULL,
908 _gtk_marshal_BOOLEAN__BOXED,
910 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
911 widget_signals[PROPERTY_NOTIFY_EVENT] =
912 g_signal_new (I_("property_notify_event"),
913 G_TYPE_FROM_CLASS (gobject_class),
915 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
916 _gtk_boolean_handled_accumulator, NULL,
917 _gtk_marshal_BOOLEAN__BOXED,
919 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
920 widget_signals[SELECTION_CLEAR_EVENT] =
921 g_signal_new (I_("selection_clear_event"),
922 G_TYPE_FROM_CLASS (gobject_class),
924 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
925 _gtk_boolean_handled_accumulator, NULL,
926 _gtk_marshal_BOOLEAN__BOXED,
928 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
929 widget_signals[SELECTION_REQUEST_EVENT] =
930 g_signal_new (I_("selection_request_event"),
931 G_TYPE_FROM_CLASS (gobject_class),
933 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
934 _gtk_boolean_handled_accumulator, NULL,
935 _gtk_marshal_BOOLEAN__BOXED,
937 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
938 widget_signals[SELECTION_NOTIFY_EVENT] =
939 g_signal_new (I_("selection_notify_event"),
940 G_TYPE_FROM_CLASS (gobject_class),
942 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
943 _gtk_boolean_handled_accumulator, NULL,
944 _gtk_marshal_BOOLEAN__BOXED,
946 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
947 widget_signals[SELECTION_RECEIVED] =
948 g_signal_new (I_("selection_received"),
949 G_TYPE_FROM_CLASS (gobject_class),
951 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
953 _gtk_marshal_VOID__BOXED_UINT,
955 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
957 widget_signals[SELECTION_GET] =
958 g_signal_new (I_("selection_get"),
959 G_TYPE_FROM_CLASS (gobject_class),
961 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
963 _gtk_marshal_VOID__BOXED_UINT_UINT,
965 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
968 widget_signals[PROXIMITY_IN_EVENT] =
969 g_signal_new (I_("proximity_in_event"),
970 G_TYPE_FROM_CLASS (gobject_class),
972 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
973 _gtk_boolean_handled_accumulator, NULL,
974 _gtk_marshal_BOOLEAN__BOXED,
976 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
977 widget_signals[PROXIMITY_OUT_EVENT] =
978 g_signal_new (I_("proximity_out_event"),
979 G_TYPE_FROM_CLASS (gobject_class),
981 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
982 _gtk_boolean_handled_accumulator, NULL,
983 _gtk_marshal_BOOLEAN__BOXED,
985 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
988 * GtkWidget::drag-leave:
989 * @widget: the object which received the signal.
990 * @drag_context: the drag context
991 * @time: the timestamp of the motion event
993 * The ::drag-leave signal is emitted on the drop site when the cursor
994 * leaves the widget. A typical reason to connect to this signal is to
995 * undo things done in ::drag-motion, e.g. undo highlighting with
996 * gtk_drag_unhighlight()
998 widget_signals[DRAG_LEAVE] =
999 g_signal_new (I_("drag_leave"),
1000 G_TYPE_FROM_CLASS (gobject_class),
1002 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
1004 _gtk_marshal_VOID__OBJECT_UINT,
1006 GDK_TYPE_DRAG_CONTEXT,
1010 * GtkWidget::drag-begin:
1011 * @widget: the object which received the signal.
1012 * @drag_context: the drag context
1014 * The ::drag-begin signal is emitted on the drag source when a drag is started.
1015 * A typical reason to connect to this signal is to set up a custom drag icon with
1016 * gtk_drag_source_set_icon().
1018 widget_signals[DRAG_BEGIN] =
1019 g_signal_new (I_("drag_begin"),
1020 G_TYPE_FROM_CLASS (gobject_class),
1022 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
1024 _gtk_marshal_VOID__OBJECT,
1026 GDK_TYPE_DRAG_CONTEXT);
1029 * GtkWidget::drag-end:
1030 * @widget: the object which received the signal.
1031 * @drag_context: the drag context
1033 * The ::drag-end signal is emitted on the drag source when a drag is finished.
1034 * A typical reason to connect to this signal is to undo things done in ::drag-begin.
1036 widget_signals[DRAG_END] =
1037 g_signal_new (I_("drag_end"),
1038 G_TYPE_FROM_CLASS (gobject_class),
1040 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
1042 _gtk_marshal_VOID__OBJECT,
1044 GDK_TYPE_DRAG_CONTEXT);
1047 * GtkWidget::drag-data-delete:
1048 * @widget: the object which received the signal.
1049 * @drag_context: the drag context
1051 * The ::drag-data-delete signal is emitted on the drag source when a drag
1052 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
1053 * handler is responsible for deleting the data that has been dropped. What
1054 * "delete" means, depends on the context of the drag operation.
1056 widget_signals[DRAG_DATA_DELETE] =
1057 g_signal_new (I_("drag_data_delete"),
1058 G_TYPE_FROM_CLASS (gobject_class),
1060 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
1062 _gtk_marshal_VOID__OBJECT,
1064 GDK_TYPE_DRAG_CONTEXT);
1067 * GtkWidget::drag-motion:
1068 * @widget: the object which received the signal.
1069 * @drag_context: the drag context
1070 * @x: the x coordinate of the current cursor position
1071 * @y: the y coordinate of the current cursor position
1072 * @time: the timestamp of the motion event
1073 * @returns: whether the cursor position is in a drop zone
1075 * The ::drag-motion signal is emitted on the drop site when the user
1076 * moves the cursor over the widget during a drag. The signal handler
1077 * must determine whether the cursor position is in a drop zone or not.
1078 * If it is not in a drop zone, it returns %FALSE and no further processing
1079 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
1080 * handler is responsible for providing the necessary information for
1081 * displaying feedback to the user, by calling gdk_drag_status(). If the
1082 * decision whether the drop will be accepted or rejected can't be made
1083 * based solely on the cursor position and the type of the data, the handler
1084 * may inspect the dragged data by calling gtk_drag_get_data() and defer the
1085 * gdk_drag_status() call to the ::drag-data-received handler.
1087 * Note that there is no ::drag-enter signal. The drag receiver has to keep
1088 * track of whether he has received any ::drag-motion signals since the last
1089 * ::drag-leave and if not, treat the ::drag-motion signal as an "enter" signal.
1090 * Upon an "enter", the handler will typically highlight the drop site with
1091 * gtk_drag_highlight().
1093 * <informalexample><programlisting>
1095 * drag_motion (GtkWidget *widget,
1096 * GdkDragContext *context,
1103 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1105 * if (!private_data->drag_highlight)
1107 * private_data->drag_highlight = 1;
1108 * gtk_drag_highlight (widget);
1111 * target = gtk_drag_dest_find_target (widget, context, NULL);
1112 * if (target == GDK_NONE)
1113 * gdk_drag_status (context, 0, time);
1116 * private_data->pending_status = context->suggested_action;
1117 * gtk_drag_get_data (widget, context, target, time);
1124 * drag_data_received (GtkWidget *widget,
1125 * GdkDragContext *context,
1128 * GtkSelectionData *selection_data,
1132 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1134 * if (private_data->suggested_action)
1136 * private_data->suggested_action = 0;
1138 * /<!-- -->* We are getting this data due to a request in drag_motion,
1139 * * rather than due to a request in drag_drop, so we are just
1140 * * supposed to call gdk_drag_status(<!-- -->), not actually paste in
1143 * str = gtk_selection_data_get_text (selection_data);
1144 * if (!data_is_acceptable (str))
1145 * gdk_drag_status (context, 0, time);
1147 * gdk_drag_status (context, private_data->suggested_action, time);
1151 * /<!-- -->* accept the drop *<!-- -->/
1154 * </programlisting></informalexample>
1156 widget_signals[DRAG_MOTION] =
1157 g_signal_new (I_("drag_motion"),
1158 G_TYPE_FROM_CLASS (gobject_class),
1160 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
1161 _gtk_boolean_handled_accumulator, NULL,
1162 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1164 GDK_TYPE_DRAG_CONTEXT,
1170 * GtkWidget::drag-drop:
1171 * @widget: the object which received the signal.
1172 * @drag_context: the drag context
1173 * @x: the x coordinate of the current cursor position
1174 * @y: the y coordinate of the current cursor position
1175 * @time: the timestamp of the motion event
1176 * @returns: whether the cursor position is in a drop zone
1178 * The ::drag-drop signal is emitted on the drop site when the user drops the
1179 * data onto the widget. The signal handler must determine whether the cursor
1180 * position is in a drop zone or not. If it is not in a drop zone, it returns
1181 * %FALSE and no further processing is necessary. Otherwise, the handler returns
1182 * %TRUE. In this case, the handler must ensure that gtk_drag_finish() is called
1183 * to let the source know that the drop is done. The call to gtk_drag_finish()
1184 * can be done either directly or in a ::drag-data-received handler which gets
1185 * triggered by calling gtk_drop_get_data() to receive the data for one or more
1186 * of the supported targets.
1188 widget_signals[DRAG_DROP] =
1189 g_signal_new (I_("drag_drop"),
1190 G_TYPE_FROM_CLASS (gobject_class),
1192 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
1193 _gtk_boolean_handled_accumulator, NULL,
1194 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1196 GDK_TYPE_DRAG_CONTEXT,
1202 * GtkWidget::drag-data-get:
1203 * @widget: the object which received the signal.
1204 * @drag_context: the drag context
1205 * @data: the #GtkSelectionData to be filled with the dragged data
1206 * @info: the info that has been registered with the target in the #GtkTargetList.
1207 * @time: the timestamp at which the data was requested
1209 * The ::drag-data-get signal is emitted on the drag source when the drop site
1210 * requests the data which is dragged. It is the responsibility of the signal
1211 * handler to fill @data with the data in the format which is indicated by @info.
1212 * See gtk_selection_data_set() and gtk_selection_data_set_text().
1214 widget_signals[DRAG_DATA_GET] =
1215 g_signal_new (I_("drag_data_get"),
1216 G_TYPE_FROM_CLASS (gobject_class),
1218 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
1220 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
1222 GDK_TYPE_DRAG_CONTEXT,
1223 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1228 * GtkWidget::drag-data-received:
1229 * @widget: the object which received the signal.
1230 * @drag_context: the drag context
1231 * @x: where the drop happened
1232 * @y: where the drop happened
1233 * @data: the received data
1234 * @info: the info that has been registered with the target in the #GtkTargetList.
1235 * @time: the timestamp at which the data was received
1237 * The ::drag-data-received signal is emitted on the drop site when the dragged
1238 * data has been received. If the data was received in order to determine whether
1239 * the drop will be accepted, the handler is expected to call gdk_drag_status()
1240 * and <emphasis>not</emphasis> finish the drag. If the data was received in
1241 * response to a ::drag-drop signal (and this is the last target to be received),
1242 * the handler for this signal is expected to process the received data and then
1243 * call gtk_drag_finish(), setting the @success parameter depending on whether
1244 * the data was processed successfully.
1246 * The handler may inspect and modify @drag_context->action before calling
1247 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the following
1249 * <informalexample><programlisting>
1251 * drag_data_received (GtkWidget *widget,
1252 * GdkDragContext *drag_context,
1255 * GtkSelectionData *data,
1259 * if ((data->length >= 0) && (data->format == 8))
1261 * if (drag_context->action == GDK_ACTION_ASK)
1263 * GtkWidget *dialog;
1266 * dialog = gtk_message_dialog_new (NULL,
1267 * GTK_DIALOG_MODAL |
1268 * GTK_DIALOG_DESTROY_WITH_PARENT,
1270 * GTK_BUTTONS_YES_NO,
1271 * "Move the data ?\n");
1272 * response = gtk_dialog_run (GTK_DIALOG (dialog));
1273 * gtk_widget_destroy (dialog);
1275 * if (response == GTK_RESPONSE_YES)
1276 * drag_context->action = GDK_ACTION_MOVE;
1278 * drag_context->action = GDK_ACTION_COPY;
1281 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
1285 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
1287 * </programlisting></informalexample>
1289 widget_signals[DRAG_DATA_RECEIVED] =
1290 g_signal_new (I_("drag_data_received"),
1291 G_TYPE_FROM_CLASS (gobject_class),
1293 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
1295 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
1297 GDK_TYPE_DRAG_CONTEXT,
1300 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1303 widget_signals[VISIBILITY_NOTIFY_EVENT] =
1304 g_signal_new (I_("visibility_notify_event"),
1305 G_TYPE_FROM_CLASS (gobject_class),
1307 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
1308 _gtk_boolean_handled_accumulator, NULL,
1309 _gtk_marshal_BOOLEAN__BOXED,
1311 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1312 widget_signals[CLIENT_EVENT] =
1313 g_signal_new (I_("client_event"),
1314 G_TYPE_FROM_CLASS (gobject_class),
1316 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
1317 _gtk_boolean_handled_accumulator, NULL,
1318 _gtk_marshal_BOOLEAN__BOXED,
1320 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1321 widget_signals[NO_EXPOSE_EVENT] =
1322 g_signal_new (I_("no_expose_event"),
1323 G_TYPE_FROM_CLASS (gobject_class),
1325 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
1326 _gtk_boolean_handled_accumulator, NULL,
1327 _gtk_marshal_BOOLEAN__BOXED,
1329 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1330 widget_signals[WINDOW_STATE_EVENT] =
1331 g_signal_new (I_("window_state_event"),
1332 G_TYPE_FROM_CLASS (gobject_class),
1334 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
1335 _gtk_boolean_handled_accumulator, NULL,
1336 _gtk_marshal_BOOLEAN__BOXED,
1338 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1340 * GtkWidget::grab-broken-event:
1341 * @widget: the object which received the signal
1342 * @event: the #GdkEventGrabBroken event
1344 * Emitted when a pointer or keyboard grab on a window belonging
1345 * to @widget gets broken.
1347 * On X11, this happens when the grab window becomes unviewable
1348 * (i.e. it or one of its ancestors is unmapped), or if the same
1349 * application grabs the pointer or keyboard again.
1351 * Returns: %TRUE to stop other handlers from being invoked for the event.
1352 * %FALSE to propagate the event further.
1356 widget_signals[GRAB_BROKEN] =
1357 g_signal_new (I_("grab_broken_event"),
1358 G_TYPE_FROM_CLASS (gobject_class),
1360 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
1361 _gtk_boolean_handled_accumulator, NULL,
1362 _gtk_marshal_BOOLEAN__BOXED,
1364 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1366 * GtkWidget::popup-menu
1367 * @widget: the object which received the signal
1368 * @returns: TRUE if a menu was activated
1370 * This signal gets emitted whenever a widget should pop up a context-sensitive
1371 * menu. This usually happens through the standard key binding mechanism; by
1372 * pressing a certain key while a widget is focused, the user can cause the
1373 * widget to pop up a menu. For example, the #GtkEntry widget creates a menu
1374 * with clipboard commands. See <xref linkend="checklist-popup-menu"/> for an
1375 * example of how to use this signal.
1377 widget_signals[POPUP_MENU] =
1378 g_signal_new (I_("popup_menu"),
1379 G_TYPE_FROM_CLASS (gobject_class),
1380 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1381 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
1382 _gtk_boolean_handled_accumulator, NULL,
1383 _gtk_marshal_BOOLEAN__VOID,
1385 widget_signals[SHOW_HELP] =
1386 g_signal_new (I_("show_help"),
1387 G_TYPE_FROM_CLASS (gobject_class),
1388 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1389 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
1390 _gtk_boolean_handled_accumulator, NULL,
1391 _gtk_marshal_BOOLEAN__ENUM,
1393 GTK_TYPE_WIDGET_HELP_TYPE);
1394 widget_signals[ACCEL_CLOSURES_CHANGED] =
1395 g_signal_new (I_("accel_closures_changed"),
1396 G_TYPE_FROM_CLASS (gobject_class),
1400 _gtk_marshal_NONE__NONE,
1402 widget_signals[SCREEN_CHANGED] =
1403 g_signal_new (I_("screen_changed"),
1404 G_TYPE_FROM_CLASS (gobject_class),
1406 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
1408 _gtk_marshal_VOID__OBJECT,
1412 * GtkWidget::can-activate-accel:
1413 * @widget: the object which received the signal
1414 * @signal_id: the ID of a signal installed on @widget
1415 * @returns: %TRUE if the signal can be activated.
1417 * Determines whether an accelerator that activates the signal
1418 * identified by @signal_id can currently be activated.
1419 * This signal is present to allow applications and derived
1420 * widgets to override the default #GtkWidget handling
1421 * for determining whether an accelerator can be activated.
1423 widget_signals[CAN_ACTIVATE_ACCEL] =
1424 g_signal_new (I_("can_activate_accel"),
1425 G_TYPE_FROM_CLASS (gobject_class),
1427 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
1428 _gtk_boolean_handled_accumulator, NULL,
1429 _gtk_marshal_BOOLEAN__UINT,
1430 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
1432 binding_set = gtk_binding_set_by_class (klass);
1433 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
1435 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
1438 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
1440 GTK_TYPE_WIDGET_HELP_TYPE,
1441 GTK_WIDGET_HELP_TOOLTIP);
1442 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
1444 GTK_TYPE_WIDGET_HELP_TYPE,
1445 GTK_WIDGET_HELP_TOOLTIP);
1446 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
1448 GTK_TYPE_WIDGET_HELP_TYPE,
1449 GTK_WIDGET_HELP_WHATS_THIS);
1450 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
1452 GTK_TYPE_WIDGET_HELP_TYPE,
1453 GTK_WIDGET_HELP_WHATS_THIS);
1455 gtk_widget_class_install_style_property (klass,
1456 g_param_spec_boolean ("interior-focus",
1457 P_("Interior Focus"),
1458 P_("Whether to draw the focus indicator inside widgets"),
1460 GTK_PARAM_READABLE));
1462 gtk_widget_class_install_style_property (klass,
1463 g_param_spec_int ("focus-line-width",
1464 P_("Focus linewidth"),
1465 P_("Width, in pixels, of the focus indicator line"),
1467 GTK_PARAM_READABLE));
1469 gtk_widget_class_install_style_property (klass,
1470 g_param_spec_string ("focus-line-pattern",
1471 P_("Focus line dash pattern"),
1472 P_("Dash pattern used to draw the focus indicator"),
1474 GTK_PARAM_READABLE));
1475 gtk_widget_class_install_style_property (klass,
1476 g_param_spec_int ("focus-padding",
1477 P_("Focus padding"),
1478 P_("Width, in pixels, between focus indicator and the widget 'box'"),
1480 GTK_PARAM_READABLE));
1481 gtk_widget_class_install_style_property (klass,
1482 g_param_spec_boxed ("cursor-color",
1484 P_("Color with which to draw insertion cursor"),
1486 GTK_PARAM_READABLE));
1487 gtk_widget_class_install_style_property (klass,
1488 g_param_spec_boxed ("secondary-cursor-color",
1489 P_("Secondary cursor color"),
1490 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
1492 GTK_PARAM_READABLE));
1493 gtk_widget_class_install_style_property (klass,
1494 g_param_spec_float ("cursor-aspect-ratio",
1495 P_("Cursor line aspect ratio"),
1496 P_("Aspect ratio with which to draw insertion cursor"),
1498 GTK_PARAM_READABLE));
1499 gtk_widget_class_install_style_property (klass,
1500 g_param_spec_boxed ("draw-border",
1502 P_("Size of areas outside the widget's allocation to draw"),
1504 GTK_PARAM_READABLE));
1506 gtk_widget_class_install_style_property (klass,
1507 g_param_spec_boxed ("link-color",
1508 P_("Unvisited Link Color"),
1509 P_("Color of unvisited links"),
1511 GTK_PARAM_READABLE));
1513 gtk_widget_class_install_style_property (klass,
1514 g_param_spec_boxed ("visited-link-color",
1515 P_("Visited Link Color"),
1516 P_("Color of visited links"),
1518 GTK_PARAM_READABLE));
1520 gtk_widget_class_install_style_property (klass,
1521 g_param_spec_boolean ("wide-separators",
1522 P_("Wide Separators"),
1523 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
1525 GTK_PARAM_READABLE));
1527 gtk_widget_class_install_style_property (klass,
1528 g_param_spec_int ("separator-width",
1529 P_("Separator Width"),
1530 P_("The width of separators if wide-separators is TRUE"),
1532 GTK_PARAM_READABLE));
1534 gtk_widget_class_install_style_property (klass,
1535 g_param_spec_int ("separator-height",
1536 P_("Separator Height"),
1537 P_("The height of separators if wide-separators is TRUE"),
1539 GTK_PARAM_READABLE));
1543 gtk_widget_set_property (GObject *object,
1545 const GValue *value,
1548 GtkWidget *widget = GTK_WIDGET (object);
1552 guint32 saved_flags;
1555 gtk_widget_set_name (widget, g_value_get_string (value));
1558 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
1560 case PROP_WIDTH_REQUEST:
1561 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
1563 case PROP_HEIGHT_REQUEST:
1564 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
1567 if (g_value_get_boolean (value))
1568 gtk_widget_show (widget);
1570 gtk_widget_hide (widget);
1572 case PROP_SENSITIVE:
1573 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
1575 case PROP_APP_PAINTABLE:
1576 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
1578 case PROP_CAN_FOCUS:
1579 saved_flags = GTK_WIDGET_FLAGS (widget);
1580 if (g_value_get_boolean (value))
1581 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
1583 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
1584 if (saved_flags != GTK_WIDGET_FLAGS (widget))
1585 gtk_widget_queue_resize (widget);
1587 case PROP_HAS_FOCUS:
1588 if (g_value_get_boolean (value))
1589 gtk_widget_grab_focus (widget);
1592 if (g_value_get_boolean (value))
1593 gtk_widget_grab_focus (widget);
1595 case PROP_CAN_DEFAULT:
1596 saved_flags = GTK_WIDGET_FLAGS (widget);
1597 if (g_value_get_boolean (value))
1598 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
1600 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT);
1601 if (saved_flags != GTK_WIDGET_FLAGS (widget))
1602 gtk_widget_queue_resize (widget);
1604 case PROP_HAS_DEFAULT:
1605 if (g_value_get_boolean (value))
1606 gtk_widget_grab_default (widget);
1608 case PROP_RECEIVES_DEFAULT:
1609 if (g_value_get_boolean (value))
1610 GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1612 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1615 gtk_widget_set_style (widget, g_value_get_object (value));
1618 if (!GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget))
1619 gtk_widget_set_events (widget, g_value_get_flags (value));
1621 case PROP_EXTENSION_EVENTS:
1622 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
1624 case PROP_NO_SHOW_ALL:
1625 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
1633 gtk_widget_get_property (GObject *object,
1638 GtkWidget *widget = GTK_WIDGET (object);
1643 GdkExtensionMode *modep;
1647 g_value_set_string (value, widget->name);
1649 g_value_set_string (value, "");
1653 g_value_set_object (value, widget->parent);
1655 g_value_set_object (value, NULL);
1657 case PROP_WIDTH_REQUEST:
1660 gtk_widget_get_size_request (widget, &w, NULL);
1661 g_value_set_int (value, w);
1664 case PROP_HEIGHT_REQUEST:
1667 gtk_widget_get_size_request (widget, NULL, &h);
1668 g_value_set_int (value, h);
1672 g_value_set_boolean (value, (GTK_WIDGET_VISIBLE (widget) != FALSE));
1674 case PROP_SENSITIVE:
1675 g_value_set_boolean (value, (GTK_WIDGET_SENSITIVE (widget) != FALSE));
1677 case PROP_APP_PAINTABLE:
1678 g_value_set_boolean (value, (GTK_WIDGET_APP_PAINTABLE (widget) != FALSE));
1680 case PROP_CAN_FOCUS:
1681 g_value_set_boolean (value, (GTK_WIDGET_CAN_FOCUS (widget) != FALSE));
1683 case PROP_HAS_FOCUS:
1684 g_value_set_boolean (value, (GTK_WIDGET_HAS_FOCUS (widget) != FALSE));
1687 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
1689 case PROP_CAN_DEFAULT:
1690 g_value_set_boolean (value, (GTK_WIDGET_CAN_DEFAULT (widget) != FALSE));
1692 case PROP_HAS_DEFAULT:
1693 g_value_set_boolean (value, (GTK_WIDGET_HAS_DEFAULT (widget) != FALSE));
1695 case PROP_RECEIVES_DEFAULT:
1696 g_value_set_boolean (value, (GTK_WIDGET_RECEIVES_DEFAULT (widget) != FALSE));
1698 case PROP_COMPOSITE_CHILD:
1699 g_value_set_boolean (value, (GTK_WIDGET_COMPOSITE_CHILD (widget) != FALSE));
1702 g_value_set_object (value, gtk_widget_get_style (widget));
1705 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
1707 g_value_set_flags (value, 0);
1709 g_value_set_flags (value, *eventp);
1711 case PROP_EXTENSION_EVENTS:
1712 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
1714 g_value_set_enum (value, 0);
1716 g_value_set_enum (value, (GdkExtensionMode) *modep);
1718 case PROP_NO_SHOW_ALL:
1719 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
1722 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1728 gtk_widget_init (GtkWidget *widget)
1730 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
1731 widget->state = GTK_STATE_NORMAL;
1732 widget->saved_state = GTK_STATE_NORMAL;
1733 widget->name = NULL;
1734 widget->requisition.width = 0;
1735 widget->requisition.height = 0;
1736 widget->allocation.x = -1;
1737 widget->allocation.y = -1;
1738 widget->allocation.width = 1;
1739 widget->allocation.height = 1;
1740 widget->window = NULL;
1741 widget->parent = NULL;
1743 GTK_WIDGET_SET_FLAGS (widget,
1745 GTK_PARENT_SENSITIVE |
1746 (composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
1747 GTK_DOUBLE_BUFFERED);
1749 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
1750 GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
1751 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
1753 widget->style = gtk_widget_get_default_style ();
1754 g_object_ref (widget->style);
1759 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
1761 GParamSpec **pspecs)
1763 GtkWidget *container = widget->parent;
1766 for (i = 0; widget->parent == container && i < n_pspecs; i++)
1767 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
1771 * gtk_widget_freeze_child_notify:
1772 * @widget: a #GtkWidget
1774 * Stops emission of "child-notify" signals on @widget. The signals are
1775 * queued until gtk_widget_thaw_child_notify() is called on @widget.
1777 * This is the analogue of g_object_freeze_notify() for child properties.
1780 gtk_widget_freeze_child_notify (GtkWidget *widget)
1782 g_return_if_fail (GTK_IS_WIDGET (widget));
1784 if (!G_OBJECT (widget)->ref_count)
1787 g_object_ref (widget);
1788 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1789 g_object_unref (widget);
1793 * gtk_widget_child_notify:
1794 * @widget: a #GtkWidget
1795 * @child_property: the name of a child property installed on the
1796 * class of @widget<!-- -->'s parent.
1798 * Emits a "child-notify" signal for the
1799 * <link linkend="child-properties">child property</link> @child_property
1802 * This is the analogue of g_object_notify() for child properties.
1805 gtk_widget_child_notify (GtkWidget *widget,
1806 const gchar *child_property)
1810 g_return_if_fail (GTK_IS_WIDGET (widget));
1811 g_return_if_fail (child_property != NULL);
1812 if (!G_OBJECT (widget)->ref_count || !widget->parent)
1815 g_object_ref (widget);
1816 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
1818 G_OBJECT_TYPE (widget->parent),
1821 g_warning ("%s: container class `%s' has no child property named `%s'",
1823 G_OBJECT_TYPE_NAME (widget->parent),
1827 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1829 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
1830 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1832 g_object_unref (widget);
1836 * gtk_widget_thaw_child_notify:
1837 * @widget: a #GtkWidget
1839 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
1840 * This causes all queued "child-notify" signals on @widget to be emitted.
1843 gtk_widget_thaw_child_notify (GtkWidget *widget)
1845 GObjectNotifyQueue *nqueue;
1847 g_return_if_fail (GTK_IS_WIDGET (widget));
1849 if (!G_OBJECT (widget)->ref_count)
1852 g_object_ref (widget);
1853 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1854 if (!nqueue || !nqueue->freeze_count)
1855 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
1856 G_OBJECT_TYPE_NAME (widget), widget);
1858 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1859 g_object_unref (widget);
1865 * @type: type ID of the widget to create
1866 * @first_property_name: name of first property to set
1867 * @Varargs: value of first property, followed by more properties, %NULL-terminated
1869 * This is a convenience function for creating a widget and setting
1870 * its properties in one go. For example you might write:
1871 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
1872 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
1873 * g_object_new(), but returns a widget so you don't have to
1874 * cast the object yourself.
1876 * Return value: a new #GtkWidget of type @widget_type
1879 gtk_widget_new (GType type,
1880 const gchar *first_property_name,
1886 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
1888 va_start (var_args, first_property_name);
1889 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
1897 * @widget: a #GtkWidget
1898 * @first_property_name: name of first property to set
1899 * @Varargs: value of first property, followed by more properties, %NULL-terminated
1901 * Like g_object_set() - there's no reason to use this instead of
1905 gtk_widget_set (GtkWidget *widget,
1906 const gchar *first_property_name,
1911 g_return_if_fail (GTK_IS_WIDGET (widget));
1913 va_start (var_args, first_property_name);
1914 g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
1919 gtk_widget_queue_draw_child (GtkWidget *widget)
1923 parent = widget->parent;
1924 if (parent && GTK_WIDGET_DRAWABLE (parent))
1925 gtk_widget_queue_draw_area (parent,
1926 widget->allocation.x,
1927 widget->allocation.y,
1928 widget->allocation.width,
1929 widget->allocation.height);
1933 * gtk_widget_unparent:
1934 * @widget: a #GtkWidget
1936 * This function is only for use in widget implementations.
1937 * Should be called by implementations of the remove method
1938 * on #GtkContainer, to dissociate a child from the container.
1941 gtk_widget_unparent (GtkWidget *widget)
1943 GObjectNotifyQueue *nqueue;
1944 GtkWidget *toplevel;
1945 GtkWidget *old_parent;
1947 g_return_if_fail (GTK_IS_WIDGET (widget));
1948 if (widget->parent == NULL)
1951 /* keep this function in sync with gtk_menu_detach()
1954 g_object_freeze_notify (G_OBJECT (widget));
1955 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1957 toplevel = gtk_widget_get_toplevel (widget);
1958 if (GTK_WIDGET_TOPLEVEL (toplevel))
1959 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
1961 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
1962 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
1964 /* If we are unanchoring the child, we save around the toplevel
1965 * to emit hierarchy changed
1967 if (GTK_WIDGET_ANCHORED (widget->parent))
1968 g_object_ref (toplevel);
1972 gtk_widget_queue_draw_child (widget);
1974 /* Reset the width and height here, to force reallocation if we
1975 * get added back to a new parent. This won't work if our new
1976 * allocation is smaller than 1x1 and we actually want a size of 1x1...
1977 * (would 0x0 be OK here?)
1979 widget->allocation.width = 1;
1980 widget->allocation.height = 1;
1982 if (GTK_WIDGET_REALIZED (widget))
1984 if (GTK_WIDGET_IN_REPARENT (widget))
1985 gtk_widget_unmap (widget);
1987 gtk_widget_unrealize (widget);
1990 /* Removing a widget from a container restores the child visible
1991 * flag to the default state, so it doesn't affect the child
1992 * in the next parent.
1994 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
1996 old_parent = widget->parent;
1997 widget->parent = NULL;
1998 gtk_widget_set_parent_window (widget, NULL);
1999 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
2002 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
2003 g_object_unref (toplevel);
2006 g_object_notify (G_OBJECT (widget), "parent");
2007 g_object_thaw_notify (G_OBJECT (widget));
2008 if (!widget->parent)
2009 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
2010 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2011 g_object_unref (widget);
2015 * gtk_widget_destroy:
2016 * @widget: a #GtkWidget
2018 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
2019 * you don't have to cast the widget to #GtkObject. When a widget is
2020 * destroyed, it will break any references it holds to other objects.
2021 * If the widget is inside a container, the widget will be removed
2022 * from the container. If the widget is a toplevel (derived from
2023 * #GtkWindow), it will be removed from the list of toplevels, and the
2024 * reference GTK+ holds to it will be removed. Removing a
2025 * widget from its container or the list of toplevels results in the
2026 * widget being finalized, unless you've added additional references
2027 * to the widget with g_object_ref().
2029 * In most cases, only toplevel widgets (windows) require explicit
2030 * destruction, because when you destroy a toplevel its children will
2031 * be destroyed as well.
2035 gtk_widget_destroy (GtkWidget *widget)
2037 g_return_if_fail (GTK_IS_WIDGET (widget));
2039 gtk_object_destroy ((GtkObject*) widget);
2043 * gtk_widget_destroyed:
2044 * @widget: a #GtkWidget
2045 * @widget_pointer: address of a variable that contains @widget
2047 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
2048 * %NULL. It's intended to be used as a callback connected to the
2049 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
2050 * as a signal handler, and pass the address of your widget variable
2051 * as user data. Then when the widget is destroyed, the variable will
2052 * be set to %NULL. Useful for example to avoid multiple copies
2053 * of the same dialog.
2057 gtk_widget_destroyed (GtkWidget *widget,
2058 GtkWidget **widget_pointer)
2060 /* Don't make any assumptions about the
2062 * Even check widget_pointer.
2065 *widget_pointer = NULL;
2070 * @widget: a #GtkWidget
2072 * Flags a widget to be displayed. Any widget that isn't shown will
2073 * not appear on the screen. If you want to show all the widgets in a
2074 * container, it's easier to call gtk_widget_show_all() on the
2075 * container, instead of individually showing the widgets.
2077 * Remember that you have to show the containers containing a widget,
2078 * in addition to the widget itself, before it will appear onscreen.
2080 * When a toplevel container is shown, it is immediately realized and
2081 * mapped; other shown widgets are realized and mapped when their
2082 * toplevel container is realized and mapped.
2086 gtk_widget_show (GtkWidget *widget)
2088 if (!GTK_WIDGET_VISIBLE (widget))
2090 g_object_ref (widget);
2091 if (!GTK_WIDGET_TOPLEVEL (widget))
2092 gtk_widget_queue_resize (widget);
2093 g_signal_emit (widget, widget_signals[SHOW], 0);
2094 g_object_notify (G_OBJECT (widget), "visible");
2095 g_object_unref (widget);
2100 gtk_widget_real_show (GtkWidget *widget)
2102 if (!GTK_WIDGET_VISIBLE (widget))
2104 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
2106 if (widget->parent &&
2107 GTK_WIDGET_MAPPED (widget->parent) &&
2108 GTK_WIDGET_CHILD_VISIBLE (widget) &&
2109 !GTK_WIDGET_MAPPED (widget))
2110 gtk_widget_map (widget);
2115 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
2118 g_signal_handlers_disconnect_by_func (widget,
2119 gtk_widget_show_map_callback,
2124 * gtk_widget_show_now:
2125 * @widget: a #GtkWidget
2127 * Shows a widget. If the widget is an unmapped toplevel widget
2128 * (i.e. a #GtkWindow that has not yet been shown), enter the main
2129 * loop and wait for the window to actually be mapped. Be careful;
2130 * because the main loop is running, anything can happen during
2134 gtk_widget_show_now (GtkWidget *widget)
2138 g_return_if_fail (GTK_IS_WIDGET (widget));
2140 /* make sure we will get event */
2141 if (!GTK_WIDGET_MAPPED (widget) &&
2142 GTK_WIDGET_TOPLEVEL (widget))
2144 gtk_widget_show (widget);
2146 g_signal_connect (widget, "map_event",
2147 G_CALLBACK (gtk_widget_show_map_callback),
2151 gtk_main_iteration ();
2154 gtk_widget_show (widget);
2159 * @widget: a #GtkWidget
2161 * Reverses the effects of gtk_widget_show(), causing the widget to be
2162 * hidden (invisible to the user).
2165 gtk_widget_hide (GtkWidget *widget)
2167 g_return_if_fail (GTK_IS_WIDGET (widget));
2169 if (GTK_WIDGET_VISIBLE (widget))
2171 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
2173 g_object_ref (widget);
2174 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
2175 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
2177 g_signal_emit (widget, widget_signals[HIDE], 0);
2178 if (!GTK_WIDGET_TOPLEVEL (widget))
2179 gtk_widget_queue_resize (widget);
2180 g_object_notify (G_OBJECT (widget), "visible");
2181 g_object_unref (widget);
2186 gtk_widget_real_hide (GtkWidget *widget)
2188 if (GTK_WIDGET_VISIBLE (widget))
2190 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
2192 if (GTK_WIDGET_MAPPED (widget))
2193 gtk_widget_unmap (widget);
2198 * gtk_widget_hide_on_delete:
2199 * @widget: a #GtkWidget
2201 * Utility function; intended to be connected to the "delete_event"
2202 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
2203 * argument, then returns %TRUE. If connected to "delete_event", the
2204 * result is that clicking the close button for a window (on the
2205 * window frame, top right corner usually) will hide but not destroy
2206 * the window. By default, GTK+ destroys windows when "delete_event"
2209 * Return value: %TRUE
2212 gtk_widget_hide_on_delete (GtkWidget *widget)
2214 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2216 gtk_widget_hide (widget);
2222 * gtk_widget_show_all:
2223 * @widget: a #GtkWidget
2225 * Recursively shows a widget, and any child widgets (if the widget is
2229 gtk_widget_show_all (GtkWidget *widget)
2231 GtkWidgetClass *class;
2233 g_return_if_fail (GTK_IS_WIDGET (widget));
2235 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
2238 class = GTK_WIDGET_GET_CLASS (widget);
2240 if (class->show_all)
2241 class->show_all (widget);
2245 * gtk_widget_hide_all:
2246 * @widget: a #GtkWidget
2248 * Recursively hides a widget and any child widgets.
2251 gtk_widget_hide_all (GtkWidget *widget)
2253 GtkWidgetClass *class;
2255 g_return_if_fail (GTK_IS_WIDGET (widget));
2257 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
2260 class = GTK_WIDGET_GET_CLASS (widget);
2262 if (class->hide_all)
2263 class->hide_all (widget);
2268 * @widget: a #GtkWidget
2270 * This function is only for use in widget implementations. Causes
2271 * a widget to be mapped if it isn't already.
2275 gtk_widget_map (GtkWidget *widget)
2277 g_return_if_fail (GTK_IS_WIDGET (widget));
2278 g_return_if_fail (GTK_WIDGET_VISIBLE (widget));
2279 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
2281 if (!GTK_WIDGET_MAPPED (widget))
2283 if (!GTK_WIDGET_REALIZED (widget))
2284 gtk_widget_realize (widget);
2286 g_signal_emit (widget, widget_signals[MAP], 0);
2288 if (GTK_WIDGET_NO_WINDOW (widget))
2289 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
2295 * @widget: a #GtkWidget
2297 * This function is only for use in widget implementations. Causes
2298 * a widget to be unmapped if it's currently mapped.
2302 gtk_widget_unmap (GtkWidget *widget)
2304 g_return_if_fail (GTK_IS_WIDGET (widget));
2306 if (GTK_WIDGET_MAPPED (widget))
2308 if (GTK_WIDGET_NO_WINDOW (widget))
2309 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
2310 g_signal_emit (widget, widget_signals[UNMAP], 0);
2315 * gtk_widget_realize:
2316 * @widget: a #GtkWidget
2318 * Creates the GDK (windowing system) resources associated with a
2319 * widget. For example, @widget->window will be created when a widget
2320 * is realized. Normally realization happens implicitly; if you show
2321 * a widget and all its parent containers, then the widget will be
2322 * realized and mapped automatically.
2324 * Realizing a widget requires all
2325 * the widget's parent widgets to be realized; calling
2326 * gtk_widget_realize() realizes the widget's parents in addition to
2327 * @widget itself. If a widget is not yet inside a toplevel window
2328 * when you realize it, bad things will happen.
2330 * This function is primarily used in widget implementations, and
2331 * isn't very useful otherwise. Many times when you think you might
2332 * need it, a better approach is to connect to a signal that will be
2333 * called after the widget is realized automatically, such as
2334 * "expose_event". Or simply g_signal_connect_after() to the
2339 gtk_widget_realize (GtkWidget *widget)
2342 GdkExtensionMode mode;
2343 GtkWidgetShapeInfo *shape_info;
2345 g_return_if_fail (GTK_IS_WIDGET (widget));
2346 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
2347 GTK_IS_INVISIBLE (widget));
2349 if (!GTK_WIDGET_REALIZED (widget))
2352 if (GTK_IS_CONTAINER (widget) && !GTK_WIDGET_NO_WINDOW (widget))
2353 g_message ("gtk_widget_realize(%s)", g_type_name (GTK_WIDGET_TYPE (widget)));
2356 if (widget->parent == NULL &&
2357 !GTK_WIDGET_TOPLEVEL (widget))
2358 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
2359 "inside a toplevel window is not going to work very well. "
2360 "Widgets must be inside a toplevel container before realizing them.");
2362 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
2363 gtk_widget_realize (widget->parent);
2365 gtk_widget_ensure_style (widget);
2367 g_signal_emit (widget, widget_signals[REALIZE], 0);
2369 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
2371 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
2372 gdk_window_shape_combine_mask (widget->window,
2373 shape_info->shape_mask,
2374 shape_info->offset_x,
2375 shape_info->offset_y);
2378 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
2380 gdk_window_input_shape_combine_mask (widget->window,
2381 shape_info->shape_mask,
2382 shape_info->offset_x,
2383 shape_info->offset_y);
2385 if (!GTK_WIDGET_NO_WINDOW (widget))
2387 mode = gtk_widget_get_extension_events (widget);
2388 if (mode != GDK_EXTENSION_EVENTS_NONE)
2390 events = gtk_widget_get_events (widget);
2391 gdk_input_set_extension_events (widget->window, events, mode);
2399 * gtk_widget_unrealize:
2400 * @widget: a #GtkWidget
2402 * This function is only useful in widget implementations.
2403 * Causes a widget to be unrealized (frees all GDK resources
2404 * associated with the widget, such as @widget->window).
2408 gtk_widget_unrealize (GtkWidget *widget)
2410 g_return_if_fail (GTK_IS_WIDGET (widget));
2412 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
2413 gtk_widget_shape_combine_mask (widget, NULL, 0, 0);
2415 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
2416 gtk_widget_input_shape_combine_mask (widget, NULL, 0, 0);
2418 if (GTK_WIDGET_REALIZED (widget))
2420 g_object_ref (widget);
2421 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
2422 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
2423 g_object_unref (widget);
2427 /*****************************************
2429 *****************************************/
2432 * gtk_widget_queue_draw_area:
2433 * @widget: a #GtkWidget
2434 * @x: x coordinate of upper-left corner of rectangle to redraw
2435 * @y: y coordinate of upper-left corner of rectangle to redraw
2436 * @width: width of region to draw
2437 * @height: height of region to draw
2439 * Invalidates the rectangular area of @widget defined by @x, @y,
2440 * @width and @height by calling gdk_window_invalidate_rect() on the
2441 * widget's window and all its child windows. Once the main loop
2442 * becomes idle (after the current batch of events has been processed,
2443 * roughly), the window will receive expose events for the union of
2444 * all regions that have been invalidated.
2446 * Normally you would only use this function in widget
2447 * implementations. You might also use it, or
2448 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
2449 * #GtkDrawingArea or some portion thereof.
2451 * Frequently you can just call gdk_window_invalidate_rect() or
2452 * gdk_window_invalidate_region() instead of this function. Those
2453 * functions will invalidate only a single window, instead of the
2454 * widget and all its children.
2456 * The advantage of adding to the invalidated region compared to
2457 * simply drawing immediately is efficiency; using an invalid region
2458 * ensures that you only have to redraw one time.
2462 gtk_widget_queue_draw_area (GtkWidget *widget,
2468 GdkRectangle invalid_rect;
2471 g_return_if_fail (GTK_IS_WIDGET (widget));
2473 if (!GTK_WIDGET_REALIZED (widget))
2476 /* Just return if the widget or one of its ancestors isn't mapped */
2477 for (w = widget; w != NULL; w = w->parent)
2478 if (!GTK_WIDGET_MAPPED (w))
2481 /* Find the correct widget */
2483 if (!GTK_WIDGET_NO_WINDOW (widget))
2487 /* Translate widget relative to window-relative */
2489 gint wx, wy, wwidth, wheight;
2491 gdk_window_get_position (widget->window, &wx, &wy);
2492 x -= wx - widget->allocation.x;
2493 y -= wy - widget->allocation.y;
2495 gdk_drawable_get_size (widget->window, &wwidth, &wheight);
2497 if (x + width <= 0 || y + height <= 0 ||
2498 x >= wwidth || y >= wheight)
2509 if (x + width > wwidth)
2511 if (y + height > wheight)
2512 height = wheight - y;
2518 invalid_rect.width = width;
2519 invalid_rect.height = height;
2521 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
2525 widget_add_child_draw_rectangle (GtkWidget *widget,
2528 GdkRectangle child_rect;
2530 if (!GTK_WIDGET_MAPPED (widget) ||
2531 widget->window != widget->parent->window)
2534 gtk_widget_get_draw_rectangle (widget, &child_rect);
2535 gdk_rectangle_union (rect, &child_rect, rect);
2539 gtk_widget_get_draw_rectangle (GtkWidget *widget,
2542 if (GTK_WIDGET_NO_WINDOW (widget))
2544 GtkBorder *draw_border = NULL;
2546 *rect = widget->allocation;
2548 gtk_widget_style_get (widget,
2549 "draw-border", &draw_border,
2553 rect->x -= draw_border->top;
2554 rect->y -= draw_border->left;
2555 rect->width += draw_border->left + draw_border->right;
2556 rect->height += draw_border->top + draw_border->bottom;
2559 if (GTK_IS_CONTAINER (widget))
2560 gtk_container_forall (GTK_CONTAINER (widget),
2561 (GtkCallback)widget_add_child_draw_rectangle,
2568 rect->width = widget->allocation.width;
2569 rect->height = widget->allocation.height;
2574 * gtk_widget_queue_draw:
2575 * @widget: a #GtkWidget
2577 * Equivalent to calling gtk_widget_queue_draw_area() for the
2578 * entire area of a widget.
2582 gtk_widget_queue_draw (GtkWidget *widget)
2586 g_return_if_fail (GTK_IS_WIDGET (widget));
2588 gtk_widget_get_draw_rectangle (widget, &rect);
2590 gtk_widget_queue_draw_area (widget,
2592 rect.width, rect.height);
2595 /* Invalidates the given area (allocation-relative-coordinates)
2596 * in all of the widget's windows
2599 * gtk_widget_queue_clear_area:
2600 * @widget: a #GtkWidget
2601 * @x: x coordinate of upper-left corner of rectangle to redraw
2602 * @y: y coordinate of upper-left corner of rectangle to redraw
2603 * @width: width of region to draw
2604 * @height: height of region to draw
2606 * This function is no longer different from
2607 * gtk_widget_queue_draw_area(), though it once was. Now it just calls
2608 * gtk_widget_queue_draw_area(). Originally
2609 * gtk_widget_queue_clear_area() would force a redraw of the
2610 * background for %GTK_NO_WINDOW widgets, and
2611 * gtk_widget_queue_draw_area() would not. Now both functions ensure
2612 * the background will be redrawn.
2614 * @Deprecated: Use gtk_widget_queue_draw_area() instead.
2617 gtk_widget_queue_clear_area (GtkWidget *widget,
2623 g_return_if_fail (GTK_IS_WIDGET (widget));
2625 gtk_widget_queue_draw_area (widget, x, y, width, height);
2629 * gtk_widget_queue_clear:
2630 * @widget: a #GtkWidget
2632 * This function does the same as gtk_widget_queue_draw().
2634 * @Deprecated: Use gtk_widget_queue_draw() instead.
2637 gtk_widget_queue_clear (GtkWidget *widget)
2639 g_return_if_fail (GTK_IS_WIDGET (widget));
2641 gtk_widget_queue_draw (widget);
2645 * gtk_widget_queue_resize:
2646 * @widget: a #GtkWidget
2648 * This function is only for use in widget implementations.
2649 * Flags a widget to have its size renegotiated; should
2650 * be called when a widget for some reason has a new size request.
2651 * For example, when you change the text in a #GtkLabel, #GtkLabel
2652 * queues a resize to ensure there's enough space for the new text.
2655 gtk_widget_queue_resize (GtkWidget *widget)
2657 g_return_if_fail (GTK_IS_WIDGET (widget));
2659 if (GTK_WIDGET_REALIZED (widget))
2660 gtk_widget_queue_shallow_draw (widget);
2662 _gtk_size_group_queue_resize (widget);
2666 * gtk_widget_queue_resize_no_redraw:
2667 * @widget: a #GtkWidget
2669 * This function works like gtk_widget_queue_resize(), except that the
2670 * widget is not invalidated.
2675 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
2677 g_return_if_fail (GTK_IS_WIDGET (widget));
2679 _gtk_size_group_queue_resize (widget);
2684 * @widget: a #GtkWidget
2685 * @area: area to draw
2687 * In GTK+ 1.2, this function would immediately render the
2688 * region @area of a widget, by invoking the virtual draw method of a
2689 * widget. In GTK+ 2.0, the draw method is gone, and instead
2690 * gtk_widget_draw() simply invalidates the specified region of the
2691 * widget, then updates the invalid region of the widget immediately.
2692 * Usually you don't want to update the region immediately for
2693 * performance reasons, so in general gtk_widget_queue_draw_area() is
2694 * a better choice if you want to draw a region of a widget.
2698 gtk_widget_draw (GtkWidget *widget,
2701 g_return_if_fail (GTK_IS_WIDGET (widget));
2703 if (GTK_WIDGET_DRAWABLE (widget))
2706 gtk_widget_queue_draw_area (widget,
2708 area->width, area->height);
2710 gtk_widget_queue_draw (widget);
2712 gdk_window_process_updates (widget->window, TRUE);
2717 * gtk_widget_size_request:
2718 * @widget: a #GtkWidget
2719 * @requisition: a #GtkRequisition to be filled in
2721 * This function is typically used when implementing a #GtkContainer
2722 * subclass. Obtains the preferred size of a widget. The container
2723 * uses this information to arrange its child widgets and decide what
2724 * size allocations to give them with gtk_widget_size_allocate().
2726 * You can also call this function from an application, with some
2727 * caveats. Most notably, getting a size request requires the widget
2728 * to be associated with a screen, because font information may be
2729 * needed. Multihead-aware applications should keep this in mind.
2731 * Also remember that the size request is not necessarily the size
2732 * a widget will actually be allocated.
2734 * See also gtk_widget_get_child_requisition().
2737 gtk_widget_size_request (GtkWidget *widget,
2738 GtkRequisition *requisition)
2740 g_return_if_fail (GTK_IS_WIDGET (widget));
2742 #ifdef G_ENABLE_DEBUG
2743 if (requisition == &widget->requisition)
2744 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.");
2745 #endif /* G_ENABLE_DEBUG */
2747 _gtk_size_group_compute_requisition (widget, requisition);
2751 * gtk_widget_get_child_requisition:
2752 * @widget: a #GtkWidget
2753 * @requisition: a #GtkRequisition to be filled in
2755 * This function is only for use in widget implementations. Obtains
2756 * @widget->requisition, unless someone has forced a particular
2757 * geometry on the widget (e.g. with gtk_widget_set_usize()), in which
2758 * case it returns that geometry instead of the widget's requisition.
2760 * This function differs from gtk_widget_size_request() in that
2761 * it retrieves the last size request value from @widget->requisition,
2762 * while gtk_widget_size_request() actually calls the "size_request" method
2763 * on @widget to compute the size request and fill in @widget->requisition,
2764 * and only then returns @widget->requisition.
2766 * Because this function does not call the "size_request" method, it
2767 * can only be used when you know that @widget->requisition is
2768 * up-to-date, that is, gtk_widget_size_request() has been called
2769 * since the last time a resize was queued. In general, only container
2770 * implementations have this information; applications should use
2771 * gtk_widget_size_request().
2774 gtk_widget_get_child_requisition (GtkWidget *widget,
2775 GtkRequisition *requisition)
2777 _gtk_size_group_get_child_requisition (widget, requisition);
2781 invalidate_predicate (GdkWindow *window,
2786 gdk_window_get_user_data (window, &user_data);
2788 return (user_data == data);
2791 /* Invalidate @region in widget->window and all children
2792 * of widget->window owned by widget. @region is in the
2793 * same coordinates as widget->allocation and will be
2794 * modified by this call.
2797 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
2800 if (!GTK_WIDGET_REALIZED (widget))
2803 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
2807 gdk_window_get_position (widget->window, &x, &y);
2808 gdk_region_offset (region, -x, -y);
2811 gdk_window_invalidate_maybe_recurse (widget->window, region,
2812 invalidate_predicate, widget);
2816 * gtk_widget_queue_shallow_draw:
2817 * @widget: a #GtkWidget
2819 * Like gtk_widget_queue_draw(), but only windows owned
2820 * by @widget are invalidated.
2823 gtk_widget_queue_shallow_draw (GtkWidget *widget)
2828 if (!GTK_WIDGET_REALIZED (widget))
2831 gtk_widget_get_draw_rectangle (widget, &rect);
2833 /* get_draw_rectangle() gives us window coordinates, we
2834 * need to convert to the coordinates that widget->allocation
2837 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
2841 gdk_window_get_position (widget->window, &wx, &wy);
2847 region = gdk_region_rectangle (&rect);
2848 gtk_widget_invalidate_widget_windows (widget, region);
2849 gdk_region_destroy (region);
2853 * gtk_widget_size_allocate:
2854 * @widget: a #GtkWidget
2855 * @allocation: position and size to be allocated to @widget
2857 * This function is only used by #GtkContainer subclasses, to assign a size
2858 * and position to their child widgets.
2862 gtk_widget_size_allocate (GtkWidget *widget,
2863 GtkAllocation *allocation)
2865 GtkWidgetAuxInfo *aux_info;
2866 GdkRectangle real_allocation;
2867 GdkRectangle old_allocation;
2868 gboolean alloc_needed;
2869 gboolean size_changed;
2870 gboolean position_changed;
2872 g_return_if_fail (GTK_IS_WIDGET (widget));
2874 #ifdef G_ENABLE_DEBUG
2875 if (gtk_debug_flags & GTK_DEBUG_GEOMETRY)
2886 parent = gtk_widget_get_parent (parent);
2889 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
2890 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
2891 2 * depth, " ", name,
2892 allocation->width, allocation->height);
2894 #endif /* G_ENABLE_DEBUG */
2896 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
2897 if (!GTK_WIDGET_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
2898 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
2900 old_allocation = widget->allocation;
2901 real_allocation = *allocation;
2902 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
2906 if (aux_info->x_set)
2907 real_allocation.x = aux_info->x;
2908 if (aux_info->y_set)
2909 real_allocation.y = aux_info->y;
2912 if (real_allocation.width < 0 || real_allocation.height < 0)
2914 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
2915 real_allocation.width,
2916 real_allocation.height);
2919 real_allocation.width = MAX (real_allocation.width, 1);
2920 real_allocation.height = MAX (real_allocation.height, 1);
2922 size_changed = (old_allocation.width != real_allocation.width ||
2923 old_allocation.height != real_allocation.height);
2924 position_changed = (old_allocation.x != real_allocation.x ||
2925 old_allocation.y != real_allocation.y);
2927 if (!alloc_needed && !size_changed && !position_changed)
2930 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
2932 if (GTK_WIDGET_MAPPED (widget))
2934 if (GTK_WIDGET_NO_WINDOW (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
2936 /* Invalidate union(old_allaction,widget->allocation) in widget->window
2938 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
2939 gdk_region_union_with_rect (invalidate, &old_allocation);
2941 gdk_window_invalidate_region (widget->window, invalidate, FALSE);
2942 gdk_region_destroy (invalidate);
2947 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
2949 /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
2951 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
2952 gdk_region_union_with_rect (invalidate, &old_allocation);
2954 gtk_widget_invalidate_widget_windows (widget, invalidate);
2955 gdk_region_destroy (invalidate);
2960 if ((size_changed || position_changed) && widget->parent &&
2961 GTK_WIDGET_REALIZED (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
2963 GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
2964 gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
2965 gdk_region_destroy (invalidate);
2970 * gtk_widget_common_ancestor:
2971 * @widget_a: a #GtkWidget
2972 * @widget_b: a #GtkWidget
2974 * Find the common ancestor of @widget_a and @widget_b that
2975 * is closest to the two widgets.
2977 * Return value: the closest common ancestor of @widget_a and
2978 * @widget_b or %NULL if @widget_a and @widget_b do not
2979 * share a common ancestor.
2982 gtk_widget_common_ancestor (GtkWidget *widget_a,
2983 GtkWidget *widget_b)
2985 GtkWidget *parent_a;
2986 GtkWidget *parent_b;
2990 parent_a = widget_a;
2991 while (parent_a->parent)
2993 parent_a = parent_a->parent;
2997 parent_b = widget_b;
2998 while (parent_b->parent)
3000 parent_b = parent_b->parent;
3004 if (parent_a != parent_b)
3007 while (depth_a > depth_b)
3009 widget_a = widget_a->parent;
3013 while (depth_b > depth_a)
3015 widget_b = widget_b->parent;
3019 while (widget_a != widget_b)
3021 widget_a = widget_a->parent;
3022 widget_b = widget_b->parent;
3029 * gtk_widget_translate_coordinates:
3030 * @src_widget: a #GtkWidget
3031 * @dest_widget: a #GtkWidget
3032 * @src_x: X position relative to @src_widget
3033 * @src_y: Y position relative to @src_widget
3034 * @dest_x: location to store X position relative to @dest_widget
3035 * @dest_y: location to store Y position relative to @dest_widget
3037 * Translate coordinates relative to @src_widget's allocation to coordinates
3038 * relative to @dest_widget's allocations. In order to perform this
3039 * operation, both widgets must be realized, and must share a common
3042 * Return value: %FALSE if either widget was not realized, or there
3043 * was no common ancestor. In this case, nothing is stored in
3044 * *@dest_x and *@dest_y. Otherwise %TRUE.
3047 gtk_widget_translate_coordinates (GtkWidget *src_widget,
3048 GtkWidget *dest_widget,
3054 GtkWidget *ancestor;
3057 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
3058 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
3060 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
3061 if (!ancestor || !GTK_WIDGET_REALIZED (src_widget) || !GTK_WIDGET_REALIZED (dest_widget))
3064 /* Translate from allocation relative to window relative */
3065 if (!GTK_WIDGET_NO_WINDOW (src_widget) && src_widget->parent)
3068 gdk_window_get_position (src_widget->window, &wx, &wy);
3070 src_x -= wx - src_widget->allocation.x;
3071 src_y -= wy - src_widget->allocation.y;
3075 src_x += src_widget->allocation.x;
3076 src_y += src_widget->allocation.y;
3079 /* Translate to the common ancestor */
3080 window = src_widget->window;
3081 while (window != ancestor->window)
3085 gdk_window_get_position (window, &dx, &dy);
3090 window = gdk_window_get_parent (window);
3092 if (!window) /* Handle GtkHandleBox */
3097 window = dest_widget->window;
3098 while (window != ancestor->window)
3102 gdk_window_get_position (window, &dx, &dy);
3107 window = gdk_window_get_parent (window);
3109 if (!window) /* Handle GtkHandleBox */
3113 /* Translate from window relative to allocation relative */
3114 if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent)
3117 gdk_window_get_position (dest_widget->window, &wx, &wy);
3119 src_x += wx - dest_widget->allocation.x;
3120 src_y += wy - dest_widget->allocation.y;
3124 src_x -= dest_widget->allocation.x;
3125 src_y -= dest_widget->allocation.y;
3137 gtk_widget_real_size_allocate (GtkWidget *widget,
3138 GtkAllocation *allocation)
3140 widget->allocation = *allocation;
3142 if (GTK_WIDGET_REALIZED (widget) &&
3143 !GTK_WIDGET_NO_WINDOW (widget))
3145 gdk_window_move_resize (widget->window,
3146 allocation->x, allocation->y,
3147 allocation->width, allocation->height);
3152 gtk_widget_real_can_activate_accel (GtkWidget *widget,
3155 /* widgets must be onscreen for accels to take effect */
3156 return GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_DRAWABLE (widget) && gdk_window_is_viewable (widget->window);
3160 * gtk_widget_can_activate_accel:
3161 * @widget: a #GtkWidget
3162 * @signal_id: the ID of a signal installed on @widget
3164 * Determines whether an accelerator that activates the signal
3165 * identified by @signal_id can currently be activated.
3166 * This is done by emitting the GtkWidget::can-activate-accel
3167 * signal on @widget; if the signal isn't overridden by a
3168 * handler or in a derived widget, then the default check is
3169 * that the widget must be sensitive, and the widget and all
3170 * its ancestors mapped.
3172 * Return value: %TRUE if the accelerator can be activated.
3177 gtk_widget_can_activate_accel (GtkWidget *widget,
3180 gboolean can_activate = FALSE;
3181 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3182 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
3183 return can_activate;
3192 closure_accel_activate (GClosure *closure,
3193 GValue *return_value,
3194 guint n_param_values,
3195 const GValue *param_values,
3196 gpointer invocation_hint,
3197 gpointer marshal_data)
3199 AccelClosure *aclosure = (AccelClosure*) closure;
3200 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
3203 g_signal_emit (closure->data, aclosure->signal_id, 0);
3205 /* whether accelerator was handled */
3206 g_value_set_boolean (return_value, can_activate);
3210 closures_destroy (gpointer data)
3212 GSList *slist, *closures = data;
3214 for (slist = closures; slist; slist = slist->next)
3216 g_closure_invalidate (slist->data);
3217 g_closure_unref (slist->data);
3219 g_slist_free (closures);
3223 widget_new_accel_closure (GtkWidget *widget,
3226 AccelClosure *aclosure;
3227 GClosure *closure = NULL;
3228 GSList *slist, *closures;
3230 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
3231 for (slist = closures; slist; slist = slist->next)
3232 if (!gtk_accel_group_from_accel_closure (slist->data))
3234 /* reuse this closure */
3235 closure = slist->data;
3240 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
3241 closures = g_slist_prepend (closures, g_closure_ref (closure));
3242 g_closure_sink (closure);
3243 g_closure_set_marshal (closure, closure_accel_activate);
3245 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
3247 aclosure = (AccelClosure*) closure;
3248 g_assert (closure->data == widget);
3249 g_assert (closure->marshal == closure_accel_activate);
3250 aclosure->signal_id = signal_id;
3256 * gtk_widget_add_accelerator
3257 * @widget: widget to install an accelerator on
3258 * @accel_signal: widget signal to emit on accelerator activation
3259 * @accel_group: accel group for this widget, added to its toplevel
3260 * @accel_key: GDK keyval of the accelerator
3261 * @accel_mods: modifier key combination of the accelerator
3262 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
3264 * Installs an accelerator for this @widget in @accel_group that causes
3265 * @accel_signal to be emitted if the accelerator is activated.
3266 * The @accel_group needs to be added to the widget's toplevel via
3267 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
3268 * Accelerators added through this function are not user changeable during
3269 * runtime. If you want to support accelerators that can be changed by the
3270 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
3271 * gtk_menu_item_set_accel_path() instead.
3274 gtk_widget_add_accelerator (GtkWidget *widget,
3275 const gchar *accel_signal,
3276 GtkAccelGroup *accel_group,
3278 GdkModifierType accel_mods,
3279 GtkAccelFlags accel_flags)
3284 g_return_if_fail (GTK_IS_WIDGET (widget));
3285 g_return_if_fail (accel_signal != NULL);
3286 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
3288 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
3289 if (!query.signal_id ||
3290 !(query.signal_flags & G_SIGNAL_ACTION) ||
3291 query.return_type != G_TYPE_NONE ||
3294 /* hmm, should be elaborate enough */
3295 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
3296 G_OBJECT_TYPE_NAME (widget), accel_signal);
3300 closure = widget_new_accel_closure (widget, query.signal_id);
3302 g_object_ref (widget);
3304 /* install the accelerator. since we don't map this onto an accel_path,
3305 * the accelerator will automatically be locked.
3307 gtk_accel_group_connect (accel_group,
3310 accel_flags | GTK_ACCEL_LOCKED,
3313 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3315 g_object_unref (widget);
3319 * gtk_widget_remove_accelerator:
3320 * @widget: widget to install an accelerator on
3321 * @accel_group: accel group for this widget
3322 * @accel_key: GDK keyval of the accelerator
3323 * @accel_mods: modifier key combination of the accelerator
3324 * @returns: whether an accelerator was installed and could be removed
3326 * Removes an accelerator from @widget, previously installed with
3327 * gtk_widget_add_accelerator().
3330 gtk_widget_remove_accelerator (GtkWidget *widget,
3331 GtkAccelGroup *accel_group,
3333 GdkModifierType accel_mods)
3335 GtkAccelGroupEntry *ag_entry;
3336 GList *slist, *clist;
3339 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3340 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
3342 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
3343 clist = gtk_widget_list_accel_closures (widget);
3344 for (slist = clist; slist; slist = slist->next)
3348 for (i = 0; i < n; i++)
3349 if (slist->data == (gpointer) ag_entry[i].closure)
3351 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
3353 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3355 g_list_free (clist);
3360 g_list_free (clist);
3362 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
3363 accel_key, accel_mods, accel_group,
3364 G_OBJECT_TYPE_NAME (widget), widget);
3370 * gtk_widget_list_accel_closures
3371 * @widget: widget to list accelerator closures for
3372 * @returns: a newly allocated #GList of closures
3374 * Lists the closures used by @widget for accelerator group connections
3375 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
3376 * The closures can be used to monitor accelerator changes on @widget,
3377 * by connecting to the ::accel_changed signal of the #GtkAccelGroup of a
3378 * closure which can be found out with gtk_accel_group_from_accel_closure().
3381 gtk_widget_list_accel_closures (GtkWidget *widget)
3384 GList *clist = NULL;
3386 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3388 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
3389 if (gtk_accel_group_from_accel_closure (slist->data))
3390 clist = g_list_prepend (clist, slist->data);
3396 GtkAccelGroup *accel_group;
3401 destroy_accel_path (gpointer data)
3403 AccelPath *apath = data;
3405 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
3407 /* closures_destroy takes care of unrefing the closure */
3408 g_object_unref (apath->accel_group);
3410 g_slice_free (AccelPath, apath);
3415 * gtk_widget_set_accel_path:
3416 * @widget: a #GtkWidget
3417 * @accel_path: path used to look up the accelerator
3418 * @accel_group: a #GtkAccelGroup.
3420 * Given an accelerator group, @accel_group, and an accelerator path,
3421 * @accel_path, sets up an accelerator in @accel_group so whenever the
3422 * key binding that is defined for @accel_path is pressed, @widget
3423 * will be activated. This removes any accelerators (for any
3424 * accelerator group) installed by previous calls to
3425 * gtk_widget_set_accel_path(). Associating accelerators with
3426 * paths allows them to be modified by the user and the modifications
3427 * to be saved for future use. (See gtk_accel_map_save().)
3429 * This function is a low level function that would most likely
3430 * be used by a menu creation system like #GtkItemFactory. If you
3431 * use #GtkItemFactory, setting up accelerator paths will be done
3434 * Even when you you aren't using #GtkItemFactory, if you only want to
3435 * set up accelerators on menu items gtk_menu_item_set_accel_path()
3436 * provides a somewhat more convenient interface.
3439 gtk_widget_set_accel_path (GtkWidget *widget,
3440 const gchar *accel_path,
3441 GtkAccelGroup *accel_group)
3445 g_return_if_fail (GTK_IS_WIDGET (widget));
3446 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
3450 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
3451 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
3453 gtk_accel_map_add_entry (accel_path, 0, 0);
3454 apath = g_slice_new (AccelPath);
3455 apath->accel_group = g_object_ref (accel_group);
3456 apath->path_quark = g_quark_from_string (accel_path);
3457 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
3462 /* also removes possible old settings */
3463 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
3466 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
3468 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3472 _gtk_widget_get_accel_path (GtkWidget *widget,
3477 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3479 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
3481 *locked = apath ? apath->accel_group->lock_count > 0 : TRUE;
3482 return apath ? g_quark_to_string (apath->path_quark) : NULL;
3486 gtk_widget_mnemonic_activate (GtkWidget *widget,
3487 gboolean group_cycling)
3491 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3493 group_cycling = group_cycling != FALSE;
3494 if (!GTK_WIDGET_IS_SENSITIVE (widget))
3497 g_signal_emit (widget,
3498 widget_signals[MNEMONIC_ACTIVATE],
3506 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
3507 gboolean group_cycling)
3509 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
3510 gtk_widget_activate (widget);
3511 else if (GTK_WIDGET_CAN_FOCUS (widget))
3512 gtk_widget_grab_focus (widget);
3515 g_warning ("widget `%s' isn't suitable for mnemonic activation",
3516 G_OBJECT_TYPE_NAME (widget));
3517 gdk_display_beep (gtk_widget_get_display (widget));
3523 gtk_widget_real_key_press_event (GtkWidget *widget,
3526 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
3530 gtk_widget_real_key_release_event (GtkWidget *widget,
3533 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
3537 gtk_widget_real_focus_in_event (GtkWidget *widget,
3538 GdkEventFocus *event)
3540 gtk_widget_queue_shallow_draw (widget);
3546 gtk_widget_real_focus_out_event (GtkWidget *widget,
3547 GdkEventFocus *event)
3549 gtk_widget_queue_shallow_draw (widget);
3554 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
3555 (event->type == GDK_FOCUS_CHANGE || GTK_WIDGET_REALIZED(widget))
3559 * @widget: a #GtkWidget
3560 * @event: a #GdkEvent
3562 * Rarely-used function. This function is used to emit
3563 * the event signals on a widget (those signals should never
3564 * be emitted without using this function to do so).
3565 * If you want to synthesize an event though, don't use this function;
3566 * instead, use gtk_main_do_event() so the event will behave as if
3567 * it were in the event queue. Don't synthesize expose events; instead,
3568 * use gdk_window_invalidate_rect() to invalidate a region of the
3571 * Return value: return from the event signal emission (%TRUE if the event was handled)
3574 gtk_widget_event (GtkWidget *widget,
3577 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
3578 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
3580 if (event->type == GDK_EXPOSE)
3582 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
3583 "the same effect, call gdk_window_invalidate_rect/region(), "
3584 "followed by gdk_window_process_updates().");
3588 return gtk_widget_event_internal (widget, event);
3593 * gtk_widget_send_expose:
3594 * @widget: a #GtkWidget
3595 * @event: a expose #GdkEvent
3597 * Very rarely-used function. This function is used to emit
3598 * an expose event signals on a widget. This function is not
3599 * normally used directly. The only time it is used is when
3600 * propagating an expose event to a child %NO_WINDOW widget, and
3601 * that is normally done using gtk_container_propagate_expose().
3603 * If you want to force an area of a window to be redrawn,
3604 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
3605 * To cause the redraw to be done immediately, follow that call
3606 * with a call to gdk_window_process_updates().
3608 * Return value: return from the event signal emission (%TRUE if the event was handled)
3611 gtk_widget_send_expose (GtkWidget *widget,
3614 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
3615 g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), TRUE);
3616 g_return_val_if_fail (event != NULL, TRUE);
3617 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
3619 return gtk_widget_event_internal (widget, event);
3623 event_window_is_still_viewable (GdkEvent *event)
3625 /* Some programs, such as gnome-theme-manager, fake widgets
3626 * into exposing onto a pixmap by sending expose events with
3627 * event->window pointing to a pixmap
3629 if (GDK_IS_PIXMAP (event->any.window))
3630 return event->type == GDK_EXPOSE;
3632 /* Check that we think the event's window is viewable before
3633 * delivering the event, to prevent suprises. We do this here
3634 * at the last moment, since the event may have been queued
3635 * up behind other events, held over a recursive main loop, etc.
3637 switch (event->type)
3640 case GDK_MOTION_NOTIFY:
3641 case GDK_BUTTON_PRESS:
3642 case GDK_2BUTTON_PRESS:
3643 case GDK_3BUTTON_PRESS:
3645 case GDK_ENTER_NOTIFY:
3646 case GDK_PROXIMITY_IN:
3648 return event->any.window && gdk_window_is_viewable (event->any.window);
3651 /* The following events are the second half of paired events;
3652 * we always deliver them to deal with widgets that clean up
3653 * on the second half.
3655 case GDK_BUTTON_RELEASE:
3656 case GDK_KEY_RELEASE:
3657 case GDK_LEAVE_NOTIFY:
3658 case GDK_PROXIMITY_OUT:
3662 /* Remaining events would make sense on an not-viewable window,
3663 * or don't have an associated window.
3670 gtk_widget_event_internal (GtkWidget *widget,
3673 gboolean return_val = FALSE;
3675 /* We check only once for is-still-visible; if someone
3676 * hides the window in on of the signals on the widget,
3677 * they are responsible for returning TRUE to terminate
3680 if (!event_window_is_still_viewable (event))
3683 g_object_ref (widget);
3685 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
3686 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
3691 switch (event->type)
3696 case GDK_BUTTON_PRESS:
3697 case GDK_2BUTTON_PRESS:
3698 case GDK_3BUTTON_PRESS:
3699 signal_num = BUTTON_PRESS_EVENT;
3702 signal_num = SCROLL_EVENT;
3704 case GDK_BUTTON_RELEASE:
3705 signal_num = BUTTON_RELEASE_EVENT;
3707 case GDK_MOTION_NOTIFY:
3708 signal_num = MOTION_NOTIFY_EVENT;
3711 signal_num = DELETE_EVENT;
3714 signal_num = DESTROY_EVENT;
3717 signal_num = KEY_PRESS_EVENT;
3719 case GDK_KEY_RELEASE:
3720 signal_num = KEY_RELEASE_EVENT;
3722 case GDK_ENTER_NOTIFY:
3723 signal_num = ENTER_NOTIFY_EVENT;
3725 case GDK_LEAVE_NOTIFY:
3726 signal_num = LEAVE_NOTIFY_EVENT;
3728 case GDK_FOCUS_CHANGE:
3729 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
3732 signal_num = CONFIGURE_EVENT;
3735 signal_num = MAP_EVENT;
3738 signal_num = UNMAP_EVENT;
3740 case GDK_WINDOW_STATE:
3741 signal_num = WINDOW_STATE_EVENT;
3743 case GDK_PROPERTY_NOTIFY:
3744 signal_num = PROPERTY_NOTIFY_EVENT;
3746 case GDK_SELECTION_CLEAR:
3747 signal_num = SELECTION_CLEAR_EVENT;
3749 case GDK_SELECTION_REQUEST:
3750 signal_num = SELECTION_REQUEST_EVENT;
3752 case GDK_SELECTION_NOTIFY:
3753 signal_num = SELECTION_NOTIFY_EVENT;
3755 case GDK_PROXIMITY_IN:
3756 signal_num = PROXIMITY_IN_EVENT;
3758 case GDK_PROXIMITY_OUT:
3759 signal_num = PROXIMITY_OUT_EVENT;
3762 signal_num = NO_EXPOSE_EVENT;
3764 case GDK_CLIENT_EVENT:
3765 signal_num = CLIENT_EVENT;
3768 signal_num = EXPOSE_EVENT;
3770 case GDK_VISIBILITY_NOTIFY:
3771 signal_num = VISIBILITY_NOTIFY_EVENT;
3773 case GDK_GRAB_BROKEN:
3774 signal_num = GRAB_BROKEN;
3777 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
3781 if (signal_num != -1)
3782 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
3784 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
3785 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
3789 g_object_unref (widget);
3795 * gtk_widget_activate:
3796 * @widget: a #GtkWidget that's activatable
3798 * For widgets that can be "activated" (buttons, menu items, etc.)
3799 * this function activates them. Activation is what happens when you
3800 * press Enter on a widget during key navigation. If @widget isn't
3801 * activatable, the function returns %FALSE.
3803 * Return value: %TRUE if the widget was activatable
3806 gtk_widget_activate (GtkWidget *widget)
3808 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3810 if (WIDGET_CLASS (widget)->activate_signal)
3812 /* FIXME: we should eventually check the signals signature here */
3813 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
3822 * gtk_widget_set_scroll_adjustments:
3823 * @widget: a #GtkWidget
3824 * @hadjustment: an adjustment for horizontal scrolling, or %NULL
3825 * @vadjustment: an adjustment for vertical scrolling, or %NULL
3827 * For widgets that support scrolling, sets the scroll adjustments and
3828 * returns %TRUE. For widgets that don't support scrolling, does
3829 * nothing and returns %FALSE. Widgets that don't support scrolling
3830 * can be scrolled by placing them in a #GtkViewport, which does
3831 * support scrolling.
3833 * Return value: %TRUE if the widget supports scrolling
3836 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
3837 GtkAdjustment *hadjustment,
3838 GtkAdjustment *vadjustment)
3840 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3842 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
3844 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
3846 if (WIDGET_CLASS (widget)->set_scroll_adjustments_signal)
3848 /* FIXME: we should eventually check the signals signature here */
3849 g_signal_emit (widget,
3850 WIDGET_CLASS (widget)->set_scroll_adjustments_signal, 0,
3851 hadjustment, vadjustment);
3859 gtk_widget_reparent_subwindows (GtkWidget *widget,
3860 GdkWindow *new_window)
3862 if (GTK_WIDGET_NO_WINDOW (widget))
3864 GList *children = gdk_window_get_children (widget->window);
3867 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
3870 GdkWindow *window = tmp_list->data;
3872 gdk_window_get_user_data (window, (void **)&child);
3873 while (child && child != widget)
3874 child = child->parent;
3877 gdk_window_reparent (window, new_window, 0, 0);
3880 g_list_free (children);
3885 GList *tmp_list, *children;
3887 parent = gdk_window_get_parent (widget->window);
3890 gdk_window_reparent (widget->window, new_window, 0, 0);
3893 children = gdk_window_get_children (parent);
3895 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
3898 GdkWindow *window = tmp_list->data;
3900 gdk_window_get_user_data (window, (void **)&child);
3901 if (child == widget)
3902 gdk_window_reparent (window, new_window, 0, 0);
3905 g_list_free (children);
3911 gtk_widget_reparent_fixup_child (GtkWidget *widget,
3912 gpointer client_data)
3914 g_assert (client_data != NULL);
3916 if (GTK_WIDGET_NO_WINDOW (widget))
3919 g_object_unref (widget->window);
3920 widget->window = (GdkWindow*) client_data;
3922 g_object_ref (widget->window);
3924 if (GTK_IS_CONTAINER (widget))
3925 gtk_container_forall (GTK_CONTAINER (widget),
3926 gtk_widget_reparent_fixup_child,
3932 * gtk_widget_reparent:
3933 * @widget: a #GtkWidget
3934 * @new_parent: a #GtkContainer to move the widget into
3936 * Moves a widget from one #GtkContainer to another, handling reference
3937 * count issues to avoid destroying the widget.
3941 gtk_widget_reparent (GtkWidget *widget,
3942 GtkWidget *new_parent)
3944 g_return_if_fail (GTK_IS_WIDGET (widget));
3945 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
3946 g_return_if_fail (widget->parent != NULL);
3948 if (widget->parent != new_parent)
3950 /* First try to see if we can get away without unrealizing
3951 * the widget as we reparent it. if so we set a flag so
3952 * that gtk_widget_unparent doesn't unrealize widget
3954 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent))
3955 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
3957 g_object_ref (widget);
3958 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
3959 gtk_container_add (GTK_CONTAINER (new_parent), widget);
3960 g_object_unref (widget);
3962 if (GTK_WIDGET_IN_REPARENT (widget))
3964 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
3966 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
3967 gtk_widget_reparent_fixup_child (widget,
3968 gtk_widget_get_parent_window (widget));
3971 g_object_notify (G_OBJECT (widget), "parent");
3976 * gtk_widget_intersect:
3977 * @widget: a #GtkWidget
3978 * @area: a rectangle
3979 * @intersection: rectangle to store intersection of @widget and @area
3981 * Computes the intersection of a @widget's area and @area, storing
3982 * the intersection in @intersection, and returns %TRUE if there was
3983 * an intersection. @intersection may be %NULL if you're only
3984 * interested in whether there was an intersection.
3986 * Return value: %TRUE if there was an intersection
3989 gtk_widget_intersect (GtkWidget *widget,
3991 GdkRectangle *intersection)
3997 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3998 g_return_val_if_fail (area != NULL, FALSE);
4001 dest = intersection;
4005 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
4007 if (return_val && intersection && !GTK_WIDGET_NO_WINDOW (widget))
4009 intersection->x -= widget->allocation.x;
4010 intersection->y -= widget->allocation.y;
4017 * gtk_widget_region_intersect:
4018 * @widget: a #GtkWidget
4019 * @region: a #GdkRegion, in the same coordinate system as
4020 * @widget->allocation. That is, relative to @widget->window
4021 * for %NO_WINDOW widgets; relative to the parent window
4022 * of @widget->window for widgets with their own window.
4023 * @returns: A newly allocated region holding the intersection of @widget
4024 * and @region. The coordinates of the return value are
4025 * relative to @widget->window for %NO_WINDOW widgets, and
4026 * relative to the parent window of @widget->window for
4027 * widgets with their own window.
4029 * Computes the intersection of a @widget's area and @region, returning
4030 * the intersection. The result may be empty, use gdk_region_empty() to
4034 gtk_widget_region_intersect (GtkWidget *widget,
4040 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4041 g_return_val_if_fail (region != NULL, NULL);
4043 gtk_widget_get_draw_rectangle (widget, &rect);
4045 dest = gdk_region_rectangle (&rect);
4047 gdk_region_intersect (dest, region);
4053 * _gtk_widget_grab_notify:
4054 * @widget: a #GtkWidget
4055 * @was_grabbed: whether a grab is now in effect
4057 * Emits the signal "grab_notify" on @widget.
4062 _gtk_widget_grab_notify (GtkWidget *widget,
4063 gboolean was_grabbed)
4065 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
4069 * gtk_widget_grab_focus:
4070 * @widget: a #GtkWidget
4072 * Causes @widget to have the keyboard focus for the #GtkWindow it's
4073 * inside. @widget must be a focusable widget, such as a #GtkEntry;
4074 * something like #GtkFrame won't work. (More precisely, it must have the
4075 * %GTK_CAN_FOCUS flag set.)
4079 gtk_widget_grab_focus (GtkWidget *widget)
4081 g_return_if_fail (GTK_IS_WIDGET (widget));
4083 if (!GTK_WIDGET_IS_SENSITIVE (widget))
4086 g_object_ref (widget);
4087 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
4088 g_object_notify (G_OBJECT (widget), "has-focus");
4089 g_object_unref (widget);
4093 reset_focus_recurse (GtkWidget *widget,
4096 if (GTK_IS_CONTAINER (widget))
4098 GtkContainer *container;
4100 container = GTK_CONTAINER (widget);
4101 gtk_container_set_focus_child (container, NULL);
4103 gtk_container_foreach (container,
4104 reset_focus_recurse,
4110 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
4112 if (GTK_WIDGET_CAN_FOCUS (focus_widget))
4114 GtkWidget *toplevel;
4117 /* clear the current focus setting, break if the current widget
4118 * is the focus widget's parent, since containers above that will
4119 * be set by the next loop.
4121 toplevel = gtk_widget_get_toplevel (focus_widget);
4122 if (GTK_WIDGET_TOPLEVEL (toplevel))
4124 widget = GTK_WINDOW (toplevel)->focus_widget;
4126 if (widget == focus_widget)
4128 /* We call _gtk_window_internal_set_focus() here so that the
4129 * toplevel window can request the focus if necessary.
4130 * This is needed when the toplevel is a GtkPlug
4132 if (!GTK_WIDGET_HAS_FOCUS (widget))
4133 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
4140 while (widget->parent && widget->parent != focus_widget->parent)
4142 widget = widget->parent;
4143 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
4147 else if (toplevel != focus_widget)
4149 /* gtk_widget_grab_focus() operates on a tree without window...
4150 * actually, this is very questionable behaviour.
4153 gtk_container_foreach (GTK_CONTAINER (toplevel),
4154 reset_focus_recurse,
4158 /* now propagate the new focus up the widget tree and finally
4159 * set it on the window
4161 widget = focus_widget;
4162 while (widget->parent)
4164 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
4165 widget = widget->parent;
4167 if (GTK_IS_WINDOW (widget))
4168 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
4173 gtk_widget_real_show_help (GtkWidget *widget,
4174 GtkWidgetHelpType help_type)
4176 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
4178 _gtk_tooltips_toggle_keyboard_mode (widget);
4186 gtk_widget_real_focus (GtkWidget *widget,
4187 GtkDirectionType direction)
4189 if (!GTK_WIDGET_CAN_FOCUS (widget))
4192 if (!gtk_widget_is_focus (widget))
4194 gtk_widget_grab_focus (widget);
4202 * gtk_widget_is_focus:
4203 * @widget: a #GtkWidget
4205 * Determines if the widget is the focus widget within its
4206 * toplevel. (This does not mean that the %HAS_FOCUS flag is
4207 * necessarily set; %HAS_FOCUS will only be set if the
4208 * toplevel widget additionally has the global input focus.)
4210 * Return value: %TRUE if the widget is the focus widget.
4213 gtk_widget_is_focus (GtkWidget *widget)
4215 GtkWidget *toplevel;
4217 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4219 toplevel = gtk_widget_get_toplevel (widget);
4221 if (GTK_IS_WINDOW (toplevel))
4222 return widget == GTK_WINDOW (toplevel)->focus_widget;
4228 * gtk_widget_grab_default:
4229 * @widget: a #GtkWidget
4231 * Causes @widget to become the default widget. @widget must have the
4232 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
4233 * yourself by calling <literal>GTK_WIDGET_SET_FLAGS (@widget,
4234 * GTK_CAN_DEFAULT)</literal>. The default widget is activated when the user
4235 * presses Enter in a window. Default widgets must be activatable,
4236 * that is, gtk_widget_activate() should affect them.
4240 gtk_widget_grab_default (GtkWidget *widget)
4244 g_return_if_fail (GTK_IS_WIDGET (widget));
4245 g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget));
4247 window = gtk_widget_get_toplevel (widget);
4249 if (window && GTK_WIDGET_TOPLEVEL (window))
4250 gtk_window_set_default (GTK_WINDOW (window), widget);
4252 g_warning (G_STRLOC ": widget not within a GtkWindow");
4256 * gtk_widget_set_name:
4257 * @widget: a #GtkWidget
4258 * @name: name for the widget
4260 * Widgets can be named, which allows you to refer to them from a
4261 * gtkrc file. You can apply a style to widgets with a particular name
4262 * in the gtkrc file. See the documentation for gtkrc files (on the
4263 * same page as the docs for #GtkRcStyle).
4265 * Note that widget names are separated by periods in paths (see
4266 * gtk_widget_path()), so names with embedded periods may cause confusion.
4269 gtk_widget_set_name (GtkWidget *widget,
4274 g_return_if_fail (GTK_IS_WIDGET (widget));
4276 new_name = g_strdup (name);
4277 g_free (widget->name);
4278 widget->name = new_name;
4280 if (GTK_WIDGET_RC_STYLE (widget))
4281 gtk_widget_reset_rc_style (widget);
4283 g_object_notify (G_OBJECT (widget), "name");
4287 * gtk_widget_get_name:
4288 * @widget: a #GtkWidget
4290 * Retrieves the name of a widget. See gtk_widget_set_name() for the
4291 * significance of widget names.
4293 * Return value: name of the widget. This string is owned by GTK+ and
4294 * should not be modified or freed
4296 G_CONST_RETURN gchar*
4297 gtk_widget_get_name (GtkWidget *widget)
4299 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4302 return widget->name;
4303 return g_type_name (GTK_WIDGET_TYPE (widget));
4307 * gtk_widget_set_state:
4308 * @widget: a #GtkWidget
4309 * @state: new state for @widget
4311 * This function is for use in widget implementations. Sets the state
4312 * of a widget (insensitive, prelighted, etc.) Usually you should set
4313 * the state using wrapper functions such as gtk_widget_set_sensitive().
4317 gtk_widget_set_state (GtkWidget *widget,
4320 g_return_if_fail (GTK_IS_WIDGET (widget));
4322 if (state == GTK_WIDGET_STATE (widget))
4325 if (state == GTK_STATE_INSENSITIVE)
4326 gtk_widget_set_sensitive (widget, FALSE);
4332 data.state_restoration = FALSE;
4333 data.use_forall = FALSE;
4335 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
4337 data.parent_sensitive = TRUE;
4339 gtk_widget_propagate_state (widget, &data);
4341 if (GTK_WIDGET_DRAWABLE (widget))
4342 gtk_widget_queue_draw (widget);
4348 * gtk_widget_set_app_paintable:
4349 * @widget: a #GtkWidget
4350 * @app_paintable: %TRUE if the application will paint on the widget
4352 * Sets whether the application intends to draw on the widget in
4353 * an ::expose-event handler.
4355 * This is a hint to the widget and does not affect the behavior of
4356 * the GTK+ core; many widgets ignore this flag entirely. For widgets
4357 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
4358 * the effect is to suppress default themed drawing of the widget's
4359 * background. (Children of the widget will still be drawn.) The application
4360 * is then entirely responsible for drawing the widget background.
4362 * Note that the background is still drawn when the widget is mapped.
4363 * If this is not suitable (e.g. because you want to make a transparent
4364 * window using an RGBA visual), you can work around this by doing:
4365 * <informalexample><programlisting>
4366 * gtk_widget_realize (window);
4367 * gdk_window_set_back_pixmap (window->window, NULL, FALSE);
4368 * gtk_widget_show (window);
4369 * </programlisting></informalexample>
4372 gtk_widget_set_app_paintable (GtkWidget *widget,
4373 gboolean app_paintable)
4375 g_return_if_fail (GTK_IS_WIDGET (widget));
4377 app_paintable = (app_paintable != FALSE);
4379 if (GTK_WIDGET_APP_PAINTABLE (widget) != app_paintable)
4382 GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE);
4384 GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE);
4386 if (GTK_WIDGET_DRAWABLE (widget))
4387 gtk_widget_queue_draw (widget);
4389 g_object_notify (G_OBJECT (widget), "app-paintable");
4394 * gtk_widget_set_double_buffered:
4395 * @widget: a #GtkWidget
4396 * @double_buffered: %TRUE to double-buffer a widget
4398 * Widgets are double buffered by default; you can use this function
4399 * to turn off the buffering. "Double buffered" simply means that
4400 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
4401 * automatically around expose events sent to the
4402 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
4403 * window to an offscreen buffer, and gdk_window_end_paint() draws the
4404 * buffer to the screen. The result is that users see the window
4405 * update in one smooth step, and don't see individual graphics
4406 * primitives being rendered.
4408 * In very simple terms, double buffered widgets don't flicker,
4409 * so you would only use this function to turn off double buffering
4410 * if you had special needs and really knew what you were doing.
4412 * Note: if you turn off double-buffering, you have to handle
4413 * expose events, since even the clearing to the background color or
4414 * pixmap will not happen automatically (as it is done in
4415 * gdk_window_begin_paint()).
4419 gtk_widget_set_double_buffered (GtkWidget *widget,
4420 gboolean double_buffered)
4422 g_return_if_fail (GTK_IS_WIDGET (widget));
4424 if (double_buffered)
4425 GTK_WIDGET_SET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
4427 GTK_WIDGET_UNSET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
4431 * gtk_widget_set_redraw_on_allocate:
4432 * @widget: a #GtkWidget
4433 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
4434 * when it is allocated to a new size. Otherwise, only the
4435 * new portion of the widget will be redrawn.
4437 * Sets whether the entire widget is queued for drawing when its size
4438 * allocation changes. By default, this setting is %TRUE and
4439 * the entire widget is redrawn on every size change. If your widget
4440 * leaves the upper left unchanged when made bigger, turning this
4441 * setting on will improve performance.
4443 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
4444 * off all allocation on resizing: the widget will not even redraw if
4445 * its position changes; this is to allow containers that don't draw
4446 * anything to avoid excess invalidations. If you set this flag on a
4447 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
4448 * you are responsible for invalidating both the old and new allocation
4449 * of the widget when the widget is moved and responsible for invalidating
4450 * regions newly when the widget increases size.
4453 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
4454 gboolean redraw_on_allocate)
4456 g_return_if_fail (GTK_IS_WIDGET (widget));
4458 if (redraw_on_allocate)
4459 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
4461 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
4465 * gtk_widget_set_sensitive:
4466 * @widget: a #GtkWidget
4467 * @sensitive: %TRUE to make the widget sensitive
4469 * Sets the sensitivity of a widget. A widget is sensitive if the user
4470 * can interact with it. Insensitive widgets are "grayed out" and the
4471 * user can't interact with them. Insensitive widgets are known as
4472 * "inactive", "disabled", or "ghosted" in some other toolkits.
4476 gtk_widget_set_sensitive (GtkWidget *widget,
4481 g_return_if_fail (GTK_IS_WIDGET (widget));
4483 sensitive = (sensitive != FALSE);
4485 if (sensitive == (GTK_WIDGET_SENSITIVE (widget) != FALSE))
4490 GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE);
4491 data.state = GTK_WIDGET_SAVED_STATE (widget);
4495 GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE);
4496 data.state = GTK_WIDGET_STATE (widget);
4498 data.state_restoration = TRUE;
4499 data.use_forall = TRUE;
4502 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
4504 data.parent_sensitive = TRUE;
4506 gtk_widget_propagate_state (widget, &data);
4507 if (GTK_WIDGET_DRAWABLE (widget))
4508 gtk_widget_queue_draw (widget);
4510 g_object_notify (G_OBJECT (widget), "sensitive");
4514 * gtk_widget_set_parent:
4515 * @widget: a #GtkWidget
4516 * @parent: parent container
4518 * This function is useful only when implementing subclasses of #GtkContainer.
4519 * Sets the container as the parent of @widget, and takes care of
4520 * some details such as updating the state and style of the child
4521 * to reflect its new location. The opposite function is
4522 * gtk_widget_unparent().
4526 gtk_widget_set_parent (GtkWidget *widget,
4531 g_return_if_fail (GTK_IS_WIDGET (widget));
4532 g_return_if_fail (GTK_IS_WIDGET (parent));
4533 g_return_if_fail (widget != parent);
4534 if (widget->parent != NULL)
4536 g_warning ("Can't set a parent on widget which has a parent\n");
4539 if (GTK_WIDGET_TOPLEVEL (widget))
4541 g_warning ("Can't set a parent on a toplevel widget\n");
4545 /* keep this function in sync with gtk_menu_attach_to_widget()
4548 g_object_ref_sink (widget);
4549 widget->parent = parent;
4551 if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
4552 data.state = GTK_WIDGET_STATE (parent);
4554 data.state = GTK_WIDGET_STATE (widget);
4555 data.state_restoration = FALSE;
4556 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (parent) != FALSE);
4557 data.use_forall = GTK_WIDGET_IS_SENSITIVE (parent) != GTK_WIDGET_IS_SENSITIVE (widget);
4559 gtk_widget_propagate_state (widget, &data);
4561 gtk_widget_reset_rc_styles (widget);
4563 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
4564 if (GTK_WIDGET_ANCHORED (widget->parent))
4565 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
4566 g_object_notify (G_OBJECT (widget), "parent");
4568 /* Enforce realized/mapped invariants
4570 if (GTK_WIDGET_REALIZED (widget->parent))
4571 gtk_widget_realize (widget);
4573 if (GTK_WIDGET_VISIBLE (widget->parent) &&
4574 GTK_WIDGET_VISIBLE (widget))
4576 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
4577 GTK_WIDGET_MAPPED (widget->parent))
4578 gtk_widget_map (widget);
4580 gtk_widget_queue_resize (widget);
4585 * gtk_widget_get_parent:
4586 * @widget: a #GtkWidget
4588 * Returns the parent container of @widget.
4590 * Return value: the parent container of @widget, or %NULL
4593 gtk_widget_get_parent (GtkWidget *widget)
4595 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4597 return widget->parent;
4600 /*****************************************
4602 * see docs/styles.txt
4603 *****************************************/
4606 * gtk_widget_set_style:
4607 * @widget: a #GtkWidget
4608 * @style: a #GtkStyle, or %NULL to remove the effect of a previous
4609 * gtk_widget_set_style() and go back to the default style
4611 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
4612 * want to use this function; it interacts badly with themes, because
4613 * themes work by replacing the #GtkStyle. Instead, use
4614 * gtk_widget_modify_style().
4618 gtk_widget_set_style (GtkWidget *widget,
4621 g_return_if_fail (GTK_IS_WIDGET (widget));
4625 gboolean initial_emission;
4627 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
4629 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
4630 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
4632 gtk_widget_set_style_internal (widget, style, initial_emission);
4636 if (GTK_WIDGET_USER_STYLE (widget))
4637 gtk_widget_reset_rc_style (widget);
4642 * gtk_widget_ensure_style:
4643 * @widget: a #GtkWidget
4645 * Ensures that @widget has a style (@widget->style). Not a very useful
4646 * function; most of the time, if you want the style, the widget is
4647 * realized, and realized widgets are guaranteed to have a style
4652 gtk_widget_ensure_style (GtkWidget *widget)
4654 g_return_if_fail (GTK_IS_WIDGET (widget));
4656 if (!GTK_WIDGET_USER_STYLE (widget) &&
4657 !GTK_WIDGET_RC_STYLE (widget))
4658 gtk_widget_reset_rc_style (widget);
4661 /* Look up the RC style for this widget, unsetting any user style that
4662 * may be in effect currently
4665 gtk_widget_reset_rc_style (GtkWidget *widget)
4667 GtkStyle *new_style = NULL;
4668 gboolean initial_emission;
4670 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
4672 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
4673 GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
4675 if (gtk_widget_has_screen (widget))
4676 new_style = gtk_rc_get_style (widget);
4678 new_style = gtk_widget_get_default_style ();
4680 if (initial_emission || new_style != widget->style)
4681 gtk_widget_set_style_internal (widget, new_style, initial_emission);
4685 * gtk_widget_get_style:
4686 * @widget: a #GtkWidget
4688 * Simply an accessor function that returns @widget->style.
4690 * Return value: the widget's #GtkStyle
4693 gtk_widget_get_style (GtkWidget *widget)
4695 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4697 return widget->style;
4701 * gtk_widget_modify_style:
4702 * @widget: a #GtkWidget
4703 * @style: the #GtkRcStyle holding the style modifications
4705 * Modifies style values on the widget. Modifications made using this
4706 * technique take precedence over style values set via an RC file,
4707 * however, they will be overriden if a style is explicitely set on
4708 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
4709 * is designed so each field can either be set or unset, so it is
4710 * possible, using this function, to modify some style values and
4711 * leave the others unchanged.
4713 * Note that modifications made with this function are not cumulative
4714 * with previous calls to gtk_widget_modify_style() or with such
4715 * functions as gtk_widget_modify_fg(). If you wish to retain
4716 * previous values, you must first call gtk_widget_get_modifier_style(),
4717 * make your modifications to the returned style, then call
4718 * gtk_widget_modify_style() with that style. On the other hand,
4719 * if you first call gtk_widget_modify_style(), subsequent calls
4720 * to such functions gtk_widget_modify_fg() will have a cumulative
4721 * effect with the initial modifications.
4724 gtk_widget_modify_style (GtkWidget *widget,
4727 g_return_if_fail (GTK_IS_WIDGET (widget));
4728 g_return_if_fail (GTK_IS_RC_STYLE (style));
4730 g_object_set_qdata_full (G_OBJECT (widget),
4732 gtk_rc_style_copy (style),
4733 (GDestroyNotify) gtk_rc_style_unref);
4735 /* note that "style" may be invalid here if it was the old
4736 * modifier style and the only reference was our own.
4739 if (GTK_WIDGET_RC_STYLE (widget))
4740 gtk_widget_reset_rc_style (widget);
4744 * gtk_widget_get_modifier_style:
4745 * @widget: a #GtkWidget
4747 * Returns the current modifier style for the widget. (As set by
4748 * gtk_widget_modify_style().) If no style has previously set, a new
4749 * #GtkRcStyle will be created with all values unset, and set as the
4750 * modifier style for the widget. If you make changes to this rc
4751 * style, you must call gtk_widget_modify_style(), passing in the
4752 * returned rc style, to make sure that your changes take effect.
4754 * Caution: passing the style back to gtk_widget_modify_style() will
4755 * normally end up destroying it, because gtk_widget_modify_style() copies
4756 * the passed-in style and sets the copy as the new modifier style,
4757 * thus dropping any reference to the old modifier style. Add a reference
4758 * to the modifier style if you want to keep it alive.
4760 * Return value: the modifier style for the widget. This rc style is
4761 * owned by the widget. If you want to keep a pointer to value this
4762 * around, you must add a refcount using gtk_rc_style_ref().
4765 gtk_widget_get_modifier_style (GtkWidget *widget)
4767 GtkRcStyle *rc_style;
4769 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4771 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
4775 rc_style = gtk_rc_style_new ();
4776 g_object_set_qdata_full (G_OBJECT (widget),
4779 (GDestroyNotify) gtk_rc_style_unref);
4786 gtk_widget_modify_color_component (GtkWidget *widget,
4787 GtkRcFlags component,
4789 const GdkColor *color)
4791 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
4798 rc_style->fg[state] = *color;
4801 rc_style->bg[state] = *color;
4804 rc_style->text[state] = *color;
4807 rc_style->base[state] = *color;
4810 g_assert_not_reached();
4813 rc_style->color_flags[state] |= component;
4816 rc_style->color_flags[state] &= ~component;
4818 gtk_widget_modify_style (widget, rc_style);
4822 * gtk_widget_modify_fg:
4823 * @widget: a #GtkWidget.
4824 * @state: the state for which to set the foreground color.
4825 * @color: the color to assign (does not need to be allocated),
4826 * or %NULL to undo the effect of previous calls to
4827 * of gtk_widget_modify_fg().
4829 * Sets the foreground color for a widget in a particular state. All
4830 * other style values are left untouched. See also
4831 * gtk_widget_modify_style().
4834 gtk_widget_modify_fg (GtkWidget *widget,
4836 const GdkColor *color)
4838 g_return_if_fail (GTK_IS_WIDGET (widget));
4839 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4841 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
4845 * gtk_widget_modify_bg:
4846 * @widget: a #GtkWidget.
4847 * @state: the state for which to set the background color.
4848 * @color: the color to assign (does not need to be allocated),
4849 * or %NULL to undo the effect of previous calls to
4850 * of gtk_widget_modify_bg().
4852 * Sets the background color for a widget in a particular state. All
4853 * other style values are left untouched. See also
4854 * gtk_widget_modify_style().
4856 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
4857 * draw on their parent container's window and thus may not draw any background
4858 * themselves. This is the case for e.g. #GtkLabel. To modify the background
4859 * of such widgets, you have to set the background color on their parent; if you want
4860 * to set the background of a rectangular area around a label, try placing the
4861 * label in a #GtkEventBox widget and setting the background color on that.
4864 gtk_widget_modify_bg (GtkWidget *widget,
4866 const GdkColor *color)
4868 g_return_if_fail (GTK_IS_WIDGET (widget));
4869 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4871 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
4875 * gtk_widget_modify_text:
4876 * @widget: a #GtkWidget.
4877 * @state: the state for which to set the text color.
4878 * @color: the color to assign (does not need to be allocated),
4879 * or %NULL to undo the effect of previous calls to
4880 * of gtk_widget_modify_text().
4882 * Sets the text color for a widget in a particular state. All other
4883 * style values are left untouched. The text color is the foreground
4884 * color used along with the base color (see gtk_widget_modify_base())
4885 * for widgets such as #GtkEntry and #GtkTextView. See also
4886 * gtk_widget_modify_style().
4889 gtk_widget_modify_text (GtkWidget *widget,
4891 const GdkColor *color)
4893 g_return_if_fail (GTK_IS_WIDGET (widget));
4894 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4896 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
4900 * gtk_widget_modify_base:
4901 * @widget: a #GtkWidget.
4902 * @state: the state for which to set the base color.
4903 * @color: the color to assign (does not need to be allocated),
4904 * or %NULL to undo the effect of previous calls to
4905 * of gtk_widget_modify_base().
4907 * Sets the base color for a widget in a particular state.
4908 * All other style values are left untouched. The base color
4909 * is the background color used along with the text color
4910 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
4911 * and #GtkTextView. See also gtk_widget_modify_style().
4913 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
4914 * draw on their parent container's window and thus may not draw any background
4915 * themselves. This is the case for e.g. #GtkLabel. To modify the background
4916 * of such widgets, you have to set the base color on their parent; if you want
4917 * to set the background of a rectangular area around a label, try placing the
4918 * label in a #GtkEventBox widget and setting the base color on that.
4921 gtk_widget_modify_base (GtkWidget *widget,
4923 const GdkColor *color)
4925 g_return_if_fail (GTK_IS_WIDGET (widget));
4926 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4928 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
4932 * gtk_widget_modify_font:
4933 * @widget: a #GtkWidget
4934 * @font_desc: the font description to use, or %NULL to undo
4935 * the effect of previous calls to gtk_widget_modify_font().
4937 * Sets the font to use for a widget. All other style values are left
4938 * untouched. See also gtk_widget_modify_style().
4941 gtk_widget_modify_font (GtkWidget *widget,
4942 PangoFontDescription *font_desc)
4944 GtkRcStyle *rc_style;
4946 g_return_if_fail (GTK_IS_WIDGET (widget));
4948 rc_style = gtk_widget_get_modifier_style (widget);
4950 if (rc_style->font_desc)
4951 pango_font_description_free (rc_style->font_desc);
4954 rc_style->font_desc = pango_font_description_copy (font_desc);
4956 rc_style->font_desc = NULL;
4958 gtk_widget_modify_style (widget, rc_style);
4962 gtk_widget_direction_changed (GtkWidget *widget,
4963 GtkTextDirection previous_direction)
4965 gtk_widget_queue_resize (widget);
4969 gtk_widget_style_set (GtkWidget *widget,
4970 GtkStyle *previous_style)
4972 if (GTK_WIDGET_REALIZED (widget) &&
4973 !GTK_WIDGET_NO_WINDOW (widget))
4974 gtk_style_set_background (widget->style, widget->window, widget->state);
4978 gtk_widget_set_style_internal (GtkWidget *widget,
4980 gboolean initial_emission)
4982 g_object_ref (widget);
4983 g_object_freeze_notify (G_OBJECT (widget));
4985 if (widget->style != style)
4987 GtkStyle *previous_style;
4989 if (GTK_WIDGET_REALIZED (widget))
4991 gtk_widget_reset_shapes (widget);
4992 gtk_style_detach (widget->style);
4995 previous_style = widget->style;
4996 widget->style = style;
4997 g_object_ref (widget->style);
4999 if (GTK_WIDGET_REALIZED (widget))
5000 widget->style = gtk_style_attach (widget->style, widget->window);
5002 gtk_widget_update_pango_context (widget);
5003 g_signal_emit (widget,
5004 widget_signals[STYLE_SET],
5006 initial_emission ? NULL : previous_style);
5007 g_object_unref (previous_style);
5009 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
5010 gtk_widget_queue_resize (widget);
5012 else if (initial_emission)
5014 gtk_widget_update_pango_context (widget);
5015 g_signal_emit (widget,
5016 widget_signals[STYLE_SET],
5020 g_object_notify (G_OBJECT (widget), "style");
5021 g_object_thaw_notify (G_OBJECT (widget));
5022 g_object_unref (widget);
5026 GtkWidget *previous_toplevel;
5027 GdkScreen *previous_screen;
5028 GdkScreen *new_screen;
5029 } HierarchyChangedInfo;
5032 do_screen_change (GtkWidget *widget,
5033 GdkScreen *old_screen,
5034 GdkScreen *new_screen)
5036 if (old_screen != new_screen)
5040 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
5042 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
5045 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
5050 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
5051 gpointer client_data)
5053 gboolean new_anchored;
5054 HierarchyChangedInfo *info = client_data;
5056 new_anchored = GTK_WIDGET_TOPLEVEL (widget) ||
5057 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
5059 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
5061 g_object_ref (widget);
5064 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
5066 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
5068 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
5069 do_screen_change (widget, info->previous_screen, info->new_screen);
5071 if (GTK_IS_CONTAINER (widget))
5072 gtk_container_forall (GTK_CONTAINER (widget),
5073 gtk_widget_propagate_hierarchy_changed_recurse,
5076 g_object_unref (widget);
5081 * _gtk_widget_propagate_hierarchy_changed:
5082 * @widget: a #GtkWidget
5083 * @previous_toplevel: Previous toplevel
5085 * Propagates changes in the anchored state to a widget and all
5086 * children, unsetting or setting the %ANCHORED flag, and
5087 * emitting ::hierarchy_changed.
5090 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
5091 GtkWidget *previous_toplevel)
5093 HierarchyChangedInfo info;
5095 info.previous_toplevel = previous_toplevel;
5096 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
5098 if (GTK_WIDGET_TOPLEVEL (widget) ||
5099 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
5100 info.new_screen = gtk_widget_get_screen (widget);
5102 info.new_screen = NULL;
5104 if (info.previous_screen)
5105 g_object_ref (info.previous_screen);
5106 if (previous_toplevel)
5107 g_object_ref (previous_toplevel);
5109 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
5111 if (previous_toplevel)
5112 g_object_unref (previous_toplevel);
5113 if (info.previous_screen)
5114 g_object_unref (info.previous_screen);
5118 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
5119 gpointer client_data)
5121 HierarchyChangedInfo *info = client_data;
5123 g_object_ref (widget);
5125 do_screen_change (widget, info->previous_screen, info->new_screen);
5127 if (GTK_IS_CONTAINER (widget))
5128 gtk_container_forall (GTK_CONTAINER (widget),
5129 gtk_widget_propagate_screen_changed_recurse,
5132 g_object_unref (widget);
5136 * _gtk_widget_propagate_screen_changed:
5137 * @widget: a #GtkWidget
5138 * @previous_screen: Previous screen
5140 * Propagates changes in the screen for a widget to all
5141 * children, emitting ::screen_changed.
5144 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
5145 GdkScreen *previous_screen)
5147 HierarchyChangedInfo info;
5149 info.previous_screen = previous_screen;
5150 info.new_screen = gtk_widget_get_screen (widget);
5152 if (previous_screen)
5153 g_object_ref (previous_screen);
5155 gtk_widget_propagate_screen_changed_recurse (widget, &info);
5157 if (previous_screen)
5158 g_object_unref (previous_screen);
5162 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
5164 if (GTK_WIDGET_RC_STYLE (widget))
5165 gtk_widget_reset_rc_style (widget);
5167 if (GTK_IS_CONTAINER (widget))
5168 gtk_container_forall (GTK_CONTAINER (widget),
5169 reset_rc_styles_recurse,
5174 gtk_widget_reset_rc_styles (GtkWidget *widget)
5176 g_return_if_fail (GTK_IS_WIDGET (widget));
5178 reset_rc_styles_recurse (widget, NULL);
5182 * gtk_widget_get_default_style:
5184 * Returns the default style used by all widgets initially.
5186 * Returns: the default style. This #GtkStyle object is owned by GTK+ and
5187 * should not be modified or freed.
5190 gtk_widget_get_default_style (void)
5192 if (!gtk_default_style)
5194 gtk_default_style = gtk_style_new ();
5195 g_object_ref (gtk_default_style);
5198 return gtk_default_style;
5201 static PangoContext *
5202 gtk_widget_peek_pango_context (GtkWidget *widget)
5204 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
5208 * gtk_widget_get_pango_context:
5209 * @widget: a #GtkWidget
5211 * Gets a #PangoContext with the appropriate colormap, font description
5212 * and base direction for this widget. Unlike the context returned
5213 * by gtk_widget_create_pango_context(), this context is owned by
5214 * the widget (it can be used until the screen for the widget changes
5215 * or the widget is removed from its toplevel), and will be updated to
5216 * match any changes to the widget's attributes.
5218 * If you create and keep a #PangoLayout using this context, you must
5219 * deal with changes to the context by calling pango_layout_context_changed()
5220 * on the layout in response to the ::style-set and ::direction-changed signals
5223 * Return value: the #PangoContext for the widget.
5226 gtk_widget_get_pango_context (GtkWidget *widget)
5228 PangoContext *context;
5230 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5232 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
5235 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
5236 g_object_set_qdata_full (G_OBJECT (widget),
5237 quark_pango_context,
5246 update_pango_context (GtkWidget *widget,
5247 PangoContext *context)
5249 pango_context_set_font_description (context, widget->style->font_desc);
5250 pango_context_set_base_dir (context,
5251 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
5252 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
5256 gtk_widget_update_pango_context (GtkWidget *widget)
5258 PangoContext *context = gtk_widget_peek_pango_context (widget);
5264 update_pango_context (widget, context);
5266 screen = gtk_widget_get_screen_unchecked (widget);
5269 pango_cairo_context_set_resolution (context,
5270 gdk_screen_get_resolution (screen));
5271 pango_cairo_context_set_font_options (context,
5272 gdk_screen_get_font_options (screen));
5278 * gtk_widget_create_pango_context:
5279 * @widget: a #GtkWidget
5281 * Creates a new #PangoContext with the appropriate colormap,
5282 * font description, and base direction for drawing text for
5283 * this widget. See also gtk_widget_get_pango_context().
5285 * Return value: the new #PangoContext
5288 gtk_widget_create_pango_context (GtkWidget *widget)
5291 PangoContext *context;
5293 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5295 screen = gtk_widget_get_screen_unchecked (widget);
5298 GTK_NOTE (MULTIHEAD,
5299 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
5301 screen = gdk_screen_get_default ();
5304 context = gdk_pango_context_get_for_screen (screen);
5306 update_pango_context (widget, context);
5307 pango_context_set_language (context, gtk_get_default_language ());
5313 * gtk_widget_create_pango_layout:
5314 * @widget: a #GtkWidget
5315 * @text: text to set on the layout (can be %NULL)
5317 * Creates a new #PangoLayout with the appropriate colormap,
5318 * font description, and base direction for drawing text for
5321 * If you keep a #PangoLayout created in this way around, in order
5322 * notify the layout of changes to the base direction or font of this
5323 * widget, you must call pango_layout_context_changed() in response to
5324 * the ::style-set and ::direction-changed signals for the widget.
5326 * Return value: the new #PangoLayout
5329 gtk_widget_create_pango_layout (GtkWidget *widget,
5332 PangoLayout *layout;
5333 PangoContext *context;
5335 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5337 context = gtk_widget_get_pango_context (widget);
5338 layout = pango_layout_new (context);
5341 pango_layout_set_text (layout, text, -1);
5347 * gtk_widget_render_icon:
5348 * @widget: a #GtkWidget
5349 * @stock_id: a stock ID
5350 * @size: a stock size. A size of (GtkIconSize)-1 means render at
5351 * the size of the source and don't scale (if there are multiple
5352 * source sizes, GTK+ picks one of the available sizes).
5353 * @detail: render detail to pass to theme engine
5355 * A convenience function that uses the theme engine and RC file
5356 * settings for @widget to look up @stock_id and render it to
5357 * a pixbuf. @stock_id should be a stock icon ID such as
5358 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
5359 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
5360 * identifies the widget or code doing the rendering, so that
5361 * theme engines can special-case rendering for that widget or code.
5363 * The pixels in the returned #GdkPixbuf are shared with the rest of
5364 * the application and should not be modified. The pixbuf should be freed
5365 * after use with g_object_unref().
5367 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
5370 gtk_widget_render_icon (GtkWidget *widget,
5371 const gchar *stock_id,
5373 const gchar *detail)
5375 GtkIconSet *icon_set;
5378 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5379 g_return_val_if_fail (stock_id != NULL, NULL);
5380 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
5382 gtk_widget_ensure_style (widget);
5384 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
5386 if (icon_set == NULL)
5389 retval = gtk_icon_set_render_icon (icon_set,
5391 gtk_widget_get_direction (widget),
5392 GTK_WIDGET_STATE (widget),
5401 * gtk_widget_set_parent_window:
5402 * @widget: a #GtkWidget.
5403 * @parent_window: the new parent window.
5405 * Sets a non default parent window for @widget.
5408 gtk_widget_set_parent_window (GtkWidget *widget,
5409 GdkWindow *parent_window)
5411 GdkWindow *old_parent_window;
5413 g_return_if_fail (GTK_IS_WIDGET (widget));
5415 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
5416 quark_parent_window);
5418 if (parent_window != old_parent_window)
5420 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
5422 if (old_parent_window)
5423 g_object_unref (old_parent_window);
5425 g_object_ref (parent_window);
5431 * gtk_widget_set_child_visible:
5432 * @widget: a #GtkWidget
5433 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
5435 * Sets whether @widget should be mapped along with its when its parent
5436 * is mapped and @widget has been shown with gtk_widget_show().
5438 * The child visibility can be set for widget before it is added to
5439 * a container with gtk_widget_set_parent(), to avoid mapping
5440 * children unnecessary before immediately unmapping them. However
5441 * it will be reset to its default state of %TRUE when the widget
5442 * is removed from a container.
5444 * Note that changing the child visibility of a widget does not
5445 * queue a resize on the widget. Most of the time, the size of
5446 * a widget is computed from all visible children, whether or
5447 * not they are mapped. If this is not the case, the container
5448 * can queue a resize itself.
5450 * This function is only useful for container implementations and
5451 * never should be called by an application.
5454 gtk_widget_set_child_visible (GtkWidget *widget,
5455 gboolean is_visible)
5457 g_return_if_fail (GTK_IS_WIDGET (widget));
5458 g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
5460 g_object_ref (widget);
5463 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
5466 GtkWidget *toplevel;
5468 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
5470 toplevel = gtk_widget_get_toplevel (widget);
5471 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
5472 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
5475 if (widget->parent && GTK_WIDGET_REALIZED (widget->parent))
5477 if (GTK_WIDGET_MAPPED (widget->parent) &&
5478 GTK_WIDGET_CHILD_VISIBLE (widget) &&
5479 GTK_WIDGET_VISIBLE (widget))
5480 gtk_widget_map (widget);
5482 gtk_widget_unmap (widget);
5485 g_object_unref (widget);
5489 * gtk_widget_get_child_visible:
5490 * @widget: a #GtkWidget
5492 * Gets the value set with gtk_widget_set_child_visible().
5493 * If you feel a need to use this function, your code probably
5494 * needs reorganization.
5496 * This function is only useful for container implementations and
5497 * never should be called by an application.
5499 * Return value: %TRUE if the widget is mapped with the parent.
5502 gtk_widget_get_child_visible (GtkWidget *widget)
5504 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5506 return GTK_WIDGET_CHILD_VISIBLE (widget);
5510 gtk_widget_get_screen_unchecked (GtkWidget *widget)
5512 GtkWidget *toplevel;
5514 toplevel = gtk_widget_get_toplevel (widget);
5516 if (GTK_WIDGET_TOPLEVEL (toplevel))
5518 if (GTK_IS_WINDOW (toplevel))
5519 return GTK_WINDOW (toplevel)->screen;
5520 else if (GTK_IS_INVISIBLE (toplevel))
5521 return GTK_INVISIBLE (widget)->screen;
5528 * gtk_widget_get_screen:
5529 * @widget: a #GtkWidget
5531 * Get the #GdkScreen from the toplevel window associated with
5532 * this widget. This function can only be called after the widget
5533 * has been added to a widget hierarchy with a #GtkWindow
5536 * In general, you should only create screen specific
5537 * resources when a widget has been realized, and you should
5538 * free those resources when the widget is unrealized.
5540 * Return value: the #GdkScreen for the toplevel for this widget.
5545 gtk_widget_get_screen (GtkWidget *widget)
5549 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5551 screen = gtk_widget_get_screen_unchecked (widget);
5558 g_warning (G_STRLOC ": Can't get associated screen"
5559 " for a widget unless it is inside a toplevel GtkWindow\n"
5560 " widget type is %s associated top level type is %s",
5561 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
5562 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
5564 return gdk_screen_get_default ();
5569 * gtk_widget_has_screen:
5570 * @widget: a #GtkWidget
5572 * Checks whether there is a #GdkScreen is associated with
5573 * this widget. All toplevel widgets have an associated
5574 * screen, and all widgets added into a heirarchy with a toplevel
5575 * window at the top.
5577 * Return value: %TRUE if there is a #GdkScreen associcated
5583 gtk_widget_has_screen (GtkWidget *widget)
5585 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5587 return (gtk_widget_get_screen_unchecked (widget) != NULL);
5591 * gtk_widget_get_display:
5592 * @widget: a #GtkWidget
5594 * Get the #GdkDisplay for the toplevel window associated with
5595 * this widget. This function can only be called after the widget
5596 * has been added to a widget hierarchy with a #GtkWindow at the top.
5598 * In general, you should only create display specific
5599 * resources when a widget has been realized, and you should
5600 * free those resources when the widget is unrealized.
5602 * Return value: the #GdkDisplay for the toplevel for this widget.
5607 gtk_widget_get_display (GtkWidget *widget)
5609 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5611 return gdk_screen_get_display (gtk_widget_get_screen (widget));
5615 * gtk_widget_get_root_window:
5616 * @widget: a #GtkWidget
5618 * Get the root window where this widget is located. This function can
5619 * only be called after the widget has been added to a widget
5620 * heirarchy with #GtkWindow at the top.
5622 * The root window is useful for such purposes as creating a popup
5623 * #GdkWindow associated with the window. In general, you should only
5624 * create display specific resources when a widget has been realized,
5625 * and you should free those resources when the widget is unrealized.
5627 * Return value: the #GdkWindow root window for the toplevel for this widget.
5632 gtk_widget_get_root_window (GtkWidget *widget)
5634 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5636 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
5640 * gtk_widget_get_parent_window:
5641 * @widget: a #GtkWidget.
5642 * @returns: the parent window of @widget.
5644 * Gets @widget's parent window.
5647 gtk_widget_get_parent_window (GtkWidget *widget)
5649 GdkWindow *parent_window;
5651 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5652 g_return_val_if_fail (widget->parent != NULL, NULL);
5654 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
5656 return (parent_window != NULL) ? parent_window : widget->parent->window;
5660 * gtk_widget_child_focus:
5661 * @widget: a #GtkWidget
5662 * @direction: direction of focus movement
5664 * This function is used by custom widget implementations; if you're
5665 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
5666 * to a particular widget, and gtk_container_set_focus_chain() to
5667 * change the focus tab order. So you may want to investigate those
5668 * functions instead.
5670 * gtk_widget_child_focus() is called by containers as the user moves
5671 * around the window using keyboard shortcuts. @direction indicates
5672 * what kind of motion is taking place (up, down, left, right, tab
5673 * forward, tab backward). gtk_widget_child_focus() invokes the
5674 * "focus" signal on #GtkWidget; widgets override the default handler
5675 * for this signal in order to implement appropriate focus behavior.
5677 * The "focus" default handler for a widget should return %TRUE if
5678 * moving in @direction left the focus on a focusable location inside
5679 * that widget, and %FALSE if moving in @direction moved the focus
5680 * outside the widget. If returning %TRUE, widgets normally
5681 * call gtk_widget_grab_focus() to place the focus accordingly;
5682 * if returning %FALSE, they don't modify the current focus location.
5684 * This function replaces gtk_container_focus() from GTK+ 1.2. It was
5685 * necessary to check that the child was visible, sensitive, and
5686 * focusable before calling
5687 * gtk_container_focus(). gtk_widget_child_focus() returns %FALSE if
5688 * the widget is not currently in a focusable state, so there's no
5689 * need for those checks.
5691 * Return value: %TRUE if focus ended up inside @widget
5694 gtk_widget_child_focus (GtkWidget *widget,
5695 GtkDirectionType direction)
5697 gboolean return_val;
5699 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5701 if (!GTK_WIDGET_VISIBLE (widget) ||
5702 !GTK_WIDGET_IS_SENSITIVE (widget))
5705 /* child widgets must set CAN_FOCUS, containers
5706 * don't have to though.
5708 if (!GTK_IS_CONTAINER (widget) &&
5709 !GTK_WIDGET_CAN_FOCUS (widget))
5712 g_signal_emit (widget,
5713 widget_signals[FOCUS],
5715 direction, &return_val);
5721 * gtk_widget_set_uposition:
5722 * @widget: a #GtkWidget
5723 * @x: x position; -1 to unset x; -2 to leave x unchanged
5724 * @y: y position; -1 to unset y; -2 to leave y unchanged
5727 * Sets the position of a widget. The funny "u" in the name comes from
5728 * the "user position" hint specified by the X Window System, and
5729 * exists for legacy reasons. This function doesn't work if a widget
5730 * is inside a container; it's only really useful on #GtkWindow.
5732 * Don't use this function to center dialogs over the main application
5733 * window; most window managers will do the centering on your behalf
5734 * if you call gtk_window_set_transient_for(), and it's really not
5735 * possible to get the centering to work correctly in all cases from
5736 * application code. But if you insist, use gtk_window_set_position()
5737 * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
5740 * Note that although @x and @y can be individually unset, the position
5741 * is not honoured unless both @x and @y are set.
5744 gtk_widget_set_uposition (GtkWidget *widget,
5748 /* FIXME this function is the only place that aux_info->x and
5749 * aux_info->y are even used I believe, and this function is
5750 * deprecated. Should be cleaned up.
5752 * (Actually, size_allocate uses them) -Yosh
5755 GtkWidgetAuxInfo *aux_info;
5757 g_return_if_fail (GTK_IS_WIDGET (widget));
5759 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
5764 aux_info->x_set = FALSE;
5767 aux_info->x_set = TRUE;
5775 aux_info->y_set = FALSE;
5778 aux_info->y_set = TRUE;
5783 if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
5784 _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
5786 if (GTK_WIDGET_VISIBLE (widget) && widget->parent)
5787 gtk_widget_size_allocate (widget, &widget->allocation);
5791 gtk_widget_set_usize_internal (GtkWidget *widget,
5795 GtkWidgetAuxInfo *aux_info;
5796 gboolean changed = FALSE;
5798 g_object_freeze_notify (G_OBJECT (widget));
5800 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
5802 if (width > -2 && aux_info->width != width)
5804 g_object_notify (G_OBJECT (widget), "width-request");
5805 aux_info->width = width;
5808 if (height > -2 && aux_info->height != height)
5810 g_object_notify (G_OBJECT (widget), "height-request");
5811 aux_info->height = height;
5815 if (GTK_WIDGET_VISIBLE (widget) && changed)
5816 gtk_widget_queue_resize (widget);
5818 g_object_thaw_notify (G_OBJECT (widget));
5822 * gtk_widget_set_usize:
5823 * @widget: a #GtkWidget
5824 * @width: minimum width, or -1 to unset
5825 * @height: minimum height, or -1 to unset
5827 * Sets the minimum size of a widget; that is, the widget's size
5828 * request will be @width by @height. You can use this function to
5829 * force a widget to be either larger or smaller than it is. The
5830 * strange "usize" name dates from the early days of GTK+, and derives
5831 * from X Window System terminology. In many cases,
5832 * gtk_window_set_default_size() is a better choice for toplevel
5833 * windows than this function; setting the default size will still
5834 * allow users to shrink the window. Setting the usize will force them
5835 * to leave the window at least as large as the usize. When dealing
5836 * with window sizes, gtk_window_set_geometry_hints() can be a useful
5839 * Note the inherent danger of setting any fixed size - themes,
5840 * translations into other languages, different fonts, and user action
5841 * can all change the appropriate size for a given widget. So, it's
5842 * basically impossible to hardcode a size that will always be
5845 * @Deprecated: Use gtk_widget_set_size_request() instead.
5848 gtk_widget_set_usize (GtkWidget *widget,
5852 g_return_if_fail (GTK_IS_WIDGET (widget));
5854 gtk_widget_set_usize_internal (widget, width, height);
5858 * gtk_widget_set_size_request:
5859 * @widget: a #GtkWidget
5860 * @width: width @widget should request, or -1 to unset
5861 * @height: height @widget should request, or -1 to unset
5863 * Sets the minimum size of a widget; that is, the widget's size
5864 * request will be @width by @height. You can use this function to
5865 * force a widget to be either larger or smaller than it normally
5868 * In most cases, gtk_window_set_default_size() is a better choice for
5869 * toplevel windows than this function; setting the default size will
5870 * still allow users to shrink the window. Setting the size request
5871 * will force them to leave the window at least as large as the size
5872 * request. When dealing with window sizes,
5873 * gtk_window_set_geometry_hints() can be a useful function as well.
5875 * Note the inherent danger of setting any fixed size - themes,
5876 * translations into other languages, different fonts, and user action
5877 * can all change the appropriate size for a given widget. So, it's
5878 * basically impossible to hardcode a size that will always be
5881 * The size request of a widget is the smallest size a widget can
5882 * accept while still functioning well and drawing itself correctly.
5883 * However in some strange cases a widget may be allocated less than
5884 * its requested size, and in many cases a widget may be allocated more
5885 * space than it requested.
5887 * If the size request in a given direction is -1 (unset), then
5888 * the "natural" size request of the widget will be used instead.
5890 * Widgets can't actually be allocated a size less than 1 by 1, but
5891 * you can pass 0,0 to this function to mean "as small as possible."
5894 gtk_widget_set_size_request (GtkWidget *widget,
5898 g_return_if_fail (GTK_IS_WIDGET (widget));
5899 g_return_if_fail (width >= -1);
5900 g_return_if_fail (height >= -1);
5907 gtk_widget_set_usize_internal (widget, width, height);
5912 * gtk_widget_get_size_request:
5913 * @widget: a #GtkWidget
5914 * @width: return location for width, or %NULL
5915 * @height: return location for height, or %NULL
5917 * Gets the size request that was explicitly set for the widget using
5918 * gtk_widget_set_size_request(). A value of -1 stored in @width or
5919 * @height indicates that that dimension has not been set explicitly
5920 * and the natural requisition of the widget will be used intead. See
5921 * gtk_widget_set_size_request(). To get the size a widget will
5922 * actually use, call gtk_widget_size_request() instead of
5926 gtk_widget_get_size_request (GtkWidget *widget,
5930 GtkWidgetAuxInfo *aux_info;
5932 g_return_if_fail (GTK_IS_WIDGET (widget));
5934 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
5937 *width = aux_info ? aux_info->width : -1;
5940 *height = aux_info ? aux_info->height : -1;
5944 * gtk_widget_set_events:
5945 * @widget: a #GtkWidget
5946 * @events: event mask
5948 * Sets the event mask (see #GdkEventMask) for a widget. The event
5949 * mask determines which events a widget will receive. Keep in mind
5950 * that different widgets have different default event masks, and by
5951 * changing the event mask you may disrupt a widget's functionality,
5952 * so be careful. This function must be called while a widget is
5953 * unrealized. Consider gtk_widget_add_events() for widgets that are
5954 * already realized, or if you want to preserve the existing event
5955 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
5956 * to get events on those widgets, place them inside a #GtkEventBox
5957 * and receive events on the event box.
5960 gtk_widget_set_events (GtkWidget *widget,
5965 g_return_if_fail (GTK_IS_WIDGET (widget));
5966 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
5968 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
5973 eventp = g_slice_new (gint);
5976 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, eventp);
5980 g_slice_free (gint, eventp);
5981 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, NULL);
5984 g_object_notify (G_OBJECT (widget), "events");
5988 gtk_widget_add_events_internal (GtkWidget *widget,
5994 for (l = window_list; l != NULL; l = l->next)
5996 GdkWindow *window = l->data;
5999 gdk_window_get_user_data (window, &user_data);
6000 if (user_data == widget)
6004 gdk_window_set_events (window, gdk_window_get_events (window) | events);
6006 children = gdk_window_get_children (window);
6007 gtk_widget_add_events_internal (widget, events, children);
6008 g_list_free (children);
6014 * gtk_widget_add_events:
6015 * @widget: a #GtkWidget
6016 * @events: an event mask, see #GdkEventMask
6018 * Adds the events in the bitfield @events to the event mask for
6019 * @widget. See gtk_widget_set_events() for details.
6023 gtk_widget_add_events (GtkWidget *widget,
6028 g_return_if_fail (GTK_IS_WIDGET (widget));
6030 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
6036 eventp = g_slice_new (gint);
6041 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, eventp);
6045 g_slice_free (gint, eventp);
6046 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, NULL);
6049 if (GTK_WIDGET_REALIZED (widget))
6053 if (GTK_WIDGET_NO_WINDOW (widget))
6054 window_list = gdk_window_get_children (widget->window);
6056 window_list = g_list_prepend (NULL, widget->window);
6058 gtk_widget_add_events_internal (widget, events, window_list);
6060 g_list_free (window_list);
6063 g_object_notify (G_OBJECT (widget), "events");
6067 * gtk_widget_set_extension_events:
6068 * @widget: a #GtkWidget
6069 * @mode: bitfield of extension events to receive
6071 * Sets the extension events mask to @mode. See #GdkExtensionMode
6072 * and gdk_input_set_extension_events().
6076 gtk_widget_set_extension_events (GtkWidget *widget,
6077 GdkExtensionMode mode)
6079 GdkExtensionMode *modep;
6081 g_return_if_fail (GTK_IS_WIDGET (widget));
6083 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
6086 modep = g_slice_new (GdkExtensionMode);
6089 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode, modep);
6090 g_object_notify (G_OBJECT (widget), "extension-events");
6094 * gtk_widget_get_toplevel:
6095 * @widget: a #GtkWidget
6097 * This function returns the topmost widget in the container hierarchy
6098 * @widget is a part of. If @widget has no parent widgets, it will be
6099 * returned as the topmost widget. No reference will be added to the
6100 * returned widget; it should not be unreferenced.
6102 * Note the difference in behavior vs. gtk_widget_get_ancestor();
6103 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
6105 * %NULL if @widget wasn't inside a toplevel window, and if the
6106 * window was inside a #GtkWindow-derived widget which was in turn
6107 * inside the toplevel #GtkWindow. While the second case may
6108 * seem unlikely, it actually happens when a #GtkPlug is embedded
6109 * inside a #GtkSocket within the same application.
6111 * To reliably find the toplevel #GtkWindow, use
6112 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
6113 * is set on the result.
6114 * <informalexample><programlisting>
6115 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6116 * if (GTK_WIDGET_TOPLEVEL (toplevel))
6118 * [ Perform action on toplevel. ]
6120 * </programlisting></informalexample>
6122 * Return value: the topmost ancestor of @widget, or @widget itself if there's no ancestor.
6125 gtk_widget_get_toplevel (GtkWidget *widget)
6127 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6129 while (widget->parent)
6130 widget = widget->parent;
6136 * gtk_widget_get_ancestor:
6137 * @widget: a #GtkWidget
6138 * @widget_type: ancestor type
6140 * Gets the first ancestor of @widget with type @widget_type. For example,
6141 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets the
6142 * first #GtkBox that's
6143 * an ancestor of @widget. No reference will be added to the returned widget;
6144 * it should not be unreferenced. See note about checking for a toplevel
6145 * #GtkWindow in the docs for gtk_widget_get_toplevel().
6147 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
6148 * considers @widget to be an ancestor of itself.
6150 * Return value: the ancestor widget, or %NULL if not found
6153 gtk_widget_get_ancestor (GtkWidget *widget,
6156 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6158 while (widget && !g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))
6159 widget = widget->parent;
6161 if (!(widget && g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)))
6168 * gtk_widget_get_colormap:
6169 * @widget: a #GtkWidget
6171 * Gets the colormap that will be used to render @widget. No reference will
6172 * be added to the returned colormap; it should not be unreferenced.
6174 * Return value: the colormap used by @widget
6177 gtk_widget_get_colormap (GtkWidget *widget)
6179 GdkColormap *colormap;
6180 GtkWidget *tmp_widget;
6182 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6186 colormap = gdk_drawable_get_colormap (widget->window);
6187 /* If window was destroyed previously, we'll get NULL here */
6192 tmp_widget = widget;
6195 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
6199 tmp_widget= tmp_widget->parent;
6202 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
6206 * gtk_widget_get_visual:
6207 * @widget: a #GtkWidget
6209 * Gets the visual that will be used to render @widget.
6211 * Return value: the visual for @widget
6214 gtk_widget_get_visual (GtkWidget *widget)
6216 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6218 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
6222 * gtk_widget_get_settings:
6223 * @widget: a #GtkWidget
6225 * Gets the settings object holding the settings (global property
6226 * settings, RC file information, etc) used for this widget.
6228 * Note that this function can only be called when the #GtkWidget
6229 * is attached to a toplevel, since the settings object is specific
6230 * to a particular #GdkScreen.
6232 * Return value: the relevant #GtkSettings object
6235 gtk_widget_get_settings (GtkWidget *widget)
6237 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6239 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
6243 * gtk_widget_set_colormap:
6244 * @widget: a #GtkWidget
6245 * @colormap: a colormap
6247 * Sets the colormap for the widget to the given value. Widget must not
6248 * have been previously realized. This probably should only be used
6249 * from an <function>init()</function> function (i.e. from the constructor
6254 gtk_widget_set_colormap (GtkWidget *widget,
6255 GdkColormap *colormap)
6257 g_return_if_fail (GTK_IS_WIDGET (widget));
6258 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
6259 g_return_if_fail (GDK_IS_COLORMAP (colormap));
6261 g_object_ref (colormap);
6263 g_object_set_qdata_full (G_OBJECT (widget),
6270 * gtk_widget_get_events:
6271 * @widget: a #GtkWidget
6273 * Returns the event mask for the widget (a bitfield containing flags
6274 * from the #GdkEventMask enumeration). These are the events that the widget
6277 * Return value: event mask for @widget
6280 gtk_widget_get_events (GtkWidget *widget)
6284 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
6286 events = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
6294 * gtk_widget_get_extension_events:
6295 * @widget: a #GtkWidget
6297 * Retrieves the extension events the widget will receive; see
6298 * gdk_input_set_extension_events().
6300 * Return value: extension events for @widget
6303 gtk_widget_get_extension_events (GtkWidget *widget)
6305 GdkExtensionMode *mode;
6307 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
6309 mode = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
6317 * gtk_widget_get_pointer:
6318 * @widget: a #GtkWidget
6319 * @x: return location for the X coordinate, or %NULL
6320 * @y: return location for the Y coordinate, or %NULL
6322 * Obtains the location of the mouse pointer in widget coordinates.
6323 * Widget coordinates are a bit odd; for historical reasons, they are
6324 * defined as @widget->window coordinates for widgets that are not
6325 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
6326 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
6330 gtk_widget_get_pointer (GtkWidget *widget,
6334 g_return_if_fail (GTK_IS_WIDGET (widget));
6341 if (GTK_WIDGET_REALIZED (widget))
6343 gdk_window_get_pointer (widget->window, x, y, NULL);
6345 if (GTK_WIDGET_NO_WINDOW (widget))
6348 *x -= widget->allocation.x;
6350 *y -= widget->allocation.y;
6356 * gtk_widget_is_ancestor:
6357 * @widget: a #GtkWidget
6358 * @ancestor: another #GtkWidget
6360 * Determines whether @widget is somewhere inside @ancestor, possibly with
6361 * intermediate containers.
6363 * Return value: %TRUE if @ancestor contains @widget as a child, grandchild, great grandchild, etc.
6366 gtk_widget_is_ancestor (GtkWidget *widget,
6367 GtkWidget *ancestor)
6369 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6370 g_return_val_if_fail (ancestor != NULL, FALSE);
6374 if (widget->parent == ancestor)
6376 widget = widget->parent;
6382 static GQuark quark_composite_name = 0;
6385 * gtk_widget_set_composite_name:
6386 * @widget: a #GtkWidget.
6387 * @name: the name to set.
6389 * Sets a widgets composite name. The widget must be
6390 * a composite child of its parent; see gtk_widget_push_composite_child().
6393 gtk_widget_set_composite_name (GtkWidget *widget,
6396 g_return_if_fail (GTK_IS_WIDGET (widget));
6397 g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget));
6398 g_return_if_fail (name != NULL);
6400 if (!quark_composite_name)
6401 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
6403 g_object_set_qdata_full (G_OBJECT (widget),
6404 quark_composite_name,
6410 * gtk_widget_get_composite_name:
6411 * @widget: a #GtkWidget.
6412 * @returns: the composite name of @widget, or %NULL if @widget is not
6413 * a composite child. The string should not be freed when it is no
6416 * Obtains the composite name of a widget.
6419 gtk_widget_get_composite_name (GtkWidget *widget)
6421 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6423 if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent)
6424 return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
6431 * gtk_widget_push_composite_child:
6433 * Makes all newly-created widgets as composite children until
6434 * the corresponding gtk_widget_pop_composite_child() call.
6436 * A composite child is a child that's an implementation detail of the
6437 * container it's inside and should not be visible to people using the
6438 * container. Composite children aren't treated differently by GTK (but
6439 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
6440 * builders might want to treat them in a different way.
6442 * Here is a simple example:
6443 * <informalexample><programlisting>
6444 * gtk_widget_push_composite_child (<!-- -->);
6445 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
6446 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
6447 * gtk_widget_pop_composite_child (<!-- -->);
6448 * gtk_widget_set_parent (scrolled_window->hscrollbar,
6449 * GTK_WIDGET (scrolled_window));
6450 * g_object_ref (scrolled_window->hscrollbar);
6451 * </programlisting></informalexample>
6454 gtk_widget_push_composite_child (void)
6456 composite_child_stack++;
6460 * gtk_widget_pop_composite_child:
6462 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
6465 gtk_widget_pop_composite_child (void)
6467 if (composite_child_stack)
6468 composite_child_stack--;
6472 * gtk_widget_push_colormap:
6473 * @cmap: a #GdkColormap
6475 * Pushes @cmap onto a global stack of colormaps; the topmost
6476 * colormap on the stack will be used to create all widgets.
6477 * Remove @cmap with gtk_widget_pop_colormap(). There's little
6478 * reason to use this function.
6482 gtk_widget_push_colormap (GdkColormap *cmap)
6484 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
6486 colormap_stack = g_slist_prepend (colormap_stack, cmap);
6490 * gtk_widget_pop_colormap:
6492 * Removes a colormap pushed with gtk_widget_push_colormap().
6496 gtk_widget_pop_colormap (void)
6499 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
6503 * gtk_widget_set_default_colormap:
6504 * @colormap: a #GdkColormap
6506 * Sets the default colormap to use when creating widgets.
6507 * gtk_widget_push_colormap() is a better function to use if
6508 * you only want to affect a few widgets, rather than all widgets.
6511 gtk_widget_set_default_colormap (GdkColormap *colormap)
6513 g_return_if_fail (GDK_IS_COLORMAP (colormap));
6515 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
6520 * gtk_widget_get_default_colormap:
6522 * Obtains the default colormap used to create widgets.
6524 * Return value: default widget colormap
6527 gtk_widget_get_default_colormap (void)
6529 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
6533 * gtk_widget_get_default_visual:
6535 * Obtains the visual of the default colormap. Not really useful;
6536 * used to be useful before gdk_colormap_get_visual() existed.
6538 * Return value: visual of the default colormap
6541 gtk_widget_get_default_visual (void)
6543 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
6547 gtk_widget_emit_direction_changed (GtkWidget *widget,
6548 GtkTextDirection old_dir)
6550 gtk_widget_update_pango_context (widget);
6552 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
6556 * gtk_widget_set_direction:
6557 * @widget: a #GtkWidget
6558 * @dir: the new direction
6560 * Sets the reading direction on a particular widget. This direction
6561 * controls the primary direction for widgets containing text,
6562 * and also the direction in which the children of a container are
6563 * packed. The ability to set the direction is present in order
6564 * so that correct localization into languages with right-to-left
6565 * reading directions can be done. Generally, applications will
6566 * let the default reading direction present, except for containers
6567 * where the containers are arranged in an order that is explicitely
6568 * visual rather than logical (such as buttons for text justification).
6570 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
6571 * set by gtk_widget_set_default_direction() will be used.
6574 gtk_widget_set_direction (GtkWidget *widget,
6575 GtkTextDirection dir)
6577 GtkTextDirection old_dir;
6579 g_return_if_fail (GTK_IS_WIDGET (widget));
6580 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
6582 old_dir = gtk_widget_get_direction (widget);
6584 if (dir == GTK_TEXT_DIR_NONE)
6585 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
6588 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
6589 if (dir == GTK_TEXT_DIR_LTR)
6590 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
6592 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
6595 if (old_dir != gtk_widget_get_direction (widget))
6596 gtk_widget_emit_direction_changed (widget, old_dir);
6600 * gtk_widget_get_direction:
6601 * @widget: a #GtkWidget
6603 * Gets the reading direction for a particular widget. See
6604 * gtk_widget_set_direction().
6606 * Return value: the reading direction for the widget.
6609 gtk_widget_get_direction (GtkWidget *widget)
6611 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
6613 if (GTK_WIDGET_DIRECTION_SET (widget))
6614 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
6616 return gtk_default_direction;
6620 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
6622 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
6624 g_object_ref (widget);
6626 if (!GTK_WIDGET_DIRECTION_SET (widget))
6627 gtk_widget_emit_direction_changed (widget, old_dir);
6629 if (GTK_IS_CONTAINER (widget))
6630 gtk_container_forall (GTK_CONTAINER (widget),
6631 gtk_widget_set_default_direction_recurse,
6634 g_object_unref (widget);
6638 * gtk_widget_set_default_direction:
6639 * @dir: the new default direction. This cannot be
6640 * %GTK_TEXT_DIR_NONE.
6642 * Sets the default reading direction for widgets where the
6643 * direction has not been explicitly set by gtk_widget_set_direction().
6646 gtk_widget_set_default_direction (GtkTextDirection dir)
6648 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
6650 if (dir != gtk_default_direction)
6652 GList *toplevels, *tmp_list;
6653 GtkTextDirection old_dir = gtk_default_direction;
6655 gtk_default_direction = dir;
6657 tmp_list = toplevels = gtk_window_list_toplevels ();
6658 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
6662 gtk_widget_set_default_direction_recurse (tmp_list->data,
6663 GUINT_TO_POINTER (old_dir));
6664 g_object_unref (tmp_list->data);
6665 tmp_list = tmp_list->next;
6668 g_list_free (toplevels);
6673 * gtk_widget_get_default_direction:
6675 * Obtains the current default reading direction. See
6676 * gtk_widget_set_default_direction().
6678 * Return value: the current default direction.
6681 gtk_widget_get_default_direction (void)
6683 return gtk_default_direction;
6687 gtk_widget_dispose (GObject *object)
6689 GtkWidget *widget = GTK_WIDGET (object);
6692 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
6693 else if (GTK_WIDGET_VISIBLE (widget))
6694 gtk_widget_hide (widget);
6696 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
6697 if (GTK_WIDGET_REALIZED (widget))
6698 gtk_widget_unrealize (widget);
6700 G_OBJECT_CLASS (parent_class)->dispose (object);
6704 gtk_widget_real_destroy (GtkObject *object)
6706 /* gtk_object_destroy() will already hold a refcount on object */
6707 GtkWidget *widget = GTK_WIDGET (object);
6709 /* wipe accelerator closures (keep order) */
6710 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
6711 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
6713 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
6714 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
6716 gtk_grab_remove (widget);
6718 g_object_unref (widget->style);
6719 widget->style = gtk_widget_get_default_style ();
6720 g_object_ref (widget->style);
6722 GTK_OBJECT_CLASS (parent_class)->destroy (object);
6726 gtk_widget_finalize (GObject *object)
6728 GtkWidget *widget = GTK_WIDGET (object);
6729 GtkWidgetAuxInfo *aux_info;
6731 GdkExtensionMode *mode;
6732 GtkAccessible *accessible;
6734 gtk_grab_remove (widget);
6736 g_object_unref (widget->style);
6737 widget->style = NULL;
6740 g_free (widget->name);
6742 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
6744 gtk_widget_aux_info_destroy (aux_info);
6746 events = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
6748 g_slice_free (gint, events);
6750 mode = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
6752 g_slice_free (GdkExtensionMode, mode);
6754 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
6756 g_object_unref (accessible);
6758 G_OBJECT_CLASS (parent_class)->finalize (object);
6761 /*****************************************
6762 * gtk_widget_real_map:
6767 *****************************************/
6770 gtk_widget_real_map (GtkWidget *widget)
6772 g_assert (GTK_WIDGET_REALIZED (widget));
6774 if (!GTK_WIDGET_MAPPED (widget))
6776 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
6778 if (!GTK_WIDGET_NO_WINDOW (widget))
6779 gdk_window_show (widget->window);
6783 /*****************************************
6784 * gtk_widget_real_unmap:
6789 *****************************************/
6792 gtk_widget_real_unmap (GtkWidget *widget)
6794 if (GTK_WIDGET_MAPPED (widget))
6796 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
6798 if (!GTK_WIDGET_NO_WINDOW (widget))
6799 gdk_window_hide (widget->window);
6803 /*****************************************
6804 * gtk_widget_real_realize:
6809 *****************************************/
6812 gtk_widget_real_realize (GtkWidget *widget)
6814 g_assert (GTK_WIDGET_NO_WINDOW (widget));
6816 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
6819 widget->window = gtk_widget_get_parent_window (widget);
6820 g_object_ref (widget->window);
6822 widget->style = gtk_style_attach (widget->style, widget->window);
6825 /*****************************************
6826 * gtk_widget_real_unrealize:
6831 *****************************************/
6834 gtk_widget_real_unrealize (GtkWidget *widget)
6836 if (GTK_WIDGET_MAPPED (widget))
6837 gtk_widget_real_unmap (widget);
6839 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
6841 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
6844 /* We must do unrealize child widget BEFORE container widget.
6845 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
6846 * So, unrealizing container widget bofore its children causes the problem
6847 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
6850 if (GTK_IS_CONTAINER (widget))
6851 gtk_container_forall (GTK_CONTAINER (widget),
6852 (GtkCallback) gtk_widget_unrealize,
6855 gtk_style_detach (widget->style);
6856 if (!GTK_WIDGET_NO_WINDOW (widget))
6858 gdk_window_set_user_data (widget->window, NULL);
6859 gdk_window_destroy (widget->window);
6860 widget->window = NULL;
6864 g_object_unref (widget->window);
6865 widget->window = NULL;
6868 gtk_selection_remove_all (widget);
6870 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
6874 gtk_widget_real_size_request (GtkWidget *widget,
6875 GtkRequisition *requisition)
6877 requisition->width = widget->requisition.width;
6878 requisition->height = widget->requisition.height;
6882 * _gtk_widget_peek_colormap:
6884 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
6886 * Return value: the currently pushed colormap, or %NULL if there is none.
6889 _gtk_widget_peek_colormap (void)
6892 return (GdkColormap*) colormap_stack->data;
6897 gtk_widget_propagate_state (GtkWidget *widget,
6902 /* don't call this function with state==GTK_STATE_INSENSITIVE,
6903 * parent_sensitive==TRUE on a sensitive widget
6906 old_state = GTK_WIDGET_STATE (widget);
6908 if (data->parent_sensitive)
6910 GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
6912 if (GTK_WIDGET_IS_SENSITIVE (widget))
6914 if (data->state_restoration)
6915 GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget);
6917 GTK_WIDGET_STATE (widget) = data->state;
6921 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
6922 if (!data->state_restoration &&
6923 data->state != GTK_STATE_INSENSITIVE)
6924 GTK_WIDGET_SAVED_STATE (widget) = data->state;
6929 GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
6930 if (!data->state_restoration)
6932 if (data->state != GTK_STATE_INSENSITIVE)
6933 GTK_WIDGET_SAVED_STATE (widget) = data->state;
6935 else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
6936 GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget);
6937 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
6940 if (gtk_widget_is_focus (widget) && !GTK_WIDGET_IS_SENSITIVE (widget))
6944 window = gtk_widget_get_toplevel (widget);
6945 if (window && GTK_WIDGET_TOPLEVEL (window))
6946 gtk_window_set_focus (GTK_WINDOW (window), NULL);
6949 if (old_state != GTK_WIDGET_STATE (widget))
6951 g_object_ref (widget);
6953 if (!GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_HAS_GRAB (widget))
6954 gtk_grab_remove (widget);
6956 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
6958 if (GTK_IS_CONTAINER (widget))
6960 data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE);
6961 data->state = GTK_WIDGET_STATE (widget);
6962 if (data->use_forall)
6963 gtk_container_forall (GTK_CONTAINER (widget),
6964 (GtkCallback) gtk_widget_propagate_state,
6967 gtk_container_foreach (GTK_CONTAINER (widget),
6968 (GtkCallback) gtk_widget_propagate_state,
6971 g_object_unref (widget);
6976 * _gtk_widget_get_aux_info:
6977 * @widget: a #GtkWidget
6978 * @create: if %TRUE, create the structure if it doesn't exist
6980 * Get the #GtkWidgetAuxInfo structure for the widget.
6982 * Return value: the #GtkAuxInfo structure for the widget, or
6983 * %NULL if @create is %FALSE and one doesn't already exist.
6986 _gtk_widget_get_aux_info (GtkWidget *widget,
6989 GtkWidgetAuxInfo *aux_info;
6991 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
6992 if (!aux_info && create)
6994 aux_info = g_slice_new (GtkWidgetAuxInfo);
6996 aux_info->width = -1;
6997 aux_info->height = -1;
7000 aux_info->x_set = FALSE;
7001 aux_info->y_set = FALSE;
7002 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
7008 /*****************************************
7009 * gtk_widget_aux_info_destroy:
7014 *****************************************/
7017 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
7019 g_slice_free (GtkWidgetAuxInfo, aux_info);
7023 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
7025 g_object_unref (info->shape_mask);
7026 g_slice_free (GtkWidgetShapeInfo, info);
7030 * gtk_widget_shape_combine_mask:
7031 * @widget: a #GtkWidget.
7032 * @shape_mask: shape to be added, or %NULL to remove an existing shape.
7033 * @offset_x: X position of shape mask with respect to @window.
7034 * @offset_y: Y position of shape mask with respect to @window.
7036 * Sets a shape for this widget's GDK window. This allows for
7037 * transparent windows etc., see gdk_window_shape_combine_mask()
7038 * for more information.
7041 gtk_widget_shape_combine_mask (GtkWidget *widget,
7042 GdkBitmap *shape_mask,
7046 GtkWidgetShapeInfo* shape_info;
7048 g_return_if_fail (GTK_IS_WIDGET (widget));
7049 /* set_shape doesn't work on widgets without gdk window */
7050 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
7054 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
7057 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
7059 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
7063 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
7065 shape_info = g_slice_new (GtkWidgetShapeInfo);
7066 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
7067 (GDestroyNotify) gtk_widget_shape_info_destroy);
7069 shape_info->shape_mask = g_object_ref (shape_mask);
7070 shape_info->offset_x = offset_x;
7071 shape_info->offset_y = offset_y;
7073 /* set shape if widget has a gdk window already.
7074 * otherwise the shape is scheduled to be set by gtk_widget_realize().
7077 gdk_window_shape_combine_mask (widget->window, shape_mask,
7078 offset_x, offset_y);
7083 * gtk_widget_input_shape_combine_mask:
7084 * @widget: a #GtkWidget.
7085 * @shape_mask: shape to be added, or %NULL to remove an existing shape.
7086 * @offset_x: X position of shape mask with respect to @window.
7087 * @offset_y: Y position of shape mask with respect to @window.
7089 * Sets an input shape for this widget's GDK window. This allows for
7090 * windows which react to mouse click in a nonrectangular region, see
7091 * gdk_window_input_shape_combine_mask() for more information.
7096 gtk_widget_input_shape_combine_mask (GtkWidget *widget,
7097 GdkBitmap *shape_mask,
7101 GtkWidgetShapeInfo* shape_info;
7103 g_return_if_fail (GTK_IS_WIDGET (widget));
7104 /* set_shape doesn't work on widgets without gdk window */
7105 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
7110 gdk_window_input_shape_combine_mask (widget->window, NULL, 0, 0);
7112 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
7116 shape_info = g_slice_new (GtkWidgetShapeInfo);
7117 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
7119 (GDestroyNotify) gtk_widget_shape_info_destroy);
7121 shape_info->shape_mask = g_object_ref (shape_mask);
7122 shape_info->offset_x = offset_x;
7123 shape_info->offset_y = offset_y;
7125 /* set shape if widget has a gdk window already.
7126 * otherwise the shape is scheduled to be set by gtk_widget_realize().
7129 gdk_window_input_shape_combine_mask (widget->window, shape_mask,
7130 offset_x, offset_y);
7136 gtk_reset_shapes_recurse (GtkWidget *widget,
7142 gdk_window_get_user_data (window, &data);
7146 gdk_window_shape_combine_mask (window, NULL, 0, 0);
7147 for (list = gdk_window_peek_children (window); list; list = list->next)
7148 gtk_reset_shapes_recurse (widget, list->data);
7152 * gtk_widget_reset_shapes:
7153 * @widget: a #GtkWidget.
7155 * Recursively resets the shape on this widget and its descendants.
7158 gtk_widget_reset_shapes (GtkWidget *widget)
7160 g_return_if_fail (GTK_IS_WIDGET (widget));
7161 g_return_if_fail (GTK_WIDGET_REALIZED (widget));
7163 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
7164 gtk_reset_shapes_recurse (widget, widget->window);
7169 * @widget: a #GtkWidget
7171 * Adds a reference to a widget. This function is exactly the same
7172 * as calling g_object_ref(), and exists mostly for historical
7173 * reasons. It can still be convenient to avoid casting a widget
7174 * to a #GObject, it saves a small amount of typing.
7176 * Return value: the widget that was referenced
7179 gtk_widget_ref (GtkWidget *widget)
7181 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7183 return (GtkWidget*) g_object_ref ((GObject*) widget);
7188 * @widget: a #GtkWidget
7190 * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
7194 gtk_widget_unref (GtkWidget *widget)
7196 g_return_if_fail (GTK_IS_WIDGET (widget));
7198 g_object_unref ((GObject*) widget);
7206 * gtk_widget_class_install_style_property_parser:
7207 * @klass: a #GtkWidgetClass
7208 * @pspec: the #GParamSpec for the style property
7209 * @parser: the parser for the style property
7211 * Installs a style property on a widget class.
7214 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
7216 GtkRcPropertyParser parser)
7218 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
7219 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
7220 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
7221 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
7223 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
7225 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
7226 G_OBJECT_CLASS_NAME (klass),
7231 g_param_spec_ref_sink (pspec);
7232 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
7233 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
7237 * gtk_widget_class_install_style_property:
7238 * @klass: a #GtkWidgetClass
7239 * @pspec: the #GParamSpec for the property
7241 * Installs a style property on a widget class. The parser for the
7242 * style property is determined by the value type of @pspec.
7245 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
7248 GtkRcPropertyParser parser;
7250 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
7251 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
7253 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
7255 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
7259 * gtk_widget_class_find_style_property:
7260 * @klass: a #GtkWidgetClass
7261 * @property_name: the name of the style property to find
7262 * @returns: the #GParamSpec of the style property or %NULL if @class has no
7263 * style property with that name.
7265 * Finds a style property of a widget class by name.
7270 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
7271 const gchar *property_name)
7273 g_return_val_if_fail (property_name != NULL, NULL);
7275 return g_param_spec_pool_lookup (style_property_spec_pool,
7277 G_OBJECT_CLASS_TYPE (klass),
7282 * gtk_widget_class_list_style_properties:
7283 * @klass: a #GtkWidgetClass
7284 * @n_properties: location to return the number of style properties found
7285 * @returns: an newly allocated array of #GParamSpec*. The array must be freed with g_free().
7287 * Returns all style properties of a widget class.
7292 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
7293 guint *n_properties)
7295 GParamSpec **pspecs;
7298 pspecs = g_param_spec_pool_list (style_property_spec_pool,
7299 G_OBJECT_CLASS_TYPE (klass),
7308 * gtk_widget_style_get_property:
7309 * @widget: a #GtkWidget
7310 * @property_name: the name of a style property
7311 * @value: location to return the property value
7313 * Gets the value of a style property of @widget.
7316 gtk_widget_style_get_property (GtkWidget *widget,
7317 const gchar *property_name,
7322 g_return_if_fail (GTK_IS_WIDGET (widget));
7323 g_return_if_fail (property_name != NULL);
7324 g_return_if_fail (G_IS_VALUE (value));
7326 g_object_ref (widget);
7327 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
7329 G_OBJECT_TYPE (widget),
7332 g_warning ("%s: widget class `%s' has no property named `%s'",
7334 G_OBJECT_TYPE_NAME (widget),
7338 const GValue *peek_value;
7340 peek_value = _gtk_style_peek_property_value (widget->style,
7341 G_OBJECT_TYPE (widget),
7343 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
7345 /* auto-conversion of the caller's value type
7347 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
7348 g_value_copy (peek_value, value);
7349 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
7350 g_value_transform (peek_value, value);
7352 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
7354 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
7355 G_VALUE_TYPE_NAME (value));
7357 g_object_unref (widget);
7361 * gtk_widget_style_get_valist:
7362 * @widget: a #GtkWidget
7363 * @first_property_name: the name of the first property to get
7364 * @var_args: a <type>va_list</type> of pairs of property names and
7365 * locations to return the property values, starting with the location
7366 * for @first_property_name.
7368 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
7372 gtk_widget_style_get_valist (GtkWidget *widget,
7373 const gchar *first_property_name,
7378 g_return_if_fail (GTK_IS_WIDGET (widget));
7380 g_object_ref (widget);
7382 name = first_property_name;
7385 const GValue *peek_value;
7389 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
7391 G_OBJECT_TYPE (widget),
7395 g_warning ("%s: widget class `%s' has no property named `%s'",
7397 G_OBJECT_TYPE_NAME (widget),
7401 /* style pspecs are always readable so we can spare that check here */
7403 peek_value = _gtk_style_peek_property_value (widget->style,
7404 G_OBJECT_TYPE (widget),
7406 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
7407 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
7410 g_warning ("%s: %s", G_STRLOC, error);
7415 name = va_arg (var_args, gchar*);
7418 g_object_unref (widget);
7422 * gtk_widget_style_get:
7423 * @widget: a #GtkWidget
7424 * @first_property_name: the name of the first property to get
7425 * @Varargs: pairs of property names and locations to
7426 * return the property values, starting with the location for
7427 * @first_property_name, terminated by %NULL.
7429 * Gets the values of a multiple style properties of @widget.
7432 gtk_widget_style_get (GtkWidget *widget,
7433 const gchar *first_property_name,
7438 g_return_if_fail (GTK_IS_WIDGET (widget));
7440 va_start (var_args, first_property_name);
7441 gtk_widget_style_get_valist (widget, first_property_name, var_args);
7447 * @widget: a #GtkWidget
7448 * @path_length: location to store length of the path, or %NULL
7449 * @path: location to store allocated path string, or %NULL
7450 * @path_reversed: location to store allocated reverse path string, or %NULL
7452 * Obtains the full path to @widget. The path is simply the name of a
7453 * widget and all its parents in the container hierarchy, separated by
7454 * periods. The name of a widget comes from
7455 * gtk_widget_get_name(). Paths are used to apply styles to a widget
7456 * in gtkrc configuration files. Widget names are the type of the
7457 * widget by default (e.g. "GtkButton") or can be set to an
7458 * application-specific value with gtk_widget_set_name(). By setting
7459 * the name of a widget, you allow users or theme authors to apply
7460 * styles to that specific widget in their gtkrc
7461 * file. @path_reversed_p fills in the path in reverse order,
7462 * i.e. starting with @widget's name instead of starting with the name
7463 * of @widget's outermost ancestor.
7467 gtk_widget_path (GtkWidget *widget,
7470 gchar **path_reversed)
7472 static gchar *rev_path = NULL;
7473 static guint tmp_path_len = 0;
7476 g_return_if_fail (GTK_IS_WIDGET (widget));
7481 const gchar *string;
7486 string = gtk_widget_get_name (widget);
7487 l = strlen (string);
7488 while (tmp_path_len <= len + l + 1)
7490 tmp_path_len += INIT_PATH_SIZE;
7491 rev_path = g_realloc (rev_path, tmp_path_len);
7499 widget = widget->parent;
7502 rev_path[len++] = '.';
7504 rev_path[len++] = 0;
7509 *path_length = len - 1;
7511 *path_reversed = g_strdup (rev_path);
7514 *path = g_strdup (rev_path);
7515 g_strreverse (*path);
7520 * gtk_widget_class_path:
7521 * @widget: a #GtkWidget
7522 * @path_length: location to store the length of the class path, or %NULL
7523 * @path: location to store the class path as an allocated string, or %NULL
7524 * @path_reversed: location to store the reverse class path as an allocated string, or %NULL
7526 * Same as gtk_widget_path(), but always uses the name of a widget's type,
7527 * never uses a custom name set with gtk_widget_set_name().
7531 gtk_widget_class_path (GtkWidget *widget,
7534 gchar **path_reversed)
7536 static gchar *rev_path = NULL;
7537 static guint tmp_path_len = 0;
7540 g_return_if_fail (GTK_IS_WIDGET (widget));
7545 const gchar *string;
7550 string = g_type_name (GTK_WIDGET_TYPE (widget));
7551 l = strlen (string);
7552 while (tmp_path_len <= len + l + 1)
7554 tmp_path_len += INIT_PATH_SIZE;
7555 rev_path = g_realloc (rev_path, tmp_path_len);
7563 widget = widget->parent;
7566 rev_path[len++] = '.';
7568 rev_path[len++] = 0;
7573 *path_length = len - 1;
7575 *path_reversed = g_strdup (rev_path);
7578 *path = g_strdup (rev_path);
7579 g_strreverse (*path);
7584 * gtk_requisition_copy:
7585 * @requisition: a #GtkRequisition.
7586 * @returns: a copy of @requisition.
7588 * Copies a #GtkRequisition.
7591 gtk_requisition_copy (const GtkRequisition *requisition)
7593 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
7597 * gtk_requisition_free:
7598 * @requisition: a #GtkRequisition.
7600 * Frees a #GtkRequisition.
7603 gtk_requisition_free (GtkRequisition *requisition)
7605 g_free (requisition);
7609 gtk_requisition_get_type (void)
7611 static GType our_type = 0;
7614 our_type = g_boxed_type_register_static (I_("GtkRequisition"),
7615 (GBoxedCopyFunc) gtk_requisition_copy,
7616 (GBoxedFreeFunc) gtk_requisition_free);
7622 * gtk_widget_get_accessible:
7623 * @widget: a #GtkWidget
7625 * Returns the accessible object that describes the widget to an
7626 * assistive technology.
7628 * If no accessibility library is loaded (i.e. no ATK implementation library is
7629 * loaded via <envar>GTK_MODULES</envar> or via another application library,
7630 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
7631 * if no class-specific #AtkObject implementation is available for the widget
7632 * instance in question, it will inherit an #AtkObject implementation from the
7633 * first ancestor class for which such an implementation is defined.
7635 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
7636 * library contains more information about accessible objects and their uses.
7638 * Returns: the #AtkObject associated with @widget
7641 gtk_widget_get_accessible (GtkWidget *widget)
7643 GtkWidgetClass *klass;
7645 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7647 klass = GTK_WIDGET_GET_CLASS (widget);
7649 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
7651 return klass->get_accessible (widget);
7655 gtk_widget_real_get_accessible (GtkWidget *widget)
7657 AtkObject* accessible;
7659 accessible = g_object_get_qdata (G_OBJECT (widget),
7660 quark_accessible_object);
7663 AtkObjectFactory *factory;
7664 AtkRegistry *default_registry;
7666 default_registry = atk_get_default_registry ();
7667 factory = atk_registry_get_factory (default_registry,
7668 G_TYPE_FROM_INSTANCE (widget));
7670 atk_object_factory_create_accessible (factory,
7672 g_object_set_qdata (G_OBJECT (widget),
7673 quark_accessible_object,
7680 * Initialize a AtkImplementorIface instance's virtual pointers as
7681 * appropriate to this implementor's class (GtkWidget).
7684 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
7686 iface->ref_accessible = gtk_widget_ref_accessible;
7690 gtk_widget_ref_accessible (AtkImplementor *implementor)
7692 AtkObject *accessible;
7694 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
7696 g_object_ref (accessible);
7701 * gtk_widget_get_clipboard:
7702 * @widget: a #GtkWidget
7703 * @selection: a #GdkAtom which identifies the clipboard
7704 * to use. %GDK_SELECTION_CLIPBOARD gives the
7705 * default clipboard. Another common value
7706 * is %GDK_SELECTION_PRIMARY, which gives
7707 * the primary X selection.
7709 * Returns the clipboard object for the given selection to
7710 * be used with @widget. @widget must have a #GdkDisplay
7711 * associated with it, so must be attached to a toplevel
7714 * Return value: the appropriate clipboard object. If no
7715 * clipboard already exists, a new one will
7716 * be created. Once a clipboard object has
7717 * been created, it is persistent for all time.
7722 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
7724 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7725 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
7727 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
7732 * gtk_widget_list_mnemonic_labels:
7733 * @widget: a #GtkWidget
7735 * Returns a newly allocated list of the widgets, normally labels, for
7736 * which this widget is a the target of a mnemonic (see for example,
7737 * gtk_label_set_mnemonic_widget()).
7739 * The widgets in the list are not individually referenced. If you
7740 * want to iterate through the list and perform actions involving
7741 * callbacks that might destroy the widgets, you
7742 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
7743 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
7744 * widgets afterwards.
7746 * Return value: the list of mnemonic labels; free this list
7747 * with g_list_free() when you are done with it.
7752 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
7757 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7759 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
7760 list = g_list_prepend (list, l->data);
7766 * gtk_widget_add_mnemonic_label:
7767 * @widget: a #GtkWidget
7768 * @label: a #GtkWidget that acts as a mnemonic label for @widget.
7770 * Adds a widget to the list of mnemonic labels for
7771 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
7772 * list of mnemonic labels for the widget is cleared when the
7773 * widget is destroyed, so the caller must make sure to update
7774 * its internal state at this point as well, by using a connection
7775 * to the ::destroy signal or a weak notifier.
7780 gtk_widget_add_mnemonic_label (GtkWidget *widget,
7783 GSList *old_list, *new_list;
7785 g_return_if_fail (GTK_IS_WIDGET (widget));
7786 g_return_if_fail (GTK_IS_WIDGET (label));
7788 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
7789 new_list = g_slist_prepend (old_list, label);
7791 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
7792 new_list, (GDestroyNotify) g_slist_free);
7796 * gtk_widget_remove_mnemonic_label:
7797 * @widget: a #GtkWidget
7798 * @label: a #GtkWidget that was previously set as a mnemnic label for
7799 * @widget with gtk_widget_add_mnemonic_label().
7801 * Removes a widget from the list of mnemonic labels for
7802 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
7803 * must have previously been added to the list with
7804 * gtk_widget_add_mnemonic_label().
7809 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
7812 GSList *old_list, *new_list;
7814 g_return_if_fail (GTK_IS_WIDGET (widget));
7815 g_return_if_fail (GTK_IS_WIDGET (label));
7817 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
7818 new_list = g_slist_remove (old_list, label);
7821 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
7822 new_list, (GDestroyNotify) g_slist_free);
7826 * gtk_widget_get_no_show_all:
7827 * @widget: a #GtkWidget
7829 * Returns the current value of the "no_show_all" property, which determines
7830 * whether calls to gtk_widget_show_all() and gtk_widget_hide_all()
7831 * will affect this widget.
7833 * Return value: the current value of the "no_show_all" property.
7838 gtk_widget_get_no_show_all (GtkWidget *widget)
7840 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7842 return (GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
7846 * gtk_widget_set_no_show_all:
7847 * @widget: a #GtkWidget
7848 * @no_show_all: the new value for the "no_show_all" property
7850 * Sets the "no_show_all" property, which determines whether calls to
7851 * gtk_widget_show_all() and gtk_widget_hide_all() will affect this widget.
7853 * This is mostly for use in constructing widget hierarchies with externally
7854 * controlled visibility, see #GtkUIManager.
7859 gtk_widget_set_no_show_all (GtkWidget *widget,
7860 gboolean no_show_all)
7862 g_return_if_fail (GTK_IS_WIDGET (widget));
7864 no_show_all = (no_show_all != FALSE);
7866 if (no_show_all == ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0))
7870 GTK_WIDGET_SET_FLAGS (widget, GTK_NO_SHOW_ALL);
7872 GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_SHOW_ALL);
7874 g_object_notify (G_OBJECT (widget), "no-show-all");
7877 #define __GTK_WIDGET_C__
7878 #include "gtkaliasdef.c"