diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols index ba61ba3c2f..bf2e861bbd 100644 --- a/gtk/gtk.symbols +++ b/gtk/gtk.symbols @@ -4998,6 +4998,7 @@ gtk_widget_get_tooltip_text gtk_widget_get_tooltip_window gtk_widget_get_toplevel gtk_widget_get_type G_GNUC_CONST +gtk_widget_get_visible gtk_widget_get_visual gtk_widget_grab_default gtk_widget_grab_focus @@ -5076,6 +5077,7 @@ gtk_widget_set_style gtk_widget_set_tooltip_markup gtk_widget_set_tooltip_text gtk_widget_set_tooltip_window +gtk_widget_set_visible gtk_widget_shape_combine_mask gtk_widget_input_shape_combine_mask gtk_widget_show diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index a81dc2debc..28422b2e28 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -5577,6 +5577,58 @@ gtk_widget_get_state (GtkWidget *widget) 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_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_WIDGET_FLAGS (widget) & GTK_VISIBLE) != 0; +} + /** * gtk_widget_set_has_window: * @widget: a #GtkWidget diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h index e074baa860..d5de8bd13c 100644 --- a/gtk/gtkwidget.h +++ b/gtk/gtkwidget.h @@ -574,6 +574,10 @@ void gtk_widget_set_sensitive (GtkWidget *widget, gboolean gtk_widget_get_sensitive (GtkWidget *widget); gboolean gtk_widget_is_sensitive (GtkWidget *widget); +void gtk_widget_set_visible (GtkWidget *widget, + gboolean visible); +gboolean gtk_widget_get_visible (GtkWidget *widget); + void gtk_widget_set_has_window (GtkWidget *widget, gboolean has_window); gboolean gtk_widget_get_has_window (GtkWidget *widget);