From: Matthias Clasen Date: Wed, 1 Feb 2023 17:03:59 +0000 (+0100) Subject: Deprecate GtkStatusbar X-Git-Tag: archive/raspbian/4.12.3+ds-1+rpi1~1^2^2^2~22^2~8^2~25 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=d8cb11ec4a57938901a3d850905d09dae75c6284;p=gtk4.git Deprecate GtkStatusbar The design patterns using statusbar are no longer popular, and it is pretty easy to make a statusbar yourself with boxes and labels, if you need one. The only thing special about GtkStatusbar was its window resize handle, but that has been gone for a long time. --- diff --git a/demos/gtk-demo/application.c b/demos/gtk-demo/application.c index 56567b197b..76982361d0 100644 --- a/demos/gtk-demo/application.c +++ b/demos/gtk-demo/application.c @@ -2,6 +2,8 @@ #include +G_GNUC_BEGIN_IGNORE_DEPRECATIONS + typedef GtkApplication DemoApplication; typedef GtkApplicationClass DemoApplicationClass; diff --git a/demos/gtk-demo/builder.c b/demos/gtk-demo/builder.c index 54e777d8c3..126ea9c9b8 100644 --- a/demos/gtk-demo/builder.c +++ b/demos/gtk-demo/builder.c @@ -37,6 +37,8 @@ remove_timeout (gpointer data) g_source_remove (id); } +G_GNUC_BEGIN_IGNORE_DEPRECATIONS + static gboolean pop_status (gpointer data) { @@ -57,6 +59,8 @@ status_message (GtkStatusbar *status, g_object_set_data_full (G_OBJECT (status), "timeout", GUINT_TO_POINTER (id), remove_timeout); } +G_GNUC_END_IGNORE_DEPRECATIONS + static void help_activate (GSimpleAction *action, GVariant *parameter, diff --git a/demos/widget-factory/widget-factory.c b/demos/widget-factory/widget-factory.c index 146ecfab26..58cbae10d0 100644 --- a/demos/widget-factory/widget-factory.c +++ b/demos/widget-factory/widget-factory.c @@ -2252,11 +2252,13 @@ activate (GApplication *app) for (i = 0; i < G_N_ELEMENTS (accels); i++) gtk_application_set_accels_for_action (GTK_APPLICATION (app), accels[i].action_and_target, accels[i].accelerators); +G_GNUC_BEGIN_IGNORE_DEPRECATIONS widget = (GtkWidget *)gtk_builder_get_object (builder, "statusbar"); gtk_statusbar_push (GTK_STATUSBAR (widget), 0, "All systems are operating normally."); action = G_ACTION (g_property_action_new ("statusbar", widget, "visible")); g_action_map_add_action (G_ACTION_MAP (window), action); g_object_unref (G_OBJECT (action)); +G_GNUC_END_IGNORE_DEPRECATIONS widget = (GtkWidget *)gtk_builder_get_object (builder, "toolbar"); action = G_ACTION (g_property_action_new ("toolbar", widget, "visible")); diff --git a/docs/reference/gtk/migrating-4to5.md b/docs/reference/gtk/migrating-4to5.md index 04a8b19c5f..54f35906f5 100644 --- a/docs/reference/gtk/migrating-4to5.md +++ b/docs/reference/gtk/migrating-4to5.md @@ -109,3 +109,8 @@ Other libraries, such as libadwaita, may provide replacements as well. ## gtk_show_uri is being replaced Instead of gtk_show_uri(), you should use GtkUriLauncher or GtkFileLauncher. + +## GtkStatusbar is going away + +This is an oldfashioned widget that does not do all that much anymore, since +it no longer has a resize handle for the window. diff --git a/gtk/deprecated/gtklockbutton.c b/gtk/deprecated/gtklockbutton.c new file mode 100644 index 0000000000..5f94cfa372 --- /dev/null +++ b/gtk/deprecated/gtklockbutton.c @@ -0,0 +1,587 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2010 Red Hat, Inc. + * Author: Matthias Clasen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library. If not, see . + */ + +#include "config.h" + +#include "gtklockbuttonprivate.h" + +#include "gtkbox.h" +#include "gtkimage.h" +#include +#include "gtklabel.h" +#include "gtksizegroup.h" +#include "gtkstack.h" +#include "gtkprivate.h" + +/** + * GtkLockButton: + * + * `GtkLockButton` is a widget to obtain and revoke authorizations + * needed to operate the controls. + * + * ![An example GtkLockButton](lock-button.png) + * + * It is typically used in preference dialogs or control panels. + * + * The required authorization is represented by a `GPermission` object. + * Concrete implementations of `GPermission` may use PolicyKit or some + * other authorization framework. To obtain a PolicyKit-based + * `GPermission`, use `polkit_permission_new()`. + * + * If the user is not currently allowed to perform the action, but can + * obtain the permission, the widget looks like this: + * + * ![](lockbutton-locked.png) + * + * and the user can click the button to request the permission. Depending + * on the platform, this may pop up an authentication dialog or ask the user + * to authenticate in some other way. Once the user has obtained the permission, + * the widget changes to this: + * + * ![](lockbutton-unlocked.png) + * + * and the permission can be dropped again by clicking the button. If the user + * is not able to obtain the permission at all, the widget looks like this: + * + * ![](lockbutton-sorry.png) + * + * If the user has the permission and cannot drop it, the button is hidden. + * + * The text (and tooltips) that are shown in the various cases can be adjusted + * with the [property@Gtk.LockButton:text-lock], + * [property@Gtk.LockButton:text-unlock], + * [property@Gtk.LockButton:tooltip-lock], + * [property@Gtk.LockButton:tooltip-unlock] and + * [property@Gtk.LockButton:tooltip-not-authorized] properties. + */ + +struct _GtkLockButton +{ + GtkButton parent_instance; + + GPermission *permission; + GCancellable *cancellable; + + char *tooltip_lock; + char *tooltip_unlock; + char *tooltip_not_authorized; + GIcon *icon_lock; + GIcon *icon_unlock; + + GtkWidget *box; + GtkWidget *image; + GtkWidget *stack; + GtkWidget *label_lock; + GtkWidget *label_unlock; +}; + +typedef struct _GtkLockButtonClass GtkLockButtonClass; +struct _GtkLockButtonClass +{ + GtkButtonClass parent_class; +}; + +enum +{ + PROP_0, + PROP_PERMISSION, + PROP_TEXT_LOCK, + PROP_TEXT_UNLOCK, + PROP_TOOLTIP_LOCK, + PROP_TOOLTIP_UNLOCK, + PROP_TOOLTIP_NOT_AUTHORIZED +}; + +static void update_state (GtkLockButton *button); +static void gtk_lock_button_clicked (GtkButton *button); + +static void on_permission_changed (GPermission *permission, + GParamSpec *pspec, + gpointer user_data); + +G_DEFINE_TYPE (GtkLockButton, gtk_lock_button, GTK_TYPE_BUTTON) + +static void +gtk_lock_button_finalize (GObject *object) +{ + GtkLockButton *button = GTK_LOCK_BUTTON (object); + + g_free (button->tooltip_lock); + g_free (button->tooltip_unlock); + g_free (button->tooltip_not_authorized); + + g_object_unref (button->icon_lock); + g_object_unref (button->icon_unlock); + + if (button->cancellable != NULL) + { + g_cancellable_cancel (button->cancellable); + g_object_unref (button->cancellable); + } + + if (button->permission) + { + g_signal_handlers_disconnect_by_func (button->permission, + on_permission_changed, + button); + g_object_unref (button->permission); + } + + G_OBJECT_CLASS (gtk_lock_button_parent_class)->finalize (object); +} + +static void +gtk_lock_button_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + GtkLockButton *button = GTK_LOCK_BUTTON (object); + + switch (property_id) + { + case PROP_PERMISSION: + g_value_set_object (value, button->permission); + break; + + case PROP_TEXT_LOCK: + g_value_set_string (value, gtk_label_get_text (GTK_LABEL (button->label_lock))); + break; + + case PROP_TEXT_UNLOCK: + g_value_set_string (value, gtk_label_get_text (GTK_LABEL (button->label_unlock))); + break; + + case PROP_TOOLTIP_LOCK: + g_value_set_string (value, button->tooltip_lock); + break; + + case PROP_TOOLTIP_UNLOCK: + g_value_set_string (value, button->tooltip_unlock); + break; + + case PROP_TOOLTIP_NOT_AUTHORIZED: + g_value_set_string (value, button->tooltip_not_authorized); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +gtk_lock_button_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + GtkLockButton *button = GTK_LOCK_BUTTON (object); + + switch (property_id) + { + case PROP_PERMISSION: + gtk_lock_button_set_permission (button, g_value_get_object (value)); + break; + + case PROP_TEXT_LOCK: + gtk_label_set_text (GTK_LABEL (button->label_lock), g_value_get_string (value)); + break; + + case PROP_TEXT_UNLOCK: + gtk_label_set_text (GTK_LABEL (button->label_unlock), g_value_get_string (value)); + break; + + case PROP_TOOLTIP_LOCK: + g_free (button->tooltip_lock); + button->tooltip_lock = g_value_dup_string (value); + break; + + case PROP_TOOLTIP_UNLOCK: + g_free (button->tooltip_unlock); + button->tooltip_unlock = g_value_dup_string (value); + break; + + case PROP_TOOLTIP_NOT_AUTHORIZED: + g_free (button->tooltip_not_authorized); + button->tooltip_not_authorized = g_value_dup_string (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } + + update_state (button); +} + +static void +gtk_lock_button_init (GtkLockButton *button) +{ + const char *names[3]; + + gtk_widget_init_template (GTK_WIDGET (button)); + + names[0] = "changes-allow-symbolic"; + names[1] = "changes-allow"; + names[2] = NULL; + button->icon_unlock = g_themed_icon_new_from_names ((char **) names, -1); + + names[0] = "changes-prevent-symbolic"; + names[1] = "changes-prevent"; + names[2] = NULL; + button->icon_lock = g_themed_icon_new_from_names ((char **) names, -1); + + update_state (button); + + gtk_widget_add_css_class (GTK_WIDGET (button), I_("lock")); +} + +static void +gtk_lock_button_class_init (GtkLockButtonClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass); + + gobject_class->finalize = gtk_lock_button_finalize; + gobject_class->get_property = gtk_lock_button_get_property; + gobject_class->set_property = gtk_lock_button_set_property; + + button_class->clicked = gtk_lock_button_clicked; + + /** + * GtkLockButton:permission: (attributes org.gtk.Property.get=gtk_lock_button_get_permission org.gtk.Property.set=gtk_lock_button_set_permission) + * + * The `GPermission object controlling this button. + */ + g_object_class_install_property (gobject_class, PROP_PERMISSION, + g_param_spec_object ("permission", NULL, NULL, + G_TYPE_PERMISSION, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); + + /** + * GtkLockButton:text-lock: + * + * The text to display when prompting the user to lock. + */ + g_object_class_install_property (gobject_class, PROP_TEXT_LOCK, + g_param_spec_string ("text-lock", NULL, NULL, + _("Lock"), + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT | + G_PARAM_STATIC_STRINGS)); + + /** + * GtkLockButton:text-unlock: + * + * The text to display when prompting the user to unlock. + */ + g_object_class_install_property (gobject_class, PROP_TEXT_UNLOCK, + g_param_spec_string ("text-unlock", NULL, NULL, + _("Unlock"), + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT | + G_PARAM_STATIC_STRINGS)); + + /** + * GtkLockButton:tooltip-lock: + * + * The tooltip to display when prompting the user to lock. + */ + g_object_class_install_property (gobject_class, PROP_TOOLTIP_LOCK, + g_param_spec_string ("tooltip-lock", NULL, NULL, + _("Dialog is unlocked.\nClick to prevent further changes"), + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT | + G_PARAM_STATIC_STRINGS)); + + /** + * GtkLockButton:tooltip-unlock: + * + * The tooltip to display when prompting the user to unlock. + */ + g_object_class_install_property (gobject_class, PROP_TOOLTIP_UNLOCK, + g_param_spec_string ("tooltip-unlock", NULL, NULL, + _("Dialog is locked.\nClick to make changes"), + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT | + G_PARAM_STATIC_STRINGS)); + + /** + * GtkLockButton:tooltip-not-authorized: + * + * The tooltip to display when the user cannot obtain authorization. + */ + g_object_class_install_property (gobject_class, PROP_TOOLTIP_NOT_AUTHORIZED, + g_param_spec_string ("tooltip-not-authorized", NULL, NULL, + _("System policy prevents changes.\nContact your system administrator"), + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT | + G_PARAM_STATIC_STRINGS)); + + /* Bind class to template + */ + gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/ui/gtklockbutton.ui"); + gtk_widget_class_bind_template_child (widget_class, GtkLockButton, box); + gtk_widget_class_bind_template_child (widget_class, GtkLockButton, image); + gtk_widget_class_bind_template_child (widget_class, GtkLockButton, label_lock); + gtk_widget_class_bind_template_child (widget_class, GtkLockButton, label_unlock); + gtk_widget_class_bind_template_child (widget_class, GtkLockButton, stack); + + gtk_widget_class_set_css_name (widget_class, I_("button")); +} + +static void +update_state (GtkLockButton *button) +{ + gboolean allowed; + gboolean can_acquire; + gboolean can_release; + gboolean sensitive; + gboolean visible; + GIcon *icon; + const char *tooltip; + + if (button->permission) + { + allowed = g_permission_get_allowed (button->permission); + can_acquire = g_permission_get_can_acquire (button->permission); + can_release = g_permission_get_can_release (button->permission); + } + else + { + allowed = TRUE; + can_acquire = FALSE; + can_release = FALSE; + } + + if (allowed && can_release) + { + visible = TRUE; + sensitive = TRUE; + icon = button->icon_lock; + tooltip = button->tooltip_lock; + } + else if (allowed && !can_release) + { + visible = FALSE; + sensitive = TRUE; + icon = button->icon_lock; + tooltip = button->tooltip_lock; + } + else if (!allowed && can_acquire) + { + visible = TRUE; + sensitive = TRUE; + icon = button->icon_unlock; + tooltip = button->tooltip_unlock; + } + else if (!allowed && !can_acquire) + { + visible = TRUE; + sensitive = FALSE; + icon = button->icon_unlock; + tooltip = button->tooltip_not_authorized; + } + else + { + g_assert_not_reached (); + } + + gtk_image_set_from_gicon (GTK_IMAGE (button->image), icon); + gtk_stack_set_visible_child (GTK_STACK (button->stack), + allowed ? button->label_lock : button->label_unlock); + gtk_widget_set_tooltip_markup (GTK_WIDGET (button), tooltip); + gtk_widget_set_sensitive (GTK_WIDGET (button), sensitive); + gtk_widget_set_visible (GTK_WIDGET (button), visible); +} + +static void +on_permission_changed (GPermission *permission, + GParamSpec *pspec, + gpointer user_data) +{ + GtkLockButton *button = GTK_LOCK_BUTTON (user_data); + + update_state (button); +} + +static void +acquire_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + GtkLockButton *button = GTK_LOCK_BUTTON (user_data); + GError *error; + + error = NULL; + if (!g_permission_acquire_finish (button->permission, result, &error)) + { + g_warning ("Error acquiring permission: %s", error->message); + g_error_free (error); + } + + g_object_unref (button->cancellable); + button->cancellable = NULL; + + update_state (button); +} + +static void +release_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + GtkLockButton *button = GTK_LOCK_BUTTON (user_data); + GError *error; + + error = NULL; + if (!g_permission_release_finish (button->permission, result, &error)) + { + g_warning ("Error releasing permission: %s", error->message); + g_error_free (error); + } + + g_object_unref (button->cancellable); + button->cancellable = NULL; + + update_state (button); +} + +static void +gtk_lock_button_clicked (GtkButton *widget) +{ + GtkLockButton *button = GTK_LOCK_BUTTON (widget); + + /* if we already have a pending interactive check or permission is not set, + * then do nothing + */ + if (button->cancellable != NULL || button->permission == NULL) + return; + + if (g_permission_get_allowed (button->permission)) + { + if (g_permission_get_can_release (button->permission)) + { + button->cancellable = g_cancellable_new (); + + g_permission_release_async (button->permission, + button->cancellable, + release_cb, + button); + } + } + else + { + if (g_permission_get_can_acquire (button->permission)) + { + button->cancellable = g_cancellable_new (); + + g_permission_acquire_async (button->permission, + button->cancellable, + acquire_cb, + button); + } + } +} + +/** + * gtk_lock_button_new: + * @permission: (nullable): a `GPermission` + * + * Creates a new lock button which reflects the @permission. + * + * Returns: a new `GtkLockButton` + */ +GtkWidget * +gtk_lock_button_new (GPermission *permission) +{ + return GTK_WIDGET (g_object_new (GTK_TYPE_LOCK_BUTTON, + "permission", permission, + NULL)); +} + +/** + * gtk_lock_button_get_permission: (attributes org.gtk.Method.get_property=permission) + * @button: a `GtkLockButton` + * + * Obtains the `GPermission` object that controls @button. + * + * Returns: (transfer none) (nullable): the `GPermission` of @button + */ +GPermission * +gtk_lock_button_get_permission (GtkLockButton *button) +{ + g_return_val_if_fail (GTK_IS_LOCK_BUTTON (button), NULL); + + return button->permission; +} + +/** + * gtk_lock_button_set_permission: (attributes org.gtk.Method.set_property=permission) + * @button: a `GtkLockButton` + * @permission: (nullable): a `GPermission` object + * + * Sets the `GPermission` object that controls @button. + */ +void +gtk_lock_button_set_permission (GtkLockButton *button, + GPermission *permission) +{ + g_return_if_fail (GTK_IS_LOCK_BUTTON (button)); + g_return_if_fail (permission == NULL || G_IS_PERMISSION (permission)); + + if (button->permission != permission) + { + if (button->permission) + { + g_signal_handlers_disconnect_by_func (button->permission, + on_permission_changed, + button); + g_object_unref (button->permission); + } + + button->permission = permission; + + if (button->permission) + { + g_object_ref (button->permission); + g_signal_connect (button->permission, "notify", + G_CALLBACK (on_permission_changed), button); + } + + update_state (button); + + g_object_notify (G_OBJECT (button), "permission"); + } +} + +const char * +_gtk_lock_button_get_current_text (GtkLockButton *button) +{ + GtkWidget *label; + + g_return_val_if_fail (GTK_IS_LOCK_BUTTON (button), NULL); + + label = gtk_stack_get_visible_child (GTK_STACK (button->stack)); + + return gtk_label_get_text (GTK_LABEL (label)); +} + diff --git a/gtk/deprecated/gtklockbutton.h b/gtk/deprecated/gtklockbutton.h new file mode 100644 index 0000000000..5d24b06f38 --- /dev/null +++ b/gtk/deprecated/gtklockbutton.h @@ -0,0 +1,47 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2010 Red Hat, Inc. + * Author: Matthias Clasen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library. If not, see . + */ + +#ifndef __GTK_LOCK_BUTTON_H__ +#define __GTK_LOCK_BUTTON_H__ + +#include +#include + +G_BEGIN_DECLS + +#define GTK_TYPE_LOCK_BUTTON (gtk_lock_button_get_type ()) +#define GTK_LOCK_BUTTON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_LOCK_BUTTON, GtkLockButton)) +#define GTK_IS_LOCK_BUTTON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_LOCK_BUTTON)) + +typedef struct _GtkLockButton GtkLockButton; + +GDK_AVAILABLE_IN_ALL +GType gtk_lock_button_get_type (void) G_GNUC_CONST; +GDK_AVAILABLE_IN_ALL +GtkWidget *gtk_lock_button_new (GPermission *permission); +GDK_AVAILABLE_IN_ALL +GPermission *gtk_lock_button_get_permission (GtkLockButton *button); +GDK_AVAILABLE_IN_ALL +void gtk_lock_button_set_permission (GtkLockButton *button, + GPermission *permission); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkLockButton, g_object_unref) + +G_END_DECLS + +#endif /* __GTK_LOCK_BUTTON_H__ */ diff --git a/gtk/deprecated/gtklockbuttonprivate.h b/gtk/deprecated/gtklockbuttonprivate.h new file mode 100644 index 0000000000..f029bf8b67 --- /dev/null +++ b/gtk/deprecated/gtklockbuttonprivate.h @@ -0,0 +1,30 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2010 Red Hat, Inc. + * Author: Matthias Clasen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library. If not, see . + */ + +#ifndef __GTK_LOCK_BUTTON_PRIVATE_H__ +#define __GTK_LOCK_BUTTON_PRIVATE_H__ + +#include "gtklockbutton.h" + +G_BEGIN_DECLS + +const char * _gtk_lock_button_get_current_text (GtkLockButton *button); + +G_END_DECLS + +#endif /* __GTK_LOCK_BUTTON_PRIVATE_H__ */ diff --git a/gtk/deprecated/gtkstatusbar.c b/gtk/deprecated/gtkstatusbar.c new file mode 100644 index 0000000000..a5bb70de54 --- /dev/null +++ b/gtk/deprecated/gtkstatusbar.c @@ -0,0 +1,509 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald + * GtkStatusbar Copyright (C) 1998 Shawn T. Amundson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +/* + * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS + * file for a list of people on the GTK+ Team. See the ChangeLog + * files for a list of changes. These files are distributed with + * GTK+ at ftp://ftp.gtk.org/pub/gtk/. + */ + +#include "config.h" + +#include "gtkstatusbar.h" +#include "gtkstatusbarprivate.h" + +#include "gtkbinlayout.h" +#include "gtklabel.h" +#include "gtkmarshalers.h" +#include "gtkprivate.h" +#include "gtkorientable.h" +#include "gtktypebuiltins.h" +#include "gtkwidgetprivate.h" + +G_GNUC_BEGIN_IGNORE_DEPRECATIONS + +/** + * GtkStatusbar: + * + * A `GtkStatusbar` widget is usually placed along the bottom of an application's + * main [class@Gtk.Window]. + * + * ![An example GtkStatusbar](statusbar.png) + * + * A `GtkStatusBar` may provide a regular commentary of the application's + * status (as is usually the case in a web browser, for example), or may be + * used to simply output a message when the status changes, (when an upload + * is complete in an FTP client, for example). + * + * Status bars in GTK maintain a stack of messages. The message at + * the top of the each bar’s stack is the one that will currently be displayed. + * + * Any messages added to a statusbar’s stack must specify a context id that + * is used to uniquely identify the source of a message. This context id can + * be generated by [method@Gtk.Statusbar.get_context_id], given a message and + * the statusbar that it will be added to. Note that messages are stored in a + * stack, and when choosing which message to display, the stack structure is + * adhered to, regardless of the context identifier of a message. + * + * One could say that a statusbar maintains one stack of messages for + * display purposes, but allows multiple message producers to maintain + * sub-stacks of the messages they produced (via context ids). + * + * Status bars are created using [ctor@Gtk.Statusbar.new]. + * + * Messages are added to the bar’s stack with [method@Gtk.Statusbar.push]. + * + * The message at the top of the stack can be removed using + * [method@Gtk.Statusbar.pop]. A message can be removed from anywhere in the + * stack if its message id was recorded at the time it was added. This is done + * using [method@Gtk.Statusbar.remove]. + * + * ## CSS node + * + * `GtkStatusbar` has a single CSS node with name `statusbar`. + */ + +typedef struct _GtkStatusbarMsg GtkStatusbarMsg; + +typedef struct _GtkStatusbarClass GtkStatusbarClass; + +struct _GtkStatusbar +{ + GtkWidget parent_instance; + + GtkWidget *label; + GtkWidget *message_area; + + GSList *messages; + GSList *keys; + + guint seq_context_id; + guint seq_message_id; +}; + +struct _GtkStatusbarClass +{ + GtkWidgetClass parent_class; + + void (*text_pushed) (GtkStatusbar *statusbar, + guint context_id, + const char *text); + void (*text_popped) (GtkStatusbar *statusbar, + guint context_id, + const char *text); +}; + +struct _GtkStatusbarMsg +{ + char *text; + guint context_id; + guint message_id; +}; + +enum +{ + SIGNAL_TEXT_PUSHED, + SIGNAL_TEXT_POPPED, + SIGNAL_LAST +}; + +static void gtk_statusbar_update (GtkStatusbar *statusbar, + guint context_id, + const char *text); + +static void gtk_statusbar_msg_free (GtkStatusbarMsg *msg); + +static guint statusbar_signals[SIGNAL_LAST] = { 0 }; + +G_DEFINE_TYPE (GtkStatusbar, gtk_statusbar, GTK_TYPE_WIDGET) + +static void +gtk_statusbar_dispose (GObject *object) +{ + GtkStatusbar *self = GTK_STATUSBAR (object); + + g_slist_free_full (self->messages, (GDestroyNotify) gtk_statusbar_msg_free); + self->messages = NULL; + + g_slist_free_full (self->keys, g_free); + self->keys = NULL; + + gtk_widget_dispose_template (GTK_WIDGET (self), GTK_TYPE_STATUSBAR); + + G_OBJECT_CLASS (gtk_statusbar_parent_class)->dispose (object); +} + +static void +gtk_statusbar_class_init (GtkStatusbarClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); + + object_class->dispose = gtk_statusbar_dispose; + + class->text_pushed = gtk_statusbar_update; + class->text_popped = gtk_statusbar_update; + + /** + * GtkStatusbar::text-pushed: + * @statusbar: the object which received the signal + * @context_id: the context id of the relevant message/statusbar + * @text: the message that was pushed + * + * Emitted whenever a new message gets pushed onto a statusbar's stack. + */ + statusbar_signals[SIGNAL_TEXT_PUSHED] = + g_signal_new (I_("text-pushed"), + G_OBJECT_CLASS_TYPE (class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GtkStatusbarClass, text_pushed), + NULL, NULL, + _gtk_marshal_VOID__UINT_STRING, + G_TYPE_NONE, 2, + G_TYPE_UINT, + G_TYPE_STRING); + + /** + * GtkStatusbar::text-popped: + * @statusbar: the object which received the signal + * @context_id: the context id of the relevant message/statusbar + * @text: the message that was just popped + * + * Emitted whenever a new message is popped off a statusbar's stack. + */ + statusbar_signals[SIGNAL_TEXT_POPPED] = + g_signal_new (I_("text-popped"), + G_OBJECT_CLASS_TYPE (class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GtkStatusbarClass, text_popped), + NULL, NULL, + _gtk_marshal_VOID__UINT_STRING, + G_TYPE_NONE, 2, + G_TYPE_UINT, + G_TYPE_STRING); + + /* Bind class to template + */ + gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/ui/gtkstatusbar.ui"); + gtk_widget_class_bind_template_child_internal (widget_class, GtkStatusbar, message_area); + gtk_widget_class_bind_template_child (widget_class, GtkStatusbar, label); + + gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); + gtk_widget_class_set_css_name (widget_class, I_("statusbar")); +} + +static void +gtk_statusbar_init (GtkStatusbar *statusbar) +{ + statusbar->seq_context_id = 1; + statusbar->seq_message_id = 1; + statusbar->messages = NULL; + statusbar->keys = NULL; + + gtk_widget_init_template (GTK_WIDGET (statusbar)); +} + +/** + * gtk_statusbar_new: + * + * Creates a new `GtkStatusbar` ready for messages. + * + * Returns: the new `GtkStatusbar` + */ +GtkWidget* +gtk_statusbar_new (void) +{ + return g_object_new (GTK_TYPE_STATUSBAR, NULL); +} + +static void +gtk_statusbar_update (GtkStatusbar *statusbar, + guint context_id, + const char *text) +{ + g_return_if_fail (GTK_IS_STATUSBAR (statusbar)); + + if (!text) + text = ""; + + gtk_label_set_text (GTK_LABEL (statusbar->label), text); +} + +/** + * gtk_statusbar_get_context_id: + * @statusbar: a `GtkStatusbar` + * @context_description: textual description of what context + * the new message is being used in + * + * Returns a new context identifier, given a description + * of the actual context. + * + * Note that the description is not shown in the UI. + * + * Returns: an integer id + */ +guint +gtk_statusbar_get_context_id (GtkStatusbar *statusbar, + const char *context_description) +{ + char *string; + guint id; + + g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), 0); + g_return_val_if_fail (context_description != NULL, 0); + + /* we need to preserve namespaces on object data */ + string = g_strconcat ("gtk-status-bar-context:", context_description, NULL); + + id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (statusbar), string)); + if (id == 0) + { + id = statusbar->seq_context_id++; + g_object_set_data_full (G_OBJECT (statusbar), string, GUINT_TO_POINTER (id), NULL); + statusbar->keys = g_slist_prepend (statusbar->keys, string); + } + else + g_free (string); + + return id; +} + +static GtkStatusbarMsg * +gtk_statusbar_msg_create (GtkStatusbar *statusbar, + guint context_id, + const char *text) +{ + GtkStatusbarMsg *msg; + + msg = g_slice_new (GtkStatusbarMsg); + msg->text = g_strdup (text); + msg->context_id = context_id; + msg->message_id = statusbar->seq_message_id++; + + return msg; +} + +static void +gtk_statusbar_msg_free (GtkStatusbarMsg *msg) +{ + g_free (msg->text); + g_slice_free (GtkStatusbarMsg, msg); +} + +/** + * gtk_statusbar_push: + * @statusbar: a `GtkStatusbar` + * @context_id: the message’s context id, as returned by + * gtk_statusbar_get_context_id() + * @text: the message to add to the statusbar + * + * Pushes a new message onto a statusbar’s stack. + * + * Returns: a message id that can be used with + * [method@Gtk.Statusbar.remove]. + */ +guint +gtk_statusbar_push (GtkStatusbar *statusbar, + guint context_id, + const char *text) +{ + GtkStatusbarMsg *msg; + + g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), 0); + g_return_val_if_fail (text != NULL, 0); + + msg = gtk_statusbar_msg_create (statusbar, context_id, text); + statusbar->messages = g_slist_prepend (statusbar->messages, msg); + + g_signal_emit (statusbar, + statusbar_signals[SIGNAL_TEXT_PUSHED], + 0, + msg->context_id, + msg->text); + + return msg->message_id; +} + +/** + * gtk_statusbar_pop: + * @statusbar: a `GtkStatusbar` + * @context_id: a context identifier + * + * Removes the first message in the `GtkStatusbar`’s stack + * with the given context id. + * + * Note that this may not change the displayed message, + * if the message at the top of the stack has a different + * context id. + */ +void +gtk_statusbar_pop (GtkStatusbar *statusbar, + guint context_id) +{ + GtkStatusbarMsg *msg; + + g_return_if_fail (GTK_IS_STATUSBAR (statusbar)); + + if (statusbar->messages) + { + GSList *list; + + for (list = statusbar->messages; list; list = list->next) + { + msg = list->data; + + if (msg->context_id == context_id) + { + statusbar->messages = g_slist_remove_link (statusbar->messages, list); + gtk_statusbar_msg_free (msg); + g_slist_free_1 (list); + break; + } + } + } + + msg = statusbar->messages ? statusbar->messages->data : NULL; + + g_signal_emit (statusbar, + statusbar_signals[SIGNAL_TEXT_POPPED], + 0, + (guint) (msg ? msg->context_id : 0), + msg ? msg->text : NULL); +} + +/** + * gtk_statusbar_remove: + * @statusbar: a `GtkStatusbar` + * @context_id: a context identifier + * @message_id: a message identifier, as returned by [method@Gtk.Statusbar.push] + * + * Forces the removal of a message from a statusbar’s stack. + * The exact @context_id and @message_id must be specified. + */ +void +gtk_statusbar_remove (GtkStatusbar *statusbar, + guint context_id, + guint message_id) +{ + GtkStatusbarMsg *msg; + + g_return_if_fail (GTK_IS_STATUSBAR (statusbar)); + g_return_if_fail (message_id > 0); + + msg = statusbar->messages ? statusbar->messages->data : NULL; + if (msg) + { + GSList *list; + + /* care about signal emission if the topmost item is removed */ + if (msg->context_id == context_id && + msg->message_id == message_id) + { + gtk_statusbar_pop (statusbar, context_id); + return; + } + + for (list = statusbar->messages; list; list = list->next) + { + msg = list->data; + + if (msg->context_id == context_id && + msg->message_id == message_id) + { + statusbar->messages = g_slist_remove_link (statusbar->messages, list); + gtk_statusbar_msg_free (msg); + g_slist_free_1 (list); + + break; + } + } + } +} + +/** + * gtk_statusbar_remove_all: + * @statusbar: a `GtkStatusbar` + * @context_id: a context identifier + * + * Forces the removal of all messages from a statusbar's + * stack with the exact @context_id. + */ +void +gtk_statusbar_remove_all (GtkStatusbar *statusbar, + guint context_id) +{ + GtkStatusbarMsg *msg; + GSList *prev, *list; + + g_return_if_fail (GTK_IS_STATUSBAR (statusbar)); + + if (statusbar->messages == NULL) + return; + + /* We special-case the topmost message at the bottom of this + * function: + * If we need to pop it, we have to update various state and we want + * an up-to-date list of remaining messages in that case. + */ + prev = statusbar->messages; + list = prev->next; + + while (list != NULL) + { + msg = list->data; + + if (msg->context_id == context_id) + { + prev->next = list->next; + + gtk_statusbar_msg_free (msg); + g_slist_free_1 (list); + + list = prev->next; + } + else + { + prev = list; + list = prev->next; + } + } + + /* Treat topmost message here */ + msg = statusbar->messages->data; + if (msg->context_id == context_id) + { + gtk_statusbar_pop (statusbar, context_id); + } +} + +/** + * gtk_statusbar_get_message: + * @statusbar: a `GtkStatusbar` + * + * Retrieves the contents of the label in `GtkStatusbar`. + * + * Returns: (transfer none): the contents of the statusbar + */ +const char * +gtk_statusbar_get_message (GtkStatusbar *statusbar) +{ + g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), NULL); + + return gtk_label_get_label (GTK_LABEL (statusbar->label)); +} diff --git a/gtk/deprecated/gtkstatusbar.h b/gtk/deprecated/gtkstatusbar.h new file mode 100644 index 0000000000..d1a2356515 --- /dev/null +++ b/gtk/deprecated/gtkstatusbar.h @@ -0,0 +1,69 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald + * GtkStatusbar Copyright (C) 1998 Shawn T. Amundson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +/* + * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS + * file for a list of people on the GTK+ Team. See the ChangeLog + * files for a list of changes. These files are distributed with + * GTK+ at ftp://ftp.gtk.org/pub/gtk/. + */ + +#ifndef __GTK_STATUSBAR_H__ +#define __GTK_STATUSBAR_H__ + +#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) +#error "Only can be included directly." +#endif + +#include + +G_BEGIN_DECLS + +#define GTK_TYPE_STATUSBAR (gtk_statusbar_get_type ()) +#define GTK_STATUSBAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_STATUSBAR, GtkStatusbar)) +#define GTK_IS_STATUSBAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_STATUSBAR)) + +typedef struct _GtkStatusbar GtkStatusbar; + +GDK_AVAILABLE_IN_ALL +GType gtk_statusbar_get_type (void) G_GNUC_CONST; +GDK_DEPRECATED_IN_4_10 +GtkWidget* gtk_statusbar_new (void); +GDK_DEPRECATED_IN_4_10 +guint gtk_statusbar_get_context_id (GtkStatusbar *statusbar, + const char *context_description); +GDK_DEPRECATED_IN_4_10 +guint gtk_statusbar_push (GtkStatusbar *statusbar, + guint context_id, + const char *text); +GDK_DEPRECATED_IN_4_10 +void gtk_statusbar_pop (GtkStatusbar *statusbar, + guint context_id); +GDK_DEPRECATED_IN_4_10 +void gtk_statusbar_remove (GtkStatusbar *statusbar, + guint context_id, + guint message_id); +GDK_DEPRECATED_IN_4_10 +void gtk_statusbar_remove_all (GtkStatusbar *statusbar, + guint context_id); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkStatusbar, g_object_unref) + +G_END_DECLS + +#endif /* __GTK_STATUSBAR_H__ */ diff --git a/gtk/deprecated/meson.build b/gtk/deprecated/meson.build index dd6c8ade9d..84f6f11d04 100644 --- a/gtk/deprecated/meson.build +++ b/gtk/deprecated/meson.build @@ -33,6 +33,7 @@ gtk_deprecated_sources = [ 'deprecated/gtkliststore.c', 'deprecated/gtkrender.c', 'deprecated/gtkshow.c', + 'deprecated/gtkstatusbar.c', 'deprecated/gtkstylecontext.c', 'deprecated/gtktreedatalist.c', 'deprecated/gtktreednd.c', @@ -90,6 +91,7 @@ gtk_deprecated_headers = [ 'deprecated/gtkmessagedialog.h', 'deprecated/gtkrender.h', 'deprecated/gtkshow.h', + 'deprecated/gtkstatusbar.h', 'deprecated/gtkstylecontext.h', 'deprecated/gtktreednd.h', 'deprecated/gtktreemodel.h', diff --git a/gtk/gtk.h b/gtk/gtk.h index ccb9c98fa3..6d14c88ded 100644 --- a/gtk/gtk.h +++ b/gtk/gtk.h @@ -252,7 +252,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/gtk/gtklockbutton.c b/gtk/gtklockbutton.c deleted file mode 100644 index 5f94cfa372..0000000000 --- a/gtk/gtklockbutton.c +++ /dev/null @@ -1,587 +0,0 @@ -/* GTK - The GIMP Toolkit - * Copyright (C) 2010 Red Hat, Inc. - * Author: Matthias Clasen - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library. If not, see . - */ - -#include "config.h" - -#include "gtklockbuttonprivate.h" - -#include "gtkbox.h" -#include "gtkimage.h" -#include -#include "gtklabel.h" -#include "gtksizegroup.h" -#include "gtkstack.h" -#include "gtkprivate.h" - -/** - * GtkLockButton: - * - * `GtkLockButton` is a widget to obtain and revoke authorizations - * needed to operate the controls. - * - * ![An example GtkLockButton](lock-button.png) - * - * It is typically used in preference dialogs or control panels. - * - * The required authorization is represented by a `GPermission` object. - * Concrete implementations of `GPermission` may use PolicyKit or some - * other authorization framework. To obtain a PolicyKit-based - * `GPermission`, use `polkit_permission_new()`. - * - * If the user is not currently allowed to perform the action, but can - * obtain the permission, the widget looks like this: - * - * ![](lockbutton-locked.png) - * - * and the user can click the button to request the permission. Depending - * on the platform, this may pop up an authentication dialog or ask the user - * to authenticate in some other way. Once the user has obtained the permission, - * the widget changes to this: - * - * ![](lockbutton-unlocked.png) - * - * and the permission can be dropped again by clicking the button. If the user - * is not able to obtain the permission at all, the widget looks like this: - * - * ![](lockbutton-sorry.png) - * - * If the user has the permission and cannot drop it, the button is hidden. - * - * The text (and tooltips) that are shown in the various cases can be adjusted - * with the [property@Gtk.LockButton:text-lock], - * [property@Gtk.LockButton:text-unlock], - * [property@Gtk.LockButton:tooltip-lock], - * [property@Gtk.LockButton:tooltip-unlock] and - * [property@Gtk.LockButton:tooltip-not-authorized] properties. - */ - -struct _GtkLockButton -{ - GtkButton parent_instance; - - GPermission *permission; - GCancellable *cancellable; - - char *tooltip_lock; - char *tooltip_unlock; - char *tooltip_not_authorized; - GIcon *icon_lock; - GIcon *icon_unlock; - - GtkWidget *box; - GtkWidget *image; - GtkWidget *stack; - GtkWidget *label_lock; - GtkWidget *label_unlock; -}; - -typedef struct _GtkLockButtonClass GtkLockButtonClass; -struct _GtkLockButtonClass -{ - GtkButtonClass parent_class; -}; - -enum -{ - PROP_0, - PROP_PERMISSION, - PROP_TEXT_LOCK, - PROP_TEXT_UNLOCK, - PROP_TOOLTIP_LOCK, - PROP_TOOLTIP_UNLOCK, - PROP_TOOLTIP_NOT_AUTHORIZED -}; - -static void update_state (GtkLockButton *button); -static void gtk_lock_button_clicked (GtkButton *button); - -static void on_permission_changed (GPermission *permission, - GParamSpec *pspec, - gpointer user_data); - -G_DEFINE_TYPE (GtkLockButton, gtk_lock_button, GTK_TYPE_BUTTON) - -static void -gtk_lock_button_finalize (GObject *object) -{ - GtkLockButton *button = GTK_LOCK_BUTTON (object); - - g_free (button->tooltip_lock); - g_free (button->tooltip_unlock); - g_free (button->tooltip_not_authorized); - - g_object_unref (button->icon_lock); - g_object_unref (button->icon_unlock); - - if (button->cancellable != NULL) - { - g_cancellable_cancel (button->cancellable); - g_object_unref (button->cancellable); - } - - if (button->permission) - { - g_signal_handlers_disconnect_by_func (button->permission, - on_permission_changed, - button); - g_object_unref (button->permission); - } - - G_OBJECT_CLASS (gtk_lock_button_parent_class)->finalize (object); -} - -static void -gtk_lock_button_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - GtkLockButton *button = GTK_LOCK_BUTTON (object); - - switch (property_id) - { - case PROP_PERMISSION: - g_value_set_object (value, button->permission); - break; - - case PROP_TEXT_LOCK: - g_value_set_string (value, gtk_label_get_text (GTK_LABEL (button->label_lock))); - break; - - case PROP_TEXT_UNLOCK: - g_value_set_string (value, gtk_label_get_text (GTK_LABEL (button->label_unlock))); - break; - - case PROP_TOOLTIP_LOCK: - g_value_set_string (value, button->tooltip_lock); - break; - - case PROP_TOOLTIP_UNLOCK: - g_value_set_string (value, button->tooltip_unlock); - break; - - case PROP_TOOLTIP_NOT_AUTHORIZED: - g_value_set_string (value, button->tooltip_not_authorized); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -gtk_lock_button_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - GtkLockButton *button = GTK_LOCK_BUTTON (object); - - switch (property_id) - { - case PROP_PERMISSION: - gtk_lock_button_set_permission (button, g_value_get_object (value)); - break; - - case PROP_TEXT_LOCK: - gtk_label_set_text (GTK_LABEL (button->label_lock), g_value_get_string (value)); - break; - - case PROP_TEXT_UNLOCK: - gtk_label_set_text (GTK_LABEL (button->label_unlock), g_value_get_string (value)); - break; - - case PROP_TOOLTIP_LOCK: - g_free (button->tooltip_lock); - button->tooltip_lock = g_value_dup_string (value); - break; - - case PROP_TOOLTIP_UNLOCK: - g_free (button->tooltip_unlock); - button->tooltip_unlock = g_value_dup_string (value); - break; - - case PROP_TOOLTIP_NOT_AUTHORIZED: - g_free (button->tooltip_not_authorized); - button->tooltip_not_authorized = g_value_dup_string (value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } - - update_state (button); -} - -static void -gtk_lock_button_init (GtkLockButton *button) -{ - const char *names[3]; - - gtk_widget_init_template (GTK_WIDGET (button)); - - names[0] = "changes-allow-symbolic"; - names[1] = "changes-allow"; - names[2] = NULL; - button->icon_unlock = g_themed_icon_new_from_names ((char **) names, -1); - - names[0] = "changes-prevent-symbolic"; - names[1] = "changes-prevent"; - names[2] = NULL; - button->icon_lock = g_themed_icon_new_from_names ((char **) names, -1); - - update_state (button); - - gtk_widget_add_css_class (GTK_WIDGET (button), I_("lock")); -} - -static void -gtk_lock_button_class_init (GtkLockButtonClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass); - - gobject_class->finalize = gtk_lock_button_finalize; - gobject_class->get_property = gtk_lock_button_get_property; - gobject_class->set_property = gtk_lock_button_set_property; - - button_class->clicked = gtk_lock_button_clicked; - - /** - * GtkLockButton:permission: (attributes org.gtk.Property.get=gtk_lock_button_get_permission org.gtk.Property.set=gtk_lock_button_set_permission) - * - * The `GPermission object controlling this button. - */ - g_object_class_install_property (gobject_class, PROP_PERMISSION, - g_param_spec_object ("permission", NULL, NULL, - G_TYPE_PERMISSION, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS)); - - /** - * GtkLockButton:text-lock: - * - * The text to display when prompting the user to lock. - */ - g_object_class_install_property (gobject_class, PROP_TEXT_LOCK, - g_param_spec_string ("text-lock", NULL, NULL, - _("Lock"), - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT | - G_PARAM_STATIC_STRINGS)); - - /** - * GtkLockButton:text-unlock: - * - * The text to display when prompting the user to unlock. - */ - g_object_class_install_property (gobject_class, PROP_TEXT_UNLOCK, - g_param_spec_string ("text-unlock", NULL, NULL, - _("Unlock"), - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT | - G_PARAM_STATIC_STRINGS)); - - /** - * GtkLockButton:tooltip-lock: - * - * The tooltip to display when prompting the user to lock. - */ - g_object_class_install_property (gobject_class, PROP_TOOLTIP_LOCK, - g_param_spec_string ("tooltip-lock", NULL, NULL, - _("Dialog is unlocked.\nClick to prevent further changes"), - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT | - G_PARAM_STATIC_STRINGS)); - - /** - * GtkLockButton:tooltip-unlock: - * - * The tooltip to display when prompting the user to unlock. - */ - g_object_class_install_property (gobject_class, PROP_TOOLTIP_UNLOCK, - g_param_spec_string ("tooltip-unlock", NULL, NULL, - _("Dialog is locked.\nClick to make changes"), - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT | - G_PARAM_STATIC_STRINGS)); - - /** - * GtkLockButton:tooltip-not-authorized: - * - * The tooltip to display when the user cannot obtain authorization. - */ - g_object_class_install_property (gobject_class, PROP_TOOLTIP_NOT_AUTHORIZED, - g_param_spec_string ("tooltip-not-authorized", NULL, NULL, - _("System policy prevents changes.\nContact your system administrator"), - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT | - G_PARAM_STATIC_STRINGS)); - - /* Bind class to template - */ - gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/ui/gtklockbutton.ui"); - gtk_widget_class_bind_template_child (widget_class, GtkLockButton, box); - gtk_widget_class_bind_template_child (widget_class, GtkLockButton, image); - gtk_widget_class_bind_template_child (widget_class, GtkLockButton, label_lock); - gtk_widget_class_bind_template_child (widget_class, GtkLockButton, label_unlock); - gtk_widget_class_bind_template_child (widget_class, GtkLockButton, stack); - - gtk_widget_class_set_css_name (widget_class, I_("button")); -} - -static void -update_state (GtkLockButton *button) -{ - gboolean allowed; - gboolean can_acquire; - gboolean can_release; - gboolean sensitive; - gboolean visible; - GIcon *icon; - const char *tooltip; - - if (button->permission) - { - allowed = g_permission_get_allowed (button->permission); - can_acquire = g_permission_get_can_acquire (button->permission); - can_release = g_permission_get_can_release (button->permission); - } - else - { - allowed = TRUE; - can_acquire = FALSE; - can_release = FALSE; - } - - if (allowed && can_release) - { - visible = TRUE; - sensitive = TRUE; - icon = button->icon_lock; - tooltip = button->tooltip_lock; - } - else if (allowed && !can_release) - { - visible = FALSE; - sensitive = TRUE; - icon = button->icon_lock; - tooltip = button->tooltip_lock; - } - else if (!allowed && can_acquire) - { - visible = TRUE; - sensitive = TRUE; - icon = button->icon_unlock; - tooltip = button->tooltip_unlock; - } - else if (!allowed && !can_acquire) - { - visible = TRUE; - sensitive = FALSE; - icon = button->icon_unlock; - tooltip = button->tooltip_not_authorized; - } - else - { - g_assert_not_reached (); - } - - gtk_image_set_from_gicon (GTK_IMAGE (button->image), icon); - gtk_stack_set_visible_child (GTK_STACK (button->stack), - allowed ? button->label_lock : button->label_unlock); - gtk_widget_set_tooltip_markup (GTK_WIDGET (button), tooltip); - gtk_widget_set_sensitive (GTK_WIDGET (button), sensitive); - gtk_widget_set_visible (GTK_WIDGET (button), visible); -} - -static void -on_permission_changed (GPermission *permission, - GParamSpec *pspec, - gpointer user_data) -{ - GtkLockButton *button = GTK_LOCK_BUTTON (user_data); - - update_state (button); -} - -static void -acquire_cb (GObject *source, - GAsyncResult *result, - gpointer user_data) -{ - GtkLockButton *button = GTK_LOCK_BUTTON (user_data); - GError *error; - - error = NULL; - if (!g_permission_acquire_finish (button->permission, result, &error)) - { - g_warning ("Error acquiring permission: %s", error->message); - g_error_free (error); - } - - g_object_unref (button->cancellable); - button->cancellable = NULL; - - update_state (button); -} - -static void -release_cb (GObject *source, - GAsyncResult *result, - gpointer user_data) -{ - GtkLockButton *button = GTK_LOCK_BUTTON (user_data); - GError *error; - - error = NULL; - if (!g_permission_release_finish (button->permission, result, &error)) - { - g_warning ("Error releasing permission: %s", error->message); - g_error_free (error); - } - - g_object_unref (button->cancellable); - button->cancellable = NULL; - - update_state (button); -} - -static void -gtk_lock_button_clicked (GtkButton *widget) -{ - GtkLockButton *button = GTK_LOCK_BUTTON (widget); - - /* if we already have a pending interactive check or permission is not set, - * then do nothing - */ - if (button->cancellable != NULL || button->permission == NULL) - return; - - if (g_permission_get_allowed (button->permission)) - { - if (g_permission_get_can_release (button->permission)) - { - button->cancellable = g_cancellable_new (); - - g_permission_release_async (button->permission, - button->cancellable, - release_cb, - button); - } - } - else - { - if (g_permission_get_can_acquire (button->permission)) - { - button->cancellable = g_cancellable_new (); - - g_permission_acquire_async (button->permission, - button->cancellable, - acquire_cb, - button); - } - } -} - -/** - * gtk_lock_button_new: - * @permission: (nullable): a `GPermission` - * - * Creates a new lock button which reflects the @permission. - * - * Returns: a new `GtkLockButton` - */ -GtkWidget * -gtk_lock_button_new (GPermission *permission) -{ - return GTK_WIDGET (g_object_new (GTK_TYPE_LOCK_BUTTON, - "permission", permission, - NULL)); -} - -/** - * gtk_lock_button_get_permission: (attributes org.gtk.Method.get_property=permission) - * @button: a `GtkLockButton` - * - * Obtains the `GPermission` object that controls @button. - * - * Returns: (transfer none) (nullable): the `GPermission` of @button - */ -GPermission * -gtk_lock_button_get_permission (GtkLockButton *button) -{ - g_return_val_if_fail (GTK_IS_LOCK_BUTTON (button), NULL); - - return button->permission; -} - -/** - * gtk_lock_button_set_permission: (attributes org.gtk.Method.set_property=permission) - * @button: a `GtkLockButton` - * @permission: (nullable): a `GPermission` object - * - * Sets the `GPermission` object that controls @button. - */ -void -gtk_lock_button_set_permission (GtkLockButton *button, - GPermission *permission) -{ - g_return_if_fail (GTK_IS_LOCK_BUTTON (button)); - g_return_if_fail (permission == NULL || G_IS_PERMISSION (permission)); - - if (button->permission != permission) - { - if (button->permission) - { - g_signal_handlers_disconnect_by_func (button->permission, - on_permission_changed, - button); - g_object_unref (button->permission); - } - - button->permission = permission; - - if (button->permission) - { - g_object_ref (button->permission); - g_signal_connect (button->permission, "notify", - G_CALLBACK (on_permission_changed), button); - } - - update_state (button); - - g_object_notify (G_OBJECT (button), "permission"); - } -} - -const char * -_gtk_lock_button_get_current_text (GtkLockButton *button) -{ - GtkWidget *label; - - g_return_val_if_fail (GTK_IS_LOCK_BUTTON (button), NULL); - - label = gtk_stack_get_visible_child (GTK_STACK (button->stack)); - - return gtk_label_get_text (GTK_LABEL (label)); -} - diff --git a/gtk/gtklockbutton.h b/gtk/gtklockbutton.h deleted file mode 100644 index 5d24b06f38..0000000000 --- a/gtk/gtklockbutton.h +++ /dev/null @@ -1,47 +0,0 @@ -/* GTK - The GIMP Toolkit - * Copyright (C) 2010 Red Hat, Inc. - * Author: Matthias Clasen - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library. If not, see . - */ - -#ifndef __GTK_LOCK_BUTTON_H__ -#define __GTK_LOCK_BUTTON_H__ - -#include -#include - -G_BEGIN_DECLS - -#define GTK_TYPE_LOCK_BUTTON (gtk_lock_button_get_type ()) -#define GTK_LOCK_BUTTON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_LOCK_BUTTON, GtkLockButton)) -#define GTK_IS_LOCK_BUTTON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_LOCK_BUTTON)) - -typedef struct _GtkLockButton GtkLockButton; - -GDK_AVAILABLE_IN_ALL -GType gtk_lock_button_get_type (void) G_GNUC_CONST; -GDK_AVAILABLE_IN_ALL -GtkWidget *gtk_lock_button_new (GPermission *permission); -GDK_AVAILABLE_IN_ALL -GPermission *gtk_lock_button_get_permission (GtkLockButton *button); -GDK_AVAILABLE_IN_ALL -void gtk_lock_button_set_permission (GtkLockButton *button, - GPermission *permission); - -G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkLockButton, g_object_unref) - -G_END_DECLS - -#endif /* __GTK_LOCK_BUTTON_H__ */ diff --git a/gtk/gtklockbuttonprivate.h b/gtk/gtklockbuttonprivate.h deleted file mode 100644 index f029bf8b67..0000000000 --- a/gtk/gtklockbuttonprivate.h +++ /dev/null @@ -1,30 +0,0 @@ -/* GTK - The GIMP Toolkit - * Copyright (C) 2010 Red Hat, Inc. - * Author: Matthias Clasen - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library. If not, see . - */ - -#ifndef __GTK_LOCK_BUTTON_PRIVATE_H__ -#define __GTK_LOCK_BUTTON_PRIVATE_H__ - -#include "gtklockbutton.h" - -G_BEGIN_DECLS - -const char * _gtk_lock_button_get_current_text (GtkLockButton *button); - -G_END_DECLS - -#endif /* __GTK_LOCK_BUTTON_PRIVATE_H__ */ diff --git a/gtk/gtkstatusbar.c b/gtk/gtkstatusbar.c deleted file mode 100644 index 5cbea341d2..0000000000 --- a/gtk/gtkstatusbar.c +++ /dev/null @@ -1,507 +0,0 @@ -/* GTK - The GIMP Toolkit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * GtkStatusbar Copyright (C) 1998 Shawn T. Amundson - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - */ - -/* - * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -#include "config.h" - -#include "gtkstatusbar.h" -#include "gtkstatusbarprivate.h" - -#include "gtkbinlayout.h" -#include "gtklabel.h" -#include "gtkmarshalers.h" -#include "gtkprivate.h" -#include "gtkorientable.h" -#include "gtktypebuiltins.h" -#include "gtkwidgetprivate.h" - -/** - * GtkStatusbar: - * - * A `GtkStatusbar` widget is usually placed along the bottom of an application's - * main [class@Gtk.Window]. - * - * ![An example GtkStatusbar](statusbar.png) - * - * A `GtkStatusBar` may provide a regular commentary of the application's - * status (as is usually the case in a web browser, for example), or may be - * used to simply output a message when the status changes, (when an upload - * is complete in an FTP client, for example). - * - * Status bars in GTK maintain a stack of messages. The message at - * the top of the each bar’s stack is the one that will currently be displayed. - * - * Any messages added to a statusbar’s stack must specify a context id that - * is used to uniquely identify the source of a message. This context id can - * be generated by [method@Gtk.Statusbar.get_context_id], given a message and - * the statusbar that it will be added to. Note that messages are stored in a - * stack, and when choosing which message to display, the stack structure is - * adhered to, regardless of the context identifier of a message. - * - * One could say that a statusbar maintains one stack of messages for - * display purposes, but allows multiple message producers to maintain - * sub-stacks of the messages they produced (via context ids). - * - * Status bars are created using [ctor@Gtk.Statusbar.new]. - * - * Messages are added to the bar’s stack with [method@Gtk.Statusbar.push]. - * - * The message at the top of the stack can be removed using - * [method@Gtk.Statusbar.pop]. A message can be removed from anywhere in the - * stack if its message id was recorded at the time it was added. This is done - * using [method@Gtk.Statusbar.remove]. - * - * ## CSS node - * - * `GtkStatusbar` has a single CSS node with name `statusbar`. - */ - -typedef struct _GtkStatusbarMsg GtkStatusbarMsg; - -typedef struct _GtkStatusbarClass GtkStatusbarClass; - -struct _GtkStatusbar -{ - GtkWidget parent_instance; - - GtkWidget *label; - GtkWidget *message_area; - - GSList *messages; - GSList *keys; - - guint seq_context_id; - guint seq_message_id; -}; - -struct _GtkStatusbarClass -{ - GtkWidgetClass parent_class; - - void (*text_pushed) (GtkStatusbar *statusbar, - guint context_id, - const char *text); - void (*text_popped) (GtkStatusbar *statusbar, - guint context_id, - const char *text); -}; - -struct _GtkStatusbarMsg -{ - char *text; - guint context_id; - guint message_id; -}; - -enum -{ - SIGNAL_TEXT_PUSHED, - SIGNAL_TEXT_POPPED, - SIGNAL_LAST -}; - -static void gtk_statusbar_update (GtkStatusbar *statusbar, - guint context_id, - const char *text); - -static void gtk_statusbar_msg_free (GtkStatusbarMsg *msg); - -static guint statusbar_signals[SIGNAL_LAST] = { 0 }; - -G_DEFINE_TYPE (GtkStatusbar, gtk_statusbar, GTK_TYPE_WIDGET) - -static void -gtk_statusbar_dispose (GObject *object) -{ - GtkStatusbar *self = GTK_STATUSBAR (object); - - g_slist_free_full (self->messages, (GDestroyNotify) gtk_statusbar_msg_free); - self->messages = NULL; - - g_slist_free_full (self->keys, g_free); - self->keys = NULL; - - gtk_widget_dispose_template (GTK_WIDGET (self), GTK_TYPE_STATUSBAR); - - G_OBJECT_CLASS (gtk_statusbar_parent_class)->dispose (object); -} - -static void -gtk_statusbar_class_init (GtkStatusbarClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); - - object_class->dispose = gtk_statusbar_dispose; - - class->text_pushed = gtk_statusbar_update; - class->text_popped = gtk_statusbar_update; - - /** - * GtkStatusbar::text-pushed: - * @statusbar: the object which received the signal - * @context_id: the context id of the relevant message/statusbar - * @text: the message that was pushed - * - * Emitted whenever a new message gets pushed onto a statusbar's stack. - */ - statusbar_signals[SIGNAL_TEXT_PUSHED] = - g_signal_new (I_("text-pushed"), - G_OBJECT_CLASS_TYPE (class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GtkStatusbarClass, text_pushed), - NULL, NULL, - _gtk_marshal_VOID__UINT_STRING, - G_TYPE_NONE, 2, - G_TYPE_UINT, - G_TYPE_STRING); - - /** - * GtkStatusbar::text-popped: - * @statusbar: the object which received the signal - * @context_id: the context id of the relevant message/statusbar - * @text: the message that was just popped - * - * Emitted whenever a new message is popped off a statusbar's stack. - */ - statusbar_signals[SIGNAL_TEXT_POPPED] = - g_signal_new (I_("text-popped"), - G_OBJECT_CLASS_TYPE (class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GtkStatusbarClass, text_popped), - NULL, NULL, - _gtk_marshal_VOID__UINT_STRING, - G_TYPE_NONE, 2, - G_TYPE_UINT, - G_TYPE_STRING); - - /* Bind class to template - */ - gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/ui/gtkstatusbar.ui"); - gtk_widget_class_bind_template_child_internal (widget_class, GtkStatusbar, message_area); - gtk_widget_class_bind_template_child (widget_class, GtkStatusbar, label); - - gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); - gtk_widget_class_set_css_name (widget_class, I_("statusbar")); -} - -static void -gtk_statusbar_init (GtkStatusbar *statusbar) -{ - statusbar->seq_context_id = 1; - statusbar->seq_message_id = 1; - statusbar->messages = NULL; - statusbar->keys = NULL; - - gtk_widget_init_template (GTK_WIDGET (statusbar)); -} - -/** - * gtk_statusbar_new: - * - * Creates a new `GtkStatusbar` ready for messages. - * - * Returns: the new `GtkStatusbar` - */ -GtkWidget* -gtk_statusbar_new (void) -{ - return g_object_new (GTK_TYPE_STATUSBAR, NULL); -} - -static void -gtk_statusbar_update (GtkStatusbar *statusbar, - guint context_id, - const char *text) -{ - g_return_if_fail (GTK_IS_STATUSBAR (statusbar)); - - if (!text) - text = ""; - - gtk_label_set_text (GTK_LABEL (statusbar->label), text); -} - -/** - * gtk_statusbar_get_context_id: - * @statusbar: a `GtkStatusbar` - * @context_description: textual description of what context - * the new message is being used in - * - * Returns a new context identifier, given a description - * of the actual context. - * - * Note that the description is not shown in the UI. - * - * Returns: an integer id - */ -guint -gtk_statusbar_get_context_id (GtkStatusbar *statusbar, - const char *context_description) -{ - char *string; - guint id; - - g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), 0); - g_return_val_if_fail (context_description != NULL, 0); - - /* we need to preserve namespaces on object data */ - string = g_strconcat ("gtk-status-bar-context:", context_description, NULL); - - id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (statusbar), string)); - if (id == 0) - { - id = statusbar->seq_context_id++; - g_object_set_data_full (G_OBJECT (statusbar), string, GUINT_TO_POINTER (id), NULL); - statusbar->keys = g_slist_prepend (statusbar->keys, string); - } - else - g_free (string); - - return id; -} - -static GtkStatusbarMsg * -gtk_statusbar_msg_create (GtkStatusbar *statusbar, - guint context_id, - const char *text) -{ - GtkStatusbarMsg *msg; - - msg = g_slice_new (GtkStatusbarMsg); - msg->text = g_strdup (text); - msg->context_id = context_id; - msg->message_id = statusbar->seq_message_id++; - - return msg; -} - -static void -gtk_statusbar_msg_free (GtkStatusbarMsg *msg) -{ - g_free (msg->text); - g_slice_free (GtkStatusbarMsg, msg); -} - -/** - * gtk_statusbar_push: - * @statusbar: a `GtkStatusbar` - * @context_id: the message’s context id, as returned by - * gtk_statusbar_get_context_id() - * @text: the message to add to the statusbar - * - * Pushes a new message onto a statusbar’s stack. - * - * Returns: a message id that can be used with - * [method@Gtk.Statusbar.remove]. - */ -guint -gtk_statusbar_push (GtkStatusbar *statusbar, - guint context_id, - const char *text) -{ - GtkStatusbarMsg *msg; - - g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), 0); - g_return_val_if_fail (text != NULL, 0); - - msg = gtk_statusbar_msg_create (statusbar, context_id, text); - statusbar->messages = g_slist_prepend (statusbar->messages, msg); - - g_signal_emit (statusbar, - statusbar_signals[SIGNAL_TEXT_PUSHED], - 0, - msg->context_id, - msg->text); - - return msg->message_id; -} - -/** - * gtk_statusbar_pop: - * @statusbar: a `GtkStatusbar` - * @context_id: a context identifier - * - * Removes the first message in the `GtkStatusbar`’s stack - * with the given context id. - * - * Note that this may not change the displayed message, - * if the message at the top of the stack has a different - * context id. - */ -void -gtk_statusbar_pop (GtkStatusbar *statusbar, - guint context_id) -{ - GtkStatusbarMsg *msg; - - g_return_if_fail (GTK_IS_STATUSBAR (statusbar)); - - if (statusbar->messages) - { - GSList *list; - - for (list = statusbar->messages; list; list = list->next) - { - msg = list->data; - - if (msg->context_id == context_id) - { - statusbar->messages = g_slist_remove_link (statusbar->messages, list); - gtk_statusbar_msg_free (msg); - g_slist_free_1 (list); - break; - } - } - } - - msg = statusbar->messages ? statusbar->messages->data : NULL; - - g_signal_emit (statusbar, - statusbar_signals[SIGNAL_TEXT_POPPED], - 0, - (guint) (msg ? msg->context_id : 0), - msg ? msg->text : NULL); -} - -/** - * gtk_statusbar_remove: - * @statusbar: a `GtkStatusbar` - * @context_id: a context identifier - * @message_id: a message identifier, as returned by [method@Gtk.Statusbar.push] - * - * Forces the removal of a message from a statusbar’s stack. - * The exact @context_id and @message_id must be specified. - */ -void -gtk_statusbar_remove (GtkStatusbar *statusbar, - guint context_id, - guint message_id) -{ - GtkStatusbarMsg *msg; - - g_return_if_fail (GTK_IS_STATUSBAR (statusbar)); - g_return_if_fail (message_id > 0); - - msg = statusbar->messages ? statusbar->messages->data : NULL; - if (msg) - { - GSList *list; - - /* care about signal emission if the topmost item is removed */ - if (msg->context_id == context_id && - msg->message_id == message_id) - { - gtk_statusbar_pop (statusbar, context_id); - return; - } - - for (list = statusbar->messages; list; list = list->next) - { - msg = list->data; - - if (msg->context_id == context_id && - msg->message_id == message_id) - { - statusbar->messages = g_slist_remove_link (statusbar->messages, list); - gtk_statusbar_msg_free (msg); - g_slist_free_1 (list); - - break; - } - } - } -} - -/** - * gtk_statusbar_remove_all: - * @statusbar: a `GtkStatusbar` - * @context_id: a context identifier - * - * Forces the removal of all messages from a statusbar's - * stack with the exact @context_id. - */ -void -gtk_statusbar_remove_all (GtkStatusbar *statusbar, - guint context_id) -{ - GtkStatusbarMsg *msg; - GSList *prev, *list; - - g_return_if_fail (GTK_IS_STATUSBAR (statusbar)); - - if (statusbar->messages == NULL) - return; - - /* We special-case the topmost message at the bottom of this - * function: - * If we need to pop it, we have to update various state and we want - * an up-to-date list of remaining messages in that case. - */ - prev = statusbar->messages; - list = prev->next; - - while (list != NULL) - { - msg = list->data; - - if (msg->context_id == context_id) - { - prev->next = list->next; - - gtk_statusbar_msg_free (msg); - g_slist_free_1 (list); - - list = prev->next; - } - else - { - prev = list; - list = prev->next; - } - } - - /* Treat topmost message here */ - msg = statusbar->messages->data; - if (msg->context_id == context_id) - { - gtk_statusbar_pop (statusbar, context_id); - } -} - -/** - * gtk_statusbar_get_message: - * @statusbar: a `GtkStatusbar` - * - * Retrieves the contents of the label in `GtkStatusbar`. - * - * Returns: (transfer none): the contents of the statusbar - */ -const char * -gtk_statusbar_get_message (GtkStatusbar *statusbar) -{ - g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), NULL); - - return gtk_label_get_label (GTK_LABEL (statusbar->label)); -} diff --git a/gtk/gtkstatusbar.h b/gtk/gtkstatusbar.h deleted file mode 100644 index 39b710b227..0000000000 --- a/gtk/gtkstatusbar.h +++ /dev/null @@ -1,69 +0,0 @@ -/* GTK - The GIMP Toolkit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * GtkStatusbar Copyright (C) 1998 Shawn T. Amundson - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - */ - -/* - * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -#ifndef __GTK_STATUSBAR_H__ -#define __GTK_STATUSBAR_H__ - -#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) -#error "Only can be included directly." -#endif - -#include - -G_BEGIN_DECLS - -#define GTK_TYPE_STATUSBAR (gtk_statusbar_get_type ()) -#define GTK_STATUSBAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_STATUSBAR, GtkStatusbar)) -#define GTK_IS_STATUSBAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_STATUSBAR)) - -typedef struct _GtkStatusbar GtkStatusbar; - -GDK_AVAILABLE_IN_ALL -GType gtk_statusbar_get_type (void) G_GNUC_CONST; -GDK_AVAILABLE_IN_ALL -GtkWidget* gtk_statusbar_new (void); -GDK_AVAILABLE_IN_ALL -guint gtk_statusbar_get_context_id (GtkStatusbar *statusbar, - const char *context_description); -GDK_AVAILABLE_IN_ALL -guint gtk_statusbar_push (GtkStatusbar *statusbar, - guint context_id, - const char *text); -GDK_AVAILABLE_IN_ALL -void gtk_statusbar_pop (GtkStatusbar *statusbar, - guint context_id); -GDK_AVAILABLE_IN_ALL -void gtk_statusbar_remove (GtkStatusbar *statusbar, - guint context_id, - guint message_id); -GDK_AVAILABLE_IN_ALL -void gtk_statusbar_remove_all (GtkStatusbar *statusbar, - guint context_id); - -G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkStatusbar, g_object_unref) - -G_END_DECLS - -#endif /* __GTK_STATUSBAR_H__ */ diff --git a/gtk/meson.build b/gtk/meson.build index 13d2404630..281c652f3d 100644 --- a/gtk/meson.build +++ b/gtk/meson.build @@ -360,7 +360,6 @@ gtk_public_sources = files([ 'gtkstack.c', 'gtkstacksidebar.c', 'gtkstackswitcher.c', - 'gtkstatusbar.c', 'gtkstringfilter.c', 'gtkstringlist.c', 'gtkstringsorter.c', @@ -593,7 +592,6 @@ gtk_public_headers = files([ 'gtkstack.h', 'gtkstacksidebar.h', 'gtkstackswitcher.h', - 'gtkstatusbar.h', 'gtkstringfilter.h', 'gtkstringlist.h', 'gtkstringsorter.h', diff --git a/tests/testcolumnview.c b/tests/testcolumnview.c index 6b85251b50..4039e9ec79 100644 --- a/tests/testcolumnview.c +++ b/tests/testcolumnview.c @@ -1,5 +1,7 @@ #include +G_GNUC_BEGIN_IGNORE_DEPRECATIONS + GSList *pending = NULL; guint active = 0; diff --git a/tests/testlistview.c b/tests/testlistview.c index 2ceb672169..f0f172f98f 100644 --- a/tests/testlistview.c +++ b/tests/testlistview.c @@ -1,5 +1,7 @@ #include +G_GNUC_BEGIN_IGNORE_DEPRECATIONS + #define FILE_INFO_TYPE_SELECTION (file_info_selection_get_type ()) G_DECLARE_FINAL_TYPE (FileInfoSelection, file_info_selection, FILE_INFO, SELECTION, GObject) diff --git a/testsuite/reftests/statusbar-remove-all.c b/testsuite/reftests/statusbar-remove-all.c index 6960fd1625..2a4ac7cbdb 100644 --- a/testsuite/reftests/statusbar-remove-all.c +++ b/testsuite/reftests/statusbar-remove-all.c @@ -17,6 +17,7 @@ #include +G_GNUC_BEGIN_IGNORE_DEPRECATIONS G_MODULE_EXPORT void statusbar_remove_all (GtkStatusbar *s)