X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fextension%2Fparameter.cpp;h=70f66c41660c37995e4dc63f1b332797f5358ab0;hb=7150f0829e7f5452f5cab605b8014a245f9b7e7c;hp=eda540a9d56d789cf72b115cea19b014a5db1fa7;hpb=b6ae2ff55ce50b104521cce0a0c2e96f40881006;p=inkscape.git diff --git a/src/extension/parameter.cpp b/src/extension/parameter.cpp index eda540a9d..70f66c416 100644 --- a/src/extension/parameter.cpp +++ b/src/extension/parameter.cpp @@ -3,10 +3,11 @@ */ /* - * Authors: + * Author: * Ted Gould * - * Copyright (C) 2005-2006 Authors + * Copyright (C) 2006 Johan Engelen + * Copyright (C) 2005-2006 Author * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -30,6 +31,8 @@ #include "sp-object.h" #include "parameter.h" +#include "paramnotebook.h" +#include "paramenum.h" /** \brief The root directory in the preferences database for extension related parameters. */ @@ -38,6 +41,16 @@ 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); +}; + /** \brief A boolean parameter */ class ParamBool : public Parameter { private: @@ -196,6 +209,40 @@ public: Glib::ustring * string (void); }; +class ParamEnum : public Parameter { +private: + class Choice { + public: + gchar * _gui_name; + gchar * _value; + Choice(gchar * gui_name, gchar * value) : _gui_name(NULL), _value(NULL) { + if (gui_name != NULL) + _gui_name = g_strdup(_(gui_name)); + if (value != NULL) + _value = g_strdup(value); + return; + }; + ~Choice (void) { + g_free(_gui_name); + g_free(_value); + }; + }; /* class Choice */ + /** \brief Internal value. This should point to a string that has + been allocated in memory. And should be free'd. */ + Choice * _current_choice; + typedef std::list choice_list_t; + choice_list_t _choice_list; +public: + ParamEnum(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); + ~ParamEnum(void); + /** \brief Returns \c _value, with a \i const to protect it. */ + const gchar * get (const SPDocument * doc, const Inkscape::XML::Node * node) { return _current_choice != NULL ? _current_choice->_value : NULL; } + const gchar * set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node); + Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node); + Glib::ustring * string (void); +}; /* class ParamEnum */ + + /** \return None \brief This function creates a parameter that can be used later. This @@ -263,6 +310,12 @@ Parameter::make (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * param = new ParamFloat(name, guitext, desc, scope, in_ext, in_repr); } else if (!strcmp(type, "string")) { param = new ParamString(name, guitext, desc, scope, in_ext, in_repr); + } else if (!strcmp(type, "description")) { + param = new ParamDescription(name, guitext, desc, scope, in_ext, in_repr); + } else if (!strcmp(type, "enum")) { + param = new ParamComboBox(name, guitext, desc, scope, in_ext, in_repr); + } else if (!strcmp(type, "notebook")) { + param = new ParamNotebook(name, guitext, desc, scope, in_ext, in_repr); } /* Note: param could equal NULL */ @@ -647,7 +700,7 @@ ParamIntAdjustment::val_changed (void) Gtk::Widget * ParamFloat::get_widget (SPDocument * doc, Inkscape::XML::Node * node) { - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox()); + Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT)); label->show(); @@ -671,7 +724,7 @@ ParamFloat::get_widget (SPDocument * doc, Inkscape::XML::Node * node) Gtk::Widget * ParamInt::get_widget (SPDocument * doc, Inkscape::XML::Node * node) { - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox()); + Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT)); label->show(); @@ -732,7 +785,7 @@ ParamBoolCheckButton::on_toggle (void) Gtk::Widget * ParamBool::get_widget (SPDocument * doc, Inkscape::XML::Node * node) { - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox()); + Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT)); label->show(); @@ -788,15 +841,15 @@ ParamStringEntry::changed_text (void) Gtk::Widget * ParamString::get_widget (SPDocument * doc, Inkscape::XML::Node * node) { - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox()); + 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, false, false); ParamStringEntry * textbox = new ParamStringEntry(this, doc, node); textbox->show(); - hbox->pack_start(*textbox, false, false); + hbox->pack_start(*textbox, true, true); hbox->show(); @@ -848,6 +901,70 @@ ParamString::string (void) return mystring; } +/** \brief Create a label for the description */ +Gtk::Widget * +ParamDescription::get_widget (SPDocument * doc, Inkscape::XML::Node * node) +{ + 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) +{ + return; +} + +ParamEnum::~ParamEnum (void) +{ + +} + +/** \brief Return the value as a string */ +Glib::ustring * +ParamEnum::string (void) +{ + Glib::ustring * mystring = new Glib::ustring(""); + *mystring += "\""; + *mystring += this->get(NULL, NULL); + *mystring += "\""; + return mystring; +} + +Gtk::Widget * +ParamEnum::get_widget (SPDocument * doc, Inkscape::XML::Node * node) +{ + return NULL; +} + +const gchar * +ParamEnum::set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node) +{ + return NULL; +} + } /* namespace Extension */ } /* namespace Inkscape */