From bfb7f43dbcbe537ae2ebbefb6b386a14d790fe72 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Fri, 20 Sep 2019 19:24:40 +0200 Subject: [PATCH] libgimp: add GimpProcedureDialog, the new dialog class for plug-ins It knows about the procedure and its config, and so far implements the entire construction boilerplate and "Reset" on its own. --- libgimp/Makefile.gi | 2 + libgimp/gimpproceduredialog.c | 228 ++++++++++++++++++++++++++++++++++ libgimp/gimpproceduredialog.h | 78 ++++++++++++ libgimp/gimpui.def | 3 + libgimp/gimpui.h | 1 + libgimp/gimpuitypes.h | 2 + libgimp/meson.build | 2 + 7 files changed, 316 insertions(+) create mode 100644 libgimp/gimpproceduredialog.c create mode 100644 libgimp/gimpproceduredialog.h diff --git a/libgimp/Makefile.gi b/libgimp/Makefile.gi index 3079facadc..6739572ea4 100644 --- a/libgimp/Makefile.gi +++ b/libgimp/Makefile.gi @@ -185,6 +185,7 @@ libgimpui_introspectable_headers = \ ../libgimp/gimppaletteselectbutton.h \ ../libgimp/gimppatternselectbutton.h \ ../libgimp/gimpprocbrowserdialog.h \ + ../libgimp/gimpproceduredialog.h \ ../libgimp/gimpprocview.h \ ../libgimp/gimpprogressbar.h \ ../libgimp/gimpselectbutton.h \ @@ -205,6 +206,7 @@ libgimpui_introspectable = \ ../libgimp/gimppaletteselectbutton.c \ ../libgimp/gimppatternselectbutton.c \ ../libgimp/gimpprocbrowserdialog.c \ + ../libgimp/gimpproceduredialog.c \ ../libgimp/gimpprocview.c \ ../libgimp/gimpprogressbar.c \ ../libgimp/gimpselectbutton.c \ diff --git a/libgimp/gimpproceduredialog.c b/libgimp/gimpproceduredialog.c new file mode 100644 index 0000000000..ee06fe2264 --- /dev/null +++ b/libgimp/gimpproceduredialog.c @@ -0,0 +1,228 @@ +/* GIMP - The GNU Image Manipulation Program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * gimpproceduredialog.c + * Copyright (C) 2019 Michael Natterer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "config.h" + +#include +#include + +#include "libgimpwidgets/gimpwidgets.h" + +#include "gimp.h" +#include "gimpui.h" + +#include "libgimp-intl.h" + + +enum +{ + PROP_0, + PROP_PROCEDURE, + PROP_CONFIG, + N_PROPS +}; + +#define RESPONSE_RESET 1 + + +struct _GimpProcedureDialogPrivate +{ + GimpProcedure *procedure; + GimpProcedureConfig *config; +}; + + +static void gimp_procedure_dialog_dispose (GObject *object); +static void gimp_procedure_dialog_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void gimp_procedure_dialog_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + + +G_DEFINE_TYPE_WITH_PRIVATE (GimpProcedureDialog, gimp_procedure_dialog, + GIMP_TYPE_DIALOG) + +#define parent_class gimp_procedure_dialog_parent_class + +static GParamSpec *props[N_PROPS] = { NULL, }; + + +static void +gimp_procedure_dialog_class_init (GimpProcedureDialogClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = gimp_procedure_dialog_dispose; + object_class->get_property = gimp_procedure_dialog_get_property; + object_class->set_property = gimp_procedure_dialog_set_property; + + props[PROP_PROCEDURE] = + g_param_spec_object ("procedure", NULL, NULL, + GIMP_TYPE_PROCEDURE, + GIMP_PARAM_READWRITE); + + props[PROP_CONFIG] = + g_param_spec_object ("config", NULL, NULL, + GIMP_TYPE_PROCEDURE_CONFIG, + GIMP_PARAM_READWRITE | + G_PARAM_CONSTRUCT); + + g_object_class_install_properties (object_class, N_PROPS, props); +} + +static void +gimp_procedure_dialog_init (GimpProcedureDialog *dialog) +{ + dialog->priv = gimp_procedure_dialog_get_instance_private (dialog); +} + +static void +gimp_procedure_dialog_dispose (GObject *object) +{ + GimpProcedureDialog *dialog = GIMP_PROCEDURE_DIALOG (object); + + g_clear_object (&dialog->priv->procedure); + g_clear_object (&dialog->priv->config); + + G_OBJECT_CLASS (parent_class)->dispose (object); +} + +static void +gimp_procedure_dialog_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + GimpProcedureDialog *dialog = GIMP_PROCEDURE_DIALOG (object); + + switch (property_id) + { + case PROP_PROCEDURE: + dialog->priv->procedure = g_value_dup_object (value); + break; + + case PROP_CONFIG: + dialog->priv->config = g_value_dup_object (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +gimp_procedure_dialog_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + GimpProcedureDialog *dialog = GIMP_PROCEDURE_DIALOG (object); + + switch (property_id) + { + case PROP_PROCEDURE: + g_value_set_object (value, dialog->priv->procedure); + break; + + case PROP_CONFIG: + g_value_set_object (value, dialog->priv->config); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +GtkWidget * +gimp_procedure_dialog_new (GimpProcedure *procedure, + GimpProcedureConfig *config, + const gchar *title) +{ + GtkWidget *dialog; + gchar *role; + const gchar *help_id; + gboolean use_header_bar; + + g_return_val_if_fail (GIMP_IS_PROCEDURE (procedure), NULL); + g_return_val_if_fail (GIMP_IS_PROCEDURE_CONFIG (config), NULL); + g_return_val_if_fail (title != NULL, NULL); + + role = g_strdup_printf ("gimp-%s", gimp_procedure_get_name (procedure)); + + help_id = gimp_procedure_get_help_id (procedure); + + g_object_get (gtk_settings_get_default (), + "gtk-dialogs-use-header", &use_header_bar, + NULL); + + dialog = g_object_new (GIMP_TYPE_PROCEDURE_DIALOG, + "procedure", procedure, + "config", config, + "title", title, + "role", role, + "help-func", gimp_standard_help_func, + "help-id", help_id, + "use-header-bar", use_header_bar, + NULL); + + g_free (role); + + gimp_dialog_add_buttons (GIMP_DIALOG (dialog), + _("_Reset"), RESPONSE_RESET, + _("_Cancel"), GTK_RESPONSE_CANCEL, + _("_OK"), GTK_RESPONSE_OK, + NULL); + + gimp_dialog_set_alternative_button_order (GTK_DIALOG (dialog), + GTK_RESPONSE_OK, + RESPONSE_RESET, + GTK_RESPONSE_CANCEL, + -1); + + gimp_window_set_transient (GTK_WINDOW (dialog)); + + return GTK_WIDGET (dialog); +} + +gboolean +gimp_procedure_dialog_run (GimpProcedureDialog *dialog) +{ + g_return_val_if_fail (GIMP_IS_PROCEDURE_DIALOG (dialog), FALSE); + + while (TRUE) + { + gint response = gimp_dialog_run (GIMP_DIALOG (dialog)); + + if (response == RESPONSE_RESET) + { + gimp_config_reset (GIMP_CONFIG (dialog->priv->config)); + } + else + { + return response == GTK_RESPONSE_OK; + } + } +} diff --git a/libgimp/gimpproceduredialog.h b/libgimp/gimpproceduredialog.h new file mode 100644 index 0000000000..1c54da7589 --- /dev/null +++ b/libgimp/gimpproceduredialog.h @@ -0,0 +1,78 @@ +/* GIMP - The GNU Image Manipulation Program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * gimpproceduredialog.h + * Copyright (C) 2019 Michael Natterer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined (__GIMP_UI_H_INSIDE__) && !defined (GIMP_COMPILATION) +#error "Only can be included directly." +#endif + +#ifndef __GIMP_PROCEDURE_DIALOG_H__ +#define __GIMP_PROCEDURE_DIALOG_H__ + +G_BEGIN_DECLS + +/* For information look into the C source or the html documentation */ + + +#define GIMP_TYPE_PROCEDURE_DIALOG (gimp_procedure_dialog_get_type ()) +#define GIMP_PROCEDURE_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_PROCEDURE_DIALOG, GimpProcedureDialog)) +#define GIMP_PROCEDURE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_PROCEDURE_DIALOG, GimpProcedureDialogClass)) +#define GIMP_IS_PROCEDURE_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_PROCEDURE_DIALOG)) +#define GIMP_IS_PROCEDURE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_PROCEDURE_DIALOG)) +#define GIMP_PROCEDURE_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_PROCEDURE_DIALOG, GimpProcedureDialogClass)) + + +typedef struct _GimpProcedureDialogClass GimpProcedureDialogClass; +typedef struct _GimpProcedureDialogPrivate GimpProcedureDialogPrivate; + +struct _GimpProcedureDialog +{ + GimpDialog parent_instance; + + GimpProcedureDialogPrivate *priv; +}; + +struct _GimpProcedureDialogClass +{ + GimpDialogClass parent_class; + + /* Padding for future expansion */ + void (*_gimp_reserved1) (void); + void (*_gimp_reserved2) (void); + void (*_gimp_reserved3) (void); + void (*_gimp_reserved4) (void); + void (*_gimp_reserved5) (void); + void (*_gimp_reserved6) (void); + void (*_gimp_reserved7) (void); + void (*_gimp_reserved8) (void); +}; + + +GType gimp_procedure_dialog_get_type (void) G_GNUC_CONST; + +GtkWidget * gimp_procedure_dialog_new (GimpProcedure *procedure, + GimpProcedureConfig *config, + const gchar *title); + +gboolean gimp_procedure_dialog_run (GimpProcedureDialog *dialog); + + +G_END_DECLS + +#endif /* __GIMP_PROCEDURE_DIALOG_H__ */ diff --git a/libgimp/gimpui.def b/libgimp/gimpui.def index 3d97311b5a..3061930900 100644 --- a/libgimp/gimpui.def +++ b/libgimp/gimpui.def @@ -44,6 +44,9 @@ EXPORTS gimp_proc_browser_dialog_get_type gimp_proc_browser_dialog_new gimp_proc_view_new + gimp_procedure_dialog_get_type + gimp_procedure_dialog_new + gimp_procedure_dialog_run gimp_progress_bar_get_type gimp_progress_bar_new gimp_select_button_close_popup diff --git a/libgimp/gimpui.h b/libgimp/gimpui.h index 334329c7a7..b2e515821c 100644 --- a/libgimp/gimpui.h +++ b/libgimp/gimpui.h @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include diff --git a/libgimp/gimpuitypes.h b/libgimp/gimpuitypes.h index 06178d184b..aa168d760a 100644 --- a/libgimp/gimpuitypes.h +++ b/libgimp/gimpuitypes.h @@ -28,6 +28,8 @@ G_BEGIN_DECLS /* For information look into the html documentation */ +typedef struct _GimpProcedureDialog GimpProcedureDialog; + typedef struct _GimpAspectPreview GimpAspectPreview; typedef struct _GimpDrawablePreview GimpDrawablePreview; typedef struct _GimpProcBrowserDialog GimpProcBrowserDialog; diff --git a/libgimp/meson.build b/libgimp/meson.build index ab72c90f03..fa7e407070 100644 --- a/libgimp/meson.build +++ b/libgimp/meson.build @@ -231,6 +231,7 @@ libgimpui_sources_introspectable = [ 'gimppaletteselectbutton.c', 'gimppatternselectbutton.c', 'gimpprocbrowserdialog.c', + 'gimpproceduredialog.c', 'gimpprocview.c', 'gimpprogressbar.c', 'gimpselectbutton.c', @@ -256,6 +257,7 @@ libgimpui_headers_introspectable = [ 'gimppaletteselectbutton.h', 'gimppatternselectbutton.h', 'gimpprocbrowserdialog.h', + 'gimpproeduredialog.h', 'gimpprocview.h', 'gimpprogressbar.h', 'gimpselectbutton.h',