Code

r11512@tres: ted | 2006-04-24 21:36:08 -0700
[inkscape.git] / src / extension / parameter.cpp
index 7e5d46739b5e2e833db339ebf438a1972d07906a..ce6c8c272634a19baadfe1558c19da1c3fd270d0 100644 (file)
 namespace Inkscape {
 namespace Extension {
 
-/*
-template <typename T> class ParamSpecific : public Parameter {
-private:
-    T _value;
-public:
-    ParamSpecific (const gchar * name, const gchar * guitext, Inkscape::Extension * ext, Inkscape::XML::Node * xml);
-    T get (const Inkscape::XML::Document * doc, const Inkscape::XML::Node * node);
-    T set (T in, Inkscape::XML::Document * doc, Inkscape::XML::Node * node);
-    Gtk::Widget * get_widget(void);
-    Glib::ustring * string (void);
-};
-
-bool
-ParamSpecific<bool>::get (const Inkscape::XML::Document * doc, const Inkscape::XML::Node * node)
-{
-    return _value;
-}
-
-int
-ParamSpecific<int>::get (const Inkscape::XML::Document * doc, const Inkscape::XML::Node * node)
-{
-    return _value;
-}
-*/
-
 /** \brief  A boolean parameter */
 class ParamBool : public Parameter {
 private:
     /** \brief  Internal value. */
     bool _value;
 public:
-    ParamBool(const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml);
+    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 Inkscape::XML::Document * doc, const Inkscape::XML::Node * node) { return _value; }
     bool set (bool in, Inkscape::XML::Document * doc, Inkscape::XML::Node * node);
@@ -74,8 +49,8 @@ public:
 };
 
 /** \brief  Use the superclass' allocator and set the \c _value */
-ParamBool::ParamBool (const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) :
-        Parameter(name, guitext, ext), _value(false)
+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)
@@ -101,7 +76,7 @@ private:
     int _min;
     int _max;
 public:
-    ParamInt (const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml);
+    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 Inkscape::XML::Document * doc, const Inkscape::XML::Node * node) { return _value; }
     int set (int in, Inkscape::XML::Document * doc, Inkscape::XML::Node * node);
@@ -112,8 +87,8 @@ public:
 };
 
 /** \brief  Use the superclass' allocator and set the \c _value */
-ParamInt::ParamInt (const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) :
-        Parameter(name, guitext, ext), _value(0), _min(0), _max(10)
+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)
@@ -155,7 +130,7 @@ private:
     float _min;
     float _max;
 public:
-    ParamFloat (const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml);
+    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 Inkscape::XML::Document * doc, const Inkscape::XML::Node * node) { return _value; }
     float set (float in, Inkscape::XML::Document * doc, Inkscape::XML::Node * node);
@@ -166,8 +141,8 @@ public:
 };
 
 /** \brief  Use the superclass' allocator and set the \c _value */
-ParamFloat::ParamFloat (const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) :
-        Parameter(name, guitext, ext), _value(0.0), _min(0.0), _max(10.0)
+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)
@@ -208,7 +183,7 @@ private:
                 been allocated in memory.  And should be free'd. */
     gchar * _value;
 public:
-    ParamString(const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml);
+    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 Inkscape::XML::Document * doc, const Inkscape::XML::Node * node) { return _value; }
@@ -246,27 +221,44 @@ Parameter::make (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension *
     const char * name;
     const char * type;
     const char * guitext;
+    const char * desc;
+    const char * scope_str;
+    Parameter::_scope_t scope = Parameter::SCOPE_USER;
 
     name = in_repr->attribute("name");
     type = in_repr->attribute("type");
     guitext = in_repr->attribute("gui-text");
     if (guitext == NULL)
         guitext = in_repr->attribute("_gui-text");
+    desc = in_repr->attribute("gui-description");
+    if (desc == NULL)
+        desc = in_repr->attribute("_gui-description");
+    scope_str = in_repr->attribute("scope");
 
     /* In this case we just don't have enough information */
     if (name == NULL || type == NULL) {
         return NULL;
     }
 
+    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 * param = NULL;
     if (!strcmp(type, "boolean")) {
-        param = new ParamBool(name, guitext, in_ext, in_repr);
+        param = new ParamBool(name, guitext, desc, scope, in_ext, in_repr);
     } else if (!strcmp(type, "int")) {
-        param = new ParamInt(name, guitext, in_ext, in_repr);
+        param = new ParamInt(name, guitext, desc, scope, in_ext, in_repr);
     } else if (!strcmp(type, "float")) {
-        param = new ParamFloat(name, guitext, in_ext, in_repr);
+        param = new ParamFloat(name, guitext, desc, scope, in_ext, in_repr);
     } else if (!strcmp(type, "string")) {
-        param = new ParamString(name, guitext, in_ext, in_repr);
+        param = new ParamString(name, guitext, desc, scope, in_ext, in_repr);
     }
 
     /* Note: param could equal NULL */
@@ -458,8 +450,8 @@ Parameter::set_string (const gchar * in, Inkscape::XML::Document * doc, Inkscape
 }
 
 /** \brief  Initialize the object, to do that, copy the data. */
-ParamString::ParamString (const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) :
-    Parameter(name, guitext, ext), _value(NULL)
+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)
 {
     const char * defaultval = NULL;
     if (sp_repr_children(xml) != NULL)
@@ -484,14 +476,23 @@ ParamString::~ParamString(void)
 }
 
 /** \brief  Oop, now that we need a parameter, we need it's name.  */
-Parameter::Parameter (const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext) :
-    extension(ext), _name(NULL), _text(NULL)
-{
-    _name = g_strdup(name);
+Parameter::Parameter (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext) :
+    extension(ext), _name(NULL), _desc(NULL), _scope(scope), _text(NULL)
+{
+    if (name != NULL)
+        _name = g_strdup(name);
+    if (desc != NULL) {
+        _desc = g_strdup(desc);
+        // printf("Adding description: '%s' on '%s'\n", _desc, _name);
+    }
+
+
     if (guitext != NULL)
         _text = g_strdup(guitext);
     else
         _text = g_strdup(name);
+
+    return;
 }
 
 /** \brief  Just free the allocated name. */
@@ -594,14 +595,14 @@ ParamIntAdjustment::val_changed (void)
 Gtk::Widget *
 ParamFloat::get_widget (void)
 {
-    Gtk::HBox * hbox = new Gtk::HBox();
+    Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox());
 
-    Gtk::Label * label = new Gtk::Label(_(_text), Gtk::ALIGN_LEFT);
+    Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT));
     label->show();
     hbox->pack_start(*label, true, true);
 
     ParamFloatAdjustment * fadjust = new ParamFloatAdjustment(this);
-    Gtk::SpinButton * spin = new Gtk::SpinButton(*fadjust, 0.1, 1);
+    Gtk::SpinButton * spin = Gtk::manage(new Gtk::SpinButton(*fadjust, 0.1, 1));
     spin->show();
     hbox->pack_start(*spin, false, false);
 
@@ -618,14 +619,14 @@ ParamFloat::get_widget (void)
 Gtk::Widget *
 ParamInt::get_widget (void)
 {
-    Gtk::HBox * hbox = new Gtk::HBox();
+    Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox());
 
-    Gtk::Label * label = new Gtk::Label(_(_text), Gtk::ALIGN_LEFT);
+    Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT));
     label->show();
     hbox->pack_start(*label, true, true);
 
     ParamIntAdjustment * fadjust = new ParamIntAdjustment(this);
-    Gtk::SpinButton * spin = new Gtk::SpinButton(*fadjust, 1.0, 0);
+    Gtk::SpinButton * spin = Gtk::manage(new Gtk::SpinButton(*fadjust, 1.0, 0));
     spin->show();
     hbox->pack_start(*spin, false, false);
 
@@ -677,9 +678,9 @@ ParamBoolCheckButton::on_toggle (void)
 Gtk::Widget *
 ParamBool::get_widget (void)
 {
-    Gtk::HBox * hbox = new Gtk::HBox();
+    Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox());
 
-    Gtk::Label * label = new Gtk::Label(_(_text), Gtk::ALIGN_LEFT);
+    Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT));
     label->show();
     hbox->pack_start(*label, true, true);
 
@@ -731,9 +732,9 @@ ParamStringEntry::changed_text (void)
 Gtk::Widget *
 ParamString::get_widget (void)
 {
-    Gtk::HBox * hbox = new Gtk::HBox();
+    Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox());
 
-    Gtk::Label * label = new Gtk::Label(_(_text), Gtk::ALIGN_LEFT);
+    Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT));
     label->show();
     hbox->pack_start(*label, true, true);