diff options
| author | Andrew Higginson <at.higginson@gmail.com> | 2011-12-27 21:04:47 +0000 |
|---|---|---|
| committer | Andrew <at.higginson@gmail.com> | 2011-12-27 21:04:47 +0000 |
| commit | 80960b623a99aae1402ab651b2974ef544ed3b03 (patch) | |
| tree | ba49d42c2789e9e11f805e2d5263e10f9fedeef8 /src/extension/param | |
| parent | try to fix bug (diff) | |
| parent | GDL: Cherry-pick upstream patch 73852 (2011-03-23) - Add missing return value. (diff) | |
| download | inkscape-80960b623a99aae1402ab651b2974ef544ed3b03.tar.gz inkscape-80960b623a99aae1402ab651b2974ef544ed3b03.zip | |
merged with trunk so I can build again...
(bzr r10092.1.36)
Diffstat (limited to 'src/extension/param')
23 files changed, 1056 insertions, 857 deletions
diff --git a/src/extension/param/CMakeLists.txt b/src/extension/param/CMakeLists.txt deleted file mode 100644 index 2ef5d5005..000000000 --- a/src/extension/param/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -SET(extension_param_SRC -bool.cpp -color.cpp -description.cpp -groupheader.cpp -enum.cpp -parameter.cpp -float.cpp -int.cpp -notebook.cpp -radiobutton.cpp -string.cpp -) - diff --git a/src/extension/param/bool.cpp b/src/extension/param/bool.cpp index a8a410382..3073d2e76 100644 --- a/src/extension/param/bool.cpp +++ b/src/extension/param/bool.cpp @@ -2,6 +2,7 @@ * Copyright (C) 2005-2007 Authors: * Ted Gould <ted@gould.cx> * Johan Engelen <johan@shouraizou.nl> * + * Jon A. Cruz <jon@joncruz.org> * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -21,13 +22,14 @@ namespace Inkscape { namespace Extension { -/** \brief Use the superclass' allocator and set the \c _value */ -ParamBool::ParamBool (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), _value(false) +ParamBool::ParamBool(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : + Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), + _value(false), _indent(0) { const char * defaultval = NULL; - if (sp_repr_children(xml) != NULL) + if (sp_repr_children(xml) != NULL) { defaultval = sp_repr_children(xml)->content(); + } if (defaultval != NULL && (!strcmp(defaultval, "true") || !strcmp(defaultval, "true") || !strcmp(defaultval, "1"))) { _value = true; @@ -35,6 +37,11 @@ ParamBool::ParamBool (const gchar * name, const gchar * guitext, const gchar * d _value = false; } + const char * indent = xml->attribute("indent"); + if (indent != NULL) { + _indent = atoi(indent) * 12; + } + gchar * pref_name = this->pref_name(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); _value = prefs->getBool(extension_pref_root + pref_name, _value); @@ -43,17 +50,7 @@ ParamBool::ParamBool (const gchar * name, const gchar * guitext, const gchar * d return; } -/** \brief A function to set the \c _value - \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 - - 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. -*/ -bool -ParamBool::set( bool in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/ ) +bool ParamBool::set( bool in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/ ) { _value = in; @@ -65,46 +62,47 @@ ParamBool::set( bool in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/ ) return _value; } -/** \brief Returns \c _value */ -bool -ParamBool::get (const SPDocument * doc, const Inkscape::XML::Node * node) +bool ParamBool::get(const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) const { - return _value; + return _value; } -/** \brief A check button which is Param aware. It works with the - parameter to change it's value as the check button changes - 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 { -private: - /** \brief Param to change */ - ParamBool * _pref; - SPDocument * _doc; - Inkscape::XML::Node * _node; - sigc::signal<void> * _changeSignal; public: - /** \brief Initialize the check button - \param param Which parameter to adjust on changing 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. - */ + /** + * 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, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) : Gtk::CheckButton(), _pref(param), _doc(doc), _node(node), _changeSignal(changeSignal) { this->set_active(_pref->get(NULL, NULL) /**\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 (void); -}; -/** - \brief A function to respond to the check box changing +private: + /** Param to change. */ + ParamBool * _pref; + SPDocument * _doc; + Inkscape::XML::Node * _node; + sigc::signal<void> * _changeSignal; +}; - Adjusts the value of the preference to match that in the check box. -*/ -void -ParamBoolCheckButton::on_toggle (void) +void ParamBoolCheckButton::on_toggle(void) { _pref->set(this->get_active(), NULL /**\todo fix this */, NULL); if (_changeSignal != NULL) { @@ -113,9 +111,7 @@ ParamBoolCheckButton::on_toggle (void) return; } -/** \brief Return 'true' or 'false' */ -void -ParamBool::string (std::string &string) +void ParamBool::string(std::string &string) const { if (_value) { string += "true"; @@ -126,15 +122,12 @@ ParamBool::string (std::string &string) return; } -/** - \brief Creates a bool check button for a bool parameter - - Builds a hbox with a label and a check button in it. -*/ -Gtk::Widget * -ParamBool::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) +Gtk::Widget *ParamBool::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) { - if (_gui_hidden) return NULL; + if (_gui_hidden) { + return NULL; + } + Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT)); @@ -143,7 +136,7 @@ ParamBool::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signa ParamBoolCheckButton * checkbox = Gtk::manage(new ParamBoolCheckButton(this, doc, node, changeSignal)); checkbox->show(); - hbox->pack_start(*checkbox, false, false); + hbox->pack_start(*checkbox, false, false, _indent); hbox->show(); diff --git a/src/extension/param/bool.h b/src/extension/param/bool.h index a1cd4ce4a..11d06e1c0 100644 --- a/src/extension/param/bool.h +++ b/src/extension/param/bool.h @@ -1,9 +1,10 @@ -#ifndef __INK_EXTENSION_PARAMBOOL_H__ -#define __INK_EXTENSION_PARAMBOOL_H__ +#ifndef SEEN_INK_EXTENSION_PARAMBOOL_H +#define SEEN_INK_EXTENSION_PARAMBOOL_H /* * Copyright (C) 2005-2007 Authors: * Ted Gould <ted@gould.cx> * Johan Engelen <johan@shouraizou.nl> * + * Jon A. Cruz <jon@joncruz.org> * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -15,23 +16,59 @@ namespace Inkscape { namespace Extension { -/** \brief A boolean parameter */ +/** + * A boolean parameter. + */ class ParamBool : public Parameter { -private: - /** \brief Internal value. */ - bool _value; public: + + /** + * Use the superclass' allocator and set the \c _value. + */ ParamBool(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); - bool get (const SPDocument * doc, const Inkscape::XML::Node * node); - bool set (bool in, SPDocument * doc, Inkscape::XML::Node * node); - Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); - void string (std::string &string); + + /** + * 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<void> * changeSignal); + + // Explicitly call superclass version to avoid method being hidden. + virtual void string(std::list <std::string> &list) const { return Parameter::string(list); } + + /** + * Appends 'true' or 'false'. + * @todo investigate. Returning a value that can then be appended would probably work better/safer. + */ + virtual void string(std::string &string) const; + +private: + /** Internal value. */ + bool _value; + int _indent; }; -} /* namespace Extension */ -} /* namespace Inkscape */ +} // namespace Extension +} // namespace Inkscape -#endif /* __INK_EXTENSION_PARAMBOOL_H__ */ +#endif // SEEN_INK_EXTENSION_PARAMBOOL_H /* Local Variables: diff --git a/src/extension/param/color.cpp b/src/extension/param/color.cpp index 58db85748..6600d5f2a 100644 --- a/src/extension/param/color.cpp +++ b/src/extension/param/color.cpp @@ -3,6 +3,7 @@ * Ted Gould <ted@gould.cx> * Johan Engelen <johan@shouraizou.nl> * Christopher Brown <audiere@gmail.com> + * Jon A. Cruz <jon@joncruz.org> * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -40,8 +41,7 @@ ParamColor::~ParamColor(void) } -guint32 -ParamColor::set( guint32 in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/ ) +guint32 ParamColor::set( guint32 in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/ ) { _value = in; @@ -58,7 +58,8 @@ ParamColor::set( guint32 in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node* /** \brief Initialize the object, to do that, copy the data. */ ParamColor::ParamColor (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext) + Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), + _changeSignal(0) { const char * defaulthex = NULL; if (sp_repr_children(xml) != NULL) @@ -73,21 +74,16 @@ ParamColor::ParamColor (const gchar * name, const gchar * guitext, const gchar * defaulthex = paramval.data(); _value = atoi(defaulthex); - - return; } -void -ParamColor::string (std::string &string) +void ParamColor::string(std::string &string) const { char str[16]; sprintf(str, "%i", _value); string += str; - return; } -Gtk::Widget * -ParamColor::get_widget( SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal<void> * changeSignal ) +Gtk::Widget *ParamColor::get_widget( SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal<void> * changeSignal ) { if (_gui_hidden) return NULL; @@ -112,8 +108,7 @@ ParamColor::get_widget( SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, si return dynamic_cast<Gtk::Widget *>(hbox); } -void -sp_color_param_changed(SPColorSelector *csel, GObject *obj) +void sp_color_param_changed(SPColorSelector *csel, GObject *obj) { const SPColor color = csel->base->getColor(); float alpha = csel->base->getAlpha(); diff --git a/src/extension/param/color.h b/src/extension/param/color.h index e6b44fbcb..f46e26286 100644 --- a/src/extension/param/color.h +++ b/src/extension/param/color.h @@ -1,9 +1,10 @@ -#ifndef __INK_EXTENSION_PARAMCOLOR_H__ -#define __INK_EXTENSION_PARAMCOLOR_H__ +#ifndef SEEN_INK_EXTENSION_PARAMCOLOR_H__ +#define SEEN_INK_EXTENSION_PARAMCOLOR_H__ /* * Copyright (C) 2005-2007 Authors: * Ted Gould <ted@gould.cx> * Johan Engelen <johan@shouraizou.nl> * + * Jon A. Cruz <jon@joncruz.org> * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -21,16 +22,36 @@ private: guint32 _value; public: ParamColor(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); + virtual ~ParamColor(void); - /** \brief Returns \c _value, with a \i const to protect it. */ - guint32 get( const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/ ) { return _value; } + + /** Returns \c _value, with a \i const to protect it. */ + guint32 get( SPDocument const * /*doc*/, Inkscape::XML::Node const * /*node*/ ) const { return _value; } + guint32 set (guint32 in, SPDocument * doc, Inkscape::XML::Node * node); + Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); - void string (std::string &string); + + // Explicitly call superclass version to avoid method being hidden. + virtual void string(std::list <std::string> &list) const { return Parameter::string(list); } + + virtual void string (std::string &string) const; + sigc::signal<void> * _changeSignal; -}; /* class ParamColor */ +}; // class ParamColor -} /* namespace Extension */ -} /* namespace Inkscape */ +} // namespace Extension +} // namespace Inkscape -#endif /* __INK_EXTENSION_PARAMCOLOR_H__ */ +#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 index f17b45b4b..7a68aff62 100644 --- a/src/extension/param/description.cpp +++ b/src/extension/param/description.cpp @@ -30,19 +30,35 @@ namespace Extension { /** \brief Initialize the object, to do that, copy the data. */ -ParamDescription::ParamDescription (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), _value(NULL) +ParamDescription::ParamDescription (const gchar * name, + const gchar * guitext, + const gchar * desc, + const Parameter::_scope_t scope, + bool gui_hidden, + const gchar * gui_tip, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml, + AppearanceMode mode) : + Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), + _value(NULL), _mode(mode), _indent(0) { // printf("Building Description\n"); const char * defaultval = NULL; - if (sp_repr_children(xml) != NULL) + if (sp_repr_children(xml) != NULL) { defaultval = sp_repr_children(xml)->content(); + } - if (defaultval != NULL) + if (defaultval != NULL) { _value = g_strdup(defaultval); - + } + _context = xml->attribute("msgctxt"); - + + const char * indent = xml->attribute("indent"); + if (indent != NULL) { + _indent = atoi(indent) * 12; + } + return; } @@ -50,7 +66,9 @@ ParamDescription::ParamDescription (const gchar * name, const gchar * guitext, c Gtk::Widget * ParamDescription::get_widget (SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal<void> * /*changeSignal*/) { - if (_gui_hidden) return NULL; + if (_gui_hidden) { + return NULL; + } Glib::ustring newguitext; @@ -60,13 +78,21 @@ ParamDescription::get_widget (SPDocument * /*doc*/, Inkscape::XML::Node * /*node newguitext = _(_value); } - Gtk::Label * label = Gtk::manage(new Gtk::Label(newguitext, Gtk::ALIGN_LEFT)); - + Gtk::Label * label; + int padding = 12 + _indent; + if (_mode == HEADER) { + label = Gtk::manage(new Gtk::Label(Glib::ustring("<b>") +newguitext + Glib::ustring("</b>"), Gtk::ALIGN_LEFT)); + label->set_padding(0,5); + label->set_use_markup(true); + padding = _indent; + } else { + label = Gtk::manage(new Gtk::Label(newguitext, Gtk::ALIGN_LEFT)); + } label->set_line_wrap(); label->show(); Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); - hbox->pack_start(*label, true, true, 12); + hbox->pack_start(*label, true, true, padding); hbox->show(); return hbox; diff --git a/src/extension/param/description.h b/src/extension/param/description.h index c56b5c21d..a33ff719a 100644 --- a/src/extension/param/description.h +++ b/src/extension/param/description.h @@ -18,13 +18,26 @@ namespace Extension { /** \brief A description parameter */ class ParamDescription : public Parameter { +public: + enum AppearanceMode { + DESC, HEADER + }; + ParamDescription(const gchar * name, + const gchar * guitext, + const gchar * desc, + const Parameter::_scope_t scope, + bool gui_hidden, + const gchar * gui_tip, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml, + AppearanceMode mode); + Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); private: /** \brief Internal value. */ gchar * _value; + AppearanceMode _mode; + int _indent; const gchar* _context; -public: - ParamDescription(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); - Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); }; } /* namespace Extension */ diff --git a/src/extension/param/enum.cpp b/src/extension/param/enum.cpp index 9ed5aac16..755cc92ad 100644 --- a/src/extension/param/enum.cpp +++ b/src/extension/param/enum.cpp @@ -7,6 +7,7 @@ /* * Author: * Johan Engelen <johan@shouraizou.nl> + * Jon A. Cruz <jon@joncruz.org> * * Copyright (C) 2006-2007 Johan Engelen * @@ -49,7 +50,7 @@ public: ParamComboBox::ParamComboBox (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext) + Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), _indent(0) { choices = NULL; _value = NULL; @@ -62,7 +63,9 @@ ParamComboBox::ParamComboBox (const gchar * name, const gchar * guitext, const g if (!strcmp(chname, INKSCAPE_EXTENSION_NS "item") || !strcmp(chname, INKSCAPE_EXTENSION_NS "_item")) { Glib::ustring newguitext, newvalue; const char * contents = NULL; - if (node->firstChild()) contents = node->firstChild()->content(); + if (node->firstChild()) { + contents = node->firstChild()->content(); + } if (contents != NULL) { // don't translate when 'item' but do translate when '_item' // NOTE: internal extensions use build_from_mem and don't need _item but @@ -80,10 +83,11 @@ ParamComboBox::ParamComboBox (const gchar * name, const gchar * guitext, const g continue; const char * val = node->attribute("value"); - if (val != NULL) + if (val != NULL) { newvalue = val; - else + } else { newvalue = contents; + } if ( (!newguitext.empty()) && (!newvalue.empty()) ) { // logical error if this is not true here choices = g_slist_append( choices, new enumentry(newvalue, newguitext) ); @@ -95,20 +99,26 @@ ParamComboBox::ParamComboBox (const gchar * name, const gchar * guitext, const g // Initialize _value with the default value from xml // for simplicity : default to the contents of the first xml-child const char * defaultval = NULL; - if (xml->firstChild() && xml->firstChild()->firstChild()) + if (xml->firstChild() && xml->firstChild()->firstChild()) { defaultval = xml->firstChild()->attribute("value"); + } + + const char * indent = xml->attribute("indent"); + if (indent != NULL) { + _indent = atoi(indent) * 12; + } 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()) + if (!paramval.empty()) { defaultval = paramval.data(); - if (defaultval != NULL) + } + if (defaultval != NULL) { _value = g_strdup(defaultval); - - return; + } } ParamComboBox::~ParamComboBox (void) @@ -123,23 +133,26 @@ ParamComboBox::~ParamComboBox (void) } -/** \brief A function to set the \c _value - \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 - - 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(). -*/ -const gchar * -ParamComboBox::set (const gchar * in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) +/** + * 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 == NULL) return NULL; /* Can't have NULL string */ + if (in == NULL) { + return NULL; /* Can't have NULL string */ + } Glib::ustring settext; for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { @@ -150,7 +163,9 @@ ParamComboBox::set (const gchar * in, SPDocument * /*doc*/, Inkscape::XML::Node } } if (!settext.empty()) { - if (_value != NULL) g_free(_value); + if (_value != NULL) { + g_free(_value); + } _value = g_strdup(settext.data()); gchar * prefname = this->pref_name(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -166,22 +181,15 @@ ParamComboBox::changed (void) { } - -/** - \brief A function to get the value of the parameter in string form - \return A string with the 'value' as command line argument -*/ -void -ParamComboBox::string (std::string &string) +void ParamComboBox::string(std::string &string) const { string += _value; - return; } -/** \brief A special category of Gtk::Entry to handle string parameteres */ +/** A special category of Gtk::Entry to handle string parameteres. */ class ParamComboBoxEntry : public Gtk::ComboBoxText { private: ParamComboBox * _pref; @@ -189,10 +197,11 @@ private: Inkscape::XML::Node * _node; sigc::signal<void> * _changeSignal; public: - /** \brief Build a string preference for the given parameter - \param pref Where to get the string from, and where to put it - when it changes. - */ + /** + * 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<void> * changeSignal) : Gtk::ComboBoxText(), _pref(pref), _doc(doc), _node(node), _changeSignal(changeSignal) { this->signal_changed().connect(sigc::mem_fun(this, &ParamComboBoxEntry::changed)); @@ -200,11 +209,12 @@ public: void changed (void); }; -/** \brief 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. -*/ +/** + * 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 (void) { @@ -216,18 +226,19 @@ ParamComboBoxEntry::changed (void) } /** - \brief Creates a combobox widget for an enumeration parameter -*/ -Gtk::Widget * -ParamComboBox::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) + * Creates a combobox widget for an enumeration parameter. + */ +Gtk::Widget *ParamComboBox::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) { - if (_gui_hidden) return NULL; + if (_gui_hidden) { + return NULL; + } Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT)); label->show(); - hbox->pack_start(*label, false, false); + hbox->pack_start(*label, false, false, _indent); ParamComboBoxEntry * combo = Gtk::manage(new ParamComboBoxEntry(this, doc, node, changeSignal)); // add choice strings: @@ -240,7 +251,9 @@ ParamComboBox::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::s settext = entr->guitext; } } - if (!settext.empty()) combo->set_active_text(settext); + if (!settext.empty()) { + combo->set_active_text(settext); + } combo->show(); hbox->pack_start(*combo, true, true); @@ -251,5 +264,16 @@ ParamComboBox::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::s } -} /* namespace Extension */ -} /* namespace Inkscape */ +} // 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 index 3f9707c34..a598458c5 100644 --- a/src/extension/param/enum.h +++ b/src/extension/param/enum.h @@ -6,8 +6,9 @@ */ /* - * Author: + * Authors: * Johan Engelen <johan@shouraizou.nl> + * Jon A. Cruz <jon@joncruz.org> * * Copyright (C) 2006-2007 Johan Engelen * @@ -17,13 +18,13 @@ #include <gtkmm/widget.h> #include "xml/document.h" -#include <extension/extension-forward.h> #include "parameter.h" namespace Inkscape { namespace Extension { +class Extension; // \brief A class to represent a notebookparameter of an extension @@ -33,16 +34,21 @@ private: been allocated in memory. And should be free'd. It is the value of the current selected string */ gchar * _value; - + int _indent; GSList * choices; /**< A table to store the choice strings */ public: ParamComboBox(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); virtual ~ParamComboBox(void); Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); - void string (std::string &string); - const gchar * get (const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) { return _value; } + // Explicitly call superclass version to avoid method being hidden. + virtual void string(std::list <std::string> &list) const { return Parameter::string(list); } + + virtual void string(std::string &string) const; + + 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); void changed (void); diff --git a/src/extension/param/float.cpp b/src/extension/param/float.cpp index 62762b3bb..2b501a9a4 100644 --- a/src/extension/param/float.cpp +++ b/src/extension/param/float.cpp @@ -2,6 +2,7 @@ * Copyright (C) 2005-2007 Authors: * Ted Gould <ted@gould.cx> * Johan Engelen <johan@shouraizou.nl> * + * Jon A. Cruz <jon@joncruz.org> * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -11,7 +12,8 @@ #include <gtkmm/adjustment.h> #include <gtkmm/box.h> -#include <gtkmm/spinbutton.h> +#include <gtkmm/scale.h> +#include "ui/widget/spinbutton.h" #include "xml/node.h" #include "extension/extension.h" @@ -22,29 +24,42 @@ namespace Inkscape { namespace Extension { -/** \brief Use the superclass' allocator and set the \c _value */ -ParamFloat::ParamFloat (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), _value(0.0), _min(0.0), _max(10.0) +/** Use the superclass' allocator and set the \c _value. */ +ParamFloat::ParamFloat (const gchar * name, + const gchar * guitext, + const gchar * desc, + const Parameter::_scope_t scope, + bool gui_hidden, + const gchar * gui_tip, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml, + AppearanceMode mode) : + Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), + _value(0.0), _mode(mode), _indent(0), _min(0.0), _max(10.0) { const gchar * defaultval = NULL; - if (sp_repr_children(xml) != NULL) + if (sp_repr_children(xml) != NULL) { defaultval = sp_repr_children(xml)->content(); + } if (defaultval != NULL) { _value = g_ascii_strtod (defaultval,NULL); } const char * maxval = xml->attribute("max"); - if (maxval != NULL) + if (maxval != NULL) { _max = g_ascii_strtod (maxval,NULL); + } const char * minval = xml->attribute("min"); - if (minval != NULL) + if (minval != NULL) { _min = g_ascii_strtod (minval,NULL); + } _precision = 1; const char * precision = xml->attribute("precision"); - if (precision != NULL) + if (precision != NULL) { _precision = atoi(precision); + } /* We're handling this by just killing both values */ if (_max < _min) { @@ -52,6 +67,11 @@ ParamFloat::ParamFloat (const gchar * name, const gchar * guitext, const gchar * _min = 0.0; } + const char * indent = xml->attribute("indent"); + if (indent != NULL) { + _indent = atoi(indent) * 12; + } + gchar * pref_name = this->pref_name(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); _value = prefs->getDouble(extension_pref_root + pref_name, _value); @@ -59,27 +79,36 @@ ParamFloat::ParamFloat (const gchar * name, const gchar * guitext, const gchar * // std::cout << "New Float:: value: " << _value << " max: " << _max << " min: " << _min << std::endl; - if (_value > _max) _value = _max; - if (_value < _min) _value = _min; + if (_value > _max) { + _value = _max; + } + if (_value < _min) { + _value = _min; + } return; } -/** \brief A function to set the \c _value - \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 - - 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. -*/ -float -ParamFloat::set (float in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) +/** + * 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; + if (_value > _max) { + _value = _max; + } + if (_value < _min) { + _value = _min; + } gchar * prefname = this->pref_name(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -89,9 +118,7 @@ ParamFloat::set (float in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) return _value; } -/** \brief Return the value as a string */ -void -ParamFloat::string (std::string &string) +void ParamFloat::string(std::string &string) const { char startstring[G_ASCII_DTOSTR_BUF_SIZE]; g_ascii_dtostr(startstring, G_ASCII_DTOSTR_BUF_SIZE, _value); @@ -99,18 +126,18 @@ ParamFloat::string (std::string &string) return; } -/** \brief A class to make an adjustment that uses Extension params */ +/** A class to make an adjustment that uses Extension params. */ class ParamFloatAdjustment : public Gtk::Adjustment { - /** The parameter to adjust */ + /** The parameter to adjust. */ ParamFloat * _pref; SPDocument * _doc; Inkscape::XML::Node * _node; sigc::signal<void> * _changeSignal; public: - /** \brief Make the adjustment using an extension and the string + /** Make the adjustment using an extension and the string describing the parameter. */ ParamFloatAdjustment (ParamFloat * param, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) : - Gtk::Adjustment(0.0, param->min(), param->max(), 0.1, 0), _pref(param), _doc(doc), _node(node), _changeSignal(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(NULL, NULL) /* \todo fix */); this->signal_value_changed().connect(sigc::mem_fun(this, &ParamFloatAdjustment::val_changed)); return; @@ -119,14 +146,13 @@ public: void val_changed (void); }; /* class ParamFloatAdjustment */ -/** \brief 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 (void) +/** + * 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(void) { //std::cout << "Value Changed to: " << this->get_value() << std::endl; _pref->set(this->get_value(), _doc, _node); @@ -137,23 +163,33 @@ ParamFloatAdjustment::val_changed (void) } /** - \brief 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<void> * changeSignal) + * 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<void> * changeSignal) { - if (_gui_hidden) return NULL; + if (_gui_hidden) { + return NULL; + } Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT)); label->show(); - hbox->pack_start(*label, true, true); + hbox->pack_start(*label, true, true, _indent); ParamFloatAdjustment * fadjust = Gtk::manage(new ParamFloatAdjustment(this, doc, node, changeSignal)); - Gtk::SpinButton * spin = Gtk::manage(new Gtk::SpinButton(*fadjust, 0.1, _precision)); + + if (_mode == FULL) { + Gtk::HScale * scale = Gtk::manage(new Gtk::HScale(*fadjust)); + scale->set_draw_value(false); + scale->set_size_request(200, -1); + scale->show(); + hbox->pack_start(*scale, false, false); + } + + Inkscape::UI::Widget::SpinButton * spin = Gtk::manage(new Inkscape::UI::Widget::SpinButton(*fadjust, 0.1, _precision)); spin->show(); hbox->pack_start(*spin, false, false); diff --git a/src/extension/param/float.h b/src/extension/param/float.h index f105d8f0e..24747b5f1 100644 --- a/src/extension/param/float.h +++ b/src/extension/param/float.h @@ -5,6 +5,7 @@ * Copyright (C) 2005-2007 Authors: * Ted Gould <ted@gould.cx> * Johan Engelen <johan@shouraizou.nl> * + * Jon A. Cruz <jon@joncruz.org> * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -17,22 +18,45 @@ namespace Inkscape { namespace Extension { class ParamFloat : public Parameter { -private: - /** \brief Internal value. */ - float _value; - float _min; - float _max; - int _precision; public: - ParamFloat (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); - /** \brief Returns \c _value */ - float get (const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) { return _value; } + enum AppearanceMode { + FULL, MINIMAL + }; + ParamFloat (const gchar * name, + const gchar * guitext, + const gchar * desc, + const Parameter::_scope_t scope, + bool gui_hidden, + const gchar * gui_tip, + 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 (void) { return _max; } + float min (void) { return _min; } + float precision (void) { return _precision; } + Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); - void string (std::string &string); + + // Explicitly call superclass version to avoid method being hidden. + virtual void string(std::list <std::string> &list) const { return Parameter::string(list); } + + virtual void string(std::string &string) const; + +private: + /** Internal value. */ + float _value; + AppearanceMode _mode; + int _indent; + float _min; + float _max; + int _precision; }; } /* namespace Extension */ diff --git a/src/extension/param/groupheader.cpp b/src/extension/param/groupheader.cpp deleted file mode 100755 index abf5f8beb..000000000 --- a/src/extension/param/groupheader.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2005-2010 Authors: - * Ted Gould <ted@gould.cx> - * Johan Engelen <johan@shouraizou.nl> * - * Nicolas Dufour <nicoduf@yahoo.fr> - * Released under GNU GPL, 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 - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - - -#include "groupheader.h" - -#include <gtkmm/adjustment.h> -#include <gtkmm/box.h> -#include <gtkmm/spinbutton.h> -#include <sstream> -#include <glibmm/i18n.h> - -#include "xml/node.h" -#include "extension/extension.h" - -namespace Inkscape { -namespace Extension { - - -/** \brief Initialize the object, to do that, copy the data. */ -ParamGroupHeader::ParamGroupHeader (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), _value(NULL) -{ - // printf("Building GroupHeader\n"); - const char * defaultval = NULL; - if (sp_repr_children(xml) != NULL) - defaultval = sp_repr_children(xml)->content(); - - if (defaultval != NULL) - _value = g_strdup(defaultval); - - _context = xml->attribute("msgctxt"); - - return; -} - -/** \brief Create a label for the GroupHeader */ -Gtk::Widget * -ParamGroupHeader::get_widget (SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal<void> * /*changeSignal*/) -{ - if (_gui_hidden) return NULL; - - Glib::ustring newguitext; - - if (_context != NULL) { - newguitext = g_dpgettext2(NULL, _context, _value); - } else { - newguitext = _(_value); - } - - Gtk::Label * label = Gtk::manage(new Gtk::Label(Glib::ustring("<b>") +newguitext + Glib::ustring("</b>"), Gtk::ALIGN_LEFT)); - label->set_line_wrap(); - label->set_padding(0,5); - label->set_use_markup(true); - label->show(); - - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); - hbox->pack_start(*label, true, true); - hbox->show(); - - return hbox; -} - -} /* namespace Extension */ -} /* namespace Inkscape */ diff --git a/src/extension/param/groupheader.h b/src/extension/param/groupheader.h deleted file mode 100755 index 94fe880f9..000000000 --- a/src/extension/param/groupheader.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef __INK_EXTENSION_PARAMGROUPHEADER_H__ -#define __INK_EXTENSION_PARAMGROUPHEADER_H__ - -/* - * Copyright (C) 2005-2010 Authors: - * Ted Gould <ted@gould.cx> - * Johan Engelen <johan@shouraizou.nl> * - * Nicolas Dufour <nicoduf@yahoo.fr> - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include <gtkmm/widget.h> -#include <xml/node.h> -#include <document.h> -#include "parameter.h" - -namespace Inkscape { -namespace Extension { - -/** \brief A GroupLabel parameter */ -class ParamGroupHeader : public Parameter { -private: - /** \brief Internal value. */ - gchar * _value; - const gchar* _context; -public: - ParamGroupHeader(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); - Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); -}; - -} /* namespace Extension */ -} /* namespace Inkscape */ - -#endif /* __INK_EXTENSION_PARAMGROUPHEADER_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/int.cpp b/src/extension/param/int.cpp index ae69d0661..cd6815c4d 100644 --- a/src/extension/param/int.cpp +++ b/src/extension/param/int.cpp @@ -2,6 +2,7 @@ * Copyright (C) 2005-2007 Authors: * Ted Gould <ted@gould.cx> * Johan Engelen <johan@shouraizou.nl> * + * Jon A. Cruz <jon@joncruz.org> * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -11,7 +12,8 @@ #include <gtkmm/adjustment.h> #include <gtkmm/box.h> -#include <gtkmm/spinbutton.h> +#include <gtkmm/scale.h> +#include "ui/widget/spinbutton.h" #include "xml/node.h" #include "extension/extension.h" @@ -22,31 +24,47 @@ namespace Inkscape { namespace Extension { -/** \brief Use the superclass' allocator and set the \c _value */ -ParamInt::ParamInt (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), _value(0), _min(0), _max(10) +/** Use the superclass' allocator and set the \c _value. */ +ParamInt::ParamInt (const gchar * name, + const gchar * guitext, + const gchar * desc, + const Parameter::_scope_t scope, + bool gui_hidden, + const gchar * gui_tip, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml, + AppearanceMode mode) : + Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), + _value(0), _mode(mode), _indent(0), _min(0), _max(10) { const char * defaultval = NULL; - if (sp_repr_children(xml) != NULL) + if (sp_repr_children(xml) != NULL) { defaultval = sp_repr_children(xml)->content(); + } if (defaultval != NULL) { _value = atoi(defaultval); } const char * maxval = xml->attribute("max"); - if (maxval != NULL) + if (maxval != NULL) { _max = atoi(maxval); + } const char * minval = xml->attribute("min"); - if (minval != NULL) + if (minval != NULL) { _min = atoi(minval); - + } /* We're handling this by just killing both values */ if (_max < _min) { _max = 10; _min = 0; } + const char * indent = xml->attribute("indent"); + if (indent != NULL) { + _indent = atoi(indent) * 12; + } + gchar *pref_name = this->pref_name(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); _value = prefs->getInt(extension_pref_root + pref_name, _value); @@ -54,27 +72,33 @@ ParamInt::ParamInt (const gchar * name, const gchar * guitext, const gchar * des // std::cout << "New Int:: value: " << _value << " max: " << _max << " min: " << _min << std::endl; - if (_value > _max) _value = _max; - if (_value < _min) _value = _min; - - return; + if (_value > _max) { + _value = _max; + } + if (_value < _min) { + _value = _min; + } } -/** \brief A function to set the \c _value - \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 - - 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. -*/ -int -ParamInt::set (int in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) +/** + * 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; + if (_value > _max) { + _value = _max; + } + if (_value < _min) { + _value = _min; + } gchar * prefname = this->pref_name(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -84,61 +108,69 @@ ParamInt::set (int in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) return _value; } -/** \brief A class to make an adjustment that uses Extension params */ +/** A class to make an adjustment that uses Extension params. */ class ParamIntAdjustment : public Gtk::Adjustment { - /** The parameter to adjust */ + /** The parameter to adjust. */ ParamInt * _pref; SPDocument * _doc; Inkscape::XML::Node * _node; sigc::signal<void> * _changeSignal; public: - /** \brief Make the adjustment using an extension and the string - describing the parameter. */ + /** Make the adjustment using an extension and the string + describing the parameter. */ ParamIntAdjustment (ParamInt * param, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) : - Gtk::Adjustment(0.0, param->min(), param->max(), 1.0, 0), _pref(param), _doc(doc), _node(node), _changeSignal(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(NULL, NULL) /* \todo fix */); this->signal_value_changed().connect(sigc::mem_fun(this, &ParamIntAdjustment::val_changed)); - return; }; void val_changed (void); }; /* class ParamIntAdjustment */ -/** \brief 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 (void) +/** + * 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(void) { //std::cout << "Value Changed to: " << this->get_value() << std::endl; _pref->set((int)this->get_value(), _doc, _node); if (_changeSignal != NULL) { _changeSignal->emit(); } - return; } /** - \brief Creates a Int Adjustment for a int parameter - - Builds a hbox with a label and a int adjustment in it. -*/ + * 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<void> * changeSignal) { - if (_gui_hidden) return NULL; + if (_gui_hidden) { + return NULL; + } Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT)); label->show(); - hbox->pack_start(*label, true, true); + hbox->pack_start(*label, true, true, _indent); ParamIntAdjustment * fadjust = Gtk::manage(new ParamIntAdjustment(this, doc, node, changeSignal)); - Gtk::SpinButton * spin = Gtk::manage(new Gtk::SpinButton(*fadjust, 1.0, 0)); + + if (_mode == FULL) { + Gtk::HScale * scale = Gtk::manage(new Gtk::HScale(*fadjust)); + scale->set_draw_value(false); + scale->set_size_request(200, -1); + scale->show(); + hbox->pack_start(*scale, false, false); + } + + Inkscape::UI::Widget::SpinButton * spin = Gtk::manage(new Inkscape::UI::Widget::SpinButton(*fadjust, 1.0, 0)); spin->show(); hbox->pack_start(*spin, false, false); @@ -147,18 +179,15 @@ ParamInt::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal return dynamic_cast<Gtk::Widget *>(hbox); } -/** \brief Return the value as a string */ -void -ParamInt::string (std::string &string) +void ParamInt::string(std::string &string) const { char startstring[32]; sprintf(startstring, "%d", _value); string += startstring; - return; } -} /* namespace Extension */ -} /* namespace Inkscape */ +} // namespace Extension +} // namespace Inkscape /* Local Variables: diff --git a/src/extension/param/int.h b/src/extension/param/int.h index a4eb54c81..83fc67be9 100644 --- a/src/extension/param/int.h +++ b/src/extension/param/int.h @@ -5,6 +5,7 @@ * Copyright (C) 2005-2007 Authors: * Ted Gould <ted@gould.cx> * Johan Engelen <johan@shouraizou.nl> * + * Jon A. Cruz <jon@joncruz.org> * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -17,20 +18,43 @@ namespace Inkscape { namespace Extension { class ParamInt : public Parameter { -private: - /** \brief Internal value. */ - int _value; - int _min; - int _max; public: - ParamInt (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); - /** \brief Returns \c _value */ - int get (const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) { return _value; } + enum AppearanceMode { + FULL, MINIMAL + }; + ParamInt (const gchar * name, + const gchar * guitext, + const gchar * desc, + const Parameter::_scope_t scope, + bool gui_hidden, + const gchar * gui_tip, + 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 (void) { return _max; } + int min (void) { return _min; } + Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); - void string (std::string &string); + + // Explicitly call superclass version to avoid method being hidden. + virtual void string(std::list <std::string> &list) const { return Parameter::string(list); } + + virtual void string(std::string &string) const; + +private: + /** Internal value. */ + int _value; + AppearanceMode _mode; + int _indent; + int _min; + int _max; }; } /* namespace Extension */ diff --git a/src/extension/param/notebook.cpp b/src/extension/param/notebook.cpp index e1ab1de6d..80042febc 100644 --- a/src/extension/param/notebook.cpp +++ b/src/extension/param/notebook.cpp @@ -3,8 +3,9 @@ */ /* - * Author: + * Authors: * Johan Engelen <johan@shouraizou.nl> + * Jon A. Cruz <jon@joncruz.org> * * Copyright (C) 2006 Author * @@ -33,15 +34,19 @@ #include "notebook.h" -/** \brief The root directory in the preferences database for extension - related parameters. */ +/** + * The root directory in the preferences database for extension + * related parameters. + */ #define PREF_DIR "extensions" namespace Inkscape { namespace Extension { -// \brief A class to represent the pages of a notebookparameter of an extension +/** + * A class to represent the pages of a notebookparameter of an extension. + */ class ParamNotebookPage : public Parameter { private: GSList * parameters; /**< A table to store the parameters for this page. @@ -62,7 +67,8 @@ public: ParamNotebookPage::ParamNotebookPage (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext) + Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), + _tooltips(NULL) { parameters = NULL; @@ -84,8 +90,6 @@ ParamNotebookPage::ParamNotebookPage (const gchar * name, const gchar * guitext, child_repr = sp_repr_next(child_repr); } } - - return; } ParamNotebookPage::~ParamNotebookPage (void) @@ -99,16 +103,13 @@ ParamNotebookPage::~ParamNotebookPage (void) g_slist_free(parameters); } -/** \brief Return the value as a string */ -void -ParamNotebookPage::paramString (std::list <std::string> &list) +/** Return the value as a string. */ +void ParamNotebookPage::paramString(std::list <std::string> &list) { for (GSList * plist = parameters; plist != NULL; plist = g_slist_next(plist)) { Parameter * param = reinterpret_cast<Parameter *>(plist->data); param->string(list); } - - return; } @@ -119,6 +120,7 @@ ParamNotebookPage::paramString (std::list <std::string> &list) 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 @@ -191,16 +193,19 @@ ParamNotebookPage::makepage (Inkscape::XML::Node * in_repr, Inkscape::Extension: /** - \brief Creates a notebookpage widget for a notebook - - Builds a notebook page (a vbox) and puts parameters on it. -*/ -Gtk::Widget * -ParamNotebookPage::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) + * Creates a notebookpage widget for a notebook. + * + * Builds a notebook page (a vbox) and puts parameters on it. + */ +Gtk::Widget * ParamNotebookPage::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) { - if (_gui_hidden) return NULL; + if (_gui_hidden) { + return NULL; + } - if (!_tooltips) _tooltips = new Gtk::Tooltips(); + if (!_tooltips) { + _tooltips = new Gtk::Tooltips(); + } Gtk::VBox * vbox = Gtk::manage(new Gtk::VBox); vbox->set_border_width(5); @@ -264,8 +269,6 @@ ParamNotebook::ParamNotebook (const gchar * name, const gchar * guitext, const g defaultval = paramval.data(); if (defaultval != NULL) _value = g_strdup(defaultval); // allocate space for _value - - return; } ParamNotebook::~ParamNotebook (void) @@ -281,21 +284,22 @@ ParamNotebook::~ParamNotebook (void) } -/** \brief A function to set the \c _value - \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 - - 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(). -*/ -const gchar * -ParamNotebook::set (const int in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) +/** + * 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*/) { ParamNotebookPage * page = NULL; int i = 0; @@ -317,13 +321,7 @@ ParamNotebook::set (const int in, SPDocument * /*doc*/, Inkscape::XML::Node * /* return _value; } - -/** - \brief 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 -ParamNotebook::string (std::list <std::string> &list) +void ParamNotebook::string(std::list <std::string> &list) const { std::string param_string; param_string += "--"; @@ -339,51 +337,47 @@ ParamNotebook::string (std::list <std::string> &list) ParamNotebookPage * page = reinterpret_cast<ParamNotebookPage *>(pglist->data); page->paramString(list); } - - return; } -/** \brief A special category of Gtk::Notebook to handle notebook parameters */ +/** 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: - /** \brief 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. - */ + /** + * 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)); - return; }; void changed_page(GtkNotebookPage *page, guint pagenum); bool activated; }; -/** \brief 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(GtkNotebookPage */*page*/, - guint pagenum) +/** + * 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(GtkNotebookPage */*page*/, + guint pagenum) { if (is_visible()) { _pref->set((int)pagenum, _doc, _node); } - return; } -/** \brief Search the parameter's name in the notebook content */ -Parameter * -ParamNotebook::get_param(const gchar * name) +/** Search the parameter's name in the notebook content. */ +Parameter *ParamNotebook::get_param(const gchar * name) { if (name == NULL) { throw Extension::param_not_exist(); @@ -399,9 +393,8 @@ ParamNotebook::get_param(const gchar * name) return NULL; } -/** \brief Search the parameter's name in the page content */ -Parameter * -ParamNotebookPage::get_param(const gchar * name) +/** Search the parameter's name in the page content. */ +Parameter *ParamNotebookPage::get_param(const gchar * name) { if (name == NULL) { throw Extension::param_not_exist(); @@ -422,14 +415,15 @@ ParamNotebookPage::get_param(const gchar * name) } /** - \brief 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<void> * changeSignal) + * 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<void> * changeSignal) { - if (_gui_hidden) return NULL; + if (_gui_hidden) { + return NULL; + } ParamNotebookWdg * nb = Gtk::manage(new ParamNotebookWdg(this, doc, node)); @@ -454,8 +448,8 @@ ParamNotebook::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::s } -} /* namespace Extension */ -} /* namespace Inkscape */ +} // namespace Extension +} // namespace Inkscape /* Local Variables: diff --git a/src/extension/param/notebook.h b/src/extension/param/notebook.h index fb21c9b63..23058f465 100644 --- a/src/extension/param/notebook.h +++ b/src/extension/param/notebook.h @@ -8,6 +8,7 @@ /* * Author: * Johan Engelen <johan@shouraizou.nl> + * Jon A. Cruz <jon@joncruz.org> * * Copyright (C) 2006 Author * @@ -17,21 +18,23 @@ #include <gtkmm/widget.h> #include "xml/document.h" -#include <extension/extension-forward.h> #include "parameter.h" namespace Inkscape { namespace Extension { +class Extension; -// \brief A class to represent a notebookparameter of an extension +/** A class to represent a notebookparameter of an extension. */ class ParamNotebook : 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 name of the current page. */ + /** + * 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; GSList * pages; /**< A table to store the pages with parameters for this notebook. @@ -41,7 +44,16 @@ public: ParamNotebook(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); virtual ~ParamNotebook(void); Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); - void string (std::list <std::string> &list); + + /** + * 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. + */ + virtual void string (std::list <std::string> &list) const; + + // Explicitly call superclass version to avoid method being hidden. + virtual void string(std::string &string) const {return Parameter::string(string);} + Parameter * get_param (const gchar * name); @@ -53,8 +65,8 @@ public: -} /* namespace Extension */ -} /* namespace Inkscape */ +} // namespace Extension +} // namespace Inkscape #endif /* INK_EXTENSION_PARAMNOTEBOOK_H_SEEN */ diff --git a/src/extension/param/parameter.cpp b/src/extension/param/parameter.cpp index 529d5a775..063ec32be 100644 --- a/src/extension/param/parameter.cpp +++ b/src/extension/param/parameter.cpp @@ -1,5 +1,5 @@ /** @file - * @brief Parameters for extensions. + * Parameters for extensions. */ /* Author: * Ted Gould <ted@gould.cx> @@ -19,10 +19,6 @@ # define ESCAPE_DOLLAR_COMMANDLINE #endif -#include <gtkmm/adjustment.h> -#include <gtkmm/box.h> -#include <gtkmm/spinbutton.h> - #include <xml/node.h> #include <extension/extension.h> @@ -36,7 +32,6 @@ #include "bool.h" #include "color.h" #include "description.h" -#include "groupheader.h" #include "enum.h" #include "float.h" #include "int.h" @@ -47,76 +42,52 @@ namespace Inkscape { namespace Extension { -/** - \return None - \brief 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) :) - \param in_repr The XML describing the parameter - - 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. -*/ -Parameter * -Parameter::make (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * in_ext) +Parameter *Parameter::make(Inkscape::XML::Node *in_repr, Inkscape::Extension::Extension *in_ext) { - const char * name; - const char * type; - const char * guitext; - const char * desc; - const char * scope_str; - Parameter::_scope_t scope = Parameter::SCOPE_USER; - bool gui_hidden = false; - const char * gui_hide; - const char * gui_tip; - - name = in_repr->attribute("name"); - type = in_repr->attribute("type"); - guitext = in_repr->attribute("gui-text"); - if (guitext == NULL) + const char *name = in_repr->attribute("name"); + const char *type = in_repr->attribute("type"); + + // In this case we just don't have enough information + if (!name || !type) { + return NULL; + } + + const char *guitext = in_repr->attribute("gui-text"); + if (guitext == NULL) { guitext = in_repr->attribute("_gui-text"); - gui_tip = in_repr->attribute("gui-tip"); - if (gui_tip == NULL) + } + const char *gui_tip = in_repr->attribute("gui-tip"); + if (gui_tip == NULL) { gui_tip = in_repr->attribute("_gui-tip"); - desc = in_repr->attribute("gui-description"); - if (desc == NULL) + } + const char *desc = in_repr->attribute("gui-description"); + if (desc == NULL) { desc = in_repr->attribute("_gui-description"); - scope_str = in_repr->attribute("scope"); - gui_hide = in_repr->attribute("gui-hidden"); - if (gui_hide != NULL) { - if (strcmp(gui_hide, "1") == 0 || - strcmp(gui_hide, "true") == 0) { - gui_hidden = true; - } - /* else stays false */ - } - const gchar* appearance = in_repr->attribute("appearance"); - - /* In this case we just don't have enough information */ - if (name == NULL || type == NULL) { - return NULL; } + bool gui_hidden = false; + { + const char *gui_hide = in_repr->attribute("gui-hidden"); + if (gui_hide != NULL) { + if (strcmp(gui_hide, "1") == 0 || + strcmp(gui_hide, "true") == 0) { + gui_hidden = true; + } + /* else stays false */ + } + } + const gchar* appearance = in_repr->attribute("appearance"); - if (scope_str != NULL) { - if (!strcmp(scope_str, "user")) { - scope = Parameter::SCOPE_USER; - } else if (!strcmp(scope_str, "document")) { - scope = Parameter::SCOPE_DOCUMENT; - } else if (!strcmp(scope_str, "node")) { - scope = Parameter::SCOPE_NODE; + Parameter::_scope_t scope = Parameter::SCOPE_USER; + { + const char *scope_str = in_repr->attribute("scope"); + if (scope_str != NULL) { + if (!strcmp(scope_str, "user")) { + scope = Parameter::SCOPE_USER; + } else if (!strcmp(scope_str, "document")) { + scope = Parameter::SCOPE_DOCUMENT; + } else if (!strcmp(scope_str, "node")) { + scope = Parameter::SCOPE_NODE; + } } } @@ -124,20 +95,30 @@ Parameter::make (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * if (!strcmp(type, "boolean")) { param = new ParamBool(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr); } else if (!strcmp(type, "int")) { - param = new ParamInt(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr); + if (appearance && !strcmp(appearance, "full")) { + param = new ParamInt(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr, ParamInt::FULL); + } else { + param = new ParamInt(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr, ParamInt::MINIMAL); + } } else if (!strcmp(type, "float")) { - param = new ParamFloat(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr); + if (appearance && !strcmp(appearance, "full")) { + param = new ParamFloat(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr, ParamFloat::FULL); + } else { + param = new ParamFloat(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr, ParamFloat::MINIMAL); + } } else if (!strcmp(type, "string")) { param = new ParamString(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr); - const gchar * max_length = in_repr->attribute("max_length"); + gchar const * max_length = in_repr->attribute("max_length"); if (max_length != NULL) { - ParamString * ps = dynamic_cast<ParamString *>(param); - ps->setMaxLength(atoi(max_length)); + ParamString * ps = dynamic_cast<ParamString *>(param); + ps->setMaxLength(atoi(max_length)); } } else if (!strcmp(type, "description")) { - param = new ParamDescription(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr); - } else if (!strcmp(type, "groupheader")) { - param = new ParamGroupHeader(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr); + if (appearance && !strcmp(appearance, "header")) { + param = new ParamDescription(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr, ParamDescription::HEADER); + } else { + param = new ParamDescription(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr, ParamDescription::DESC); + } } else if (!strcmp(type, "enum")) { param = new ParamComboBox(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr); } else if (!strcmp(type, "notebook")) { @@ -152,82 +133,74 @@ Parameter::make (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * param = new ParamColor(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr); } - /* Note: param could equal NULL */ + // Note: param could equal NULL return param; } -/** \brief Wrapper to cast to the object and use it's function. */ -bool -Parameter::get_bool (const SPDocument * doc, const Inkscape::XML::Node * node) +bool Parameter::get_bool(SPDocument const *doc, Inkscape::XML::Node const *node) const { - ParamBool * boolpntr = dynamic_cast<ParamBool *>(this); - if (boolpntr == NULL) + ParamBool const *boolpntr = dynamic_cast<ParamBool const *>(this); + if (!boolpntr) { throw Extension::param_not_bool_param(); + } return boolpntr->get(doc, node); } -/** \brief Wrapper to cast to the object and use it's function. */ -int -Parameter::get_int (const SPDocument * doc, const Inkscape::XML::Node * node) +int Parameter::get_int(SPDocument const *doc, Inkscape::XML::Node const *node) const { - ParamInt * intpntr = dynamic_cast<ParamInt *>(this); - if (intpntr == NULL) + ParamInt const *intpntr = dynamic_cast<ParamInt const *>(this); + if (!intpntr) { throw Extension::param_not_int_param(); + } return intpntr->get(doc, node); } -/** \brief Wrapper to cast to the object and use it's function. */ -float -Parameter::get_float (const SPDocument * doc, const Inkscape::XML::Node * node) +float Parameter::get_float(SPDocument const *doc, Inkscape::XML::Node const *node) const { - ParamFloat * floatpntr = dynamic_cast<ParamFloat *>(this); - if (floatpntr == NULL) + ParamFloat const *floatpntr = dynamic_cast<ParamFloat const *>(this); + if (!floatpntr) { throw Extension::param_not_float_param(); + } return floatpntr->get(doc, node); } -/** \brief Wrapper to cast to the object and use it's function. */ -const gchar * -Parameter::get_string (const SPDocument * doc, const Inkscape::XML::Node * node) +gchar const *Parameter::get_string(SPDocument const *doc, Inkscape::XML::Node const *node) const { - ParamString * stringpntr = dynamic_cast<ParamString *>(this); - if (stringpntr == NULL) + ParamString const *stringpntr = dynamic_cast<ParamString const *>(this); + if (!stringpntr) { throw Extension::param_not_string_param(); + } return stringpntr->get(doc, node); } -/** \brief Wrapper to cast to the object and use it's function. */ -const gchar * -Parameter::get_enum (const SPDocument * doc, const Inkscape::XML::Node * node) +gchar const *Parameter::get_enum(SPDocument const *doc, Inkscape::XML::Node const *node) const { - ParamComboBox * param = dynamic_cast<ParamComboBox *>(this); - if (param == NULL) + ParamComboBox const *param = dynamic_cast<ParamComboBox const *>(this); + if (!param) { throw Extension::param_not_enum_param(); + } return param->get(doc, node); } -/** \brief Wrapper to cast to the object and use it's function. */ -gchar const *Parameter::get_optiongroup(SPDocument const * doc, Inkscape::XML::Node const * node) +gchar const *Parameter::get_optiongroup(SPDocument const *doc, Inkscape::XML::Node const * node) const { - ParamRadioButton * param = dynamic_cast<ParamRadioButton *>(this); + ParamRadioButton const *param = dynamic_cast<ParamRadioButton const *>(this); if (!param) { throw Extension::param_not_optiongroup_param(); } return param->get(doc, node); } -guint32 -Parameter::get_color(const SPDocument* doc, const Inkscape::XML::Node* node) +guint32 Parameter::get_color(const SPDocument* doc, Inkscape::XML::Node const *node) const { - ParamColor* param = dynamic_cast<ParamColor *>(this); - if (param == NULL) + ParamColor const *param = dynamic_cast<ParamColor const *>(this); + if (!param) { throw Extension::param_not_color_param(); + } return param->get(doc, node); } -/** \brief Wrapper to cast to the object and use it's function. */ -bool -Parameter::set_bool (bool in, SPDocument * doc, Inkscape::XML::Node * node) +bool Parameter::set_bool(bool in, SPDocument * doc, Inkscape::XML::Node * node) { ParamBool * boolpntr = dynamic_cast<ParamBool *>(this); if (boolpntr == NULL) @@ -235,9 +208,7 @@ Parameter::set_bool (bool in, SPDocument * doc, Inkscape::XML::Node * node) return boolpntr->set(in, doc, node); } -/** \brief Wrapper to cast to the object and use it's function. */ -int -Parameter::set_int (int in, SPDocument * doc, Inkscape::XML::Node * node) +int Parameter::set_int(int in, SPDocument * doc, Inkscape::XML::Node * node) { ParamInt * intpntr = dynamic_cast<ParamInt *>(this); if (intpntr == NULL) @@ -245,7 +216,7 @@ Parameter::set_int (int in, SPDocument * doc, Inkscape::XML::Node * node) return intpntr->set(in, doc, node); } -/** \brief Wrapper to cast to the object and use it's function. */ +/** Wrapper to cast to the object and use it's function. */ float Parameter::set_float (float in, SPDocument * doc, Inkscape::XML::Node * node) { @@ -256,9 +227,9 @@ Parameter::set_float (float in, SPDocument * doc, Inkscape::XML::Node * node) return floatpntr->set(in, doc, node); } -/** \brief Wrapper to cast to the object and use it's function. */ -const gchar * -Parameter::set_string (const gchar * in, SPDocument * doc, Inkscape::XML::Node * 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<ParamString *>(this); if (stringpntr == NULL) @@ -276,7 +247,7 @@ gchar const * Parameter::set_optiongroup( gchar const * in, SPDocument * doc, In } -/** \brief Wrapper to cast to the object and use it's function. */ +/** Wrapper to cast to the object and use it's function. */ guint32 Parameter::set_color (guint32 in, SPDocument * doc, Inkscape::XML::Node * node) { @@ -287,9 +258,15 @@ Parameter::set_color (guint32 in, SPDocument * doc, Inkscape::XML::Node * node) } -/** \brief Oop, now that we need a parameter, we need it's name. */ -Parameter::Parameter (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext) : - extension(ext), _name(NULL), _desc(NULL), _scope(scope), _text(NULL), _gui_hidden(gui_hidden), _gui_tip(NULL) +/** Oop, now that we need a parameter, we need it's name. */ +Parameter::Parameter(gchar const * name, gchar const * guitext, gchar const * desc, const Parameter::_scope_t scope, bool gui_hidden, gchar const * gui_tip, Inkscape::Extension::Extension * ext) : + _desc(0), + _scope(scope), + _text(0), + _gui_hidden(gui_hidden), + _gui_tip(0), + extension(ext), + _name(0) { if (name != NULL) { _name = g_strdup(name); @@ -302,28 +279,53 @@ Parameter::Parameter (const gchar * name, const gchar * guitext, const gchar * d _gui_tip = g_strdup(gui_tip); } + if (guitext != NULL) { + _text = g_strdup(guitext); + } else { + _text = g_strdup(name); + } - if (guitext != NULL) + return; +} + +/** Oop, now that we need a parameter, we need it's name. */ +Parameter::Parameter (gchar const * name, gchar const * guitext, Inkscape::Extension::Extension * ext) : + _desc(0), + _scope(Parameter::SCOPE_USER), + _text(0), + _gui_hidden(false), + _gui_tip(0), + extension(ext), + _name(0) +{ + if (name != NULL) { + _name = g_strdup(name); + } + if (guitext != NULL) { _text = g_strdup(guitext); - else + } else { _text = g_strdup(name); + } return; } -/** \brief Just free the allocated name. */ -Parameter::~Parameter (void) +Parameter::~Parameter(void) { g_free(_name); + _name = 0; + g_free(_text); - g_free(_gui_tip); + _text = 0; + + g_free(_gui_tip); + _gui_tip = 0; + g_free(_desc); + _desc = 0; } -/** \brief Build the name to write the parameter from the extension's - ID and the name of this parameter. */ -gchar * -Parameter::pref_name (void) +gchar *Parameter::pref_name(void) const { return g_strdup_printf("%s.%s", extension->get_id(), _name); } @@ -349,7 +351,7 @@ Parameter::new_child (Inkscape::XML::Node * parent) Inkscape::XML::Node *Parameter::document_param_node(SPDocument * doc) { Inkscape::XML::Document *xml_doc = doc->getReprDoc(); - Inkscape::XML::Node * defs = SP_DOCUMENT_DEFS(doc)->getRepr(); + Inkscape::XML::Node * defs = doc->getDefs()->getRepr(); Inkscape::XML::Node * params = NULL; GQuark const name_quark = g_quark_from_string("inkscape:extension-params"); @@ -374,50 +376,43 @@ Inkscape::XML::Node *Parameter::document_param_node(SPDocument * doc) return params; } -/** \brief Basically, if there is no widget pass a NULL. */ +/** Basically, if there is no widget pass a NULL. */ Gtk::Widget * Parameter::get_widget (SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal<void> * /*changeSignal*/) { return NULL; } -/** \brief If I'm not sure which it is, just don't return a value. */ -void -Parameter::string (std::string &/*string*/) +/** If I'm not sure which it is, just don't return a value. */ +void Parameter::string(std::string &/*string*/) const { - return; + // TODO investigate clearing the target string. } -void -Parameter::string (std::list <std::string> &list) +void Parameter::string(std::list <std::string> &list) const { std::string value; string(value); - if (value == "") { - return; + if (!value.empty()) { + std::string final; + final += "--"; + final += name(); + final += "="; + final += value; + + list.insert(list.end(), final); } - - std::string final; - final += "--"; - final += name(); - final += "="; - final += value; - - list.insert(list.end(), final); - return; } -/** \brief All the code in Notebook::get_param to get the notebook content */ -Parameter * -Parameter::get_param(const gchar * name) +Parameter *Parameter::get_param(gchar const * /*name*/) { return NULL; } Glib::ustring const extension_pref_root = "/extensions/"; -} /* namespace Extension */ -} /* namespace Inkscape */ +} // namespace Extension +} // namespace Inkscape /* Local Variables: diff --git a/src/extension/param/parameter.h b/src/extension/param/parameter.h index d8ed68439..8d80e6c40 100644 --- a/src/extension/param/parameter.h +++ b/src/extension/param/parameter.h @@ -1,8 +1,9 @@ /** @file - * @brief Parameters for extensions. + * Parameters for extensions. */ /* Authors: * Ted Gould <ted@gould.cx> + * Jon A. Cruz <jon@joncruz.org> * * Copyright (C) 2005-2006 Authors * @@ -18,117 +19,178 @@ #include "xml/document.h" #include "xml/node.h" #include "document.h" -#include "extension/extension-forward.h" #include <color.h> namespace Inkscape { namespace Extension { +class Extension; + + /** - * @brief The root directory in the preferences database for extension-related parameters + * 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; -/** \brief 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. -*/ +/** + * 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 { -private: - /** \brief Which extension is this parameter attached to? */ - Inkscape::Extension::Extension * extension; - /** \brief The name of this parameter. */ - gchar * _name; protected: - /** \brief Description of the parameter. */ - gchar * _desc; - /** \brief List of possible scopes. */ + /** List of possible scopes. */ typedef enum { SCOPE_USER, /**< Parameter value is saved in the user's configuration file. (default) */ SCOPE_DOCUMENT, /**< Parameter value is saved in the document. */ SCOPE_NODE /**< Parameter value is attached to the node. */ } _scope_t; - /** \brief Scope of the parameter. */ + +public: + Parameter(gchar const *name, + gchar const *guitext, + gchar const *desc, + const Parameter::_scope_t scope, + bool gui_hidden, + gchar const *gui_tip, + Inkscape::Extension::Extension * ext); + + Parameter(gchar const *name, + gchar const *guitext, + Inkscape::Extension::Extension * ext); + + virtual ~Parameter(void); + + /** 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. */ + 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_string(gchar const * in, SPDocument * doc, Inkscape::XML::Node * node); + + guint32 set_color(guint32 in, SPDocument * doc, Inkscape::XML::Node * node); + + gchar const * name(void) 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<void> * changeSignal); + + gchar const * get_tooltip(void) const { return _desc; } + + /** Indicates if the GUI for this parameter is hidden or not */ + bool get_gui_hidden() const { return _gui_hidden; } + + virtual void string(std::list <std::string> &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); + +protected: + /** Description of the parameter. */ + gchar * _desc; + + /** Scope of the parameter. */ _scope_t _scope; - /** \brief Text for the GUI selection of this. */ + + /** Text for the GUI selection of this. */ gchar * _text; - /** \brief Whether the GUI is visible */ + + /** Whether the GUI is visible. */ bool _gui_hidden; - /** \brief A tip for the GUI if there is one */ + + /** A tip for the GUI if there is one. */ gchar * _gui_tip; /* **** funcs **** */ - gchar * pref_name (void); + + /** + * Build the name to write the parameter from the extension's ID and the name of this parameter. + */ + gchar *pref_name(void) 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); -public: - Parameter (const gchar * name, - const gchar * guitext, - const gchar * desc, - const Parameter::_scope_t scope, - bool gui_hidden, - const gchar * gui_tip, - Inkscape::Extension::Extension * ext); - Parameter (const gchar * name, - const gchar * guitext, - Inkscape::Extension::Extension * ext) { - Parameter(name, guitext, NULL, Parameter::SCOPE_USER, false, NULL, ext); - }; - virtual ~Parameter (void); - - bool get_bool (const SPDocument * doc, - const Inkscape::XML::Node * node); - int get_int (const SPDocument * doc, - const Inkscape::XML::Node * node); - float get_float (const SPDocument * doc, - const Inkscape::XML::Node * node); - const gchar * get_string (const SPDocument * doc, - const Inkscape::XML::Node * node); - guint32 get_color (const SPDocument * doc, - const Inkscape::XML::Node * node); - const gchar * get_enum (const SPDocument * doc, - const Inkscape::XML::Node * node); - - gchar const * get_optiongroup( SPDocument const * doc, - Inkscape::XML::Node const * node); - - bool set_bool (bool in, SPDocument * doc, Inkscape::XML::Node * node); - 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); - const gchar * set_string (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node); - guint32 set_color (guint32 in, SPDocument * doc, Inkscape::XML::Node * node); - - const gchar * name (void) {return _name;} - - 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<void> * changeSignal); - - gchar const * get_tooltip (void) { return _desc; } - - /** \brief Indicates if the GUI for this parameter is hidden or not */ - bool get_gui_hidden () { return _gui_hidden; } - - virtual void string (std::list <std::string> &list); - virtual void string (std::string &string); - - virtual Parameter * get_param (const gchar * name); +private: + /** Which extension is this parameter attached to. */ + Inkscape::Extension::Extension *extension; + + /** The name of this parameter. */ + gchar *_name; }; -} /* namespace Extension */ -} /* namespace Inkscape */ +} // namespace Extension +} // namespace Inkscape -#endif /* __INK_EXTENSION_PARAM_H__ */ +#endif // SEEN_INK_EXTENSION_PARAM_H__ /* Local Variables: diff --git a/src/extension/param/radiobutton.cpp b/src/extension/param/radiobutton.cpp index 23655baea..a9fcbfd6c 100644 --- a/src/extension/param/radiobutton.cpp +++ b/src/extension/param/radiobutton.cpp @@ -35,8 +35,10 @@ #include "radiobutton.h" -/** \brief The root directory in the preferences database for extension - related parameters. */ +/** + * The root directory in the preferences database for extension + * related parameters. + */ #define PREF_DIR "extensions" namespace Inkscape { @@ -69,9 +71,7 @@ ParamRadioButton::ParamRadioButton (const gchar * name, Inkscape::XML::Node * xml, AppearanceMode mode) : Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), - _value(0), - _mode(mode), - choices(0) + _value(0), _mode(mode), _indent(0), choices(0) { // Read XML tree to add enumeration items: // printf("Extension Constructor: "); @@ -95,16 +95,17 @@ ParamRadioButton::ParamRadioButton (const gchar * name, } else { newguitext = new Glib::ustring(contents); } - } else + } else { continue; - + } const char * val = child_repr->attribute("value"); - if (val != NULL) + if (val != NULL) { newvalue = new Glib::ustring(val); - else + } else { newvalue = new Glib::ustring(contents); + } if ( (newguitext) && (newvalue) ) { // logical error if this is not true here choices = g_slist_append( choices, new optionentry(newvalue, newguitext) ); @@ -117,20 +118,26 @@ ParamRadioButton::ParamRadioButton (const gchar * name, // Initialize _value with the default value from xml // for simplicity : default to the contents of the first xml-child const char * defaultval = NULL; - if (choices) + if (choices) { defaultval = ((optionentry*) choices->data)->value->c_str(); + } + + const char * indent = xml->attribute("indent"); + if (indent != NULL) { + _indent = atoi(indent) * 12; + } 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()) + if (!paramval.empty()) { defaultval = paramval.data(); - if (defaultval != NULL) + } + if (defaultval != NULL) { _value = g_strdup(defaultval); // allocate space for _value - - return; + } } ParamRadioButton::~ParamRadioButton (void) @@ -145,23 +152,26 @@ ParamRadioButton::~ParamRadioButton (void) } -/** \brief A function to set the \c _value - \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 - - 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(). -*/ -const gchar * -ParamRadioButton::set (const gchar * in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) +/** + * 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 == NULL) return NULL; /* Can't have NULL string */ + if (in == NULL) { + return NULL; /* Can't have NULL string */ + } Glib::ustring * settext = NULL; for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { @@ -172,7 +182,9 @@ ParamRadioButton::set (const gchar * in, SPDocument * /*doc*/, Inkscape::XML::No } } if (settext) { - if (_value != NULL) g_free(_value); + if (_value != NULL) { + g_free(_value); + } _value = g_strdup(settext->c_str()); gchar * prefname = this->pref_name(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -183,19 +195,12 @@ ParamRadioButton::set (const gchar * in, SPDocument * /*doc*/, Inkscape::XML::No return _value; } - -/** - \brief A function to get the current value of the parameter in a string form - \return A string with the 'value' as command line argument -*/ -void -ParamRadioButton::string (std::string &string) +void ParamRadioButton::string(std::string &string) const { string += _value; - return; } -/** \brief A special radiobutton class to use in ParamRadioButton */ +/** A special radiobutton class to use in ParamRadioButton. */ class ParamRadioButtonWdg : public Gtk::RadioButton { private: ParamRadioButton * _pref; @@ -203,9 +208,10 @@ private: Inkscape::XML::Node * _node; sigc::signal<void> * _changeSignal; public: - /** \brief Build a string preference for the given parameter - \param pref Where to put the radiobutton's string when it is selected. - */ + /** + * 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<void> * changeSignal ) : Gtk::RadioButton(group, label), _pref(pref), _doc(doc), _node(node), _changeSignal(changeSignal) { @@ -222,13 +228,13 @@ public: void changed (void); }; -/** \brief 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 (void) +/** + * 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(void) { if (this->get_active()) { Glib::ustring data = this->get_label(); @@ -264,19 +270,20 @@ protected: }; /** - \brief Creates a combobox widget for an enumeration parameter -*/ -Gtk::Widget * -ParamRadioButton::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) + * Creates a combobox widget for an enumeration parameter. + */ +Gtk::Widget * ParamRadioButton::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) { - if (_gui_hidden) return NULL; + if (_gui_hidden) { + return NULL; + } Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); Gtk::VBox * vbox = Gtk::manage(new Gtk::VBox(false, 0)); Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT, Gtk::ALIGN_TOP)); label->show(); - hbox->pack_start(*label, false, false); + hbox->pack_start(*label, false, false, _indent); Gtk::ComboBoxText* cbt = 0; bool comboSet = false; diff --git a/src/extension/param/radiobutton.h b/src/extension/param/radiobutton.h index ea8440de2..957a5b9df 100644 --- a/src/extension/param/radiobutton.h +++ b/src/extension/param/radiobutton.h @@ -6,8 +6,9 @@ */ /* - * Author: + * Authors: * Johan Engelen <johan@shouraizou.nl> + * Jon A. Cruz <jon@joncruz.org> * * Copyright (C) 2006-2007 Johan Engelen * @@ -17,13 +18,13 @@ #include <gtkmm/widget.h> #include "xml/document.h" -#include <extension/extension-forward.h> #include "parameter.h" namespace Inkscape { namespace Extension { +class Extension; // \brief A class to represent a radiobutton parameter of an extension @@ -44,10 +45,15 @@ public: AppearanceMode mode); virtual ~ParamRadioButton(void); Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); - void string (std::string &string); - const gchar * get (const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) { return _value; } - const gchar * set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node); + // Explicitly call superclass version to avoid method being hidden. + virtual void string(std::list <std::string> &list) const { return Parameter::string(list); } + + virtual void string(std::string &string) const; + + 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 @@ -55,7 +61,7 @@ private: It is the value of the current selected string */ gchar * _value; AppearanceMode _mode; - + int _indent; GSList * choices; /**< A table to store the choice strings */ }; /* class ParamRadioButton */ @@ -69,3 +75,13 @@ private: #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 index e32224332..13b8e326a 100644 --- a/src/extension/param/string.cpp +++ b/src/extension/param/string.cpp @@ -2,6 +2,7 @@ * Copyright (C) 2005-2007 Authors: * Ted Gould <ted@gould.cx> * Johan Engelen <johan@shouraizou.nl> * + * Jon A. Cruz <jon@joncruz.org> * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -22,32 +23,38 @@ namespace Inkscape { namespace Extension { -/** \brief Free the allocated data. */ +/** Free the allocated data. */ ParamString::~ParamString(void) { g_free(_value); + _value = 0; } -/** \brief A function to set the \c _value - \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 - - 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(). -*/ -const gchar * -ParamString::set (const gchar * in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) +/** + * 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 == NULL) return NULL; /* Can't have NULL string */ + if (in == NULL) { + return NULL; /* Can't have NULL string */ + } - if (_value != NULL) + if (_value != NULL) { g_free(_value); + } + _value = g_strdup(in); gchar * prefname = this->pref_name(); @@ -58,41 +65,44 @@ ParamString::set (const gchar * in, SPDocument * /*doc*/, Inkscape::XML::Node * return _value; } -/** \brief Return the value as a string */ -void -ParamString::string (std::string &string) +void ParamString::string(std::string &string) const { - if (_value == NULL) - return; - - string += _value; - return; + if (_value) { + string += _value; + } } -/** \brief Initialize the object, to do that, copy the data. */ +/** Initialize the object, to do that, copy the data. */ ParamString::ParamString (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), _value(NULL) + Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), + _value(NULL), _indent(0) { const char * defaultval = NULL; - if (sp_repr_children(xml) != NULL) + if (sp_repr_children(xml) != NULL) { defaultval = sp_repr_children(xml)->content(); + } + + const char * indent = xml->attribute("indent"); + if (indent != NULL) { + _indent = atoi(indent) * 12; + } 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()) + if (!paramval.empty()) { defaultval = paramval.data(); - if (defaultval != NULL) + } + if (defaultval != NULL) { _value = g_strdup(defaultval); - - _max_length = 0; + } - return; + _max_length = 0; } -/** \brief A special type of Gtk::Entry to handle string parameteres */ +/** A special type of Gtk::Entry to handle string parameteres. */ class ParamStringEntry : public Gtk::Entry { private: ParamString * _pref; @@ -100,14 +110,16 @@ private: Inkscape::XML::Node * _node; sigc::signal<void> * _changeSignal; public: - /** \brief Build a string preference for the given parameter - \param pref Where to get the string from, and where to put it - when it changes. - */ + /** + * 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<void> * changeSignal) : Gtk::Entry(), _pref(pref), _doc(doc), _node(node), _changeSignal(changeSignal) { - if (_pref->get(NULL, NULL) != NULL) + if (_pref->get(NULL, NULL) != NULL) { this->set_text(Glib::ustring(_pref->get(NULL, NULL))); + } this->set_max_length(_pref->getMaxLength()); //Set the max lenght - default zero means no maximum this->signal_changed().connect(sigc::mem_fun(this, &ParamStringEntry::changed_text)); }; @@ -115,37 +127,37 @@ public: }; -/** \brief 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 (void) +/** + * 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(void) { Glib::ustring data = this->get_text(); _pref->set(data.c_str(), _doc, _node); if (_changeSignal != NULL) { _changeSignal->emit(); } - return; } /** - \brief 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<void> * changeSignal) + * 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<void> * changeSignal) { - if (_gui_hidden) return NULL; + if (_gui_hidden) { + return NULL; + } Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT)); label->show(); - hbox->pack_start(*label, false, false); + hbox->pack_start(*label, false, false, _indent); ParamStringEntry * textbox = new ParamStringEntry(this, doc, node, changeSignal); textbox->show(); diff --git a/src/extension/param/string.h b/src/extension/param/string.h index 10f45e5ac..8e7f093f7 100644 --- a/src/extension/param/string.h +++ b/src/extension/param/string.h @@ -5,6 +5,7 @@ * Copyright (C) 2005-2007 Authors: * Ted Gould <ted@gould.cx> * Johan Engelen <johan@shouraizou.nl> * + * Jon A. Cruz <jon@joncruz.org> * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -23,22 +24,31 @@ private: gchar * _value; /** \brief Internal value. This indicates the maximum leght of the string. Zero meaning unlimited. */ + int _indent; gint _max_length; public: ParamString(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); virtual ~ParamString(void); + /** \brief Returns \c _value, with a \i const to protect it. */ - const gchar * get (const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) { return _value; } + 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<void> * changeSignal); - void string (std::string &string); + + // Explicitly call superclass version to avoid method being hidden. + virtual void string(std::list <std::string> &list) const { return Parameter::string(list); } + + virtual void string(std::string &string) const; + void setMaxLength(int maxLenght) { _max_length = maxLenght; } int getMaxLength(void) { return _max_length; } }; -} /* namespace Extension */ -} /* namespace Inkscape */ +} // namespace Extension +} // namespace Inkscape #endif /* INK_EXTENSION_PARAMSTRING_H_SEEN */ |
