From 7311f3ac5161a4d53cf2ed7e0a5a97993f646321 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Sun, 21 Jul 2019 15:24:05 +0200 Subject: Move prefdialog to own directory --- src/extension/CMakeLists.txt | 47 +-- src/extension/effect.cpp | 13 +- src/extension/execution-env.cpp | 2 +- src/extension/extension.cpp | 2 +- src/extension/input.cpp | 2 +- src/extension/output.cpp | 2 +- src/extension/param/bool.cpp | 154 --------- src/extension/param/bool.h | 95 ----- src/extension/param/color.cpp | 119 ------- src/extension/param/color.h | 74 ---- src/extension/param/description.cpp | 134 ------- src/extension/param/description.h | 63 ---- src/extension/param/enum.cpp | 268 -------------- src/extension/param/enum.h | 106 ------ src/extension/param/float.cpp | 205 ----------- src/extension/param/float.h | 83 ----- src/extension/param/int.cpp | 201 ----------- src/extension/param/int.h | 80 ----- src/extension/param/notebook.cpp | 413 ---------------------- src/extension/param/notebook.h | 117 ------- src/extension/param/parameter.cpp | 461 ------------------------- src/extension/param/parameter.h | 219 ------------ src/extension/param/radiobutton.cpp | 349 ------------------- src/extension/param/radiobutton.h | 107 ------ src/extension/param/string.cpp | 181 ---------- src/extension/param/string.h | 67 ---- src/extension/prefdialog.cpp | 276 --------------- src/extension/prefdialog.h | 94 ----- src/extension/prefdialog/param/bool.cpp | 154 +++++++++ src/extension/prefdialog/param/bool.h | 95 +++++ src/extension/prefdialog/param/color.cpp | 119 +++++++ src/extension/prefdialog/param/color.h | 74 ++++ src/extension/prefdialog/param/description.cpp | 134 +++++++ src/extension/prefdialog/param/description.h | 63 ++++ src/extension/prefdialog/param/enum.cpp | 268 ++++++++++++++ src/extension/prefdialog/param/enum.h | 106 ++++++ src/extension/prefdialog/param/float.cpp | 205 +++++++++++ src/extension/prefdialog/param/float.h | 83 +++++ src/extension/prefdialog/param/int.cpp | 201 +++++++++++ src/extension/prefdialog/param/int.h | 80 +++++ src/extension/prefdialog/param/notebook.cpp | 413 ++++++++++++++++++++++ src/extension/prefdialog/param/notebook.h | 117 +++++++ src/extension/prefdialog/param/parameter.cpp | 461 +++++++++++++++++++++++++ src/extension/prefdialog/param/parameter.h | 219 ++++++++++++ src/extension/prefdialog/param/radiobutton.cpp | 349 +++++++++++++++++++ src/extension/prefdialog/param/radiobutton.h | 107 ++++++ src/extension/prefdialog/param/string.cpp | 181 ++++++++++ src/extension/prefdialog/param/string.h | 67 ++++ src/extension/prefdialog/prefdialog.cpp | 277 +++++++++++++++ src/extension/prefdialog/prefdialog.h | 94 +++++ 50 files changed, 3902 insertions(+), 3899 deletions(-) delete mode 100644 src/extension/param/bool.cpp delete mode 100644 src/extension/param/bool.h delete mode 100644 src/extension/param/color.cpp delete mode 100644 src/extension/param/color.h delete mode 100644 src/extension/param/description.cpp delete mode 100644 src/extension/param/description.h delete mode 100644 src/extension/param/enum.cpp delete mode 100644 src/extension/param/enum.h delete mode 100644 src/extension/param/float.cpp delete mode 100644 src/extension/param/float.h delete mode 100644 src/extension/param/int.cpp delete mode 100644 src/extension/param/int.h delete mode 100644 src/extension/param/notebook.cpp delete mode 100644 src/extension/param/notebook.h delete mode 100644 src/extension/param/parameter.cpp delete mode 100644 src/extension/param/parameter.h delete mode 100644 src/extension/param/radiobutton.cpp delete mode 100644 src/extension/param/radiobutton.h delete mode 100644 src/extension/param/string.cpp delete mode 100644 src/extension/param/string.h delete mode 100644 src/extension/prefdialog.cpp delete mode 100644 src/extension/prefdialog.h create mode 100644 src/extension/prefdialog/param/bool.cpp create mode 100644 src/extension/prefdialog/param/bool.h create mode 100644 src/extension/prefdialog/param/color.cpp create mode 100644 src/extension/prefdialog/param/color.h create mode 100644 src/extension/prefdialog/param/description.cpp create mode 100644 src/extension/prefdialog/param/description.h create mode 100644 src/extension/prefdialog/param/enum.cpp create mode 100644 src/extension/prefdialog/param/enum.h create mode 100644 src/extension/prefdialog/param/float.cpp create mode 100644 src/extension/prefdialog/param/float.h create mode 100644 src/extension/prefdialog/param/int.cpp create mode 100644 src/extension/prefdialog/param/int.h create mode 100644 src/extension/prefdialog/param/notebook.cpp create mode 100644 src/extension/prefdialog/param/notebook.h create mode 100644 src/extension/prefdialog/param/parameter.cpp create mode 100644 src/extension/prefdialog/param/parameter.h create mode 100644 src/extension/prefdialog/param/radiobutton.cpp create mode 100644 src/extension/prefdialog/param/radiobutton.h create mode 100644 src/extension/prefdialog/param/string.cpp create mode 100644 src/extension/prefdialog/param/string.h create mode 100644 src/extension/prefdialog/prefdialog.cpp create mode 100644 src/extension/prefdialog/prefdialog.h diff --git a/src/extension/CMakeLists.txt b/src/extension/CMakeLists.txt index eaa9b4956..c00111209 100644 --- a/src/extension/CMakeLists.txt +++ b/src/extension/CMakeLists.txt @@ -11,7 +11,6 @@ set(extension_SRC input.cpp output.cpp patheffect.cpp - prefdialog.cpp print.cpp system.cpp timer.cpp @@ -21,17 +20,6 @@ set(extension_SRC implementation/xslt.cpp implementation/script.cpp - param/bool.cpp - param/color.cpp - param/description.cpp - param/enum.cpp - param/float.cpp - param/int.cpp - param/notebook.cpp - param/parameter.cpp - param/radiobutton.cpp - param/string.cpp - internal/bluredge.cpp internal/cairo-ps-out.cpp internal/cairo-render-context.cpp @@ -64,6 +52,18 @@ set(extension_SRC internal/pdfinput/pdf-parser.cpp internal/pdfinput/svg-builder.cpp + prefdialog/prefdialog.cpp + prefdialog/param/bool.cpp + prefdialog/param/color.cpp + prefdialog/param/description.cpp + prefdialog/param/enum.cpp + prefdialog/param/float.cpp + prefdialog/param/int.cpp + prefdialog/param/notebook.cpp + prefdialog/param/parameter.cpp + prefdialog/param/radiobutton.cpp + prefdialog/param/string.cpp + # ------ # Header db.h @@ -75,18 +75,7 @@ set(extension_SRC init.h input.h output.h - param/bool.h - param/color.h - param/description.h - param/enum.h - param/float.h - param/int.h - param/notebook.h - param/parameter.h - param/radiobutton.h - param/string.h patheffect.h - prefdialog.h print.h system.h timer.h @@ -137,6 +126,18 @@ set(extension_SRC internal/text_reassemble.h internal/wmf-inout.h internal/wmf-print.h + + prefdialog/prefdialog.h + prefdialog/param/bool.h + prefdialog/param/color.h + prefdialog/param/description.h + prefdialog/param/enum.h + prefdialog/param/float.h + prefdialog/param/int.h + prefdialog/param/notebook.h + prefdialog/param/parameter.h + prefdialog/param/radiobutton.h + prefdialog/param/string.h ) if(WIN32) diff --git a/src/extension/effect.cpp b/src/extension/effect.cpp index 3c9940240..c10ad10bd 100644 --- a/src/extension/effect.cpp +++ b/src/extension/effect.cpp @@ -9,16 +9,17 @@ * Released under GNU GPL v2+, read the file 'COPYING' for more information. */ -#include "prefdialog.h" -#include "inkscape.h" -#include "helper/action.h" -#include "ui/view/view.h" - -#include "implementation/implementation.h" #include "effect.h" + #include "execution-env.h" +#include "inkscape.h" #include "timer.h" +#include "helper/action.h" +#include "implementation/implementation.h" +#include "prefdialog/prefdialog.h" +#include "ui/view/view.h" + /* Inkscape::Extension::Effect */ diff --git a/src/extension/execution-env.cpp b/src/extension/execution-env.cpp index ca770e1f6..a2bae3832 100644 --- a/src/extension/execution-env.cpp +++ b/src/extension/execution-env.cpp @@ -13,7 +13,7 @@ #include #include "execution-env.h" -#include "prefdialog.h" +#include "prefdialog/prefdialog.h" #include "implementation/implementation.h" #include "selection.h" diff --git a/src/extension/extension.cpp b/src/extension/extension.cpp index 77a171487..f85be2a70 100644 --- a/src/extension/extension.cpp +++ b/src/extension/extension.cpp @@ -29,7 +29,7 @@ #include "db.h" #include "dependency.h" #include "timer.h" -#include "param/parameter.h" +#include "prefdialog/param/parameter.h" #include "io/resource.h" namespace Inkscape { diff --git a/src/extension/input.cpp b/src/extension/input.cpp index 708324de2..792b794c8 100644 --- a/src/extension/input.cpp +++ b/src/extension/input.cpp @@ -11,7 +11,7 @@ #ifdef HAVE_CONFIG_H #endif -#include "prefdialog.h" +#include "prefdialog/prefdialog.h" #include "implementation/implementation.h" #include "timer.h" #include "input.h" diff --git a/src/extension/output.cpp b/src/extension/output.cpp index c6cf399b8..51d58bc89 100644 --- a/src/extension/output.cpp +++ b/src/extension/output.cpp @@ -9,7 +9,7 @@ * Released under GNU GPL v2+, read the file 'COPYING' for more information. */ -#include "prefdialog.h" +#include "prefdialog/prefdialog.h" #include "document.h" #include "implementation/implementation.h" #include "output.h" diff --git a/src/extension/param/bool.cpp b/src/extension/param/bool.cpp deleted file mode 100644 index 10121f7ab..000000000 --- a/src/extension/param/bool.cpp +++ /dev/null @@ -1,154 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (C) 2005-2007 Authors: - * Ted Gould - * Johan Engelen * - * Jon A. Cruz - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include -#include -#include -#include - -#include "xml/node.h" -#include "../extension.h" -#include "bool.h" -#include "preferences.h" - -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) -{ - const char * defaultval = nullptr; - if (xml->firstChild() != nullptr) { - defaultval = xml->firstChild()->content(); - } - - if (defaultval != nullptr && (!strcmp(defaultval, "true") || !strcmp(defaultval, "1"))) { - _value = true; - } else { - _value = false; - } - - 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(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setBool(extension_pref_root + prefname, _value); - g_free(prefname); - - return _value; -} - -bool ParamBool::get(const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) const -{ - return _value; -} - -/** - * A check button which is Param aware. It works with the - * parameter to change it's value as the check button changes - * value. - */ -class ParamBoolCheckButton : public Gtk::CheckButton { -public: - /** - * Initialize the check button. - * This function sets the value of the checkbox to be that of the - * parameter, and then sets up a callback to \c on_toggle. - * - * @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) : - 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)); - return; - } - - /** - * A function to respond to the check box changing. - * Adjusts the value of the preference to match that in the check box. - */ - void on_toggle (); - -private: - /** Param to change. */ - ParamBool * _pref; - SPDocument * _doc; - Inkscape::XML::Node * _node; - sigc::signal * _changeSignal; -}; - -void ParamBoolCheckButton::on_toggle() -{ - _pref->set(this->get_active(), nullptr /**\todo fix this */, nullptr); - if (_changeSignal != nullptr) { - _changeSignal->emit(); - } - return; -} - -void ParamBool::string(std::string &string) const -{ - if (_value) { - string += "true"; - } else { - string += "false"; - } - - return; -} - -Gtk::Widget *ParamBool::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) -{ - if (_hidden) { - return nullptr; - } - - auto hbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, Parameter::GUI_PARAM_WIDGETS_SPACING)); - hbox->set_homogeneous(false); - - ParamBoolCheckButton * checkbox = Gtk::manage(new ParamBoolCheckButton(this, _text, doc, node, changeSignal)); - checkbox->show(); - hbox->pack_start(*checkbox, false, false); - - 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/extension/param/bool.h b/src/extension/param/bool.h deleted file mode 100644 index 9864cac38..000000000 --- a/src/extension/param/bool.h +++ /dev/null @@ -1,95 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -#ifndef SEEN_INK_EXTENSION_PARAMBOOL_H -#define SEEN_INK_EXTENSION_PARAMBOOL_H -/* - * Copyright (C) 2005-2007 Authors: - * Ted Gould - * Johan Engelen * - * Jon A. Cruz - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include "parameter.h" - -class SPDocument; - -namespace Gtk { -class Widget; -} - -namespace Inkscape { -namespace XML { -class Node; -} - -namespace Extension { - -/** - * A boolean parameter. - */ -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); - - /** - * Returns the current state/value. - */ - bool get(const SPDocument *doc, const Inkscape::XML::Node *node) const; - - /** - * A function to set the state/value. - * This function sets 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. - * - * @param in The value to set to - * @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); - - /** - * 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; - - // Explicitly call superclass version to avoid method being hidden. - void string(std::list &list) const override { return Parameter::string(list); } - - /** - * Appends 'true' or 'false'. - * @todo investigate. Returning a value that can then be appended would probably work better/safer. - */ - void string(std::string &string) const override; - -private: - /** Internal value. */ - bool _value; -}; - -} // namespace Extension -} // namespace Inkscape - -#endif // SEEN_INK_EXTENSION_PARAMBOOL_H - -/* - 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/param/color.cpp b/src/extension/param/color.cpp deleted file mode 100644 index f71670cb2..000000000 --- a/src/extension/param/color.cpp +++ /dev/null @@ -1,119 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (C) 2005-2007 Authors: - * Ted Gould - * Johan Engelen - * Christopher Brown - * Jon A. Cruz - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include -#include - -#include -#include -#include - -#include - -#include "../extension.h" -#include "color.h" - -#include -#include "ui/widget/color-notebook.h" -#include "preferences.h" - -namespace Inkscape { -namespace Extension { - -ParamColor::~ParamColor() -{ - _color_changed.disconnect(); -} - -guint32 ParamColor::set( guint32 in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/ ) -{ - _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(); - - gchar * pref_name = this->pref_name(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring paramval = prefs->getString(extension_pref_root + pref_name); - g_free(pref_name); - - if (!paramval.empty()) - defaulthex = paramval.data(); - - if (defaulthex) { - _color.setValue(atoi(defaulthex)); - } - _color_changed = _color.signal_changed.connect(sigc::mem_fun(this, &ParamColor::_onColorChanged)); - -} - -void ParamColor::string(std::string &string) const -{ - char str[16]; - snprintf(str, 16, "%i", _color.value()); - string += str; -} - -Gtk::Widget *ParamColor::get_widget( SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal * changeSignal ) -{ - using Inkscape::UI::Widget::ColorNotebook; - - if (_hidden) return nullptr; - - if (changeSignal) { - _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() -{ - if (_changeSignal) - _changeSignal->emit(); -} - -}; /* namespace Extension */ -}; /* namespace Inkscape */ diff --git a/src/extension/param/color.h b/src/extension/param/color.h deleted file mode 100644 index c2d3c2ccb..000000000 --- a/src/extension/param/color.h +++ /dev/null @@ -1,74 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -#ifndef SEEN_INK_EXTENSION_PARAMCOLOR_H__ -#define SEEN_INK_EXTENSION_PARAMCOLOR_H__ -/* - * Copyright (C) 2005-2007 Authors: - * Ted Gould - * Johan Engelen * - * Jon A. Cruz - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include "parameter.h" -#include "ui/selected-color.h" - -class SPDocument; - -namespace Gtk { -class Widget; -} - -namespace Inkscape { -namespace XML { -class Node; -} - -namespace Extension { - -class ParamColor : public Parameter { -private: - void _onColorChanged(); - - Inkscape::UI::SelectedColor _color; - sigc::connection _color_changed; -public: - ParamColor(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml); - ~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); - - 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; - -}; // class ParamColor - -} // namespace Extension -} // namespace Inkscape - -#endif // SEEN_INK_EXTENSION_PARAMCOLOR_H__ - -/* - 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/param/description.cpp b/src/extension/param/description.cpp deleted file mode 100644 index 60e2d02c8..000000000 --- a/src/extension/param/description.cpp +++ /dev/null @@ -1,134 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (C) 2005-2007 Authors: - * Ted Gould - * Johan Engelen * - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#ifdef linux // does the dollar sign need escaping when passed as string parameter? -# define ESCAPE_DOLLAR_COMMANDLINE -#endif - -#include -#include -#include -#include -#include - -#include "xml/node.h" -#include "extension/extension.h" -#include "description.h" - -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) -{ - // 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(); - } else if (cur_child->type() == XML::ELEMENT_NODE && !g_strcmp0(cur_child->name(), "extension:br")) { - 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); - } - - // 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()); - } - } - - // 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; -} - -/** \brief Create a label for the description */ -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()); - if (_mode == HEADER) { - label->set_markup(Glib::ustring("") + Glib::Markup::escape_text(newtext) + Glib::ustring("")); - label->set_margin_top(5); - label->set_margin_bottom(5); - } else if (_mode == URL) { - Glib::ustring escaped_url = Glib::Markup::escape_text(newtext); - label->set_markup(Glib::ustring::compose("%1", escaped_url)); - } else { - label->set_text(newtext); - } - label->set_line_wrap(); - label->set_xalign(0); - - // 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 - // - 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 - // 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(); - label->set_width_chars(len > Parameter::GUI_MAX_LINE_LENGTH ? Parameter::GUI_MAX_LINE_LENGTH : len); - - label->show(); - - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox()); - hbox->pack_start(*label, true, true); - hbox->show(); - - return hbox; -} - -} /* namespace Extension */ -} /* namespace Inkscape */ diff --git a/src/extension/param/description.h b/src/extension/param/description.h deleted file mode 100644 index 822370b82..000000000 --- a/src/extension/param/description.h +++ /dev/null @@ -1,63 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -#ifndef __INK_EXTENSION_PARAMDESCRIPTION_H__ -#define __INK_EXTENSION_PARAMDESCRIPTION_H__ - -/* - * Copyright (C) 2005-2007 Authors: - * Ted Gould - * Johan Engelen * - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include "parameter.h" - -class SPDocument; - -namespace Gtk { - class Widget; -} - -namespace Inkscape { -namespace Xml { - class Node; -} - -namespace Extension { - -/** \brief A description parameter */ -class ParamDescription : public Parameter { -public: - enum AppearanceMode { - DESCRIPTION, 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; -private: - /** \brief Internal value. */ - gchar * _value; - AppearanceMode _mode; -}; - -} /* namespace Extension */ -} /* namespace Inkscape */ - -#endif /* __INK_EXTENSION_PARAMDESCRIPTION_H__ */ - -/* - 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/param/enum.cpp b/src/extension/param/enum.cpp deleted file mode 100644 index 5ba3e5772..000000000 --- a/src/extension/param/enum.cpp +++ /dev/null @@ -1,268 +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 -#include -#include - -#include "xml/node.h" -#include "extension/extension.h" -#include "enum.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/param/enum.h b/src/extension/param/enum.h deleted file mode 100644 index 329bb26f9..000000000 --- a/src/extension/param/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/param/float.cpp b/src/extension/param/float.cpp deleted file mode 100644 index 661c533ca..000000000 --- a/src/extension/param/float.cpp +++ /dev/null @@ -1,205 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (C) 2005-2007 Authors: - * Ted Gould - * Johan Engelen * - * Jon A. Cruz - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include -#include -#include -#include "ui/widget/spinbutton.h" -#include "ui/widget/spin-scale.h" - -#include "xml/node.h" -#include "extension/extension.h" -#include "preferences.h" -#include "./float.h" - -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) -{ - const gchar * defaultval = nullptr; - if (xml->firstChild() != nullptr) { - defaultval = xml->firstChild()->content(); - } - if (defaultval != nullptr) { - _value = g_ascii_strtod (defaultval,nullptr); - } - - const char * maxval = xml->attribute("max"); - if (maxval != nullptr) { - _max = g_ascii_strtod (maxval,nullptr); - } - - const char * minval = xml->attribute("min"); - if (minval != nullptr) { - _min = g_ascii_strtod (minval,nullptr); - } - - _precision = 1; - const char * precision = xml->attribute("precision"); - if (precision != nullptr) { - _precision = atoi(precision); - } - - /* We're handling this by just killing both values */ - if (_max < _min) { - _max = 10.0; - _min = 0.0; - } - - 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; - } - - return; -} - -/** - * A function to set the \c _value. - * - * This function sets 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. - * - * @param in The value to set to. - * @param doc A document that should be used to set the value. - * @param node The node where the value may be placed. - */ -float ParamFloat::set(float in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) -{ - _value = in; - if (_value > _max) { - _value = _max; - } - if (_value < _min) { - _value = _min; - } - - gchar * prefname = this->pref_name(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setDouble(extension_pref_root + prefname, _value); - g_free(prefname); - - return _value; -} - -void ParamFloat::string(std::string &string) const -{ - char startstring[G_ASCII_DTOSTR_BUF_SIZE]; - g_ascii_dtostr(startstring, G_ASCII_DTOSTR_BUF_SIZE, _value); - string += startstring; - return; -} - -/** 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; -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) : - 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)); - return; - }; - - void val_changed (); -}; /* class ParamFloatAdjustment */ - -/** - * A function to respond to the value_changed signal from the adjustment. - * - * This function just grabs the value from the adjustment and writes - * it to the parameter. Very simple, but yet beautiful. - */ -void ParamFloatAdjustment::val_changed() -{ - //std::cout << "Value Changed to: " << this->get_value() << std::endl; - _pref->set(this->get_value(), _doc, _node); - if (_changeSignal != nullptr) { - _changeSignal->emit(); - } - return; -} - -/** - * Creates a Float Adjustment for a float parameter. - * - * 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) -{ - if (_hidden) { - return nullptr; - } - - 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); - - if (_mode == FULL) { - - Glib::ustring text; - if (_text != nullptr) - text = _text; - UI::Widget::SpinScale *scale = new UI::Widget::SpinScale(text, fadjust, _precision); - scale->set_size_request(400, -1); - scale->show(); - hbox->pack_start(*scale, true, true); - - } - else if (_mode == MINIMAL) { - - Gtk::Label * label = Gtk::manage(new Gtk::Label(_text, Gtk::ALIGN_START)); - label->show(); - hbox->pack_start(*label, true, true); - - auto spin = Gtk::manage(new Inkscape::UI::Widget::SpinButton(fadjust, 0.1, _precision)); - spin->show(); - hbox->pack_start(*spin, false, false); - } - - hbox->show(); - - return dynamic_cast(hbox); -} - - -} /* namespace Extension */ -} /* namespace Inkscape */ diff --git a/src/extension/param/float.h b/src/extension/param/float.h deleted file mode 100644 index c1d0f0f79..000000000 --- a/src/extension/param/float.h +++ /dev/null @@ -1,83 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -#ifndef INK_EXTENSION_PARAMFLOAT_H_SEEN -#define INK_EXTENSION_PARAMFLOAT_H_SEEN - -/* - * Copyright (C) 2005-2007 Authors: - * Ted Gould - * Johan Engelen * - * Jon A. Cruz - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include "parameter.h" - -class SPDocument; - -namespace Gtk { -class Widget; -} - -namespace Inkscape { -namespace XML { -class Node; -} - -namespace Extension { - -class ParamFloat : public Parameter { -public: - enum AppearanceMode { - FULL, MINIMAL - }; - ParamFloat(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml, - AppearanceMode mode); - - /** 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 max () { return _max; } - - float min () { return _min; } - - float precision () { return _precision; } - - 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; - -private: - /** Internal value. */ - float _value; - AppearanceMode _mode; - float _min; - float _max; - int _precision; -}; - -} /* namespace Extension */ -} /* namespace Inkscape */ - -#endif /* INK_EXTENSION_PARAMFLOAT_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/param/int.cpp b/src/extension/param/int.cpp deleted file mode 100644 index 1c41c0834..000000000 --- a/src/extension/param/int.cpp +++ /dev/null @@ -1,201 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (C) 2005-2007 Authors: - * Ted Gould - * Johan Engelen * - * Jon A. Cruz - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include -#include -#include -#include "ui/widget/spinbutton.h" -#include "ui/widget/spin-scale.h" - -#include "xml/node.h" -#include "extension/extension.h" -#include "preferences.h" -#include "int.h" - -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) -{ - 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; - } - - gchar *pref_name = this->pref_name(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - _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; - - if (_value > _max) { - _value = _max; - } - if (_value < _min) { - _value = _min; - } -} - -/** - * A function to set the \c _value. - * This function sets 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. - * - * @param in The value to set to. - * @param doc A document that should be used to set the value. - * @param node The node where the value may be placed. - */ -int ParamInt::set(int in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) -{ - _value = in; - if (_value > _max) { - _value = _max; - } - if (_value < _min) { - _value = _min; - } - - gchar * prefname = this->pref_name(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setInt(extension_pref_root + prefname, _value); - g_free(prefname); - - return _value; -} - -/** 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; -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) : - 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)); - }; - - void val_changed (); -}; /* class ParamIntAdjustment */ - -/** - * A function to respond to the value_changed signal from the adjustment. - * - * This function just grabs the value from the adjustment and writes - * it to the parameter. Very simple, but yet beautiful. - */ -void ParamIntAdjustment::val_changed() -{ - //std::cout << "Value Changed to: " << this->get_value() << std::endl; - _pref->set((int)this->get_value(), _doc, _node); - if (_changeSignal != nullptr) { - _changeSignal->emit(); - } -} - -/** - * Creates a Int Adjustment for a int parameter. - * - * 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) -{ - if (_hidden) { - return nullptr; - } - - 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); - - if (_mode == FULL) { - - Glib::ustring text; - if (_text != nullptr) - text = _text; - UI::Widget::SpinScale *scale = new UI::Widget::SpinScale(text, fadjust, 0); - scale->set_size_request(400, -1); - scale->show(); - hbox->pack_start(*scale, true, true); - } - else if (_mode == MINIMAL) { - Gtk::Label * label = Gtk::manage(new Gtk::Label(_text, Gtk::ALIGN_START)); - label->show(); - hbox->pack_start(*label, true, true); - - auto spin = Gtk::manage(new Inkscape::UI::Widget::SpinButton(fadjust, 1.0, 0)); - spin->show(); - hbox->pack_start(*spin, false, false); - } - - hbox->show(); - - return dynamic_cast(hbox); -} - -void ParamInt::string(std::string &string) const -{ - char startstring[32]; - sprintf(startstring, "%d", _value); - string += startstring; -} - -} // 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/extension/param/int.h b/src/extension/param/int.h deleted file mode 100644 index fac481267..000000000 --- a/src/extension/param/int.h +++ /dev/null @@ -1,80 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -#ifndef INK_EXTENSION_PARAMINT_H_SEEN -#define INK_EXTENSION_PARAMINT_H_SEEN - -/* - * Copyright (C) 2005-2007 Authors: - * Ted Gould - * Johan Engelen * - * Jon A. Cruz - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include "parameter.h" - -class SPDocument; - -namespace Gtk { -class Widget; -} - -namespace Inkscape { -namespace XML { -class Node; -} - -namespace Extension { - -class ParamInt : public Parameter { -public: - enum AppearanceMode { - FULL, MINIMAL - }; - ParamInt(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml, - AppearanceMode mode); - - /** 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 max () { return _max; } - - int min () { return _min; } - - 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; - -private: - /** Internal value. */ - int _value; - AppearanceMode _mode; - int _min; - int _max; -}; - -} /* namespace Extension */ -} /* namespace Inkscape */ - -#endif /* INK_EXTENSION_PARAMINT_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/param/notebook.cpp b/src/extension/param/notebook.cpp deleted file mode 100644 index 838c09d5b..000000000 --- a/src/extension/param/notebook.cpp +++ /dev/null @@ -1,413 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** \file - * Notebook and NotebookPage parameters for extensions. - */ - -/* - * Authors: - * Johan Engelen - * Jon A. Cruz - * - * Copyright (C) 2006 Author - * - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include -#include -#include -#include - -#include - -#include - -#include -#include "preferences.h" - -#include "notebook.h" - -/** - * The root directory in the preferences database for extension - * related parameters. - */ -#define PREF_DIR "extensions" - -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) -{ - - // Read XML to build page - if (xml != nullptr) { - 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, "param") || !strcmp(chname, "_param")) { - Parameter * param; - param = Parameter::make(child_repr, ext); - if (param != nullptr) parameters.push_back(param); - } - child_repr = child_repr->next(); - } - } -} - -ParamNotebook::ParamNotebookPage::~ParamNotebookPage () -{ - //destroy parameters - for (auto param:parameters) { - delete param; - } -} - -/** 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 */ - } - - /* 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) -{ - if (_hidden) { - return nullptr; - } - - Gtk::VBox * vbox = Gtk::manage(new Gtk::VBox); - vbox->set_border_width(Parameter::GUI_BOX_MARGIN); - 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); - } - } - } - - vbox->show(); - - return dynamic_cast(vbox); -} - -/** Search the parameter's name in the page content. */ -Parameter *ParamNotebook::ParamNotebookPage::get_param(const gchar * name) -{ - if (name == nullptr) { - throw Extension::param_not_exist(); - } - if (this->parameters.empty()) { - // the list of parameters is empty - throw Extension::param_not_exist(); - } - - for (auto param:parameters) { - if (!strcmp(param->name(), name)) { - return param; - } - } - - return nullptr; -} - -/** 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) -{ - // Read XML tree to add pages: - if (xml != nullptr) { - 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); - } - 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(); - } - - gchar * pref_name = this->pref_name(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring paramval = 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 -} - -ParamNotebook::~ParamNotebook () -{ - //destroy pages - for (auto page:pages) { - delete page; - } - g_free(_value); -} - - -/** - * A function to set the \c _value. - * - * This function sets 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 number of the page which value must be 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 *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; - - if (_value != nullptr) g_free(_value); - _value = g_strdup(page->name()); - - gchar * prefname = this->pref_name(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString(extension_pref_root + prefname, _value); - g_free(prefname); - - return _value; -} - -void ParamNotebook::string(std::list &list) const -{ - std::string param_string; - param_string += "--"; - param_string += name(); - param_string += "="; - - param_string += "\""; - param_string += _value; // the name of the current page - param_string += "\""; - list.insert(list.end(), param_string); - - for (auto page:pages) { - page->paramString(list); - } -} - -/** A special category of Gtk::Notebook to handle notebook parameters. */ -class ParamNotebookWdg : public Gtk::Notebook { -private: - 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. - */ - 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)); - }; - void changed_page(Gtk::Widget *page, guint pagenum); - bool activated; -}; - -/** - * Respond to the selected page of notebook changing. - * This function responds to the changing by reporting it to - * ParamNotebook. The change is only reported when the notebook - * is actually visible. This to exclude 'fake' changes when the - * notebookpages are added or removed. - */ -void ParamNotebookWdg::changed_page(Gtk::Widget * /*page*/, guint pagenum) -{ - if (get_visible()) { - _pref->set((int)pagenum, _doc, _node); - } -} - -/** Search the parameter's name in the notebook content. */ -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); - if (subparam) { - return subparam; - } - } - - return nullptr; -} - - -/** - * Creates a Notebook widget for a notebook parameter. - * - * Builds a notebook and puts pages in it. - */ -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? - } - } - - nb->show(); - - if (pagenr >= 0) nb->set_current_page(pagenr); - - return dynamic_cast(nb); -} - - -} // 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/extension/param/notebook.h b/src/extension/param/notebook.h deleted file mode 100644 index dd7154f06..000000000 --- a/src/extension/param/notebook.h +++ /dev/null @@ -1,117 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -#ifndef INK_EXTENSION_PARAMNOTEBOOK_H_SEEN -#define INK_EXTENSION_PARAMNOTEBOOK_H_SEEN - -/** \file - * Notebook parameter for extensions. - */ - -/* - * Author: - * Johan Engelen - * Jon A. Cruz - * - * Copyright (C) 2006 Author - * - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include "parameter.h" - -namespace Gtk { -class Widget; -} - -namespace Inkscape { -namespace Extension { - -class Extension; - - -/** A class to represent a notebookparameter 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; - - /** - * A class to represent the pages of a notebookparameter 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 */ - - 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() 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; - }; /* class ParamNotebookPage */ - - - 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() 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. - * @return A string with the 'value' and all the parameters on all pages as command line arguments. - */ - void string (std::list &list) const override; - - // Explicitly call superclass version to avoid method being hidden. - void string(std::string &string) const override {return Parameter::string(string);} - - - 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); -}; /* class ParamNotebook */ - - - - - -} // namespace Extension -} // namespace Inkscape - -#endif /* INK_EXTENSION_PARAMNOTEBOOK_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/param/parameter.cpp b/src/extension/param/parameter.cpp deleted file mode 100644 index 1a60ef32e..000000000 --- a/src/extension/param/parameter.cpp +++ /dev/null @@ -1,461 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** @file - * Parameters for extensions. - */ -/* Author: - * Ted Gould - * Johan Engelen - * Jon A. Cruz - * - * Copyright (C) 2005-2007 Authors - * - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#ifdef linux // does the dollar sign need escaping when passed as string parameter? -# define ESCAPE_DOLLAR_COMMANDLINE -#endif - -#include -#include - -#include -#include - -#include "bool.h" -#include "color.h" -#include "description.h" -#include "enum.h" -#include "./float.h" -#include "int.h" -#include "notebook.h" -#include "parameter.h" -#include "radiobutton.h" -#include "./string.h" - -#include "extension/extension.h" - -#include "object/sp-defs.h" - -#include "ui/widget/color-notebook.h" - -#include "xml/node.h" - - -namespace Inkscape { -namespace Extension { - -Parameter *Parameter::make(Inkscape::XML::Node *in_repr, Inkscape::Extension::Extension *in_ext) -{ - const char *name = in_repr->attribute("name"); - const char *type = in_repr->attribute("type"); - - // we can't create a parameter without type - if (!type) { - return nullptr; - } - // also require name unless it's a pure UI element that does not store its value - if (!name) { - static std::vector ui_elements = {"description"}; - if (std::find(ui_elements.begin(), ui_elements.end(), type) == ui_elements.end()) { - return nullptr; - } - } - - const char *text = in_repr->attribute("gui-text"); - if (text == nullptr) { - text = in_repr->attribute("_gui-text"); - if (text == nullptr) { - // text = ""; // probably better to require devs to explicitly set an empty gui-text if this is what they want - } else { - const char *context = in_repr->attribute("msgctxt"); - if (context != nullptr) { - text = g_dpgettext2(nullptr, context, text); - } else { - text = _(text); - } - } - } - const char *description = in_repr->attribute("gui-description"); - if (description == nullptr) { - description = in_repr->attribute("_gui-description"); - if (description != nullptr) { - const char *context = in_repr->attribute("msgctxt"); - if (context != nullptr) { - description = g_dpgettext2(nullptr, context, description); - } else { - description = _(description); - } - } - } - bool hidden = false; - { - const char *gui_hide = in_repr->attribute("gui-hidden"); - if (gui_hide != nullptr) { - if (strcmp(gui_hide, "1") == 0 || - strcmp(gui_hide, "true") == 0) { - hidden = true; - } - /* else stays false */ - } - } - int indent = 0; - { - const char *indent_attr = in_repr->attribute("indent"); - if (indent_attr != nullptr) { - if (strcmp(indent_attr, "true") == 0) { - indent = 1; - } else { - indent = atoi(indent_attr); - } - } - } - const gchar* appearance = in_repr->attribute("appearance"); - - Parameter * param = nullptr; - if (!strcmp(type, "boolean")) { - param = new ParamBool(name, text, description, hidden, indent, in_ext, in_repr); - } else if (!strcmp(type, "int")) { - if (appearance && !strcmp(appearance, "full")) { - param = new ParamInt(name, text, description, hidden, indent, in_ext, in_repr, ParamInt::FULL); - } else { - param = new ParamInt(name, text, description, hidden, indent, in_ext, in_repr, ParamInt::MINIMAL); - } - } else if (!strcmp(type, "float")) { - if (appearance && !strcmp(appearance, "full")) { - param = new ParamFloat(name, text, description, hidden, indent, in_ext, in_repr, ParamFloat::FULL); - } else { - param = new ParamFloat(name, text, description, hidden, indent, in_ext, in_repr, ParamFloat::MINIMAL); - } - } else if (!strcmp(type, "string")) { - param = new ParamString(name, text, description, hidden, indent, in_ext, in_repr); - gchar const * max_length = in_repr->attribute("max_length"); - if (max_length != nullptr) { - ParamString * ps = dynamic_cast(param); - ps->setMaxLength(atoi(max_length)); - } - } else if (!strcmp(type, "description")) { - ParamDescription::AppearanceMode appearance_mode = ParamDescription::DESCRIPTION; - if (appearance) { - if (!strcmp(appearance, "header")) { - appearance_mode = ParamDescription::HEADER; - } else if (!strcmp(appearance, "url")) { - appearance_mode = ParamDescription::URL; - } - } - param = new ParamDescription(name, text, description, hidden, indent, in_ext, in_repr, appearance_mode); - } else if (!strcmp(type, "enum")) { - param = new ParamComboBox(name, text, description, hidden, indent, in_ext, in_repr); - } else if (!strcmp(type, "notebook")) { - param = new ParamNotebook(name, text, description, hidden, indent, in_ext, in_repr); - } else if (!strcmp(type, "optiongroup")) { - if (appearance && !strcmp(appearance, "minimal")) { - param = new ParamRadioButton(name, text, description, hidden, indent, in_ext, in_repr, ParamRadioButton::MINIMAL); - } else { - param = new ParamRadioButton(name, text, description, hidden, indent, in_ext, in_repr, ParamRadioButton::FULL); - } - } else if (!strcmp(type, "color")) { - param = new ParamColor(name, text, description, hidden, indent, in_ext, in_repr); - } - - // Note: param could equal NULL - return param; -} - -bool Parameter::get_bool(SPDocument const *doc, Inkscape::XML::Node const *node) const -{ - ParamBool const *boolpntr = dynamic_cast(this); - if (!boolpntr) { - throw Extension::param_not_bool_param(); - } - return boolpntr->get(doc, node); -} - -int Parameter::get_int(SPDocument const *doc, Inkscape::XML::Node const *node) const -{ - ParamInt const *intpntr = dynamic_cast(this); - if (!intpntr) { - throw Extension::param_not_int_param(); - } - return intpntr->get(doc, node); -} - -float Parameter::get_float(SPDocument const *doc, Inkscape::XML::Node const *node) const -{ - ParamFloat const *floatpntr = dynamic_cast(this); - if (!floatpntr) { - throw Extension::param_not_float_param(); - } - return floatpntr->get(doc, node); -} - -gchar const *Parameter::get_string(SPDocument const *doc, Inkscape::XML::Node const *node) const -{ - ParamString const *stringpntr = dynamic_cast(this); - if (!stringpntr) { - throw Extension::param_not_string_param(); - } - return stringpntr->get(doc, node); -} - -gchar const *Parameter::get_enum(SPDocument const *doc, Inkscape::XML::Node const *node) const -{ - ParamComboBox const *param = dynamic_cast(this); - if (!param) { - throw Extension::param_not_enum_param(); - } - return param->get(doc, node); -} - -bool Parameter::get_enum_contains(gchar const * value, SPDocument const *doc, Inkscape::XML::Node const *node) const -{ - ParamComboBox const *param = dynamic_cast(this); - if (!param) { - throw Extension::param_not_enum_param(); - } - return param->contains(value, doc, node); -} - -gchar const *Parameter::get_optiongroup(SPDocument const *doc, Inkscape::XML::Node const * node) const -{ - ParamRadioButton const *param = dynamic_cast(this); - if (!param) { - throw Extension::param_not_optiongroup_param(); - } - return param->get(doc, node); -} - -guint32 Parameter::get_color(const SPDocument* doc, Inkscape::XML::Node const *node) const -{ - ParamColor const *param = dynamic_cast(this); - if (!param) { - throw Extension::param_not_color_param(); - } - return param->get(doc, node); -} - -bool Parameter::set_bool(bool in, SPDocument * doc, Inkscape::XML::Node * node) -{ - ParamBool * boolpntr = dynamic_cast(this); - if (boolpntr == nullptr) - throw Extension::param_not_bool_param(); - return boolpntr->set(in, doc, node); -} - -int Parameter::set_int(int in, SPDocument * doc, Inkscape::XML::Node * node) -{ - ParamInt * intpntr = dynamic_cast(this); - if (intpntr == nullptr) - throw Extension::param_not_int_param(); - return intpntr->set(in, doc, node); -} - -/** Wrapper to cast to the object and use it's function. */ -float -Parameter::set_float (float in, SPDocument * doc, Inkscape::XML::Node * node) -{ - ParamFloat * floatpntr; - floatpntr = dynamic_cast(this); - if (floatpntr == nullptr) - throw Extension::param_not_float_param(); - return floatpntr->set(in, doc, node); -} - -/** Wrapper to cast to the object and use it's function. */ -gchar const * -Parameter::set_string (gchar const * in, SPDocument * doc, Inkscape::XML::Node * node) -{ - ParamString * stringpntr = dynamic_cast(this); - if (stringpntr == nullptr) - throw Extension::param_not_string_param(); - return stringpntr->set(in, doc, node); -} - -gchar const * Parameter::set_optiongroup( gchar const * in, SPDocument * doc, Inkscape::XML::Node * node ) -{ - ParamRadioButton *param = dynamic_cast(this); - if (!param) { - throw Extension::param_not_optiongroup_param(); - } - return param->set(in, doc, node); -} - -gchar const *Parameter::set_enum( gchar const * in, SPDocument * doc, Inkscape::XML::Node * node ) -{ - ParamComboBox *param = dynamic_cast(this); - if (!param) { - throw Extension::param_not_enum_param(); - } - return param->set(in, doc, node); -} - - -/** Wrapper to cast to the object and use it's function. */ -guint32 -Parameter::set_color (guint32 in, SPDocument * doc, Inkscape::XML::Node * node) -{ - ParamColor* param = dynamic_cast(this); - if (param == nullptr) - throw Extension::param_not_color_param(); - return param->set(in, doc, node); -} - - -/** Oop, now that we need a parameter, we need it's name. */ -Parameter::Parameter(gchar const * name, gchar const * text, gchar const * description, bool hidden, int indent, Inkscape::Extension::Extension * ext) : - _description(nullptr), - _text(nullptr), - _hidden(hidden), - _indent(indent), - _extension(ext), - _name(nullptr) -{ - if (name != nullptr) { - _name = g_strdup(name); - } - - if (description != nullptr) { - _description = g_strdup(description); - } - - if (text != nullptr) { - _text = g_strdup(text); - } else { - _text = g_strdup(name); - } - - return; -} - -/** Oop, now that we need a parameter, we need it's name. */ -Parameter::Parameter (gchar const * name, gchar const * text, Inkscape::Extension::Extension * ext) : - _description(nullptr), - _text(nullptr), - _hidden(false), - _indent(0), - _extension(ext), - _name(nullptr) -{ - if (name != nullptr) { - _name = g_strdup(name); - } - if (text != nullptr) { - _text = g_strdup(text); - } else { - _text = g_strdup(name); - } - - return; -} - -Parameter::~Parameter() -{ - g_free(_name); - _name = nullptr; - - g_free(_text); - _text = nullptr; - - g_free(_description); - _description = nullptr; -} - -gchar *Parameter::pref_name() const -{ - return g_strdup_printf("%s.%s", _extension->get_id(), _name); -} - -Inkscape::XML::Node * -Parameter::find_child (Inkscape::XML::Node * adult) -{ - return sp_repr_lookup_child(adult, "name", _name); -} - -Inkscape::XML::Node * -Parameter::new_child (Inkscape::XML::Node * parent) -{ - Inkscape::XML::Node * retval; - retval = parent->document()->createElement("inkscape:extension-param"); - retval->setAttribute("name", _name); - - parent->appendChild(retval); - Inkscape::GC::release(retval); - return retval; -} - -Inkscape::XML::Node *Parameter::document_param_node(SPDocument * doc) -{ - Inkscape::XML::Document *xml_doc = doc->getReprDoc(); - Inkscape::XML::Node * defs = doc->getDefs()->getRepr(); - Inkscape::XML::Node * params = nullptr; - - GQuark const name_quark = g_quark_from_string("inkscape:extension-params"); - - for (Inkscape::XML::Node * child = defs->firstChild(); - child != nullptr; - child = child->next()) { - if ((GQuark)child->code() == name_quark && - !strcmp(child->attribute("extension"), _extension->get_id())) { - params = child; - break; - } - } - - if (params == nullptr) { - params = xml_doc->createElement("inkscape:extension-param"); - params->setAttribute("extension", _extension->get_id()); - defs->appendChild(params); - Inkscape::GC::release(params); - } - - return params; -} - -/** Basically, if there is no widget pass a NULL. */ -Gtk::Widget * -Parameter::get_widget (SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal * /*changeSignal*/) -{ - return nullptr; -} - -/** If I'm not sure which it is, just don't return a value. */ -void Parameter::string(std::string &/*string*/) const -{ - // TODO investigate clearing the target string. -} - -void Parameter::string(std::list &list) const -{ - std::string value; - string(value); - if (!value.empty()) { - std::string final; - final += "--"; - final += name(); - final += "="; - final += value; - - list.insert(list.end(), final); - } -} - -Parameter *Parameter::get_param(gchar const * /*name*/) -{ - return nullptr; -} - -Glib::ustring const extension_pref_root = "/extensions/"; - -} // 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/extension/param/parameter.h b/src/extension/param/parameter.h deleted file mode 100644 index c37d1539a..000000000 --- a/src/extension/param/parameter.h +++ /dev/null @@ -1,219 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** @file - * Parameters for extensions. - */ -/* Authors: - * Ted Gould - * Jon A. Cruz - * - * Copyright (C) 2005-2006 Authors - * - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#ifndef SEEN_INK_EXTENSION_PARAM_H__ -#define SEEN_INK_EXTENSION_PARAM_H__ - -#include - -#include - -class SPDocument; - -namespace Gtk { -class Widget; -} - -namespace Inkscape { -namespace XML { -class Node; -} - -namespace Extension { - -class Extension; - - -/** - * The root directory in the preferences database for extension-related parameters. - * - * The directory path has both a leading and a trailing slash, so that extension_pref_root + pref_name works - * without having to append a separator. - */ -extern Glib::ustring const extension_pref_root; - -/** - * A class to represent the parameter of an extension. - * - * This is really a super class that allows them to abstract all - * the different types of parameters into some that can be passed - * around. There is also a few functions that are used by all the - * different parameters. - */ -class Parameter { - -public: - Parameter(gchar const *name, - gchar const *text, - gchar const *description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext); - - Parameter(gchar const *name, - gchar const *text, - Inkscape::Extension::Extension * ext); - - virtual ~Parameter(); - - /** Wrapper to cast to the object and use its function. */ - bool get_bool(SPDocument const *doc, Inkscape::XML::Node const *node) const; - - /** Wrapper to cast to the object and use it's function. */ - int get_int(SPDocument const *doc, Inkscape::XML::Node const *node) const; - - /** Wrapper to cast to the object and use it's function. */ - float get_float(SPDocument const *doc, Inkscape::XML::Node const *node) const; - - /** Wrapper to cast to the object and use it's function. */ - gchar const *get_string(SPDocument const *doc, Inkscape::XML::Node const *node) const; - - guint32 get_color(SPDocument const *doc, Inkscape::XML::Node const *node) const; - - /** Wrapper to cast to the object and use it's function. */ - gchar const *get_enum(SPDocument const *doc, Inkscape::XML::Node const *node) const; - - /** Wrapper to cast to the object and use it's function. */ - bool get_enum_contains(gchar const * value, SPDocument const *doc, Inkscape::XML::Node const *node) const; - - /** Wrapper to cast to the object and use it's function. */ - gchar const *get_optiongroup(SPDocument const * doc, Inkscape::XML::Node const *node) const; - - /** Wrapper to cast to the object and use it's function. */ - bool set_bool(bool in, SPDocument * doc, Inkscape::XML::Node * node); - - /** Wrapper to cast to the object and use it's function. */ - int set_int(int in, SPDocument * doc, Inkscape::XML::Node * node); - - float set_float(float in, SPDocument * doc, Inkscape::XML::Node * node); - - gchar const *set_optiongroup(gchar const *in, SPDocument * doc, Inkscape::XML::Node *node); - - gchar const *set_enum(gchar const * in, SPDocument * doc, Inkscape::XML::Node *node); - - gchar const *set_string(gchar const * in, SPDocument * doc, Inkscape::XML::Node * node); - - guint32 set_color(guint32 in, SPDocument * doc, Inkscape::XML::Node * node); - - gchar const * name() const {return _name;} - - /** - * This function creates a parameter that can be used later. This - * is typically done in the creation of the extension and defined - * in the XML file describing the extension (it's private so people - * have to use the system) :) - * - * 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 or a type in the XML, then no parameter 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. - * - * @param in_repr The XML describing the parameter. - * @return a pointer to a new Parameter if applicable, null otherwise.. - */ - static Parameter *make(Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * in_ext); - - virtual Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal); - - gchar const * get_tooltip() const { return _description; } - - /** Indicates if the GUI for this parameter is hidden or not */ - bool get_hidden() const { return _hidden; } - - /** Indentation level of the parameter */ - int get_indent() const { return _indent; } - - virtual void string(std::list &list) const; - - /** - * Gets the current value of the parameter in a string form. - * @return A string with the 'value'. - */ - virtual void string(std::string &string) const; - - /** All the code in Notebook::get_param to get the notebook content. */ - virtual Parameter *get_param(gchar const *name); - - - /** Recommended margin of boxes containing multiple Parameters (in px) */ - const static int GUI_BOX_MARGIN = 10; - /** Recommended spacing between multiple Parameters packed into a box (in px) */ - const static int GUI_BOX_SPACING = 4; - /** Recommended spacing between the widgets making up a single Parameter (e.g. label and input) (in px) */ - const static int GUI_PARAM_WIDGETS_SPACING = 4; - /** Recommended indentation width of parameters (in px) */ - const static int GUI_INDENTATION = 12; - /** Recommended maximum line length for wrapping textual parameters (in chars) */ - const static int GUI_MAX_LINE_LENGTH = 60; - - -protected: - /** Parameter text to show as the GUI label. */ - gchar * _text; - - /** Extended description of the parameter (crrently shown as tooltip on hover). */ - gchar * _description; - - /** Whether the parameter is visible. */ - bool _hidden; - - /** Indentation level of the parameter. */ - int _indent; - - - /* **** funcs **** */ - - /** - * Build the name to write the parameter from the extension's ID and the name of this parameter. - */ - gchar *pref_name() const; - - Inkscape::XML::Node * find_child (Inkscape::XML::Node * adult); - - Inkscape::XML::Node * document_param_node (SPDocument * doc); - - Inkscape::XML::Node * new_child (Inkscape::XML::Node * parent); - -private: - /** Which extension is this parameter attached to. */ - Inkscape::Extension::Extension *_extension; - - /** The name of this parameter. */ - gchar *_name; -}; - -} // namespace Extension -} // namespace Inkscape - -#endif // SEEN_INK_EXTENSION_PARAM_H__ - -/* - 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/extension/param/radiobutton.cpp b/src/extension/param/radiobutton.cpp deleted file mode 100644 index 8c1d6a5f7..000000000 --- a/src/extension/param/radiobutton.cpp +++ /dev/null @@ -1,349 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** \file - * extension parameter for radiobuttons. - * - * It uses a Gtk:ComboBoxText widget in the extension UI. - */ - -/* - * 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 -#include -#include -#include - -#include "xml/node.h" -#include "extension/extension.h" -#include "preferences.h" - -#include "radiobutton.h" - -/** - * The root directory in the preferences database for extension - * related parameters. - */ -#define PREF_DIR "extensions" - -namespace Inkscape { -namespace Extension { - -/* 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. */ - -ParamRadioButton::ParamRadioButton(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) -{ - // Read XML tree to add enumeration items: - // printf("Extension Constructor: "); - if (xml != nullptr) { - Inkscape::XML::Node *child_repr = xml->firstChild(); - while (child_repr != nullptr) { - char const * chname = child_repr->name(); - if (!strcmp(chname, INKSCAPE_EXTENSION_NS "option") || !strcmp(chname, INKSCAPE_EXTENSION_NS "_option")) { - Glib::ustring * newtext = nullptr; - Glib::ustring * newvalue = nullptr; - const char * contents = child_repr->firstChild()->content(); - - if (contents != nullptr) { - // don't translate when 'item' but do translate when '_option' - if (!strcmp(chname, INKSCAPE_EXTENSION_NS "_option")) { - if (child_repr->attribute("msgctxt") != nullptr) { - newtext = new Glib::ustring(g_dpgettext2(nullptr, child_repr->attribute("msgctxt"), contents)); - } else { - newtext = new Glib::ustring(_(contents)); - } - } else { - newtext = new Glib::ustring(contents); - } - } else { - continue; - } - - - const char * val = child_repr->attribute("value"); - if (val != nullptr) { - newvalue = new Glib::ustring(val); - } else { - newvalue = new Glib::ustring(contents); - } - - if ( (newtext) && (newvalue) ) { // logical error if this is not true here - choices.push_back(new optionentry(newvalue, newtext)); - } - } - child_repr = child_repr->next(); - } - } - - // Initialize _value with the default value from xml - // for simplicity : default to the contents of the first xml-child - const char * defaultval = nullptr; - if (!choices.empty()) { - defaultval = (static_cast (choices[0]))->value->c_str(); - } - - gchar * pref_name = this->pref_name(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring paramval = 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 - } -} - -ParamRadioButton::~ParamRadioButton () -{ - //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 *ParamRadioButton::set(const gchar * in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) -{ - if (in == nullptr) { - return nullptr; /* Can't have NULL string */ - } - - Glib::ustring * settext = nullptr; - for (auto entr:choices) { - if ( !entr->value->compare(in) ) { - settext = entr->value; - break; // break out of for loop - } - } - if (settext) { - if (_value != nullptr) { - g_free(_value); - } - _value = g_strdup(settext->c_str()); - gchar * prefname = this->pref_name(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString(extension_pref_root + prefname, _value); - g_free(prefname); - } else { - g_warning("Couldn't set ParamRadioButton %s", in); - } - - return _value; -} - -void ParamRadioButton::string(std::string &string) const -{ - string += _value; -} - -/** A special radiobutton class to use in ParamRadioButton. */ -class ParamRadioButtonWdg : public Gtk::RadioButton { -private: - ParamRadioButton * _pref; - SPDocument * _doc; - Inkscape::XML::Node * _node; - sigc::signal * _changeSignal; -public: - /** - * Build a string preference for the given parameter. - * @param pref Where to put the radiobutton's string when it is selected. - */ - ParamRadioButtonWdg ( Gtk::RadioButtonGroup& group, const Glib::ustring& label, - ParamRadioButton * pref, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal ) : - Gtk::RadioButton(group, label), _pref(pref), _doc(doc), _node(node), _changeSignal(changeSignal) { - add_changesignal(); - }; - ParamRadioButtonWdg ( const Glib::ustring& label, - ParamRadioButton * pref, SPDocument * doc, Inkscape::XML::Node * node , sigc::signal * changeSignal) : - Gtk::RadioButton(label), _pref(pref), _doc(doc), _node(node), _changeSignal(changeSignal) { - add_changesignal(); - }; - void add_changesignal() { - this->signal_toggled().connect(sigc::mem_fun(this, &ParamRadioButtonWdg::changed)); - }; - void changed (); -}; - -/** - * Respond to the selected radiobutton changing. - * - * This function responds to the radiobutton selection changing by grabbing the value - * from the text box and putting it in the parameter. - */ -void ParamRadioButtonWdg::changed() -{ - if (this->get_active()) { - Glib::ustring value = _pref->value_from_label(this->get_label()); - _pref->set(value.c_str(), _doc, _node); - } - if (_changeSignal != nullptr) { - _changeSignal->emit(); - } -} - - -class ComboWdg : public Gtk::ComboBoxText { -private: - ParamRadioButton* _base; - SPDocument* _doc; - Inkscape::XML::Node* _node; - sigc::signal * _changeSignal; - -public: - ComboWdg(ParamRadioButton* base, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) : - _base(base), - _doc(doc), - _node(node), - _changeSignal(changeSignal) - { - this->signal_changed().connect(sigc::mem_fun(this, &ComboWdg::changed)); - } - ~ComboWdg() override = default; - void changed (); -}; - -void ComboWdg::changed() -{ - if ( _base ) { - Glib::ustring value = _base->value_from_label(get_active_text()); - _base->set(value.c_str(), _doc, _node); - } - if (_changeSignal != nullptr) { - _changeSignal->emit(); - } -} - -/** - * Returns the value for the options label parameter - */ -Glib::ustring ParamRadioButton::value_from_label(const Glib::ustring label) -{ - Glib::ustring value = ""; - - for ( auto entr:choices) { - if ( !entr->text->compare(label) ) { - value = *(entr->value); - break; - } - } - - return value; - -} - -/** - * Creates a combobox widget for an enumeration parameter. - */ -Gtk::Widget * ParamRadioButton::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) -{ - if (_hidden) { - return nullptr; - } - - auto hbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, Parameter::GUI_PARAM_WIDGETS_SPACING)); - hbox->set_homogeneous(false); - auto vbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0)); - vbox->set_homogeneous(false); - - Gtk::Label * label = Gtk::manage(new Gtk::Label(_text, Gtk::ALIGN_START, Gtk::ALIGN_START)); - label->show(); - hbox->pack_start(*label, false, false); - - Gtk::ComboBoxText* cbt = nullptr; - bool comboSet = false; - if (_mode == MINIMAL) { - cbt = Gtk::manage(new ComboWdg(this, doc, node, changeSignal)); - cbt->show(); - vbox->pack_start(*cbt, false, false); - } - - // add choice strings as radiobuttons - // and select last selected option (_value) - Gtk::RadioButtonGroup group; - for (auto entr:choices) { - Glib::ustring * text = entr->text; - switch ( _mode ) { - case MINIMAL: - { - cbt->append(*text); - if (!entr->value->compare(_value)) { - cbt->set_active_text(*text); - comboSet = true; - } - } - break; - case COMPACT: - case FULL: - { - ParamRadioButtonWdg * radio = Gtk::manage(new ParamRadioButtonWdg(group, *text, this, doc, node, changeSignal)); - radio->show(); - vbox->pack_start(*radio, true, true); - if (!entr->value->compare(_value)) { - radio->set_active(); - } - } - break; - } - } - - if ( (_mode == MINIMAL) && !comboSet) { - cbt->set_active(0); - } - - vbox->show(); - hbox->pack_end(*vbox, false, false); - 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/param/radiobutton.h b/src/extension/param/radiobutton.h deleted file mode 100644 index 48d470a01..000000000 --- a/src/extension/param/radiobutton.h +++ /dev/null @@ -1,107 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -#ifndef INK_EXTENSION_PARAMRADIOBUTTON_H_SEEN -#define INK_EXTENSION_PARAMRADIOBUTTON_H_SEEN - -/** \file - * Radiobutton 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 "parameter.h" - -namespace Gtk { -class Widget; -} - -namespace Inkscape { -namespace Extension { - -class Extension; - - - -// \brief A class to represent a radiobutton parameter of an extension -class ParamRadioButton : public Parameter { -public: - enum AppearanceMode { - FULL, COMPACT, MINIMAL - }; - - ParamRadioButton(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml, - AppearanceMode mode); - ~ParamRadioButton() 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; - - Glib::ustring value_from_label(const Glib::ustring label); - - const gchar *get(const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) const { return _value; } - - const gchar *set(const gchar *in, SPDocument *doc, Inkscape::XML::Node *node); - -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; - AppearanceMode _mode; - - /* 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 optionentry { - public: - optionentry (Glib::ustring * val, Glib::ustring * txt) { - value = val; - text = txt; - } - ~optionentry() { - delete value; - delete text; - } - Glib::ustring * value; - Glib::ustring * text; - }; - - std::vector choices; /**< A table to store the choice strings */ - -}; /* class ParamRadioButton */ - - - - - -} /* namespace Extension */ -} /* namespace Inkscape */ - -#endif /* INK_EXTENSION_PARAMRADIOBUTTON_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:fileencoding=utf-8:textwidth=99 : diff --git a/src/extension/param/string.cpp b/src/extension/param/string.cpp deleted file mode 100644 index c1986cf92..000000000 --- a/src/extension/param/string.cpp +++ /dev/null @@ -1,181 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (C) 2005-2007 Authors: - * Ted Gould - * Johan Engelen * - * Jon A. Cruz - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include -#include -#include - -#include - -#include "xml/node.h" -#include "extension/extension.h" -#include "./string.h" -#include "preferences.h" -#include - -namespace Inkscape { -namespace Extension { - - -/** Free the allocated data. */ -ParamString::~ParamString() -{ - g_free(_value); - _value = nullptr; -} - -/** - * A function to set the \c _value. - * - * This function sets 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 to. - * @param doc A document that should be used to set the value. - * @param node The node where the value may be placed. - */ -const gchar * ParamString::set(const gchar * in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) -{ - if (in == nullptr) { - return nullptr; /* Can't have NULL string */ - } - - if (_value != nullptr) { - g_free(_value); - } - - _value = g_strdup(in); - - gchar * prefname = this->pref_name(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString(extension_pref_root + prefname, _value); - g_free(prefname); - - return _value; -} - -void ParamString::string(std::string &string) const -{ - if (_value) { - string += _value; - } -} - -/** Initialize the object, to do that, copy the data. */ -ParamString::ParamString(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 * defaultval = nullptr; - if (xml->firstChild() != nullptr) { - defaultval = xml->firstChild()->content(); - } - - gchar * pref_name = this->pref_name(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring paramval = prefs->getString(extension_pref_root + pref_name); - g_free(pref_name); - - if (!paramval.empty()) { - defaultval = paramval.data(); - } - if (defaultval != nullptr) { - char const * chname = xml->name(); - if (!strcmp(chname, INKSCAPE_EXTENSION_NS "_param")) { - if (xml->attribute("msgctxt") != nullptr) { - _value = g_strdup(g_dpgettext2(nullptr, xml->attribute("msgctxt"), defaultval)); - } else { - _value = g_strdup(_(defaultval)); - } - } else { - _value = g_strdup(defaultval); - } - } - - _max_length = 0; -} - -/** A special type of Gtk::Entry to handle string parameteres. */ -class ParamStringEntry : public Gtk::Entry { -private: - ParamString * _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. - */ - ParamStringEntry (ParamString * pref, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) : - Gtk::Entry(), _pref(pref), _doc(doc), _node(node), _changeSignal(changeSignal) { - if (_pref->get(nullptr, nullptr) != nullptr) { - this->set_text(Glib::ustring(_pref->get(nullptr, nullptr))); - } - this->set_max_length(_pref->getMaxLength()); //Set the max length - default zero means no maximum - this->signal_changed().connect(sigc::mem_fun(this, &ParamStringEntry::changed_text)); - }; - void changed_text (); -}; - - -/** - * 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 ParamStringEntry::changed_text() -{ - Glib::ustring data = this->get_text(); - _pref->set(data.c_str(), _doc, _node); - if (_changeSignal != nullptr) { - _changeSignal->emit(); - } -} - -/** - * Creates a text box for the string parameter. - * - * Builds a hbox with a label and a text box in it. - */ -Gtk::Widget * ParamString::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); - - ParamStringEntry * textbox = new ParamStringEntry(this, doc, node, changeSignal); - textbox->show(); - hbox->pack_start(*textbox, true, true); - - hbox->show(); - - return dynamic_cast(hbox); -} - -} /* namespace Extension */ -} /* namespace Inkscape */ diff --git a/src/extension/param/string.h b/src/extension/param/string.h deleted file mode 100644 index 7c094d394..000000000 --- a/src/extension/param/string.h +++ /dev/null @@ -1,67 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -#ifndef INK_EXTENSION_PARAMSTRING_H_SEEN -#define INK_EXTENSION_PARAMSTRING_H_SEEN - -/* - * Copyright (C) 2005-2007 Authors: - * Ted Gould - * Johan Engelen * - * Jon A. Cruz - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include "parameter.h" - -namespace Inkscape { -namespace Extension { - -class ParamString : public Parameter { -private: - /** \brief Internal value. This should point to a string that has - been allocated in memory. And should be free'd. */ - gchar * _value; - /** \brief Internal value. This indicates the maximum length of the string. Zero meaning unlimited. - */ - gint _max_length; -public: - ParamString(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml); - ~ParamString() override; - - /** \brief Returns \c _value, with a \i const to protect it. */ - const gchar *get(SPDocument const * /*doc*/, Inkscape::XML::Node const * /*node*/) const { return _value; } - - const gchar * set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node); - - 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; - - void setMaxLength(int maxLength) { _max_length = maxLength; } - int getMaxLength() { return _max_length; } -}; - - -} // namespace Extension -} // namespace Inkscape - -#endif /* INK_EXTENSION_PARAMSTRING_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.cpp b/src/extension/prefdialog.cpp deleted file mode 100644 index de58545fb..000000000 --- a/src/extension/prefdialog.cpp +++ /dev/null @@ -1,276 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Authors: - * Ted Gould - * - * Copyright (C) 2005-2008 Authors - * - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include "prefdialog.h" -#include -#include -#include - -#include "ui/dialog-events.h" -#include "xml/repr.h" - -// Used to get SP_ACTIVE_DESKTOP -#include "inkscape.h" -#include "desktop.h" -#include "document.h" -#include "document-undo.h" - -#include "effect.h" -#include "implementation/implementation.h" - -#include "execution-env.h" -#include "param/parameter.h" - - -namespace Inkscape { -namespace Extension { - - -/** \brief Creates a new preference dialog for extension preferences - \param name Name of the Extension whose dialog this is - \param help The help string for the extension (NULL if none) - \param controls The extension specific widgets in the dialog - - This function initializes the dialog with the name of the extension - in the title. It adds a few buttons and sets up handlers for - them. It also places the passed-in widgets into the dialog. -*/ -PrefDialog::PrefDialog (Glib::ustring name, gchar const * help, Gtk::Widget * controls, Effect * effect) : - Gtk::Dialog(_(name.c_str()), true), - _help(help), - _name(name), - _button_ok(nullptr), - _button_cancel(nullptr), - _button_preview(nullptr), - _param_preview(nullptr), - _effect(effect), - _exEnv(nullptr) -{ - this->set_default_size(0,0); // we want the window to be as small as possible instead of clobbering up space - - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox()); - if (controls == nullptr) { - if (_effect == nullptr) { - std::cout << "AH!!! No controls and no effect!!!" << std::endl; - return; - } - controls = _effect->get_imp()->prefs_effect(_effect, SP_ACTIVE_DESKTOP, &_signal_param_change, nullptr); - _signal_param_change.connect(sigc::mem_fun(this, &PrefDialog::param_change)); - } - - hbox->pack_start(*controls, true, true, 0); - hbox->show(); - - this->get_content_area()->pack_start(*hbox, true, true, 0); - - /* - Gtk::Button * help_button = add_button(Gtk::Stock::HELP, Gtk::RESPONSE_HELP); - if (_help == NULL) - help_button->set_sensitive(false); - */ - _button_cancel = add_button(_effect == nullptr ? _("_Cancel") : _("_Close"), Gtk::RESPONSE_CANCEL); - _button_ok = add_button(_effect == nullptr ? _("_OK") : _("_Apply"), Gtk::RESPONSE_OK); - set_default_response(Gtk::RESPONSE_OK); - _button_ok->grab_focus(); - - if (_effect != nullptr && !_effect->no_live_preview) { - if (_param_preview == nullptr) { - XML::Document * doc = sp_repr_read_mem(live_param_xml, strlen(live_param_xml), nullptr); - if (doc == nullptr) { - std::cout << "Error encountered loading live parameter XML !!!" << std::endl; - return; - } - _param_preview = Parameter::make(doc->root(), _effect); - } - - auto sep = Gtk::manage(new Gtk::Separator()); - sep->show(); - - this->get_content_area()->pack_start(*sep, false, false, Parameter::GUI_BOX_SPACING); - - hbox = Gtk::manage(new Gtk::HBox()); - hbox->set_border_width(Parameter::GUI_BOX_MARGIN); - _button_preview = _param_preview->get_widget(nullptr, nullptr, &_signal_preview); - _button_preview->show(); - hbox->pack_start(*_button_preview, true, true, 0); - hbox->show(); - - this->get_content_area()->pack_start(*hbox, false, false, 0); - - Gtk::Box * hbox = dynamic_cast(_button_preview); - if (hbox != nullptr) { - _checkbox_preview = dynamic_cast(hbox->get_children().front()); - } - - preview_toggle(); - _signal_preview.connect(sigc::mem_fun(this, &PrefDialog::preview_toggle)); - } - - // Set window modality for effects that don't use live preview - if (_effect != nullptr && _effect->no_live_preview) { - set_modal(false); - } - - GtkWidget *dlg = GTK_WIDGET(gobj()); - sp_transientize(dlg); - - return; -} - -PrefDialog::~PrefDialog ( ) -{ - if (_param_preview != nullptr) { - delete _param_preview; - _param_preview = nullptr; - } - - if (_exEnv != nullptr) { - _exEnv->cancel(); - delete _exEnv; - _exEnv = nullptr; - _effect->set_execution_env(_exEnv); - } - - if (_effect != nullptr) { - _effect->set_pref_dialog(nullptr); - } - - return; -} - -#if 0 -/** \brief Runs the dialog - \return The response to the dialog - - This function overrides the run function in the GTKmm dialog - class, but basically it only calls it. This function only - handles the \c Gtk::RESPONSE_HELP return, and in that case it - brings up the help window. All other return values are returned - to the calling function. -*/ -int -PrefDialog::run (void) { - int resp = Gtk::RESPONSE_HELP; - while (resp == Gtk::RESPONSE_HELP) { - resp = Gtk::Dialog::run(); - if (resp == Gtk::RESPONSE_HELP) { - /* - if (_helpDialog == NULL) { - _helpDialog = new HelpDialog(_help); - } - */ - } - } - return resp; -} -#endif - -void -PrefDialog::preview_toggle () { - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - SPDocument *document = SP_ACTIVE_DOCUMENT; - bool modified = document->isModifiedSinceSave(); - if(_param_preview->get_bool(nullptr, nullptr)) { - if (_exEnv == nullptr) { - set_modal(true); - _exEnv = new ExecutionEnv(_effect, SP_ACTIVE_DESKTOP, nullptr, false, false); - _effect->set_execution_env(_exEnv); - _exEnv->run(); - } - } else { - set_modal(false); - if (_exEnv != nullptr) { - _exEnv->cancel(); - _exEnv->undo(); - _exEnv->reselect(); - delete _exEnv; - _exEnv = nullptr; - _effect->set_execution_env(_exEnv); - } - } - document->setModifiedSinceSave(modified); -} - -void -PrefDialog::param_change () { - if (_exEnv != nullptr) { - if (!_effect->loaded()) { - _effect->set_state(Extension::STATE_LOADED); - } - _timersig.disconnect(); - _timersig = Glib::signal_timeout().connect(sigc::mem_fun(this, &PrefDialog::param_timer_expire), - 250, /* ms */ - Glib::PRIORITY_DEFAULT_IDLE); - } - - return; -} - -bool -PrefDialog::param_timer_expire () { - if (_exEnv != nullptr) { - _exEnv->cancel(); - _exEnv->undo(); - _exEnv->reselect(); - _exEnv->run(); - } - - return false; -} - -void -PrefDialog::on_response (int signal) { - if (signal == Gtk::RESPONSE_OK) { - if (_exEnv == nullptr) { - if (_effect != nullptr) { - _effect->effect(SP_ACTIVE_DESKTOP); - } else { - // Shutdown run() - return; - } - } else { - if (_exEnv->wait()) { - _exEnv->commit(); - } else { - _exEnv->undo(); - _exEnv->reselect(); - } - delete _exEnv; - _exEnv = nullptr; - _effect->set_execution_env(_exEnv); - } - } - - if (_param_preview != nullptr) { - _checkbox_preview->set_active(false); - } - - if ((signal == Gtk::RESPONSE_CANCEL || signal == Gtk::RESPONSE_DELETE_EVENT) && _effect != nullptr) { - delete this; - } - return; -} - -#include "internal/clear-n_.h" - -const char * PrefDialog::live_param_xml = "false"; - -}; }; /* namespace Inkscape, Extension */ - -/* - 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.h b/src/extension/prefdialog.h deleted file mode 100644 index 087900fbe..000000000 --- a/src/extension/prefdialog.h +++ /dev/null @@ -1,94 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Authors: - * Ted Gould - * - * Copyright (C) 2005,2007-2008 Authors - * - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#ifndef INKSCAPE_EXTENSION_DIALOG_H__ -#define INKSCAPE_EXTENSION_DIALOG_H__ - -#include -#include -#include - -namespace Gtk { -class CheckButton; -} - -namespace Inkscape { -namespace Extension { -class Effect; -class ExecutionEnv; -class Parameter; - -/** \brief A class to represent the preferences for an extension */ -class PrefDialog : public Gtk::Dialog { - /** \brief Help string if it exists */ - gchar const * _help; - /** \brief Name of the extension */ - Glib::ustring _name; - - /** \brief A pointer to the OK button */ - Gtk::Button * _button_ok; - /** \brief A pointer to the CANCEL button */ - Gtk::Button * _button_cancel; - - /** \brief Button to control live preview */ - Gtk::Widget * _button_preview; - /** \brief Checkbox for the preview */ - Gtk::CheckButton * _checkbox_preview; - - /** \brief Parameter to control live preview */ - Parameter * _param_preview; - - /** \brief XML to define the live effects parameter on the dialog */ - static const char * live_param_xml; - - /** \brief Signal that the user is changing the live effect state */ - sigc::signal _signal_preview; - /** \brief Signal that one of the parameters change */ - sigc::signal _signal_param_change; - - /** \brief If this is the preferences for an effect, the effect - that we're working with. */ - Effect * _effect; - /** \brief If we're executing in preview mode here is the execution - environment for the effect. */ - ExecutionEnv * _exEnv; - - /** \brief The timer used to make it so that parameters don't respond - directly and allows for changes. */ - sigc::connection _timersig; - - void preview_toggle(); - void param_change(); - bool param_timer_expire(); - void on_response (int signal) override; - -public: - PrefDialog (Glib::ustring name, - gchar const * help, - Gtk::Widget * controls = nullptr, - Effect * effect = nullptr); - ~PrefDialog () override; -}; - - -};}; /* namespace Inkscape, Extension */ - -#endif /* INKSCAPE_EXTENSION_DIALOG_H__ */ - -/* - 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/param/bool.cpp b/src/extension/prefdialog/param/bool.cpp new file mode 100644 index 000000000..f304f9aef --- /dev/null +++ b/src/extension/prefdialog/param/bool.cpp @@ -0,0 +1,154 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Jon A. Cruz + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include +#include +#include +#include + +#include "xml/node.h" +#include "extension/extension.h" +#include "bool.h" +#include "preferences.h" + +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) +{ + const char * defaultval = nullptr; + if (xml->firstChild() != nullptr) { + defaultval = xml->firstChild()->content(); + } + + if (defaultval != nullptr && (!strcmp(defaultval, "true") || !strcmp(defaultval, "1"))) { + _value = true; + } else { + _value = false; + } + + 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(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setBool(extension_pref_root + prefname, _value); + g_free(prefname); + + return _value; +} + +bool ParamBool::get(const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) const +{ + return _value; +} + +/** + * A check button which is Param aware. It works with the + * parameter to change it's value as the check button changes + * value. + */ +class ParamBoolCheckButton : public Gtk::CheckButton { +public: + /** + * Initialize the check button. + * This function sets the value of the checkbox to be that of the + * parameter, and then sets up a callback to \c on_toggle. + * + * @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) : + 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)); + return; + } + + /** + * A function to respond to the check box changing. + * Adjusts the value of the preference to match that in the check box. + */ + void on_toggle (); + +private: + /** Param to change. */ + ParamBool * _pref; + SPDocument * _doc; + Inkscape::XML::Node * _node; + sigc::signal * _changeSignal; +}; + +void ParamBoolCheckButton::on_toggle() +{ + _pref->set(this->get_active(), nullptr /**\todo fix this */, nullptr); + if (_changeSignal != nullptr) { + _changeSignal->emit(); + } + return; +} + +void ParamBool::string(std::string &string) const +{ + if (_value) { + string += "true"; + } else { + string += "false"; + } + + return; +} + +Gtk::Widget *ParamBool::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) +{ + if (_hidden) { + return nullptr; + } + + auto hbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, Parameter::GUI_PARAM_WIDGETS_SPACING)); + hbox->set_homogeneous(false); + + ParamBoolCheckButton * checkbox = Gtk::manage(new ParamBoolCheckButton(this, _text, doc, node, changeSignal)); + checkbox->show(); + hbox->pack_start(*checkbox, false, false); + + 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/extension/prefdialog/param/bool.h b/src/extension/prefdialog/param/bool.h new file mode 100644 index 000000000..9864cac38 --- /dev/null +++ b/src/extension/prefdialog/param/bool.h @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef SEEN_INK_EXTENSION_PARAMBOOL_H +#define SEEN_INK_EXTENSION_PARAMBOOL_H +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Jon A. Cruz + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "parameter.h" + +class SPDocument; + +namespace Gtk { +class Widget; +} + +namespace Inkscape { +namespace XML { +class Node; +} + +namespace Extension { + +/** + * A boolean parameter. + */ +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); + + /** + * Returns the current state/value. + */ + bool get(const SPDocument *doc, const Inkscape::XML::Node *node) const; + + /** + * A function to set the state/value. + * This function sets 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. + * + * @param in The value to set to + * @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); + + /** + * 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; + + // Explicitly call superclass version to avoid method being hidden. + void string(std::list &list) const override { return Parameter::string(list); } + + /** + * Appends 'true' or 'false'. + * @todo investigate. Returning a value that can then be appended would probably work better/safer. + */ + void string(std::string &string) const override; + +private: + /** Internal value. */ + bool _value; +}; + +} // namespace Extension +} // namespace Inkscape + +#endif // SEEN_INK_EXTENSION_PARAMBOOL_H + +/* + 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/param/color.cpp b/src/extension/prefdialog/param/color.cpp new file mode 100644 index 000000000..ed9940154 --- /dev/null +++ b/src/extension/prefdialog/param/color.cpp @@ -0,0 +1,119 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen + * Christopher Brown + * Jon A. Cruz + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include +#include + +#include +#include +#include + +#include + +#include "extension/extension.h" +#include "color.h" + +#include +#include "ui/widget/color-notebook.h" +#include "preferences.h" + +namespace Inkscape { +namespace Extension { + +ParamColor::~ParamColor() +{ + _color_changed.disconnect(); +} + +guint32 ParamColor::set( guint32 in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/ ) +{ + _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(); + + gchar * pref_name = this->pref_name(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring paramval = prefs->getString(extension_pref_root + pref_name); + g_free(pref_name); + + if (!paramval.empty()) + defaulthex = paramval.data(); + + if (defaulthex) { + _color.setValue(atoi(defaulthex)); + } + _color_changed = _color.signal_changed.connect(sigc::mem_fun(this, &ParamColor::_onColorChanged)); + +} + +void ParamColor::string(std::string &string) const +{ + char str[16]; + snprintf(str, 16, "%i", _color.value()); + string += str; +} + +Gtk::Widget *ParamColor::get_widget( SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal * changeSignal ) +{ + using Inkscape::UI::Widget::ColorNotebook; + + if (_hidden) return nullptr; + + if (changeSignal) { + _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() +{ + if (_changeSignal) + _changeSignal->emit(); +} + +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/prefdialog/param/color.h b/src/extension/prefdialog/param/color.h new file mode 100644 index 000000000..c2d3c2ccb --- /dev/null +++ b/src/extension/prefdialog/param/color.h @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef SEEN_INK_EXTENSION_PARAMCOLOR_H__ +#define SEEN_INK_EXTENSION_PARAMCOLOR_H__ +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Jon A. Cruz + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "parameter.h" +#include "ui/selected-color.h" + +class SPDocument; + +namespace Gtk { +class Widget; +} + +namespace Inkscape { +namespace XML { +class Node; +} + +namespace Extension { + +class ParamColor : public Parameter { +private: + void _onColorChanged(); + + Inkscape::UI::SelectedColor _color; + sigc::connection _color_changed; +public: + ParamColor(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml); + ~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); + + 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; + +}; // class ParamColor + +} // namespace Extension +} // namespace Inkscape + +#endif // SEEN_INK_EXTENSION_PARAMCOLOR_H__ + +/* + 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/param/description.cpp b/src/extension/prefdialog/param/description.cpp new file mode 100644 index 000000000..60e2d02c8 --- /dev/null +++ b/src/extension/prefdialog/param/description.cpp @@ -0,0 +1,134 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#ifdef linux // does the dollar sign need escaping when passed as string parameter? +# define ESCAPE_DOLLAR_COMMANDLINE +#endif + +#include +#include +#include +#include +#include + +#include "xml/node.h" +#include "extension/extension.h" +#include "description.h" + +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) +{ + // 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(); + } else if (cur_child->type() == XML::ELEMENT_NODE && !g_strcmp0(cur_child->name(), "extension:br")) { + 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); + } + + // 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()); + } + } + + // 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; +} + +/** \brief Create a label for the description */ +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()); + if (_mode == HEADER) { + label->set_markup(Glib::ustring("") + Glib::Markup::escape_text(newtext) + Glib::ustring("")); + label->set_margin_top(5); + label->set_margin_bottom(5); + } else if (_mode == URL) { + Glib::ustring escaped_url = Glib::Markup::escape_text(newtext); + label->set_markup(Glib::ustring::compose("%1", escaped_url)); + } else { + label->set_text(newtext); + } + label->set_line_wrap(); + label->set_xalign(0); + + // 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 + // - 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 + // 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(); + label->set_width_chars(len > Parameter::GUI_MAX_LINE_LENGTH ? Parameter::GUI_MAX_LINE_LENGTH : len); + + label->show(); + + Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox()); + hbox->pack_start(*label, true, true); + hbox->show(); + + return hbox; +} + +} /* namespace Extension */ +} /* namespace Inkscape */ diff --git a/src/extension/prefdialog/param/description.h b/src/extension/prefdialog/param/description.h new file mode 100644 index 000000000..822370b82 --- /dev/null +++ b/src/extension/prefdialog/param/description.h @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef __INK_EXTENSION_PARAMDESCRIPTION_H__ +#define __INK_EXTENSION_PARAMDESCRIPTION_H__ + +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "parameter.h" + +class SPDocument; + +namespace Gtk { + class Widget; +} + +namespace Inkscape { +namespace Xml { + class Node; +} + +namespace Extension { + +/** \brief A description parameter */ +class ParamDescription : public Parameter { +public: + enum AppearanceMode { + DESCRIPTION, 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; +private: + /** \brief Internal value. */ + gchar * _value; + AppearanceMode _mode; +}; + +} /* namespace Extension */ +} /* namespace Inkscape */ + +#endif /* __INK_EXTENSION_PARAMDESCRIPTION_H__ */ + +/* + 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/param/enum.cpp b/src/extension/prefdialog/param/enum.cpp new file mode 100644 index 000000000..5ba3e5772 --- /dev/null +++ b/src/extension/prefdialog/param/enum.cpp @@ -0,0 +1,268 @@ +// 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 +#include +#include + +#include "xml/node.h" +#include "extension/extension.h" +#include "enum.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/param/enum.h b/src/extension/prefdialog/param/enum.h new file mode 100644 index 000000000..329bb26f9 --- /dev/null +++ b/src/extension/prefdialog/param/enum.h @@ -0,0 +1,106 @@ +// 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/param/float.cpp b/src/extension/prefdialog/param/float.cpp new file mode 100644 index 000000000..661c533ca --- /dev/null +++ b/src/extension/prefdialog/param/float.cpp @@ -0,0 +1,205 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Jon A. Cruz + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include +#include +#include +#include "ui/widget/spinbutton.h" +#include "ui/widget/spin-scale.h" + +#include "xml/node.h" +#include "extension/extension.h" +#include "preferences.h" +#include "./float.h" + +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) +{ + const gchar * defaultval = nullptr; + if (xml->firstChild() != nullptr) { + defaultval = xml->firstChild()->content(); + } + if (defaultval != nullptr) { + _value = g_ascii_strtod (defaultval,nullptr); + } + + const char * maxval = xml->attribute("max"); + if (maxval != nullptr) { + _max = g_ascii_strtod (maxval,nullptr); + } + + const char * minval = xml->attribute("min"); + if (minval != nullptr) { + _min = g_ascii_strtod (minval,nullptr); + } + + _precision = 1; + const char * precision = xml->attribute("precision"); + if (precision != nullptr) { + _precision = atoi(precision); + } + + /* We're handling this by just killing both values */ + if (_max < _min) { + _max = 10.0; + _min = 0.0; + } + + 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; + } + + return; +} + +/** + * A function to set the \c _value. + * + * This function sets 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. + * + * @param in The value to set to. + * @param doc A document that should be used to set the value. + * @param node The node where the value may be placed. + */ +float ParamFloat::set(float in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) +{ + _value = in; + if (_value > _max) { + _value = _max; + } + if (_value < _min) { + _value = _min; + } + + gchar * prefname = this->pref_name(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setDouble(extension_pref_root + prefname, _value); + g_free(prefname); + + return _value; +} + +void ParamFloat::string(std::string &string) const +{ + char startstring[G_ASCII_DTOSTR_BUF_SIZE]; + g_ascii_dtostr(startstring, G_ASCII_DTOSTR_BUF_SIZE, _value); + string += startstring; + return; +} + +/** 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; +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) : + 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)); + return; + }; + + void val_changed (); +}; /* class ParamFloatAdjustment */ + +/** + * A function to respond to the value_changed signal from the adjustment. + * + * This function just grabs the value from the adjustment and writes + * it to the parameter. Very simple, but yet beautiful. + */ +void ParamFloatAdjustment::val_changed() +{ + //std::cout << "Value Changed to: " << this->get_value() << std::endl; + _pref->set(this->get_value(), _doc, _node); + if (_changeSignal != nullptr) { + _changeSignal->emit(); + } + return; +} + +/** + * Creates a Float Adjustment for a float parameter. + * + * 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) +{ + if (_hidden) { + return nullptr; + } + + 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); + + if (_mode == FULL) { + + Glib::ustring text; + if (_text != nullptr) + text = _text; + UI::Widget::SpinScale *scale = new UI::Widget::SpinScale(text, fadjust, _precision); + scale->set_size_request(400, -1); + scale->show(); + hbox->pack_start(*scale, true, true); + + } + else if (_mode == MINIMAL) { + + Gtk::Label * label = Gtk::manage(new Gtk::Label(_text, Gtk::ALIGN_START)); + label->show(); + hbox->pack_start(*label, true, true); + + auto spin = Gtk::manage(new Inkscape::UI::Widget::SpinButton(fadjust, 0.1, _precision)); + spin->show(); + hbox->pack_start(*spin, false, false); + } + + hbox->show(); + + return dynamic_cast(hbox); +} + + +} /* namespace Extension */ +} /* namespace Inkscape */ diff --git a/src/extension/prefdialog/param/float.h b/src/extension/prefdialog/param/float.h new file mode 100644 index 000000000..c1d0f0f79 --- /dev/null +++ b/src/extension/prefdialog/param/float.h @@ -0,0 +1,83 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef INK_EXTENSION_PARAMFLOAT_H_SEEN +#define INK_EXTENSION_PARAMFLOAT_H_SEEN + +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Jon A. Cruz + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "parameter.h" + +class SPDocument; + +namespace Gtk { +class Widget; +} + +namespace Inkscape { +namespace XML { +class Node; +} + +namespace Extension { + +class ParamFloat : public Parameter { +public: + enum AppearanceMode { + FULL, MINIMAL + }; + ParamFloat(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml, + AppearanceMode mode); + + /** 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 max () { return _max; } + + float min () { return _min; } + + float precision () { return _precision; } + + 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; + +private: + /** Internal value. */ + float _value; + AppearanceMode _mode; + float _min; + float _max; + int _precision; +}; + +} /* namespace Extension */ +} /* namespace Inkscape */ + +#endif /* INK_EXTENSION_PARAMFLOAT_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/param/int.cpp b/src/extension/prefdialog/param/int.cpp new file mode 100644 index 000000000..1c41c0834 --- /dev/null +++ b/src/extension/prefdialog/param/int.cpp @@ -0,0 +1,201 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Jon A. Cruz + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include +#include +#include +#include "ui/widget/spinbutton.h" +#include "ui/widget/spin-scale.h" + +#include "xml/node.h" +#include "extension/extension.h" +#include "preferences.h" +#include "int.h" + +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) +{ + 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; + } + + gchar *pref_name = this->pref_name(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + _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; + + if (_value > _max) { + _value = _max; + } + if (_value < _min) { + _value = _min; + } +} + +/** + * A function to set the \c _value. + * This function sets 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. + * + * @param in The value to set to. + * @param doc A document that should be used to set the value. + * @param node The node where the value may be placed. + */ +int ParamInt::set(int in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) +{ + _value = in; + if (_value > _max) { + _value = _max; + } + if (_value < _min) { + _value = _min; + } + + gchar * prefname = this->pref_name(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setInt(extension_pref_root + prefname, _value); + g_free(prefname); + + return _value; +} + +/** 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; +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) : + 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)); + }; + + void val_changed (); +}; /* class ParamIntAdjustment */ + +/** + * A function to respond to the value_changed signal from the adjustment. + * + * This function just grabs the value from the adjustment and writes + * it to the parameter. Very simple, but yet beautiful. + */ +void ParamIntAdjustment::val_changed() +{ + //std::cout << "Value Changed to: " << this->get_value() << std::endl; + _pref->set((int)this->get_value(), _doc, _node); + if (_changeSignal != nullptr) { + _changeSignal->emit(); + } +} + +/** + * Creates a Int Adjustment for a int parameter. + * + * 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) +{ + if (_hidden) { + return nullptr; + } + + 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); + + if (_mode == FULL) { + + Glib::ustring text; + if (_text != nullptr) + text = _text; + UI::Widget::SpinScale *scale = new UI::Widget::SpinScale(text, fadjust, 0); + scale->set_size_request(400, -1); + scale->show(); + hbox->pack_start(*scale, true, true); + } + else if (_mode == MINIMAL) { + Gtk::Label * label = Gtk::manage(new Gtk::Label(_text, Gtk::ALIGN_START)); + label->show(); + hbox->pack_start(*label, true, true); + + auto spin = Gtk::manage(new Inkscape::UI::Widget::SpinButton(fadjust, 1.0, 0)); + spin->show(); + hbox->pack_start(*spin, false, false); + } + + hbox->show(); + + return dynamic_cast(hbox); +} + +void ParamInt::string(std::string &string) const +{ + char startstring[32]; + sprintf(startstring, "%d", _value); + string += startstring; +} + +} // 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/extension/prefdialog/param/int.h b/src/extension/prefdialog/param/int.h new file mode 100644 index 000000000..fac481267 --- /dev/null +++ b/src/extension/prefdialog/param/int.h @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef INK_EXTENSION_PARAMINT_H_SEEN +#define INK_EXTENSION_PARAMINT_H_SEEN + +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Jon A. Cruz + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "parameter.h" + +class SPDocument; + +namespace Gtk { +class Widget; +} + +namespace Inkscape { +namespace XML { +class Node; +} + +namespace Extension { + +class ParamInt : public Parameter { +public: + enum AppearanceMode { + FULL, MINIMAL + }; + ParamInt(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml, + AppearanceMode mode); + + /** 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 max () { return _max; } + + int min () { return _min; } + + 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; + +private: + /** Internal value. */ + int _value; + AppearanceMode _mode; + int _min; + int _max; +}; + +} /* namespace Extension */ +} /* namespace Inkscape */ + +#endif /* INK_EXTENSION_PARAMINT_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/param/notebook.cpp b/src/extension/prefdialog/param/notebook.cpp new file mode 100644 index 000000000..838c09d5b --- /dev/null +++ b/src/extension/prefdialog/param/notebook.cpp @@ -0,0 +1,413 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** \file + * Notebook and NotebookPage parameters for extensions. + */ + +/* + * Authors: + * Johan Engelen + * Jon A. Cruz + * + * Copyright (C) 2006 Author + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include +#include +#include +#include + +#include + +#include + +#include +#include "preferences.h" + +#include "notebook.h" + +/** + * The root directory in the preferences database for extension + * related parameters. + */ +#define PREF_DIR "extensions" + +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) +{ + + // Read XML to build page + if (xml != nullptr) { + 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, "param") || !strcmp(chname, "_param")) { + Parameter * param; + param = Parameter::make(child_repr, ext); + if (param != nullptr) parameters.push_back(param); + } + child_repr = child_repr->next(); + } + } +} + +ParamNotebook::ParamNotebookPage::~ParamNotebookPage () +{ + //destroy parameters + for (auto param:parameters) { + delete param; + } +} + +/** 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 */ + } + + /* 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) +{ + if (_hidden) { + return nullptr; + } + + Gtk::VBox * vbox = Gtk::manage(new Gtk::VBox); + vbox->set_border_width(Parameter::GUI_BOX_MARGIN); + 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); + } + } + } + + vbox->show(); + + return dynamic_cast(vbox); +} + +/** Search the parameter's name in the page content. */ +Parameter *ParamNotebook::ParamNotebookPage::get_param(const gchar * name) +{ + if (name == nullptr) { + throw Extension::param_not_exist(); + } + if (this->parameters.empty()) { + // the list of parameters is empty + throw Extension::param_not_exist(); + } + + for (auto param:parameters) { + if (!strcmp(param->name(), name)) { + return param; + } + } + + return nullptr; +} + +/** 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) +{ + // Read XML tree to add pages: + if (xml != nullptr) { + 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); + } + 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(); + } + + gchar * pref_name = this->pref_name(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring paramval = 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 +} + +ParamNotebook::~ParamNotebook () +{ + //destroy pages + for (auto page:pages) { + delete page; + } + g_free(_value); +} + + +/** + * A function to set the \c _value. + * + * This function sets 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 number of the page which value must be 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 *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; + + if (_value != nullptr) g_free(_value); + _value = g_strdup(page->name()); + + gchar * prefname = this->pref_name(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setString(extension_pref_root + prefname, _value); + g_free(prefname); + + return _value; +} + +void ParamNotebook::string(std::list &list) const +{ + std::string param_string; + param_string += "--"; + param_string += name(); + param_string += "="; + + param_string += "\""; + param_string += _value; // the name of the current page + param_string += "\""; + list.insert(list.end(), param_string); + + for (auto page:pages) { + page->paramString(list); + } +} + +/** A special category of Gtk::Notebook to handle notebook parameters. */ +class ParamNotebookWdg : public Gtk::Notebook { +private: + 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. + */ + 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)); + }; + void changed_page(Gtk::Widget *page, guint pagenum); + bool activated; +}; + +/** + * Respond to the selected page of notebook changing. + * This function responds to the changing by reporting it to + * ParamNotebook. The change is only reported when the notebook + * is actually visible. This to exclude 'fake' changes when the + * notebookpages are added or removed. + */ +void ParamNotebookWdg::changed_page(Gtk::Widget * /*page*/, guint pagenum) +{ + if (get_visible()) { + _pref->set((int)pagenum, _doc, _node); + } +} + +/** Search the parameter's name in the notebook content. */ +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); + if (subparam) { + return subparam; + } + } + + return nullptr; +} + + +/** + * Creates a Notebook widget for a notebook parameter. + * + * Builds a notebook and puts pages in it. + */ +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? + } + } + + nb->show(); + + if (pagenr >= 0) nb->set_current_page(pagenr); + + return dynamic_cast(nb); +} + + +} // 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/extension/prefdialog/param/notebook.h b/src/extension/prefdialog/param/notebook.h new file mode 100644 index 000000000..dd7154f06 --- /dev/null +++ b/src/extension/prefdialog/param/notebook.h @@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef INK_EXTENSION_PARAMNOTEBOOK_H_SEEN +#define INK_EXTENSION_PARAMNOTEBOOK_H_SEEN + +/** \file + * Notebook parameter for extensions. + */ + +/* + * Author: + * Johan Engelen + * Jon A. Cruz + * + * Copyright (C) 2006 Author + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "parameter.h" + +namespace Gtk { +class Widget; +} + +namespace Inkscape { +namespace Extension { + +class Extension; + + +/** A class to represent a notebookparameter 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; + + /** + * A class to represent the pages of a notebookparameter 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 */ + + 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() 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; + }; /* class ParamNotebookPage */ + + + 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() 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. + * @return A string with the 'value' and all the parameters on all pages as command line arguments. + */ + void string (std::list &list) const override; + + // Explicitly call superclass version to avoid method being hidden. + void string(std::string &string) const override {return Parameter::string(string);} + + + 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); +}; /* class ParamNotebook */ + + + + + +} // namespace Extension +} // namespace Inkscape + +#endif /* INK_EXTENSION_PARAMNOTEBOOK_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/param/parameter.cpp b/src/extension/prefdialog/param/parameter.cpp new file mode 100644 index 000000000..1a60ef32e --- /dev/null +++ b/src/extension/prefdialog/param/parameter.cpp @@ -0,0 +1,461 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** @file + * Parameters for extensions. + */ +/* Author: + * Ted Gould + * Johan Engelen + * Jon A. Cruz + * + * Copyright (C) 2005-2007 Authors + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#ifdef linux // does the dollar sign need escaping when passed as string parameter? +# define ESCAPE_DOLLAR_COMMANDLINE +#endif + +#include +#include + +#include +#include + +#include "bool.h" +#include "color.h" +#include "description.h" +#include "enum.h" +#include "./float.h" +#include "int.h" +#include "notebook.h" +#include "parameter.h" +#include "radiobutton.h" +#include "./string.h" + +#include "extension/extension.h" + +#include "object/sp-defs.h" + +#include "ui/widget/color-notebook.h" + +#include "xml/node.h" + + +namespace Inkscape { +namespace Extension { + +Parameter *Parameter::make(Inkscape::XML::Node *in_repr, Inkscape::Extension::Extension *in_ext) +{ + const char *name = in_repr->attribute("name"); + const char *type = in_repr->attribute("type"); + + // we can't create a parameter without type + if (!type) { + return nullptr; + } + // also require name unless it's a pure UI element that does not store its value + if (!name) { + static std::vector ui_elements = {"description"}; + if (std::find(ui_elements.begin(), ui_elements.end(), type) == ui_elements.end()) { + return nullptr; + } + } + + const char *text = in_repr->attribute("gui-text"); + if (text == nullptr) { + text = in_repr->attribute("_gui-text"); + if (text == nullptr) { + // text = ""; // probably better to require devs to explicitly set an empty gui-text if this is what they want + } else { + const char *context = in_repr->attribute("msgctxt"); + if (context != nullptr) { + text = g_dpgettext2(nullptr, context, text); + } else { + text = _(text); + } + } + } + const char *description = in_repr->attribute("gui-description"); + if (description == nullptr) { + description = in_repr->attribute("_gui-description"); + if (description != nullptr) { + const char *context = in_repr->attribute("msgctxt"); + if (context != nullptr) { + description = g_dpgettext2(nullptr, context, description); + } else { + description = _(description); + } + } + } + bool hidden = false; + { + const char *gui_hide = in_repr->attribute("gui-hidden"); + if (gui_hide != nullptr) { + if (strcmp(gui_hide, "1") == 0 || + strcmp(gui_hide, "true") == 0) { + hidden = true; + } + /* else stays false */ + } + } + int indent = 0; + { + const char *indent_attr = in_repr->attribute("indent"); + if (indent_attr != nullptr) { + if (strcmp(indent_attr, "true") == 0) { + indent = 1; + } else { + indent = atoi(indent_attr); + } + } + } + const gchar* appearance = in_repr->attribute("appearance"); + + Parameter * param = nullptr; + if (!strcmp(type, "boolean")) { + param = new ParamBool(name, text, description, hidden, indent, in_ext, in_repr); + } else if (!strcmp(type, "int")) { + if (appearance && !strcmp(appearance, "full")) { + param = new ParamInt(name, text, description, hidden, indent, in_ext, in_repr, ParamInt::FULL); + } else { + param = new ParamInt(name, text, description, hidden, indent, in_ext, in_repr, ParamInt::MINIMAL); + } + } else if (!strcmp(type, "float")) { + if (appearance && !strcmp(appearance, "full")) { + param = new ParamFloat(name, text, description, hidden, indent, in_ext, in_repr, ParamFloat::FULL); + } else { + param = new ParamFloat(name, text, description, hidden, indent, in_ext, in_repr, ParamFloat::MINIMAL); + } + } else if (!strcmp(type, "string")) { + param = new ParamString(name, text, description, hidden, indent, in_ext, in_repr); + gchar const * max_length = in_repr->attribute("max_length"); + if (max_length != nullptr) { + ParamString * ps = dynamic_cast(param); + ps->setMaxLength(atoi(max_length)); + } + } else if (!strcmp(type, "description")) { + ParamDescription::AppearanceMode appearance_mode = ParamDescription::DESCRIPTION; + if (appearance) { + if (!strcmp(appearance, "header")) { + appearance_mode = ParamDescription::HEADER; + } else if (!strcmp(appearance, "url")) { + appearance_mode = ParamDescription::URL; + } + } + param = new ParamDescription(name, text, description, hidden, indent, in_ext, in_repr, appearance_mode); + } else if (!strcmp(type, "enum")) { + param = new ParamComboBox(name, text, description, hidden, indent, in_ext, in_repr); + } else if (!strcmp(type, "notebook")) { + param = new ParamNotebook(name, text, description, hidden, indent, in_ext, in_repr); + } else if (!strcmp(type, "optiongroup")) { + if (appearance && !strcmp(appearance, "minimal")) { + param = new ParamRadioButton(name, text, description, hidden, indent, in_ext, in_repr, ParamRadioButton::MINIMAL); + } else { + param = new ParamRadioButton(name, text, description, hidden, indent, in_ext, in_repr, ParamRadioButton::FULL); + } + } else if (!strcmp(type, "color")) { + param = new ParamColor(name, text, description, hidden, indent, in_ext, in_repr); + } + + // Note: param could equal NULL + return param; +} + +bool Parameter::get_bool(SPDocument const *doc, Inkscape::XML::Node const *node) const +{ + ParamBool const *boolpntr = dynamic_cast(this); + if (!boolpntr) { + throw Extension::param_not_bool_param(); + } + return boolpntr->get(doc, node); +} + +int Parameter::get_int(SPDocument const *doc, Inkscape::XML::Node const *node) const +{ + ParamInt const *intpntr = dynamic_cast(this); + if (!intpntr) { + throw Extension::param_not_int_param(); + } + return intpntr->get(doc, node); +} + +float Parameter::get_float(SPDocument const *doc, Inkscape::XML::Node const *node) const +{ + ParamFloat const *floatpntr = dynamic_cast(this); + if (!floatpntr) { + throw Extension::param_not_float_param(); + } + return floatpntr->get(doc, node); +} + +gchar const *Parameter::get_string(SPDocument const *doc, Inkscape::XML::Node const *node) const +{ + ParamString const *stringpntr = dynamic_cast(this); + if (!stringpntr) { + throw Extension::param_not_string_param(); + } + return stringpntr->get(doc, node); +} + +gchar const *Parameter::get_enum(SPDocument const *doc, Inkscape::XML::Node const *node) const +{ + ParamComboBox const *param = dynamic_cast(this); + if (!param) { + throw Extension::param_not_enum_param(); + } + return param->get(doc, node); +} + +bool Parameter::get_enum_contains(gchar const * value, SPDocument const *doc, Inkscape::XML::Node const *node) const +{ + ParamComboBox const *param = dynamic_cast(this); + if (!param) { + throw Extension::param_not_enum_param(); + } + return param->contains(value, doc, node); +} + +gchar const *Parameter::get_optiongroup(SPDocument const *doc, Inkscape::XML::Node const * node) const +{ + ParamRadioButton const *param = dynamic_cast(this); + if (!param) { + throw Extension::param_not_optiongroup_param(); + } + return param->get(doc, node); +} + +guint32 Parameter::get_color(const SPDocument* doc, Inkscape::XML::Node const *node) const +{ + ParamColor const *param = dynamic_cast(this); + if (!param) { + throw Extension::param_not_color_param(); + } + return param->get(doc, node); +} + +bool Parameter::set_bool(bool in, SPDocument * doc, Inkscape::XML::Node * node) +{ + ParamBool * boolpntr = dynamic_cast(this); + if (boolpntr == nullptr) + throw Extension::param_not_bool_param(); + return boolpntr->set(in, doc, node); +} + +int Parameter::set_int(int in, SPDocument * doc, Inkscape::XML::Node * node) +{ + ParamInt * intpntr = dynamic_cast(this); + if (intpntr == nullptr) + throw Extension::param_not_int_param(); + return intpntr->set(in, doc, node); +} + +/** Wrapper to cast to the object and use it's function. */ +float +Parameter::set_float (float in, SPDocument * doc, Inkscape::XML::Node * node) +{ + ParamFloat * floatpntr; + floatpntr = dynamic_cast(this); + if (floatpntr == nullptr) + throw Extension::param_not_float_param(); + return floatpntr->set(in, doc, node); +} + +/** Wrapper to cast to the object and use it's function. */ +gchar const * +Parameter::set_string (gchar const * in, SPDocument * doc, Inkscape::XML::Node * node) +{ + ParamString * stringpntr = dynamic_cast(this); + if (stringpntr == nullptr) + throw Extension::param_not_string_param(); + return stringpntr->set(in, doc, node); +} + +gchar const * Parameter::set_optiongroup( gchar const * in, SPDocument * doc, Inkscape::XML::Node * node ) +{ + ParamRadioButton *param = dynamic_cast(this); + if (!param) { + throw Extension::param_not_optiongroup_param(); + } + return param->set(in, doc, node); +} + +gchar const *Parameter::set_enum( gchar const * in, SPDocument * doc, Inkscape::XML::Node * node ) +{ + ParamComboBox *param = dynamic_cast(this); + if (!param) { + throw Extension::param_not_enum_param(); + } + return param->set(in, doc, node); +} + + +/** Wrapper to cast to the object and use it's function. */ +guint32 +Parameter::set_color (guint32 in, SPDocument * doc, Inkscape::XML::Node * node) +{ + ParamColor* param = dynamic_cast(this); + if (param == nullptr) + throw Extension::param_not_color_param(); + return param->set(in, doc, node); +} + + +/** Oop, now that we need a parameter, we need it's name. */ +Parameter::Parameter(gchar const * name, gchar const * text, gchar const * description, bool hidden, int indent, Inkscape::Extension::Extension * ext) : + _description(nullptr), + _text(nullptr), + _hidden(hidden), + _indent(indent), + _extension(ext), + _name(nullptr) +{ + if (name != nullptr) { + _name = g_strdup(name); + } + + if (description != nullptr) { + _description = g_strdup(description); + } + + if (text != nullptr) { + _text = g_strdup(text); + } else { + _text = g_strdup(name); + } + + return; +} + +/** Oop, now that we need a parameter, we need it's name. */ +Parameter::Parameter (gchar const * name, gchar const * text, Inkscape::Extension::Extension * ext) : + _description(nullptr), + _text(nullptr), + _hidden(false), + _indent(0), + _extension(ext), + _name(nullptr) +{ + if (name != nullptr) { + _name = g_strdup(name); + } + if (text != nullptr) { + _text = g_strdup(text); + } else { + _text = g_strdup(name); + } + + return; +} + +Parameter::~Parameter() +{ + g_free(_name); + _name = nullptr; + + g_free(_text); + _text = nullptr; + + g_free(_description); + _description = nullptr; +} + +gchar *Parameter::pref_name() const +{ + return g_strdup_printf("%s.%s", _extension->get_id(), _name); +} + +Inkscape::XML::Node * +Parameter::find_child (Inkscape::XML::Node * adult) +{ + return sp_repr_lookup_child(adult, "name", _name); +} + +Inkscape::XML::Node * +Parameter::new_child (Inkscape::XML::Node * parent) +{ + Inkscape::XML::Node * retval; + retval = parent->document()->createElement("inkscape:extension-param"); + retval->setAttribute("name", _name); + + parent->appendChild(retval); + Inkscape::GC::release(retval); + return retval; +} + +Inkscape::XML::Node *Parameter::document_param_node(SPDocument * doc) +{ + Inkscape::XML::Document *xml_doc = doc->getReprDoc(); + Inkscape::XML::Node * defs = doc->getDefs()->getRepr(); + Inkscape::XML::Node * params = nullptr; + + GQuark const name_quark = g_quark_from_string("inkscape:extension-params"); + + for (Inkscape::XML::Node * child = defs->firstChild(); + child != nullptr; + child = child->next()) { + if ((GQuark)child->code() == name_quark && + !strcmp(child->attribute("extension"), _extension->get_id())) { + params = child; + break; + } + } + + if (params == nullptr) { + params = xml_doc->createElement("inkscape:extension-param"); + params->setAttribute("extension", _extension->get_id()); + defs->appendChild(params); + Inkscape::GC::release(params); + } + + return params; +} + +/** Basically, if there is no widget pass a NULL. */ +Gtk::Widget * +Parameter::get_widget (SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal * /*changeSignal*/) +{ + return nullptr; +} + +/** If I'm not sure which it is, just don't return a value. */ +void Parameter::string(std::string &/*string*/) const +{ + // TODO investigate clearing the target string. +} + +void Parameter::string(std::list &list) const +{ + std::string value; + string(value); + if (!value.empty()) { + std::string final; + final += "--"; + final += name(); + final += "="; + final += value; + + list.insert(list.end(), final); + } +} + +Parameter *Parameter::get_param(gchar const * /*name*/) +{ + return nullptr; +} + +Glib::ustring const extension_pref_root = "/extensions/"; + +} // 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/extension/prefdialog/param/parameter.h b/src/extension/prefdialog/param/parameter.h new file mode 100644 index 000000000..c37d1539a --- /dev/null +++ b/src/extension/prefdialog/param/parameter.h @@ -0,0 +1,219 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** @file + * Parameters for extensions. + */ +/* Authors: + * Ted Gould + * Jon A. Cruz + * + * Copyright (C) 2005-2006 Authors + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#ifndef SEEN_INK_EXTENSION_PARAM_H__ +#define SEEN_INK_EXTENSION_PARAM_H__ + +#include + +#include + +class SPDocument; + +namespace Gtk { +class Widget; +} + +namespace Inkscape { +namespace XML { +class Node; +} + +namespace Extension { + +class Extension; + + +/** + * The root directory in the preferences database for extension-related parameters. + * + * The directory path has both a leading and a trailing slash, so that extension_pref_root + pref_name works + * without having to append a separator. + */ +extern Glib::ustring const extension_pref_root; + +/** + * A class to represent the parameter of an extension. + * + * This is really a super class that allows them to abstract all + * the different types of parameters into some that can be passed + * around. There is also a few functions that are used by all the + * different parameters. + */ +class Parameter { + +public: + Parameter(gchar const *name, + gchar const *text, + gchar const *description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext); + + Parameter(gchar const *name, + gchar const *text, + Inkscape::Extension::Extension * ext); + + virtual ~Parameter(); + + /** Wrapper to cast to the object and use its function. */ + bool get_bool(SPDocument const *doc, Inkscape::XML::Node const *node) const; + + /** Wrapper to cast to the object and use it's function. */ + int get_int(SPDocument const *doc, Inkscape::XML::Node const *node) const; + + /** Wrapper to cast to the object and use it's function. */ + float get_float(SPDocument const *doc, Inkscape::XML::Node const *node) const; + + /** Wrapper to cast to the object and use it's function. */ + gchar const *get_string(SPDocument const *doc, Inkscape::XML::Node const *node) const; + + guint32 get_color(SPDocument const *doc, Inkscape::XML::Node const *node) const; + + /** Wrapper to cast to the object and use it's function. */ + gchar const *get_enum(SPDocument const *doc, Inkscape::XML::Node const *node) const; + + /** Wrapper to cast to the object and use it's function. */ + bool get_enum_contains(gchar const * value, SPDocument const *doc, Inkscape::XML::Node const *node) const; + + /** Wrapper to cast to the object and use it's function. */ + gchar const *get_optiongroup(SPDocument const * doc, Inkscape::XML::Node const *node) const; + + /** Wrapper to cast to the object and use it's function. */ + bool set_bool(bool in, SPDocument * doc, Inkscape::XML::Node * node); + + /** Wrapper to cast to the object and use it's function. */ + int set_int(int in, SPDocument * doc, Inkscape::XML::Node * node); + + float set_float(float in, SPDocument * doc, Inkscape::XML::Node * node); + + gchar const *set_optiongroup(gchar const *in, SPDocument * doc, Inkscape::XML::Node *node); + + gchar const *set_enum(gchar const * in, SPDocument * doc, Inkscape::XML::Node *node); + + gchar const *set_string(gchar const * in, SPDocument * doc, Inkscape::XML::Node * node); + + guint32 set_color(guint32 in, SPDocument * doc, Inkscape::XML::Node * node); + + gchar const * name() const {return _name;} + + /** + * This function creates a parameter that can be used later. This + * is typically done in the creation of the extension and defined + * in the XML file describing the extension (it's private so people + * have to use the system) :) + * + * 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 or a type in the XML, then no parameter 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. + * + * @param in_repr The XML describing the parameter. + * @return a pointer to a new Parameter if applicable, null otherwise.. + */ + static Parameter *make(Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * in_ext); + + virtual Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal); + + gchar const * get_tooltip() const { return _description; } + + /** Indicates if the GUI for this parameter is hidden or not */ + bool get_hidden() const { return _hidden; } + + /** Indentation level of the parameter */ + int get_indent() const { return _indent; } + + virtual void string(std::list &list) const; + + /** + * Gets the current value of the parameter in a string form. + * @return A string with the 'value'. + */ + virtual void string(std::string &string) const; + + /** All the code in Notebook::get_param to get the notebook content. */ + virtual Parameter *get_param(gchar const *name); + + + /** Recommended margin of boxes containing multiple Parameters (in px) */ + const static int GUI_BOX_MARGIN = 10; + /** Recommended spacing between multiple Parameters packed into a box (in px) */ + const static int GUI_BOX_SPACING = 4; + /** Recommended spacing between the widgets making up a single Parameter (e.g. label and input) (in px) */ + const static int GUI_PARAM_WIDGETS_SPACING = 4; + /** Recommended indentation width of parameters (in px) */ + const static int GUI_INDENTATION = 12; + /** Recommended maximum line length for wrapping textual parameters (in chars) */ + const static int GUI_MAX_LINE_LENGTH = 60; + + +protected: + /** Parameter text to show as the GUI label. */ + gchar * _text; + + /** Extended description of the parameter (crrently shown as tooltip on hover). */ + gchar * _description; + + /** Whether the parameter is visible. */ + bool _hidden; + + /** Indentation level of the parameter. */ + int _indent; + + + /* **** funcs **** */ + + /** + * Build the name to write the parameter from the extension's ID and the name of this parameter. + */ + gchar *pref_name() const; + + Inkscape::XML::Node * find_child (Inkscape::XML::Node * adult); + + Inkscape::XML::Node * document_param_node (SPDocument * doc); + + Inkscape::XML::Node * new_child (Inkscape::XML::Node * parent); + +private: + /** Which extension is this parameter attached to. */ + Inkscape::Extension::Extension *_extension; + + /** The name of this parameter. */ + gchar *_name; +}; + +} // namespace Extension +} // namespace Inkscape + +#endif // SEEN_INK_EXTENSION_PARAM_H__ + +/* + 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/extension/prefdialog/param/radiobutton.cpp b/src/extension/prefdialog/param/radiobutton.cpp new file mode 100644 index 000000000..8c1d6a5f7 --- /dev/null +++ b/src/extension/prefdialog/param/radiobutton.cpp @@ -0,0 +1,349 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** \file + * extension parameter for radiobuttons. + * + * It uses a Gtk:ComboBoxText widget in the extension UI. + */ + +/* + * 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 +#include +#include +#include + +#include "xml/node.h" +#include "extension/extension.h" +#include "preferences.h" + +#include "radiobutton.h" + +/** + * The root directory in the preferences database for extension + * related parameters. + */ +#define PREF_DIR "extensions" + +namespace Inkscape { +namespace Extension { + +/* 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. */ + +ParamRadioButton::ParamRadioButton(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) +{ + // Read XML tree to add enumeration items: + // printf("Extension Constructor: "); + if (xml != nullptr) { + Inkscape::XML::Node *child_repr = xml->firstChild(); + while (child_repr != nullptr) { + char const * chname = child_repr->name(); + if (!strcmp(chname, INKSCAPE_EXTENSION_NS "option") || !strcmp(chname, INKSCAPE_EXTENSION_NS "_option")) { + Glib::ustring * newtext = nullptr; + Glib::ustring * newvalue = nullptr; + const char * contents = child_repr->firstChild()->content(); + + if (contents != nullptr) { + // don't translate when 'item' but do translate when '_option' + if (!strcmp(chname, INKSCAPE_EXTENSION_NS "_option")) { + if (child_repr->attribute("msgctxt") != nullptr) { + newtext = new Glib::ustring(g_dpgettext2(nullptr, child_repr->attribute("msgctxt"), contents)); + } else { + newtext = new Glib::ustring(_(contents)); + } + } else { + newtext = new Glib::ustring(contents); + } + } else { + continue; + } + + + const char * val = child_repr->attribute("value"); + if (val != nullptr) { + newvalue = new Glib::ustring(val); + } else { + newvalue = new Glib::ustring(contents); + } + + if ( (newtext) && (newvalue) ) { // logical error if this is not true here + choices.push_back(new optionentry(newvalue, newtext)); + } + } + child_repr = child_repr->next(); + } + } + + // Initialize _value with the default value from xml + // for simplicity : default to the contents of the first xml-child + const char * defaultval = nullptr; + if (!choices.empty()) { + defaultval = (static_cast (choices[0]))->value->c_str(); + } + + gchar * pref_name = this->pref_name(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring paramval = 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 + } +} + +ParamRadioButton::~ParamRadioButton () +{ + //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 *ParamRadioButton::set(const gchar * in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) +{ + if (in == nullptr) { + return nullptr; /* Can't have NULL string */ + } + + Glib::ustring * settext = nullptr; + for (auto entr:choices) { + if ( !entr->value->compare(in) ) { + settext = entr->value; + break; // break out of for loop + } + } + if (settext) { + if (_value != nullptr) { + g_free(_value); + } + _value = g_strdup(settext->c_str()); + gchar * prefname = this->pref_name(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setString(extension_pref_root + prefname, _value); + g_free(prefname); + } else { + g_warning("Couldn't set ParamRadioButton %s", in); + } + + return _value; +} + +void ParamRadioButton::string(std::string &string) const +{ + string += _value; +} + +/** A special radiobutton class to use in ParamRadioButton. */ +class ParamRadioButtonWdg : public Gtk::RadioButton { +private: + ParamRadioButton * _pref; + SPDocument * _doc; + Inkscape::XML::Node * _node; + sigc::signal * _changeSignal; +public: + /** + * Build a string preference for the given parameter. + * @param pref Where to put the radiobutton's string when it is selected. + */ + ParamRadioButtonWdg ( Gtk::RadioButtonGroup& group, const Glib::ustring& label, + ParamRadioButton * pref, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal ) : + Gtk::RadioButton(group, label), _pref(pref), _doc(doc), _node(node), _changeSignal(changeSignal) { + add_changesignal(); + }; + ParamRadioButtonWdg ( const Glib::ustring& label, + ParamRadioButton * pref, SPDocument * doc, Inkscape::XML::Node * node , sigc::signal * changeSignal) : + Gtk::RadioButton(label), _pref(pref), _doc(doc), _node(node), _changeSignal(changeSignal) { + add_changesignal(); + }; + void add_changesignal() { + this->signal_toggled().connect(sigc::mem_fun(this, &ParamRadioButtonWdg::changed)); + }; + void changed (); +}; + +/** + * Respond to the selected radiobutton changing. + * + * This function responds to the radiobutton selection changing by grabbing the value + * from the text box and putting it in the parameter. + */ +void ParamRadioButtonWdg::changed() +{ + if (this->get_active()) { + Glib::ustring value = _pref->value_from_label(this->get_label()); + _pref->set(value.c_str(), _doc, _node); + } + if (_changeSignal != nullptr) { + _changeSignal->emit(); + } +} + + +class ComboWdg : public Gtk::ComboBoxText { +private: + ParamRadioButton* _base; + SPDocument* _doc; + Inkscape::XML::Node* _node; + sigc::signal * _changeSignal; + +public: + ComboWdg(ParamRadioButton* base, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) : + _base(base), + _doc(doc), + _node(node), + _changeSignal(changeSignal) + { + this->signal_changed().connect(sigc::mem_fun(this, &ComboWdg::changed)); + } + ~ComboWdg() override = default; + void changed (); +}; + +void ComboWdg::changed() +{ + if ( _base ) { + Glib::ustring value = _base->value_from_label(get_active_text()); + _base->set(value.c_str(), _doc, _node); + } + if (_changeSignal != nullptr) { + _changeSignal->emit(); + } +} + +/** + * Returns the value for the options label parameter + */ +Glib::ustring ParamRadioButton::value_from_label(const Glib::ustring label) +{ + Glib::ustring value = ""; + + for ( auto entr:choices) { + if ( !entr->text->compare(label) ) { + value = *(entr->value); + break; + } + } + + return value; + +} + +/** + * Creates a combobox widget for an enumeration parameter. + */ +Gtk::Widget * ParamRadioButton::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) +{ + if (_hidden) { + return nullptr; + } + + auto hbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, Parameter::GUI_PARAM_WIDGETS_SPACING)); + hbox->set_homogeneous(false); + auto vbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0)); + vbox->set_homogeneous(false); + + Gtk::Label * label = Gtk::manage(new Gtk::Label(_text, Gtk::ALIGN_START, Gtk::ALIGN_START)); + label->show(); + hbox->pack_start(*label, false, false); + + Gtk::ComboBoxText* cbt = nullptr; + bool comboSet = false; + if (_mode == MINIMAL) { + cbt = Gtk::manage(new ComboWdg(this, doc, node, changeSignal)); + cbt->show(); + vbox->pack_start(*cbt, false, false); + } + + // add choice strings as radiobuttons + // and select last selected option (_value) + Gtk::RadioButtonGroup group; + for (auto entr:choices) { + Glib::ustring * text = entr->text; + switch ( _mode ) { + case MINIMAL: + { + cbt->append(*text); + if (!entr->value->compare(_value)) { + cbt->set_active_text(*text); + comboSet = true; + } + } + break; + case COMPACT: + case FULL: + { + ParamRadioButtonWdg * radio = Gtk::manage(new ParamRadioButtonWdg(group, *text, this, doc, node, changeSignal)); + radio->show(); + vbox->pack_start(*radio, true, true); + if (!entr->value->compare(_value)) { + radio->set_active(); + } + } + break; + } + } + + if ( (_mode == MINIMAL) && !comboSet) { + cbt->set_active(0); + } + + vbox->show(); + hbox->pack_end(*vbox, false, false); + 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/param/radiobutton.h b/src/extension/prefdialog/param/radiobutton.h new file mode 100644 index 000000000..48d470a01 --- /dev/null +++ b/src/extension/prefdialog/param/radiobutton.h @@ -0,0 +1,107 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef INK_EXTENSION_PARAMRADIOBUTTON_H_SEEN +#define INK_EXTENSION_PARAMRADIOBUTTON_H_SEEN + +/** \file + * Radiobutton 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 "parameter.h" + +namespace Gtk { +class Widget; +} + +namespace Inkscape { +namespace Extension { + +class Extension; + + + +// \brief A class to represent a radiobutton parameter of an extension +class ParamRadioButton : public Parameter { +public: + enum AppearanceMode { + FULL, COMPACT, MINIMAL + }; + + ParamRadioButton(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml, + AppearanceMode mode); + ~ParamRadioButton() 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; + + Glib::ustring value_from_label(const Glib::ustring label); + + const gchar *get(const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) const { return _value; } + + const gchar *set(const gchar *in, SPDocument *doc, Inkscape::XML::Node *node); + +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; + AppearanceMode _mode; + + /* 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 optionentry { + public: + optionentry (Glib::ustring * val, Glib::ustring * txt) { + value = val; + text = txt; + } + ~optionentry() { + delete value; + delete text; + } + Glib::ustring * value; + Glib::ustring * text; + }; + + std::vector choices; /**< A table to store the choice strings */ + +}; /* class ParamRadioButton */ + + + + + +} /* namespace Extension */ +} /* namespace Inkscape */ + +#endif /* INK_EXTENSION_PARAMRADIOBUTTON_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:fileencoding=utf-8:textwidth=99 : diff --git a/src/extension/prefdialog/param/string.cpp b/src/extension/prefdialog/param/string.cpp new file mode 100644 index 000000000..c1986cf92 --- /dev/null +++ b/src/extension/prefdialog/param/string.cpp @@ -0,0 +1,181 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Jon A. Cruz + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include +#include +#include + +#include + +#include "xml/node.h" +#include "extension/extension.h" +#include "./string.h" +#include "preferences.h" +#include + +namespace Inkscape { +namespace Extension { + + +/** Free the allocated data. */ +ParamString::~ParamString() +{ + g_free(_value); + _value = nullptr; +} + +/** + * A function to set the \c _value. + * + * This function sets 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 to. + * @param doc A document that should be used to set the value. + * @param node The node where the value may be placed. + */ +const gchar * ParamString::set(const gchar * in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) +{ + if (in == nullptr) { + return nullptr; /* Can't have NULL string */ + } + + if (_value != nullptr) { + g_free(_value); + } + + _value = g_strdup(in); + + gchar * prefname = this->pref_name(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setString(extension_pref_root + prefname, _value); + g_free(prefname); + + return _value; +} + +void ParamString::string(std::string &string) const +{ + if (_value) { + string += _value; + } +} + +/** Initialize the object, to do that, copy the data. */ +ParamString::ParamString(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 * defaultval = nullptr; + if (xml->firstChild() != nullptr) { + defaultval = xml->firstChild()->content(); + } + + gchar * pref_name = this->pref_name(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring paramval = prefs->getString(extension_pref_root + pref_name); + g_free(pref_name); + + if (!paramval.empty()) { + defaultval = paramval.data(); + } + if (defaultval != nullptr) { + char const * chname = xml->name(); + if (!strcmp(chname, INKSCAPE_EXTENSION_NS "_param")) { + if (xml->attribute("msgctxt") != nullptr) { + _value = g_strdup(g_dpgettext2(nullptr, xml->attribute("msgctxt"), defaultval)); + } else { + _value = g_strdup(_(defaultval)); + } + } else { + _value = g_strdup(defaultval); + } + } + + _max_length = 0; +} + +/** A special type of Gtk::Entry to handle string parameteres. */ +class ParamStringEntry : public Gtk::Entry { +private: + ParamString * _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. + */ + ParamStringEntry (ParamString * pref, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) : + Gtk::Entry(), _pref(pref), _doc(doc), _node(node), _changeSignal(changeSignal) { + if (_pref->get(nullptr, nullptr) != nullptr) { + this->set_text(Glib::ustring(_pref->get(nullptr, nullptr))); + } + this->set_max_length(_pref->getMaxLength()); //Set the max length - default zero means no maximum + this->signal_changed().connect(sigc::mem_fun(this, &ParamStringEntry::changed_text)); + }; + void changed_text (); +}; + + +/** + * 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 ParamStringEntry::changed_text() +{ + Glib::ustring data = this->get_text(); + _pref->set(data.c_str(), _doc, _node); + if (_changeSignal != nullptr) { + _changeSignal->emit(); + } +} + +/** + * Creates a text box for the string parameter. + * + * Builds a hbox with a label and a text box in it. + */ +Gtk::Widget * ParamString::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); + + ParamStringEntry * textbox = new ParamStringEntry(this, doc, node, changeSignal); + textbox->show(); + hbox->pack_start(*textbox, true, true); + + hbox->show(); + + return dynamic_cast(hbox); +} + +} /* namespace Extension */ +} /* namespace Inkscape */ diff --git a/src/extension/prefdialog/param/string.h b/src/extension/prefdialog/param/string.h new file mode 100644 index 000000000..7c094d394 --- /dev/null +++ b/src/extension/prefdialog/param/string.h @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef INK_EXTENSION_PARAMSTRING_H_SEEN +#define INK_EXTENSION_PARAMSTRING_H_SEEN + +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Jon A. Cruz + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "parameter.h" + +namespace Inkscape { +namespace Extension { + +class ParamString : public Parameter { +private: + /** \brief Internal value. This should point to a string that has + been allocated in memory. And should be free'd. */ + gchar * _value; + /** \brief Internal value. This indicates the maximum length of the string. Zero meaning unlimited. + */ + gint _max_length; +public: + ParamString(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml); + ~ParamString() override; + + /** \brief Returns \c _value, with a \i const to protect it. */ + const gchar *get(SPDocument const * /*doc*/, Inkscape::XML::Node const * /*node*/) const { return _value; } + + const gchar * set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node); + + 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; + + void setMaxLength(int maxLength) { _max_length = maxLength; } + int getMaxLength() { return _max_length; } +}; + + +} // namespace Extension +} // namespace Inkscape + +#endif /* INK_EXTENSION_PARAMSTRING_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/prefdialog.cpp b/src/extension/prefdialog/prefdialog.cpp new file mode 100644 index 000000000..6fbffb262 --- /dev/null +++ b/src/extension/prefdialog/prefdialog.cpp @@ -0,0 +1,277 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Authors: + * Ted Gould + * + * Copyright (C) 2005-2008 Authors + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "prefdialog.h" + +#include +#include +#include + +#include "ui/dialog-events.h" +#include "xml/repr.h" + +// Used to get SP_ACTIVE_DESKTOP +#include "inkscape.h" +#include "desktop.h" +#include "document.h" +#include "document-undo.h" + +#include "extension/effect.h" +#include "extension/execution-env.h" +#include "extension/implementation/implementation.h" + +#include "param/parameter.h" + + +namespace Inkscape { +namespace Extension { + + +/** \brief Creates a new preference dialog for extension preferences + \param name Name of the Extension whose dialog this is + \param help The help string for the extension (NULL if none) + \param controls The extension specific widgets in the dialog + + This function initializes the dialog with the name of the extension + in the title. It adds a few buttons and sets up handlers for + them. It also places the passed-in widgets into the dialog. +*/ +PrefDialog::PrefDialog (Glib::ustring name, gchar const * help, Gtk::Widget * controls, Effect * effect) : + Gtk::Dialog(_(name.c_str()), true), + _help(help), + _name(name), + _button_ok(nullptr), + _button_cancel(nullptr), + _button_preview(nullptr), + _param_preview(nullptr), + _effect(effect), + _exEnv(nullptr) +{ + this->set_default_size(0,0); // we want the window to be as small as possible instead of clobbering up space + + Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox()); + if (controls == nullptr) { + if (_effect == nullptr) { + std::cout << "AH!!! No controls and no effect!!!" << std::endl; + return; + } + controls = _effect->get_imp()->prefs_effect(_effect, SP_ACTIVE_DESKTOP, &_signal_param_change, nullptr); + _signal_param_change.connect(sigc::mem_fun(this, &PrefDialog::param_change)); + } + + hbox->pack_start(*controls, true, true, 0); + hbox->show(); + + this->get_content_area()->pack_start(*hbox, true, true, 0); + + /* + Gtk::Button * help_button = add_button(Gtk::Stock::HELP, Gtk::RESPONSE_HELP); + if (_help == NULL) + help_button->set_sensitive(false); + */ + _button_cancel = add_button(_effect == nullptr ? _("_Cancel") : _("_Close"), Gtk::RESPONSE_CANCEL); + _button_ok = add_button(_effect == nullptr ? _("_OK") : _("_Apply"), Gtk::RESPONSE_OK); + set_default_response(Gtk::RESPONSE_OK); + _button_ok->grab_focus(); + + if (_effect != nullptr && !_effect->no_live_preview) { + if (_param_preview == nullptr) { + XML::Document * doc = sp_repr_read_mem(live_param_xml, strlen(live_param_xml), nullptr); + if (doc == nullptr) { + std::cout << "Error encountered loading live parameter XML !!!" << std::endl; + return; + } + _param_preview = Parameter::make(doc->root(), _effect); + } + + auto sep = Gtk::manage(new Gtk::Separator()); + sep->show(); + + this->get_content_area()->pack_start(*sep, false, false, Parameter::GUI_BOX_SPACING); + + hbox = Gtk::manage(new Gtk::HBox()); + hbox->set_border_width(Parameter::GUI_BOX_MARGIN); + _button_preview = _param_preview->get_widget(nullptr, nullptr, &_signal_preview); + _button_preview->show(); + hbox->pack_start(*_button_preview, true, true, 0); + hbox->show(); + + this->get_content_area()->pack_start(*hbox, false, false, 0); + + Gtk::Box * hbox = dynamic_cast(_button_preview); + if (hbox != nullptr) { + _checkbox_preview = dynamic_cast(hbox->get_children().front()); + } + + preview_toggle(); + _signal_preview.connect(sigc::mem_fun(this, &PrefDialog::preview_toggle)); + } + + // Set window modality for effects that don't use live preview + if (_effect != nullptr && _effect->no_live_preview) { + set_modal(false); + } + + GtkWidget *dlg = GTK_WIDGET(gobj()); + sp_transientize(dlg); + + return; +} + +PrefDialog::~PrefDialog ( ) +{ + if (_param_preview != nullptr) { + delete _param_preview; + _param_preview = nullptr; + } + + if (_exEnv != nullptr) { + _exEnv->cancel(); + delete _exEnv; + _exEnv = nullptr; + _effect->set_execution_env(_exEnv); + } + + if (_effect != nullptr) { + _effect->set_pref_dialog(nullptr); + } + + return; +} + +#if 0 +/** \brief Runs the dialog + \return The response to the dialog + + This function overrides the run function in the GTKmm dialog + class, but basically it only calls it. This function only + handles the \c Gtk::RESPONSE_HELP return, and in that case it + brings up the help window. All other return values are returned + to the calling function. +*/ +int +PrefDialog::run (void) { + int resp = Gtk::RESPONSE_HELP; + while (resp == Gtk::RESPONSE_HELP) { + resp = Gtk::Dialog::run(); + if (resp == Gtk::RESPONSE_HELP) { + /* + if (_helpDialog == NULL) { + _helpDialog = new HelpDialog(_help); + } + */ + } + } + return resp; +} +#endif + +void +PrefDialog::preview_toggle () { + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + SPDocument *document = SP_ACTIVE_DOCUMENT; + bool modified = document->isModifiedSinceSave(); + if(_param_preview->get_bool(nullptr, nullptr)) { + if (_exEnv == nullptr) { + set_modal(true); + _exEnv = new ExecutionEnv(_effect, SP_ACTIVE_DESKTOP, nullptr, false, false); + _effect->set_execution_env(_exEnv); + _exEnv->run(); + } + } else { + set_modal(false); + if (_exEnv != nullptr) { + _exEnv->cancel(); + _exEnv->undo(); + _exEnv->reselect(); + delete _exEnv; + _exEnv = nullptr; + _effect->set_execution_env(_exEnv); + } + } + document->setModifiedSinceSave(modified); +} + +void +PrefDialog::param_change () { + if (_exEnv != nullptr) { + if (!_effect->loaded()) { + _effect->set_state(Extension::STATE_LOADED); + } + _timersig.disconnect(); + _timersig = Glib::signal_timeout().connect(sigc::mem_fun(this, &PrefDialog::param_timer_expire), + 250, /* ms */ + Glib::PRIORITY_DEFAULT_IDLE); + } + + return; +} + +bool +PrefDialog::param_timer_expire () { + if (_exEnv != nullptr) { + _exEnv->cancel(); + _exEnv->undo(); + _exEnv->reselect(); + _exEnv->run(); + } + + return false; +} + +void +PrefDialog::on_response (int signal) { + if (signal == Gtk::RESPONSE_OK) { + if (_exEnv == nullptr) { + if (_effect != nullptr) { + _effect->effect(SP_ACTIVE_DESKTOP); + } else { + // Shutdown run() + return; + } + } else { + if (_exEnv->wait()) { + _exEnv->commit(); + } else { + _exEnv->undo(); + _exEnv->reselect(); + } + delete _exEnv; + _exEnv = nullptr; + _effect->set_execution_env(_exEnv); + } + } + + if (_param_preview != nullptr) { + _checkbox_preview->set_active(false); + } + + if ((signal == Gtk::RESPONSE_CANCEL || signal == Gtk::RESPONSE_DELETE_EVENT) && _effect != nullptr) { + delete this; + } + return; +} + +#include "extension/internal/clear-n_.h" + +const char * PrefDialog::live_param_xml = "false"; + +}; }; /* namespace Inkscape, Extension */ + +/* + 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/prefdialog.h b/src/extension/prefdialog/prefdialog.h new file mode 100644 index 000000000..087900fbe --- /dev/null +++ b/src/extension/prefdialog/prefdialog.h @@ -0,0 +1,94 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Authors: + * Ted Gould + * + * Copyright (C) 2005,2007-2008 Authors + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#ifndef INKSCAPE_EXTENSION_DIALOG_H__ +#define INKSCAPE_EXTENSION_DIALOG_H__ + +#include +#include +#include + +namespace Gtk { +class CheckButton; +} + +namespace Inkscape { +namespace Extension { +class Effect; +class ExecutionEnv; +class Parameter; + +/** \brief A class to represent the preferences for an extension */ +class PrefDialog : public Gtk::Dialog { + /** \brief Help string if it exists */ + gchar const * _help; + /** \brief Name of the extension */ + Glib::ustring _name; + + /** \brief A pointer to the OK button */ + Gtk::Button * _button_ok; + /** \brief A pointer to the CANCEL button */ + Gtk::Button * _button_cancel; + + /** \brief Button to control live preview */ + Gtk::Widget * _button_preview; + /** \brief Checkbox for the preview */ + Gtk::CheckButton * _checkbox_preview; + + /** \brief Parameter to control live preview */ + Parameter * _param_preview; + + /** \brief XML to define the live effects parameter on the dialog */ + static const char * live_param_xml; + + /** \brief Signal that the user is changing the live effect state */ + sigc::signal _signal_preview; + /** \brief Signal that one of the parameters change */ + sigc::signal _signal_param_change; + + /** \brief If this is the preferences for an effect, the effect + that we're working with. */ + Effect * _effect; + /** \brief If we're executing in preview mode here is the execution + environment for the effect. */ + ExecutionEnv * _exEnv; + + /** \brief The timer used to make it so that parameters don't respond + directly and allows for changes. */ + sigc::connection _timersig; + + void preview_toggle(); + void param_change(); + bool param_timer_expire(); + void on_response (int signal) override; + +public: + PrefDialog (Glib::ustring name, + gchar const * help, + Gtk::Widget * controls = nullptr, + Effect * effect = nullptr); + ~PrefDialog () override; +}; + + +};}; /* namespace Inkscape, Extension */ + +#endif /* INKSCAPE_EXTENSION_DIALOG_H__ */ + +/* + 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 : -- cgit v1.2.3 From 9864c6fb1ee878830cbdecdba4e18bab1e31a1c6 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Sun, 21 Jul 2019 15:59:41 +0200 Subject: Remove unused functions --- src/extension/prefdialog/param/parameter.cpp | 46 ---------------------------- src/extension/prefdialog/param/parameter.h | 5 --- 2 files changed, 51 deletions(-) diff --git a/src/extension/prefdialog/param/parameter.cpp b/src/extension/prefdialog/param/parameter.cpp index 1a60ef32e..a07821441 100644 --- a/src/extension/prefdialog/param/parameter.cpp +++ b/src/extension/prefdialog/param/parameter.cpp @@ -365,52 +365,6 @@ gchar *Parameter::pref_name() const return g_strdup_printf("%s.%s", _extension->get_id(), _name); } -Inkscape::XML::Node * -Parameter::find_child (Inkscape::XML::Node * adult) -{ - return sp_repr_lookup_child(adult, "name", _name); -} - -Inkscape::XML::Node * -Parameter::new_child (Inkscape::XML::Node * parent) -{ - Inkscape::XML::Node * retval; - retval = parent->document()->createElement("inkscape:extension-param"); - retval->setAttribute("name", _name); - - parent->appendChild(retval); - Inkscape::GC::release(retval); - return retval; -} - -Inkscape::XML::Node *Parameter::document_param_node(SPDocument * doc) -{ - Inkscape::XML::Document *xml_doc = doc->getReprDoc(); - Inkscape::XML::Node * defs = doc->getDefs()->getRepr(); - Inkscape::XML::Node * params = nullptr; - - GQuark const name_quark = g_quark_from_string("inkscape:extension-params"); - - for (Inkscape::XML::Node * child = defs->firstChild(); - child != nullptr; - child = child->next()) { - if ((GQuark)child->code() == name_quark && - !strcmp(child->attribute("extension"), _extension->get_id())) { - params = child; - break; - } - } - - if (params == nullptr) { - params = xml_doc->createElement("inkscape:extension-param"); - params->setAttribute("extension", _extension->get_id()); - defs->appendChild(params); - Inkscape::GC::release(params); - } - - return params; -} - /** Basically, if there is no widget pass a NULL. */ Gtk::Widget * Parameter::get_widget (SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal * /*changeSignal*/) diff --git a/src/extension/prefdialog/param/parameter.h b/src/extension/prefdialog/param/parameter.h index c37d1539a..cc10787e6 100644 --- a/src/extension/prefdialog/param/parameter.h +++ b/src/extension/prefdialog/param/parameter.h @@ -188,11 +188,6 @@ protected: */ gchar *pref_name() const; - Inkscape::XML::Node * find_child (Inkscape::XML::Node * adult); - - Inkscape::XML::Node * document_param_node (SPDocument * doc); - - Inkscape::XML::Node * new_child (Inkscape::XML::Node * parent); private: /** Which extension is this parameter attached to. */ -- cgit v1.2.3 From 664b20d7da3629cfa0a1d6e9449881b5e9f59be9 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Sun, 21 Jul 2019 16:48:54 +0200 Subject: Rename parameter source files to avoid name conflicts --- src/extension/CMakeLists.txt | 40 +- src/extension/extension.cpp | 2 +- src/extension/prefdialog/param/bool.cpp | 154 -------- src/extension/prefdialog/param/bool.h | 95 ----- src/extension/prefdialog/param/color.cpp | 119 ------ src/extension/prefdialog/param/color.h | 74 ---- src/extension/prefdialog/param/description.cpp | 134 ------- src/extension/prefdialog/param/description.h | 63 ---- src/extension/prefdialog/param/enum.cpp | 268 ------------- src/extension/prefdialog/param/enum.h | 106 ------ src/extension/prefdialog/param/float.cpp | 205 ---------- src/extension/prefdialog/param/float.h | 83 ----- src/extension/prefdialog/param/int.cpp | 201 ---------- src/extension/prefdialog/param/int.h | 80 ---- src/extension/prefdialog/param/notebook.cpp | 413 -------------------- src/extension/prefdialog/param/notebook.h | 117 ------ src/extension/prefdialog/param/parameter.cpp | 415 --------------------- src/extension/prefdialog/param/parameter.h | 214 ----------- src/extension/prefdialog/param/radiobutton.cpp | 349 ----------------- src/extension/prefdialog/param/radiobutton.h | 107 ------ src/extension/prefdialog/param/string.cpp | 181 --------- src/extension/prefdialog/param/string.h | 67 ---- src/extension/prefdialog/parameter-bool.cpp | 155 ++++++++ src/extension/prefdialog/parameter-bool.h | 95 +++++ src/extension/prefdialog/parameter-color.cpp | 120 ++++++ src/extension/prefdialog/parameter-color.h | 74 ++++ src/extension/prefdialog/parameter-description.cpp | 135 +++++++ src/extension/prefdialog/parameter-description.h | 63 ++++ src/extension/prefdialog/parameter-enum.cpp | 269 +++++++++++++ src/extension/prefdialog/parameter-enum.h | 106 ++++++ src/extension/prefdialog/parameter-float.cpp | 206 ++++++++++ src/extension/prefdialog/parameter-float.h | 83 +++++ src/extension/prefdialog/parameter-int.cpp | 202 ++++++++++ src/extension/prefdialog/parameter-int.h | 80 ++++ src/extension/prefdialog/parameter-notebook.cpp | 414 ++++++++++++++++++++ src/extension/prefdialog/parameter-notebook.h | 119 ++++++ src/extension/prefdialog/parameter-radiobutton.cpp | 349 +++++++++++++++++ src/extension/prefdialog/parameter-radiobutton.h | 109 ++++++ src/extension/prefdialog/parameter-string.cpp | 182 +++++++++ src/extension/prefdialog/parameter-string.h | 67 ++++ src/extension/prefdialog/parameter.cpp | 415 +++++++++++++++++++++ src/extension/prefdialog/parameter.h | 215 +++++++++++ src/extension/prefdialog/prefdialog.cpp | 2 +- 43 files changed, 3480 insertions(+), 3467 deletions(-) delete mode 100644 src/extension/prefdialog/param/bool.cpp delete mode 100644 src/extension/prefdialog/param/bool.h delete mode 100644 src/extension/prefdialog/param/color.cpp delete mode 100644 src/extension/prefdialog/param/color.h delete mode 100644 src/extension/prefdialog/param/description.cpp delete mode 100644 src/extension/prefdialog/param/description.h delete mode 100644 src/extension/prefdialog/param/enum.cpp delete mode 100644 src/extension/prefdialog/param/enum.h delete mode 100644 src/extension/prefdialog/param/float.cpp delete mode 100644 src/extension/prefdialog/param/float.h delete mode 100644 src/extension/prefdialog/param/int.cpp delete mode 100644 src/extension/prefdialog/param/int.h delete mode 100644 src/extension/prefdialog/param/notebook.cpp delete mode 100644 src/extension/prefdialog/param/notebook.h delete mode 100644 src/extension/prefdialog/param/parameter.cpp delete mode 100644 src/extension/prefdialog/param/parameter.h delete mode 100644 src/extension/prefdialog/param/radiobutton.cpp delete mode 100644 src/extension/prefdialog/param/radiobutton.h delete mode 100644 src/extension/prefdialog/param/string.cpp delete mode 100644 src/extension/prefdialog/param/string.h create mode 100644 src/extension/prefdialog/parameter-bool.cpp create mode 100644 src/extension/prefdialog/parameter-bool.h create mode 100644 src/extension/prefdialog/parameter-color.cpp create mode 100644 src/extension/prefdialog/parameter-color.h create mode 100644 src/extension/prefdialog/parameter-description.cpp create mode 100644 src/extension/prefdialog/parameter-description.h create mode 100644 src/extension/prefdialog/parameter-enum.cpp create mode 100644 src/extension/prefdialog/parameter-enum.h create mode 100644 src/extension/prefdialog/parameter-float.cpp create mode 100644 src/extension/prefdialog/parameter-float.h create mode 100644 src/extension/prefdialog/parameter-int.cpp create mode 100644 src/extension/prefdialog/parameter-int.h create mode 100644 src/extension/prefdialog/parameter-notebook.cpp create mode 100644 src/extension/prefdialog/parameter-notebook.h create mode 100644 src/extension/prefdialog/parameter-radiobutton.cpp create mode 100644 src/extension/prefdialog/parameter-radiobutton.h create mode 100644 src/extension/prefdialog/parameter-string.cpp create mode 100644 src/extension/prefdialog/parameter-string.h create mode 100644 src/extension/prefdialog/parameter.cpp create mode 100644 src/extension/prefdialog/parameter.h diff --git a/src/extension/CMakeLists.txt b/src/extension/CMakeLists.txt index c00111209..3f5772cd2 100644 --- a/src/extension/CMakeLists.txt +++ b/src/extension/CMakeLists.txt @@ -53,16 +53,16 @@ set(extension_SRC internal/pdfinput/svg-builder.cpp prefdialog/prefdialog.cpp - prefdialog/param/bool.cpp - prefdialog/param/color.cpp - prefdialog/param/description.cpp - prefdialog/param/enum.cpp - prefdialog/param/float.cpp - prefdialog/param/int.cpp - prefdialog/param/notebook.cpp - prefdialog/param/parameter.cpp - prefdialog/param/radiobutton.cpp - prefdialog/param/string.cpp + prefdialog/parameter.cpp + 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-string.cpp # ------ # Header @@ -128,16 +128,16 @@ set(extension_SRC internal/wmf-print.h prefdialog/prefdialog.h - prefdialog/param/bool.h - prefdialog/param/color.h - prefdialog/param/description.h - prefdialog/param/enum.h - prefdialog/param/float.h - prefdialog/param/int.h - prefdialog/param/notebook.h - prefdialog/param/parameter.h - prefdialog/param/radiobutton.h - prefdialog/param/string.h + prefdialog/parameter.h + 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-string.h ) if(WIN32) diff --git a/src/extension/extension.cpp b/src/extension/extension.cpp index f85be2a70..bd593ea15 100644 --- a/src/extension/extension.cpp +++ b/src/extension/extension.cpp @@ -29,7 +29,7 @@ #include "db.h" #include "dependency.h" #include "timer.h" -#include "prefdialog/param/parameter.h" +#include "prefdialog/parameter.h" #include "io/resource.h" namespace Inkscape { diff --git a/src/extension/prefdialog/param/bool.cpp b/src/extension/prefdialog/param/bool.cpp deleted file mode 100644 index f304f9aef..000000000 --- a/src/extension/prefdialog/param/bool.cpp +++ /dev/null @@ -1,154 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (C) 2005-2007 Authors: - * Ted Gould - * Johan Engelen * - * Jon A. Cruz - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include -#include -#include -#include - -#include "xml/node.h" -#include "extension/extension.h" -#include "bool.h" -#include "preferences.h" - -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) -{ - const char * defaultval = nullptr; - if (xml->firstChild() != nullptr) { - defaultval = xml->firstChild()->content(); - } - - if (defaultval != nullptr && (!strcmp(defaultval, "true") || !strcmp(defaultval, "1"))) { - _value = true; - } else { - _value = false; - } - - 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(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setBool(extension_pref_root + prefname, _value); - g_free(prefname); - - return _value; -} - -bool ParamBool::get(const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) const -{ - return _value; -} - -/** - * A check button which is Param aware. It works with the - * parameter to change it's value as the check button changes - * value. - */ -class ParamBoolCheckButton : public Gtk::CheckButton { -public: - /** - * Initialize the check button. - * This function sets the value of the checkbox to be that of the - * parameter, and then sets up a callback to \c on_toggle. - * - * @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) : - 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)); - return; - } - - /** - * A function to respond to the check box changing. - * Adjusts the value of the preference to match that in the check box. - */ - void on_toggle (); - -private: - /** Param to change. */ - ParamBool * _pref; - SPDocument * _doc; - Inkscape::XML::Node * _node; - sigc::signal * _changeSignal; -}; - -void ParamBoolCheckButton::on_toggle() -{ - _pref->set(this->get_active(), nullptr /**\todo fix this */, nullptr); - if (_changeSignal != nullptr) { - _changeSignal->emit(); - } - return; -} - -void ParamBool::string(std::string &string) const -{ - if (_value) { - string += "true"; - } else { - string += "false"; - } - - return; -} - -Gtk::Widget *ParamBool::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) -{ - if (_hidden) { - return nullptr; - } - - auto hbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, Parameter::GUI_PARAM_WIDGETS_SPACING)); - hbox->set_homogeneous(false); - - ParamBoolCheckButton * checkbox = Gtk::manage(new ParamBoolCheckButton(this, _text, doc, node, changeSignal)); - checkbox->show(); - hbox->pack_start(*checkbox, false, false); - - 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/extension/prefdialog/param/bool.h b/src/extension/prefdialog/param/bool.h deleted file mode 100644 index 9864cac38..000000000 --- a/src/extension/prefdialog/param/bool.h +++ /dev/null @@ -1,95 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -#ifndef SEEN_INK_EXTENSION_PARAMBOOL_H -#define SEEN_INK_EXTENSION_PARAMBOOL_H -/* - * Copyright (C) 2005-2007 Authors: - * Ted Gould - * Johan Engelen * - * Jon A. Cruz - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include "parameter.h" - -class SPDocument; - -namespace Gtk { -class Widget; -} - -namespace Inkscape { -namespace XML { -class Node; -} - -namespace Extension { - -/** - * A boolean parameter. - */ -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); - - /** - * Returns the current state/value. - */ - bool get(const SPDocument *doc, const Inkscape::XML::Node *node) const; - - /** - * A function to set the state/value. - * This function sets 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. - * - * @param in The value to set to - * @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); - - /** - * 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; - - // Explicitly call superclass version to avoid method being hidden. - void string(std::list &list) const override { return Parameter::string(list); } - - /** - * Appends 'true' or 'false'. - * @todo investigate. Returning a value that can then be appended would probably work better/safer. - */ - void string(std::string &string) const override; - -private: - /** Internal value. */ - bool _value; -}; - -} // namespace Extension -} // namespace Inkscape - -#endif // SEEN_INK_EXTENSION_PARAMBOOL_H - -/* - 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/param/color.cpp b/src/extension/prefdialog/param/color.cpp deleted file mode 100644 index ed9940154..000000000 --- a/src/extension/prefdialog/param/color.cpp +++ /dev/null @@ -1,119 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (C) 2005-2007 Authors: - * Ted Gould - * Johan Engelen - * Christopher Brown - * Jon A. Cruz - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include -#include - -#include -#include -#include - -#include - -#include "extension/extension.h" -#include "color.h" - -#include -#include "ui/widget/color-notebook.h" -#include "preferences.h" - -namespace Inkscape { -namespace Extension { - -ParamColor::~ParamColor() -{ - _color_changed.disconnect(); -} - -guint32 ParamColor::set( guint32 in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/ ) -{ - _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(); - - gchar * pref_name = this->pref_name(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring paramval = prefs->getString(extension_pref_root + pref_name); - g_free(pref_name); - - if (!paramval.empty()) - defaulthex = paramval.data(); - - if (defaulthex) { - _color.setValue(atoi(defaulthex)); - } - _color_changed = _color.signal_changed.connect(sigc::mem_fun(this, &ParamColor::_onColorChanged)); - -} - -void ParamColor::string(std::string &string) const -{ - char str[16]; - snprintf(str, 16, "%i", _color.value()); - string += str; -} - -Gtk::Widget *ParamColor::get_widget( SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal * changeSignal ) -{ - using Inkscape::UI::Widget::ColorNotebook; - - if (_hidden) return nullptr; - - if (changeSignal) { - _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() -{ - if (_changeSignal) - _changeSignal->emit(); -} - -}; /* namespace Extension */ -}; /* namespace Inkscape */ diff --git a/src/extension/prefdialog/param/color.h b/src/extension/prefdialog/param/color.h deleted file mode 100644 index c2d3c2ccb..000000000 --- a/src/extension/prefdialog/param/color.h +++ /dev/null @@ -1,74 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -#ifndef SEEN_INK_EXTENSION_PARAMCOLOR_H__ -#define SEEN_INK_EXTENSION_PARAMCOLOR_H__ -/* - * Copyright (C) 2005-2007 Authors: - * Ted Gould - * Johan Engelen * - * Jon A. Cruz - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include "parameter.h" -#include "ui/selected-color.h" - -class SPDocument; - -namespace Gtk { -class Widget; -} - -namespace Inkscape { -namespace XML { -class Node; -} - -namespace Extension { - -class ParamColor : public Parameter { -private: - void _onColorChanged(); - - Inkscape::UI::SelectedColor _color; - sigc::connection _color_changed; -public: - ParamColor(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml); - ~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); - - 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; - -}; // class ParamColor - -} // namespace Extension -} // namespace Inkscape - -#endif // SEEN_INK_EXTENSION_PARAMCOLOR_H__ - -/* - 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/param/description.cpp b/src/extension/prefdialog/param/description.cpp deleted file mode 100644 index 60e2d02c8..000000000 --- a/src/extension/prefdialog/param/description.cpp +++ /dev/null @@ -1,134 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (C) 2005-2007 Authors: - * Ted Gould - * Johan Engelen * - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#ifdef linux // does the dollar sign need escaping when passed as string parameter? -# define ESCAPE_DOLLAR_COMMANDLINE -#endif - -#include -#include -#include -#include -#include - -#include "xml/node.h" -#include "extension/extension.h" -#include "description.h" - -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) -{ - // 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(); - } else if (cur_child->type() == XML::ELEMENT_NODE && !g_strcmp0(cur_child->name(), "extension:br")) { - 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); - } - - // 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()); - } - } - - // 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; -} - -/** \brief Create a label for the description */ -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()); - if (_mode == HEADER) { - label->set_markup(Glib::ustring("") + Glib::Markup::escape_text(newtext) + Glib::ustring("")); - label->set_margin_top(5); - label->set_margin_bottom(5); - } else if (_mode == URL) { - Glib::ustring escaped_url = Glib::Markup::escape_text(newtext); - label->set_markup(Glib::ustring::compose("%1", escaped_url)); - } else { - label->set_text(newtext); - } - label->set_line_wrap(); - label->set_xalign(0); - - // 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 - // - 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 - // 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(); - label->set_width_chars(len > Parameter::GUI_MAX_LINE_LENGTH ? Parameter::GUI_MAX_LINE_LENGTH : len); - - label->show(); - - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox()); - hbox->pack_start(*label, true, true); - hbox->show(); - - return hbox; -} - -} /* namespace Extension */ -} /* namespace Inkscape */ diff --git a/src/extension/prefdialog/param/description.h b/src/extension/prefdialog/param/description.h deleted file mode 100644 index 822370b82..000000000 --- a/src/extension/prefdialog/param/description.h +++ /dev/null @@ -1,63 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -#ifndef __INK_EXTENSION_PARAMDESCRIPTION_H__ -#define __INK_EXTENSION_PARAMDESCRIPTION_H__ - -/* - * Copyright (C) 2005-2007 Authors: - * Ted Gould - * Johan Engelen * - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include "parameter.h" - -class SPDocument; - -namespace Gtk { - class Widget; -} - -namespace Inkscape { -namespace Xml { - class Node; -} - -namespace Extension { - -/** \brief A description parameter */ -class ParamDescription : public Parameter { -public: - enum AppearanceMode { - DESCRIPTION, 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; -private: - /** \brief Internal value. */ - gchar * _value; - AppearanceMode _mode; -}; - -} /* namespace Extension */ -} /* namespace Inkscape */ - -#endif /* __INK_EXTENSION_PARAMDESCRIPTION_H__ */ - -/* - 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/param/enum.cpp b/src/extension/prefdialog/param/enum.cpp deleted file mode 100644 index 5ba3e5772..000000000 --- a/src/extension/prefdialog/param/enum.cpp +++ /dev/null @@ -1,268 +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 -#include -#include - -#include "xml/node.h" -#include "extension/extension.h" -#include "enum.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/param/enum.h b/src/extension/prefdialog/param/enum.h deleted file mode 100644 index 329bb26f9..000000000 --- a/src/extension/prefdialog/param/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/param/float.cpp b/src/extension/prefdialog/param/float.cpp deleted file mode 100644 index 661c533ca..000000000 --- a/src/extension/prefdialog/param/float.cpp +++ /dev/null @@ -1,205 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (C) 2005-2007 Authors: - * Ted Gould - * Johan Engelen * - * Jon A. Cruz - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include -#include -#include -#include "ui/widget/spinbutton.h" -#include "ui/widget/spin-scale.h" - -#include "xml/node.h" -#include "extension/extension.h" -#include "preferences.h" -#include "./float.h" - -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) -{ - const gchar * defaultval = nullptr; - if (xml->firstChild() != nullptr) { - defaultval = xml->firstChild()->content(); - } - if (defaultval != nullptr) { - _value = g_ascii_strtod (defaultval,nullptr); - } - - const char * maxval = xml->attribute("max"); - if (maxval != nullptr) { - _max = g_ascii_strtod (maxval,nullptr); - } - - const char * minval = xml->attribute("min"); - if (minval != nullptr) { - _min = g_ascii_strtod (minval,nullptr); - } - - _precision = 1; - const char * precision = xml->attribute("precision"); - if (precision != nullptr) { - _precision = atoi(precision); - } - - /* We're handling this by just killing both values */ - if (_max < _min) { - _max = 10.0; - _min = 0.0; - } - - 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; - } - - return; -} - -/** - * A function to set the \c _value. - * - * This function sets 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. - * - * @param in The value to set to. - * @param doc A document that should be used to set the value. - * @param node The node where the value may be placed. - */ -float ParamFloat::set(float in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) -{ - _value = in; - if (_value > _max) { - _value = _max; - } - if (_value < _min) { - _value = _min; - } - - gchar * prefname = this->pref_name(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setDouble(extension_pref_root + prefname, _value); - g_free(prefname); - - return _value; -} - -void ParamFloat::string(std::string &string) const -{ - char startstring[G_ASCII_DTOSTR_BUF_SIZE]; - g_ascii_dtostr(startstring, G_ASCII_DTOSTR_BUF_SIZE, _value); - string += startstring; - return; -} - -/** 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; -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) : - 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)); - return; - }; - - void val_changed (); -}; /* class ParamFloatAdjustment */ - -/** - * A function to respond to the value_changed signal from the adjustment. - * - * This function just grabs the value from the adjustment and writes - * it to the parameter. Very simple, but yet beautiful. - */ -void ParamFloatAdjustment::val_changed() -{ - //std::cout << "Value Changed to: " << this->get_value() << std::endl; - _pref->set(this->get_value(), _doc, _node); - if (_changeSignal != nullptr) { - _changeSignal->emit(); - } - return; -} - -/** - * Creates a Float Adjustment for a float parameter. - * - * 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) -{ - if (_hidden) { - return nullptr; - } - - 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); - - if (_mode == FULL) { - - Glib::ustring text; - if (_text != nullptr) - text = _text; - UI::Widget::SpinScale *scale = new UI::Widget::SpinScale(text, fadjust, _precision); - scale->set_size_request(400, -1); - scale->show(); - hbox->pack_start(*scale, true, true); - - } - else if (_mode == MINIMAL) { - - Gtk::Label * label = Gtk::manage(new Gtk::Label(_text, Gtk::ALIGN_START)); - label->show(); - hbox->pack_start(*label, true, true); - - auto spin = Gtk::manage(new Inkscape::UI::Widget::SpinButton(fadjust, 0.1, _precision)); - spin->show(); - hbox->pack_start(*spin, false, false); - } - - hbox->show(); - - return dynamic_cast(hbox); -} - - -} /* namespace Extension */ -} /* namespace Inkscape */ diff --git a/src/extension/prefdialog/param/float.h b/src/extension/prefdialog/param/float.h deleted file mode 100644 index c1d0f0f79..000000000 --- a/src/extension/prefdialog/param/float.h +++ /dev/null @@ -1,83 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -#ifndef INK_EXTENSION_PARAMFLOAT_H_SEEN -#define INK_EXTENSION_PARAMFLOAT_H_SEEN - -/* - * Copyright (C) 2005-2007 Authors: - * Ted Gould - * Johan Engelen * - * Jon A. Cruz - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include "parameter.h" - -class SPDocument; - -namespace Gtk { -class Widget; -} - -namespace Inkscape { -namespace XML { -class Node; -} - -namespace Extension { - -class ParamFloat : public Parameter { -public: - enum AppearanceMode { - FULL, MINIMAL - }; - ParamFloat(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml, - AppearanceMode mode); - - /** 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 max () { return _max; } - - float min () { return _min; } - - float precision () { return _precision; } - - 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; - -private: - /** Internal value. */ - float _value; - AppearanceMode _mode; - float _min; - float _max; - int _precision; -}; - -} /* namespace Extension */ -} /* namespace Inkscape */ - -#endif /* INK_EXTENSION_PARAMFLOAT_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/param/int.cpp b/src/extension/prefdialog/param/int.cpp deleted file mode 100644 index 1c41c0834..000000000 --- a/src/extension/prefdialog/param/int.cpp +++ /dev/null @@ -1,201 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (C) 2005-2007 Authors: - * Ted Gould - * Johan Engelen * - * Jon A. Cruz - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include -#include -#include -#include "ui/widget/spinbutton.h" -#include "ui/widget/spin-scale.h" - -#include "xml/node.h" -#include "extension/extension.h" -#include "preferences.h" -#include "int.h" - -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) -{ - 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; - } - - gchar *pref_name = this->pref_name(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - _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; - - if (_value > _max) { - _value = _max; - } - if (_value < _min) { - _value = _min; - } -} - -/** - * A function to set the \c _value. - * This function sets 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. - * - * @param in The value to set to. - * @param doc A document that should be used to set the value. - * @param node The node where the value may be placed. - */ -int ParamInt::set(int in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) -{ - _value = in; - if (_value > _max) { - _value = _max; - } - if (_value < _min) { - _value = _min; - } - - gchar * prefname = this->pref_name(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setInt(extension_pref_root + prefname, _value); - g_free(prefname); - - return _value; -} - -/** 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; -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) : - 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)); - }; - - void val_changed (); -}; /* class ParamIntAdjustment */ - -/** - * A function to respond to the value_changed signal from the adjustment. - * - * This function just grabs the value from the adjustment and writes - * it to the parameter. Very simple, but yet beautiful. - */ -void ParamIntAdjustment::val_changed() -{ - //std::cout << "Value Changed to: " << this->get_value() << std::endl; - _pref->set((int)this->get_value(), _doc, _node); - if (_changeSignal != nullptr) { - _changeSignal->emit(); - } -} - -/** - * Creates a Int Adjustment for a int parameter. - * - * 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) -{ - if (_hidden) { - return nullptr; - } - - 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); - - if (_mode == FULL) { - - Glib::ustring text; - if (_text != nullptr) - text = _text; - UI::Widget::SpinScale *scale = new UI::Widget::SpinScale(text, fadjust, 0); - scale->set_size_request(400, -1); - scale->show(); - hbox->pack_start(*scale, true, true); - } - else if (_mode == MINIMAL) { - Gtk::Label * label = Gtk::manage(new Gtk::Label(_text, Gtk::ALIGN_START)); - label->show(); - hbox->pack_start(*label, true, true); - - auto spin = Gtk::manage(new Inkscape::UI::Widget::SpinButton(fadjust, 1.0, 0)); - spin->show(); - hbox->pack_start(*spin, false, false); - } - - hbox->show(); - - return dynamic_cast(hbox); -} - -void ParamInt::string(std::string &string) const -{ - char startstring[32]; - sprintf(startstring, "%d", _value); - string += startstring; -} - -} // 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/extension/prefdialog/param/int.h b/src/extension/prefdialog/param/int.h deleted file mode 100644 index fac481267..000000000 --- a/src/extension/prefdialog/param/int.h +++ /dev/null @@ -1,80 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -#ifndef INK_EXTENSION_PARAMINT_H_SEEN -#define INK_EXTENSION_PARAMINT_H_SEEN - -/* - * Copyright (C) 2005-2007 Authors: - * Ted Gould - * Johan Engelen * - * Jon A. Cruz - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include "parameter.h" - -class SPDocument; - -namespace Gtk { -class Widget; -} - -namespace Inkscape { -namespace XML { -class Node; -} - -namespace Extension { - -class ParamInt : public Parameter { -public: - enum AppearanceMode { - FULL, MINIMAL - }; - ParamInt(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml, - AppearanceMode mode); - - /** 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 max () { return _max; } - - int min () { return _min; } - - 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; - -private: - /** Internal value. */ - int _value; - AppearanceMode _mode; - int _min; - int _max; -}; - -} /* namespace Extension */ -} /* namespace Inkscape */ - -#endif /* INK_EXTENSION_PARAMINT_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/param/notebook.cpp b/src/extension/prefdialog/param/notebook.cpp deleted file mode 100644 index 838c09d5b..000000000 --- a/src/extension/prefdialog/param/notebook.cpp +++ /dev/null @@ -1,413 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** \file - * Notebook and NotebookPage parameters for extensions. - */ - -/* - * Authors: - * Johan Engelen - * Jon A. Cruz - * - * Copyright (C) 2006 Author - * - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include -#include -#include -#include - -#include - -#include - -#include -#include "preferences.h" - -#include "notebook.h" - -/** - * The root directory in the preferences database for extension - * related parameters. - */ -#define PREF_DIR "extensions" - -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) -{ - - // Read XML to build page - if (xml != nullptr) { - 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, "param") || !strcmp(chname, "_param")) { - Parameter * param; - param = Parameter::make(child_repr, ext); - if (param != nullptr) parameters.push_back(param); - } - child_repr = child_repr->next(); - } - } -} - -ParamNotebook::ParamNotebookPage::~ParamNotebookPage () -{ - //destroy parameters - for (auto param:parameters) { - delete param; - } -} - -/** 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 */ - } - - /* 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) -{ - if (_hidden) { - return nullptr; - } - - Gtk::VBox * vbox = Gtk::manage(new Gtk::VBox); - vbox->set_border_width(Parameter::GUI_BOX_MARGIN); - 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); - } - } - } - - vbox->show(); - - return dynamic_cast(vbox); -} - -/** Search the parameter's name in the page content. */ -Parameter *ParamNotebook::ParamNotebookPage::get_param(const gchar * name) -{ - if (name == nullptr) { - throw Extension::param_not_exist(); - } - if (this->parameters.empty()) { - // the list of parameters is empty - throw Extension::param_not_exist(); - } - - for (auto param:parameters) { - if (!strcmp(param->name(), name)) { - return param; - } - } - - return nullptr; -} - -/** 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) -{ - // Read XML tree to add pages: - if (xml != nullptr) { - 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); - } - 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(); - } - - gchar * pref_name = this->pref_name(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring paramval = 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 -} - -ParamNotebook::~ParamNotebook () -{ - //destroy pages - for (auto page:pages) { - delete page; - } - g_free(_value); -} - - -/** - * A function to set the \c _value. - * - * This function sets 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 number of the page which value must be 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 *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; - - if (_value != nullptr) g_free(_value); - _value = g_strdup(page->name()); - - gchar * prefname = this->pref_name(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString(extension_pref_root + prefname, _value); - g_free(prefname); - - return _value; -} - -void ParamNotebook::string(std::list &list) const -{ - std::string param_string; - param_string += "--"; - param_string += name(); - param_string += "="; - - param_string += "\""; - param_string += _value; // the name of the current page - param_string += "\""; - list.insert(list.end(), param_string); - - for (auto page:pages) { - page->paramString(list); - } -} - -/** A special category of Gtk::Notebook to handle notebook parameters. */ -class ParamNotebookWdg : public Gtk::Notebook { -private: - 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. - */ - 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)); - }; - void changed_page(Gtk::Widget *page, guint pagenum); - bool activated; -}; - -/** - * Respond to the selected page of notebook changing. - * This function responds to the changing by reporting it to - * ParamNotebook. The change is only reported when the notebook - * is actually visible. This to exclude 'fake' changes when the - * notebookpages are added or removed. - */ -void ParamNotebookWdg::changed_page(Gtk::Widget * /*page*/, guint pagenum) -{ - if (get_visible()) { - _pref->set((int)pagenum, _doc, _node); - } -} - -/** Search the parameter's name in the notebook content. */ -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); - if (subparam) { - return subparam; - } - } - - return nullptr; -} - - -/** - * Creates a Notebook widget for a notebook parameter. - * - * Builds a notebook and puts pages in it. - */ -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? - } - } - - nb->show(); - - if (pagenr >= 0) nb->set_current_page(pagenr); - - return dynamic_cast(nb); -} - - -} // 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/extension/prefdialog/param/notebook.h b/src/extension/prefdialog/param/notebook.h deleted file mode 100644 index dd7154f06..000000000 --- a/src/extension/prefdialog/param/notebook.h +++ /dev/null @@ -1,117 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -#ifndef INK_EXTENSION_PARAMNOTEBOOK_H_SEEN -#define INK_EXTENSION_PARAMNOTEBOOK_H_SEEN - -/** \file - * Notebook parameter for extensions. - */ - -/* - * Author: - * Johan Engelen - * Jon A. Cruz - * - * Copyright (C) 2006 Author - * - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include "parameter.h" - -namespace Gtk { -class Widget; -} - -namespace Inkscape { -namespace Extension { - -class Extension; - - -/** A class to represent a notebookparameter 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; - - /** - * A class to represent the pages of a notebookparameter 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 */ - - 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() 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; - }; /* class ParamNotebookPage */ - - - 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() 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. - * @return A string with the 'value' and all the parameters on all pages as command line arguments. - */ - void string (std::list &list) const override; - - // Explicitly call superclass version to avoid method being hidden. - void string(std::string &string) const override {return Parameter::string(string);} - - - 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); -}; /* class ParamNotebook */ - - - - - -} // namespace Extension -} // namespace Inkscape - -#endif /* INK_EXTENSION_PARAMNOTEBOOK_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/param/parameter.cpp b/src/extension/prefdialog/param/parameter.cpp deleted file mode 100644 index a07821441..000000000 --- a/src/extension/prefdialog/param/parameter.cpp +++ /dev/null @@ -1,415 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** @file - * Parameters for extensions. - */ -/* Author: - * Ted Gould - * Johan Engelen - * Jon A. Cruz - * - * Copyright (C) 2005-2007 Authors - * - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#ifdef linux // does the dollar sign need escaping when passed as string parameter? -# define ESCAPE_DOLLAR_COMMANDLINE -#endif - -#include -#include - -#include -#include - -#include "bool.h" -#include "color.h" -#include "description.h" -#include "enum.h" -#include "./float.h" -#include "int.h" -#include "notebook.h" -#include "parameter.h" -#include "radiobutton.h" -#include "./string.h" - -#include "extension/extension.h" - -#include "object/sp-defs.h" - -#include "ui/widget/color-notebook.h" - -#include "xml/node.h" - - -namespace Inkscape { -namespace Extension { - -Parameter *Parameter::make(Inkscape::XML::Node *in_repr, Inkscape::Extension::Extension *in_ext) -{ - const char *name = in_repr->attribute("name"); - const char *type = in_repr->attribute("type"); - - // we can't create a parameter without type - if (!type) { - return nullptr; - } - // also require name unless it's a pure UI element that does not store its value - if (!name) { - static std::vector ui_elements = {"description"}; - if (std::find(ui_elements.begin(), ui_elements.end(), type) == ui_elements.end()) { - return nullptr; - } - } - - const char *text = in_repr->attribute("gui-text"); - if (text == nullptr) { - text = in_repr->attribute("_gui-text"); - if (text == nullptr) { - // text = ""; // probably better to require devs to explicitly set an empty gui-text if this is what they want - } else { - const char *context = in_repr->attribute("msgctxt"); - if (context != nullptr) { - text = g_dpgettext2(nullptr, context, text); - } else { - text = _(text); - } - } - } - const char *description = in_repr->attribute("gui-description"); - if (description == nullptr) { - description = in_repr->attribute("_gui-description"); - if (description != nullptr) { - const char *context = in_repr->attribute("msgctxt"); - if (context != nullptr) { - description = g_dpgettext2(nullptr, context, description); - } else { - description = _(description); - } - } - } - bool hidden = false; - { - const char *gui_hide = in_repr->attribute("gui-hidden"); - if (gui_hide != nullptr) { - if (strcmp(gui_hide, "1") == 0 || - strcmp(gui_hide, "true") == 0) { - hidden = true; - } - /* else stays false */ - } - } - int indent = 0; - { - const char *indent_attr = in_repr->attribute("indent"); - if (indent_attr != nullptr) { - if (strcmp(indent_attr, "true") == 0) { - indent = 1; - } else { - indent = atoi(indent_attr); - } - } - } - const gchar* appearance = in_repr->attribute("appearance"); - - Parameter * param = nullptr; - if (!strcmp(type, "boolean")) { - param = new ParamBool(name, text, description, hidden, indent, in_ext, in_repr); - } else if (!strcmp(type, "int")) { - if (appearance && !strcmp(appearance, "full")) { - param = new ParamInt(name, text, description, hidden, indent, in_ext, in_repr, ParamInt::FULL); - } else { - param = new ParamInt(name, text, description, hidden, indent, in_ext, in_repr, ParamInt::MINIMAL); - } - } else if (!strcmp(type, "float")) { - if (appearance && !strcmp(appearance, "full")) { - param = new ParamFloat(name, text, description, hidden, indent, in_ext, in_repr, ParamFloat::FULL); - } else { - param = new ParamFloat(name, text, description, hidden, indent, in_ext, in_repr, ParamFloat::MINIMAL); - } - } else if (!strcmp(type, "string")) { - param = new ParamString(name, text, description, hidden, indent, in_ext, in_repr); - gchar const * max_length = in_repr->attribute("max_length"); - if (max_length != nullptr) { - ParamString * ps = dynamic_cast(param); - ps->setMaxLength(atoi(max_length)); - } - } else if (!strcmp(type, "description")) { - ParamDescription::AppearanceMode appearance_mode = ParamDescription::DESCRIPTION; - if (appearance) { - if (!strcmp(appearance, "header")) { - appearance_mode = ParamDescription::HEADER; - } else if (!strcmp(appearance, "url")) { - appearance_mode = ParamDescription::URL; - } - } - param = new ParamDescription(name, text, description, hidden, indent, in_ext, in_repr, appearance_mode); - } else if (!strcmp(type, "enum")) { - param = new ParamComboBox(name, text, description, hidden, indent, in_ext, in_repr); - } else if (!strcmp(type, "notebook")) { - param = new ParamNotebook(name, text, description, hidden, indent, in_ext, in_repr); - } else if (!strcmp(type, "optiongroup")) { - if (appearance && !strcmp(appearance, "minimal")) { - param = new ParamRadioButton(name, text, description, hidden, indent, in_ext, in_repr, ParamRadioButton::MINIMAL); - } else { - param = new ParamRadioButton(name, text, description, hidden, indent, in_ext, in_repr, ParamRadioButton::FULL); - } - } else if (!strcmp(type, "color")) { - param = new ParamColor(name, text, description, hidden, indent, in_ext, in_repr); - } - - // Note: param could equal NULL - return param; -} - -bool Parameter::get_bool(SPDocument const *doc, Inkscape::XML::Node const *node) const -{ - ParamBool const *boolpntr = dynamic_cast(this); - if (!boolpntr) { - throw Extension::param_not_bool_param(); - } - return boolpntr->get(doc, node); -} - -int Parameter::get_int(SPDocument const *doc, Inkscape::XML::Node const *node) const -{ - ParamInt const *intpntr = dynamic_cast(this); - if (!intpntr) { - throw Extension::param_not_int_param(); - } - return intpntr->get(doc, node); -} - -float Parameter::get_float(SPDocument const *doc, Inkscape::XML::Node const *node) const -{ - ParamFloat const *floatpntr = dynamic_cast(this); - if (!floatpntr) { - throw Extension::param_not_float_param(); - } - return floatpntr->get(doc, node); -} - -gchar const *Parameter::get_string(SPDocument const *doc, Inkscape::XML::Node const *node) const -{ - ParamString const *stringpntr = dynamic_cast(this); - if (!stringpntr) { - throw Extension::param_not_string_param(); - } - return stringpntr->get(doc, node); -} - -gchar const *Parameter::get_enum(SPDocument const *doc, Inkscape::XML::Node const *node) const -{ - ParamComboBox const *param = dynamic_cast(this); - if (!param) { - throw Extension::param_not_enum_param(); - } - return param->get(doc, node); -} - -bool Parameter::get_enum_contains(gchar const * value, SPDocument const *doc, Inkscape::XML::Node const *node) const -{ - ParamComboBox const *param = dynamic_cast(this); - if (!param) { - throw Extension::param_not_enum_param(); - } - return param->contains(value, doc, node); -} - -gchar const *Parameter::get_optiongroup(SPDocument const *doc, Inkscape::XML::Node const * node) const -{ - ParamRadioButton const *param = dynamic_cast(this); - if (!param) { - throw Extension::param_not_optiongroup_param(); - } - return param->get(doc, node); -} - -guint32 Parameter::get_color(const SPDocument* doc, Inkscape::XML::Node const *node) const -{ - ParamColor const *param = dynamic_cast(this); - if (!param) { - throw Extension::param_not_color_param(); - } - return param->get(doc, node); -} - -bool Parameter::set_bool(bool in, SPDocument * doc, Inkscape::XML::Node * node) -{ - ParamBool * boolpntr = dynamic_cast(this); - if (boolpntr == nullptr) - throw Extension::param_not_bool_param(); - return boolpntr->set(in, doc, node); -} - -int Parameter::set_int(int in, SPDocument * doc, Inkscape::XML::Node * node) -{ - ParamInt * intpntr = dynamic_cast(this); - if (intpntr == nullptr) - throw Extension::param_not_int_param(); - return intpntr->set(in, doc, node); -} - -/** Wrapper to cast to the object and use it's function. */ -float -Parameter::set_float (float in, SPDocument * doc, Inkscape::XML::Node * node) -{ - ParamFloat * floatpntr; - floatpntr = dynamic_cast(this); - if (floatpntr == nullptr) - throw Extension::param_not_float_param(); - return floatpntr->set(in, doc, node); -} - -/** Wrapper to cast to the object and use it's function. */ -gchar const * -Parameter::set_string (gchar const * in, SPDocument * doc, Inkscape::XML::Node * node) -{ - ParamString * stringpntr = dynamic_cast(this); - if (stringpntr == nullptr) - throw Extension::param_not_string_param(); - return stringpntr->set(in, doc, node); -} - -gchar const * Parameter::set_optiongroup( gchar const * in, SPDocument * doc, Inkscape::XML::Node * node ) -{ - ParamRadioButton *param = dynamic_cast(this); - if (!param) { - throw Extension::param_not_optiongroup_param(); - } - return param->set(in, doc, node); -} - -gchar const *Parameter::set_enum( gchar const * in, SPDocument * doc, Inkscape::XML::Node * node ) -{ - ParamComboBox *param = dynamic_cast(this); - if (!param) { - throw Extension::param_not_enum_param(); - } - return param->set(in, doc, node); -} - - -/** Wrapper to cast to the object and use it's function. */ -guint32 -Parameter::set_color (guint32 in, SPDocument * doc, Inkscape::XML::Node * node) -{ - ParamColor* param = dynamic_cast(this); - if (param == nullptr) - throw Extension::param_not_color_param(); - return param->set(in, doc, node); -} - - -/** Oop, now that we need a parameter, we need it's name. */ -Parameter::Parameter(gchar const * name, gchar const * text, gchar const * description, bool hidden, int indent, Inkscape::Extension::Extension * ext) : - _description(nullptr), - _text(nullptr), - _hidden(hidden), - _indent(indent), - _extension(ext), - _name(nullptr) -{ - if (name != nullptr) { - _name = g_strdup(name); - } - - if (description != nullptr) { - _description = g_strdup(description); - } - - if (text != nullptr) { - _text = g_strdup(text); - } else { - _text = g_strdup(name); - } - - return; -} - -/** Oop, now that we need a parameter, we need it's name. */ -Parameter::Parameter (gchar const * name, gchar const * text, Inkscape::Extension::Extension * ext) : - _description(nullptr), - _text(nullptr), - _hidden(false), - _indent(0), - _extension(ext), - _name(nullptr) -{ - if (name != nullptr) { - _name = g_strdup(name); - } - if (text != nullptr) { - _text = g_strdup(text); - } else { - _text = g_strdup(name); - } - - return; -} - -Parameter::~Parameter() -{ - g_free(_name); - _name = nullptr; - - g_free(_text); - _text = nullptr; - - g_free(_description); - _description = nullptr; -} - -gchar *Parameter::pref_name() const -{ - return g_strdup_printf("%s.%s", _extension->get_id(), _name); -} - -/** Basically, if there is no widget pass a NULL. */ -Gtk::Widget * -Parameter::get_widget (SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal * /*changeSignal*/) -{ - return nullptr; -} - -/** If I'm not sure which it is, just don't return a value. */ -void Parameter::string(std::string &/*string*/) const -{ - // TODO investigate clearing the target string. -} - -void Parameter::string(std::list &list) const -{ - std::string value; - string(value); - if (!value.empty()) { - std::string final; - final += "--"; - final += name(); - final += "="; - final += value; - - list.insert(list.end(), final); - } -} - -Parameter *Parameter::get_param(gchar const * /*name*/) -{ - return nullptr; -} - -Glib::ustring const extension_pref_root = "/extensions/"; - -} // 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/extension/prefdialog/param/parameter.h b/src/extension/prefdialog/param/parameter.h deleted file mode 100644 index cc10787e6..000000000 --- a/src/extension/prefdialog/param/parameter.h +++ /dev/null @@ -1,214 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** @file - * Parameters for extensions. - */ -/* Authors: - * Ted Gould - * Jon A. Cruz - * - * Copyright (C) 2005-2006 Authors - * - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#ifndef SEEN_INK_EXTENSION_PARAM_H__ -#define SEEN_INK_EXTENSION_PARAM_H__ - -#include - -#include - -class SPDocument; - -namespace Gtk { -class Widget; -} - -namespace Inkscape { -namespace XML { -class Node; -} - -namespace Extension { - -class Extension; - - -/** - * The root directory in the preferences database for extension-related parameters. - * - * The directory path has both a leading and a trailing slash, so that extension_pref_root + pref_name works - * without having to append a separator. - */ -extern Glib::ustring const extension_pref_root; - -/** - * A class to represent the parameter of an extension. - * - * This is really a super class that allows them to abstract all - * the different types of parameters into some that can be passed - * around. There is also a few functions that are used by all the - * different parameters. - */ -class Parameter { - -public: - Parameter(gchar const *name, - gchar const *text, - gchar const *description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext); - - Parameter(gchar const *name, - gchar const *text, - Inkscape::Extension::Extension * ext); - - virtual ~Parameter(); - - /** Wrapper to cast to the object and use its function. */ - bool get_bool(SPDocument const *doc, Inkscape::XML::Node const *node) const; - - /** Wrapper to cast to the object and use it's function. */ - int get_int(SPDocument const *doc, Inkscape::XML::Node const *node) const; - - /** Wrapper to cast to the object and use it's function. */ - float get_float(SPDocument const *doc, Inkscape::XML::Node const *node) const; - - /** Wrapper to cast to the object and use it's function. */ - gchar const *get_string(SPDocument const *doc, Inkscape::XML::Node const *node) const; - - guint32 get_color(SPDocument const *doc, Inkscape::XML::Node const *node) const; - - /** Wrapper to cast to the object and use it's function. */ - gchar const *get_enum(SPDocument const *doc, Inkscape::XML::Node const *node) const; - - /** Wrapper to cast to the object and use it's function. */ - bool get_enum_contains(gchar const * value, SPDocument const *doc, Inkscape::XML::Node const *node) const; - - /** Wrapper to cast to the object and use it's function. */ - gchar const *get_optiongroup(SPDocument const * doc, Inkscape::XML::Node const *node) const; - - /** Wrapper to cast to the object and use it's function. */ - bool set_bool(bool in, SPDocument * doc, Inkscape::XML::Node * node); - - /** Wrapper to cast to the object and use it's function. */ - int set_int(int in, SPDocument * doc, Inkscape::XML::Node * node); - - float set_float(float in, SPDocument * doc, Inkscape::XML::Node * node); - - gchar const *set_optiongroup(gchar const *in, SPDocument * doc, Inkscape::XML::Node *node); - - gchar const *set_enum(gchar const * in, SPDocument * doc, Inkscape::XML::Node *node); - - gchar const *set_string(gchar const * in, SPDocument * doc, Inkscape::XML::Node * node); - - guint32 set_color(guint32 in, SPDocument * doc, Inkscape::XML::Node * node); - - gchar const * name() const {return _name;} - - /** - * This function creates a parameter that can be used later. This - * is typically done in the creation of the extension and defined - * in the XML file describing the extension (it's private so people - * have to use the system) :) - * - * 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 or a type in the XML, then no parameter 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. - * - * @param in_repr The XML describing the parameter. - * @return a pointer to a new Parameter if applicable, null otherwise.. - */ - static Parameter *make(Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * in_ext); - - virtual Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal); - - gchar const * get_tooltip() const { return _description; } - - /** Indicates if the GUI for this parameter is hidden or not */ - bool get_hidden() const { return _hidden; } - - /** Indentation level of the parameter */ - int get_indent() const { return _indent; } - - virtual void string(std::list &list) const; - - /** - * Gets the current value of the parameter in a string form. - * @return A string with the 'value'. - */ - virtual void string(std::string &string) const; - - /** All the code in Notebook::get_param to get the notebook content. */ - virtual Parameter *get_param(gchar const *name); - - - /** Recommended margin of boxes containing multiple Parameters (in px) */ - const static int GUI_BOX_MARGIN = 10; - /** Recommended spacing between multiple Parameters packed into a box (in px) */ - const static int GUI_BOX_SPACING = 4; - /** Recommended spacing between the widgets making up a single Parameter (e.g. label and input) (in px) */ - const static int GUI_PARAM_WIDGETS_SPACING = 4; - /** Recommended indentation width of parameters (in px) */ - const static int GUI_INDENTATION = 12; - /** Recommended maximum line length for wrapping textual parameters (in chars) */ - const static int GUI_MAX_LINE_LENGTH = 60; - - -protected: - /** Parameter text to show as the GUI label. */ - gchar * _text; - - /** Extended description of the parameter (crrently shown as tooltip on hover). */ - gchar * _description; - - /** Whether the parameter is visible. */ - bool _hidden; - - /** Indentation level of the parameter. */ - int _indent; - - - /* **** funcs **** */ - - /** - * Build the name to write the parameter from the extension's ID and the name of this parameter. - */ - gchar *pref_name() const; - - -private: - /** Which extension is this parameter attached to. */ - Inkscape::Extension::Extension *_extension; - - /** The name of this parameter. */ - gchar *_name; -}; - -} // namespace Extension -} // namespace Inkscape - -#endif // SEEN_INK_EXTENSION_PARAM_H__ - -/* - 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/extension/prefdialog/param/radiobutton.cpp b/src/extension/prefdialog/param/radiobutton.cpp deleted file mode 100644 index 8c1d6a5f7..000000000 --- a/src/extension/prefdialog/param/radiobutton.cpp +++ /dev/null @@ -1,349 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** \file - * extension parameter for radiobuttons. - * - * It uses a Gtk:ComboBoxText widget in the extension UI. - */ - -/* - * 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 -#include -#include -#include - -#include "xml/node.h" -#include "extension/extension.h" -#include "preferences.h" - -#include "radiobutton.h" - -/** - * The root directory in the preferences database for extension - * related parameters. - */ -#define PREF_DIR "extensions" - -namespace Inkscape { -namespace Extension { - -/* 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. */ - -ParamRadioButton::ParamRadioButton(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) -{ - // Read XML tree to add enumeration items: - // printf("Extension Constructor: "); - if (xml != nullptr) { - Inkscape::XML::Node *child_repr = xml->firstChild(); - while (child_repr != nullptr) { - char const * chname = child_repr->name(); - if (!strcmp(chname, INKSCAPE_EXTENSION_NS "option") || !strcmp(chname, INKSCAPE_EXTENSION_NS "_option")) { - Glib::ustring * newtext = nullptr; - Glib::ustring * newvalue = nullptr; - const char * contents = child_repr->firstChild()->content(); - - if (contents != nullptr) { - // don't translate when 'item' but do translate when '_option' - if (!strcmp(chname, INKSCAPE_EXTENSION_NS "_option")) { - if (child_repr->attribute("msgctxt") != nullptr) { - newtext = new Glib::ustring(g_dpgettext2(nullptr, child_repr->attribute("msgctxt"), contents)); - } else { - newtext = new Glib::ustring(_(contents)); - } - } else { - newtext = new Glib::ustring(contents); - } - } else { - continue; - } - - - const char * val = child_repr->attribute("value"); - if (val != nullptr) { - newvalue = new Glib::ustring(val); - } else { - newvalue = new Glib::ustring(contents); - } - - if ( (newtext) && (newvalue) ) { // logical error if this is not true here - choices.push_back(new optionentry(newvalue, newtext)); - } - } - child_repr = child_repr->next(); - } - } - - // Initialize _value with the default value from xml - // for simplicity : default to the contents of the first xml-child - const char * defaultval = nullptr; - if (!choices.empty()) { - defaultval = (static_cast (choices[0]))->value->c_str(); - } - - gchar * pref_name = this->pref_name(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring paramval = 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 - } -} - -ParamRadioButton::~ParamRadioButton () -{ - //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 *ParamRadioButton::set(const gchar * in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) -{ - if (in == nullptr) { - return nullptr; /* Can't have NULL string */ - } - - Glib::ustring * settext = nullptr; - for (auto entr:choices) { - if ( !entr->value->compare(in) ) { - settext = entr->value; - break; // break out of for loop - } - } - if (settext) { - if (_value != nullptr) { - g_free(_value); - } - _value = g_strdup(settext->c_str()); - gchar * prefname = this->pref_name(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString(extension_pref_root + prefname, _value); - g_free(prefname); - } else { - g_warning("Couldn't set ParamRadioButton %s", in); - } - - return _value; -} - -void ParamRadioButton::string(std::string &string) const -{ - string += _value; -} - -/** A special radiobutton class to use in ParamRadioButton. */ -class ParamRadioButtonWdg : public Gtk::RadioButton { -private: - ParamRadioButton * _pref; - SPDocument * _doc; - Inkscape::XML::Node * _node; - sigc::signal * _changeSignal; -public: - /** - * Build a string preference for the given parameter. - * @param pref Where to put the radiobutton's string when it is selected. - */ - ParamRadioButtonWdg ( Gtk::RadioButtonGroup& group, const Glib::ustring& label, - ParamRadioButton * pref, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal ) : - Gtk::RadioButton(group, label), _pref(pref), _doc(doc), _node(node), _changeSignal(changeSignal) { - add_changesignal(); - }; - ParamRadioButtonWdg ( const Glib::ustring& label, - ParamRadioButton * pref, SPDocument * doc, Inkscape::XML::Node * node , sigc::signal * changeSignal) : - Gtk::RadioButton(label), _pref(pref), _doc(doc), _node(node), _changeSignal(changeSignal) { - add_changesignal(); - }; - void add_changesignal() { - this->signal_toggled().connect(sigc::mem_fun(this, &ParamRadioButtonWdg::changed)); - }; - void changed (); -}; - -/** - * Respond to the selected radiobutton changing. - * - * This function responds to the radiobutton selection changing by grabbing the value - * from the text box and putting it in the parameter. - */ -void ParamRadioButtonWdg::changed() -{ - if (this->get_active()) { - Glib::ustring value = _pref->value_from_label(this->get_label()); - _pref->set(value.c_str(), _doc, _node); - } - if (_changeSignal != nullptr) { - _changeSignal->emit(); - } -} - - -class ComboWdg : public Gtk::ComboBoxText { -private: - ParamRadioButton* _base; - SPDocument* _doc; - Inkscape::XML::Node* _node; - sigc::signal * _changeSignal; - -public: - ComboWdg(ParamRadioButton* base, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) : - _base(base), - _doc(doc), - _node(node), - _changeSignal(changeSignal) - { - this->signal_changed().connect(sigc::mem_fun(this, &ComboWdg::changed)); - } - ~ComboWdg() override = default; - void changed (); -}; - -void ComboWdg::changed() -{ - if ( _base ) { - Glib::ustring value = _base->value_from_label(get_active_text()); - _base->set(value.c_str(), _doc, _node); - } - if (_changeSignal != nullptr) { - _changeSignal->emit(); - } -} - -/** - * Returns the value for the options label parameter - */ -Glib::ustring ParamRadioButton::value_from_label(const Glib::ustring label) -{ - Glib::ustring value = ""; - - for ( auto entr:choices) { - if ( !entr->text->compare(label) ) { - value = *(entr->value); - break; - } - } - - return value; - -} - -/** - * Creates a combobox widget for an enumeration parameter. - */ -Gtk::Widget * ParamRadioButton::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) -{ - if (_hidden) { - return nullptr; - } - - auto hbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, Parameter::GUI_PARAM_WIDGETS_SPACING)); - hbox->set_homogeneous(false); - auto vbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0)); - vbox->set_homogeneous(false); - - Gtk::Label * label = Gtk::manage(new Gtk::Label(_text, Gtk::ALIGN_START, Gtk::ALIGN_START)); - label->show(); - hbox->pack_start(*label, false, false); - - Gtk::ComboBoxText* cbt = nullptr; - bool comboSet = false; - if (_mode == MINIMAL) { - cbt = Gtk::manage(new ComboWdg(this, doc, node, changeSignal)); - cbt->show(); - vbox->pack_start(*cbt, false, false); - } - - // add choice strings as radiobuttons - // and select last selected option (_value) - Gtk::RadioButtonGroup group; - for (auto entr:choices) { - Glib::ustring * text = entr->text; - switch ( _mode ) { - case MINIMAL: - { - cbt->append(*text); - if (!entr->value->compare(_value)) { - cbt->set_active_text(*text); - comboSet = true; - } - } - break; - case COMPACT: - case FULL: - { - ParamRadioButtonWdg * radio = Gtk::manage(new ParamRadioButtonWdg(group, *text, this, doc, node, changeSignal)); - radio->show(); - vbox->pack_start(*radio, true, true); - if (!entr->value->compare(_value)) { - radio->set_active(); - } - } - break; - } - } - - if ( (_mode == MINIMAL) && !comboSet) { - cbt->set_active(0); - } - - vbox->show(); - hbox->pack_end(*vbox, false, false); - 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/param/radiobutton.h b/src/extension/prefdialog/param/radiobutton.h deleted file mode 100644 index 48d470a01..000000000 --- a/src/extension/prefdialog/param/radiobutton.h +++ /dev/null @@ -1,107 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -#ifndef INK_EXTENSION_PARAMRADIOBUTTON_H_SEEN -#define INK_EXTENSION_PARAMRADIOBUTTON_H_SEEN - -/** \file - * Radiobutton 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 "parameter.h" - -namespace Gtk { -class Widget; -} - -namespace Inkscape { -namespace Extension { - -class Extension; - - - -// \brief A class to represent a radiobutton parameter of an extension -class ParamRadioButton : public Parameter { -public: - enum AppearanceMode { - FULL, COMPACT, MINIMAL - }; - - ParamRadioButton(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml, - AppearanceMode mode); - ~ParamRadioButton() 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; - - Glib::ustring value_from_label(const Glib::ustring label); - - const gchar *get(const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) const { return _value; } - - const gchar *set(const gchar *in, SPDocument *doc, Inkscape::XML::Node *node); - -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; - AppearanceMode _mode; - - /* 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 optionentry { - public: - optionentry (Glib::ustring * val, Glib::ustring * txt) { - value = val; - text = txt; - } - ~optionentry() { - delete value; - delete text; - } - Glib::ustring * value; - Glib::ustring * text; - }; - - std::vector choices; /**< A table to store the choice strings */ - -}; /* class ParamRadioButton */ - - - - - -} /* namespace Extension */ -} /* namespace Inkscape */ - -#endif /* INK_EXTENSION_PARAMRADIOBUTTON_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:fileencoding=utf-8:textwidth=99 : diff --git a/src/extension/prefdialog/param/string.cpp b/src/extension/prefdialog/param/string.cpp deleted file mode 100644 index c1986cf92..000000000 --- a/src/extension/prefdialog/param/string.cpp +++ /dev/null @@ -1,181 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (C) 2005-2007 Authors: - * Ted Gould - * Johan Engelen * - * Jon A. Cruz - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include -#include -#include - -#include - -#include "xml/node.h" -#include "extension/extension.h" -#include "./string.h" -#include "preferences.h" -#include - -namespace Inkscape { -namespace Extension { - - -/** Free the allocated data. */ -ParamString::~ParamString() -{ - g_free(_value); - _value = nullptr; -} - -/** - * A function to set the \c _value. - * - * This function sets 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 to. - * @param doc A document that should be used to set the value. - * @param node The node where the value may be placed. - */ -const gchar * ParamString::set(const gchar * in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) -{ - if (in == nullptr) { - return nullptr; /* Can't have NULL string */ - } - - if (_value != nullptr) { - g_free(_value); - } - - _value = g_strdup(in); - - gchar * prefname = this->pref_name(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString(extension_pref_root + prefname, _value); - g_free(prefname); - - return _value; -} - -void ParamString::string(std::string &string) const -{ - if (_value) { - string += _value; - } -} - -/** Initialize the object, to do that, copy the data. */ -ParamString::ParamString(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 * defaultval = nullptr; - if (xml->firstChild() != nullptr) { - defaultval = xml->firstChild()->content(); - } - - gchar * pref_name = this->pref_name(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Glib::ustring paramval = prefs->getString(extension_pref_root + pref_name); - g_free(pref_name); - - if (!paramval.empty()) { - defaultval = paramval.data(); - } - if (defaultval != nullptr) { - char const * chname = xml->name(); - if (!strcmp(chname, INKSCAPE_EXTENSION_NS "_param")) { - if (xml->attribute("msgctxt") != nullptr) { - _value = g_strdup(g_dpgettext2(nullptr, xml->attribute("msgctxt"), defaultval)); - } else { - _value = g_strdup(_(defaultval)); - } - } else { - _value = g_strdup(defaultval); - } - } - - _max_length = 0; -} - -/** A special type of Gtk::Entry to handle string parameteres. */ -class ParamStringEntry : public Gtk::Entry { -private: - ParamString * _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. - */ - ParamStringEntry (ParamString * pref, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) : - Gtk::Entry(), _pref(pref), _doc(doc), _node(node), _changeSignal(changeSignal) { - if (_pref->get(nullptr, nullptr) != nullptr) { - this->set_text(Glib::ustring(_pref->get(nullptr, nullptr))); - } - this->set_max_length(_pref->getMaxLength()); //Set the max length - default zero means no maximum - this->signal_changed().connect(sigc::mem_fun(this, &ParamStringEntry::changed_text)); - }; - void changed_text (); -}; - - -/** - * 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 ParamStringEntry::changed_text() -{ - Glib::ustring data = this->get_text(); - _pref->set(data.c_str(), _doc, _node); - if (_changeSignal != nullptr) { - _changeSignal->emit(); - } -} - -/** - * Creates a text box for the string parameter. - * - * Builds a hbox with a label and a text box in it. - */ -Gtk::Widget * ParamString::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); - - ParamStringEntry * textbox = new ParamStringEntry(this, doc, node, changeSignal); - textbox->show(); - hbox->pack_start(*textbox, true, true); - - hbox->show(); - - return dynamic_cast(hbox); -} - -} /* namespace Extension */ -} /* namespace Inkscape */ diff --git a/src/extension/prefdialog/param/string.h b/src/extension/prefdialog/param/string.h deleted file mode 100644 index 7c094d394..000000000 --- a/src/extension/prefdialog/param/string.h +++ /dev/null @@ -1,67 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -#ifndef INK_EXTENSION_PARAMSTRING_H_SEEN -#define INK_EXTENSION_PARAMSTRING_H_SEEN - -/* - * Copyright (C) 2005-2007 Authors: - * Ted Gould - * Johan Engelen * - * Jon A. Cruz - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include "parameter.h" - -namespace Inkscape { -namespace Extension { - -class ParamString : public Parameter { -private: - /** \brief Internal value. This should point to a string that has - been allocated in memory. And should be free'd. */ - gchar * _value; - /** \brief Internal value. This indicates the maximum length of the string. Zero meaning unlimited. - */ - gint _max_length; -public: - ParamString(const gchar * name, - const gchar * text, - const gchar * description, - bool hidden, - int indent, - Inkscape::Extension::Extension * ext, - Inkscape::XML::Node * xml); - ~ParamString() override; - - /** \brief Returns \c _value, with a \i const to protect it. */ - const gchar *get(SPDocument const * /*doc*/, Inkscape::XML::Node const * /*node*/) const { return _value; } - - const gchar * set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node); - - 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; - - void setMaxLength(int maxLength) { _max_length = maxLength; } - int getMaxLength() { return _max_length; } -}; - - -} // namespace Extension -} // namespace Inkscape - -#endif /* INK_EXTENSION_PARAMSTRING_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-bool.cpp b/src/extension/prefdialog/parameter-bool.cpp new file mode 100644 index 000000000..8277d3120 --- /dev/null +++ b/src/extension/prefdialog/parameter-bool.cpp @@ -0,0 +1,155 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Jon A. Cruz + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "parameter-bool.h" + +#include +#include +#include +#include + +#include "xml/node.h" +#include "extension/extension.h" +#include "preferences.h" + +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) +{ + const char * defaultval = nullptr; + if (xml->firstChild() != nullptr) { + defaultval = xml->firstChild()->content(); + } + + if (defaultval != nullptr && (!strcmp(defaultval, "true") || !strcmp(defaultval, "1"))) { + _value = true; + } else { + _value = false; + } + + 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(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setBool(extension_pref_root + prefname, _value); + g_free(prefname); + + return _value; +} + +bool ParamBool::get(const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) const +{ + return _value; +} + +/** + * A check button which is Param aware. It works with the + * parameter to change it's value as the check button changes + * value. + */ +class ParamBoolCheckButton : public Gtk::CheckButton { +public: + /** + * Initialize the check button. + * This function sets the value of the checkbox to be that of the + * parameter, and then sets up a callback to \c on_toggle. + * + * @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) : + 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)); + return; + } + + /** + * A function to respond to the check box changing. + * Adjusts the value of the preference to match that in the check box. + */ + void on_toggle (); + +private: + /** Param to change. */ + ParamBool * _pref; + SPDocument * _doc; + Inkscape::XML::Node * _node; + sigc::signal * _changeSignal; +}; + +void ParamBoolCheckButton::on_toggle() +{ + _pref->set(this->get_active(), nullptr /**\todo fix this */, nullptr); + if (_changeSignal != nullptr) { + _changeSignal->emit(); + } + return; +} + +void ParamBool::string(std::string &string) const +{ + if (_value) { + string += "true"; + } else { + string += "false"; + } + + return; +} + +Gtk::Widget *ParamBool::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) +{ + if (_hidden) { + return nullptr; + } + + auto hbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, Parameter::GUI_PARAM_WIDGETS_SPACING)); + hbox->set_homogeneous(false); + + ParamBoolCheckButton * checkbox = Gtk::manage(new ParamBoolCheckButton(this, _text, doc, node, changeSignal)); + checkbox->show(); + hbox->pack_start(*checkbox, false, false); + + 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/extension/prefdialog/parameter-bool.h b/src/extension/prefdialog/parameter-bool.h new file mode 100644 index 000000000..9864cac38 --- /dev/null +++ b/src/extension/prefdialog/parameter-bool.h @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef SEEN_INK_EXTENSION_PARAMBOOL_H +#define SEEN_INK_EXTENSION_PARAMBOOL_H +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Jon A. Cruz + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "parameter.h" + +class SPDocument; + +namespace Gtk { +class Widget; +} + +namespace Inkscape { +namespace XML { +class Node; +} + +namespace Extension { + +/** + * A boolean parameter. + */ +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); + + /** + * Returns the current state/value. + */ + bool get(const SPDocument *doc, const Inkscape::XML::Node *node) const; + + /** + * A function to set the state/value. + * This function sets 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. + * + * @param in The value to set to + * @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); + + /** + * 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; + + // Explicitly call superclass version to avoid method being hidden. + void string(std::list &list) const override { return Parameter::string(list); } + + /** + * Appends 'true' or 'false'. + * @todo investigate. Returning a value that can then be appended would probably work better/safer. + */ + void string(std::string &string) const override; + +private: + /** Internal value. */ + bool _value; +}; + +} // namespace Extension +} // namespace Inkscape + +#endif // SEEN_INK_EXTENSION_PARAMBOOL_H + +/* + 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-color.cpp b/src/extension/prefdialog/parameter-color.cpp new file mode 100644 index 000000000..385c7b90f --- /dev/null +++ b/src/extension/prefdialog/parameter-color.cpp @@ -0,0 +1,120 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen + * Christopher Brown + * Jon A. Cruz + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "parameter-color.h" + +#include +#include + +#include +#include +#include + +#include + +#include "extension/extension.h" + +#include "color.h" +#include "ui/widget/color-notebook.h" +#include "preferences.h" + +namespace Inkscape { +namespace Extension { + +ParamColor::~ParamColor() +{ + _color_changed.disconnect(); +} + +guint32 ParamColor::set( guint32 in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/ ) +{ + _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(); + + gchar * pref_name = this->pref_name(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring paramval = prefs->getString(extension_pref_root + pref_name); + g_free(pref_name); + + if (!paramval.empty()) + defaulthex = paramval.data(); + + if (defaulthex) { + _color.setValue(atoi(defaulthex)); + } + _color_changed = _color.signal_changed.connect(sigc::mem_fun(this, &ParamColor::_onColorChanged)); + +} + +void ParamColor::string(std::string &string) const +{ + char str[16]; + snprintf(str, 16, "%i", _color.value()); + string += str; +} + +Gtk::Widget *ParamColor::get_widget( SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal * changeSignal ) +{ + using Inkscape::UI::Widget::ColorNotebook; + + if (_hidden) return nullptr; + + if (changeSignal) { + _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() +{ + if (_changeSignal) + _changeSignal->emit(); +} + +}; /* namespace Extension */ +}; /* namespace Inkscape */ diff --git a/src/extension/prefdialog/parameter-color.h b/src/extension/prefdialog/parameter-color.h new file mode 100644 index 000000000..c2d3c2ccb --- /dev/null +++ b/src/extension/prefdialog/parameter-color.h @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef SEEN_INK_EXTENSION_PARAMCOLOR_H__ +#define SEEN_INK_EXTENSION_PARAMCOLOR_H__ +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Jon A. Cruz + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "parameter.h" +#include "ui/selected-color.h" + +class SPDocument; + +namespace Gtk { +class Widget; +} + +namespace Inkscape { +namespace XML { +class Node; +} + +namespace Extension { + +class ParamColor : public Parameter { +private: + void _onColorChanged(); + + Inkscape::UI::SelectedColor _color; + sigc::connection _color_changed; +public: + ParamColor(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml); + ~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); + + 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; + +}; // class ParamColor + +} // namespace Extension +} // namespace Inkscape + +#endif // SEEN_INK_EXTENSION_PARAMCOLOR_H__ + +/* + 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-description.cpp b/src/extension/prefdialog/parameter-description.cpp new file mode 100644 index 000000000..6dfb649b1 --- /dev/null +++ b/src/extension/prefdialog/parameter-description.cpp @@ -0,0 +1,135 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#ifdef linux // does the dollar sign need escaping when passed as string parameter? +# define ESCAPE_DOLLAR_COMMANDLINE +#endif + +#include "parameter-description.h" + +#include +#include +#include +#include +#include + +#include "xml/node.h" +#include "extension/extension.h" + +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) +{ + // 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(); + } else if (cur_child->type() == XML::ELEMENT_NODE && !g_strcmp0(cur_child->name(), "extension:br")) { + 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); + } + + // 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()); + } + } + + // 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; +} + +/** \brief Create a label for the description */ +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()); + if (_mode == HEADER) { + label->set_markup(Glib::ustring("") + Glib::Markup::escape_text(newtext) + Glib::ustring("")); + label->set_margin_top(5); + label->set_margin_bottom(5); + } else if (_mode == URL) { + Glib::ustring escaped_url = Glib::Markup::escape_text(newtext); + label->set_markup(Glib::ustring::compose("%1", escaped_url)); + } else { + label->set_text(newtext); + } + label->set_line_wrap(); + label->set_xalign(0); + + // 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 + // - 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 + // 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(); + label->set_width_chars(len > Parameter::GUI_MAX_LINE_LENGTH ? Parameter::GUI_MAX_LINE_LENGTH : len); + + label->show(); + + Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox()); + hbox->pack_start(*label, true, true); + hbox->show(); + + return hbox; +} + +} /* namespace Extension */ +} /* namespace Inkscape */ diff --git a/src/extension/prefdialog/parameter-description.h b/src/extension/prefdialog/parameter-description.h new file mode 100644 index 000000000..822370b82 --- /dev/null +++ b/src/extension/prefdialog/parameter-description.h @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef __INK_EXTENSION_PARAMDESCRIPTION_H__ +#define __INK_EXTENSION_PARAMDESCRIPTION_H__ + +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "parameter.h" + +class SPDocument; + +namespace Gtk { + class Widget; +} + +namespace Inkscape { +namespace Xml { + class Node; +} + +namespace Extension { + +/** \brief A description parameter */ +class ParamDescription : public Parameter { +public: + enum AppearanceMode { + DESCRIPTION, 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; +private: + /** \brief Internal value. */ + gchar * _value; + AppearanceMode _mode; +}; + +} /* namespace Extension */ +} /* namespace Inkscape */ + +#endif /* __INK_EXTENSION_PARAMDESCRIPTION_H__ */ + +/* + 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.cpp b/src/extension/prefdialog/parameter-enum.cpp new file mode 100644 index 000000000..9c71c3df8 --- /dev/null +++ b/src/extension/prefdialog/parameter-enum.cpp @@ -0,0 +1,269 @@ +// 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 new file mode 100644 index 000000000..329bb26f9 --- /dev/null +++ b/src/extension/prefdialog/parameter-enum.h @@ -0,0 +1,106 @@ +// 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 new file mode 100644 index 000000000..79908d841 --- /dev/null +++ b/src/extension/prefdialog/parameter-float.cpp @@ -0,0 +1,206 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Jon A. Cruz + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "parameter-float.h" + +#include +#include +#include +#include "ui/widget/spinbutton.h" +#include "ui/widget/spin-scale.h" + +#include "xml/node.h" +#include "extension/extension.h" +#include "preferences.h" + +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) +{ + const gchar * defaultval = nullptr; + if (xml->firstChild() != nullptr) { + defaultval = xml->firstChild()->content(); + } + if (defaultval != nullptr) { + _value = g_ascii_strtod (defaultval,nullptr); + } + + const char * maxval = xml->attribute("max"); + if (maxval != nullptr) { + _max = g_ascii_strtod (maxval,nullptr); + } + + const char * minval = xml->attribute("min"); + if (minval != nullptr) { + _min = g_ascii_strtod (minval,nullptr); + } + + _precision = 1; + const char * precision = xml->attribute("precision"); + if (precision != nullptr) { + _precision = atoi(precision); + } + + /* We're handling this by just killing both values */ + if (_max < _min) { + _max = 10.0; + _min = 0.0; + } + + 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; + } + + return; +} + +/** + * A function to set the \c _value. + * + * This function sets 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. + * + * @param in The value to set to. + * @param doc A document that should be used to set the value. + * @param node The node where the value may be placed. + */ +float ParamFloat::set(float in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) +{ + _value = in; + if (_value > _max) { + _value = _max; + } + if (_value < _min) { + _value = _min; + } + + gchar * prefname = this->pref_name(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setDouble(extension_pref_root + prefname, _value); + g_free(prefname); + + return _value; +} + +void ParamFloat::string(std::string &string) const +{ + char startstring[G_ASCII_DTOSTR_BUF_SIZE]; + g_ascii_dtostr(startstring, G_ASCII_DTOSTR_BUF_SIZE, _value); + string += startstring; + return; +} + +/** 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; +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) : + 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)); + return; + }; + + void val_changed (); +}; /* class ParamFloatAdjustment */ + +/** + * A function to respond to the value_changed signal from the adjustment. + * + * This function just grabs the value from the adjustment and writes + * it to the parameter. Very simple, but yet beautiful. + */ +void ParamFloatAdjustment::val_changed() +{ + //std::cout << "Value Changed to: " << this->get_value() << std::endl; + _pref->set(this->get_value(), _doc, _node); + if (_changeSignal != nullptr) { + _changeSignal->emit(); + } + return; +} + +/** + * Creates a Float Adjustment for a float parameter. + * + * 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) +{ + if (_hidden) { + return nullptr; + } + + 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); + + if (_mode == FULL) { + + Glib::ustring text; + if (_text != nullptr) + text = _text; + UI::Widget::SpinScale *scale = new UI::Widget::SpinScale(text, fadjust, _precision); + scale->set_size_request(400, -1); + scale->show(); + hbox->pack_start(*scale, true, true); + + } + else if (_mode == MINIMAL) { + + Gtk::Label * label = Gtk::manage(new Gtk::Label(_text, Gtk::ALIGN_START)); + label->show(); + hbox->pack_start(*label, true, true); + + auto spin = Gtk::manage(new Inkscape::UI::Widget::SpinButton(fadjust, 0.1, _precision)); + spin->show(); + hbox->pack_start(*spin, false, false); + } + + hbox->show(); + + return dynamic_cast(hbox); +} + + +} /* namespace Extension */ +} /* namespace Inkscape */ diff --git a/src/extension/prefdialog/parameter-float.h b/src/extension/prefdialog/parameter-float.h new file mode 100644 index 000000000..c1d0f0f79 --- /dev/null +++ b/src/extension/prefdialog/parameter-float.h @@ -0,0 +1,83 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef INK_EXTENSION_PARAMFLOAT_H_SEEN +#define INK_EXTENSION_PARAMFLOAT_H_SEEN + +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Jon A. Cruz + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "parameter.h" + +class SPDocument; + +namespace Gtk { +class Widget; +} + +namespace Inkscape { +namespace XML { +class Node; +} + +namespace Extension { + +class ParamFloat : public Parameter { +public: + enum AppearanceMode { + FULL, MINIMAL + }; + ParamFloat(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml, + AppearanceMode mode); + + /** 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 max () { return _max; } + + float min () { return _min; } + + float precision () { return _precision; } + + 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; + +private: + /** Internal value. */ + float _value; + AppearanceMode _mode; + float _min; + float _max; + int _precision; +}; + +} /* namespace Extension */ +} /* namespace Inkscape */ + +#endif /* INK_EXTENSION_PARAMFLOAT_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-int.cpp b/src/extension/prefdialog/parameter-int.cpp new file mode 100644 index 000000000..2b9e2c5f6 --- /dev/null +++ b/src/extension/prefdialog/parameter-int.cpp @@ -0,0 +1,202 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Jon A. Cruz + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "parameter-int.h" + +#include +#include +#include +#include "ui/widget/spinbutton.h" +#include "ui/widget/spin-scale.h" + +#include "xml/node.h" +#include "extension/extension.h" +#include "preferences.h" + +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) +{ + 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; + } + + gchar *pref_name = this->pref_name(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + _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; + + if (_value > _max) { + _value = _max; + } + if (_value < _min) { + _value = _min; + } +} + +/** + * A function to set the \c _value. + * This function sets 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. + * + * @param in The value to set to. + * @param doc A document that should be used to set the value. + * @param node The node where the value may be placed. + */ +int ParamInt::set(int in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) +{ + _value = in; + if (_value > _max) { + _value = _max; + } + if (_value < _min) { + _value = _min; + } + + gchar * prefname = this->pref_name(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setInt(extension_pref_root + prefname, _value); + g_free(prefname); + + return _value; +} + +/** 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; +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) : + 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)); + }; + + void val_changed (); +}; /* class ParamIntAdjustment */ + +/** + * A function to respond to the value_changed signal from the adjustment. + * + * This function just grabs the value from the adjustment and writes + * it to the parameter. Very simple, but yet beautiful. + */ +void ParamIntAdjustment::val_changed() +{ + //std::cout << "Value Changed to: " << this->get_value() << std::endl; + _pref->set((int)this->get_value(), _doc, _node); + if (_changeSignal != nullptr) { + _changeSignal->emit(); + } +} + +/** + * Creates a Int Adjustment for a int parameter. + * + * 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) +{ + if (_hidden) { + return nullptr; + } + + 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); + + if (_mode == FULL) { + + Glib::ustring text; + if (_text != nullptr) + text = _text; + UI::Widget::SpinScale *scale = new UI::Widget::SpinScale(text, fadjust, 0); + scale->set_size_request(400, -1); + scale->show(); + hbox->pack_start(*scale, true, true); + } + else if (_mode == MINIMAL) { + Gtk::Label * label = Gtk::manage(new Gtk::Label(_text, Gtk::ALIGN_START)); + label->show(); + hbox->pack_start(*label, true, true); + + auto spin = Gtk::manage(new Inkscape::UI::Widget::SpinButton(fadjust, 1.0, 0)); + spin->show(); + hbox->pack_start(*spin, false, false); + } + + hbox->show(); + + return dynamic_cast(hbox); +} + +void ParamInt::string(std::string &string) const +{ + char startstring[32]; + sprintf(startstring, "%d", _value); + string += startstring; +} + +} // 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/extension/prefdialog/parameter-int.h b/src/extension/prefdialog/parameter-int.h new file mode 100644 index 000000000..fac481267 --- /dev/null +++ b/src/extension/prefdialog/parameter-int.h @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef INK_EXTENSION_PARAMINT_H_SEEN +#define INK_EXTENSION_PARAMINT_H_SEEN + +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Jon A. Cruz + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "parameter.h" + +class SPDocument; + +namespace Gtk { +class Widget; +} + +namespace Inkscape { +namespace XML { +class Node; +} + +namespace Extension { + +class ParamInt : public Parameter { +public: + enum AppearanceMode { + FULL, MINIMAL + }; + ParamInt(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml, + AppearanceMode mode); + + /** 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 max () { return _max; } + + int min () { return _min; } + + 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; + +private: + /** Internal value. */ + int _value; + AppearanceMode _mode; + int _min; + int _max; +}; + +} /* namespace Extension */ +} /* namespace Inkscape */ + +#endif /* INK_EXTENSION_PARAMINT_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-notebook.cpp b/src/extension/prefdialog/parameter-notebook.cpp new file mode 100644 index 000000000..77d94aa5a --- /dev/null +++ b/src/extension/prefdialog/parameter-notebook.cpp @@ -0,0 +1,414 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** \file + * Notebook and NotebookPage parameters for extensions. + */ + +/* + * Authors: + * Johan Engelen + * Jon A. Cruz + * + * Copyright (C) 2006 Author + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "parameter-notebook.h" + +#include +#include +#include +#include + +#include + +#include + +#include +#include "preferences.h" + + +/** + * The root directory in the preferences database for extension + * related parameters. + */ +#define PREF_DIR "extensions" + +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) +{ + + // Read XML to build page + if (xml != nullptr) { + 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, "param") || !strcmp(chname, "_param")) { + Parameter * param; + param = Parameter::make(child_repr, ext); + if (param != nullptr) parameters.push_back(param); + } + child_repr = child_repr->next(); + } + } +} + +ParamNotebook::ParamNotebookPage::~ParamNotebookPage () +{ + //destroy parameters + for (auto param:parameters) { + delete param; + } +} + +/** 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 */ + } + + /* 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) +{ + if (_hidden) { + return nullptr; + } + + Gtk::VBox * vbox = Gtk::manage(new Gtk::VBox); + vbox->set_border_width(Parameter::GUI_BOX_MARGIN); + 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); + } + } + } + + vbox->show(); + + return dynamic_cast(vbox); +} + +/** Search the parameter's name in the page content. */ +Parameter *ParamNotebook::ParamNotebookPage::get_param(const gchar * name) +{ + if (name == nullptr) { + throw Extension::param_not_exist(); + } + if (this->parameters.empty()) { + // the list of parameters is empty + throw Extension::param_not_exist(); + } + + for (auto param:parameters) { + if (!strcmp(param->name(), name)) { + return param; + } + } + + return nullptr; +} + +/** 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) +{ + // Read XML tree to add pages: + if (xml != nullptr) { + 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); + } + 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(); + } + + gchar * pref_name = this->pref_name(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring paramval = 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 +} + +ParamNotebook::~ParamNotebook () +{ + //destroy pages + for (auto page:pages) { + delete page; + } + g_free(_value); +} + + +/** + * A function to set the \c _value. + * + * This function sets 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 number of the page which value must be 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 *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; + + if (_value != nullptr) g_free(_value); + _value = g_strdup(page->name()); + + gchar * prefname = this->pref_name(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setString(extension_pref_root + prefname, _value); + g_free(prefname); + + return _value; +} + +void ParamNotebook::string(std::list &list) const +{ + std::string param_string; + param_string += "--"; + param_string += name(); + param_string += "="; + + param_string += "\""; + param_string += _value; // the name of the current page + param_string += "\""; + list.insert(list.end(), param_string); + + for (auto page:pages) { + page->paramString(list); + } +} + +/** A special category of Gtk::Notebook to handle notebook parameters. */ +class ParamNotebookWdg : public Gtk::Notebook { +private: + 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. + */ + 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)); + }; + void changed_page(Gtk::Widget *page, guint pagenum); + bool activated; +}; + +/** + * Respond to the selected page of notebook changing. + * This function responds to the changing by reporting it to + * ParamNotebook. The change is only reported when the notebook + * is actually visible. This to exclude 'fake' changes when the + * notebookpages are added or removed. + */ +void ParamNotebookWdg::changed_page(Gtk::Widget * /*page*/, guint pagenum) +{ + if (get_visible()) { + _pref->set((int)pagenum, _doc, _node); + } +} + +/** Search the parameter's name in the notebook content. */ +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); + if (subparam) { + return subparam; + } + } + + return nullptr; +} + + +/** + * Creates a Notebook widget for a notebook parameter. + * + * Builds a notebook and puts pages in it. + */ +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? + } + } + + nb->show(); + + if (pagenr >= 0) nb->set_current_page(pagenr); + + return dynamic_cast(nb); +} + + +} // 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/extension/prefdialog/parameter-notebook.h b/src/extension/prefdialog/parameter-notebook.h new file mode 100644 index 000000000..f1e16308b --- /dev/null +++ b/src/extension/prefdialog/parameter-notebook.h @@ -0,0 +1,119 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef INK_EXTENSION_PARAMNOTEBOOK_H_SEEN +#define INK_EXTENSION_PARAMNOTEBOOK_H_SEEN + +/** \file + * Notebook parameter for extensions. + */ + +/* + * Author: + * Johan Engelen + * Jon A. Cruz + * + * Copyright (C) 2006 Author + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include + +#include "parameter.h" + +namespace Gtk { +class Widget; +} + +namespace Inkscape { +namespace Extension { + +class Extension; + + +/** A class to represent a notebookparameter 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; + + /** + * A class to represent the pages of a notebookparameter 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 */ + + 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() 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; + }; /* class ParamNotebookPage */ + + + 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() 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. + * @return A string with the 'value' and all the parameters on all pages as command line arguments. + */ + void string (std::list &list) const override; + + // Explicitly call superclass version to avoid method being hidden. + void string(std::string &string) const override {return Parameter::string(string);} + + + 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); +}; /* class ParamNotebook */ + + + + + +} // namespace Extension +} // namespace Inkscape + +#endif /* INK_EXTENSION_PARAMNOTEBOOK_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-radiobutton.cpp b/src/extension/prefdialog/parameter-radiobutton.cpp new file mode 100644 index 000000000..f2c3187af --- /dev/null +++ b/src/extension/prefdialog/parameter-radiobutton.cpp @@ -0,0 +1,349 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** \file + * extension parameter for radiobuttons. + * + * It uses a Gtk:ComboBoxText widget in the extension UI. + */ + +/* + * 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-radiobutton.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 { + +/* 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. */ + +ParamRadioButton::ParamRadioButton(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) +{ + // Read XML tree to add enumeration items: + // printf("Extension Constructor: "); + if (xml != nullptr) { + Inkscape::XML::Node *child_repr = xml->firstChild(); + while (child_repr != nullptr) { + char const * chname = child_repr->name(); + if (!strcmp(chname, INKSCAPE_EXTENSION_NS "option") || !strcmp(chname, INKSCAPE_EXTENSION_NS "_option")) { + Glib::ustring * newtext = nullptr; + Glib::ustring * newvalue = nullptr; + const char * contents = child_repr->firstChild()->content(); + + if (contents != nullptr) { + // don't translate when 'item' but do translate when '_option' + if (!strcmp(chname, INKSCAPE_EXTENSION_NS "_option")) { + if (child_repr->attribute("msgctxt") != nullptr) { + newtext = new Glib::ustring(g_dpgettext2(nullptr, child_repr->attribute("msgctxt"), contents)); + } else { + newtext = new Glib::ustring(_(contents)); + } + } else { + newtext = new Glib::ustring(contents); + } + } else { + continue; + } + + + const char * val = child_repr->attribute("value"); + if (val != nullptr) { + newvalue = new Glib::ustring(val); + } else { + newvalue = new Glib::ustring(contents); + } + + if ( (newtext) && (newvalue) ) { // logical error if this is not true here + choices.push_back(new optionentry(newvalue, newtext)); + } + } + child_repr = child_repr->next(); + } + } + + // Initialize _value with the default value from xml + // for simplicity : default to the contents of the first xml-child + const char * defaultval = nullptr; + if (!choices.empty()) { + defaultval = (static_cast (choices[0]))->value->c_str(); + } + + gchar * pref_name = this->pref_name(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring paramval = 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 + } +} + +ParamRadioButton::~ParamRadioButton () +{ + //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 *ParamRadioButton::set(const gchar * in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) +{ + if (in == nullptr) { + return nullptr; /* Can't have NULL string */ + } + + Glib::ustring * settext = nullptr; + for (auto entr:choices) { + if ( !entr->value->compare(in) ) { + settext = entr->value; + break; // break out of for loop + } + } + if (settext) { + if (_value != nullptr) { + g_free(_value); + } + _value = g_strdup(settext->c_str()); + gchar * prefname = this->pref_name(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setString(extension_pref_root + prefname, _value); + g_free(prefname); + } else { + g_warning("Couldn't set ParamRadioButton %s", in); + } + + return _value; +} + +void ParamRadioButton::string(std::string &string) const +{ + string += _value; +} + +/** A special radiobutton class to use in ParamRadioButton. */ +class ParamRadioButtonWdg : public Gtk::RadioButton { +private: + ParamRadioButton * _pref; + SPDocument * _doc; + Inkscape::XML::Node * _node; + sigc::signal * _changeSignal; +public: + /** + * Build a string preference for the given parameter. + * @param pref Where to put the radiobutton's string when it is selected. + */ + ParamRadioButtonWdg ( Gtk::RadioButtonGroup& group, const Glib::ustring& label, + ParamRadioButton * pref, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal ) : + Gtk::RadioButton(group, label), _pref(pref), _doc(doc), _node(node), _changeSignal(changeSignal) { + add_changesignal(); + }; + ParamRadioButtonWdg ( const Glib::ustring& label, + ParamRadioButton * pref, SPDocument * doc, Inkscape::XML::Node * node , sigc::signal * changeSignal) : + Gtk::RadioButton(label), _pref(pref), _doc(doc), _node(node), _changeSignal(changeSignal) { + add_changesignal(); + }; + void add_changesignal() { + this->signal_toggled().connect(sigc::mem_fun(this, &ParamRadioButtonWdg::changed)); + }; + void changed (); +}; + +/** + * Respond to the selected radiobutton changing. + * + * This function responds to the radiobutton selection changing by grabbing the value + * from the text box and putting it in the parameter. + */ +void ParamRadioButtonWdg::changed() +{ + if (this->get_active()) { + Glib::ustring value = _pref->value_from_label(this->get_label()); + _pref->set(value.c_str(), _doc, _node); + } + if (_changeSignal != nullptr) { + _changeSignal->emit(); + } +} + + +class ComboWdg : public Gtk::ComboBoxText { +private: + ParamRadioButton* _base; + SPDocument* _doc; + Inkscape::XML::Node* _node; + sigc::signal * _changeSignal; + +public: + ComboWdg(ParamRadioButton* base, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) : + _base(base), + _doc(doc), + _node(node), + _changeSignal(changeSignal) + { + this->signal_changed().connect(sigc::mem_fun(this, &ComboWdg::changed)); + } + ~ComboWdg() override = default; + void changed (); +}; + +void ComboWdg::changed() +{ + if ( _base ) { + Glib::ustring value = _base->value_from_label(get_active_text()); + _base->set(value.c_str(), _doc, _node); + } + if (_changeSignal != nullptr) { + _changeSignal->emit(); + } +} + +/** + * Returns the value for the options label parameter + */ +Glib::ustring ParamRadioButton::value_from_label(const Glib::ustring label) +{ + Glib::ustring value = ""; + + for ( auto entr:choices) { + if ( !entr->text->compare(label) ) { + value = *(entr->value); + break; + } + } + + return value; + +} + +/** + * Creates a combobox widget for an enumeration parameter. + */ +Gtk::Widget * ParamRadioButton::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) +{ + if (_hidden) { + return nullptr; + } + + auto hbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, Parameter::GUI_PARAM_WIDGETS_SPACING)); + hbox->set_homogeneous(false); + auto vbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0)); + vbox->set_homogeneous(false); + + Gtk::Label * label = Gtk::manage(new Gtk::Label(_text, Gtk::ALIGN_START, Gtk::ALIGN_START)); + label->show(); + hbox->pack_start(*label, false, false); + + Gtk::ComboBoxText* cbt = nullptr; + bool comboSet = false; + if (_mode == MINIMAL) { + cbt = Gtk::manage(new ComboWdg(this, doc, node, changeSignal)); + cbt->show(); + vbox->pack_start(*cbt, false, false); + } + + // add choice strings as radiobuttons + // and select last selected option (_value) + Gtk::RadioButtonGroup group; + for (auto entr:choices) { + Glib::ustring * text = entr->text; + switch ( _mode ) { + case MINIMAL: + { + cbt->append(*text); + if (!entr->value->compare(_value)) { + cbt->set_active_text(*text); + comboSet = true; + } + } + break; + case COMPACT: + case FULL: + { + ParamRadioButtonWdg * radio = Gtk::manage(new ParamRadioButtonWdg(group, *text, this, doc, node, changeSignal)); + radio->show(); + vbox->pack_start(*radio, true, true); + if (!entr->value->compare(_value)) { + radio->set_active(); + } + } + break; + } + } + + if ( (_mode == MINIMAL) && !comboSet) { + cbt->set_active(0); + } + + vbox->show(); + hbox->pack_end(*vbox, false, false); + 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-radiobutton.h b/src/extension/prefdialog/parameter-radiobutton.h new file mode 100644 index 000000000..f35126d13 --- /dev/null +++ b/src/extension/prefdialog/parameter-radiobutton.h @@ -0,0 +1,109 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef INK_EXTENSION_PARAMRADIOBUTTON_H_SEEN +#define INK_EXTENSION_PARAMRADIOBUTTON_H_SEEN + +/** \file + * Radiobutton 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" + +namespace Gtk { +class Widget; +} + +namespace Inkscape { +namespace Extension { + +class Extension; + + + +// \brief A class to represent a radiobutton parameter of an extension +class ParamRadioButton : public Parameter { +public: + enum AppearanceMode { + FULL, COMPACT, MINIMAL + }; + + ParamRadioButton(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml, + AppearanceMode mode); + ~ParamRadioButton() 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; + + Glib::ustring value_from_label(const Glib::ustring label); + + const gchar *get(const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) const { return _value; } + + const gchar *set(const gchar *in, SPDocument *doc, Inkscape::XML::Node *node); + +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; + AppearanceMode _mode; + + /* 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 optionentry { + public: + optionentry (Glib::ustring * val, Glib::ustring * txt) { + value = val; + text = txt; + } + ~optionentry() { + delete value; + delete text; + } + Glib::ustring * value; + Glib::ustring * text; + }; + + std::vector choices; /**< A table to store the choice strings */ + +}; /* class ParamRadioButton */ + + + + + +} /* namespace Extension */ +} /* namespace Inkscape */ + +#endif /* INK_EXTENSION_PARAMRADIOBUTTON_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:fileencoding=utf-8:textwidth=99 : diff --git a/src/extension/prefdialog/parameter-string.cpp b/src/extension/prefdialog/parameter-string.cpp new file mode 100644 index 000000000..829b603d8 --- /dev/null +++ b/src/extension/prefdialog/parameter-string.cpp @@ -0,0 +1,182 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Jon A. Cruz + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "parameter-string.h" + +#include +#include +#include + +#include + +#include "xml/node.h" +#include "extension/extension.h" +#include "preferences.h" +#include + +namespace Inkscape { +namespace Extension { + + +/** Free the allocated data. */ +ParamString::~ParamString() +{ + g_free(_value); + _value = nullptr; +} + +/** + * A function to set the \c _value. + * + * This function sets 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 to. + * @param doc A document that should be used to set the value. + * @param node The node where the value may be placed. + */ +const gchar * ParamString::set(const gchar * in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) +{ + if (in == nullptr) { + return nullptr; /* Can't have NULL string */ + } + + if (_value != nullptr) { + g_free(_value); + } + + _value = g_strdup(in); + + gchar * prefname = this->pref_name(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setString(extension_pref_root + prefname, _value); + g_free(prefname); + + return _value; +} + +void ParamString::string(std::string &string) const +{ + if (_value) { + string += _value; + } +} + +/** Initialize the object, to do that, copy the data. */ +ParamString::ParamString(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 * defaultval = nullptr; + if (xml->firstChild() != nullptr) { + defaultval = xml->firstChild()->content(); + } + + gchar * pref_name = this->pref_name(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Glib::ustring paramval = prefs->getString(extension_pref_root + pref_name); + g_free(pref_name); + + if (!paramval.empty()) { + defaultval = paramval.data(); + } + if (defaultval != nullptr) { + char const * chname = xml->name(); + if (!strcmp(chname, INKSCAPE_EXTENSION_NS "_param")) { + if (xml->attribute("msgctxt") != nullptr) { + _value = g_strdup(g_dpgettext2(nullptr, xml->attribute("msgctxt"), defaultval)); + } else { + _value = g_strdup(_(defaultval)); + } + } else { + _value = g_strdup(defaultval); + } + } + + _max_length = 0; +} + +/** A special type of Gtk::Entry to handle string parameteres. */ +class ParamStringEntry : public Gtk::Entry { +private: + ParamString * _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. + */ + ParamStringEntry (ParamString * pref, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) : + Gtk::Entry(), _pref(pref), _doc(doc), _node(node), _changeSignal(changeSignal) { + if (_pref->get(nullptr, nullptr) != nullptr) { + this->set_text(Glib::ustring(_pref->get(nullptr, nullptr))); + } + this->set_max_length(_pref->getMaxLength()); //Set the max length - default zero means no maximum + this->signal_changed().connect(sigc::mem_fun(this, &ParamStringEntry::changed_text)); + }; + void changed_text (); +}; + + +/** + * 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 ParamStringEntry::changed_text() +{ + Glib::ustring data = this->get_text(); + _pref->set(data.c_str(), _doc, _node); + if (_changeSignal != nullptr) { + _changeSignal->emit(); + } +} + +/** + * Creates a text box for the string parameter. + * + * Builds a hbox with a label and a text box in it. + */ +Gtk::Widget * ParamString::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); + + ParamStringEntry * textbox = new ParamStringEntry(this, doc, node, changeSignal); + textbox->show(); + hbox->pack_start(*textbox, true, true); + + hbox->show(); + + return dynamic_cast(hbox); +} + +} /* namespace Extension */ +} /* namespace Inkscape */ diff --git a/src/extension/prefdialog/parameter-string.h b/src/extension/prefdialog/parameter-string.h new file mode 100644 index 000000000..7c094d394 --- /dev/null +++ b/src/extension/prefdialog/parameter-string.h @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef INK_EXTENSION_PARAMSTRING_H_SEEN +#define INK_EXTENSION_PARAMSTRING_H_SEEN + +/* + * Copyright (C) 2005-2007 Authors: + * Ted Gould + * Johan Engelen * + * Jon A. Cruz + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "parameter.h" + +namespace Inkscape { +namespace Extension { + +class ParamString : public Parameter { +private: + /** \brief Internal value. This should point to a string that has + been allocated in memory. And should be free'd. */ + gchar * _value; + /** \brief Internal value. This indicates the maximum length of the string. Zero meaning unlimited. + */ + gint _max_length; +public: + ParamString(const gchar * name, + const gchar * text, + const gchar * description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml); + ~ParamString() override; + + /** \brief Returns \c _value, with a \i const to protect it. */ + const gchar *get(SPDocument const * /*doc*/, Inkscape::XML::Node const * /*node*/) const { return _value; } + + const gchar * set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node); + + 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; + + void setMaxLength(int maxLength) { _max_length = maxLength; } + int getMaxLength() { return _max_length; } +}; + + +} // namespace Extension +} // namespace Inkscape + +#endif /* INK_EXTENSION_PARAMSTRING_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.cpp b/src/extension/prefdialog/parameter.cpp new file mode 100644 index 000000000..159f54b9c --- /dev/null +++ b/src/extension/prefdialog/parameter.cpp @@ -0,0 +1,415 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** @file + * Parameters for extensions. + */ +/* Author: + * Ted Gould + * Johan Engelen + * Jon A. Cruz + * + * Copyright (C) 2005-2007 Authors + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#ifdef linux // does the dollar sign need escaping when passed as string parameter? +# define ESCAPE_DOLLAR_COMMANDLINE +#endif + +#include +#include + +#include +#include + +#include "parameter.h" +#include "parameter-bool.h" +#include "parameter-color.h" +#include "parameter-description.h" +#include "parameter-enum.h" +#include "parameter-float.h" +#include "parameter-int.h" +#include "parameter-notebook.h" +#include "parameter-radiobutton.h" +#include "parameter-string.h" + +#include "extension/extension.h" + +#include "object/sp-defs.h" + +#include "ui/widget/color-notebook.h" + +#include "xml/node.h" + + +namespace Inkscape { +namespace Extension { + +Parameter *Parameter::make(Inkscape::XML::Node *in_repr, Inkscape::Extension::Extension *in_ext) +{ + const char *name = in_repr->attribute("name"); + const char *type = in_repr->attribute("type"); + + // we can't create a parameter without type + if (!type) { + return nullptr; + } + // also require name unless it's a pure UI element that does not store its value + if (!name) { + static std::vector ui_elements = {"description"}; + if (std::find(ui_elements.begin(), ui_elements.end(), type) == ui_elements.end()) { + return nullptr; + } + } + + const char *text = in_repr->attribute("gui-text"); + if (text == nullptr) { + text = in_repr->attribute("_gui-text"); + if (text == nullptr) { + // text = ""; // probably better to require devs to explicitly set an empty gui-text if this is what they want + } else { + const char *context = in_repr->attribute("msgctxt"); + if (context != nullptr) { + text = g_dpgettext2(nullptr, context, text); + } else { + text = _(text); + } + } + } + const char *description = in_repr->attribute("gui-description"); + if (description == nullptr) { + description = in_repr->attribute("_gui-description"); + if (description != nullptr) { + const char *context = in_repr->attribute("msgctxt"); + if (context != nullptr) { + description = g_dpgettext2(nullptr, context, description); + } else { + description = _(description); + } + } + } + bool hidden = false; + { + const char *gui_hide = in_repr->attribute("gui-hidden"); + if (gui_hide != nullptr) { + if (strcmp(gui_hide, "1") == 0 || + strcmp(gui_hide, "true") == 0) { + hidden = true; + } + /* else stays false */ + } + } + int indent = 0; + { + const char *indent_attr = in_repr->attribute("indent"); + if (indent_attr != nullptr) { + if (strcmp(indent_attr, "true") == 0) { + indent = 1; + } else { + indent = atoi(indent_attr); + } + } + } + const gchar* appearance = in_repr->attribute("appearance"); + + Parameter * param = nullptr; + if (!strcmp(type, "boolean")) { + param = new ParamBool(name, text, description, hidden, indent, in_ext, in_repr); + } else if (!strcmp(type, "int")) { + if (appearance && !strcmp(appearance, "full")) { + param = new ParamInt(name, text, description, hidden, indent, in_ext, in_repr, ParamInt::FULL); + } else { + param = new ParamInt(name, text, description, hidden, indent, in_ext, in_repr, ParamInt::MINIMAL); + } + } else if (!strcmp(type, "float")) { + if (appearance && !strcmp(appearance, "full")) { + param = new ParamFloat(name, text, description, hidden, indent, in_ext, in_repr, ParamFloat::FULL); + } else { + param = new ParamFloat(name, text, description, hidden, indent, in_ext, in_repr, ParamFloat::MINIMAL); + } + } else if (!strcmp(type, "string")) { + param = new ParamString(name, text, description, hidden, indent, in_ext, in_repr); + gchar const * max_length = in_repr->attribute("max_length"); + if (max_length != nullptr) { + ParamString * ps = dynamic_cast(param); + ps->setMaxLength(atoi(max_length)); + } + } else if (!strcmp(type, "description")) { + ParamDescription::AppearanceMode appearance_mode = ParamDescription::DESCRIPTION; + if (appearance) { + if (!strcmp(appearance, "header")) { + appearance_mode = ParamDescription::HEADER; + } else if (!strcmp(appearance, "url")) { + appearance_mode = ParamDescription::URL; + } + } + param = new ParamDescription(name, text, description, hidden, indent, in_ext, in_repr, appearance_mode); + } else if (!strcmp(type, "enum")) { + param = new ParamComboBox(name, text, description, hidden, indent, in_ext, in_repr); + } else if (!strcmp(type, "notebook")) { + param = new ParamNotebook(name, text, description, hidden, indent, in_ext, in_repr); + } else if (!strcmp(type, "optiongroup")) { + if (appearance && !strcmp(appearance, "minimal")) { + param = new ParamRadioButton(name, text, description, hidden, indent, in_ext, in_repr, ParamRadioButton::MINIMAL); + } else { + param = new ParamRadioButton(name, text, description, hidden, indent, in_ext, in_repr, ParamRadioButton::FULL); + } + } else if (!strcmp(type, "color")) { + param = new ParamColor(name, text, description, hidden, indent, in_ext, in_repr); + } + + // Note: param could equal NULL + return param; +} + +bool Parameter::get_bool(SPDocument const *doc, Inkscape::XML::Node const *node) const +{ + ParamBool const *boolpntr = dynamic_cast(this); + if (!boolpntr) { + throw Extension::param_not_bool_param(); + } + return boolpntr->get(doc, node); +} + +int Parameter::get_int(SPDocument const *doc, Inkscape::XML::Node const *node) const +{ + ParamInt const *intpntr = dynamic_cast(this); + if (!intpntr) { + throw Extension::param_not_int_param(); + } + return intpntr->get(doc, node); +} + +float Parameter::get_float(SPDocument const *doc, Inkscape::XML::Node const *node) const +{ + ParamFloat const *floatpntr = dynamic_cast(this); + if (!floatpntr) { + throw Extension::param_not_float_param(); + } + return floatpntr->get(doc, node); +} + +gchar const *Parameter::get_string(SPDocument const *doc, Inkscape::XML::Node const *node) const +{ + ParamString const *stringpntr = dynamic_cast(this); + if (!stringpntr) { + throw Extension::param_not_string_param(); + } + return stringpntr->get(doc, node); +} + +gchar const *Parameter::get_enum(SPDocument const *doc, Inkscape::XML::Node const *node) const +{ + ParamComboBox const *param = dynamic_cast(this); + if (!param) { + throw Extension::param_not_enum_param(); + } + return param->get(doc, node); +} + +bool Parameter::get_enum_contains(gchar const * value, SPDocument const *doc, Inkscape::XML::Node const *node) const +{ + ParamComboBox const *param = dynamic_cast(this); + if (!param) { + throw Extension::param_not_enum_param(); + } + return param->contains(value, doc, node); +} + +gchar const *Parameter::get_optiongroup(SPDocument const *doc, Inkscape::XML::Node const * node) const +{ + ParamRadioButton const *param = dynamic_cast(this); + if (!param) { + throw Extension::param_not_optiongroup_param(); + } + return param->get(doc, node); +} + +guint32 Parameter::get_color(const SPDocument* doc, Inkscape::XML::Node const *node) const +{ + ParamColor const *param = dynamic_cast(this); + if (!param) { + throw Extension::param_not_color_param(); + } + return param->get(doc, node); +} + +bool Parameter::set_bool(bool in, SPDocument * doc, Inkscape::XML::Node * node) +{ + ParamBool * boolpntr = dynamic_cast(this); + if (boolpntr == nullptr) + throw Extension::param_not_bool_param(); + return boolpntr->set(in, doc, node); +} + +int Parameter::set_int(int in, SPDocument * doc, Inkscape::XML::Node * node) +{ + ParamInt * intpntr = dynamic_cast(this); + if (intpntr == nullptr) + throw Extension::param_not_int_param(); + return intpntr->set(in, doc, node); +} + +/** Wrapper to cast to the object and use it's function. */ +float +Parameter::set_float (float in, SPDocument * doc, Inkscape::XML::Node * node) +{ + ParamFloat * floatpntr; + floatpntr = dynamic_cast(this); + if (floatpntr == nullptr) + throw Extension::param_not_float_param(); + return floatpntr->set(in, doc, node); +} + +/** Wrapper to cast to the object and use it's function. */ +gchar const * +Parameter::set_string (gchar const * in, SPDocument * doc, Inkscape::XML::Node * node) +{ + ParamString * stringpntr = dynamic_cast(this); + if (stringpntr == nullptr) + throw Extension::param_not_string_param(); + return stringpntr->set(in, doc, node); +} + +gchar const * Parameter::set_optiongroup( gchar const * in, SPDocument * doc, Inkscape::XML::Node * node ) +{ + ParamRadioButton *param = dynamic_cast(this); + if (!param) { + throw Extension::param_not_optiongroup_param(); + } + return param->set(in, doc, node); +} + +gchar const *Parameter::set_enum( gchar const * in, SPDocument * doc, Inkscape::XML::Node * node ) +{ + ParamComboBox *param = dynamic_cast(this); + if (!param) { + throw Extension::param_not_enum_param(); + } + return param->set(in, doc, node); +} + + +/** Wrapper to cast to the object and use it's function. */ +guint32 +Parameter::set_color (guint32 in, SPDocument * doc, Inkscape::XML::Node * node) +{ + ParamColor* param = dynamic_cast(this); + if (param == nullptr) + throw Extension::param_not_color_param(); + return param->set(in, doc, node); +} + + +/** Oop, now that we need a parameter, we need it's name. */ +Parameter::Parameter(gchar const * name, gchar const * text, gchar const * description, bool hidden, int indent, Inkscape::Extension::Extension * ext) : + _description(nullptr), + _text(nullptr), + _hidden(hidden), + _indent(indent), + _extension(ext), + _name(nullptr) +{ + if (name != nullptr) { + _name = g_strdup(name); + } + + if (description != nullptr) { + _description = g_strdup(description); + } + + if (text != nullptr) { + _text = g_strdup(text); + } else { + _text = g_strdup(name); + } + + return; +} + +/** Oop, now that we need a parameter, we need it's name. */ +Parameter::Parameter (gchar const * name, gchar const * text, Inkscape::Extension::Extension * ext) : + _description(nullptr), + _text(nullptr), + _hidden(false), + _indent(0), + _extension(ext), + _name(nullptr) +{ + if (name != nullptr) { + _name = g_strdup(name); + } + if (text != nullptr) { + _text = g_strdup(text); + } else { + _text = g_strdup(name); + } + + return; +} + +Parameter::~Parameter() +{ + g_free(_name); + _name = nullptr; + + g_free(_text); + _text = nullptr; + + g_free(_description); + _description = nullptr; +} + +gchar *Parameter::pref_name() const +{ + return g_strdup_printf("%s.%s", _extension->get_id(), _name); +} + +/** Basically, if there is no widget pass a NULL. */ +Gtk::Widget * +Parameter::get_widget (SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal * /*changeSignal*/) +{ + return nullptr; +} + +/** If I'm not sure which it is, just don't return a value. */ +void Parameter::string(std::string &/*string*/) const +{ + // TODO investigate clearing the target string. +} + +void Parameter::string(std::list &list) const +{ + std::string value; + string(value); + if (!value.empty()) { + std::string final; + final += "--"; + final += name(); + final += "="; + final += value; + + list.insert(list.end(), final); + } +} + +Parameter *Parameter::get_param(gchar const * /*name*/) +{ + return nullptr; +} + +Glib::ustring const extension_pref_root = "/extensions/"; + +} // 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/extension/prefdialog/parameter.h b/src/extension/prefdialog/parameter.h new file mode 100644 index 000000000..39433b902 --- /dev/null +++ b/src/extension/prefdialog/parameter.h @@ -0,0 +1,215 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** @file + * Parameters for extensions. + */ +/* Authors: + * Ted Gould + * Jon A. Cruz + * + * Copyright (C) 2005-2006 Authors + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#ifndef SEEN_INK_EXTENSION_PARAM_H__ +#define SEEN_INK_EXTENSION_PARAM_H__ + +#include + +#include +#include + +class SPDocument; + +namespace Gtk { +class Widget; +} + +namespace Inkscape { +namespace XML { +class Node; +} + +namespace Extension { + +class Extension; + + +/** + * The root directory in the preferences database for extension-related parameters. + * + * The directory path has both a leading and a trailing slash, so that extension_pref_root + pref_name works + * without having to append a separator. + */ +extern Glib::ustring const extension_pref_root; + +/** + * A class to represent the parameter of an extension. + * + * This is really a super class that allows them to abstract all + * the different types of parameters into some that can be passed + * around. There is also a few functions that are used by all the + * different parameters. + */ +class Parameter { + +public: + Parameter(gchar const *name, + gchar const *text, + gchar const *description, + bool hidden, + int indent, + Inkscape::Extension::Extension * ext); + + Parameter(gchar const *name, + gchar const *text, + Inkscape::Extension::Extension * ext); + + virtual ~Parameter(); + + /** Wrapper to cast to the object and use its function. */ + bool get_bool(SPDocument const *doc, Inkscape::XML::Node const *node) const; + + /** Wrapper to cast to the object and use it's function. */ + int get_int(SPDocument const *doc, Inkscape::XML::Node const *node) const; + + /** Wrapper to cast to the object and use it's function. */ + float get_float(SPDocument const *doc, Inkscape::XML::Node const *node) const; + + /** Wrapper to cast to the object and use it's function. */ + gchar const *get_string(SPDocument const *doc, Inkscape::XML::Node const *node) const; + + guint32 get_color(SPDocument const *doc, Inkscape::XML::Node const *node) const; + + /** Wrapper to cast to the object and use it's function. */ + gchar const *get_enum(SPDocument const *doc, Inkscape::XML::Node const *node) const; + + /** Wrapper to cast to the object and use it's function. */ + bool get_enum_contains(gchar const * value, SPDocument const *doc, Inkscape::XML::Node const *node) const; + + /** Wrapper to cast to the object and use it's function. */ + gchar const *get_optiongroup(SPDocument const * doc, Inkscape::XML::Node const *node) const; + + /** Wrapper to cast to the object and use it's function. */ + bool set_bool(bool in, SPDocument * doc, Inkscape::XML::Node * node); + + /** Wrapper to cast to the object and use it's function. */ + int set_int(int in, SPDocument * doc, Inkscape::XML::Node * node); + + float set_float(float in, SPDocument * doc, Inkscape::XML::Node * node); + + gchar const *set_optiongroup(gchar const *in, SPDocument * doc, Inkscape::XML::Node *node); + + gchar const *set_enum(gchar const * in, SPDocument * doc, Inkscape::XML::Node *node); + + gchar const *set_string(gchar const * in, SPDocument * doc, Inkscape::XML::Node * node); + + guint32 set_color(guint32 in, SPDocument * doc, Inkscape::XML::Node * node); + + gchar const * name() const {return _name;} + + /** + * This function creates a parameter that can be used later. This + * is typically done in the creation of the extension and defined + * in the XML file describing the extension (it's private so people + * have to use the system) :) + * + * 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 or a type in the XML, then no parameter 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. + * + * @param in_repr The XML describing the parameter. + * @return a pointer to a new Parameter if applicable, null otherwise.. + */ + static Parameter *make(Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * in_ext); + + virtual Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal); + + gchar const * get_tooltip() const { return _description; } + + /** Indicates if the GUI for this parameter is hidden or not */ + bool get_hidden() const { return _hidden; } + + /** Indentation level of the parameter */ + int get_indent() const { return _indent; } + + virtual void string(std::list &list) const; + + /** + * Gets the current value of the parameter in a string form. + * @return A string with the 'value'. + */ + virtual void string(std::string &string) const; + + /** All the code in Notebook::get_param to get the notebook content. */ + virtual Parameter *get_param(gchar const *name); + + + /** Recommended margin of boxes containing multiple Parameters (in px) */ + const static int GUI_BOX_MARGIN = 10; + /** Recommended spacing between multiple Parameters packed into a box (in px) */ + const static int GUI_BOX_SPACING = 4; + /** Recommended spacing between the widgets making up a single Parameter (e.g. label and input) (in px) */ + const static int GUI_PARAM_WIDGETS_SPACING = 4; + /** Recommended indentation width of parameters (in px) */ + const static int GUI_INDENTATION = 12; + /** Recommended maximum line length for wrapping textual parameters (in chars) */ + const static int GUI_MAX_LINE_LENGTH = 60; + + +protected: + /** Parameter text to show as the GUI label. */ + gchar * _text; + + /** Extended description of the parameter (crrently shown as tooltip on hover). */ + gchar * _description; + + /** Whether the parameter is visible. */ + bool _hidden; + + /** Indentation level of the parameter. */ + int _indent; + + + /* **** funcs **** */ + + /** + * Build the name to write the parameter from the extension's ID and the name of this parameter. + */ + gchar *pref_name() const; + + +private: + /** Which extension is this parameter attached to. */ + Inkscape::Extension::Extension *_extension; + + /** The name of this parameter. */ + gchar *_name; +}; + +} // namespace Extension +} // namespace Inkscape + +#endif // SEEN_INK_EXTENSION_PARAM_H__ + +/* + 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/extension/prefdialog/prefdialog.cpp b/src/extension/prefdialog/prefdialog.cpp index 6fbffb262..90a156abe 100644 --- a/src/extension/prefdialog/prefdialog.cpp +++ b/src/extension/prefdialog/prefdialog.cpp @@ -27,7 +27,7 @@ #include "extension/execution-env.h" #include "extension/implementation/implementation.h" -#include "param/parameter.h" +#include "parameter.h" namespace Inkscape { -- cgit v1.2.3 From b666a19dafd98235907cfa9408405f06b9555765 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Sun, 21 Jul 2019 17:16:06 +0200 Subject: Remove unused define ESCAPE_DOLLAR_COMMANDLINE --- src/extension/prefdialog/parameter-description.cpp | 4 ---- src/extension/prefdialog/parameter.cpp | 4 ---- 2 files changed, 8 deletions(-) diff --git a/src/extension/prefdialog/parameter-description.cpp b/src/extension/prefdialog/parameter-description.cpp index 6dfb649b1..667670443 100644 --- a/src/extension/prefdialog/parameter-description.cpp +++ b/src/extension/prefdialog/parameter-description.cpp @@ -6,10 +6,6 @@ * Released under GNU GPL v2+, read the file 'COPYING' for more information. */ -#ifdef linux // does the dollar sign need escaping when passed as string parameter? -# define ESCAPE_DOLLAR_COMMANDLINE -#endif - #include "parameter-description.h" #include diff --git a/src/extension/prefdialog/parameter.cpp b/src/extension/prefdialog/parameter.cpp index 159f54b9c..abda73e18 100644 --- a/src/extension/prefdialog/parameter.cpp +++ b/src/extension/prefdialog/parameter.cpp @@ -12,10 +12,6 @@ * Released under GNU GPL v2+, read the file 'COPYING' for more information. */ -#ifdef linux // does the dollar sign need escaping when passed as string parameter? -# define ESCAPE_DOLLAR_COMMANDLINE -#endif - #include #include -- cgit v1.2.3 From 3c2c2921ae44841306da6ff357865481ad1fc674 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Sun, 21 Jul 2019 18:41:47 +0200 Subject: Remove unused and disabled "help" feature for extensions --- src/extension/dependency.h | 1 - src/extension/effect.cpp | 2 +- src/extension/extension.cpp | 29 +------------------------- src/extension/extension.h | 6 +----- src/extension/input.cpp | 2 +- src/extension/output.cpp | 2 +- src/extension/prefdialog/prefdialog.cpp | 36 +-------------------------------- src/extension/prefdialog/prefdialog.h | 3 --- src/ui/dialog/extension-editor.cpp | 8 -------- src/ui/dialog/extension-editor.h | 8 ++------ 10 files changed, 8 insertions(+), 89 deletions(-) diff --git a/src/extension/dependency.h b/src/extension/dependency.h index 6c360785b..3532eefcb 100644 --- a/src/extension/dependency.h +++ b/src/extension/dependency.h @@ -60,7 +60,6 @@ public: virtual ~Dependency (); bool check () const; const gchar* get_name(); - Glib::ustring &get_help () const; Glib::ustring &get_link () const; friend std::ostream & operator<< (std::ostream &out_file, const Dependency & in_dep); diff --git a/src/extension/effect.cpp b/src/extension/effect.cpp index c10ad10bd..ae06ff073 100644 --- a/src/extension/effect.cpp +++ b/src/extension/effect.cpp @@ -250,7 +250,7 @@ Effect::prefs (Inkscape::UI::View::View * doc) set_state(Extension::STATE_LOADED); if (!loaded()) return false; - _prefDialog = new PrefDialog(this->get_name(), this->get_help(), nullptr, this); + _prefDialog = new PrefDialog(this->get_name(), nullptr, this); _prefDialog->show(); return true; diff --git a/src/extension/extension.cpp b/src/extension/extension.cpp index bd593ea15..62d6f4590 100644 --- a/src/extension/extension.cpp +++ b/src/extension/extension.cpp @@ -51,8 +51,7 @@ std::ofstream Extension::error_file; 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) - : _help(nullptr) - , silent(false) + : silent(false) , _gui(true) , execution_env(nullptr) { @@ -87,9 +86,6 @@ Extension::Extension (Inkscape::XML::Node * in_repr, Implementation::Implementat if (!strcmp(chname, "name")) { name = g_strdup (child_repr->firstChild()->content()); } /* name */ - if (!strcmp(chname, "help")) { - _help = g_strdup (child_repr->firstChild()->content()); - } /* name */ if (!strcmp(chname, "param") || !strcmp(chname, "_param")) { Parameter * param; param = Parameter::make(child_repr, this); @@ -788,29 +784,6 @@ void Extension::add_val(Glib::ustring labelstr, Glib::ustring valuestr, Gtk::Gri return; } -Gtk::VBox * -Extension::get_help_widget() -{ - Gtk::VBox * retval = Gtk::manage(new Gtk::VBox()); - retval->set_border_width(4); - - if (_help == nullptr) { - Gtk::Label * content = Gtk::manage(new Gtk::Label(_("Currently there is no help available for this Extension. Please look on the Inkscape website or ask on the mailing lists if you have questions regarding this extension."))); - content->set_xalign(0); - content->set_yalign(0); - retval->pack_start(*content, true, true, 4); - content->set_line_wrap(true); - content->show(); - } else { - - - - } - - retval->show(); - return retval; -} - Gtk::VBox * Extension::get_params_widget() { diff --git a/src/extension/extension.h b/src/extension/extension.h index 619cb588e..dd93da6c2 100644 --- a/src/extension/extension.h +++ b/src/extension/extension.h @@ -101,7 +101,6 @@ public: private: gchar *id; /**< The unique identifier for the Extension */ gchar *name; /**< A user friendly name for the Extension */ - gchar *_help; /**< A string that contains a help text for the user */ state_t _state; /**< Which state the Extension is currently in */ std::vector _deps; /**< Dependencies for this extension */ static std::ofstream error_file; /**< This is the place where errors get reported */ @@ -126,9 +125,7 @@ public: Inkscape::XML::Node * get_repr (); gchar * get_id (); gchar * get_name (); - /** \brief Gets the help string for this extension */ - gchar const * get_help () { return _help; } - bool is_silent (); + bool is_silent (); void deactivate (); bool deactivated (); void printFailure (Glib::ustring reason); @@ -296,7 +293,6 @@ public: /* Extension editor dialog stuff */ public: Gtk::VBox * get_info_widget(); - Gtk::VBox * get_help_widget(); Gtk::VBox * get_params_widget(); protected: inline static void add_val(Glib::ustring labelstr, Glib::ustring valuestr, Gtk::Grid * table, int * row); diff --git a/src/extension/input.cpp b/src/extension/input.cpp index 792b794c8..dd9485202 100644 --- a/src/extension/input.cpp +++ b/src/extension/input.cpp @@ -224,7 +224,7 @@ Input::prefs (const gchar *uri) return true; } - PrefDialog * dialog = new PrefDialog(this->get_name(), this->get_help(), controls); + PrefDialog * dialog = new PrefDialog(this->get_name(), controls); int response = dialog->run(); dialog->hide(); diff --git a/src/extension/output.cpp b/src/extension/output.cpp index 51d58bc89..b4f483a91 100644 --- a/src/extension/output.cpp +++ b/src/extension/output.cpp @@ -187,7 +187,7 @@ Output::prefs () return true; } - PrefDialog * dialog = new PrefDialog(this->get_name(), this->get_help(), controls); + PrefDialog * dialog = new PrefDialog(this->get_name(), controls); int response = dialog->run(); dialog->hide(); diff --git a/src/extension/prefdialog/prefdialog.cpp b/src/extension/prefdialog/prefdialog.cpp index 90a156abe..e0fea98c8 100644 --- a/src/extension/prefdialog/prefdialog.cpp +++ b/src/extension/prefdialog/prefdialog.cpp @@ -36,16 +36,14 @@ namespace Extension { /** \brief Creates a new preference dialog for extension preferences \param name Name of the Extension whose dialog this is - \param help The help string for the extension (NULL if none) \param controls The extension specific widgets in the dialog This function initializes the dialog with the name of the extension in the title. It adds a few buttons and sets up handlers for them. It also places the passed-in widgets into the dialog. */ -PrefDialog::PrefDialog (Glib::ustring name, gchar const * help, Gtk::Widget * controls, Effect * effect) : +PrefDialog::PrefDialog (Glib::ustring name, Gtk::Widget * controls, Effect * effect) : Gtk::Dialog(_(name.c_str()), true), - _help(help), _name(name), _button_ok(nullptr), _button_cancel(nullptr), @@ -71,11 +69,6 @@ PrefDialog::PrefDialog (Glib::ustring name, gchar const * help, Gtk::Widget * co this->get_content_area()->pack_start(*hbox, true, true, 0); - /* - Gtk::Button * help_button = add_button(Gtk::Stock::HELP, Gtk::RESPONSE_HELP); - if (_help == NULL) - help_button->set_sensitive(false); - */ _button_cancel = add_button(_effect == nullptr ? _("_Cancel") : _("_Close"), Gtk::RESPONSE_CANCEL); _button_ok = add_button(_effect == nullptr ? _("_OK") : _("_Apply"), Gtk::RESPONSE_OK); set_default_response(Gtk::RESPONSE_OK); @@ -146,33 +139,6 @@ PrefDialog::~PrefDialog ( ) return; } -#if 0 -/** \brief Runs the dialog - \return The response to the dialog - - This function overrides the run function in the GTKmm dialog - class, but basically it only calls it. This function only - handles the \c Gtk::RESPONSE_HELP return, and in that case it - brings up the help window. All other return values are returned - to the calling function. -*/ -int -PrefDialog::run (void) { - int resp = Gtk::RESPONSE_HELP; - while (resp == Gtk::RESPONSE_HELP) { - resp = Gtk::Dialog::run(); - if (resp == Gtk::RESPONSE_HELP) { - /* - if (_helpDialog == NULL) { - _helpDialog = new HelpDialog(_help); - } - */ - } - } - return resp; -} -#endif - void PrefDialog::preview_toggle () { SPDesktop *desktop = SP_ACTIVE_DESKTOP; diff --git a/src/extension/prefdialog/prefdialog.h b/src/extension/prefdialog/prefdialog.h index 087900fbe..295b4a445 100644 --- a/src/extension/prefdialog/prefdialog.h +++ b/src/extension/prefdialog/prefdialog.h @@ -27,8 +27,6 @@ class Parameter; /** \brief A class to represent the preferences for an extension */ class PrefDialog : public Gtk::Dialog { - /** \brief Help string if it exists */ - gchar const * _help; /** \brief Name of the extension */ Glib::ustring _name; @@ -71,7 +69,6 @@ class PrefDialog : public Gtk::Dialog { public: PrefDialog (Glib::ustring name, - gchar const * help, Gtk::Widget * controls = nullptr, Effect * effect = nullptr); ~PrefDialog () override; diff --git a/src/ui/dialog/extension-editor.cpp b/src/ui/dialog/extension-editor.cpp index e324afcc7..1852010a0 100644 --- a/src/ui/dialog/extension-editor.cpp +++ b/src/ui/dialog/extension-editor.cpp @@ -41,7 +41,6 @@ ExtensionEditor::ExtensionEditor() : UI::Widget::Panel("/dialogs/extensioneditor", SP_VERB_DIALOG_EXTENSIONEDITOR) { _notebook_info.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); - _notebook_help.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); _notebook_params.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); //Main HBox @@ -73,7 +72,6 @@ ExtensionEditor::ExtensionEditor() hbox_list_page->pack_start(*vbox_page, true, true, 0); Gtk::Notebook * notebook = Gtk::manage(new Gtk::Notebook()); notebook->append_page(_notebook_info, *Gtk::manage(new Gtk::Label(_("Information")))); - notebook->append_page(_notebook_help, *Gtk::manage(new Gtk::Label(_("Help")))); notebook->append_page(_notebook_params, *Gtk::manage(new Gtk::Label(_("Parameters")))); vbox_page->pack_start(*notebook, true, true, 0); @@ -140,19 +138,16 @@ void ExtensionEditor::on_pagelist_selection_changed() /* Clear the notbook pages */ _notebook_info.remove(); - _notebook_help.remove(); _notebook_params.remove(); Inkscape::Extension::Extension * ext = Inkscape::Extension::db.get(id.c_str()); /* Make sure we have all the widgets */ Gtk::Widget * info = nullptr; - Gtk::Widget * help = nullptr; Gtk::Widget * params = nullptr; if (ext != nullptr) { info = ext->get_info_widget(); - help = ext->get_help_widget(); params = ext->get_params_widget(); } @@ -160,9 +155,6 @@ void ExtensionEditor::on_pagelist_selection_changed() if (info != nullptr) { _notebook_info.add(*info); } - if (help != nullptr) { - _notebook_help.add(*help); - } if (params != nullptr) { _notebook_params.add(*params); } diff --git a/src/ui/dialog/extension-editor.h b/src/ui/dialog/extension-editor.h index e9c45e209..403ee1fb5 100644 --- a/src/ui/dialog/extension-editor.h +++ b/src/ui/dialog/extension-editor.h @@ -33,8 +33,6 @@ public: static ExtensionEditor &getInstance() { return *new ExtensionEditor(); } - static void show_help (gchar const * extension_id); - protected: /** \brief The view of the list of extensions on the left of the dialog */ Gtk::TreeView _page_list; @@ -42,8 +40,6 @@ protected: Glib::RefPtr _page_list_model; /** \brief The notebook page that contains information */ Gtk::ScrolledWindow _notebook_info; - /** \brief The notebook page that contains help info */ - Gtk::ScrolledWindow _notebook_help; /** \brief The notebook page that holds all the parameters */ Gtk::ScrolledWindow _notebook_params; @@ -68,8 +64,8 @@ private: an item in the extension list */ Glib::ustring _selection_search; - ExtensionEditor(ExtensionEditor const &d); - ExtensionEditor& operator=(ExtensionEditor const &d); + ExtensionEditor(ExtensionEditor const &d) = delete; + ExtensionEditor& operator=(ExtensionEditor const &d) = delete; void on_pagelist_selection_changed(); static void dbfunc (Inkscape::Extension::Extension * in_plug, gpointer in_data); -- cgit v1.2.3 From 68a6771cd153a06d99c84901330e0c30fccfb9b7 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Sun, 21 Jul 2019 19:03:14 +0200 Subject: Remove effectively unused "silent" option from extensions. See also https://gitlab.com/inkscape/inkscape/merge_requests/698 --- src/extension/execution-env.cpp | 18 ++++++++---------- src/extension/extension.cpp | 16 +--------------- src/extension/extension.h | 2 -- 3 files changed, 9 insertions(+), 27 deletions(-) diff --git a/src/extension/execution-env.cpp b/src/extension/execution-env.cpp index a2bae3832..9293e5655 100644 --- a/src/extension/execution-env.cpp +++ b/src/extension/execution-env.cpp @@ -127,17 +127,15 @@ ExecutionEnv::createWorkingDialog () { _visibleDialog->signal_response().connect(sigc::mem_fun(this, &ExecutionEnv::workingCanceled)); g_free(dlgmessage); - if (!_effect->is_silent()){ - Gtk::Dialog *dlg = _effect->get_pref_dialog(); - if (dlg) { - _visibleDialog->set_transient_for(*dlg); - } else { - // ToDo: Do we need to make the window transient for the main window here? - // Currently imossible to test because of GUI freezing during save, - // see https://bugs.launchpad.net/inkscape/+bug/967416 - } - _visibleDialog->show_now(); + Gtk::Dialog *dlg = _effect->get_pref_dialog(); + if (dlg) { + _visibleDialog->set_transient_for(*dlg); + } else { + // ToDo: Do we need to make the window transient for the main window here? + // Currently imossible to test because of GUI freezing during save, + // see https://bugs.launchpad.net/inkscape/+bug/967416 } + _visibleDialog->show_now(); return; } diff --git a/src/extension/extension.cpp b/src/extension/extension.cpp index 62d6f4590..e5cee3b8e 100644 --- a/src/extension/extension.cpp +++ b/src/extension/extension.cpp @@ -51,8 +51,7 @@ std::ofstream Extension::error_file; 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) - : silent(false) - , _gui(true) + : _gui(true) , execution_env(nullptr) { repr = in_repr; @@ -103,9 +102,6 @@ Extension::Extension (Inkscape::XML::Node * in_repr, Implementation::Implementat } /* skip non-element nodes (see LP #1372200) */ } } /* check command as a dependency (see LP #505920) */ - if (!strcmp(chname, "options")) { - silent = !strcmp( child_repr->attribute("silent"), "true" ); - } child_repr = child_repr->next(); } @@ -319,16 +315,6 @@ Extension::get_repr () return repr; } -/** - \return bool - \brief Whether this extension should hide the "working, please wait" dialog -*/ -bool -Extension::is_silent () -{ - return silent; -} - /** \return The textual id of this extension \brief Get the ID of this extension - not a copy don't delete! diff --git a/src/extension/extension.h b/src/extension/extension.h index dd93da6c2..697219ae0 100644 --- a/src/extension/extension.h +++ b/src/extension/extension.h @@ -104,7 +104,6 @@ private: state_t _state; /**< Which state the Extension is currently in */ std::vector _deps; /**< Dependencies for this extension */ static std::ofstream error_file; /**< This is the place where errors get reported */ - bool silent; bool _gui; protected: @@ -125,7 +124,6 @@ public: Inkscape::XML::Node * get_repr (); gchar * get_id (); gchar * get_name (); - bool is_silent (); void deactivate (); bool deactivated (); void printFailure (Glib::ustring reason); -- cgit v1.2.3 From 93b1e80cf5516333d7a5068a2ba6bcc95f5577dc Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Sun, 21 Jul 2019 23:56:32 +0200 Subject: Use proper boolean values --- src/extension/internal/bitmap/raise.cpp | 2 +- src/extension/internal/filter/blurs.h | 2 +- src/extension/internal/svg.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/extension/internal/bitmap/raise.cpp b/src/extension/internal/bitmap/raise.cpp index b97455d4e..1f3c48502 100644 --- a/src/extension/internal/bitmap/raise.cpp +++ b/src/extension/internal/bitmap/raise.cpp @@ -42,7 +42,7 @@ Raise::init() "org.inkscape.effect.bitmap.raise\n" "6\n" "6\n" - "0\n" + "false\n" "\n" "all\n" "\n" diff --git a/src/extension/internal/filter/blurs.h b/src/extension/internal/filter/blurs.h index 7db128b7c..2d28f8546 100644 --- a/src/extension/internal/filter/blurs.h +++ b/src/extension/internal/filter/blurs.h @@ -56,7 +56,7 @@ public: "org.inkscape.effect.filter.Blur\n" "2\n" "2\n" - "False\n" + "false\n" "\n" "all\n" "\n" diff --git a/src/extension/internal/svg.cpp b/src/extension/internal/svg.cpp index 172a85a7f..abc702af5 100644 --- a/src/extension/internal/svg.cpp +++ b/src/extension/internal/svg.cpp @@ -686,7 +686,7 @@ Svg::init() "<_option value='optimizeSpeed' >" N_("Blocky (optimizeSpeed)") "\n" "\n" - "%s\n" + "false\n" "\n" ".svg\n" "image/svg+xml\n" -- cgit v1.2.3 From ef97e481b40f407f1328ecda471704750bd7e2a2 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Sun, 21 Jul 2019 23:58:51 +0200 Subject: Move error classes to Parameter where they belong --- src/extension/extension.h | 10 ---------- src/extension/prefdialog/parameter.cpp | 30 +++++++++++++++--------------- src/extension/prefdialog/parameter.h | 12 ++++++++++++ 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/extension/extension.h b/src/extension/extension.h index 697219ae0..25b70fc5b 100644 --- a/src/extension/extension.h +++ b/src/extension/extension.h @@ -154,16 +154,6 @@ public: unsigned int param_visible_count ( ); public: - /** An error class for when a parameter is called on a type it is not */ - class param_wrong_type {}; - class param_not_color_param {}; - class param_not_enum_param {}; - class param_not_optiongroup_param {}; - class param_not_string_param {}; - class param_not_float_param {}; - class param_not_int_param {}; - class param_not_bool_param {}; - /** An error class for when a parameter is looked for that just * simply doesn't exist */ class param_not_exist {}; diff --git a/src/extension/prefdialog/parameter.cpp b/src/extension/prefdialog/parameter.cpp index abda73e18..7a3748100 100644 --- a/src/extension/prefdialog/parameter.cpp +++ b/src/extension/prefdialog/parameter.cpp @@ -162,7 +162,7 @@ bool Parameter::get_bool(SPDocument const *doc, Inkscape::XML::Node const *node) { ParamBool const *boolpntr = dynamic_cast(this); if (!boolpntr) { - throw Extension::param_not_bool_param(); + throw param_not_bool_param(); } return boolpntr->get(doc, node); } @@ -171,7 +171,7 @@ int Parameter::get_int(SPDocument const *doc, Inkscape::XML::Node const *node) c { ParamInt const *intpntr = dynamic_cast(this); if (!intpntr) { - throw Extension::param_not_int_param(); + throw param_not_int_param(); } return intpntr->get(doc, node); } @@ -180,7 +180,7 @@ float Parameter::get_float(SPDocument const *doc, Inkscape::XML::Node const *nod { ParamFloat const *floatpntr = dynamic_cast(this); if (!floatpntr) { - throw Extension::param_not_float_param(); + throw param_not_float_param(); } return floatpntr->get(doc, node); } @@ -189,7 +189,7 @@ gchar const *Parameter::get_string(SPDocument const *doc, Inkscape::XML::Node co { ParamString const *stringpntr = dynamic_cast(this); if (!stringpntr) { - throw Extension::param_not_string_param(); + throw param_not_string_param(); } return stringpntr->get(doc, node); } @@ -198,7 +198,7 @@ gchar const *Parameter::get_enum(SPDocument const *doc, Inkscape::XML::Node cons { ParamComboBox const *param = dynamic_cast(this); if (!param) { - throw Extension::param_not_enum_param(); + throw param_not_enum_param(); } return param->get(doc, node); } @@ -207,7 +207,7 @@ bool Parameter::get_enum_contains(gchar const * value, SPDocument const *doc, In { ParamComboBox const *param = dynamic_cast(this); if (!param) { - throw Extension::param_not_enum_param(); + throw param_not_enum_param(); } return param->contains(value, doc, node); } @@ -216,7 +216,7 @@ gchar const *Parameter::get_optiongroup(SPDocument const *doc, Inkscape::XML::No { ParamRadioButton const *param = dynamic_cast(this); if (!param) { - throw Extension::param_not_optiongroup_param(); + throw param_not_optiongroup_param(); } return param->get(doc, node); } @@ -225,7 +225,7 @@ guint32 Parameter::get_color(const SPDocument* doc, Inkscape::XML::Node const *n { ParamColor const *param = dynamic_cast(this); if (!param) { - throw Extension::param_not_color_param(); + throw param_not_color_param(); } return param->get(doc, node); } @@ -234,7 +234,7 @@ bool Parameter::set_bool(bool in, SPDocument * doc, Inkscape::XML::Node * node) { ParamBool * boolpntr = dynamic_cast(this); if (boolpntr == nullptr) - throw Extension::param_not_bool_param(); + throw param_not_bool_param(); return boolpntr->set(in, doc, node); } @@ -242,7 +242,7 @@ int Parameter::set_int(int in, SPDocument * doc, Inkscape::XML::Node * node) { ParamInt * intpntr = dynamic_cast(this); if (intpntr == nullptr) - throw Extension::param_not_int_param(); + throw param_not_int_param(); return intpntr->set(in, doc, node); } @@ -253,7 +253,7 @@ Parameter::set_float (float in, SPDocument * doc, Inkscape::XML::Node * node) ParamFloat * floatpntr; floatpntr = dynamic_cast(this); if (floatpntr == nullptr) - throw Extension::param_not_float_param(); + throw param_not_float_param(); return floatpntr->set(in, doc, node); } @@ -263,7 +263,7 @@ Parameter::set_string (gchar const * in, SPDocument * doc, Inkscape::XML::Node * { ParamString * stringpntr = dynamic_cast(this); if (stringpntr == nullptr) - throw Extension::param_not_string_param(); + throw param_not_string_param(); return stringpntr->set(in, doc, node); } @@ -271,7 +271,7 @@ gchar const * Parameter::set_optiongroup( gchar const * in, SPDocument * doc, In { ParamRadioButton *param = dynamic_cast(this); if (!param) { - throw Extension::param_not_optiongroup_param(); + throw param_not_optiongroup_param(); } return param->set(in, doc, node); } @@ -280,7 +280,7 @@ gchar const *Parameter::set_enum( gchar const * in, SPDocument * doc, Inkscape:: { ParamComboBox *param = dynamic_cast(this); if (!param) { - throw Extension::param_not_enum_param(); + throw param_not_enum_param(); } return param->set(in, doc, node); } @@ -292,7 +292,7 @@ Parameter::set_color (guint32 in, SPDocument * doc, Inkscape::XML::Node * node) { ParamColor* param = dynamic_cast(this); if (param == nullptr) - throw Extension::param_not_color_param(); + throw param_not_color_param(); return param->set(in, doc, node); } diff --git a/src/extension/prefdialog/parameter.h b/src/extension/prefdialog/parameter.h index 39433b902..25762f725 100644 --- a/src/extension/prefdialog/parameter.h +++ b/src/extension/prefdialog/parameter.h @@ -168,6 +168,18 @@ public: const static int GUI_MAX_LINE_LENGTH = 60; + /** An error class for when a parameter is called on a type it is not */ + class param_no_name {}; + class param_no_type {}; + class param_not_color_param {}; + class param_not_enum_param {}; + class param_not_optiongroup_param {}; + class param_not_string_param {}; + class param_not_float_param {}; + class param_not_int_param {}; + class param_not_bool_param {}; + + protected: /** Parameter text to show as the GUI label. */ gchar * _text; -- cgit v1.2.3 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 +- src/io/file-export-cmd.cpp | 15 +- 50 files changed, 1371 insertions(+), 1955 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 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. + // -