From b29eafffd0b92cc7b67e5cd877aad5e98b0f0231 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 10 Aug 2007 17:38:51 +0000 Subject: r16217@tres: ted | 2007-08-10 10:36:27 -0700 ImageMagick effects patch from Chris Brown. Google Summer of Code project. (bzr r3450) --- src/extension/parameter.cpp | 708 ++++---------------------------------------- 1 file changed, 54 insertions(+), 654 deletions(-) (limited to 'src/extension/parameter.cpp') diff --git a/src/extension/parameter.cpp b/src/extension/parameter.cpp index f59a5cc3d..52c67267f 100644 --- a/src/extension/parameter.cpp +++ b/src/extension/parameter.cpp @@ -24,195 +24,29 @@ #include #include -#include - #include #include "extension.h" -#include "prefs-utils.h" #include "document-private.h" #include "sp-object.h" +#include "color.h" +#include "widgets/sp-color-selector.h" +#include "widgets/sp-color-notebook.h" #include "parameter.h" -#include "paramnotebook.h" +#include "parambool.h" +#include "paramcolor.h" +#include "paramdescription.h" #include "paramenum.h" +#include "paramfloat.h" +#include "paramint.h" +#include "paramnotebook.h" #include "paramradiobutton.h" - -/** \brief The root directory in the preferences database for extension - related parameters. */ -#define PREF_DIR "extensions" +#include "paramstring.h" namespace Inkscape { namespace Extension { -/** \brief A description parameter */ -class ParamDescription : public Parameter { -private: - /** \brief Internal value. */ - gchar * _value; -public: - ParamDescription(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); - Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal); -}; - -/** \brief A boolean parameter */ -class ParamBool : public Parameter { -private: - /** \brief Internal value. */ - bool _value; -public: - ParamBool(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); - /** \brief Returns \c _value */ - bool get (const SPDocument * doc, const Inkscape::XML::Node * node) { return _value; } - bool set (bool in, SPDocument * doc, Inkscape::XML::Node * node); - Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal); - Glib::ustring * string (void); -}; - -/** \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, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, ext), _value(false) -{ - const char * defaultval = 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; - } else { - _value = false; - } - - gchar * pref_name = this->pref_name(); - _value = (bool)prefs_get_int_attribute(PREF_DIR, pref_name, _value); - g_free(pref_name); - - return; -} - -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, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); - /** \brief Returns \c _value */ - int get (const SPDocument * doc, const Inkscape::XML::Node * node) { 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 * changeSignal); - Glib::ustring * string (void); -}; - -/** \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, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, ext), _value(0), _min(0), _max(10) -{ - const char * defaultval = 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) - _max = atoi(maxval); - - const char * minval = xml->attribute("min"); - if (minval != NULL) - _min = atoi(minval); - - /* We're handling this by just killing both values */ - if (_max < _min) { - _max = 10; - _min = 0; - } - - gchar * pref_name = this->pref_name(); - _value = prefs_get_int_attribute(PREF_DIR, pref_name, _value); - g_free(pref_name); - - // std::cout << "New Int:: value: " << _value << " max: " << _max << " min: " << _min << std::endl; - - if (_value > _max) _value = _max; - if (_value < _min) _value = _min; - - return; -} - -class ParamFloat : public Parameter { -private: - /** \brief Internal value. */ - float _value; - float _min; - float _max; -public: - ParamFloat (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); - /** \brief Returns \c _value */ - float get (const SPDocument * doc, const Inkscape::XML::Node * node) { return _value; } - float set (float in, SPDocument * doc, Inkscape::XML::Node * node); - float max (void) { return _max; } - float min (void) { return _min; } - Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal); - Glib::ustring * string (void); -}; - -/** \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, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, ext), _value(0.0), _min(0.0), _max(10.0) -{ - const char * defaultval = NULL; - if (sp_repr_children(xml) != NULL) - defaultval = sp_repr_children(xml)->content(); - if (defaultval != NULL) { - _value = atof(defaultval); - } - - const char * maxval = xml->attribute("max"); - if (maxval != NULL) - _max = atof(maxval); - - const char * minval = xml->attribute("min"); - if (minval != NULL) - _min = atof(minval); - - /* We're handling this by just killing both values */ - if (_max < _min) { - _max = 10.0; - _min = 0.0; - } - - gchar * pref_name = this->pref_name(); - _value = prefs_get_double_attribute(PREF_DIR, pref_name, _value); - g_free(pref_name); - - // std::cout << "New Float:: value: " << _value << " max: " << _max << " min: " << _min << std::endl; - - if (_value > _max) _value = _max; - if (_value < _min) _value = _min; - - return; -} - -class ParamString : public Parameter { -private: - /** \brief Internal value. This should point to a string that has - been allocated in memory. And should be free'd. */ - gchar * _value; -public: - ParamString(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); - ~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 * set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node); - Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal); - Glib::ustring * string (void); -}; - class ParamEnum : public Parameter { private: class Choice { @@ -245,8 +79,7 @@ public: Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal); Glib::ustring * string (void); }; /* class ParamEnum */ - - + /** \return None \brief This function creates a parameter that can be used later. This @@ -322,116 +155,23 @@ Parameter::make (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * param = new ParamNotebook(name, guitext, desc, scope, in_ext, in_repr); } else if (!strcmp(type, "optiongroup")) { param = new ParamRadioButton(name, guitext, desc, scope, in_ext, in_repr); + } else if (!strcmp(type, "color")) { + param = new ParamColor(name, guitext, desc, scope, in_ext, in_repr); } /* Note: param could equal NULL */ return param; } -/** \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) -{ - _value = in; - - gchar * prefname = this->pref_name(); - prefs_set_int_attribute(PREF_DIR, prefname, _value == true ? 1 : 0); - g_free(prefname); - - return _value; -} - -/** \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) -{ - _value = in; - if (_value > _max) _value = _max; - if (_value < _min) _value = _min; - - gchar * prefname = this->pref_name(); - prefs_set_int_attribute(PREF_DIR, prefname, _value); - g_free(prefname); - - return _value; -} - -/** \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) -{ - _value = in; - if (_value > _max) _value = _max; - if (_value < _min) _value = _min; - - gchar * prefname = this->pref_name(); - prefs_set_double_attribute(PREF_DIR, prefname, _value); - g_free(prefname); - - return _value; -} - -/** \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) -{ - if (in == NULL) return NULL; /* Can't have NULL string */ - if (_value != NULL) - g_free(_value); - _value = g_strdup(in); - - gchar * prefname = this->pref_name(); - prefs_set_string_attribute(PREF_DIR, prefname, _value); - g_free(prefname); - - return _value; -} /** \brief Wrapper to cast to the object and use it's function. */ bool Parameter::get_bool (const SPDocument * doc, const Inkscape::XML::Node * node) { - ParamBool * boolpntr; - boolpntr = dynamic_cast(this); + ParamBool * boolpntr = dynamic_cast(this); if (boolpntr == NULL) - throw Extension::param_wrong_type(); + throw Extension::param_not_bool_param(); return boolpntr->get(doc, node); } @@ -439,10 +179,9 @@ Parameter::get_bool (const SPDocument * doc, const Inkscape::XML::Node * node) int Parameter::get_int (const SPDocument * doc, const Inkscape::XML::Node * node) { - ParamInt * intpntr; - intpntr = dynamic_cast(this); + ParamInt * intpntr = dynamic_cast(this); if (intpntr == NULL) - throw Extension::param_wrong_type(); + throw Extension::param_not_int_param(); return intpntr->get(doc, node); } @@ -450,10 +189,9 @@ Parameter::get_int (const SPDocument * doc, const Inkscape::XML::Node * node) float Parameter::get_float (const SPDocument * doc, const Inkscape::XML::Node * node) { - ParamFloat * floatpntr; - floatpntr = dynamic_cast(this); + ParamFloat * floatpntr = dynamic_cast(this); if (floatpntr == NULL) - throw Extension::param_wrong_type(); + throw Extension::param_not_float_param(); return floatpntr->get(doc, node); } @@ -461,21 +199,38 @@ Parameter::get_float (const SPDocument * doc, const Inkscape::XML::Node * node) const gchar * Parameter::get_string (const SPDocument * doc, const Inkscape::XML::Node * node) { - ParamString * stringpntr; - stringpntr = dynamic_cast(this); + ParamString * stringpntr = dynamic_cast(this); if (stringpntr == NULL) - throw Extension::param_wrong_type(); + 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) +{ + ParamComboBox * param = dynamic_cast(this); + if (param == NULL) + throw Extension::param_not_enum_param(); + return param->get(doc, node); +} + +SPColor* +Parameter::get_color(const SPDocument* doc, const Inkscape::XML::Node* node) +{ + ParamColor* param = dynamic_cast(this); + if (param == NULL) + 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) { - ParamBool * boolpntr; - boolpntr = dynamic_cast(this); + ParamBool * boolpntr = dynamic_cast(this); if (boolpntr == NULL) - throw Extension::param_wrong_type(); + throw Extension::param_not_bool_param(); return boolpntr->set(in, doc, node); } @@ -483,10 +238,9 @@ Parameter::set_bool (bool in, SPDocument * doc, Inkscape::XML::Node * node) int Parameter::set_int (int in, SPDocument * doc, Inkscape::XML::Node * node) { - ParamInt * intpntr; - intpntr = dynamic_cast(this); + ParamInt * intpntr = dynamic_cast(this); if (intpntr == NULL) - throw Extension::param_wrong_type(); + throw Extension::param_not_int_param(); return intpntr->set(in, doc, node); } @@ -497,7 +251,7 @@ Parameter::set_float (float in, SPDocument * doc, Inkscape::XML::Node * node) ParamFloat * floatpntr; floatpntr = dynamic_cast(this); if (floatpntr == NULL) - throw Extension::param_wrong_type(); + throw Extension::param_not_float_param(); return floatpntr->set(in, doc, node); } @@ -505,38 +259,21 @@ Parameter::set_float (float in, SPDocument * doc, Inkscape::XML::Node * node) const gchar * Parameter::set_string (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node) { - ParamString * stringpntr; - stringpntr = dynamic_cast(this); + ParamString * stringpntr = dynamic_cast(this); if (stringpntr == NULL) - throw Extension::param_wrong_type(); + throw Extension::param_not_string_param(); return stringpntr->set(in, doc, node); } - -/** \brief 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, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, ext), _value(NULL) +/** \brief Wrapper to cast to the object and use it's function. */ +SPColor* +Parameter::set_color (SPColor* in, SPDocument * doc, Inkscape::XML::Node * node) { - const char * defaultval = NULL; - if (sp_repr_children(xml) != NULL) - defaultval = sp_repr_children(xml)->content(); - - gchar * pref_name = this->pref_name(); - const gchar * paramval = prefs_get_string_attribute(PREF_DIR, pref_name); - g_free(pref_name); - - if (paramval != NULL) - defaultval = paramval; - if (defaultval != NULL) - _value = g_strdup(defaultval); - - return; + ParamColor* param = dynamic_cast(this); + if (param == NULL) + throw Extension::param_not_color_param(); + return param->set(in, doc, node); } -/** \brief Free the allocated data. */ -ParamString::~ParamString(void) -{ - g_free(_value); -} /** \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, Inkscape::Extension::Extension * ext) : @@ -633,346 +370,9 @@ Parameter::string (void) return mystring; } -/** \brief A class to make an adjustment that uses Extension params */ -class ParamFloatAdjustment : public Gtk::Adjustment { - /** The parameter to adjust */ - ParamFloat * _pref; - SPDocument * _doc; - Inkscape::XML::Node * _node; - sigc::signal * _changeSignal; -public: - /** \brief Make the adjustment using an extension and the string - describing the parameter. */ - ParamFloatAdjustment (ParamFloat * param, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) : - Gtk::Adjustment(0.0, param->min(), param->max(), 0.1), _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; - }; - - 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) -{ - //std::cout << "Value Changed to: " << this->get_value() << std::endl; - _pref->set(this->get_value(), _doc, _node); - if (_changeSignal != NULL) { - _changeSignal->emit(); - } - return; -} - -/** \brief A class to make an adjustment that uses Extension params */ -class ParamIntAdjustment : public Gtk::Adjustment { - /** The parameter to adjust */ - ParamInt * _pref; - SPDocument * _doc; - Inkscape::XML::Node * _node; - sigc::signal * _changeSignal; -public: - /** \brief Make the adjustment using an extension and the string - describing the parameter. */ - ParamIntAdjustment (ParamInt * param, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) : - Gtk::Adjustment(0.0, param->min(), param->max(), 1.0), _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) -{ - //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 Float Adjustment for a float parameter - - Builds a hbox with a label and a float adjustment in it. -*/ -Gtk::Widget * -ParamFloat::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) -{ - 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); - - ParamFloatAdjustment * fadjust = Gtk::manage(new ParamFloatAdjustment(this, doc, node, changeSignal)); - Gtk::SpinButton * spin = Gtk::manage(new Gtk::SpinButton(*fadjust, 0.1, 1)); - spin->show(); - hbox->pack_start(*spin, false, false); - - hbox->show(); - - return dynamic_cast(hbox); -} - -/** - \brief Creates a Int Adjustment for a int parameter - - Builds a hbox with a label and a int adjustment in it. -*/ -Gtk::Widget * -ParamInt::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) -{ - 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); - ParamIntAdjustment * fadjust = Gtk::manage(new ParamIntAdjustment(this, doc, node, changeSignal)); - Gtk::SpinButton * spin = Gtk::manage(new Gtk::SpinButton(*fadjust, 1.0, 0)); - spin->show(); - hbox->pack_start(*spin, false, false); - hbox->show(); - - return dynamic_cast(hbox); -} - -/** \brief 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 * _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. - */ - ParamBoolCheckButton (ParamBool * param, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * 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; - } - void on_toggle (void); -}; - -/** - \brief A function to respond to the check box changing - - Adjusts the value of the preference to match that in the check box. -*/ -void -ParamBoolCheckButton::on_toggle (void) -{ - _pref->set(this->get_active(), NULL /**\todo fix this */, NULL); - if (_changeSignal != NULL) { - _changeSignal->emit(); - } - 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 * changeSignal) -{ - 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); - - ParamBoolCheckButton * checkbox = new ParamBoolCheckButton(this, doc, node, changeSignal); - checkbox->show(); - hbox->pack_start(*checkbox, false, false); - - hbox->show(); - - return dynamic_cast(hbox); -} - -/** \brief A special category of Gtk::Entry to handle string parameteres */ -class ParamStringEntry : public Gtk::Entry { -private: - ParamString * _pref; - SPDocument * _doc; - Inkscape::XML::Node * _node; - sigc::signal * _changeSignal; -public: - /** \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. - */ - ParamStringEntry (ParamString * pref, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) : - Gtk::Entry(), _pref(pref), _doc(doc), _node(node), _changeSignal(changeSignal) { - if (_pref->get(NULL, NULL) != NULL) - this->set_text(Glib::ustring(_pref->get(NULL, NULL))); - this->signal_changed().connect(sigc::mem_fun(this, &ParamStringEntry::changed_text)); - }; - void changed_text (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. -*/ -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 * changeSignal) -{ - 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); - - ParamStringEntry * textbox = new ParamStringEntry(this, doc, node, changeSignal); - textbox->show(); - hbox->pack_start(*textbox, true, true); - - hbox->show(); - - return dynamic_cast(hbox); -} - -/** \brief Return 'true' or 'false' */ -Glib::ustring * -ParamBool::string (void) -{ - Glib::ustring * mystring; - - if (_value) - mystring = new Glib::ustring("true"); - else - mystring = new Glib::ustring("false"); - - return mystring; -} - -/** \brief Return the value as a string */ -Glib::ustring * -ParamInt::string (void) -{ - char startstring[32]; - sprintf(startstring, "%d", _value); - Glib::ustring * mystring = new Glib::ustring(startstring); - return mystring; -} - -/** \brief Return the value as a string */ -Glib::ustring * -ParamFloat::string (void) -{ - char startstring[G_ASCII_DTOSTR_BUF_SIZE]; - g_ascii_dtostr(startstring, G_ASCII_DTOSTR_BUF_SIZE, _value); - Glib::ustring * mystring = new Glib::ustring(startstring); - return mystring; -} - -/** \brief Return the value as a string */ -Glib::ustring * -ParamString::string (void) -{ - if (_value == NULL) - return new Glib::ustring(""); - - // FIXME: I think the string should NOT be escaped. Just put between "..." - // Otherwise \frac{1}{2} will become \\frac{1}{2} and then the LaTeX effect won't work.... - //gchar * esc = g_strescape(_value, NULL); - Glib::ustring escaped(_value); - //g_free(esc); - -#ifdef ESCAPE_DOLLAR_COMMANDLINE // escape the dollar sign - Glib::ustring::iterator i; - for (i = escaped.begin(); i != escaped.end(); ++i) { - if ( *i == '$') { - i = escaped.insert(i, '\\'); - i++; - } - } -#endif - - Glib::ustring * mystring = new Glib::ustring(""); - *mystring += "\""; - *mystring += escaped; - *mystring += "\""; - - return mystring; -} - -/** \brief Create a label for the description */ -Gtk::Widget * -ParamDescription::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) -{ - Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_value))); - label->set_line_wrap(); - label->show(); - - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); - hbox->pack_start(*label, true, true, 5); - hbox->show(); - - return hbox; -} - -/** \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, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, ext), _value(NULL) -{ - // printf("Building Description\n"); - const char * defaultval = NULL; - if (sp_repr_children(xml) != NULL) - defaultval = sp_repr_children(xml)->content(); - - if (defaultval != NULL) - _value = g_strdup(defaultval); - - return; -} ParamEnum::ParamEnum (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : Parameter(name, guitext, desc, scope, ext), _current_choice(NULL) -- cgit v1.2.3