From 8f7a3a637f6a465e78e88490a03f539f0d8fdc1a Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Tue, 23 Jul 2019 01:06:21 +0200 Subject: Refactor a lot of the parameter handling code Many fixes, improvements and simplifications to existing code. Implements the first part of the changes discussed in https://gitlab.com/inkscape/inkscape/issues/333 --- src/extension/CMakeLists.txt | 6 +- src/extension/dbus/document-interface.cpp | 2 +- src/extension/extension.cpp | 307 +++++++++--------- src/extension/extension.h | 136 ++++---- src/extension/internal/bitmap/addNoise.cpp | 2 +- src/extension/internal/bitmap/channel.cpp | 2 +- src/extension/internal/bitmap/levelChannel.cpp | 2 +- src/extension/internal/cairo-ps-out.cpp | 4 +- src/extension/internal/cairo-renderer-pdf-out.cpp | 2 +- src/extension/internal/filter/blurs.h | 4 +- src/extension/internal/filter/bumps.h | 14 +- src/extension/internal/filter/color.h | 34 +- src/extension/internal/filter/distort.h | 8 +- src/extension/internal/filter/filter-file.cpp | 2 +- src/extension/internal/filter/filter.cpp | 2 +- src/extension/internal/filter/filter.h | 2 +- src/extension/internal/filter/image.h | 2 +- src/extension/internal/filter/morphology.h | 6 +- src/extension/internal/filter/overlays.h | 2 +- src/extension/internal/filter/paint.h | 20 +- src/extension/internal/filter/shadows.h | 2 +- src/extension/internal/filter/textures.h | 6 +- src/extension/internal/filter/transparency.h | 4 +- src/extension/internal/gdkpixbuf-input.cpp | 6 +- src/extension/internal/svg.cpp | 4 +- src/extension/prefdialog/parameter-bool.cpp | 55 ++-- src/extension/prefdialog/parameter-bool.h | 18 +- src/extension/prefdialog/parameter-color.cpp | 90 +++--- src/extension/prefdialog/parameter-color.h | 15 +- src/extension/prefdialog/parameter-description.cpp | 77 ++--- src/extension/prefdialog/parameter-description.h | 22 +- src/extension/prefdialog/parameter-enum.cpp | 269 ---------------- src/extension/prefdialog/parameter-enum.h | 106 ------- src/extension/prefdialog/parameter-float.cpp | 106 +++---- src/extension/prefdialog/parameter-float.h | 33 +- src/extension/prefdialog/parameter-int.cpp | 93 +++--- src/extension/prefdialog/parameter-int.h | 29 +- src/extension/prefdialog/parameter-notebook.cpp | 289 +++++++---------- src/extension/prefdialog/parameter-notebook.h | 59 ++-- src/extension/prefdialog/parameter-optiongroup.cpp | 342 ++++++++++++++++++++ src/extension/prefdialog/parameter-optiongroup.h | 108 +++++++ src/extension/prefdialog/parameter-radiobutton.cpp | 349 --------------------- src/extension/prefdialog/parameter-radiobutton.h | 109 ------- src/extension/prefdialog/parameter-string.cpp | 131 ++++---- src/extension/prefdialog/parameter-string.h | 35 +-- src/extension/prefdialog/parameter.cpp | 288 ++++++++--------- src/extension/prefdialog/parameter.h | 89 +++--- src/extension/prefdialog/prefdialog.cpp | 4 +- src/extension/prefdialog/prefdialog.h | 14 +- 49 files changed, 1364 insertions(+), 1947 deletions(-) delete mode 100644 src/extension/prefdialog/parameter-enum.cpp delete mode 100644 src/extension/prefdialog/parameter-enum.h create mode 100644 src/extension/prefdialog/parameter-optiongroup.cpp create mode 100644 src/extension/prefdialog/parameter-optiongroup.h delete mode 100644 src/extension/prefdialog/parameter-radiobutton.cpp delete mode 100644 src/extension/prefdialog/parameter-radiobutton.h (limited to 'src/extension') diff --git a/src/extension/CMakeLists.txt b/src/extension/CMakeLists.txt index 3f5772cd2..83ea6accb 100644 --- a/src/extension/CMakeLists.txt +++ b/src/extension/CMakeLists.txt @@ -57,11 +57,10 @@ set(extension_SRC prefdialog/parameter-bool.cpp prefdialog/parameter-color.cpp prefdialog/parameter-description.cpp - prefdialog/parameter-enum.cpp prefdialog/parameter-float.cpp prefdialog/parameter-int.cpp prefdialog/parameter-notebook.cpp - prefdialog/parameter-radiobutton.cpp + prefdialog/parameter-optiongroup.cpp prefdialog/parameter-string.cpp # ------ @@ -132,11 +131,10 @@ set(extension_SRC prefdialog/parameter-bool.h prefdialog/parameter-color.h prefdialog/parameter-description.h - prefdialog/parameter-enum.h prefdialog/parameter-float.h prefdialog/parameter-int.h prefdialog/parameter-notebook.h - prefdialog/parameter-radiobutton.h + prefdialog/parameter-optiongroup.h prefdialog/parameter-string.h ) diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index 265b6f61a..21a9c238b 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -1447,7 +1447,7 @@ document_interface_get_children (DocumentInterface *doc_interface, char *name, gchar* document_interface_get_parent (DocumentInterface *doc_interface, char *name, GError **error) { - SPItem* node=(SPItem* )get_object_by_name(doc_interface->target.getDocument(), name, error); + SPItem*node=(SPItem* )get_object_by_name(doc_interface->target.getDocument(), name, error); SPObject* parent=node->parent; diff --git a/src/extension/extension.cpp b/src/extension/extension.cpp index e5cee3b8e..cf1ccf2de 100644 --- a/src/extension/extension.cpp +++ b/src/extension/extension.cpp @@ -50,7 +50,7 @@ std::ofstream Extension::error_file; not related to the module directly. If the Repr does not include a name and an ID the module will be left in an errored state. */ -Extension::Extension (Inkscape::XML::Node * in_repr, Implementation::Implementation * in_imp) +Extension::Extension (Inkscape::XML::Node *in_repr, Implementation::Implementation *in_imp) : _gui(true) , execution_env(nullptr) { @@ -67,50 +67,50 @@ Extension::Extension (Inkscape::XML::Node * in_repr, Implementation::Implementat imp = in_imp; } - // printf("Extension Constructor: "); - if (repr != nullptr) { + // Read XML tree and parse extension + if (repr) { Inkscape::XML::Node *child_repr = repr->firstChild(); - /* TODO: Handle what happens if we don't have these two */ - while (child_repr != nullptr) { - char const * chname = child_repr->name(); + while (child_repr) { + const char *chname = child_repr->name(); if (!strncmp(chname, INKSCAPE_EXTENSION_NS_NC, strlen(INKSCAPE_EXTENSION_NS_NC))) { chname += strlen(INKSCAPE_EXTENSION_NS); } - if (chname[0] == '_') /* Allow _ for translation of tags */ + if (chname[0] == '_') { // allow leading underscore in tag names for backwards-compatibility chname++; + } + + /* TODO: Handle what happens if we don't have name and id */ if (!strcmp(chname, "id")) { - gchar const *val = child_repr->firstChild()->content(); - id = g_strdup (val); - } /* id */ - if (!strcmp(chname, "name")) { - name = g_strdup (child_repr->firstChild()->content()); - } /* name */ - if (!strcmp(chname, "param") || !strcmp(chname, "_param")) { - Parameter * param; - param = Parameter::make(child_repr, this); - if (param != nullptr) + const char *value = child_repr->firstChild()->content(); + id = g_strdup(value); + } else if (!strcmp(chname, "name")) { + name = g_strdup(child_repr->firstChild()->content()); + } else if (!strcmp(chname, "param")) { + Parameter *param = Parameter::make(child_repr, this); + if (param) { parameters.push_back(param); - } /* param || _param */ - if (!strcmp(chname, "dependency")) { + } + } else if (!strcmp(chname, "dependency")) { _deps.push_back(new Dependency(child_repr)); - } /* dependency */ - if (!strcmp(chname, "script")) { - for (Inkscape::XML::Node *child = child_repr->firstChild(); child != nullptr ; child = child->next()) { - if (child->type() == Inkscape::XML::ELEMENT_NODE) { + } else if (!strcmp(chname, "script")) { // check command as a dependency (see LP #505920) + for (Inkscape::XML::Node *child = child_repr->firstChild(); child != nullptr; child = child->next()) { + if (child->type() == Inkscape::XML::ELEMENT_NODE) { // skip non-element nodes (see LP #1372200) _deps.push_back(new Dependency(child)); break; - } /* skip non-element nodes (see LP #1372200) */ + } } - } /* check command as a dependency (see LP #505920) */ + } else { + // We could do some sanity checking here. + // However, we don't really know which additional elements Extension subclasses might need... + } + child_repr = child_repr->next(); } db.register_ext (this); } - // printf("%s\n", name); - timer = nullptr; - return; + timer = nullptr; } /** @@ -124,27 +124,27 @@ Extension::Extension (Inkscape::XML::Node * in_repr, Implementation::Implementat */ Extension::~Extension () { -// printf("Extension Destructor: %s\n", name); set_state(STATE_UNLOADED); + db.unregister_ext(this); + Inkscape::GC::release(repr); + g_free(id); g_free(name); + delete timer; timer = nullptr; - /** \todo Need to do parameters here */ // delete parameters: - for (auto param:parameters) { - delete param; + for (auto parameter : parameters) { + delete parameter; } for (auto & _dep : _deps) { delete _dep; } _deps.clear(); - - return; } /** @@ -373,7 +373,7 @@ Extension::deactivated () return get_state() == STATE_DEACTIVATED; } -Parameter *Extension::get_param(gchar const *name) +Parameter *Extension::get_param(const gchar *name) { if (name == nullptr) { throw Extension::param_not_exist(); @@ -397,236 +397,239 @@ Parameter *Extension::get_param(gchar const *name) throw Extension::param_not_exist(); } -Parameter const *Extension::get_param(const gchar * name) const +Parameter const *Extension::get_param(const gchar *name) const { return const_cast(this)->get_param(name); } -gchar const *Extension::get_param_string(gchar const *name, SPDocument const *doc, Inkscape::XML::Node const *node) const -{ - Parameter const *param = get_param(name); - return param->get_string(doc, node); -} - -const gchar * -Extension::get_param_enum (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node) const -{ - Parameter const *param = get_param(name); - return param->get_enum(doc, node); -} - -/** - * This is useful to find out, if a given string \c value is selectable in a ComboBox named \cname. - * - * @param name The name of the enum parameter to get. - * @param doc The document to look in for document specific parameters. - * @param node The node to look in for a specific parameter. - * @return true if value exists, false if not - */ -bool -Extension::get_param_enum_contains(gchar const * name, gchar const * value, SPDocument * doc, Inkscape::XML::Node * node) const -{ - Parameter const *param = get_param(name); - return param->get_enum_contains(value, doc, node); -} - -gchar const * -Extension::get_param_optiongroup( gchar const * name, SPDocument const * doc, Inkscape::XML::Node const * node) const -{ - Parameter const*param = get_param(name); - return param->get_optiongroup(doc, node); -} - /** \return The value of the parameter identified by the name - \brief Gets a parameter identified by name with the bool placed - in value. - \param name The name of the parameter to get + \brief Gets a parameter identified by name with the bool placed in value. + \param name The name of the parameter to get \param doc The document to look in for document specific parameters \param node The node to look in for a specific parameter - Look up in the parameters list, then execute the function on that - found parameter. + Look up in the parameters list, const then execute the function on that found parameter. */ bool -Extension::get_param_bool (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node) +Extension::get_param_bool (const gchar *name, const SPDocument *doc, const Inkscape::XML::Node *node) const { - Parameter * param; + const Parameter *param; param = get_param(name); return param->get_bool(doc, node); } /** \return The integer value for the parameter specified - \brief Gets a parameter identified by name with the integer placed - in value. - \param name The name of the parameter to get + \brief Gets a parameter identified by name with the integer placed in value. + \param name The name of the parameter to get \param doc The document to look in for document specific parameters \param node The node to look in for a specific parameter - Look up in the parameters list, then execute the function on that - found parameter. + Look up in the parameters list, const then execute the function on that found parameter. */ int -Extension::get_param_int (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node) +Extension::get_param_int (const gchar *name, const SPDocument *doc, const Inkscape::XML::Node *node) const { - Parameter * param; + const Parameter *param; param = get_param(name); return param->get_int(doc, node); } /** \return The float value for the parameter specified - \brief Gets a parameter identified by name with the float placed - in value. - \param name The name of the parameter to get + \brief Gets a parameter identified by name with the float in value. + \param name The name of the parameter to get \param doc The document to look in for document specific parameters \param node The node to look in for a specific parameter - Look up in the parameters list, then execute the function on that - found parameter. + Look up in the parameters list, const then execute the function on that found parameter. */ float -Extension::get_param_float (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node) +Extension::get_param_float (const gchar *name, const SPDocument *doc, const Inkscape::XML::Node *node) const { - Parameter * param; + const Parameter *param; param = get_param(name); return param->get_float(doc, node); } /** \return The string value for the parameter specified - \brief Gets a parameter identified by name with the float placed - in value. - \param name The name of the parameter to get + \brief Gets a parameter identified by name with the string placed in value. + \param name The name of the parameter to get \param doc The document to look in for document specific parameters \param node The node to look in for a specific parameter - Look up in the parameters list, then execute the function on that - found parameter. + Look up in the parameters list, const then execute the function on that found parameter. +*/ +const char * +Extension::get_param_string (const gchar *name, const SPDocument *doc, const Inkscape::XML::Node *node) const +{ + const Parameter *param; + param = get_param(name); + return param->get_string(doc, node); +} + +/** + \return The string value for the parameter specified + \brief Gets a parameter identified by name with the string placed in value. + \param name The name of the parameter to get + \param doc The document to look in for document specific parameters + \param node The node to look in for a specific parameter + + Look up in the parameters list, const then execute the function on that found parameter. +*/ +const char * +Extension::get_param_optiongroup (const gchar *name, const SPDocument *doc, const Inkscape::XML::Node *node) const +{ + const Parameter *param; + param = get_param(name); + return param->get_optiongroup(doc, node); +} + +/** + * This is useful to find out, if a given string \c value is selectable in a optiongroup named \cname. + * + * @param name The name of the optiongroup parameter to get. + * @param doc The document to look in for document specific parameters. + * @param node The node to look in for a specific parameter. + * @return true if value exists, false if not + */ +bool +Extension::get_param_optiongroup_contains(const gchar *name, const char *value, const SPDocument *doc, const Inkscape::XML::Node *node) const +{ + const Parameter *param; + param = get_param(name); + return param->get_optiongroup_contains(value, doc, node); +} + +/** + \return The unsigned integer RGBA value for the parameter specified + \brief Gets a parameter identified by name with the unsigned int placed in value. + \param name The name of the parameter to get + \param doc The document to look in for document specific parameters + \param node The node to look in for a specific parameter + + Look up in the parameters list, const then execute the function on that found parameter. */ guint32 -Extension::get_param_color (const gchar * name, const SPDocument * doc, const Inkscape::XML::Node * node) const +Extension::get_param_color (const gchar *name, const SPDocument *doc, const Inkscape::XML::Node *node) const { - Parameter const *param = get_param(name); + const Parameter *param; + param = get_param(name); return param->get_color(doc, node); } /** \return The passed in value - \brief Sets a parameter identified by name with the boolean - in the parameter value. - \param name The name of the parameter to set - \param value The value to set the parameter to + \brief Sets a parameter identified by name with the boolean in the parameter value. + \param name The name of the parameter to set + \param value The value to set the parameter to \param doc The document to look in for document specific parameters \param node The node to look in for a specific parameter - Look up in the parameters list, then execute the function on that - found parameter. + Look up in the parameters list, const then execute the function on that found parameter. */ bool -Extension::set_param_bool (const gchar * name, bool value, SPDocument * doc, Inkscape::XML::Node * node) +Extension::set_param_bool (const gchar *name, const bool value, SPDocument *doc, Inkscape::XML::Node *node) { - Parameter * param; + Parameter *param; param = get_param(name); return param->set_bool(value, doc, node); } /** \return The passed in value - \brief Sets a parameter identified by name with the integer - in the parameter value. - \param name The name of the parameter to set - \param value The value to set the parameter to + \brief Sets a parameter identified by name with the integer in the parameter value. + \param name The name of the parameter to set + \param value The value to set the parameter to \param doc The document to look in for document specific parameters \param node The node to look in for a specific parameter - Look up in the parameters list, then execute the function on that - found parameter. + Look up in the parameters list, const then execute the function on that found parameter. */ int -Extension::set_param_int (const gchar * name, int value, SPDocument * doc, Inkscape::XML::Node * node) +Extension::set_param_int (const gchar *name, const int value, SPDocument *doc, Inkscape::XML::Node *node) { - Parameter * param; + Parameter *param; param = get_param(name); return param->set_int(value, doc, node); } /** \return The passed in value - \brief Sets a parameter identified by name with the integer - in the parameter value. - \param name The name of the parameter to set - \param value The value to set the parameter to + \brief Sets a parameter identified by name with the float in the parameter value. + \param name The name of the parameter to set + \param value The value to set the parameter to \param doc The document to look in for document specific parameters \param node The node to look in for a specific parameter - Look up in the parameters list, then execute the function on that - found parameter. + Look up in the parameters list, const then execute the function on that found parameter. */ float -Extension::set_param_float (const gchar * name, float value, SPDocument * doc, Inkscape::XML::Node * node) +Extension::set_param_float (const gchar *name, const float value, SPDocument *doc, Inkscape::XML::Node *node) { - Parameter * param; + Parameter *param; param = get_param(name); return param->set_float(value, doc, node); } /** \return The passed in value - \brief Sets a parameter identified by name with the string - in the parameter value. - \param name The name of the parameter to set - \param value The value to set the parameter to + \brief Sets a parameter identified by name with the string in the parameter value. + \param name The name of the parameter to set + \param value The value to set the parameter to \param doc The document to look in for document specific parameters \param node The node to look in for a specific parameter - Look up in the parameters list, then execute the function on that - found parameter. + Look up in the parameters list, const then execute the function on that found parameter. */ -const gchar * -Extension::set_param_string (const gchar * name, const gchar * value, SPDocument * doc, Inkscape::XML::Node * node) +const char * +Extension::set_param_string (const gchar *name, const char *value, SPDocument *doc, Inkscape::XML::Node *node) { - Parameter * param; + Parameter *param; param = get_param(name); return param->set_string(value, doc, node); } -gchar const * -Extension::set_param_optiongroup(gchar const * name, gchar const * value, SPDocument * doc, Inkscape::XML::Node * node) -{ - Parameter * param = get_param(name); - return param->set_optiongroup(value, doc, node); -} +/** + \return The passed in value + \brief Sets a parameter identified by name with the string in the parameter value. + \param name The name of the parameter to set + \param value The value to set the parameter to + \param doc The document to look in for document specific parameters + \param node The node to look in for a specific parameter -gchar const * -Extension::set_param_enum(gchar const * name, gchar const * value, SPDocument * doc, Inkscape::XML::Node * node) + Look up in the parameters list, const then execute the function on that found parameter. +*/ +const char * +Extension::set_param_optiongroup (const gchar *name, const char *value, SPDocument *doc, Inkscape::XML::Node *node) { - Parameter * param = get_param(name); - return param->set_enum(value, doc, node); + Parameter *param; + param = get_param(name); + return param->set_optiongroup(value, doc, node); } - /** \return The passed in value - \brief Sets a parameter identified by name with the string - in the parameter value. - \param name The name of the parameter to set - \param value The value to set the parameter to + \brief Sets a parameter identified by name with the unsigned integer RGBA value in the parameter value. + \param name The name of the parameter to set + \param value The value to set the parameter to \param doc The document to look in for document specific parameters \param node The node to look in for a specific parameter - Look up in the parameters list, then execute the function on that - found parameter. +Look up in the parameters list, const then execute the function on that found parameter. */ guint32 -Extension::set_param_color (const gchar * name, guint32 color, SPDocument * doc, Inkscape::XML::Node * node) +Extension::set_param_color (const gchar *name, const guint32 color, SPDocument *doc, Inkscape::XML::Node *node) { - Parameter* param = get_param(name); + Parameter *param; + param = get_param(name); return param->set_color(color, doc, node); } + /** \brief A function to open the error log file. */ void Extension::error_file_open () @@ -690,7 +693,7 @@ public: If all parameters are gui_hidden = true NULL is returned as well. */ Gtk::Widget * -Extension::autogui (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) +Extension::autogui (SPDocument *doc, Inkscape::XML::Node *node, sigc::signal *changeSignal) { if (!_gui || param_visible_count() == 0) return nullptr; diff --git a/src/extension/extension.h b/src/extension/extension.h index 25b70fc5b..e544dcccd 100644 --- a/src/extension/extension.h +++ b/src/extension/extension.h @@ -189,83 +189,63 @@ private: Parameter const *get_param(const gchar * name) const; public: - bool get_param_bool (const gchar * name, - const SPDocument * doc = nullptr, - const Inkscape::XML::Node * node = nullptr); - - int get_param_int (const gchar * name, - const SPDocument * doc = nullptr, - const Inkscape::XML::Node * node = nullptr); - - float get_param_float (const gchar * name, - const SPDocument * doc = nullptr, - const Inkscape::XML::Node * node = nullptr); - - /** - * Gets a parameter identified by name with the string placed in value. - * It isn't duplicated into the value string. Look up in the parameters list, - * then execute the function on that found parameter. - * - * @param name The name of the parameter to get. - * @param doc The document to look in for document specific parameters. - * @param node The node to look in for a specific parameter. - * @return A constant pointer to the string held by the parameters. - */ - gchar const *get_param_string(gchar const *name, - SPDocument const *doc = nullptr, - Inkscape::XML::Node const *node = nullptr) const; - - guint32 get_param_color (const gchar * name, - const SPDocument * doc = nullptr, - const Inkscape::XML::Node * node = nullptr) const; - - const gchar * get_param_enum (const gchar * name, - const SPDocument * doc = nullptr, - const Inkscape::XML::Node * node = nullptr) const; - - gchar const *get_param_optiongroup( gchar const * name, - SPDocument const * doc = nullptr, - Inkscape::XML::Node const * node = nullptr) const; - - bool get_param_enum_contains(gchar const * name, - gchar const * value, - SPDocument * doc = nullptr, - Inkscape::XML::Node * node = nullptr) const; - - bool set_param_bool (const gchar * name, - bool value, - SPDocument * doc = nullptr, - Inkscape::XML::Node * node = nullptr); - - int set_param_int (const gchar * name, - int value, - SPDocument * doc = nullptr, - Inkscape::XML::Node * node = nullptr); - - float set_param_float (const gchar * name, - float value, - SPDocument * doc = nullptr, - Inkscape::XML::Node * node = nullptr); - - const gchar * set_param_string (const gchar * name, - const gchar * value, - SPDocument * doc = nullptr, - Inkscape::XML::Node * node = nullptr); - - gchar const * set_param_optiongroup(gchar const * name, - gchar const * value, - SPDocument * doc = nullptr, - Inkscape::XML::Node * node = nullptr); - - gchar const * set_param_enum (gchar const * name, - gchar const * value, - SPDocument * doc = nullptr, - Inkscape::XML::Node * node = nullptr); - - guint32 set_param_color (const gchar * name, - guint32 color, - SPDocument * doc = nullptr, - Inkscape::XML::Node * node = nullptr); + bool get_param_bool (const gchar *name, + const SPDocument *doc = nullptr, + const Inkscape::XML::Node *node = nullptr) const; + + int get_param_int (const gchar *name, + const SPDocument *doc = nullptr, + const Inkscape::XML::Node *node = nullptr) const; + + float get_param_float (const gchar *name, + const SPDocument *doc = nullptr, + const Inkscape::XML::Node *node = nullptr) const; + + const char *get_param_string (const gchar *name, + const SPDocument *doc = nullptr, + const Inkscape::XML::Node *node = nullptr) const; + + const char *get_param_optiongroup (const gchar *name, + const SPDocument *doc = nullptr, + const Inkscape::XML::Node *node = nullptr) const; + bool get_param_optiongroup_contains (const gchar *name, + const char *value, + const SPDocument *doc = nullptr, + const Inkscape::XML::Node * node = nullptr) const; + + guint32 get_param_color (const gchar *name, + const SPDocument *doc = nullptr, + const Inkscape::XML::Node *node = nullptr) const; + + bool set_param_bool (const gchar *name, + const bool value, + SPDocument *doc = nullptr, + Inkscape::XML::Node *node = nullptr); + + int set_param_int (const gchar *name, + const int value, + SPDocument *doc = nullptr, + Inkscape::XML::Node *node = nullptr); + + float set_param_float (const gchar *name, + const float value, + SPDocument *doc = nullptr, + Inkscape::XML::Node *node = nullptr); + + const char *set_param_string (const gchar *name, + const char *value, + SPDocument *doc = nullptr, + Inkscape::XML::Node *node = nullptr); + + const char *set_param_optiongroup (const gchar *name, + const char *value, + SPDocument *doc = nullptr, + Inkscape::XML::Node *node = nullptr); + + guint32 set_param_color (const gchar *name, + const guint32 color, + SPDocument *doc = nullptr, + Inkscape::XML::Node *node = nullptr); /* Error file handling */ public: @@ -273,7 +253,7 @@ public: static void error_file_close (); public: - Gtk::Widget * autogui (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal = nullptr); + Gtk::Widget * autogui (SPDocument * doc, Inkscape::XML::Node *node, sigc::signal * changeSignal = nullptr); void paramListString (std::list & retlist); void set_gui(bool s) { _gui = s; } bool get_gui() { return _gui; } diff --git a/src/extension/internal/bitmap/addNoise.cpp b/src/extension/internal/bitmap/addNoise.cpp index 5981eed24..b9e80a915 100644 --- a/src/extension/internal/bitmap/addNoise.cpp +++ b/src/extension/internal/bitmap/addNoise.cpp @@ -33,7 +33,7 @@ AddNoise::applyEffect(Magick::Image *image) { void AddNoise::refreshParameters(Inkscape::Extension::Effect *module) { - _noiseTypeName = module->get_param_enum("noiseType"); + _noiseTypeName = module->get_param_optiongroup("noiseType"); } #include "../clear-n_.h" diff --git a/src/extension/internal/bitmap/channel.cpp b/src/extension/internal/bitmap/channel.cpp index fb0dad635..be0cce2e1 100644 --- a/src/extension/internal/bitmap/channel.cpp +++ b/src/extension/internal/bitmap/channel.cpp @@ -36,7 +36,7 @@ Channel::applyEffect(Magick::Image *image) { void Channel::refreshParameters(Inkscape::Extension::Effect *module) { - _layerName = module->get_param_enum("layer"); + _layerName = module->get_param_optiongroup("layer"); } #include "../clear-n_.h" diff --git a/src/extension/internal/bitmap/levelChannel.cpp b/src/extension/internal/bitmap/levelChannel.cpp index 714293d28..384408cf6 100644 --- a/src/extension/internal/bitmap/levelChannel.cpp +++ b/src/extension/internal/bitmap/levelChannel.cpp @@ -37,7 +37,7 @@ LevelChannel::applyEffect(Magick::Image* image) { void LevelChannel::refreshParameters(Inkscape::Extension::Effect* module) { - _channelName = module->get_param_enum("channel"); + _channelName = module->get_param_optiongroup("channel"); _black_point = module->get_param_float("blackPoint"); _white_point = module->get_param_float("whitePoint"); _mid_point = module->get_param_float("midPoint"); diff --git a/src/extension/internal/cairo-ps-out.cpp b/src/extension/internal/cairo-ps-out.cpp index 5dfbe051e..94bb6c3f3 100644 --- a/src/extension/internal/cairo-ps-out.cpp +++ b/src/extension/internal/cairo-ps-out.cpp @@ -137,7 +137,7 @@ CairoPsOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar con int level = CAIRO_PS_LEVEL_2; try { - const gchar *new_level = mod->get_param_enum("PSlevel"); + const gchar *new_level = mod->get_param_optiongroup("PSlevel"); if((new_level != nullptr) && (g_ascii_strcasecmp("PS3", new_level) == 0)) { level = CAIRO_PS_LEVEL_3; } @@ -226,7 +226,7 @@ CairoEpsOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar co int level = CAIRO_PS_LEVEL_2; try { - const gchar *new_level = mod->get_param_enum("PSlevel"); + const gchar *new_level = mod->get_param_optiongroup("PSlevel"); if((new_level != nullptr) && (g_ascii_strcasecmp("PS3", new_level) == 0)) { level = CAIRO_PS_LEVEL_3; } diff --git a/src/extension/internal/cairo-renderer-pdf-out.cpp b/src/extension/internal/cairo-renderer-pdf-out.cpp index ecdea2005..e74b38cfd 100644 --- a/src/extension/internal/cairo-renderer-pdf-out.cpp +++ b/src/extension/internal/cairo-renderer-pdf-out.cpp @@ -139,7 +139,7 @@ CairoRendererPdfOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, int level = 0; try { - const gchar *new_level = mod->get_param_enum("PDFversion"); + const gchar *new_level = mod->get_param_optiongroup("PDFversion"); if((new_level != nullptr) && (g_ascii_strcasecmp("PDF-1.5", new_level) == 0)) { level = 1; } diff --git a/src/extension/internal/filter/blurs.h b/src/extension/internal/filter/blurs.h index 2d28f8546..a970a7c1f 100644 --- a/src/extension/internal/filter/blurs.h +++ b/src/extension/internal/filter/blurs.h @@ -224,7 +224,7 @@ CrossBlur::get_filter_text (Inkscape::Extension::Extension * ext) fade << ext->get_param_float("fade"); hblur << ext->get_param_float("hblur"); vblur << ext->get_param_float("vblur"); - blend << ext->get_param_enum("blend"); + blend << ext->get_param_optiongroup("blend"); _filter = g_strdup_printf( "\n" @@ -387,7 +387,7 @@ ImageBlur::get_filter_text (Inkscape::Extension::Extension * ext) g << ((color >> 16) & 0xff); b << ((color >> 8) & 0xff); a << (color & 0xff) / 255.0F; - blend << ext->get_param_enum("blend"); + blend << ext->get_param_optiongroup("blend"); if (ext->get_param_bool("background")) { background << "BackgroundImage" ; diff --git a/src/extension/internal/filter/bumps.h b/src/extension/internal/filter/bumps.h index bcde76542..38dcbc80e 100644 --- a/src/extension/internal/filter/bumps.h +++ b/src/extension/internal/filter/bumps.h @@ -181,7 +181,7 @@ Bump::get_filter_text (Inkscape::Extension::Extension * ext) green << ext->get_param_float("green"); blue << ext->get_param_float("blue"); crop << ext->get_param_float("crop"); - blend << ext->get_param_enum("blend"); + blend << ext->get_param_optiongroup("blend"); guint32 lightingColor = ext->get_param_color("lightingColor"); guint32 imageColor = ext->get_param_color("imageColor"); @@ -192,7 +192,7 @@ Bump::get_filter_text (Inkscape::Extension::Extension * ext) bumpSource << "blur1" ; } - const gchar *lightType = ext->get_param_enum("lightType"); + const gchar *lightType = ext->get_param_optiongroup("lightType"); if ((g_ascii_strcasecmp("specular", lightType) == 0)) { // Specular lightStart << "> 24) & 0xff) << "," @@ -209,7 +209,7 @@ Bump::get_filter_text (Inkscape::Extension::Extension * ext) lightEnd << ""; } - const gchar *lightSource = ext->get_param_enum("lightSource"); + const gchar *lightSource = ext->get_param_optiongroup("lightSource"); if ((g_ascii_strcasecmp("distant", lightSource) == 0)) { // Distant lightOptions << "get_param_int("distantAzimuth") << "\" elevation=\"" @@ -414,7 +414,7 @@ WaxBump::get_filter_text (Inkscape::Extension::Extension * ext) green << ext->get_param_float("green") - 0.72; blue << ext->get_param_float("blue") - 0.07; - background << ext->get_param_enum("background"); + background << ext->get_param_optiongroup("background"); bgopacity << ext->get_param_float("bgopacity"); height << ext->get_param_float("height"); @@ -440,9 +440,9 @@ WaxBump::get_filter_text (Inkscape::Extension::Extension * ext) revert << "out" ; } - lightingblend << ext->get_param_enum("lightingblend"); - highlightblend << ext->get_param_enum("highlightblend"); - transparency << ext->get_param_enum("transparency"); + lightingblend << ext->get_param_optiongroup("lightingblend"); + highlightblend << ext->get_param_optiongroup("highlightblend"); + transparency << ext->get_param_optiongroup("transparency"); _filter = g_strdup_printf( "\n" diff --git a/src/extension/internal/filter/color.h b/src/extension/internal/filter/color.h index a98311e38..000f5442e 100644 --- a/src/extension/internal/filter/color.h +++ b/src/extension/internal/filter/color.h @@ -297,7 +297,7 @@ ColorBlindness::get_filter_text (Inkscape::Extension::Extension * ext) if (_filter != nullptr) g_free((void *)_filter); std::ostringstream type; - type << ext->get_param_enum("type"); + type << ext->get_param_optiongroup("type"); _filter = g_strdup_printf( "\n" @@ -454,8 +454,8 @@ Colorize::get_filter_text (Inkscape::Extension::Extension * ext) hlight << ext->get_param_float("hlight"); nlight << ext->get_param_float("nlight"); - blend1 << ext->get_param_enum("blend1"); - blend2 << ext->get_param_enum("blend2"); + blend1 << ext->get_param_optiongroup("blend1"); + blend2 << ext->get_param_optiongroup("blend2"); if (ext->get_param_bool("duotone")) { duotone << "0"; } else { @@ -526,7 +526,7 @@ ComponentTransfer::get_filter_text (Inkscape::Extension::Extension * ext) if (_filter != nullptr) g_free((void *)_filter); std::ostringstream CTfunction; - const gchar *type = ext->get_param_enum("type"); + const gchar *type = ext->get_param_optiongroup("type"); if ((g_ascii_strcasecmp("identity", type) == 0)) { CTfunction << "\n" @@ -635,7 +635,7 @@ Duochrome::get_filter_text (Inkscape::Extension::Extension * ext) guint32 color1 = ext->get_param_color("color1"); guint32 color2 = ext->get_param_color("color2"); float fluorescence = ext->get_param_float("fluo"); - const gchar *swaptype = ext->get_param_enum("swap"); + const gchar *swaptype = ext->get_param_optiongroup("swap"); r1 << ((color1 >> 24) & 0xff); g1 << ((color1 >> 16) & 0xff); @@ -745,9 +745,9 @@ ExtractChannel::get_filter_text (Inkscape::Extension::Extension * ext) std::ostringstream blend; std::ostringstream colors; - blend << ext->get_param_enum("blend"); + blend << ext->get_param_optiongroup("blend"); - const gchar *channel = ext->get_param_enum("source"); + const gchar *channel = ext->get_param_optiongroup("source"); if (ext->get_param_bool("alpha")) { if ((g_ascii_strcasecmp("r", channel) == 0)) { colors << "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0"; @@ -844,7 +844,7 @@ FadeToBW::get_filter_text (Inkscape::Extension::Extension * ext) level << ext->get_param_float("level"); - const gchar *fadeto = ext->get_param_enum("fadeto"); + const gchar *fadeto = ext->get_param_optiongroup("fadeto"); if ((g_ascii_strcasecmp("white", fadeto) == 0)) { // White wlevel << (1 - ext->get_param_float("level")); @@ -1031,7 +1031,7 @@ Invert::get_filter_text (Inkscape::Extension::Extension * ext) } if (ext->get_param_bool("lightness")) { - switch (atoi(ext->get_param_enum("channels"))) { + switch (atoi(ext->get_param_optiongroup("channels"))) { case 1: line1 << "0 0 -1"; line2 << "0 -1 0"; @@ -1055,7 +1055,7 @@ Invert::get_filter_text (Inkscape::Extension::Extension * ext) } col5 << "1"; } else { - switch (atoi(ext->get_param_enum("channels"))) { + switch (atoi(ext->get_param_optiongroup("channels"))) { case 1: line1 << "0 0 1"; line2 << "0 1 0"; @@ -1526,9 +1526,9 @@ Quadritone::get_filter_text (Inkscape::Extension::Extension * ext) dist << ext->get_param_int("dist"); colors << ext->get_param_int("colors"); - blend1 << ext->get_param_enum("blend1"); + blend1 << ext->get_param_optiongroup("blend1"); sat << ext->get_param_float("sat"); - blend2 << ext->get_param_enum("blend2"); + blend2 << ext->get_param_optiongroup("blend2"); _filter = g_strdup_printf( "\n" @@ -1614,7 +1614,7 @@ SimpleBlend::get_filter_text (Inkscape::Extension::Extension * ext) g << ((color >> 16) & 0xff); b << ((color >> 8) & 0xff); a << (color & 0xff) / 255.0F; - blend << ext->get_param_enum("blendmode"); + blend << ext->get_param_optiongroup("blendmode"); _filter = g_strdup_printf( "\n" @@ -1682,7 +1682,7 @@ Solarize::get_filter_text (Inkscape::Extension::Extension * ext) std::ostringstream blend2; rotate << ext->get_param_int("rotate"); - const gchar *type = ext->get_param_enum("type"); + const gchar *type = ext->get_param_optiongroup("type"); if ((g_ascii_strcasecmp("solarize", type) == 0)) { // Solarize blend1 << "darken"; @@ -1808,14 +1808,14 @@ Tritone::get_filter_text (Inkscape::Extension::Extension * ext) g << ((color >> 16) & 0xff); b << ((color >> 8) & 0xff); a << (color & 0xff) / 255.0F; - globalblend << ext->get_param_enum("globalblend"); + globalblend << ext->get_param_optiongroup("globalblend"); dist << ext->get_param_int("dist"); glow << ext->get_param_float("glow"); - glowblend << ext->get_param_enum("glowblend"); + glowblend << ext->get_param_optiongroup("glowblend"); llight << ext->get_param_float("llight"); glight << ext->get_param_float("glight"); - const gchar *type = ext->get_param_enum("type"); + const gchar *type = ext->get_param_optiongroup("type"); if ((g_ascii_strcasecmp("enhue", type) == 0)) { // Enhance hue c1in2 << "flood"; diff --git a/src/extension/internal/filter/distort.h b/src/extension/internal/filter/distort.h index fffa3fbec..7e9095611 100644 --- a/src/extension/internal/filter/distort.h +++ b/src/extension/internal/filter/distort.h @@ -130,16 +130,16 @@ FeltFeather::get_filter_text (Inkscape::Extension::Extension * ext) dilat << ext->get_param_float("dilat"); erosion << -ext->get_param_float("erosion"); - turbulence << ext->get_param_enum("turbulence"); + turbulence << ext->get_param_optiongroup("turbulence"); hfreq << ext->get_param_float("hfreq") / 100; vfreq << ext->get_param_float("vfreq") / 100; complexity << ext->get_param_int("complexity"); variation << ext->get_param_int("variation"); intensity << ext->get_param_float("intensity"); - stroke << ext->get_param_enum("stroke"); + stroke << ext->get_param_optiongroup("stroke"); - const gchar *maptype = ext->get_param_enum("type"); + const gchar *maptype = ext->get_param_optiongroup("type"); if (g_ascii_strcasecmp("in", maptype) == 0) { map << "composite3"; } else { @@ -225,7 +225,7 @@ Roughen::get_filter_text (Inkscape::Extension::Extension * ext) std::ostringstream variation; std::ostringstream intensity; - type << ext->get_param_enum("type"); + type << ext->get_param_optiongroup("type"); hfreq << ext->get_param_float("hfreq") / 100; vfreq << ext->get_param_float("vfreq") / 100; complexity << ext->get_param_int("complexity"); diff --git a/src/extension/internal/filter/filter-file.cpp b/src/extension/internal/filter/filter-file.cpp index f6d9a58f5..afa979fd5 100644 --- a/src/extension/internal/filter/filter-file.cpp +++ b/src/extension/internal/filter/filter-file.cpp @@ -91,7 +91,7 @@ void mywriter::put (char ch) { _str += ch; } void -Filter::filters_load_node (Inkscape::XML::Node * node, gchar * menuname) +Filter::filters_load_node (Inkscape::XML::Node *node, gchar * menuname) { gchar const * label = node->attribute("inkscape:label"); gchar const * menu = node->attribute("inkscape:menu"); diff --git a/src/extension/internal/filter/filter.cpp b/src/extension/internal/filter/filter.cpp index 98c0e8ce6..45f2d0af8 100644 --- a/src/extension/internal/filter/filter.cpp +++ b/src/extension/internal/filter/filter.cpp @@ -131,7 +131,7 @@ void Filter::effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::Vie Inkscape::XML::Node * defsrepr = document->doc()->getDefs()->getRepr(); for(auto spitem : items) { - Inkscape::XML::Node * node = spitem->getRepr(); + Inkscape::XML::Node *node = spitem->getRepr(); SPCSSAttr * css = sp_repr_css_attr(node, "style"); gchar const * filter = sp_repr_css_property(css, "filter", nullptr); diff --git a/src/extension/internal/filter/filter.h b/src/extension/internal/filter/filter.h index 35a73900c..cb3ed363b 100644 --- a/src/extension/internal/filter/filter.h +++ b/src/extension/internal/filter/filter.h @@ -50,7 +50,7 @@ public: /* File loader related */ static void filters_all_files(); - static void filters_load_node(Inkscape::XML::Node * node, gchar * menuname); + static void filters_load_node(Inkscape::XML::Node *node, gchar * menuname); }; diff --git a/src/extension/internal/filter/image.h b/src/extension/internal/filter/image.h index e9dcb1d8e..e1b3c1c04 100644 --- a/src/extension/internal/filter/image.h +++ b/src/extension/internal/filter/image.h @@ -79,7 +79,7 @@ EdgeDetect::get_filter_text (Inkscape::Extension::Extension * ext) std::ostringstream inverted; std::ostringstream level; - const gchar *type = ext->get_param_enum("type"); + const gchar *type = ext->get_param_optiongroup("type"); level << 1 / ext->get_param_float("level"); diff --git a/src/extension/internal/filter/morphology.h b/src/extension/internal/filter/morphology.h index fc71b6ea2..6fb47b00d 100644 --- a/src/extension/internal/filter/morphology.h +++ b/src/extension/internal/filter/morphology.h @@ -97,7 +97,7 @@ Crosssmooth::get_filter_text (Inkscape::Extension::Extension * ext) std::ostringstream antialias; std::ostringstream content; - type << ext->get_param_enum("type"); + type << ext->get_param_optiongroup("type"); width << ext->get_param_float("width"); level << ext->get_param_float("level"); dilat << ext->get_param_float("dilat"); @@ -255,7 +255,7 @@ Outline::get_filter_text (Inkscape::Extension::Extension * ext) fopacity << ext->get_param_float("fopacity"); sopacity << ext->get_param_float("sopacity"); - const gchar *position = ext->get_param_enum("position"); + const gchar *position = ext->get_param_optiongroup("position"); if((g_ascii_strcasecmp("inside", position) == 0)) { // Indide c1in << "SourceGraphic"; @@ -279,7 +279,7 @@ Outline::get_filter_text (Inkscape::Extension::Extension * ext) c2in << "blur2"; } - c2op << ext->get_param_enum("type"); + c2op << ext->get_param_optiongroup("type"); if (ext->get_param_bool("outline")) { c4in << "composite3"; diff --git a/src/extension/internal/filter/overlays.h b/src/extension/internal/filter/overlays.h index 0dbf79db8..5e54f3ae5 100644 --- a/src/extension/internal/filter/overlays.h +++ b/src/extension/internal/filter/overlays.h @@ -106,7 +106,7 @@ NoiseFill::get_filter_text (Inkscape::Extension::Extension * ext) std::ostringstream a; std::ostringstream inverted; - type << ext->get_param_enum("type"); + type << ext->get_param_optiongroup("type"); hfreq << (ext->get_param_float("hfreq") / 1000); vfreq << (ext->get_param_float("vfreq") / 1000); complexity << ext->get_param_int("complexity"); diff --git a/src/extension/internal/filter/paint.h b/src/extension/internal/filter/paint.h index 69da5fd2c..64c47c45c 100644 --- a/src/extension/internal/filter/paint.h +++ b/src/extension/internal/filter/paint.h @@ -155,7 +155,7 @@ Chromolitho::get_filter_text (Inkscape::Extension::Extension * ext) light << ext->get_param_float("light"); saturation << ext->get_param_float("saturation"); noise << (-1000 - ext->get_param_int("noise")); - dblend << ext->get_param_enum("dblend"); + dblend << ext->get_param_optiongroup("dblend"); smooth << ext->get_param_float("smooth"); if (ext->get_param_bool("dented")) { @@ -174,7 +174,7 @@ Chromolitho::get_filter_text (Inkscape::Extension::Extension * ext) grainyf << (ext->get_param_float("grainyf") / 1000); grainc << ext->get_param_int("grainc"); grainv << ext->get_param_int("grainv"); - gblend << ext->get_param_enum("gblend"); + gblend << ext->get_param_optiongroup("gblend"); grainexp << ext->get_param_float("grainexp"); grainero << (-ext->get_param_float("grainero")); if (ext->get_param_bool("graincol")) @@ -524,7 +524,7 @@ Electrize::get_filter_text (Inkscape::Extension::Extension * ext) std::ostringstream values; blur << ext->get_param_float("blur"); - type << ext->get_param_enum("type"); + type << ext->get_param_optiongroup("type"); // TransfertComponent table values are calculated based on the effect level and inverted parameters. int val = 0; @@ -620,8 +620,8 @@ NeonDraw::get_filter_text (Inkscape::Extension::Extension * ext) std::ostringstream lightness; std::ostringstream type; - type << ext->get_param_enum("type"); - blend << ext->get_param_enum("blend"); + type << ext->get_param_optiongroup("type"); + blend << ext->get_param_optiongroup("blend"); simply << ext->get_param_float("simply"); width << ext->get_param_float("width"); lightness << ext->get_param_float("lightness"); @@ -760,13 +760,13 @@ PointEngraving::get_filter_text (Inkscape::Extension::Extension * ext) std::ostringstream iof; std::ostringstream iop; - type << ext->get_param_enum("type"); + type << ext->get_param_optiongroup("type"); hfreq << ext->get_param_float("hfreq") / 100; vfreq << ext->get_param_float("vfreq") / 100; complexity << ext->get_param_int("complexity"); variation << ext->get_param_int("variation"); reduction << (-1000 - ext->get_param_int("reduction")); - blend << ext->get_param_enum("blend"); + blend << ext->get_param_optiongroup("blend"); lightness << ext->get_param_float("lightness"); grain << ext->get_param_float("grain"); erase << ext->get_param_float("erase"); @@ -898,8 +898,8 @@ Posterize::get_filter_text (Inkscape::Extension::Extension * ext) std::ostringstream transf; std::ostringstream antialias; - table << ext->get_param_enum("table"); - blendmode << ext->get_param_enum("blend"); + table << ext->get_param_optiongroup("table"); + blendmode << ext->get_param_optiongroup("blend"); blur1 << ext->get_param_float("blur1"); blur2 << ext->get_param_float("blur2"); presat << ext->get_param_float("presaturation"); @@ -908,7 +908,7 @@ Posterize::get_filter_text (Inkscape::Extension::Extension * ext) // TransfertComponent table values are calculated based on the poster type. transf << "0"; int levels = ext->get_param_int("levels") + 1; - const gchar *effecttype = ext->get_param_enum("type"); + const gchar *effecttype = ext->get_param_optiongroup("type"); if (levels == 1) { if ((g_ascii_strcasecmp("dented", effecttype) == 0)) { transf << " 1 0 1"; diff --git a/src/extension/internal/filter/shadows.h b/src/extension/internal/filter/shadows.h index 79e6e8712..160e36c2a 100644 --- a/src/extension/internal/filter/shadows.h +++ b/src/extension/internal/filter/shadows.h @@ -108,7 +108,7 @@ ColorizableDropShadow::get_filter_text (Inkscape::Extension::Extension * ext) std::ostringstream comp2in2; std::ostringstream comp2op; - const gchar *type = ext->get_param_enum("type"); + const gchar *type = ext->get_param_optiongroup("type"); guint32 color = ext->get_param_color("color"); blur << ext->get_param_float("blur"); diff --git a/src/extension/internal/filter/textures.h b/src/extension/internal/filter/textures.h index 31e76df6c..02a134fdf 100644 --- a/src/extension/internal/filter/textures.h +++ b/src/extension/internal/filter/textures.h @@ -115,7 +115,7 @@ InkBlot::get_filter_text (Inkscape::Extension::Extension * ext) std::ostringstream stroke; std::ostringstream custom; - type << ext->get_param_enum("type"); + type << ext->get_param_optiongroup("type"); freq << ext->get_param_float("freq") / 100; complexity << ext->get_param_int("complexity"); variation << ext->get_param_int("variation"); @@ -124,14 +124,14 @@ InkBlot::get_filter_text (Inkscape::Extension::Extension * ext) displacement << ext->get_param_float("displacement"); blend << ext->get_param_float("blend"); - const gchar *ope = ext->get_param_enum("stroke"); + const gchar *ope = ext->get_param_optiongroup("stroke"); if (g_ascii_strcasecmp("arithmetic", ope) == 0) { custom << "k1=\"" << ext->get_param_float("k1") << "\" k2=\"" << ext->get_param_float("k2") << "\" k3=\"" << ext->get_param_float("k3") << "\""; } else { custom << ""; } - stroke << ext->get_param_enum("stroke"); + stroke << ext->get_param_optiongroup("stroke"); _filter = g_strdup_printf( "\n" diff --git a/src/extension/internal/filter/transparency.h b/src/extension/internal/filter/transparency.h index 2fb02a01a..302d05d15 100644 --- a/src/extension/internal/filter/transparency.h +++ b/src/extension/internal/filter/transparency.h @@ -86,8 +86,8 @@ Blend::get_filter_text (Inkscape::Extension::Extension * ext) std::ostringstream source; std::ostringstream mode; - source << ext->get_param_enum("source"); - mode << ext->get_param_enum("mode"); + source << ext->get_param_optiongroup("source"); + mode << ext->get_param_optiongroup("mode"); _filter = g_strdup_printf( "\n" diff --git a/src/extension/internal/gdkpixbuf-input.cpp b/src/extension/internal/gdkpixbuf-input.cpp index 9a1ed40e7..ec338b8ae 100644 --- a/src/extension/internal/gdkpixbuf-input.cpp +++ b/src/extension/internal/gdkpixbuf-input.cpp @@ -195,17 +195,17 @@ GdkpixbufInput::init() "%s\n" "org.inkscape.input.gdkpixbuf.%s\n" - "\n" + "\n" "<_option value='embed' >" N_("Embed") "\n" "<_option value='link' >" N_("Link") "\n" "\n" - "\n" + "\n" "<_option value='from_file' >" N_("From file") "\n" "<_option value='from_default' >" N_("Default import resolution") "\n" "\n" - "\n" + "\n" "<_option value='auto' >" N_("None (auto)") "\n" "<_option value='optimizeQuality' >" N_("Smooth (optimizeQuality)") "\n" "<_option value='optimizeSpeed' >" N_("Blocky (optimizeSpeed)") "\n" diff --git a/src/extension/internal/svg.cpp b/src/extension/internal/svg.cpp index abc702af5..a6eac62ae 100644 --- a/src/extension/internal/svg.cpp +++ b/src/extension/internal/svg.cpp @@ -674,13 +674,13 @@ Svg::init() "\n" "" N_("SVG Input") "\n" "" SP_MODULE_KEY_INPUT_SVG "\n" - "\n" + "\n" "<_option value='include' >" N_("Include SVG image as editable object(s) in the current file") "\n" "<_option value='embed' >" N_("Embed the SVG file in a image tag (not editable in this document)") "\n" "<_option value='link' >" N_("Link the SVG file in a image tag (not editable in this document).") "\n" "\n" "96.00\n" - "\n" + "\n" "<_option value='auto' >" N_("None (auto)") "\n" "<_option value='optimizeQuality' >" N_("Smooth (optimizeQuality)") "\n" "<_option value='optimizeSpeed' >" N_("Blocky (optimizeSpeed)") "\n" diff --git a/src/extension/prefdialog/parameter-bool.cpp b/src/extension/prefdialog/parameter-bool.cpp index 8277d3120..cdd754d2d 100644 --- a/src/extension/prefdialog/parameter-bool.cpp +++ b/src/extension/prefdialog/parameter-bool.cpp @@ -21,43 +21,38 @@ namespace Inkscape { namespace Extension { -ParamBool::ParamBool(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml) - : Parameter(name, text, description, hidden, indent, ext) - , _value(false) +ParamBool::ParamBool(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext) + : Parameter(xml, ext) { - const char * defaultval = nullptr; - if (xml->firstChild() != nullptr) { - defaultval = xml->firstChild()->content(); + // get value + if (xml->firstChild()) { + const char *value = xml->firstChild()->content(); + if (value) { + if (!strcmp(value, "true")) { + _value = true; + } else if (!strcmp(value, "false")) { + _value = false; + } else { + g_warning("Invalid default value ('%s') for parameter '%s' in extension '%s'", + value, _name, _extension->get_id()); + } + } } - if (defaultval != nullptr && (!strcmp(defaultval, "true") || !strcmp(defaultval, "1"))) { - _value = true; - } else { - _value = false; - } - - gchar * pref_name = this->pref_name(); + gchar *pref_name = this->pref_name(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); _value = prefs->getBool(extension_pref_root + pref_name, _value); g_free(pref_name); - - return; } bool ParamBool::set( bool in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/ ) { _value = in; - gchar * prefname = this->pref_name(); + gchar *pref_name = this->pref_name(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setBool(extension_pref_root + prefname, _value); - g_free(prefname); + prefs->setBool(extension_pref_root + pref_name, _value); + g_free(pref_name); return _value; } @@ -81,7 +76,7 @@ public: * * @param param Which parameter to adjust on changing the check button */ - ParamBoolCheckButton (ParamBool * param, gchar * label, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) : + ParamBoolCheckButton (ParamBool *param, gchar *label, SPDocument *doc, Inkscape::XML::Node *node, sigc::signal *changeSignal) : Gtk::CheckButton(label), _pref(param), _doc(doc), _node(node), _changeSignal(changeSignal) { this->set_active(_pref->get(nullptr, nullptr) /**\todo fix */); this->signal_toggled().connect(sigc::mem_fun(this, &ParamBoolCheckButton::on_toggle)); @@ -96,10 +91,10 @@ public: private: /** Param to change. */ - ParamBool * _pref; - SPDocument * _doc; - Inkscape::XML::Node * _node; - sigc::signal * _changeSignal; + ParamBool *_pref; + SPDocument *_doc; + Inkscape::XML::Node *_node; + sigc::signal *_changeSignal; }; void ParamBoolCheckButton::on_toggle() @@ -122,7 +117,7 @@ void ParamBool::string(std::string &string) const return; } -Gtk::Widget *ParamBool::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) +Gtk::Widget *ParamBool::get_widget(SPDocument *doc, Inkscape::XML::Node *node, sigc::signal *changeSignal) { if (_hidden) { return nullptr; diff --git a/src/extension/prefdialog/parameter-bool.h b/src/extension/prefdialog/parameter-bool.h index 9864cac38..5a73b42b3 100644 --- a/src/extension/prefdialog/parameter-bool.h +++ b/src/extension/prefdialog/parameter-bool.h @@ -29,17 +29,7 @@ namespace Extension { */ class ParamBool : public Parameter { public: - - /** - * Use the superclass' allocator and set the \c _value. - */ - ParamBool(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml); + ParamBool(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext); /** * Returns the current state/value. @@ -56,13 +46,13 @@ public: * @param doc A document that should be used to set the value. * @param node The node where the value may be placed */ - bool set(bool in, SPDocument * doc, Inkscape::XML::Node * node); + bool set(bool in, SPDocument *doc, Inkscape::XML::Node *node); /** * Creates a bool check button for a bool parameter. * Builds a hbox with a label and a check button in it. */ - Gtk::Widget *get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) override; + Gtk::Widget *get_widget(SPDocument *doc, Inkscape::XML::Node *node, sigc::signal *changeSignal) override; // Explicitly call superclass version to avoid method being hidden. void string(std::list &list) const override { return Parameter::string(list); } @@ -75,7 +65,7 @@ public: private: /** Internal value. */ - bool _value; + bool _value = true; }; } // namespace Extension diff --git a/src/extension/prefdialog/parameter-color.cpp b/src/extension/prefdialog/parameter-color.cpp index 385c7b90f..52ee3de73 100644 --- a/src/extension/prefdialog/parameter-color.cpp +++ b/src/extension/prefdialog/parameter-color.cpp @@ -28,65 +28,44 @@ namespace Inkscape { namespace Extension { -ParamColor::~ParamColor() -{ - _color_changed.disconnect(); -} - -guint32 ParamColor::set( guint32 in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/ ) +ParamColor::ParamColor(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext) + : Parameter(xml, ext) { - _color_changed.block(true); - _color.setValue(in); - _color_changed.block(false); - - gchar * prefname = this->pref_name(); - std::string value; - string(value); - - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString(extension_pref_root + prefname, value); - g_free(prefname); - - return in; -} - -ParamColor::ParamColor(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml) - : Parameter(name, text, description, hidden, indent, ext) - , _changeSignal(nullptr) -{ - const char * defaulthex = nullptr; - if (xml->firstChild() != nullptr) - defaulthex = xml->firstChild()->content(); + // get value + unsigned int _value = 0x000000ff; // default to black + if (xml->firstChild()) { + const char *value = xml->firstChild()->content(); + if (value) { + _value = strtoul(value, nullptr, 0); + } + } - gchar * pref_name = this->pref_name(); + gchar *pref_name = this->pref_name(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring paramval = prefs->getString(extension_pref_root + pref_name); + _value = prefs->getUInt(extension_pref_root + pref_name, _value); g_free(pref_name); - if (!paramval.empty()) - defaulthex = paramval.data(); + _color.setValue(_value); - if (defaulthex) { - _color.setValue(atoi(defaulthex)); - } _color_changed = _color.signal_changed.connect(sigc::mem_fun(this, &ParamColor::_onColorChanged)); + // TODO: SelectedColor does not properly emit signal_changed after dragging, so we also need the following + _color_released = _color.signal_released.connect(sigc::mem_fun(this, &ParamColor::_onColorChanged)); +} +ParamColor::~ParamColor() +{ + _color_changed.disconnect(); + _color_released.disconnect(); } -void ParamColor::string(std::string &string) const +guint32 ParamColor::set(guint32 in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) { - char str[16]; - snprintf(str, 16, "%i", _color.value()); - string += str; + _color.setValue(in); + + return in; } -Gtk::Widget *ParamColor::get_widget( SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal * changeSignal ) +Gtk::Widget *ParamColor::get_widget( SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal *changeSignal ) { using Inkscape::UI::Widget::ColorNotebook; @@ -96,25 +75,32 @@ Gtk::Widget *ParamColor::get_widget( SPDocument * /*doc*/, Inkscape::XML::Node * _changeSignal = new sigc::signal(*changeSignal); } - if (_color.value() < 1) { - _color_changed.block(true); - _color.setValue(0xFF000000); - _color_changed.block(false); - } - Gtk::HBox *hbox = Gtk::manage(new Gtk::HBox(false, Parameter::GUI_PARAM_WIDGETS_SPACING)); Gtk::Widget *selector = Gtk::manage(new ColorNotebook(_color)); hbox->pack_start(*selector, true, true, 0); selector->show(); hbox->show(); + return hbox; } void ParamColor::_onColorChanged() { + gchar *pref_name = this->pref_name(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setUInt(extension_pref_root + pref_name, _color.value()); + g_free(pref_name); + if (_changeSignal) _changeSignal->emit(); } +void ParamColor::string(std::string &string) const +{ + char str[16]; + snprintf(str, 16, "%u", _color.value()); + string += str; +} + }; /* namespace Extension */ }; /* namespace Inkscape */ diff --git a/src/extension/prefdialog/parameter-color.h b/src/extension/prefdialog/parameter-color.h index c2d3c2ccb..da78f5d61 100644 --- a/src/extension/prefdialog/parameter-color.h +++ b/src/extension/prefdialog/parameter-color.h @@ -31,29 +31,24 @@ private: Inkscape::UI::SelectedColor _color; sigc::connection _color_changed; + sigc::connection _color_released; public: - ParamColor(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml); + ParamColor(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext); ~ParamColor() override; /** Returns \c _value, with a \i const to protect it. */ guint32 get( SPDocument const * /*doc*/, Inkscape::XML::Node const * /*node*/ ) const { return _color.value(); } - guint32 set (guint32 in, SPDocument * doc, Inkscape::XML::Node * node); + guint32 set (guint32 in, SPDocument *doc, Inkscape::XML::Node *node); - Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) override; + Gtk::Widget *get_widget(SPDocument *doc, Inkscape::XML::Node *node, sigc::signal *changeSignal) override; // Explicitly call superclass version to avoid method being hidden. void string(std::list &list) const override { return Parameter::string(list); } void string (std::string &string) const override; - sigc::signal * _changeSignal; + sigc::signal *_changeSignal; }; // class ParamColor diff --git a/src/extension/prefdialog/parameter-description.cpp b/src/extension/prefdialog/parameter-description.cpp index 667670443..3ceea7665 100644 --- a/src/extension/prefdialog/parameter-description.cpp +++ b/src/extension/prefdialog/parameter-description.cpp @@ -21,79 +21,68 @@ namespace Inkscape { namespace Extension { -/** \brief Initialize the object, to do that, copy the data. */ -ParamDescription::ParamDescription(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml, - AppearanceMode mode) - : Parameter(name, text, description, hidden, indent, ext) - , _value(nullptr) - , _mode(mode) +ParamDescription::ParamDescription(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext) + : Parameter(xml, ext) { // construct the text content by concatenating all (non-empty) text nodes, // removing all other nodes (e.g. comment nodes) and replacing elements with "
" - Glib::ustring value; Inkscape::XML::Node * cur_child = xml->firstChild(); while (cur_child != nullptr) { if (cur_child->type() == XML::TEXT_NODE && cur_child->content() != nullptr) { - value += cur_child->content(); + _value += cur_child->content(); } else if (cur_child->type() == XML::ELEMENT_NODE && !g_strcmp0(cur_child->name(), "extension:br")) { - value += "
"; + _value += "
"; } cur_child = cur_child->next(); } - // if there is no text content we can return immediately (the description will be invisible) - if (value == Glib::ustring("")) { - return; - } - // do replacements in the source string to account for the attribute xml:space="preserve" // (those should match replacements potentially performed by xgettext to allow for proper translation) if (g_strcmp0(xml->attribute("xml:space"), "preserve") == 0) { // xgettext copies the source string verbatim in this case, so no changes needed } else { // remove all whitespace from start/end of string and replace intermediate whitespace with a single space - value = Glib::Regex::create("^\\s+|\\s+$")->replace_literal(value, 0, "", (Glib::RegexMatchFlags)0); - value = Glib::Regex::create("\\s+")->replace_literal(value, 0, " ", (Glib::RegexMatchFlags)0); + _value = Glib::Regex::create("^\\s+|\\s+$")->replace_literal(_value, 0, "", (Glib::RegexMatchFlags)0); + _value = Glib::Regex::create("\\s+")->replace_literal(_value, 0, " ", (Glib::RegexMatchFlags)0); } - // translate if underscored version (_param) was used - if (g_str_has_prefix(xml->name(), "extension:_")) { - const gchar * context = xml->attribute("msgctxt"); - if (context != nullptr) { - value = g_dpgettext2(nullptr, context, value.c_str()); - } else { - value = _(value.c_str()); + // translate value + if (!_value.empty()) { + if (_translatable != NO) { // translate unless explicitly marked untranslatable + if (_context) { + _value = g_dpgettext2(nullptr, _context, _value.c_str()); + } else { + _value = _(_value.c_str()); + } } } // finally replace all remaining
with a real newline character - value = Glib::Regex::create("
")->replace_literal(value, 0, "\n", (Glib::RegexMatchFlags)0); - - _value = g_strdup(value.c_str()); - - return; + _value = Glib::Regex::create("
")->replace_literal(_value, 0, "\n", (Glib::RegexMatchFlags)0); + + // parse appearance + if (_appearance) { + if (!strcmp(_appearance, "header")) { + _mode = HEADER; + } else if (!strcmp(_appearance, "url")) { + _mode = URL; + } else { + g_warning("Invalid value ('%s') for appearance of parameter '%s' in extension '%s'", + _appearance, _name, _extension->get_id()); + } + } } /** \brief Create a label for the description */ -Gtk::Widget * -ParamDescription::get_widget (SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal * /*changeSignal*/) +Gtk::Widget *ParamDescription::get_widget (SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal * /*changeSignal*/) { if (_hidden) { return nullptr; } - if (_value == nullptr) { - return nullptr; - } Glib::ustring newtext = _value; - Gtk::Label * label = Gtk::manage(new Gtk::Label()); + Gtk::Label *label = Gtk::manage(new Gtk::Label()); if (_mode == HEADER) { label->set_markup(Glib::ustring("") + Glib::Markup::escape_text(newtext) + Glib::ustring("")); label->set_margin_top(5); @@ -109,10 +98,10 @@ ParamDescription::get_widget (SPDocument * /*doc*/, Inkscape::XML::Node * /*node // TODO: Ugly "fix" for gtk3 width/height calculation of labels. // - If not applying any limits long labels will make the window grow horizontally until it uses up - // most of the available space (i.e. most of the screen area) which is ridicously wide + // most of the available space (i.e. most of the screen area) which is ridiculously wide. // - By using "set_default_size(0,0)" in prefidalog.cpp we tell the window to shrink as much as possible, - // however this can result in a much to narrow dialog instead and much unnecessary wrapping - // - Here we set a lower limit of GUI_MAX_LINE_LENGTH characters per line that long texts will always use + // however this can result in a much too narrow dialog instead and a lot of unnecessary wrapping. + // - Here we set a lower limit of GUI_MAX_LINE_LENGTH characters per line that long texts will always use. // This means texts can not shrink anymore (they can still grow, though) and it's also necessary // to prevent https://bugzilla.gnome.org/show_bug.cgi?id=773572 int len = newtext.length(); @@ -120,7 +109,7 @@ ParamDescription::get_widget (SPDocument * /*doc*/, Inkscape::XML::Node * /*node label->show(); - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox()); + Gtk::HBox *hbox = Gtk::manage(new Gtk::HBox()); hbox->pack_start(*label, true, true); hbox->show(); diff --git a/src/extension/prefdialog/parameter-description.h b/src/extension/prefdialog/parameter-description.h index 822370b82..7eac524a8 100644 --- a/src/extension/prefdialog/parameter-description.h +++ b/src/extension/prefdialog/parameter-description.h @@ -28,22 +28,18 @@ namespace Extension { class ParamDescription : public Parameter { public: enum AppearanceMode { - DESCRIPTION, HEADER, URL + DEFAULT, HEADER, URL }; - ParamDescription(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml, - AppearanceMode mode); - - Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) override; + + ParamDescription(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext); + + Gtk::Widget *get_widget(SPDocument *doc, Inkscape::XML::Node *node, sigc::signal *changeSignal) override; private: /** \brief Internal value. */ - gchar * _value; - AppearanceMode _mode; + Glib::ustring _value; + + /** appearance mode **/ + AppearanceMode _mode = DEFAULT; }; } /* namespace Extension */ diff --git a/src/extension/prefdialog/parameter-enum.cpp b/src/extension/prefdialog/parameter-enum.cpp deleted file mode 100644 index 9c71c3df8..000000000 --- a/src/extension/prefdialog/parameter-enum.cpp +++ /dev/null @@ -1,269 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** \file - * extension parameter for enumerations. - * - * It uses a Gtk:ComboBoxText widget in the extension UI. - */ - -/* - * Author: - * Johan Engelen - * Jon A. Cruz - * - * Copyright (C) 2006-2007 Johan Engelen - * - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include "parameter-enum.h" - -#include -#include -#include - -#include "xml/node.h" -#include "extension/extension.h" -#include "preferences.h" - -namespace Inkscape { -namespace Extension { - -ParamComboBox::ParamComboBox(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml) - : Parameter(name, text, description, hidden, indent, ext) - , _value(nullptr) -{ - const char *xmlval = nullptr; // the value stored in XML - - if (xml != nullptr) { - // Read XML tree to add enumeration items: - for (Inkscape::XML::Node *node = xml->firstChild(); node; node = node->next()) { - char const * chname = node->name(); - if (!strcmp(chname, INKSCAPE_EXTENSION_NS "item") || !strcmp(chname, INKSCAPE_EXTENSION_NS "_item")) { - Glib::ustring newtext, newvalue; - const char * contents = nullptr; - if (node->firstChild()) { - contents = node->firstChild()->content(); - } - if (contents != nullptr) { - // don't translate when 'item' but do translate when '_item' - // NOTE: internal extensions use build_from_mem and don't need _item but - // still need to include if are to be localized - if (!strcmp(chname, INKSCAPE_EXTENSION_NS "_item")) { - if (node->attribute("msgctxt") != nullptr) { - newtext = g_dpgettext2(nullptr, node->attribute("msgctxt"), contents); - } else { - newtext = _(contents); - } - } else { - newtext = contents; - } - } else - continue; - - const char * val = node->attribute("value"); - if (val != nullptr) { - newvalue = val; - } else { - newvalue = contents; - } - - if ( (!newtext.empty()) && (!newvalue.empty()) ) { // logical error if this is not true here - choices.push_back(new enumentry(newvalue, newtext) ); - } - } - } - - // Initialize _value with the default value from xml - // for simplicity : default to the contents of the first xml-child - if (xml->firstChild() && xml->firstChild()->firstChild()) { - xmlval = xml->firstChild()->attribute("value"); - } - } - - gchar * pref_name = this->pref_name(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring paramval = prefs ? prefs->getString(extension_pref_root + pref_name) : ""; - g_free(pref_name); - - if (!paramval.empty()) { - _value = g_strdup(paramval.data()); - } else if (xmlval) { - _value = g_strdup(xmlval); - } -} - -ParamComboBox::~ParamComboBox () -{ - //destroy choice strings - for (auto i:choices) { - delete i; - } - g_free(_value); -} - - -/** - * A function to set the \c _value. - * - * This function sets ONLY the internal value, but it also sets the value - * in the preferences structure. To put it in the right place, \c PREF_DIR - * and \c pref_name() are used. - * - * To copy the data into _value the old memory must be free'd first. - * It is important to note that \c g_free handles \c NULL just fine. Then - * the passed in value is duplicated using \c g_strdup(). - * - * @param in The value to set. - * @param doc A document that should be used to set the value. - * @param node The node where the value may be placed. - */ -const gchar *ParamComboBox::set(const gchar * in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) -{ - if (in == nullptr) { - return nullptr; /* Can't have NULL string */ - } - - Glib::ustring settext; - for (auto entr:choices) { - if ( !entr->text.compare(in) ) { - settext = entr->value; - break; // break out of for loop - } - } - if (!settext.empty()) { - if (_value != nullptr) { - g_free(_value); - } - _value = g_strdup(settext.data()); - gchar * prefname = this->pref_name(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString(extension_pref_root + prefname, _value); - g_free(prefname); - } - - return _value; -} - -/** - * function to test if \c text is selectable - */ -bool ParamComboBox::contains(const gchar * text, SPDocument const * /*doc*/, Inkscape::XML::Node const * /*node*/) const -{ - if (text == nullptr) { - return false; /* Can't have NULL string */ - } - - for (auto entr:choices) { - if ( !entr->text.compare(text) ) - return true; - } - // if we did not find the text in this ParamComboBox: - return false; -} - -void -ParamComboBox::changed () { - -} - -void ParamComboBox::string(std::string &string) const -{ - string += _value; -} - - - - -/** A special category of Gtk::Entry to handle string parameteres. */ -class ParamComboBoxEntry : public Gtk::ComboBoxText { -private: - ParamComboBox * _pref; - SPDocument * _doc; - Inkscape::XML::Node * _node; - sigc::signal * _changeSignal; -public: - /** - * Build a string preference for the given parameter. - * @param pref Where to get the string from, and where to put it - * when it changes. - */ - ParamComboBoxEntry (ParamComboBox * pref, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) : - Gtk::ComboBoxText(), _pref(pref), _doc(doc), _node(node), _changeSignal(changeSignal) { - this->signal_changed().connect(sigc::mem_fun(this, &ParamComboBoxEntry::changed)); - }; - void changed (); -}; - -/** - * Respond to the text box changing. - * - * This function responds to the box changing by grabbing the value - * from the text box and putting it in the parameter. - */ -void -ParamComboBoxEntry::changed () -{ - Glib::ustring data = this->get_active_text(); - _pref->set(data.c_str(), _doc, _node); - if (_changeSignal != nullptr) { - _changeSignal->emit(); - } -} - -/** - * Creates a combobox widget for an enumeration parameter. - */ -Gtk::Widget *ParamComboBox::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) -{ - if (_hidden) { - return nullptr; - } - - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, Parameter::GUI_PARAM_WIDGETS_SPACING)); - Gtk::Label * label = Gtk::manage(new Gtk::Label(_text, Gtk::ALIGN_START)); - label->show(); - hbox->pack_start(*label, false, false); - - ParamComboBoxEntry * combo = Gtk::manage(new ParamComboBoxEntry(this, doc, node, changeSignal)); - // add choice strings: - Glib::ustring settext; - for (auto entr:choices) { - Glib::ustring text = entr->text; - combo->append(text); - - if ( _value && !entr->value.compare(_value) ) { - settext = entr->text; - } - } - if (!settext.empty()) { - combo->set_active_text(settext); - } - - combo->show(); - hbox->pack_start(*combo, true, true); - - hbox->show(); - - return dynamic_cast(hbox); -} - - -} // namespace Extension -} // namespace Inkscape - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/extension/prefdialog/parameter-enum.h b/src/extension/prefdialog/parameter-enum.h deleted file mode 100644 index 329bb26f9..000000000 --- a/src/extension/prefdialog/parameter-enum.h +++ /dev/null @@ -1,106 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -#ifndef INK_EXTENSION_PARAMENUM_H_SEEN -#define INK_EXTENSION_PARAMENUM_H_SEEN - -/** \file - * Enumeration parameter for extensions. - */ - -/* - * Authors: - * Johan Engelen - * Jon A. Cruz - * - * Copyright (C) 2006-2007 Johan Engelen - * - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include - -#include "parameter.h" -#include "document.h" - -namespace Gtk { -class Widget; -} - -namespace Inkscape { -namespace Extension { - -class Extension; - - -// \brief A class to represent a notebookparameter of an extension -class ParamComboBox : public Parameter { -private: - /** \brief Internal value. This should point to a string that has - been allocated in memory. And should be free'd. - It is the value of the current selected string */ - gchar * _value; - - /* For internal use only. - * Note that value and text MUST be non-NULL. - * This is ensured by newing only at one location in the code where non-NULL checks are made. - */ - class enumentry { - public: - enumentry (Glib::ustring &val, Glib::ustring &text) : - value(val), - text(text) - {} - - Glib::ustring value; - Glib::ustring text; - }; - - std::vector choices; /**< A table to store the choice strings */ - -public: - ParamComboBox(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml); - ~ParamComboBox() override; - - Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) override; - - // Explicitly call superclass version to avoid method being hidden. - void string(std::list &list) const override { return Parameter::string(list); } - - void string(std::string &string) const override; - - gchar const *get(SPDocument const * /*doc*/, Inkscape::XML::Node const * /*node*/) const { return _value; } - - const gchar * set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node); - - /** - * @returns true if text is part of this enum - */ - bool contains(const gchar * text, SPDocument const * /*doc*/, Inkscape::XML::Node const * /*node*/) const; - - void changed (); -}; /* class ParamComboBox */ - - - - - -} /* namespace Extension */ -} /* namespace Inkscape */ - -#endif /* INK_EXTENSION_PARAMENUM_H_SEEN */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/extension/prefdialog/parameter-float.cpp b/src/extension/prefdialog/parameter-float.cpp index 79908d841..fe8a55093 100644 --- a/src/extension/prefdialog/parameter-float.cpp +++ b/src/extension/prefdialog/parameter-float.cpp @@ -22,67 +22,57 @@ namespace Inkscape { namespace Extension { - -/** Use the superclass' allocator and set the \c _value. */ -ParamFloat::ParamFloat(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml, - AppearanceMode mode) - : Parameter(name, text, description, hidden, indent, ext) - , _value(0.0) - , _mode(mode) - , _min(0.0) - , _max(10.0) +ParamFloat::ParamFloat(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext) + : Parameter(xml, ext) { - const gchar * defaultval = nullptr; - if (xml->firstChild() != nullptr) { - defaultval = xml->firstChild()->content(); - } - if (defaultval != nullptr) { - _value = g_ascii_strtod (defaultval,nullptr); + // get value + if (xml->firstChild()) { + const char *value = xml->firstChild()->content(); + if (value) { + _value = g_ascii_strtod(value, nullptr); + } } - const char * maxval = xml->attribute("max"); - if (maxval != nullptr) { - _max = g_ascii_strtod (maxval,nullptr); - } + gchar *pref_name = this->pref_name(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + _value = prefs->getDouble(extension_pref_root + pref_name, _value); + g_free(pref_name); - const char * minval = xml->attribute("min"); - if (minval != nullptr) { - _min = g_ascii_strtod (minval,nullptr); + // parse and apply limits + const char *min = xml->attribute("min"); + if (min) { + _min = g_ascii_strtod(min, nullptr); } - _precision = 1; - const char * precision = xml->attribute("precision"); - if (precision != nullptr) { - _precision = atoi(precision); + const char *max = xml->attribute("max"); + if (max) { + _max = g_ascii_strtod(max, nullptr); } - /* We're handling this by just killing both values */ - if (_max < _min) { - _max = 10.0; - _min = 0.0; + if (_value < _min) { + _value = _min; } - gchar * pref_name = this->pref_name(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - _value = prefs->getDouble(extension_pref_root + pref_name, _value); - g_free(pref_name); - - // std::cout << "New Float:: value: " << _value << " max: " << _max << " min: " << _min << std::endl; - if (_value > _max) { _value = _max; } - if (_value < _min) { - _value = _min; + + // parse precision + const char *precision = xml->attribute("precision"); + if (precision != nullptr) { + _precision = strtol(precision, nullptr, 0); } - return; + + // parse appearance + if (_appearance) { + if (!strcmp(_appearance, "full")) { + _mode = FULL; + } else { + g_warning("Invalid value ('%s') for appearance of parameter '%s' in extension '%s'", + _appearance, _name, _extension->get_id()); + } + } } /** @@ -106,10 +96,10 @@ float ParamFloat::set(float in, SPDocument * /*doc*/, Inkscape::XML::Node * /*no _value = _min; } - gchar * prefname = this->pref_name(); + gchar *pref_name = this->pref_name(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setDouble(extension_pref_root + prefname, _value); - g_free(prefname); + prefs->setDouble(extension_pref_root + pref_name, _value); + g_free(pref_name); return _value; } @@ -125,14 +115,14 @@ void ParamFloat::string(std::string &string) const /** A class to make an adjustment that uses Extension params. */ class ParamFloatAdjustment : public Gtk::Adjustment { /** The parameter to adjust. */ - ParamFloat * _pref; - SPDocument * _doc; - Inkscape::XML::Node * _node; - sigc::signal * _changeSignal; + ParamFloat *_pref; + SPDocument *_doc; + Inkscape::XML::Node *_node; + sigc::signal *_changeSignal; public: /** Make the adjustment using an extension and the string describing the parameter. */ - ParamFloatAdjustment (ParamFloat * param, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) : + ParamFloatAdjustment (ParamFloat *param, SPDocument *doc, Inkscape::XML::Node *node, sigc::signal *changeSignal) : Gtk::Adjustment(0.0, param->min(), param->max(), 0.1, 1.0, 0), _pref(param), _doc(doc), _node(node), _changeSignal(changeSignal) { this->set_value(_pref->get(nullptr, nullptr) /* \todo fix */); this->signal_value_changed().connect(sigc::mem_fun(this, &ParamFloatAdjustment::val_changed)); @@ -163,13 +153,13 @@ void ParamFloatAdjustment::val_changed() * * Builds a hbox with a label and a float adjustment in it. */ -Gtk::Widget * ParamFloat::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) +Gtk::Widget *ParamFloat::get_widget(SPDocument *doc, Inkscape::XML::Node *node, sigc::signal *changeSignal) { if (_hidden) { return nullptr; } - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, Parameter::GUI_PARAM_WIDGETS_SPACING)); + Gtk::HBox *hbox = Gtk::manage(new Gtk::HBox(false, Parameter::GUI_PARAM_WIDGETS_SPACING)); auto pfa = new ParamFloatAdjustment(this, doc, node, changeSignal); Glib::RefPtr fadjust(pfa); @@ -185,9 +175,9 @@ Gtk::Widget * ParamFloat::get_widget(SPDocument * doc, Inkscape::XML::Node * nod hbox->pack_start(*scale, true, true); } - else if (_mode == MINIMAL) { + else if (_mode == DEFAULT) { - Gtk::Label * label = Gtk::manage(new Gtk::Label(_text, Gtk::ALIGN_START)); + Gtk::Label *label = Gtk::manage(new Gtk::Label(_text, Gtk::ALIGN_START)); label->show(); hbox->pack_start(*label, true, true); diff --git a/src/extension/prefdialog/parameter-float.h b/src/extension/prefdialog/parameter-float.h index c1d0f0f79..0c42ef2bc 100644 --- a/src/extension/prefdialog/parameter-float.h +++ b/src/extension/prefdialog/parameter-float.h @@ -28,21 +28,15 @@ namespace Extension { class ParamFloat : public Parameter { public: enum AppearanceMode { - FULL, MINIMAL + DEFAULT, FULL }; - ParamFloat(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml, - AppearanceMode mode); + + ParamFloat(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext); /** Returns \c _value. */ float get(const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) const { return _value; } - float set (float in, SPDocument * doc, Inkscape::XML::Node * node); + float set (float in, SPDocument *doc, Inkscape::XML::Node *node); float max () { return _max; } @@ -50,7 +44,7 @@ public: float precision () { return _precision; } - Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) override; + Gtk::Widget *get_widget(SPDocument *doc, Inkscape::XML::Node *node, sigc::signal *changeSignal) override; // Explicitly call superclass version to avoid method being hidden. void string(std::list &list) const override { return Parameter::string(list); } @@ -59,11 +53,18 @@ public: private: /** Internal value. */ - float _value; - AppearanceMode _mode; - float _min; - float _max; - int _precision; + float _value = 0; + + /** limits */ + // TODO: do these defaults make sense or should we be unbounded by default? + float _min = 0; + float _max = 10; + + /** numeric precision (i.e. number of digits) */ + int _precision = 1; + + /** appearance mode **/ + AppearanceMode _mode = DEFAULT; }; } /* namespace Extension */ diff --git a/src/extension/prefdialog/parameter-int.cpp b/src/extension/prefdialog/parameter-int.cpp index 2b9e2c5f6..b03afc1e1 100644 --- a/src/extension/prefdialog/parameter-int.cpp +++ b/src/extension/prefdialog/parameter-int.cpp @@ -23,42 +23,15 @@ namespace Inkscape { namespace Extension { -/** Use the superclass' allocator and set the \c _value. */ -ParamInt::ParamInt(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml, - AppearanceMode mode) - : Parameter(name, text, description, hidden, indent, ext) - , _value(0) - , _mode(mode) - , _min(0) - , _max(10) +ParamInt::ParamInt(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext) + : Parameter(xml, ext) { - const char * defaultval = nullptr; - if (xml->firstChild() != nullptr) { - defaultval = xml->firstChild()->content(); - } - if (defaultval != nullptr) { - _value = atoi(defaultval); - } - - const char * maxval = xml->attribute("max"); - if (maxval != nullptr) { - _max = atoi(maxval); - } - - const char * minval = xml->attribute("min"); - if (minval != nullptr) { - _min = atoi(minval); - } - /* We're handling this by just killing both values */ - if (_max < _min) { - _max = 10; - _min = 0; + // get value + if (xml->firstChild()) { + const char *value = xml->firstChild()->content(); + if (value) { + _value = strtol(value, nullptr, 0); + } } gchar *pref_name = this->pref_name(); @@ -66,14 +39,34 @@ ParamInt::ParamInt(const gchar * name, _value = prefs->getInt(extension_pref_root + pref_name, _value); g_free(pref_name); - // std::cout << "New Int:: value: " << _value << " max: " << _max << " min: " << _min << std::endl; + // parse and apply limits + const char *min = xml->attribute("min"); + if (min) { + _min = strtol(min, nullptr, 0); + } - if (_value > _max) { - _value = _max; + const char *max = xml->attribute("max"); + if (max) { + _max = strtol(max, nullptr, 0); } + if (_value < _min) { _value = _min; } + + if (_value > _max) { + _value = _max; + } + + // parse appearance + if (_appearance) { + if (!strcmp(_appearance, "full")) { + _mode = FULL; + } else { + g_warning("Invalid value ('%s') for appearance of parameter '%s' in extension '%s'", + _appearance, _name, _extension->get_id()); + } + } } /** @@ -96,10 +89,10 @@ int ParamInt::set(int in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) _value = _min; } - gchar * prefname = this->pref_name(); + gchar *pref_name = this->pref_name(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setInt(extension_pref_root + prefname, _value); - g_free(prefname); + prefs->setInt(extension_pref_root + pref_name, _value); + g_free(pref_name); return _value; } @@ -107,14 +100,14 @@ int ParamInt::set(int in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) /** A class to make an adjustment that uses Extension params. */ class ParamIntAdjustment : public Gtk::Adjustment { /** The parameter to adjust. */ - ParamInt * _pref; - SPDocument * _doc; - Inkscape::XML::Node * _node; - sigc::signal * _changeSignal; + ParamInt *_pref; + SPDocument *_doc; + Inkscape::XML::Node *_node; + sigc::signal *_changeSignal; public: /** Make the adjustment using an extension and the string describing the parameter. */ - ParamIntAdjustment (ParamInt * param, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) : + ParamIntAdjustment (ParamInt *param, SPDocument *doc, Inkscape::XML::Node *node, sigc::signal *changeSignal) : Gtk::Adjustment(0.0, param->min(), param->max(), 1.0, 10.0, 0), _pref(param), _doc(doc), _node(node), _changeSignal(changeSignal) { this->set_value(_pref->get(nullptr, nullptr) /* \todo fix */); this->signal_value_changed().connect(sigc::mem_fun(this, &ParamIntAdjustment::val_changed)); @@ -144,13 +137,13 @@ void ParamIntAdjustment::val_changed() * Builds a hbox with a label and a int adjustment in it. */ Gtk::Widget * -ParamInt::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) +ParamInt::get_widget (SPDocument *doc, Inkscape::XML::Node *node, sigc::signal *changeSignal) { if (_hidden) { return nullptr; } - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, Parameter::GUI_PARAM_WIDGETS_SPACING)); + Gtk::HBox *hbox = Gtk::manage(new Gtk::HBox(false, Parameter::GUI_PARAM_WIDGETS_SPACING)); auto pia = new ParamIntAdjustment(this, doc, node, changeSignal); Glib::RefPtr fadjust(pia); @@ -165,8 +158,8 @@ ParamInt::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal scale->show(); hbox->pack_start(*scale, true, true); } - else if (_mode == MINIMAL) { - Gtk::Label * label = Gtk::manage(new Gtk::Label(_text, Gtk::ALIGN_START)); + else if (_mode == DEFAULT) { + Gtk::Label *label = Gtk::manage(new Gtk::Label(_text, Gtk::ALIGN_START)); label->show(); hbox->pack_start(*label, true, true); diff --git a/src/extension/prefdialog/parameter-int.h b/src/extension/prefdialog/parameter-int.h index fac481267..30e34740c 100644 --- a/src/extension/prefdialog/parameter-int.h +++ b/src/extension/prefdialog/parameter-int.h @@ -28,27 +28,21 @@ namespace Extension { class ParamInt : public Parameter { public: enum AppearanceMode { - FULL, MINIMAL + DEFAULT, FULL }; - ParamInt(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml, - AppearanceMode mode); + + ParamInt(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext); /** Returns \c _value. */ int get(const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) const { return _value; } - int set (int in, SPDocument * doc, Inkscape::XML::Node * node); + int set (int in, SPDocument *doc, Inkscape::XML::Node *node); int max () { return _max; } int min () { return _min; } - Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) override; + Gtk::Widget *get_widget(SPDocument *doc, Inkscape::XML::Node *node, sigc::signal *changeSignal) override; // Explicitly call superclass version to avoid method being hidden. void string(std::list &list) const override { return Parameter::string(list); } @@ -57,10 +51,15 @@ public: private: /** Internal value. */ - int _value; - AppearanceMode _mode; - int _min; - int _max; + int _value = 0; + + /** limits */ + // TODO: do these defaults make sense or should we be unbounded by default? + int _min = 0; + int _max = 10; + + /** appearance mode **/ + AppearanceMode _mode = DEFAULT; }; } /* namespace Extension */ diff --git a/src/extension/prefdialog/parameter-notebook.cpp b/src/extension/prefdialog/parameter-notebook.cpp index 77d94aa5a..6e733a4b4 100644 --- a/src/extension/prefdialog/parameter-notebook.cpp +++ b/src/extension/prefdialog/parameter-notebook.cpp @@ -38,30 +38,28 @@ namespace Inkscape { namespace Extension { -ParamNotebook::ParamNotebookPage::ParamNotebookPage(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml) - : Parameter(name, text, description, hidden, /*indent*/ 0, ext) +ParamNotebook::ParamNotebookPage::ParamNotebookPage(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext) + : Parameter(xml, ext) { - - // Read XML to build page - if (xml != nullptr) { + // Read XML tree of page and parse parameters + if (xml) { Inkscape::XML::Node *child_repr = xml->firstChild(); - while (child_repr != nullptr) { - char const * chname = child_repr->name(); + while (child_repr) { + const char *chname = child_repr->name(); if (!strncmp(chname, INKSCAPE_EXTENSION_NS_NC, strlen(INKSCAPE_EXTENSION_NS_NC))) { chname += strlen(INKSCAPE_EXTENSION_NS); } - if (chname[0] == '_') // Allow _ for translation of tags + if (chname[0] == '_') { // allow leading underscore in tag names for backwards-compatibility chname++; + } + if (!strcmp(chname, "param") || !strcmp(chname, "_param")) { - Parameter * param; - param = Parameter::make(child_repr, ext); - if (param != nullptr) parameters.push_back(param); + Parameter *param = Parameter::make(child_repr, ext); + if (param) { + parameters.push_back(param); + } } + child_repr = child_repr->next(); } } @@ -70,88 +68,25 @@ ParamNotebook::ParamNotebookPage::ParamNotebookPage(const gchar * name, ParamNotebook::ParamNotebookPage::~ParamNotebookPage () { //destroy parameters - for (auto param:parameters) { - delete param; + for (auto parameter : parameters) { + delete parameter; } } /** Return the value as a string. */ void ParamNotebook::ParamNotebookPage::paramString(std::list &list) { - for (auto param:parameters) { - param->string(list); - } -} - - -/** - \return None - \brief This function creates a page that can be used later. This - is typically done in the creation of the notebook and defined - in the XML file describing the extension (it's private so people - have to use the system) :) - \param in_repr The XML describing the page - \todo the 'gui-hidden' attribute is read but not used! - - This function first grabs all of the data out of the Repr and puts - it into local variables. Actually, these are just pointers, and the - data is not duplicated so we need to be careful with it. If there - isn't a name in the XML, then no page is created as - the function just returns. - - From this point on, we're pretty committed as we've allocated an - object and we're starting to fill it. The name is set first, and - is created with a strdup to actually allocate memory for it. Then - there is a case statement (roughly because strcmp requires 'ifs') - based on what type of parameter this is. Depending which type it - is, the value is interpreted differently, but they are relatively - straight forward. In all cases the value is set to the default - value from the XML and the type is set to the interpreted type. -*/ -ParamNotebook::ParamNotebookPage * -ParamNotebook::ParamNotebookPage::makepage (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * in_ext) -{ - const char * name; - const char * text; - const char * description; - bool hidden = false; - const char * hide; - - name = in_repr->attribute("name"); - text = in_repr->attribute("gui-text"); - if (text == nullptr) - text = in_repr->attribute("_gui-text"); - description = in_repr->attribute("gui-description"); - if (description == nullptr) - description = in_repr->attribute("_gui-description"); - hide = in_repr->attribute("gui-hidden"); - if (hide != nullptr) { - if (strcmp(hide, "1") == 0 || - strcmp(hide, "true") == 0) { - hidden = true; - } - /* else stays false */ + for (auto parameter : parameters) { + parameter->string(list); } - - /* In this case we just don't have enough information */ - if (name == nullptr) { - return nullptr; - } - - ParamNotebookPage * page = new ParamNotebookPage(name, text, description, hidden, in_ext, in_repr); - - /* Note: page could equal NULL */ - return page; } - - /** * Creates a notebookpage widget for a notebook. * * Builds a notebook page (a vbox) and puts parameters on it. */ -Gtk::Widget * ParamNotebook::ParamNotebookPage::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) +Gtk::Widget *ParamNotebook::ParamNotebookPage::get_widget(SPDocument *doc, Inkscape::XML::Node *node, sigc::signal *changeSignal) { if (_hidden) { return nullptr; @@ -162,19 +97,16 @@ Gtk::Widget * ParamNotebook::ParamNotebookPage::get_widget(SPDocument * doc, Ink vbox->set_spacing(Parameter::GUI_BOX_SPACING); // add parameters onto page (if any) - for (auto param:parameters) { - Gtk::Widget * widg = param->get_widget(doc, node, changeSignal); - if (widg) { - int indent = param->get_indent(); - widg->set_margin_start(indent * Parameter::GUI_INDENTATION); - vbox->pack_start(*widg, false, false, 0); - - gchar const * tip = param->get_tooltip(); - if (tip) { - widg->set_tooltip_text(tip); - } else { - widg->set_tooltip_text(""); - widg->set_has_tooltip(false); + for (auto parameter : parameters) { + Gtk::Widget *parameter_widget = parameter->get_widget(doc, node, changeSignal); + if (parameter_widget) { + int indent = parameter->get_indent(); + parameter_widget->set_margin_start(indent *Parameter::GUI_INDENTATION); + vbox->pack_start(*parameter_widget, false, false, 0); + + const gchar *tooltip = parameter->get_tooltip(); + if (tooltip) { + parameter_widget->set_tooltip_text(tooltip); } } } @@ -185,7 +117,7 @@ Gtk::Widget * ParamNotebook::ParamNotebookPage::get_widget(SPDocument * doc, Ink } /** Search the parameter's name in the page content. */ -Parameter *ParamNotebook::ParamNotebookPage::get_param(const gchar * name) +Parameter *ParamNotebook::ParamNotebookPage::get_param(const gchar *name) { if (name == nullptr) { throw Extension::param_not_exist(); @@ -195,7 +127,7 @@ Parameter *ParamNotebook::ParamNotebookPage::get_param(const gchar * name) throw Extension::param_not_exist(); } - for (auto param:parameters) { + for (auto param : parameters) { if (!strcmp(param->name(), name)) { return param; } @@ -207,59 +139,49 @@ Parameter *ParamNotebook::ParamNotebookPage::get_param(const gchar * name) /** End ParamNotebookPage **/ /** ParamNotebook **/ -ParamNotebook::ParamNotebook(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml) - : Parameter(name, text, description, hidden, indent, ext) +ParamNotebook::ParamNotebook(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext) + : Parameter(xml, ext) { - // Read XML tree to add pages: - if (xml != nullptr) { + // Read XML tree to add pages (allow _page for backwards compatibility) + if (xml) { Inkscape::XML::Node *child_repr = xml->firstChild(); - while (child_repr != nullptr) { - char const * chname = child_repr->name(); - if (!strncmp(chname, INKSCAPE_EXTENSION_NS_NC, strlen(INKSCAPE_EXTENSION_NS_NC))) { - chname += strlen(INKSCAPE_EXTENSION_NS); - } - if (chname[0] == '_') // Allow _ for translation of tags - chname++; - if (!strcmp(chname, "page")) { - ParamNotebookPage * page; - page = ParamNotebookPage::makepage(child_repr, ext); - if (page != nullptr) pages.push_back(page); + while (child_repr) { + const char *chname = child_repr->name(); + if (chname && (!strcmp(chname, INKSCAPE_EXTENSION_NS "page") || + !strcmp(chname, INKSCAPE_EXTENSION_NS "_page") )) { + ParamNotebookPage *page; + page = new ParamNotebookPage(child_repr, ext); + + if (page) { + pages.push_back(page); + } } child_repr = child_repr->next(); } } - - // Initialize _value with the current page - const char * defaultval = nullptr; - // set first page as default - if (!pages.empty()) { - defaultval = pages[0]->name(); + if (pages.empty()) { + g_warning("No (valid) pages for parameter '%s' in extension '%s'", _name, _extension->get_id()); } - gchar * pref_name = this->pref_name(); + // get value (initialize with value of first page if pref is empty) + gchar *pref_name = this->pref_name(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring paramval = prefs->getString(extension_pref_root + pref_name); + _value = prefs->getString(extension_pref_root + pref_name); g_free(pref_name); - if (!paramval.empty()) - defaultval = paramval.data(); - if (defaultval != nullptr) - _value = g_strdup(defaultval); // allocate space for _value + if (_value.empty()) { + if (!pages.empty()) { + _value = pages[0]->name(); + } + } } ParamNotebook::~ParamNotebook () { //destroy pages - for (auto page:pages) { + for (auto page : pages) { delete page; } - g_free(_value); } @@ -270,28 +192,23 @@ ParamNotebook::~ParamNotebook () * in the preferences structure. To put it in the right place, \c PREF_DIR * and \c pref_name() are used. * - * To copy the data into _value the old memory must be free'd first. - * It is important to note that \c g_free handles \c NULL just fine. Then - * the passed in value is duplicated using \c g_strdup(). - * - * @param in The number of the page which value must be set. + * @param in The number of the page to set as new value. * @param doc A document that should be used to set the value. * @param node The node where the value may be placed. */ -const gchar *ParamNotebook::set(const int in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) +const Glib::ustring& ParamNotebook::set(const int in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) { int i = in < pages.size() ? in : pages.size()-1; - ParamNotebookPage * page = pages[i]; - - if (page == nullptr) return _value; + ParamNotebookPage *page = pages[i]; - if (_value != nullptr) g_free(_value); - _value = g_strdup(page->name()); + if (page) { + _value = page->name(); - gchar * prefname = this->pref_name(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString(extension_pref_root + prefname, _value); - g_free(prefname); + gchar *pref_name = this->pref_name(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setString(extension_pref_root + pref_name, _value); + g_free(pref_name); + } return _value; } @@ -300,7 +217,7 @@ void ParamNotebook::string(std::list &list) const { std::string param_string; param_string += "--"; - param_string += name(); + param_string += _name; param_string += "="; param_string += "\""; @@ -308,30 +225,35 @@ void ParamNotebook::string(std::list &list) const param_string += "\""; list.insert(list.end(), param_string); - for (auto page:pages) { + for (auto page : pages) { page->paramString(list); } } /** A special category of Gtk::Notebook to handle notebook parameters. */ -class ParamNotebookWdg : public Gtk::Notebook { +class NotebookWidget : public Gtk::Notebook { private: - ParamNotebook * _pref; - SPDocument * _doc; - Inkscape::XML::Node * _node; + ParamNotebook *_pref; + SPDocument *_doc; + Inkscape::XML::Node *_node; public: /** * Build a notebookpage preference for the given parameter. - * @param pref Where to get the string (pagename) from, and where to put it - * when it changes. + * @param pref Where to get the string (pagename) from, and where to put it when it changes. */ - ParamNotebookWdg (ParamNotebook * pref, SPDocument * doc, Inkscape::XML::Node * node) : - Gtk::Notebook(), _pref(pref), _doc(doc), _node(node), activated(false) { - // don't have to set the correct page: this is done in ParamNotebook::get_widget. - // hook function - this->signal_switch_page().connect(sigc::mem_fun(this, &ParamNotebookWdg::changed_page)); - }; + NotebookWidget (ParamNotebook *pref, SPDocument *doc, Inkscape::XML::Node *node) + : Gtk::Notebook() + , _pref(pref) + , _doc(doc) + , _node(node) + , activated(false) + { + // don't have to set the correct page: this is done in ParamNotebook::get_widget hook function + this->signal_switch_page().connect(sigc::mem_fun(this, &NotebookWidget::changed_page)); + } + void changed_page(Gtk::Widget *page, guint pagenum); + bool activated; }; @@ -342,7 +264,7 @@ public: * is actually visible. This to exclude 'fake' changes when the * notebookpages are added or removed. */ -void ParamNotebookWdg::changed_page(Gtk::Widget * /*page*/, guint pagenum) +void NotebookWidget::changed_page(Gtk::Widget * /*page*/, guint pagenum) { if (get_visible()) { _pref->set((int)pagenum, _doc, _node); @@ -350,13 +272,13 @@ void ParamNotebookWdg::changed_page(Gtk::Widget * /*page*/, guint pagenum) } /** Search the parameter's name in the notebook content. */ -Parameter *ParamNotebook::get_param(const gchar * name) +Parameter *ParamNotebook::get_param(const gchar *name) { if (name == nullptr) { throw Extension::param_not_exist(); } - for (auto page:pages) { - Parameter * subparam = page->get_param(name); + for (auto page : pages) { + Parameter *subparam = page->get_param(name); if (subparam) { return subparam; } @@ -371,31 +293,32 @@ Parameter *ParamNotebook::get_param(const gchar * name) * * Builds a notebook and puts pages in it. */ -Gtk::Widget * ParamNotebook::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) +Gtk::Widget *ParamNotebook::get_widget(SPDocument *doc, Inkscape::XML::Node *node, sigc::signal *changeSignal) { if (_hidden) { return nullptr; } - ParamNotebookWdg * nb = Gtk::manage(new ParamNotebookWdg(this, doc, node)); - - // add pages (if any) - int i = -1; - int pagenr = i; - for (auto page:pages) { - i++; - Gtk::Widget * widg = page->get_widget(doc, node, changeSignal); - nb->append_page(*widg, _(page->get_text())); - if (!strcmp(_value, page->name())) { - pagenr = i; // this is the page to be displayed? + NotebookWidget *notebook = Gtk::manage(new NotebookWidget(this, doc, node)); + + // add pages (if any) and switch to previously selected page + int current_page = -1; + int selected_page = -1; + for (auto page : pages) { + current_page++; + Gtk::Widget *page_widget = page->get_widget(doc, node, changeSignal); + notebook->append_page(*page_widget, _(page->get_text())); + if (_value == page->name()) { + selected_page = current_page; } } + if (selected_page >= 0) { + notebook->set_current_page(selected_page); + } - nb->show(); - - if (pagenr >= 0) nb->set_current_page(pagenr); + notebook->show(); - return dynamic_cast(nb); + return static_cast(notebook); } diff --git a/src/extension/prefdialog/parameter-notebook.h b/src/extension/prefdialog/parameter-notebook.h index f1e16308b..8f6243fc8 100644 --- a/src/extension/prefdialog/parameter-notebook.h +++ b/src/extension/prefdialog/parameter-notebook.h @@ -24,63 +24,50 @@ namespace Gtk { class Widget; } +namespace Glib { +class ustring; +} + namespace Inkscape { namespace Extension { class Extension; -/** A class to represent a notebookparameter of an extension. */ +/** A class to represent a notebook parameter of an extension. */ class ParamNotebook : public Parameter { private: - /** - * Internal value. This should point to a string that has - * been allocated in memory. And should be free'd. - * It is the name of the current page. - */ - gchar * _value; + /** Internal value. */ + Glib::ustring _value; /** - * A class to represent the pages of a notebookparameter of an extension. + * A class to represent the pages of a notebook parameter of an extension. */ class ParamNotebookPage : public Parameter { private: - std::vector parameters; /**< A table to store the parameters for this page. - This only gets created if there are parameters on this - page */ + /** A table to store the parameters for this page. + * This only gets created if there are parameters on this page */ + std::vector parameters; public: - static ParamNotebookPage * makepage (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * in_ext); - - ParamNotebookPage(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml); + ParamNotebookPage(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext); ~ParamNotebookPage() override; - Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) override; + Gtk::Widget *get_widget(SPDocument *doc, Inkscape::XML::Node *node, sigc::signal *changeSignal) override; void paramString (std::list &list); - gchar * get_text () {return _text;}; - Parameter * get_param (const gchar * name) override; + gchar *get_text () {return _text;}; + Parameter *get_param (const gchar *name) override; }; /* class ParamNotebookPage */ + /** A table to store the pages with parameters for this notebook. + * This only gets created if there are pages in this notebook */ + std::vector pages; - std::vector pages; /**< A table to store the pages with parameters for this notebook. - This only gets created if there are pages in this - notebook */ public: - ParamNotebook(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml); + ParamNotebook(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext); ~ParamNotebook() override; - Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) override; + Gtk::Widget *get_widget(SPDocument *doc, Inkscape::XML::Node *node, sigc::signal *changeSignal) override; /** * A function to get the currentpage and the parameters in a string form. @@ -92,10 +79,10 @@ public: void string(std::string &string) const override {return Parameter::string(string);} - Parameter * get_param (const gchar * name) override; + Parameter *get_param (const gchar *name) override; - const gchar * get (const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) { return _value; } - const gchar * set (const int in, SPDocument * doc, Inkscape::XML::Node * node); + const Glib::ustring& get (const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) { return _value; } + const Glib::ustring& set (const int in, SPDocument *doc, Inkscape::XML::Node *node); }; /* class ParamNotebook */ diff --git a/src/extension/prefdialog/parameter-optiongroup.cpp b/src/extension/prefdialog/parameter-optiongroup.cpp new file mode 100644 index 000000000..4fa43d44c --- /dev/null +++ b/src/extension/prefdialog/parameter-optiongroup.cpp @@ -0,0 +1,342 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** \file + *extension parameter for options with multiple predefined value choices + * + * Currently implemented as either Gtk::RadioButton or Gtk::ComboBoxText + */ + +/* + * Author: + * Johan Engelen + * + * Copyright (C) 2006-2007 Johan Engelen + * Copyright (C) 2008 Jon A. Cruz + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "parameter-optiongroup.h" + +#include +#include +#include +#include + +#include "xml/node.h" +#include "extension/extension.h" +#include "preferences.h" + +/** + * The root directory in the preferences database for extension + * related parameters. + */ +#define PREF_DIR "extensions" + +namespace Inkscape { +namespace Extension { + +ParamOptionGroup::ParamOptionGroup(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext) + : Parameter(xml, ext) +{ + // Read valid optiongroup choices from XML tree, i,e. + // -