X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;ds=sidebyside;f=gtk%2Fgtkwidget.c;h=c988cdd1b6316105a11f9aa4a09cb7a85a071e83;hb=1fe7d3cefd1aeabd6d8cab2a68673bb1f7876988;hp=6307698f504638bfb39b35163c9cacaed3456b7a;hpb=2faae9fd1d67cedef36baafc818bd0b45d031184;p=~andy%2Fgtk diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 6307698f5..c988cdd1b 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -55,6 +55,74 @@ #include "gtkbuilderprivate.h" #include "gtkalias.h" +/** + * SECTION:gtkwidget + * @Short_description: Base class for all widgets + * @Title: GtkWidget + * + * GtkWidget is the base class all widgets in GTK+ derive from. It manages the + * widget lifecycle, states and style. + * + * + * GtkWidget introduces style + * properties - these are basically object properties that are stored + * not on the object, but in the style object associated to the widget. Style + * properties are set in resource files. + * This mechanism is used for configuring such things as the location of the + * scrollbar arrows through the theme, giving theme authors more control over the + * look of applications without the need to write a theme engine in C. + * + * + * Use gtk_widget_class_install_style_property() to install style properties for + * a widget class, gtk_widget_class_find_style_property() or + * gtk_widget_class_list_style_properties() to get information about existing + * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or + * gtk_widget_style_get_valist() to obtain the value of a style property. + * + * + * + * GtkWidget as GtkBuildable + * + * The GtkWidget implementation of the GtkBuildable interface supports a + * custom <accelerator> element, which has attributes named key, + * modifiers and signal and allows to specify accelerators. + * + * + * A UI definition fragment specifying an accelerator + * + * + * + * ]]> + * + * + * In addition to accelerators, GtkWidget also support a + * custom <accessible> element, which supports actions and relations. + * Properties on the accessible implementation of an object can be set by accessing the + * internal child "accessible" of a GtkWidget. + * + * + * A UI definition fragment specifying an accessible + * + * I am a Label for a Button + * + * + * + * Click the button. + * + * + * + * + * Clickable Button + * + * + * + * ]]> + * + * + */ + #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w) #define INIT_PATH_SIZE (512) @@ -154,7 +222,8 @@ enum { PROP_HAS_TOOLTIP, PROP_TOOLTIP_MARKUP, PROP_TOOLTIP_TEXT, - PROP_WINDOW + PROP_WINDOW, + PROP_DOUBLE_BUFFERED }; typedef struct _GtkStateData GtkStateData; @@ -274,6 +343,7 @@ static void gtk_widget_buildable_custom_finished (GtkBuildable static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable, GtkBuilder *builder); +static void gtk_widget_queue_tooltip_query (GtkWidget *widget); static void gtk_widget_set_usize_internal (GtkWidget *widget, gint width, @@ -691,6 +761,25 @@ gtk_widget_class_init (GtkWidgetClass *klass) GDK_TYPE_WINDOW, GTK_PARAM_READABLE)); + /** + * GtkWidget:double-buffered + * + * Whether or not the widget is double buffered. + * + * Since: 2.18 + */ + g_object_class_install_property (gobject_class, + PROP_DOUBLE_BUFFERED, + g_param_spec_boolean ("double-buffered", + P_("Double Buffered"), + P_("Whether or not the widget is double buffered"), + TRUE, + GTK_PARAM_READWRITE)); + + /** + * GtkWidget::show: + * @widget: the object which received the signal. + */ widget_signals[SHOW] = g_signal_new (I_("show"), G_TYPE_FROM_CLASS (gobject_class), @@ -699,6 +788,11 @@ gtk_widget_class_init (GtkWidgetClass *klass) NULL, NULL, _gtk_marshal_VOID__VOID, G_TYPE_NONE, 0); + + /** + * GtkWidget::hide: + * @widget: the object which received the signal. + */ widget_signals[HIDE] = g_signal_new (I_("hide"), G_TYPE_FROM_CLASS (gobject_class), @@ -707,6 +801,11 @@ gtk_widget_class_init (GtkWidgetClass *klass) NULL, NULL, _gtk_marshal_VOID__VOID, G_TYPE_NONE, 0); + + /** + * GtkWidget::map: + * @widget: the object which received the signal. + */ widget_signals[MAP] = g_signal_new (I_("map"), G_TYPE_FROM_CLASS (gobject_class), @@ -715,6 +814,11 @@ gtk_widget_class_init (GtkWidgetClass *klass) NULL, NULL, _gtk_marshal_VOID__VOID, G_TYPE_NONE, 0); + + /** + * GtkWidget::unmap: + * @widget: the object which received the signal. + */ widget_signals[UNMAP] = g_signal_new (I_("unmap"), G_TYPE_FROM_CLASS (gobject_class), @@ -723,6 +827,11 @@ gtk_widget_class_init (GtkWidgetClass *klass) NULL, NULL, _gtk_marshal_VOID__VOID, G_TYPE_NONE, 0); + + /** + * GtkWidget::realize: + * @widget: the object which received the signal. + */ widget_signals[REALIZE] = g_signal_new (I_("realize"), G_TYPE_FROM_CLASS (gobject_class), @@ -731,6 +840,11 @@ gtk_widget_class_init (GtkWidgetClass *klass) NULL, NULL, _gtk_marshal_VOID__VOID, G_TYPE_NONE, 0); + + /** + * GtkWidget::unrealize: + * @widget: the object which received the signal. + */ widget_signals[UNREALIZE] = g_signal_new (I_("unrealize"), G_TYPE_FROM_CLASS (gobject_class), @@ -739,6 +853,12 @@ gtk_widget_class_init (GtkWidgetClass *klass) NULL, NULL, _gtk_marshal_VOID__VOID, G_TYPE_NONE, 0); + + /** + * GtkWidget::size-request: + * @widget: the object which received the signal. + * @requisition: + */ widget_signals[SIZE_REQUEST] = g_signal_new (I_("size-request"), G_TYPE_FROM_CLASS (gobject_class), @@ -748,6 +868,12 @@ gtk_widget_class_init (GtkWidgetClass *klass) _gtk_marshal_VOID__BOXED, G_TYPE_NONE, 1, GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE); + + /** + * GtkWidget::size-allocate: + * @widget: the object which received the signal. + * @allocation: + */ widget_signals[SIZE_ALLOCATE] = g_signal_new (I_("size-allocate"), G_TYPE_FROM_CLASS (gobject_class), @@ -758,6 +884,14 @@ gtk_widget_class_init (GtkWidgetClass *klass) G_TYPE_NONE, 1, GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE); + /** + * GtkWidget::state-changed: + * @widget: the object which received the signal. + * @state: the previous state + * + * The ::state-changed signal is emitted when the widget state changes. + * See gtk_widget_get_state(). + */ widget_signals[STATE_CHANGED] = g_signal_new (I_("state-changed"), G_TYPE_FROM_CLASS (gobject_class), @@ -771,7 +905,7 @@ gtk_widget_class_init (GtkWidgetClass *klass) /** * GtkWidget::parent-set: * @widget: the object on which the signal is emitted - * @old_parent: the previous parent, or %NULL if the widget + * @old_parent: (allow-none): the previous parent, or %NULL if the widget * just got its initial parent. * * The ::parent-set signal is emitted when a new parent @@ -790,7 +924,7 @@ gtk_widget_class_init (GtkWidgetClass *klass) /** * GtkWidget::hierarchy-changed: * @widget: the object on which the signal is emitted - * @previous_toplevel: the previous toplevel ancestor, or %NULL + * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL * if the widget was previously unanchored * * The ::hierarchy-changed signal is emitted when the @@ -812,7 +946,7 @@ gtk_widget_class_init (GtkWidgetClass *klass) /** * GtkWidget::style-set: * @widget: the object on which the signal is emitted - * @previous_style: the previous style, or %NULL if the widget + * @previous_style: (allow-none): the previous style, or %NULL if the widget * just got its initial style * * The ::style-set signal is emitted when a new style has been set @@ -889,6 +1023,12 @@ gtk_widget_class_init (GtkWidgetClass *klass) g_cclosure_marshal_VOID__PARAM, G_TYPE_NONE, 1, G_TYPE_PARAM); + + /** + * GtkWidget::mnemonic-activate: + * @widget: the object which received the signal. + * @arg1: + */ widget_signals[MNEMONIC_ACTIVATE] = g_signal_new (I_("mnemonic-activate"), G_TYPE_FROM_CLASS (gobject_class), @@ -898,6 +1038,11 @@ gtk_widget_class_init (GtkWidgetClass *klass) _gtk_marshal_BOOLEAN__BOOLEAN, G_TYPE_BOOLEAN, 1, G_TYPE_BOOLEAN); + + /** + * GtkWidget::grab-focus: + * @widget: the object which received the signal. + */ widget_signals[GRAB_FOCUS] = g_signal_new (I_("grab-focus"), G_TYPE_FROM_CLASS (gobject_class), @@ -906,6 +1051,14 @@ gtk_widget_class_init (GtkWidgetClass *klass) NULL, NULL, _gtk_marshal_VOID__VOID, G_TYPE_NONE, 0); + + /** + * GtkWidget::focus: + * @widget: the object which received the signal. + * @direction: + * + * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further. + */ widget_signals[FOCUS] = g_signal_new (I_("focus"), G_TYPE_FROM_CLASS (object_class), @@ -915,6 +1068,12 @@ gtk_widget_class_init (GtkWidgetClass *klass) _gtk_marshal_BOOLEAN__ENUM, G_TYPE_BOOLEAN, 1, GTK_TYPE_DIRECTION_TYPE); + + /** + * GtkWidget::move-focus: + * @widget: the object which received the signal. + * @direction: + */ widget_signals[MOVE_FOCUS] = g_signal_new_class_handler (I_("move-focus"), G_TYPE_FROM_CLASS (object_class), @@ -1486,6 +1645,13 @@ gtk_widget_class_init (GtkWidgetClass *klass) G_TYPE_BOOLEAN, 1, GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); + /** + * GtkWidget::selection-notify-event: + * @widget: the object which received the signal. + * @event: + * + * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further. + */ widget_signals[SELECTION_NOTIFY_EVENT] = g_signal_new (I_("selection-notify-event"), G_TYPE_FROM_CLASS (gobject_class), @@ -1496,6 +1662,12 @@ gtk_widget_class_init (GtkWidgetClass *klass) G_TYPE_BOOLEAN, 1, GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); + /** + * GtkWidget::selection-received: + * @widget: the object which received the signal. + * @data: + * @time: + */ widget_signals[SELECTION_RECEIVED] = g_signal_new (I_("selection-received"), G_TYPE_FROM_CLASS (gobject_class), @@ -1507,6 +1679,13 @@ gtk_widget_class_init (GtkWidgetClass *klass) GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE, G_TYPE_UINT); + /** + * GtkWidget::selection-get: + * @widget: the object which received the signal. + * @data: + * @info: + * @time: + */ widget_signals[SELECTION_GET] = g_signal_new (I_("selection-get"), G_TYPE_FROM_CLASS (gobject_class), @@ -1595,6 +1774,10 @@ gtk_widget_class_init (GtkWidgetClass *klass) * The ::drag-begin signal is emitted on the drag source when a drag is * started. A typical reason to connect to this signal is to set up a * custom drag icon with gtk_drag_source_set_icon(). + * + * Note that some widgets set up a drag icon in the default handler of + * this signal, so you may have to use g_signal_connect_after() to + * override what the default handler did. */ widget_signals[DRAG_BEGIN] = g_signal_new (I_("drag-begin"), @@ -1810,7 +1993,7 @@ gtk_widget_class_init (GtkWidgetClass *klass) G_TYPE_INT, G_TYPE_UINT); - /** + /** * GtkWidget::drag-data-get: * @widget: the object which received the signal * @drag_context: the drag context @@ -2071,8 +2254,8 @@ gtk_widget_class_init (GtkWidgetClass *klass) * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard * @tooltip: a #GtkTooltip * - * Emitted when the #GtkSettings:gtk-tooltip-timeout has expired with - * the cursor hovering "above" @widget; or emitted when @widget got + * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout + * has expired with the cursor hovering "above" @widget; or emitted when @widget got * focus in keyboard mode. * * Using the given coordinates, the signal handler should determine @@ -2122,6 +2305,12 @@ gtk_widget_class_init (GtkWidgetClass *klass) _gtk_boolean_handled_accumulator, NULL, _gtk_marshal_BOOLEAN__VOID, G_TYPE_BOOLEAN, 0); + + /** + * GtkWidget::show-help: + * @widget: the object which received the signal. + * @help_type: + */ widget_signals[SHOW_HELP] = g_signal_new (I_("show-help"), G_TYPE_FROM_CLASS (gobject_class), @@ -2131,6 +2320,11 @@ gtk_widget_class_init (GtkWidgetClass *klass) _gtk_marshal_BOOLEAN__ENUM, G_TYPE_BOOLEAN, 1, GTK_TYPE_WIDGET_HELP_TYPE); + + /** + * GtkWidget::accel-closures-changed: + * @widget: the object which received the signal. + */ widget_signals[ACCEL_CLOSURES_CHANGED] = g_signal_new (I_("accel-closures-changed"), G_TYPE_FROM_CLASS (gobject_class), @@ -2143,7 +2337,7 @@ gtk_widget_class_init (GtkWidgetClass *klass) /** * GtkWidget::screen-changed: * @widget: the object on which the signal is emitted - * @previous_screen: the previous screen, or %NULL if the + * @previous_screen: (allow-none): the previous screen, or %NULL if the * widget was not associated with a screen before * * The ::screen-changed signal gets emitted when the @@ -2158,6 +2352,7 @@ gtk_widget_class_init (GtkWidgetClass *klass) _gtk_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GDK_TYPE_SCREEN); + /** * GtkWidget::can-activate-accel: * @widget: the object which received the signal @@ -2394,11 +2589,10 @@ gtk_widget_set_property (GObject *object, switch (prop_id) { gboolean tmp; - guint32 saved_flags; gchar *tooltip_markup; const gchar *tooltip_text; GtkWindow *tooltip_window; - + case PROP_NAME: gtk_widget_set_name (widget, g_value_get_string (value)); break; @@ -2412,10 +2606,7 @@ gtk_widget_set_property (GObject *object, gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value)); break; case PROP_VISIBLE: - if (g_value_get_boolean (value)) - gtk_widget_show (widget); - else - gtk_widget_hide (widget); + gtk_widget_set_visible (widget, g_value_get_boolean (value)); break; case PROP_SENSITIVE: gtk_widget_set_sensitive (widget, g_value_get_boolean (value)); @@ -2424,13 +2615,7 @@ gtk_widget_set_property (GObject *object, gtk_widget_set_app_paintable (widget, g_value_get_boolean (value)); break; case PROP_CAN_FOCUS: - saved_flags = GTK_WIDGET_FLAGS (widget); - if (g_value_get_boolean (value)) - GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS); - else - GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS); - if (saved_flags != GTK_WIDGET_FLAGS (widget)) - gtk_widget_queue_resize (widget); + gtk_widget_set_can_focus (widget, g_value_get_boolean (value)); break; case PROP_HAS_FOCUS: if (g_value_get_boolean (value)) @@ -2441,29 +2626,20 @@ gtk_widget_set_property (GObject *object, gtk_widget_grab_focus (widget); break; case PROP_CAN_DEFAULT: - saved_flags = GTK_WIDGET_FLAGS (widget); - if (g_value_get_boolean (value)) - GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT); - else - GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT); - if (saved_flags != GTK_WIDGET_FLAGS (widget)) - gtk_widget_queue_resize (widget); + gtk_widget_set_can_default (widget, g_value_get_boolean (value)); break; case PROP_HAS_DEFAULT: if (g_value_get_boolean (value)) gtk_widget_grab_default (widget); break; case PROP_RECEIVES_DEFAULT: - if (g_value_get_boolean (value)) - GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT); - else - GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT); + gtk_widget_set_receives_default (widget, g_value_get_boolean (value)); break; case PROP_STYLE: gtk_widget_set_style (widget, g_value_get_object (value)); break; case PROP_EVENTS: - if (!GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget)) + if (!GTK_WIDGET_REALIZED (widget) && gtk_widget_get_has_window (widget)) gtk_widget_set_events (widget, g_value_get_flags (value)); break; case PROP_EXTENSION_EVENTS: @@ -2484,16 +2660,18 @@ gtk_widget_set_property (GObject *object, * because an empty string would be useless for a tooltip: */ if (tooltip_markup && (strlen (tooltip_markup) == 0)) - { - g_free (tooltip_markup); - tooltip_markup = NULL; - } + { + g_free (tooltip_markup); + tooltip_markup = NULL; + } g_object_set_qdata_full (object, quark_tooltip_markup, tooltip_markup, g_free); tmp = (tooltip_window != NULL || tooltip_markup != NULL); gtk_widget_real_set_has_tooltip (widget, tmp, FALSE); + if (gtk_widget_get_visible (widget)) + gtk_widget_queue_tooltip_query (widget); break; case PROP_TOOLTIP_TEXT: tooltip_window = g_object_get_qdata (object, quark_tooltip_window); @@ -2513,6 +2691,11 @@ gtk_widget_set_property (GObject *object, tmp = (tooltip_window != NULL || tooltip_markup != NULL); gtk_widget_real_set_has_tooltip (widget, tmp, FALSE); + if (gtk_widget_get_visible (widget)) + gtk_widget_queue_tooltip_query (widget); + break; + case PROP_DOUBLE_BUFFERED: + gtk_widget_set_double_buffered (widget, g_value_get_boolean (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -2540,10 +2723,7 @@ gtk_widget_get_property (GObject *object, g_value_set_static_string (value, ""); break; case PROP_PARENT: - if (widget->parent) - g_value_set_object (value, widget->parent); - else - g_value_set_object (value, NULL); + g_value_set_object (value, widget->parent); break; case PROP_WIDTH_REQUEST: { @@ -2560,34 +2740,34 @@ gtk_widget_get_property (GObject *object, } break; case PROP_VISIBLE: - g_value_set_boolean (value, (GTK_WIDGET_VISIBLE (widget) != FALSE)); + g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE)); break; case PROP_SENSITIVE: - g_value_set_boolean (value, (GTK_WIDGET_SENSITIVE (widget) != FALSE)); + g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE)); break; case PROP_APP_PAINTABLE: - g_value_set_boolean (value, (GTK_WIDGET_APP_PAINTABLE (widget) != FALSE)); + g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE)); break; case PROP_CAN_FOCUS: - g_value_set_boolean (value, (GTK_WIDGET_CAN_FOCUS (widget) != FALSE)); + g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE)); break; case PROP_HAS_FOCUS: - g_value_set_boolean (value, (GTK_WIDGET_HAS_FOCUS (widget) != FALSE)); + g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE)); break; case PROP_IS_FOCUS: g_value_set_boolean (value, (gtk_widget_is_focus (widget))); break; case PROP_CAN_DEFAULT: - g_value_set_boolean (value, (GTK_WIDGET_CAN_DEFAULT (widget) != FALSE)); + g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE)); break; case PROP_HAS_DEFAULT: - g_value_set_boolean (value, (GTK_WIDGET_HAS_DEFAULT (widget) != FALSE)); + g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE)); break; case PROP_RECEIVES_DEFAULT: - g_value_set_boolean (value, (GTK_WIDGET_RECEIVES_DEFAULT (widget) != FALSE)); + g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE)); break; case PROP_COMPOSITE_CHILD: - g_value_set_boolean (value, (GTK_WIDGET_COMPOSITE_CHILD (widget) != FALSE)); + g_value_set_boolean (value, (GTK_WIDGET_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0 ); break; case PROP_STYLE: g_value_set_object (value, gtk_widget_get_style (widget)); @@ -2624,6 +2804,9 @@ gtk_widget_get_property (GObject *object, case PROP_WINDOW: g_value_set_object (value, gtk_widget_get_window (widget)); break; + case PROP_DOUBLE_BUFFERED: + g_value_set_boolean (value, gtk_widget_get_double_buffered (widget)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -2832,7 +3015,7 @@ gtk_widget_queue_draw_child (GtkWidget *widget) GtkWidget *parent; parent = widget->parent; - if (parent && GTK_WIDGET_DRAWABLE (parent)) + if (parent && gtk_widget_is_drawable (parent)) gtk_widget_queue_draw_area (parent, widget->allocation.x, widget->allocation.y, @@ -2866,7 +3049,7 @@ gtk_widget_unparent (GtkWidget *widget) nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context); toplevel = gtk_widget_get_toplevel (widget); - if (GTK_WIDGET_TOPLEVEL (toplevel)) + if (gtk_widget_is_toplevel (toplevel)) _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget); if (GTK_CONTAINER (widget->parent)->focus_child == widget) @@ -2952,7 +3135,7 @@ gtk_widget_destroy (GtkWidget *widget) /** * gtk_widget_destroyed: * @widget: a #GtkWidget - * @widget_pointer: address of a variable that contains @widget + * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget * * This function sets *@widget_pointer to %NULL if @widget_pointer != * %NULL. It's intended to be used as a callback connected to the @@ -2995,10 +3178,10 @@ gtk_widget_show (GtkWidget *widget) { g_return_if_fail (GTK_IS_WIDGET (widget)); - if (!GTK_WIDGET_VISIBLE (widget)) + if (!gtk_widget_get_visible (widget)) { g_object_ref (widget); - if (!GTK_WIDGET_TOPLEVEL (widget)) + if (!gtk_widget_is_toplevel (widget)) gtk_widget_queue_resize (widget); g_signal_emit (widget, widget_signals[SHOW], 0); g_object_notify (G_OBJECT (widget), "visible"); @@ -3009,14 +3192,14 @@ gtk_widget_show (GtkWidget *widget) static void gtk_widget_real_show (GtkWidget *widget) { - if (!GTK_WIDGET_VISIBLE (widget)) + if (!gtk_widget_get_visible (widget)) { GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE); if (widget->parent && - GTK_WIDGET_MAPPED (widget->parent) && + gtk_widget_get_mapped (widget->parent) && GTK_WIDGET_CHILD_VISIBLE (widget) && - !GTK_WIDGET_MAPPED (widget)) + !gtk_widget_get_mapped (widget)) gtk_widget_map (widget); } } @@ -3048,8 +3231,8 @@ gtk_widget_show_now (GtkWidget *widget) g_return_if_fail (GTK_IS_WIDGET (widget)); /* make sure we will get event */ - if (!GTK_WIDGET_MAPPED (widget) && - GTK_WIDGET_TOPLEVEL (widget)) + if (!gtk_widget_get_mapped (widget) && + gtk_widget_is_toplevel (widget)) { gtk_widget_show (widget); @@ -3076,16 +3259,16 @@ gtk_widget_hide (GtkWidget *widget) { g_return_if_fail (GTK_IS_WIDGET (widget)); - if (GTK_WIDGET_VISIBLE (widget)) + if (gtk_widget_get_visible (widget)) { GtkWidget *toplevel = gtk_widget_get_toplevel (widget); g_object_ref (widget); - if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel)) + if (toplevel != widget && gtk_widget_is_toplevel (toplevel)) _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget); g_signal_emit (widget, widget_signals[HIDE], 0); - if (!GTK_WIDGET_TOPLEVEL (widget)) + if (!gtk_widget_is_toplevel (widget)) gtk_widget_queue_resize (widget); g_object_notify (G_OBJECT (widget), "visible"); g_object_unref (widget); @@ -3095,11 +3278,11 @@ gtk_widget_hide (GtkWidget *widget) static void gtk_widget_real_hide (GtkWidget *widget) { - if (GTK_WIDGET_VISIBLE (widget)) + if (gtk_widget_get_visible (widget)) { GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE); - if (GTK_WIDGET_MAPPED (widget)) + if (gtk_widget_get_mapped (widget)) gtk_widget_unmap (widget); } } @@ -3142,7 +3325,7 @@ gtk_widget_show_all (GtkWidget *widget) g_return_if_fail (GTK_IS_WIDGET (widget)); - if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0) + if (gtk_widget_get_no_show_all (widget)) return; class = GTK_WIDGET_GET_CLASS (widget); @@ -3164,7 +3347,7 @@ gtk_widget_hide_all (GtkWidget *widget) g_return_if_fail (GTK_IS_WIDGET (widget)); - if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0) + if (gtk_widget_get_no_show_all (widget)) return; class = GTK_WIDGET_GET_CLASS (widget); @@ -3184,17 +3367,17 @@ void gtk_widget_map (GtkWidget *widget) { g_return_if_fail (GTK_IS_WIDGET (widget)); - g_return_if_fail (GTK_WIDGET_VISIBLE (widget)); + g_return_if_fail (gtk_widget_get_visible (widget)); g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget)); - if (!GTK_WIDGET_MAPPED (widget)) + if (!gtk_widget_get_mapped (widget)) { if (!GTK_WIDGET_REALIZED (widget)) gtk_widget_realize (widget); g_signal_emit (widget, widget_signals[MAP], 0); - if (GTK_WIDGET_NO_WINDOW (widget)) + if (!gtk_widget_get_has_window (widget)) gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE); } } @@ -3211,9 +3394,9 @@ gtk_widget_unmap (GtkWidget *widget) { g_return_if_fail (GTK_IS_WIDGET (widget)); - if (GTK_WIDGET_MAPPED (widget)) + if (gtk_widget_get_mapped (widget)) { - if (GTK_WIDGET_NO_WINDOW (widget)) + if (!gtk_widget_get_has_window (widget)) gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE); _gtk_tooltip_hide (widget); g_signal_emit (widget, widget_signals[UNMAP], 0); @@ -3230,7 +3413,7 @@ gtk_widget_set_extension_events_internal (GtkWidget *widget, if (window_list == NULL) { - if (!GTK_WIDGET_NO_WINDOW (widget)) + if (gtk_widget_get_has_window (widget)) window_list = g_list_prepend (NULL, widget->window); else window_list = gdk_window_get_children (widget->window); @@ -3301,12 +3484,12 @@ gtk_widget_realize (GtkWidget *widget) if (!GTK_WIDGET_REALIZED (widget)) { /* - if (GTK_IS_CONTAINER (widget) && !GTK_WIDGET_NO_WINDOW (widget)) - g_message ("gtk_widget_realize(%s)", g_type_name (GTK_WIDGET_TYPE (widget))); + if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget)) + g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget)); */ if (widget->parent == NULL && - !GTK_WIDGET_TOPLEVEL (widget)) + !gtk_widget_is_toplevel (widget)) g_warning ("Calling gtk_widget_realize() on a widget that isn't " "inside a toplevel window is not going to work very well. " "Widgets must be inside a toplevel container before realizing them."); @@ -3423,12 +3606,12 @@ gtk_widget_queue_draw_area (GtkWidget *widget, /* Just return if the widget or one of its ancestors isn't mapped */ for (w = widget; w != NULL; w = w->parent) - if (!GTK_WIDGET_MAPPED (w)) + if (!gtk_widget_get_mapped (w)) return; /* Find the correct widget */ - if (!GTK_WIDGET_NO_WINDOW (widget)) + if (gtk_widget_get_has_window (widget)) { if (widget->parent) { @@ -3475,7 +3658,7 @@ widget_add_child_draw_rectangle (GtkWidget *widget, { GdkRectangle child_rect; - if (!GTK_WIDGET_MAPPED (widget) || + if (!gtk_widget_get_mapped (widget) || widget->window != widget->parent->window) return; @@ -3487,19 +3670,19 @@ static void gtk_widget_get_draw_rectangle (GtkWidget *widget, GdkRectangle *rect) { - if (GTK_WIDGET_NO_WINDOW (widget)) + if (!gtk_widget_get_has_window (widget)) { GtkBorder *draw_border = NULL; *rect = widget->allocation; - gtk_widget_style_get (widget, + gtk_widget_style_get (widget, "draw-border", &draw_border, NULL); if (draw_border) { - rect->x -= draw_border->top; - rect->y -= draw_border->left; + rect->x -= draw_border->left; + rect->y -= draw_border->top; rect->width += draw_border->left + draw_border->right; rect->height += draw_border->top + draw_border->bottom; @@ -3648,7 +3831,7 @@ gtk_widget_draw (GtkWidget *widget, { g_return_if_fail (GTK_IS_WIDGET (widget)); - if (GTK_WIDGET_DRAWABLE (widget)) + if (gtk_widget_is_drawable (widget)) { if (area) gtk_widget_queue_draw_area (widget, @@ -3749,7 +3932,7 @@ gtk_widget_invalidate_widget_windows (GtkWidget *widget, if (!GTK_WIDGET_REALIZED (widget)) return; - if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent) + if (gtk_widget_get_has_window (widget) && widget->parent) { int x, y; @@ -3783,7 +3966,7 @@ gtk_widget_queue_shallow_draw (GtkWidget *widget) * need to convert to the coordinates that widget->allocation * is in. */ - if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent) + if (gtk_widget_get_has_window (widget) && widget->parent) { int wx, wy; @@ -3877,9 +4060,9 @@ gtk_widget_size_allocate (GtkWidget *widget, g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation); - if (GTK_WIDGET_MAPPED (widget)) + if (gtk_widget_get_mapped (widget)) { - if (GTK_WIDGET_NO_WINDOW (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed) + if (!gtk_widget_get_has_window (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed) { /* Invalidate union(old_allaction,widget->allocation) in widget->window */ @@ -3979,9 +4162,9 @@ gtk_widget_common_ancestor (GtkWidget *widget_a, * @dest_widget: a #GtkWidget * @src_x: X position relative to @src_widget * @src_y: Y position relative to @src_widget - * @dest_x: location to store X position relative to @dest_widget - * @dest_y: location to store Y position relative to @dest_widget - * + * @dest_x: (out): location to store X position relative to @dest_widget + * @dest_y: (out): location to store Y position relative to @dest_widget + * * Translate coordinates relative to @src_widget's allocation to coordinates * relative to @dest_widget's allocations. In order to perform this * operation, both widgets must be realized, and must share a common @@ -4010,7 +4193,7 @@ gtk_widget_translate_coordinates (GtkWidget *src_widget, return FALSE; /* Translate from allocation relative to window relative */ - if (!GTK_WIDGET_NO_WINDOW (src_widget) && src_widget->parent) + if (gtk_widget_get_has_window (src_widget) && src_widget->parent) { gint wx, wy; gdk_window_get_position (src_widget->window, &wx, &wy); @@ -4059,7 +4242,7 @@ gtk_widget_translate_coordinates (GtkWidget *src_widget, } /* Translate from window relative to allocation relative */ - if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent) + if (gtk_widget_get_has_window (dest_widget) && dest_widget->parent) { gint wx, wy; gdk_window_get_position (dest_widget->window, &wx, &wy); @@ -4088,7 +4271,7 @@ gtk_widget_real_size_allocate (GtkWidget *widget, widget->allocation = *allocation; if (GTK_WIDGET_REALIZED (widget) && - !GTK_WIDGET_NO_WINDOW (widget)) + gtk_widget_get_has_window (widget)) { gdk_window_move_resize (widget->window, allocation->x, allocation->y, @@ -4101,7 +4284,9 @@ gtk_widget_real_can_activate_accel (GtkWidget *widget, guint signal_id) { /* widgets must be onscreen for accels to take effect */ - return GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_DRAWABLE (widget) && gdk_window_is_viewable (widget->window); + return gtk_widget_is_sensitive (widget) && + gtk_widget_is_drawable (widget) && + gdk_window_is_viewable (widget->window); } /** @@ -4363,9 +4548,9 @@ destroy_accel_path (gpointer data) /** * gtk_widget_set_accel_path: * @widget: a #GtkWidget - * @accel_path: path used to look up the accelerator - * @accel_group: a #GtkAccelGroup. - * + * @accel_path: (allow-none): path used to look up the accelerator + * @accel_group: (allow-none): a #GtkAccelGroup. + * * Given an accelerator group, @accel_group, and an accelerator path, * @accel_path, sets up an accelerator in @accel_group so whenever the * key binding that is defined for @accel_path is pressed, @widget @@ -4435,6 +4620,19 @@ _gtk_widget_get_accel_path (GtkWidget *widget, return apath ? g_quark_to_string (apath->path_quark) : NULL; } +/** + * gtk_widget_mnemonic_activate: + * @widget: a #GtkWidget + * @group_cycling: %TRUE if there are other widgets with the same mnemonic + * + * Emits the #GtkWidget::mnemonic-activate signal. + * + * The default handler for this signal activates the @widget if + * @group_cycling is %FALSE, and just grabs the focus if @group_cycling + * is %TRUE. + * + * Returns: %TRUE if the signal has been handled + */ gboolean gtk_widget_mnemonic_activate (GtkWidget *widget, gboolean group_cycling) @@ -4444,7 +4642,7 @@ gtk_widget_mnemonic_activate (GtkWidget *widget, g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); group_cycling = group_cycling != FALSE; - if (!GTK_WIDGET_IS_SENSITIVE (widget)) + if (!gtk_widget_is_sensitive (widget)) handled = TRUE; else g_signal_emit (widget, @@ -4461,7 +4659,7 @@ gtk_widget_real_mnemonic_activate (GtkWidget *widget, { if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal) gtk_widget_activate (widget); - else if (GTK_WIDGET_CAN_FOCUS (widget)) + else if (gtk_widget_get_can_focus (widget)) gtk_widget_grab_focus (widget); else { @@ -4784,8 +4982,8 @@ gtk_widget_activate (GtkWidget *widget) /** * gtk_widget_set_scroll_adjustments: * @widget: a #GtkWidget - * @hadjustment: an adjustment for horizontal scrolling, or %NULL - * @vadjustment: an adjustment for vertical scrolling, or %NULL + * @hadjustment: (allow-none): an adjustment for horizontal scrolling, or %NULL + * @vadjustment: (allow-none): an adjustment for vertical scrolling, or %NULL * * For widgets that support scrolling, sets the scroll adjustments and * returns %TRUE. For widgets that don't support scrolling, does @@ -4800,29 +4998,42 @@ gtk_widget_set_scroll_adjustments (GtkWidget *widget, GtkAdjustment *hadjustment, GtkAdjustment *vadjustment) { + guint signal_id; + GSignalQuery query; + g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); + if (hadjustment) g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE); if (vadjustment) g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE); - if (WIDGET_CLASS (widget)->set_scroll_adjustments_signal) + signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal; + if (!signal_id) + return FALSE; + + g_signal_query (signal_id, &query); + if (!query.signal_id || + !g_type_is_a (query.itype, GTK_TYPE_WIDGET) || + query.return_type != G_TYPE_NONE || + query.n_params != 2 || + query.param_types[0] != GTK_TYPE_ADJUSTMENT || + query.param_types[1] != GTK_TYPE_ADJUSTMENT) { - /* FIXME: we should eventually check the signals signature here */ - g_signal_emit (widget, - WIDGET_CLASS (widget)->set_scroll_adjustments_signal, 0, - hadjustment, vadjustment); - return TRUE; + g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature", + G_OBJECT_TYPE_NAME (widget), query.signal_name); + return FALSE; } - else - return FALSE; + + g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment); + return TRUE; } static void gtk_widget_reparent_subwindows (GtkWidget *widget, GdkWindow *new_window) { - if (GTK_WIDGET_NO_WINDOW (widget)) + if (!gtk_widget_get_has_window (widget)) { GList *children = gdk_window_get_children (widget->window); GList *tmp_list; @@ -4877,7 +5088,7 @@ gtk_widget_reparent_fixup_child (GtkWidget *widget, { g_assert (client_data != NULL); - if (GTK_WIDGET_NO_WINDOW (widget)) + if (!gtk_widget_get_has_window (widget)) { if (widget->window) g_object_unref (widget->window); @@ -4967,7 +5178,7 @@ gtk_widget_intersect (GtkWidget *widget, return_val = gdk_rectangle_intersect (&widget->allocation, area, dest); - if (return_val && intersection && !GTK_WIDGET_NO_WINDOW (widget)) + if (return_val && intersection && gtk_widget_get_has_window (widget)) { intersection->x -= widget->allocation.x; intersection->y -= widget->allocation.y; @@ -5034,15 +5245,17 @@ _gtk_widget_grab_notify (GtkWidget *widget, * * Causes @widget to have the keyboard focus for the #GtkWindow it's * inside. @widget must be a focusable widget, such as a #GtkEntry; - * something like #GtkFrame won't work. (More precisely, it must have the - * %GTK_CAN_FOCUS flag set.) + * something like #GtkFrame won't work. + * + * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use + * gtk_widget_set_can_focus() to modify that flag. **/ void gtk_widget_grab_focus (GtkWidget *widget) { g_return_if_fail (GTK_IS_WIDGET (widget)); - if (!GTK_WIDGET_IS_SENSITIVE (widget)) + if (!gtk_widget_is_sensitive (widget)) return; g_object_ref (widget); @@ -5071,7 +5284,7 @@ reset_focus_recurse (GtkWidget *widget, static void gtk_widget_real_grab_focus (GtkWidget *focus_widget) { - if (GTK_WIDGET_CAN_FOCUS (focus_widget)) + if (gtk_widget_get_can_focus (focus_widget)) { GtkWidget *toplevel; GtkWidget *widget; @@ -5081,7 +5294,7 @@ gtk_widget_real_grab_focus (GtkWidget *focus_widget) * be set by the next loop. */ toplevel = gtk_widget_get_toplevel (focus_widget); - if (GTK_WIDGET_TOPLEVEL (toplevel)) + if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel)) { widget = GTK_WINDOW (toplevel)->focus_widget; @@ -5091,7 +5304,7 @@ gtk_widget_real_grab_focus (GtkWidget *focus_widget) * toplevel window can request the focus if necessary. * This is needed when the toplevel is a GtkPlug */ - if (!GTK_WIDGET_HAS_FOCUS (widget)) + if (!gtk_widget_has_focus (widget)) _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget); return; @@ -5171,7 +5384,7 @@ static gboolean gtk_widget_real_focus (GtkWidget *widget, GtkDirectionType direction) { - if (!GTK_WIDGET_CAN_FOCUS (widget)) + if (!gtk_widget_get_can_focus (widget)) return FALSE; if (!gtk_widget_is_focus (widget)) @@ -5226,6 +5439,74 @@ gtk_widget_real_keynav_failed (GtkWidget *widget, return TRUE; } +/** + * gtk_widget_set_can_focus: + * @widget: a #GtkWidget + * @can_focus: whether or not @widget can own the input focus. + * + * Specifies whether @widget can own the input focus. See + * gtk_widget_grab_focus() for actually setting the input focus on a + * widget. + * + * Since: 2.18 + **/ +void +gtk_widget_set_can_focus (GtkWidget *widget, + gboolean can_focus) +{ + g_return_if_fail (GTK_IS_WIDGET (widget)); + + if (can_focus != gtk_widget_get_can_focus (widget)) + { + if (can_focus) + GTK_OBJECT_FLAGS (widget) |= GTK_CAN_FOCUS; + else + GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_FOCUS); + + gtk_widget_queue_resize (widget); + g_object_notify (G_OBJECT (widget), "can-focus"); + } +} + +/** + * gtk_widget_get_can_focus: + * @widget: a #GtkWidget + * + * Determines whether @widget can own the input focus. See + * gtk_widget_set_can_focus(). + * + * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise + * + * Since: 2.18 + **/ +gboolean +gtk_widget_get_can_focus (GtkWidget *widget) +{ + g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); + + return (GTK_WIDGET_FLAGS (widget) & GTK_CAN_FOCUS) != 0; +} + +/** + * gtk_widget_has_focus: + * @widget: a #GtkWidget + * + * Determines if the widget has the global input focus. See + * gtk_widget_is_focus() for the difference between having the global + * input focus, and only having the focus within a toplevel. + * + * Return value: %TRUE if the widget has the global input focus. + * + * Since: 2.18 + **/ +gboolean +gtk_widget_has_focus (GtkWidget *widget) +{ + g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); + + return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_FOCUS) != 0; +} + /** * gtk_widget_is_focus: * @widget: a #GtkWidget @@ -5252,14 +5533,82 @@ gtk_widget_is_focus (GtkWidget *widget) return FALSE; } +/** + * gtk_widget_set_can_default: + * @widget: a #GtkWidget + * @can_default: whether or not @widget can be a default widget. + * + * Specifies whether @widget can be a default widget. See + * gtk_widget_grab_default() for details about the meaning of + * "default". + * + * Since: 2.18 + **/ +void +gtk_widget_set_can_default (GtkWidget *widget, + gboolean can_default) +{ + g_return_if_fail (GTK_IS_WIDGET (widget)); + + if (can_default != gtk_widget_get_can_default (widget)) + { + if (can_default) + GTK_OBJECT_FLAGS (widget) |= GTK_CAN_DEFAULT; + else + GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_DEFAULT); + + gtk_widget_queue_resize (widget); + g_object_notify (G_OBJECT (widget), "can-default"); + } +} + +/** + * gtk_widget_get_can_default: + * @widget: a #GtkWidget + * + * Determines whether @widget can be a default widget. See + * gtk_widget_set_can_default(). + * + * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise + * + * Since: 2.18 + **/ +gboolean +gtk_widget_get_can_default (GtkWidget *widget) +{ + g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); + + return (GTK_WIDGET_FLAGS (widget) & GTK_CAN_DEFAULT) != 0; +} + +/** + * gtk_widget_has_default: + * @widget: a #GtkWidget + * + * Determines whether @widget is the current default widget within its + * toplevel. See gtk_widget_set_can_default(). + * + * Return value: %TRUE if @widget is the current default widget within + * its toplevel, %FALSE otherwise + * + * Since: 2.18 + */ +gboolean +gtk_widget_has_default (GtkWidget *widget) +{ + g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); + + return (GTK_WIDGET_FLAGS (widget) & GTK_HAS_DEFAULT) != 0; +} + /** * gtk_widget_grab_default: * @widget: a #GtkWidget * * Causes @widget to become the default widget. @widget must have the * %GTK_CAN_DEFAULT flag set; typically you have to set this flag - * yourself by calling GTK_WIDGET_SET_FLAGS (@widget, - * GTK_CAN_DEFAULT). The default widget is activated when + * yourself by calling gtk_widget_set_can_default (@widget, + * %TRUE). The default widget is activated when * the user presses Enter in a window. Default widgets must be * activatable, that is, gtk_widget_activate() should affect them. **/ @@ -5269,16 +5618,91 @@ gtk_widget_grab_default (GtkWidget *widget) GtkWidget *window; g_return_if_fail (GTK_IS_WIDGET (widget)); - g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget)); + g_return_if_fail (gtk_widget_get_can_default (widget)); window = gtk_widget_get_toplevel (widget); - if (window && GTK_WIDGET_TOPLEVEL (window)) + if (window && gtk_widget_is_toplevel (window)) gtk_window_set_default (GTK_WINDOW (window), widget); else g_warning (G_STRLOC ": widget not within a GtkWindow"); } +/** + * gtk_widget_set_receives_default: + * @widget: a #GtkWidget + * @receives_default: whether or not @widget can be a default widget. + * + * Specifies whether @widget will be treated as the default widget + * within its toplevel when it has the focus, even if another widget + * is the default. + * + * See gtk_widget_grab_default() for details about the meaning of + * "default". + * + * Since: 2.18 + **/ +void +gtk_widget_set_receives_default (GtkWidget *widget, + gboolean receives_default) +{ + g_return_if_fail (GTK_IS_WIDGET (widget)); + + if (receives_default != gtk_widget_get_receives_default (widget)) + { + if (receives_default) + GTK_OBJECT_FLAGS (widget) |= GTK_RECEIVES_DEFAULT; + else + GTK_OBJECT_FLAGS (widget) &= ~(GTK_RECEIVES_DEFAULT); + + g_object_notify (G_OBJECT (widget), "receives-default"); + } +} + +/** + * gtk_widget_get_receives_default: + * @widget: a #GtkWidget + * + * Determines whether @widget is alyways treated as default widget + * withing its toplevel when it has the focus, even if another widget + * is the default. + * + * See gtk_widget_set_receives_default(). + * + * Return value: %TRUE if @widget acts as default widget when focussed, + * %FALSE otherwise + * + * Since: 2.18 + **/ +gboolean +gtk_widget_get_receives_default (GtkWidget *widget) +{ + g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); + + return (GTK_WIDGET_FLAGS (widget) & GTK_RECEIVES_DEFAULT) != 0; +} + +/** + * gtk_widget_has_grab: + * @widget: a #GtkWidget + * + * Determines whether the widget is currently grabbing events, so it + * is the only widget receiving input events (keyboard and mouse). + * + * See also gtk_grab_add(). + * + * Return value: %TRUE if the widget is in the grab_widgets stack + * + * Since: 2.18 + **/ +gboolean +gtk_widget_has_grab (GtkWidget *widget) +{ + g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); + + return (GTK_WIDGET_FLAGS (widget) & GTK_HAS_GRAB) != 0; +} + /** * gtk_widget_set_name: * @widget: a #GtkWidget @@ -5304,7 +5728,7 @@ gtk_widget_set_name (GtkWidget *widget, g_free (widget->name); widget->name = new_name; - if (GTK_WIDGET_RC_STYLE (widget)) + if (gtk_widget_has_rc_style (widget)) gtk_widget_reset_rc_style (widget); g_object_notify (G_OBJECT (widget), "name"); @@ -5327,7 +5751,7 @@ gtk_widget_get_name (GtkWidget *widget) if (widget->name) return widget->name; - return g_type_name (GTK_WIDGET_TYPE (widget)); + return G_OBJECT_TYPE_NAME (widget); } /** @@ -5358,27 +5782,269 @@ gtk_widget_set_state (GtkWidget *widget, data.state_restoration = FALSE; data.use_forall = FALSE; if (widget->parent) - data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE); + data.parent_sensitive = (gtk_widget_is_sensitive (widget->parent) != FALSE); else data.parent_sensitive = TRUE; gtk_widget_propagate_state (widget, &data); - if (GTK_WIDGET_DRAWABLE (widget)) + if (gtk_widget_is_drawable (widget)) gtk_widget_queue_draw (widget); } } - /** - * gtk_widget_set_app_paintable: + * gtk_widget_get_state: * @widget: a #GtkWidget - * @app_paintable: %TRUE if the application will paint on the widget * - * Sets whether the application intends to draw on the widget in - * an #GtkWidget::expose-event handler. + * Returns the widget's state. See gtk_widget_set_state(). * - * This is a hint to the widget and does not affect the behavior of + * Returns: the state of @widget. + * + * Since: 2.18 + */ +GtkStateType +gtk_widget_get_state (GtkWidget *widget) +{ + g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL); + + return widget->state; +} + +/** + * gtk_widget_set_visible: + * @widget: a #GtkWidget + * @visible: whether the widget should be shown or not + * + * Sets the visibility state of @widget. Note that setting this to + * %TRUE doesn't mean the widget is actually viewable, see + * gtk_widget_get_visible(). + * + * This function simply calls gtk_widget_show() or gtk_widget_hide() + * but is nicer to use when the visibility of the widget depends on + * some condition. + * + * Since: 2.18 + **/ +void +gtk_widget_set_visible (GtkWidget *widget, + gboolean visible) +{ + g_return_if_fail (GTK_IS_WIDGET (widget)); + + if (visible != gtk_widget_get_visible (widget)) + { + if (visible) + gtk_widget_show (widget); + else + gtk_widget_hide (widget); + } +} + +/** + * gtk_widget_get_visible: + * @widget: a #GtkWidget + * + * Determines whether the widget is visible. Note that this doesn't + * take into account whether the widget's parent is also visible + * or the widget is obscured in any way. + * + * See gtk_widget_set_visible(). + * + * Return value: %TRUE if the widget is visible + * + * Since: 2.18 + **/ +gboolean +gtk_widget_get_visible (GtkWidget *widget) +{ + g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); + + return (GTK_OBJECT_FLAGS (widget) & GTK_VISIBLE) != 0; +} + +/** + * gtk_widget_set_has_window: + * @widget: a #GtkWidget + * @has_window: whether or not @widget has a window. + * + * Specifies whether @widget has a #GdkWindow of its own. Note that + * all realized widgets have a non-%NULL "window" pointer + * (gtk_widget_get_window() never returns a %NULL window when a widget + * is realized), but for many of them it's actually the #GdkWindow of + * one of its parent widgets. Widgets that create a %window for + * themselves in GtkWidget::realize() however must announce this by + * calling this function with @has_window = %TRUE. + * + * This function should only be called by widget implementations, + * and they should call it in their init() function. + * + * Since: 2.18 + **/ +void +gtk_widget_set_has_window (GtkWidget *widget, + gboolean has_window) +{ + g_return_if_fail (GTK_IS_WIDGET (widget)); + + if (has_window) + GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_WINDOW); + else + GTK_WIDGET_SET_FLAGS (widget, GTK_NO_WINDOW); +} + +/** + * gtk_widget_get_has_window: + * @widget: a #GtkWidget + * + * Determines whether @widget has a #GdkWindow of its own. See + * gtk_widget_set_has_window(). + * + * Return value: %TRUE if @widget has a window, %FALSE otherwise + * + * Since: 2.18 + **/ +gboolean +gtk_widget_get_has_window (GtkWidget *widget) +{ + g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); + + return !((GTK_OBJECT_FLAGS (widget) & GTK_NO_WINDOW) != 0); +} + +/** + * gtk_widget_is_toplevel: + * @widget: a #GtkWidget + * + * Determines whether @widget is a toplevel widget. Currently only + * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel + * widgets have no parent widget. + * + * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise + * + * Since: 2.18 + **/ +gboolean +gtk_widget_is_toplevel (GtkWidget *widget) +{ + g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); + + return (GTK_WIDGET_FLAGS (widget) & GTK_TOPLEVEL) != 0; +} + +/** + * gtk_widget_is_drawable: + * @widget: a #GtkWidget + * + * Determines whether @widget can be drawn to. A widget can be drawn + * to if it is mapped and visible. + * + * Return value: %TRUE if @widget is drawable, %FALSE otherwise + * + * Since: 2.18 + **/ +gboolean +gtk_widget_is_drawable (GtkWidget *widget) +{ + g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); + + return ((GTK_WIDGET_FLAGS (widget) & GTK_VISIBLE) != 0 && + (GTK_WIDGET_FLAGS (widget) & GTK_MAPPED) != 0); +} + +/** + * gtk_widget_get_realized: + * @widget: a #GtkWidget + * + * Determines whether @widget is realized. + * + * Return value: %TRUE if @widget is realized, %FALSE otherwise + * + * Since: 2.20 + **/ +gboolean +gtk_widget_get_realized (GtkWidget *widget) +{ + g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); + + return (GTK_WIDGET_FLAGS (widget) & GTK_REALIZED) != 0; +} + +/** + * gtk_widget_set_realized: + * @widget: a #GtkWidget + * @realized: %TRUE to mark the widget as realized + * + * Marks the widget as being realized. + * + * This function should only ever be called in a derived widget's + * "realize" or "unrealize" implementation. + * + * Since: 2.20 + */ +void +gtk_widget_set_realized (GtkWidget *widget, + gboolean realized) +{ + g_return_if_fail (GTK_IS_WIDGET (widget)); + + if (realized) + GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); + else + GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED); +} + +/** + * gtk_widget_get_mapped: + * @widget: a #GtkWidget + * + * Whether the widget is mapped. + * + * Return value: %TRUE if the widget is mapped, %FALSE otherwise. + * + * Since: 2.20 + */ +gboolean +gtk_widget_get_mapped (GtkWidget *widget) +{ + g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); + + return (GTK_OBJECT_FLAGS (widget) & GTK_MAPPED) != 0; +} + +/** + * gtk_widget_set_mapped: + * @widget: a #GtkWidget + * @mapped: %TRUE to mark the widget as mapped + * + * Marks the widget as being realized. + * + * This function should only ever be called in a derived widget's + * "map" or "unmap" implementation. + * + * Since: 2.20 + */ +void +gtk_widget_set_mapped (GtkWidget *widget, + gboolean mapped) +{ + g_return_if_fail (GTK_IS_WIDGET (widget)); + + if (mapped) + GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED); + else + GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED); +} + +/** + * gtk_widget_set_app_paintable: + * @widget: a #GtkWidget + * @app_paintable: %TRUE if the application will paint on the widget + * + * Sets whether the application intends to draw on the widget in + * an #GtkWidget::expose-event handler. + * + * This is a hint to the widget and does not affect the behavior of * the GTK+ core; many widgets ignore this flag entirely. For widgets * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow, * the effect is to suppress default themed drawing of the widget's @@ -5402,20 +6068,41 @@ gtk_widget_set_app_paintable (GtkWidget *widget, app_paintable = (app_paintable != FALSE); - if (GTK_WIDGET_APP_PAINTABLE (widget) != app_paintable) + if (gtk_widget_get_app_paintable (widget) != app_paintable) { if (app_paintable) GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE); else GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE); - if (GTK_WIDGET_DRAWABLE (widget)) + if (gtk_widget_is_drawable (widget)) gtk_widget_queue_draw (widget); g_object_notify (G_OBJECT (widget), "app-paintable"); } } +/** + * gtk_widget_get_app_paintable: + * @widget: a #GtkWidget + * + * Determines whether the application intends to draw on the widget in + * an #GtkWidget::expose-event handler. + * + * See gtk_widget_set_app_paintable() + * + * Return value: %TRUE if the widget is app paintable + * + * Since: 2.18 + **/ +gboolean +gtk_widget_get_app_paintable (GtkWidget *widget) +{ + g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); + + return (GTK_WIDGET_FLAGS (widget) & GTK_APP_PAINTABLE) != 0; +} + /** * gtk_widget_set_double_buffered: * @widget: a #GtkWidget @@ -5446,10 +6133,37 @@ gtk_widget_set_double_buffered (GtkWidget *widget, { g_return_if_fail (GTK_IS_WIDGET (widget)); - if (double_buffered) - GTK_WIDGET_SET_FLAGS (widget, GTK_DOUBLE_BUFFERED); - else - GTK_WIDGET_UNSET_FLAGS (widget, GTK_DOUBLE_BUFFERED); + double_buffered = (double_buffered != FALSE); + + if (double_buffered != gtk_widget_get_double_buffered (widget)) + { + if (double_buffered) + GTK_OBJECT_FLAGS (widget) |= GTK_DOUBLE_BUFFERED; + else + GTK_OBJECT_FLAGS (widget) &= ~(GTK_DOUBLE_BUFFERED); + + g_object_notify (G_OBJECT (widget), "double-buffered"); + } +} + +/** + * gtk_widget_get_double_buffered: + * @widget: a #GtkWidget + * + * Determines whether the widget is double buffered. + * + * See gtk_widget_set_double_buffered() + * + * Return value: %TRUE if the widget is double buffered + * + * Since: 2.18 + **/ +gboolean +gtk_widget_get_double_buffered (GtkWidget *widget) +{ + g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); + + return (GTK_WIDGET_FLAGS (widget) & GTK_DOUBLE_BUFFERED) != 0; } /** @@ -5506,34 +6220,76 @@ gtk_widget_set_sensitive (GtkWidget *widget, sensitive = (sensitive != FALSE); - if (sensitive == (GTK_WIDGET_SENSITIVE (widget) != FALSE)) + if (sensitive == (gtk_widget_get_sensitive (widget) != FALSE)) return; if (sensitive) { - GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE); - data.state = GTK_WIDGET_SAVED_STATE (widget); + GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE; + data.state = widget->saved_state; } else { - GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE); + GTK_OBJECT_FLAGS (widget) &= ~(GTK_SENSITIVE); data.state = GTK_WIDGET_STATE (widget); } data.state_restoration = TRUE; data.use_forall = TRUE; if (widget->parent) - data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE); + data.parent_sensitive = (gtk_widget_is_sensitive (widget->parent) != FALSE); else data.parent_sensitive = TRUE; gtk_widget_propagate_state (widget, &data); - if (GTK_WIDGET_DRAWABLE (widget)) + if (gtk_widget_is_drawable (widget)) gtk_widget_queue_draw (widget); g_object_notify (G_OBJECT (widget), "sensitive"); } +/** + * gtk_widget_get_sensitive: + * @widget: a #GtkWidget + * + * Returns the widget's sensitivity (in the sense of returning + * the value that has been set using gtk_widget_set_sensitive()). + * + * The effective sensitivity of a widget is however determined by both its + * own and its parent widget's sensitivity. See gtk_widget_is_sensitive(). + * + * Returns: %TRUE if the widget is sensitive + * + * Since: 2.18 + */ +gboolean +gtk_widget_get_sensitive (GtkWidget *widget) +{ + g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); + + return (GTK_OBJECT_FLAGS (widget) & GTK_SENSITIVE) != 0; +} + +/** + * gtk_widget_is_sensitive: + * @widget: a #GtkWidget + * + * Returns the widget's effective sensitivity, which means + * it is sensitive itself and also its parent widget is sensntive + * + * Returns: %TRUE if the widget is effectively sensitive + * + * Since: 2.18 + */ +gboolean +gtk_widget_is_sensitive (GtkWidget *widget) +{ + g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); + + return (gtk_widget_get_sensitive (widget) && + (GTK_OBJECT_FLAGS (widget) & GTK_PARENT_SENSITIVE) != 0); +} + /** * gtk_widget_set_parent: * @widget: a #GtkWidget @@ -5560,7 +6316,7 @@ gtk_widget_set_parent (GtkWidget *widget, g_warning ("Can't set a parent on widget which has a parent\n"); return; } - if (GTK_WIDGET_TOPLEVEL (widget)) + if (gtk_widget_is_toplevel (widget)) { g_warning ("Can't set a parent on a toplevel widget\n"); return; @@ -5577,8 +6333,8 @@ gtk_widget_set_parent (GtkWidget *widget, else data.state = GTK_WIDGET_STATE (widget); data.state_restoration = FALSE; - data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (parent) != FALSE); - data.use_forall = GTK_WIDGET_IS_SENSITIVE (parent) != GTK_WIDGET_IS_SENSITIVE (widget); + data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE); + data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget); gtk_widget_propagate_state (widget, &data); @@ -5594,11 +6350,11 @@ gtk_widget_set_parent (GtkWidget *widget, if (GTK_WIDGET_REALIZED (widget->parent)) gtk_widget_realize (widget); - if (GTK_WIDGET_VISIBLE (widget->parent) && - GTK_WIDGET_VISIBLE (widget)) + if (gtk_widget_get_visible (widget->parent) && + gtk_widget_get_visible (widget)) { if (GTK_WIDGET_CHILD_VISIBLE (widget) && - GTK_WIDGET_MAPPED (widget->parent)) + gtk_widget_get_mapped (widget->parent)) gtk_widget_map (widget); gtk_widget_queue_resize (widget); @@ -5611,7 +6367,7 @@ gtk_widget_set_parent (GtkWidget *widget, * * Returns the parent container of @widget. * - * Return value: the parent container of @widget, or %NULL + * Return value: (transfer none): the parent container of @widget, or %NULL **/ GtkWidget * gtk_widget_get_parent (GtkWidget *widget) @@ -5626,10 +6382,56 @@ gtk_widget_get_parent (GtkWidget *widget) * see docs/styles.txt *****************************************/ +/** + * gtk_widget_style_attach: + * @widget: a #GtkWidget + * + * This function attaches the widget's #GtkStyle to the widget's + * #GdkWindow. It is a replacement for + * + * + * widget->style = gtk_style_attach (widget->style, widget->window); + * + * + * and should only ever be called in a derived widget's "realize" + * implementation which does not chain up to its parent class' + * "realize" implementation, because one of the parent classes + * (finally #GtkWidget) would attach the style itself. + * + * Since: 2.20 + **/ +void +gtk_widget_style_attach (GtkWidget *widget) +{ + g_return_if_fail (GTK_IS_WIDGET (widget)); + g_return_if_fail (GTK_WIDGET_REALIZED (widget)); + + widget->style = gtk_style_attach (widget->style, widget->window); +} + +/** + * gtk_widget_has_rc_style: + * @widget: a #GtkWidget + * + * Determines if the widget style has been looked up through the rc mechanism. + * + * Returns: %TRUE if the widget has been looked up through the rc + * mechanism, %FALSE otherwise. + * + * Since: 2.20 + **/ +gboolean +gtk_widget_has_rc_style (GtkWidget *widget) +{ + g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); + + return (GTK_WIDGET_FLAGS (widget) & GTK_RC_STYLE) != 0; +} + /** * gtk_widget_set_style: * @widget: a #GtkWidget - * @style: a #GtkStyle, or %NULL to remove the effect of a previous + * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous * gtk_widget_set_style() and go back to the default style * * Sets the #GtkStyle for a widget (@widget->style). You probably don't @@ -5647,7 +6449,7 @@ gtk_widget_set_style (GtkWidget *widget, { gboolean initial_emission; - initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget); + initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget); GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE); GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE); @@ -5676,7 +6478,7 @@ gtk_widget_ensure_style (GtkWidget *widget) g_return_if_fail (GTK_IS_WIDGET (widget)); if (!GTK_WIDGET_USER_STYLE (widget) && - !GTK_WIDGET_RC_STYLE (widget)) + !gtk_widget_has_rc_style (widget)) gtk_widget_reset_rc_style (widget); } @@ -5689,7 +6491,7 @@ gtk_widget_reset_rc_style (GtkWidget *widget) GtkStyle *new_style = NULL; gboolean initial_emission; - initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget); + initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget); GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE); GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE); @@ -5708,8 +6510,8 @@ gtk_widget_reset_rc_style (GtkWidget *widget) * @widget: a #GtkWidget * * Simply an accessor function that returns @widget->style. - * - * Return value: the widget's #GtkStyle + * + * Return value: (transfer none): the widget's #GtkStyle **/ GtkStyle* gtk_widget_get_style (GtkWidget *widget) @@ -5758,7 +6560,7 @@ gtk_widget_modify_style (GtkWidget *widget, * modifier style and the only reference was our own. */ - if (GTK_WIDGET_RC_STYLE (widget)) + if (gtk_widget_has_rc_style (widget)) gtk_widget_reset_rc_style (widget); } @@ -5778,8 +6580,8 @@ gtk_widget_modify_style (GtkWidget *widget, * the passed-in style and sets the copy as the new modifier style, * thus dropping any reference to the old modifier style. Add a reference * to the modifier style if you want to keep it alive. - * - * Return value: the modifier style for the widget. This rc style is + * + * Return value: (transfer none): the modifier style for the widget. This rc style is * owned by the widget. If you want to keep a pointer to value this * around, you must add a refcount using g_object_ref(). **/ @@ -5844,11 +6646,11 @@ gtk_widget_modify_color_component (GtkWidget *widget, * gtk_widget_modify_fg: * @widget: a #GtkWidget * @state: the state for which to set the foreground color - * @color: the color to assign (does not need to be allocated), + * @color: (allow-none): the color to assign (does not need to be allocated), * or %NULL to undo the effect of previous calls to * of gtk_widget_modify_fg(). - * - * Sets the foreground color for a widget in a particular state. + * + * Sets the foreground color for a widget in a particular state. * All other style values are left untouched. See also * gtk_widget_modify_style(). **/ @@ -5867,11 +6669,11 @@ gtk_widget_modify_fg (GtkWidget *widget, * gtk_widget_modify_bg: * @widget: a #GtkWidget * @state: the state for which to set the background color - * @color: the color to assign (does not need to be allocated), + * @color: (allow-none): the color to assign (does not need to be allocated), * or %NULL to undo the effect of previous calls to * of gtk_widget_modify_bg(). - * - * Sets the background color for a widget in a particular state. + * + * Sets the background color for a widget in a particular state. * All other style values are left untouched. See also * gtk_widget_modify_style(). * @@ -5898,10 +6700,10 @@ gtk_widget_modify_bg (GtkWidget *widget, * gtk_widget_modify_text: * @widget: a #GtkWidget * @state: the state for which to set the text color - * @color: the color to assign (does not need to be allocated), + * @color: (allow-none): the color to assign (does not need to be allocated), * or %NULL to undo the effect of previous calls to * of gtk_widget_modify_text(). - * + * * Sets the text color for a widget in a particular state. All other * style values are left untouched. The text color is the foreground * color used along with the base color (see gtk_widget_modify_base()) @@ -5923,10 +6725,10 @@ gtk_widget_modify_text (GtkWidget *widget, * gtk_widget_modify_base: * @widget: a #GtkWidget * @state: the state for which to set the base color - * @color: the color to assign (does not need to be allocated), + * @color: (allow-none): the color to assign (does not need to be allocated), * or %NULL to undo the effect of previous calls to * of gtk_widget_modify_base(). - * + * * Sets the base color for a widget in a particular state. * All other style values are left untouched. The base color * is the background color used along with the text color @@ -6019,9 +6821,9 @@ gtk_widget_modify_cursor (GtkWidget *widget, /** * gtk_widget_modify_font: * @widget: a #GtkWidget - * @font_desc: the font description to use, or %NULL to undo + * @font_desc: (allow-none): the font description to use, or %NULL to undo * the effect of previous calls to gtk_widget_modify_font(). - * + * * Sets the font to use for a widget. All other style values are left * untouched. See also gtk_widget_modify_style(). **/ @@ -6058,7 +6860,7 @@ gtk_widget_real_style_set (GtkWidget *widget, GtkStyle *previous_style) { if (GTK_WIDGET_REALIZED (widget) && - !GTK_WIDGET_NO_WINDOW (widget)) + gtk_widget_get_has_window (widget)) gtk_style_set_background (widget->style, widget->window, widget->state); } @@ -6140,7 +6942,7 @@ gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget, gpointer client_data) { HierarchyChangedInfo *info = client_data; - gboolean new_anchored = GTK_WIDGET_TOPLEVEL (widget) || + gboolean new_anchored = gtk_widget_is_toplevel (widget) || (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)); if (GTK_WIDGET_ANCHORED (widget) != new_anchored) @@ -6182,7 +6984,7 @@ _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget, info.previous_toplevel = previous_toplevel; info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL; - if (GTK_WIDGET_TOPLEVEL (widget) || + if (gtk_widget_is_toplevel (widget) || (widget->parent && GTK_WIDGET_ANCHORED (widget->parent))) info.new_screen = gtk_widget_get_screen (widget); else @@ -6229,8 +7031,7 @@ gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget, * * Please note that the semantics of this call will change * in the future if used on a widget that has a composited - * window in its heirarchy (as set by - * gdk_window_set_composited()). + * window in its hierarchy (as set by gdk_window_set_composited()). * * Return value: %TRUE if the widget can rely on its alpha * channel being drawn correctly. @@ -6298,7 +7099,7 @@ _gtk_widget_propagate_screen_changed (GtkWidget *widget, static void reset_rc_styles_recurse (GtkWidget *widget, gpointer data) { - if (GTK_WIDGET_RC_STYLE (widget)) + if (gtk_widget_has_rc_style (widget)) gtk_widget_reset_rc_style (widget); if (GTK_IS_CONTAINER (widget)) @@ -6307,6 +7108,17 @@ reset_rc_styles_recurse (GtkWidget *widget, gpointer data) NULL); } + +/** + * gtk_widget_reset_rc_styles: + * @widget: a #GtkWidget. + * + * Reset the styles of @widget and all descendents, so when + * they are looked up again, they get the correct values + * for the currently loaded RC file settings. + * + * This function is not useful for applications. + */ void gtk_widget_reset_rc_styles (GtkWidget *widget) { @@ -6319,10 +7131,10 @@ gtk_widget_reset_rc_styles (GtkWidget *widget) * gtk_widget_get_default_style: * * Returns the default style used by all widgets initially. - * - * Returns: the default style. This #GtkStyle object is owned + * + * Returns: (transfer none): the default style. This #GtkStyle object is owned * by GTK+ and should not be modified or freed. - */ + */ GtkStyle* gtk_widget_get_default_style (void) { @@ -6357,7 +7169,7 @@ gtk_widget_peek_pango_context (GtkWidget *widget) * on the layout in response to the #GtkWidget::style-set and * #GtkWidget::direction-changed signals for the widget. * - * Return value: the #PangoContext for the widget. + * Return value: (transfer none): the #PangoContext for the widget. **/ PangoContext * gtk_widget_get_pango_context (GtkWidget *widget) @@ -6485,11 +7297,11 @@ gtk_widget_create_pango_layout (GtkWidget *widget, * gtk_widget_render_icon: * @widget: a #GtkWidget * @stock_id: a stock ID - * @size: a stock size. A size of (GtkIconSize)-1 means render at - * the size of the source and don't scale (if there are multiple - * source sizes, GTK+ picks one of the available sizes). - * @detail: render detail to pass to theme engine - * + * @size: (type int) a stock size. A size of (GtkIconSize)-1 means + * render at the size of the source and don't scale (if there are + * multiple source sizes, GTK+ picks one of the available sizes). + * @detail: (allow-none): render detail to pass to theme engine + * * A convenience function that uses the theme engine and RC file * settings for @widget to look up @stock_id and render it to * a pixbuf. @stock_id should be a stock icon ID such as @@ -6567,9 +7379,10 @@ gtk_widget_set_parent_window (GtkWidget *widget, /** * gtk_widget_get_parent_window: * @widget: a #GtkWidget. - * @returns: the parent window of @widget. * * Gets @widget's parent window. + * + * Returns: (transfer none): the parent window of @widget. **/ GdkWindow * gtk_widget_get_parent_window (GtkWidget *widget) @@ -6613,7 +7426,7 @@ gtk_widget_set_child_visible (GtkWidget *widget, gboolean is_visible) { g_return_if_fail (GTK_IS_WIDGET (widget)); - g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget)); + g_return_if_fail (!gtk_widget_is_toplevel (widget)); g_object_ref (widget); @@ -6626,15 +7439,15 @@ gtk_widget_set_child_visible (GtkWidget *widget, GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE); toplevel = gtk_widget_get_toplevel (widget); - if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel)) + if (toplevel != widget && gtk_widget_is_toplevel (toplevel)) _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget); } if (widget->parent && GTK_WIDGET_REALIZED (widget->parent)) { - if (GTK_WIDGET_MAPPED (widget->parent) && + if (gtk_widget_get_mapped (widget->parent) && GTK_WIDGET_CHILD_VISIBLE (widget) && - GTK_WIDGET_VISIBLE (widget)) + gtk_widget_get_visible (widget)) gtk_widget_map (widget); else gtk_widget_unmap (widget); @@ -6671,7 +7484,7 @@ gtk_widget_get_screen_unchecked (GtkWidget *widget) toplevel = gtk_widget_get_toplevel (widget); - if (GTK_WIDGET_TOPLEVEL (toplevel)) + if (gtk_widget_is_toplevel (toplevel)) { if (GTK_IS_WINDOW (toplevel)) return GTK_WINDOW (toplevel)->screen; @@ -6694,8 +7507,8 @@ gtk_widget_get_screen_unchecked (GtkWidget *widget) * In general, you should only create screen specific * resources when a widget has been realized, and you should * free those resources when the widget is unrealized. - * - * Return value: the #GdkScreen for the toplevel for this widget. + * + * Return value: (transfer none): the #GdkScreen for the toplevel for this widget. * * Since: 2.2 **/ @@ -6729,7 +7542,7 @@ gtk_widget_get_screen (GtkWidget *widget) * * Checks whether there is a #GdkScreen is associated with * this widget. All toplevel widgets have an associated - * screen, and all widgets added into a heirarchy with a toplevel + * screen, and all widgets added into a hierarchy with a toplevel * window at the top. * * Return value: %TRUE if there is a #GdkScreen associcated @@ -6756,8 +7569,8 @@ gtk_widget_has_screen (GtkWidget *widget) * In general, you should only create display specific * resources when a widget has been realized, and you should * free those resources when the widget is unrealized. - * - * Return value: the #GdkDisplay for the toplevel for this widget. + * + * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget. * * Since: 2.2 **/ @@ -6775,14 +7588,14 @@ gtk_widget_get_display (GtkWidget *widget) * * Get the root window where this widget is located. This function can * only be called after the widget has been added to a widget - * heirarchy with #GtkWindow at the top. + * hierarchy with #GtkWindow at the top. * * The root window is useful for such purposes as creating a popup * #GdkWindow associated with the window. In general, you should only * create display specific resources when a widget has been realized, * and you should free those resources when the widget is unrealized. - * - * Return value: the #GdkWindow root window for the toplevel for this widget. + * + * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget. * * Since: 2.2 **/ @@ -6835,15 +7648,15 @@ gtk_widget_child_focus (GtkWidget *widget, g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); - if (!GTK_WIDGET_VISIBLE (widget) || - !GTK_WIDGET_IS_SENSITIVE (widget)) + if (!gtk_widget_get_visible (widget) || + !gtk_widget_is_sensitive (widget)) return FALSE; /* child widgets must set CAN_FOCUS, containers * don't have to though. */ if (!GTK_IS_CONTAINER (widget) && - !GTK_WIDGET_CAN_FOCUS (widget)) + !gtk_widget_get_can_focus (widget)) return FALSE; g_signal_emit (widget, @@ -6928,11 +7741,16 @@ gtk_widget_keynav_failed (GtkWidget *widget, void gtk_widget_error_bell (GtkWidget *widget) { + GtkSettings* settings; gboolean beep; g_return_if_fail (GTK_IS_WIDGET (widget)); - g_object_get (gtk_widget_get_settings (widget), + settings = gtk_widget_get_settings (widget); + if (!settings) + return; + + g_object_get (settings, "gtk-error-bell", &beep, NULL); @@ -7006,7 +7824,7 @@ gtk_widget_set_uposition (GtkWidget *widget, if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set) _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y); - if (GTK_WIDGET_VISIBLE (widget) && widget->parent) + if (gtk_widget_get_visible (widget) && widget->parent) gtk_widget_size_allocate (widget, &widget->allocation); } @@ -7035,7 +7853,7 @@ gtk_widget_set_usize_internal (GtkWidget *widget, changed = TRUE; } - if (GTK_WIDGET_VISIBLE (widget) && changed) + if (gtk_widget_get_visible (widget) && changed) gtk_widget_queue_resize (widget); g_object_thaw_notify (G_OBJECT (widget)); @@ -7134,8 +7952,8 @@ gtk_widget_set_size_request (GtkWidget *widget, /** * gtk_widget_get_size_request: * @widget: a #GtkWidget - * @width: return location for width, or %NULL - * @height: return location for height, or %NULL + * @width: (allow-none): (out): return location for width, or %NULL + * @height: (allow-none): (out): return location for height, or %NULL * * Gets the size request that was explicitly set for the widget using * gtk_widget_set_size_request(). A value of -1 stored in @width or @@ -7241,7 +8059,7 @@ gtk_widget_add_events (GtkWidget *widget, { GList *window_list; - if (GTK_WIDGET_NO_WINDOW (widget)) + if (!gtk_widget_get_has_window (widget)) window_list = gdk_window_get_children (widget->window); else window_list = g_list_prepend (NULL, widget->window); @@ -7299,13 +8117,13 @@ gtk_widget_set_extension_events (GtkWidget *widget, * is set on the result. * |[ * GtkWidget *toplevel = gtk_widget_get_toplevel (widget); - * if (GTK_WIDGET_TOPLEVEL (toplevel)) + * if (gtk_widget_is_toplevel (toplevel)) * { * /* Perform action on toplevel. */ * } * ]| * - * Return value: the topmost ancestor of @widget, or @widget itself + * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself * if there's no ancestor. **/ GtkWidget* @@ -7334,7 +8152,7 @@ gtk_widget_get_toplevel (GtkWidget *widget) * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor() * considers @widget to be an ancestor of itself. * - * Return value: the ancestor widget, or %NULL if not found + * Return value: (transfer none): the ancestor widget, or %NULL if not found **/ GtkWidget* gtk_widget_get_ancestor (GtkWidget *widget, @@ -7342,10 +8160,10 @@ gtk_widget_get_ancestor (GtkWidget *widget, { g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); - while (widget && !g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)) + while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type)) widget = widget->parent; - if (!(widget && g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))) + if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type))) return NULL; return widget; @@ -7357,8 +8175,8 @@ gtk_widget_get_ancestor (GtkWidget *widget, * * Gets the colormap that will be used to render @widget. No reference will * be added to the returned colormap; it should not be unreferenced. - * - * Return value: the colormap used by @widget + * + * Return value: (transfer none): the colormap used by @widget **/ GdkColormap* gtk_widget_get_colormap (GtkWidget *widget) @@ -7394,8 +8212,8 @@ gtk_widget_get_colormap (GtkWidget *widget) * @widget: a #GtkWidget * * Gets the visual that will be used to render @widget. - * - * Return value: the visual for @widget + * + * Return value: (transfer none): the visual for @widget **/ GdkVisual* gtk_widget_get_visual (GtkWidget *widget) @@ -7415,8 +8233,8 @@ gtk_widget_get_visual (GtkWidget *widget) * Note that this function can only be called when the #GtkWidget * is attached to a toplevel, since the settings object is specific * to a particular #GdkScreen. - * - * Return value: the relevant #GtkSettings object + * + * Return value: (transfer none): the relevant #GtkSettings object **/ GtkSettings* gtk_widget_get_settings (GtkWidget *widget) @@ -7490,8 +8308,8 @@ gtk_widget_get_extension_events (GtkWidget *widget) /** * gtk_widget_get_pointer: * @widget: a #GtkWidget - * @x: return location for the X coordinate, or %NULL - * @y: return location for the Y coordinate, or %NULL + * @x: (out) (allow-none): return location for the X coordinate, or %NULL + * @y: (out) (allow-none): return location for the Y coordinate, or %NULL * * Obtains the location of the mouse pointer in widget coordinates. * Widget coordinates are a bit odd; for historical reasons, they are @@ -7515,7 +8333,7 @@ gtk_widget_get_pointer (GtkWidget *widget, { gdk_window_get_pointer (widget->window, x, y, NULL); - if (GTK_WIDGET_NO_WINDOW (widget)) + if (!gtk_widget_get_has_window (widget)) { if (x) *x -= widget->allocation.x; @@ -7568,7 +8386,7 @@ gtk_widget_set_composite_name (GtkWidget *widget, const gchar *name) { g_return_if_fail (GTK_IS_WIDGET (widget)); - g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget)); + g_return_if_fail ((GTK_WIDGET_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0); g_return_if_fail (name != NULL); if (!quark_composite_name) @@ -7595,7 +8413,7 @@ gtk_widget_get_composite_name (GtkWidget *widget) { g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); - if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent) + if (((GTK_WIDGET_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0) && widget->parent) return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent), widget); else @@ -7693,8 +8511,8 @@ gtk_widget_set_default_colormap (GdkColormap *colormap) * gtk_widget_get_default_colormap: * * Obtains the default colormap used to create widgets. - * - * Return value: default widget colormap + * + * Return value: (transfer none): default widget colormap **/ GdkColormap* gtk_widget_get_default_colormap (void) @@ -7707,8 +8525,8 @@ gtk_widget_get_default_colormap (void) * * Obtains the visual of the default colormap. Not really useful; * used to be useful before gdk_colormap_get_visual() existed. - * - * Return value: visual of the default colormap + * + * Return value: (transfer none): visual of the default colormap **/ GdkVisual* gtk_widget_get_default_visual (void) @@ -7863,7 +8681,7 @@ gtk_widget_dispose (GObject *object) if (widget->parent) gtk_container_remove (GTK_CONTAINER (widget->parent), widget); - else if (GTK_WIDGET_VISIBLE (widget)) + else if (gtk_widget_get_visible (widget)) gtk_widget_hide (widget); GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE); @@ -7933,11 +8751,11 @@ gtk_widget_real_map (GtkWidget *widget) { g_assert (GTK_WIDGET_REALIZED (widget)); - if (!GTK_WIDGET_MAPPED (widget)) + if (!gtk_widget_get_mapped (widget)) { GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED); - if (!GTK_WIDGET_NO_WINDOW (widget)) + if (gtk_widget_get_has_window (widget)) gdk_window_show (widget->window); } } @@ -7953,11 +8771,11 @@ gtk_widget_real_map (GtkWidget *widget) static void gtk_widget_real_unmap (GtkWidget *widget) { - if (GTK_WIDGET_MAPPED (widget)) + if (gtk_widget_get_mapped (widget)) { GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED); - if (!GTK_WIDGET_NO_WINDOW (widget)) + if (gtk_widget_get_has_window (widget)) gdk_window_hide (widget->window); } } @@ -7973,7 +8791,7 @@ gtk_widget_real_unmap (GtkWidget *widget) static void gtk_widget_real_realize (GtkWidget *widget) { - g_assert (GTK_WIDGET_NO_WINDOW (widget)); + g_assert (!gtk_widget_get_has_window (widget)); GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); if (widget->parent) @@ -7995,7 +8813,7 @@ gtk_widget_real_realize (GtkWidget *widget) static void gtk_widget_real_unrealize (GtkWidget *widget) { - if (GTK_WIDGET_MAPPED (widget)) + if (gtk_widget_get_mapped (widget)) gtk_widget_real_unmap (widget); GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED); @@ -8015,7 +8833,7 @@ gtk_widget_real_unrealize (GtkWidget *widget) NULL); gtk_style_detach (widget->style); - if (!GTK_WIDGET_NO_WINDOW (widget)) + if (gtk_widget_get_has_window (widget)) { gdk_window_set_user_data (widget->window, NULL); gdk_window_destroy (widget->window); @@ -8055,42 +8873,49 @@ _gtk_widget_peek_colormap (void) return NULL; } -/** +/* * _gtk_widget_set_pointer_window: * @widget: a #GtkWidget. * @pointer_window: the new pointer window. - * + * * Sets pointer window for @widget. Does not ref @pointer_window. * Actually stores it on the #GdkScreen, but you don't need to know that. - **/ + */ void -_gtk_widget_set_pointer_window (GtkWidget *widget, - GdkWindow *pointer_window) +_gtk_widget_set_pointer_window (GtkWidget *widget, + GdkWindow *pointer_window) { - GdkScreen *screen; - g_return_if_fail (GTK_IS_WIDGET (widget)); - screen = gdk_drawable_get_screen (GDK_DRAWABLE (widget->window)); - g_object_set_qdata (G_OBJECT (screen), quark_pointer_window, pointer_window); + if (GTK_WIDGET_REALIZED (widget)) + { + GdkScreen *screen = gdk_drawable_get_screen (widget->window); + + g_object_set_qdata (G_OBJECT (screen), quark_pointer_window, + pointer_window); + } } -/** +/* * _gtk_widget_get_pointer_window: * @widget: a #GtkWidget. * * Return value: the pointer window set on the #GdkScreen @widget is attached * to, or %NULL. - **/ + */ GdkWindow * -_gtk_widget_get_pointer_window (GtkWidget *widget) +_gtk_widget_get_pointer_window (GtkWidget *widget) { - GdkScreen *screen; - g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); - screen = gdk_drawable_get_screen (GDK_DRAWABLE (widget->window)); - return g_object_get_qdata (G_OBJECT (screen), quark_pointer_window); + if (GTK_WIDGET_REALIZED (widget)) + { + GdkScreen *screen = gdk_drawable_get_screen (widget->window); + + return g_object_get_qdata (G_OBJECT (screen), quark_pointer_window); + } + + return NULL; } static void @@ -8124,25 +8949,24 @@ synth_crossing (GtkWidget *widget, gdk_event_free (event); } -/** +/* * _gtk_widget_is_pointer_widget: * @widget: a #GtkWidget * * Returns %TRUE if the pointer window belongs to @widget. - * */ gboolean _gtk_widget_is_pointer_widget (GtkWidget *widget) { if (GTK_WIDGET_HAS_POINTER (widget)) - { - GdkWindow *win; + { + GdkWindow *win; GtkWidget *wid; win = _gtk_widget_get_pointer_window (widget); if (win) - { - gdk_window_get_user_data (win, &wid); + { + gdk_window_get_user_data (win, (gpointer *)&wid); if (wid == widget) return TRUE; } @@ -8151,7 +8975,7 @@ _gtk_widget_is_pointer_widget (GtkWidget *widget) return FALSE; } -/** +/* * _gtk_widget_synthesize_crossing: * @from: the #GtkWidget the virtual pointer is leaving. * @to: the #GtkWidget the virtual pointer is moving to. @@ -8207,13 +9031,10 @@ _gtk_widget_synthesize_crossing (GtkWidget *from, while (from_ancestor != NULL) { - if (from_ancestor != NULL) - { - from_ancestor = gdk_window_get_parent (from_ancestor); - if (from_ancestor == NULL) - break; - from_ancestors = g_list_prepend (from_ancestors, from_ancestor); - } + from_ancestor = gdk_window_get_parent (from_ancestor); + if (from_ancestor == NULL) + break; + from_ancestors = g_list_prepend (from_ancestors, from_ancestor); } synth_crossing (from, GDK_LEAVE_NOTIFY, from_window, @@ -8235,14 +9056,11 @@ _gtk_widget_synthesize_crossing (GtkWidget *from, while (to_ancestor != NULL) { - if (to_ancestor != NULL) - { - to_ancestor = gdk_window_get_parent (to_ancestor); - if (to_ancestor == NULL) - break; - to_ancestors = g_list_prepend (to_ancestors, to_ancestor); - } - } + to_ancestor = gdk_window_get_parent (to_ancestor); + if (to_ancestor == NULL) + break; + to_ancestors = g_list_prepend (to_ancestors, to_ancestor); + } /* XXX: leave/inferior on root window? */ @@ -8270,14 +9088,16 @@ _gtk_widget_synthesize_crossing (GtkWidget *from, from_ancestor = gdk_window_get_parent (from_ancestor); if (from_ancestor == to_window) break; - from_ancestors = g_list_prepend (from_ancestors, from_ancestor); + if (from_ancestor) + from_ancestors = g_list_prepend (from_ancestors, from_ancestor); } if (to_ancestor != NULL) { to_ancestor = gdk_window_get_parent (to_ancestor); if (to_ancestor == from_window) break; - to_ancestors = g_list_prepend (to_ancestors, to_ancestor); + if (to_ancestor) + to_ancestors = g_list_prepend (to_ancestors, to_ancestor); } } if (to_ancestor == from_window) @@ -8340,7 +9160,7 @@ gtk_widget_propagate_state (GtkWidget *widget, GtkStateData *data) { guint8 old_state = GTK_WIDGET_STATE (widget); - guint8 old_saved_state = GTK_WIDGET_SAVED_STATE (widget); + guint8 old_saved_state = widget->saved_state; /* don't call this function with state==GTK_STATE_INSENSITIVE, * parent_sensitive==TRUE on a sensitive widget @@ -8352,10 +9172,10 @@ gtk_widget_propagate_state (GtkWidget *widget, else GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE); - if (GTK_WIDGET_IS_SENSITIVE (widget)) + if (gtk_widget_is_sensitive (widget)) { if (data->state_restoration) - GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget); + GTK_WIDGET_STATE (widget) = widget->saved_state; else GTK_WIDGET_STATE (widget) = data->state; } @@ -8364,35 +9184,35 @@ gtk_widget_propagate_state (GtkWidget *widget, if (!data->state_restoration) { if (data->state != GTK_STATE_INSENSITIVE) - GTK_WIDGET_SAVED_STATE (widget) = data->state; + widget->saved_state = data->state; } else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE) - GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget); + widget->saved_state = GTK_WIDGET_STATE (widget); GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE; } - if (gtk_widget_is_focus (widget) && !GTK_WIDGET_IS_SENSITIVE (widget)) + if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget)) { GtkWidget *window; window = gtk_widget_get_toplevel (widget); - if (window && GTK_WIDGET_TOPLEVEL (window)) + if (window && gtk_widget_is_toplevel (window)) gtk_window_set_focus (GTK_WINDOW (window), NULL); } if (old_state != GTK_WIDGET_STATE (widget) || - old_saved_state != GTK_WIDGET_SAVED_STATE (widget)) + old_saved_state != widget->saved_state) { g_object_ref (widget); - if (!GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_HAS_GRAB (widget)) + if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget)) gtk_grab_remove (widget); g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state); if (GTK_WIDGET_HAS_POINTER (widget) && !GTK_WIDGET_SHADOWED (widget)) { - if (!GTK_WIDGET_IS_SENSITIVE (widget)) + if (!gtk_widget_is_sensitive (widget)) _gtk_widget_synthesize_crossing (widget, NULL, GDK_CROSSING_STATE_CHANGED); else if (old_state == GTK_STATE_INSENSITIVE) @@ -8402,7 +9222,7 @@ gtk_widget_propagate_state (GtkWidget *widget, if (GTK_IS_CONTAINER (widget)) { - data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE); + data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE); if (data->use_forall) gtk_container_forall (GTK_CONTAINER (widget), (GtkCallback) gtk_widget_propagate_state, @@ -8416,7 +9236,7 @@ gtk_widget_propagate_state (GtkWidget *widget, } } -/** +/* * _gtk_widget_get_aux_info: * @widget: a #GtkWidget * @create: if %TRUE, create the structure if it doesn't exist @@ -8425,7 +9245,7 @@ gtk_widget_propagate_state (GtkWidget *widget, * * Return value: the #GtkAuxInfo structure for the widget, or * %NULL if @create is %FALSE and one doesn't already exist. - **/ + */ GtkWidgetAuxInfo* _gtk_widget_get_aux_info (GtkWidget *widget, gboolean create) @@ -8473,7 +9293,7 @@ gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info) /** * gtk_widget_shape_combine_mask: * @widget: a #GtkWidget - * @shape_mask: shape to be added, or %NULL to remove an existing shape + * @shape_mask: (allow-none): shape to be added, or %NULL to remove an existing shape * @offset_x: X position of shape mask with respect to @window * @offset_y: Y position of shape mask with respect to @window * @@ -8491,7 +9311,7 @@ gtk_widget_shape_combine_mask (GtkWidget *widget, g_return_if_fail (GTK_IS_WIDGET (widget)); /* set_shape doesn't work on widgets without gdk window */ - g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget)); + g_return_if_fail (gtk_widget_get_has_window (widget)); if (!shape_mask) { @@ -8524,12 +9344,12 @@ gtk_widget_shape_combine_mask (GtkWidget *widget, } /** - * gtk_widget_input_shape_combine_mask: + * gtk_widget_input_shape_combine_mask: * @widget: a #GtkWidget - * @shape_mask: shape to be added, or %NULL to remove an existing shape + * @shape_mask: (allow-none): shape to be added, or %NULL to remove an existing shape * @offset_x: X position of shape mask with respect to @window * @offset_y: Y position of shape mask with respect to @window - * + * * Sets an input shape for this widget's GDK window. This allows for * windows which react to mouse click in a nonrectangular region, see * gdk_window_input_shape_combine_mask() for more information. @@ -8546,7 +9366,7 @@ gtk_widget_input_shape_combine_mask (GtkWidget *widget, g_return_if_fail (GTK_IS_WIDGET (widget)); /* set_shape doesn't work on widgets without gdk window */ - g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget)); + g_return_if_fail (gtk_widget_get_has_window (widget)); if (!shape_mask) { @@ -8645,10 +9465,59 @@ gtk_widget_unref (GtkWidget *widget) g_object_unref ((GObject*) widget); } +static void +expose_window (GdkWindow *window) +{ + GdkEvent event; + GList *l, *children; + gpointer user_data; + gboolean is_double_buffered; + + gdk_window_get_user_data (window, &user_data); + + if (user_data) + is_double_buffered = gtk_widget_get_double_buffered (GTK_WIDGET (user_data)); + else + is_double_buffered = FALSE; + + event.expose.type = GDK_EXPOSE; + event.expose.window = g_object_ref (window); + event.expose.send_event = FALSE; + event.expose.count = 0; + event.expose.area.x = 0; + event.expose.area.y = 0; + gdk_drawable_get_size (GDK_DRAWABLE (window), + &event.expose.area.width, + &event.expose.area.height); + event.expose.region = gdk_region_rectangle (&event.expose.area); + + /* If this is not double buffered, force a double buffer so that + redirection works. */ + if (!is_double_buffered) + gdk_window_begin_paint_region (window, event.expose.region); + + gtk_main_do_event (&event); + + if (!is_double_buffered) + gdk_window_end_paint (window); + + children = gdk_window_peek_children (window); + for (l = children; l != NULL; l = l->next) + { + GdkWindow *child = l->data; + + /* Don't expose input-only windows */ + if (gdk_drawable_get_depth (GDK_DRAWABLE (child)) != 0) + expose_window (l->data); + } + + g_object_unref (window); +} + /** * gtk_widget_get_snapshot: * @widget: a #GtkWidget - * @clip_rect: a #GdkRectangle or %NULL + * @clip_rect: (allow-none): a #GdkRectangle or %NULL * * Create a #GdkPixmap of the contents of the widget and its children. * @@ -8691,7 +9560,7 @@ gtk_widget_get_snapshot (GtkWidget *widget, GList *windows = NULL, *list; g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); - if (!GTK_WIDGET_VISIBLE (widget)) + if (!gtk_widget_get_visible (widget)) return NULL; /* the widget (and parent_window) must be realized to be drawable */ @@ -8706,7 +9575,7 @@ gtk_widget_get_snapshot (GtkWidget *widget, width = widget->allocation.width; height = widget->allocation.height; - if (widget->parent && !GTK_WIDGET_NO_WINDOW (widget)) + if (widget->parent && gtk_widget_get_has_window (widget)) { /* grow snapshot rectangle to cover all widget windows */ parent_window = gtk_widget_get_parent_window (widget); @@ -8779,22 +9648,19 @@ gtk_widget_get_snapshot (GtkWidget *widget, { GdkWindow *subwin = list->data; int wx, wy; + if (gdk_drawable_get_depth (GDK_DRAWABLE (subwin)) == 0) + continue; /* Input only window */ gdk_window_get_position (subwin, &wx, &wy); gdk_window_redirect_to_drawable (subwin, pixmap, MAX (0, x - wx), MAX (0, y - wy), MAX (0, wx - x), MAX (0, wy - y), width, height); - gdk_window_invalidate_rect (subwin, NULL, TRUE); + + expose_window (subwin); } if (!windows) /* NO_WINDOW || toplevel => parent_window == NULL || parent_window == widget->window */ { gdk_window_redirect_to_drawable (widget->window, pixmap, x, y, 0, 0, width, height); - gdk_window_invalidate_rect (widget->window, NULL, TRUE); + expose_window (widget->window); } - gtk_widget_queue_draw (widget); - if (parent_window) - gdk_window_process_updates (parent_window, TRUE); - for (list = windows; list; list = list->next) - gdk_window_process_updates (list->data, TRUE); - gdk_window_process_updates (widget->window, TRUE); for (list = windows; list; list = list->next) gdk_window_remove_redirection (list->data); if (!windows) /* NO_WINDOW || toplevel */ @@ -8882,7 +9748,7 @@ gtk_widget_class_install_style_property (GtkWidgetClass *klass, * gtk_widget_class_find_style_property: * @klass: a #GtkWidgetClass * @property_name: the name of the style property to find - * @returns: the #GParamSpec of the style property or %NULL if @class has no + * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no * style property with that name. * * Finds a style property of a widget class by name. @@ -9069,9 +9935,9 @@ gtk_widget_style_get (GtkWidget *widget, /** * gtk_widget_path: * @widget: a #GtkWidget - * @path_length: location to store length of the path, or %NULL - * @path: location to store allocated path string, or %NULL - * @path_reversed: location to store allocated reverse path string, or %NULL + * @path_length: (out) (allow-none): location to store length of the path, or %NULL + * @path: (out) (allow-none): location to store allocated path string, or %NULL + * @path_reversed: (out) (allow-none): location to store allocated reverse path string, or %NULL * * Obtains the full path to @widget. The path is simply the name of a * widget and all its parents in the container hierarchy, separated by @@ -9142,9 +10008,9 @@ gtk_widget_path (GtkWidget *widget, /** * gtk_widget_class_path: * @widget: a #GtkWidget - * @path_length: location to store the length of the class path, or %NULL - * @path: location to store the class path as an allocated string, or %NULL - * @path_reversed: location to store the reverse class path as an allocated + * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL + * @path: (out) (allow-none) location to store the class path as an allocated string, or %NULL + * @path_reversed: (out) (allow-none) location to store the reverse class path as an allocated * string, or %NULL * * Same as gtk_widget_path(), but always uses the name of a widget's type, @@ -9171,7 +10037,7 @@ gtk_widget_class_path (GtkWidget *widget, gchar *d; guint l; - string = g_type_name (GTK_WIDGET_TYPE (widget)); + string = g_type_name (G_OBJECT_TYPE (widget)); l = strlen (string); while (tmp_path_len <= len + l + 1) { @@ -9259,10 +10125,10 @@ gtk_requisition_get_type (void) * * The documentation of the ATK * library contains more information about accessible objects and their uses. - * - * Returns: the #AtkObject associated with @widget + * + * Returns: (transfer none): the #AtkObject associated with @widget */ -AtkObject* +AtkObject* gtk_widget_get_accessible (GtkWidget *widget) { GtkWidgetClass *klass; @@ -9328,6 +10194,7 @@ gtk_widget_ref_accessible (AtkImplementor *implementor) static GQuark quark_builder_has_default = 0; static GQuark quark_builder_has_focus = 0; static GQuark quark_builder_atk_relations = 0; +static GQuark quark_builder_set_name = 0; static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface) @@ -9335,6 +10202,7 @@ gtk_widget_buildable_interface_init (GtkBuildableIface *iface) quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default"); quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus"); quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations"); + quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name"); iface->set_name = gtk_widget_buildable_set_name; iface->get_name = gtk_widget_buildable_get_name; @@ -9349,13 +10217,14 @@ static void gtk_widget_buildable_set_name (GtkBuildable *buildable, const gchar *name) { - gtk_widget_set_name (GTK_WIDGET (buildable), name); + g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name, + g_strdup (name), g_free); } static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable) { - return gtk_widget_get_name (GTK_WIDGET (buildable)); + return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name); } static GObject * @@ -9385,12 +10254,16 @@ gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable, g_object_set_property (G_OBJECT (buildable), name, value); } -typedef struct { +typedef struct +{ gchar *action_name; - gchar *description; + GString *description; + gchar *context; + gboolean translatable; } AtkActionData; - -typedef struct { + +typedef struct +{ gchar *target; gchar *type; } AtkRelationData; @@ -9399,7 +10272,8 @@ static void free_action (AtkActionData *data, gpointer user_data) { g_free (data->action_name); - g_free (data->description); + g_string_free (data->description, TRUE); + g_free (data->context); g_slice_free (AtkActionData, data); } @@ -9416,7 +10290,7 @@ gtk_widget_buildable_parser_finished (GtkBuildable *buildable, GtkBuilder *builder) { GSList *atk_relations; - + if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default)) gtk_widget_grab_default (GTK_WIDGET (buildable)); if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus)) @@ -9432,14 +10306,14 @@ gtk_widget_buildable_parser_finished (GtkBuildable *buildable, GObject *target; AtkRelationType relation_type; AtkObject *target_accessible; - + accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable)); relation_set = atk_object_ref_relation_set (accessible); for (l = atk_relations; l; l = l->next) { AtkRelationData *relation = (AtkRelationData*)l->data; - + target = gtk_builder_get_object (builder, relation->target); if (!target) { @@ -9449,7 +10323,7 @@ gtk_widget_buildable_parser_finished (GtkBuildable *buildable, } target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target)); g_assert (target_accessible != NULL); - + relation_type = atk_relation_type_for_name (relation->type); if (relation_type == ATK_RELATION_NULL) { @@ -9467,21 +10341,21 @@ gtk_widget_buildable_parser_finished (GtkBuildable *buildable, g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations, NULL); } - } -typedef struct { +typedef struct +{ GSList *actions; GSList *relations; } AccessibilitySubParserData; static void -accessibility_start_element (GMarkupParseContext *context, - const gchar *element_name, - const gchar **names, - const gchar **values, - gpointer user_data, - GError **error) +accessibility_start_element (GMarkupParseContext *context, + const gchar *element_name, + const gchar **names, + const gchar **values, + gpointer user_data, + GError **error) { AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data; guint i; @@ -9492,7 +10366,7 @@ accessibility_start_element (GMarkupParseContext *context, gchar *target = NULL; gchar *type = NULL; AtkRelationData *relation; - + for (i = 0; names[i]; i++) { if (strcmp (names[i], "target") == 0) @@ -9536,21 +10410,34 @@ accessibility_start_element (GMarkupParseContext *context, relation = g_slice_new (AtkRelationData); relation->target = target; relation->type = type; - + data->relations = g_slist_prepend (data->relations, relation); } else if (strcmp (element_name, "action") == 0) { - gchar *action_name = NULL; - gchar *description = NULL; + const gchar *action_name = NULL; + const gchar *description = NULL; + const gchar *msg_context = NULL; + gboolean translatable = FALSE; AtkActionData *action; - + for (i = 0; names[i]; i++) { if (strcmp (names[i], "action_name") == 0) - action_name = g_strdup (values[i]); + action_name = values[i]; else if (strcmp (names[i], "description") == 0) - description = g_strdup (values[i]); + description = values[i]; + else if (strcmp (names[i], "translatable") == 0) + { + if (!_gtk_builder_boolean_from_string (values[i], &translatable, error)) + return; + } + else if (strcmp (names[i], "comments") == 0) + { + /* do nothing, comments are for translators */ + } + else if (strcmp (names[i], "context") == 0) + msg_context = values[i]; else { g_markup_parse_context_get_position (context, @@ -9562,13 +10449,11 @@ accessibility_start_element (GMarkupParseContext *context, "%s:%d:%d '%s' is not a valid attribute of <%s>", "", line_number, char_number, names[i], "action"); - g_free (action_name); - g_free (description); return; } } - if (!action_name || !description) + if (!action_name) { g_markup_parse_context_get_position (context, &line_number, @@ -9579,16 +10464,16 @@ accessibility_start_element (GMarkupParseContext *context, "%s:%d:%d <%s> requires attribute \"%s\"", "", line_number, char_number, "action", - description ? "action_name" : "description"); - g_free (action_name); - g_free (description); + "action_name"); return; } action = g_slice_new (AtkActionData); - action->action_name = action_name; - action->description = description; - + action->action_name = g_strdup (action_name); + action->description = g_string_new (description); + action->context = g_strdup (msg_context); + action->translatable = translatable; + data->actions = g_slist_prepend (data->actions, action); } else if (strcmp (element_name, "accessibility") == 0) @@ -9597,12 +10482,32 @@ accessibility_start_element (GMarkupParseContext *context, g_warning ("Unsupported tag for GtkWidget: %s\n", element_name); } +static void +accessibility_text (GMarkupParseContext *context, + const gchar *text, + gsize text_len, + gpointer user_data, + GError **error) +{ + AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data; + + if (strcmp (g_markup_parse_context_get_element (context), "action") == 0) + { + AtkActionData *action = data->actions->data; + + g_string_append_len (action->description, text, text_len); + } +} + static const GMarkupParser accessibility_parser = { accessibility_start_element, + NULL, + accessibility_text, }; -typedef struct { +typedef struct +{ GObject *object; guint key; guint modifiers; @@ -9610,12 +10515,12 @@ typedef struct { } AccelGroupParserData; static void -accel_group_start_element (GMarkupParseContext *context, - const gchar *element_name, - const gchar **names, - const gchar **values, - gpointer user_data, - GError **error) +accel_group_start_element (GMarkupParseContext *context, + const gchar *element_name, + const gchar **names, + const gchar **values, + gpointer user_data, + GError **error) { gint i; guint key = 0; @@ -9686,6 +10591,44 @@ gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable, return FALSE; } +void +_gtk_widget_buildable_finish_accelerator (GtkWidget *widget, + GtkWidget *toplevel, + gpointer user_data) +{ + AccelGroupParserData *accel_data; + GSList *accel_groups; + GtkAccelGroup *accel_group; + + g_return_if_fail (GTK_IS_WIDGET (widget)); + g_return_if_fail (GTK_IS_WIDGET (toplevel)); + g_return_if_fail (user_data != NULL); + + accel_data = (AccelGroupParserData*)user_data; + accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel)); + if (g_slist_length (accel_groups) == 0) + { + accel_group = gtk_accel_group_new (); + gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group); + } + else + { + g_assert (g_slist_length (accel_groups) == 1); + accel_group = g_slist_nth_data (accel_groups, 0); + } + + gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object), + accel_data->signal, + accel_group, + accel_data->key, + accel_data->modifiers, + GTK_ACCEL_VISIBLE); + + g_object_unref (accel_data->object); + g_free (accel_data->signal); + g_slice_free (AccelGroupParserData, accel_data); +} + static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable, GtkBuilder *builder, @@ -9696,8 +10639,6 @@ gtk_widget_buildable_custom_finished (GtkBuildable *buildable, AccelGroupParserData *accel_data; AccessibilitySubParserData *a11y_data; GtkWidget *toplevel; - GSList *accel_groups; - GtkAccelGroup *accel_group; if (strcmp (tagname, "accelerator") == 0) { @@ -9705,26 +10646,8 @@ gtk_widget_buildable_custom_finished (GtkBuildable *buildable, g_assert (accel_data->object); toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object)); - accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel)); - if (g_slist_length (accel_groups) == 0) - { - accel_group = gtk_accel_group_new (); - gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group); - } - else - { - g_assert (g_slist_length (accel_groups) == 1); - accel_group = g_slist_nth_data (accel_groups, 0); - } - gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object), - accel_data->signal, - accel_group, - accel_data->key, - accel_data->modifiers, - GTK_ACCEL_VISIBLE); - g_object_unref (accel_data->object); - g_free (accel_data->signal); - g_slice_free (AccelGroupParserData, accel_data); + + _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data); } else if (strcmp (tagname, "accessibility") == 0) { @@ -9736,26 +10659,36 @@ gtk_widget_buildable_custom_finished (GtkBuildable *buildable, AtkAction *action; gint i, n_actions; GSList *l; - + accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable)); - + action = ATK_ACTION (accessible); - n_actions = atk_action_get_n_actions (action); - + n_actions = atk_action_get_n_actions (action); + for (l = a11y_data->actions; l; l = l->next) { AtkActionData *action_data = (AtkActionData*)l->data; - + for (i = 0; i < n_actions; i++) if (strcmp (atk_action_get_name (action, i), action_data->action_name) == 0) break; if (i < n_actions) - atk_action_set_description (action, i, - action_data->description); + { + gchar *description; + + if (action_data->translatable && action_data->description->len) + description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder), + action_data->context, + action_data->description->str); + else + description = action_data->description->str; + + atk_action_set_description (action, i, description); + } } - + g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL); g_slist_free (a11y_data->actions); } @@ -9763,9 +10696,8 @@ gtk_widget_buildable_custom_finished (GtkBuildable *buildable, if (a11y_data->relations) g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations, a11y_data->relations); - + g_slice_free (AccessibilitySubParserData, a11y_data); - } } @@ -9783,8 +10715,8 @@ gtk_widget_buildable_custom_finished (GtkBuildable *buildable, * be used with @widget. @widget must have a #GdkDisplay * associated with it, so must be attached to a toplevel * window. - * - * Return value: the appropriate clipboard object. If no + * + * Return value: (transfer none): the appropriate clipboard object. If no * clipboard already exists, a new one will * be created. Once a clipboard object has * been created, it is persistent for all time. @@ -9816,7 +10748,8 @@ gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection) * (GFunc)g_object_ref, NULL) first, and then unref all the * widgets afterwards. - * Return value: the list of mnemonic labels; free this list + * Return value: (element-type GtkWidget) (transfer container): the list of + * mnemonic labels; free this list * with g_list_free() when you are done with it. * * Since: 2.4 @@ -9912,7 +10845,7 @@ gtk_widget_get_no_show_all (GtkWidget *widget) { g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); - return (GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0; + return (GTK_OBJECT_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0; } /** @@ -9937,13 +10870,13 @@ gtk_widget_set_no_show_all (GtkWidget *widget, no_show_all = (no_show_all != FALSE); - if (no_show_all == ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)) + if (no_show_all == gtk_widget_get_no_show_all (widget)) return; if (no_show_all) - GTK_WIDGET_SET_FLAGS (widget, GTK_NO_SHOW_ALL); + GTK_OBJECT_FLAGS (widget) |= GTK_NO_SHOW_ALL; else - GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_SHOW_ALL); + GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_SHOW_ALL); g_object_notify (G_OBJECT (widget), "no-show-all"); } @@ -9965,14 +10898,14 @@ gtk_widget_real_set_has_tooltip (GtkWidget *widget, if (priv_has_tooltip) { - if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_NO_WINDOW (widget)) + if (GTK_WIDGET_REALIZED (widget) && !gtk_widget_get_has_window (widget)) gdk_window_set_events (widget->window, gdk_window_get_events (widget->window) | GDK_LEAVE_NOTIFY_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK); - if (!GTK_WIDGET_NO_WINDOW (widget)) + if (gtk_widget_get_has_window (widget)) gtk_widget_add_events (widget, GDK_LEAVE_NOTIFY_MASK | GDK_POINTER_MOTION_MASK | @@ -9987,7 +10920,7 @@ gtk_widget_real_set_has_tooltip (GtkWidget *widget, /** * gtk_widget_set_tooltip_window: * @widget: a #GtkWidget - * @custom_window: a #GtkWindow, or %NULL + * @custom_window: (allow-none): a #GtkWindow, or %NULL * * Replaces the default, usually yellow, window used for displaying * tooltips with @custom_window. GTK+ will take care of showing and @@ -9995,35 +10928,34 @@ gtk_widget_real_set_has_tooltip (GtkWidget *widget, * the default tooltip window. If @custom_window is %NULL, the default * tooltip window will be used. * + * If the custom window should have the default theming it needs to + * have the name "gtk-tooltip", see gtk_widget_set_name(). + * * Since: 2.12 */ void gtk_widget_set_tooltip_window (GtkWidget *widget, GtkWindow *custom_window) { - gboolean tmp; + gboolean has_tooltip; gchar *tooltip_markup; - GtkWindow *tooltip_window; g_return_if_fail (GTK_IS_WIDGET (widget)); - if (custom_window) - g_return_if_fail (GTK_IS_WINDOW (custom_window)); + g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window)); - tooltip_window = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window); tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup); if (custom_window) g_object_ref (custom_window); - tooltip_window = custom_window; g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window, - tooltip_window, g_object_unref); + custom_window, g_object_unref); - tmp = (tooltip_window != NULL || tooltip_markup != NULL); - gtk_widget_real_set_has_tooltip (widget, tmp, FALSE); + has_tooltip = (custom_window != NULL || tooltip_markup != NULL); + gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE); - if (tmp) - gtk_widget_trigger_tooltip_query (widget); + if (has_tooltip && gtk_widget_get_visible (widget)) + gtk_widget_queue_tooltip_query (widget); } /** @@ -10034,7 +10966,7 @@ gtk_widget_set_tooltip_window (GtkWidget *widget, * GtkWindow created by default, or the custom tooltip window set * using gtk_widget_set_tooltip_window(). * - * Return value: The #GtkWindow of the current tooltip. + * Return value: (transfer none): The #GtkWindow of the current tooltip. * * Since: 2.12 */ @@ -10062,6 +10994,36 @@ gtk_widget_trigger_tooltip_query (GtkWidget *widget) gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget)); } +static guint tooltip_query_id; +static GSList *tooltip_query_displays; + +static gboolean +tooltip_query_idle (gpointer data) +{ + g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL); + g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL); + g_slist_free (tooltip_query_displays); + + tooltip_query_displays = NULL; + tooltip_query_id = 0; + + return FALSE; +} + +static void +gtk_widget_queue_tooltip_query (GtkWidget *widget) +{ + GdkDisplay *display; + + display = gtk_widget_get_display (widget); + + if (!g_slist_find (tooltip_query_displays, display)) + tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display)); + + if (tooltip_query_id == 0) + tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL); +} + /** * gtk_widget_set_tooltip_text: * @widget: a #GtkWidget @@ -10110,7 +11072,7 @@ gtk_widget_get_tooltip_text (GtkWidget *widget) /** * gtk_widget_set_tooltip_markup: * @widget: a #GtkWidget - * @markup: the contents of the tooltip for @widget, or %NULL + * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL * * Sets @markup as the contents of the tooltip, which is marked up with * the Pango text markup language. @@ -10200,20 +11162,97 @@ gtk_widget_get_has_tooltip (GtkWidget *widget) /** * gtk_widget_get_allocation: * @widget: a #GtkWidget + * @allocation: (out): a pointer to a #GtkAllocation to copy to * * Retrieves the widget's allocation. * - * Return value: widget's allocation + * Since: 2.18 + */ +void +gtk_widget_get_allocation (GtkWidget *widget, + GtkAllocation *allocation) +{ + g_return_if_fail (GTK_IS_WIDGET (widget)); + g_return_if_fail (allocation != NULL); + + *allocation = widget->allocation; +} + +/** + * gtk_widget_set_allocation: + * @widget: a #GtkWidget + * @allocation: a pointer to a #GtkAllocation to copy from * - * Since: 2.14 + * Sets the widget's allocation. This should not be used + * directly, but from within a widget's size_allocate method. + * + * Since: 2.18 */ -GtkAllocation -gtk_widget_get_allocation (GtkWidget *widget) +void +gtk_widget_set_allocation (GtkWidget *widget, + const GtkAllocation *allocation) +{ + g_return_if_fail (GTK_IS_WIDGET (widget)); + g_return_if_fail (allocation != NULL); + + widget->allocation = *allocation; +} + +/** + * gtk_widget_get_requisition: + * @widget: a #GtkWidget + * @requisition: (out): a pointer to a #GtkRequisition to copy to + * + * Retrieves the widget's requisition. + * + * This function should only be used by widget implementations in + * order to figure whether the widget's requisition has actually + * changed after some internal state change (so that they can call + * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()). + * + * Normally, gtk_widget_size_request() should be used. + * + * Since: 2.20 + */ +void +gtk_widget_get_requisition (GtkWidget *widget, + GtkRequisition *requisition) { - static GtkAllocation allocation = { 0 }; - g_return_val_if_fail (GTK_IS_WIDGET (widget), allocation); + g_return_if_fail (GTK_IS_WIDGET (widget)); + g_return_if_fail (requisition != NULL); + + *requisition = widget->requisition; +} - return widget->allocation; +/** + * gtk_widget_set_window: + * @widget: a #GtkWidget + * @window: a #GdkWindow + * + * Sets a widget's window. This function should only be used in a + * widget's GtkWidget::realize() implementation. The %window passed is + * usually either new window created with gdk_window_new(), or the + * window of its parent widget as returned by + * gtk_widget_get_parent_window(). + * + * Widgets must indicate whether they will create their own #GdkWindow + * by calling gtk_widget_set_has_window(). This is usually done in the + * widget's init() function. + * + * Since: 2.18 + */ +void +gtk_widget_set_window (GtkWidget *widget, + GdkWindow *window) +{ + g_return_if_fail (GTK_IS_WIDGET (widget)); + g_return_if_fail (window == NULL || GDK_IS_WINDOW (window)); + + if (widget->window != window) + { + widget->window = window; + g_object_notify (G_OBJECT (widget), "window"); + } } /**