1 #ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_ENUM_H
2 #define INKSCAPE_LIVEPATHEFFECT_PARAMETER_ENUM_H
4 /*
5 * Inkscape::LivePathEffectParameters
6 *
7 * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
8 *
9 * Released under GNU GPL, read the file 'COPYING' for more information
10 */
12 #include <glib/gtypes.h>
14 #include "ui/widget/registry.h"
15 #include "ui/widget/registered-enums.h"
16 #include <gtkmm/tooltips.h>
18 #include "live_effects/parameter/parameter.h"
19 #include "verbs.h"
21 namespace Inkscape {
23 namespace LivePathEffect {
25 template<typename E> class EnumParam : public Parameter {
26 public:
27 EnumParam( const Glib::ustring& label,
28 const Glib::ustring& tip,
29 const Glib::ustring& key,
30 const Util::EnumDataConverter<E>& c,
31 Inkscape::UI::Widget::Registry* wr,
32 Effect* effect,
33 E default_value)
34 : Parameter(label, tip, key, wr, effect)
35 {
36 regenum = NULL;
37 enumdataconv = &c;
38 defvalue = default_value;
39 value = defvalue;
40 };
41 virtual ~EnumParam() {
42 if (regenum)
43 delete regenum;
44 };
46 virtual Gtk::Widget * param_newWidget(Gtk::Tooltips * tooltips) {
47 // WIDGET TODO: This implementation is incorrect, it should create a *new* widget for the caller, not just return an already created widget
48 g_warning("EnumParam::param_newWidget still needs recoding to work with multiple document views");
49 if (!regenum) {
50 regenum = new Inkscape::UI::Widget::RegisteredEnum<E>();
51 regenum->init(param_label, param_tooltip, param_key, *enumdataconv, *param_wr, param_effect->getRepr(), param_effect->getSPDoc());
52 regenum->combobox()->set_active_by_id(value);
53 regenum->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change enum parameter"));
54 }
55 return dynamic_cast<Gtk::Widget *> (regenum->labelled);
56 };
58 bool param_readSVGValue(const gchar * strvalue) {
59 if (!strvalue) {
60 param_set_default();
61 return true;
62 }
64 param_set_value( enumdataconv->get_id_from_key(Glib::ustring(strvalue)) );
66 return true;
67 };
68 gchar * param_writeSVGValue() const {
69 gchar * str = g_strdup( enumdataconv->get_key(value).c_str() );
70 return str;
71 };
73 E get_value() const {
74 return value;
75 }
77 void param_set_default() {
78 param_set_value(defvalue);
79 }
81 void param_set_value(E val) {
82 value = val;
83 if (regenum)
84 regenum->combobox()->set_active_by_id(value);
85 }
87 private:
88 EnumParam(const EnumParam&);
89 EnumParam& operator=(const EnumParam&);
91 UI::Widget::RegisteredEnum<E> * regenum;
92 E value;
93 E defvalue;
95 const Util::EnumDataConverter<E> * enumdataconv;
96 };
99 }; //namespace LivePathEffect
101 }; //namespace Inkscape
103 #endif