1c5384f57dda03e2ff6c363e6738840f43ca50af
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 Gtk::Widget * param_getWidget() {
47 if (!regenum) {
48 regenum = new Inkscape::UI::Widget::RegisteredEnum<E>();
49 regenum->init(param_label, param_tooltip, param_key, *enumdataconv, *param_wr, param_effect->getRepr(), param_effect->getSPDoc());
50 regenum->combobox()->set_active_by_id(value);
51 regenum->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change enum parameter"));
52 }
53 return dynamic_cast<Gtk::Widget *> (regenum->labelled);
54 };
56 bool param_readSVGValue(const gchar * strvalue) {
57 if (!strvalue) {
58 param_set_default();
59 return true;
60 }
62 param_set_value( enumdataconv->get_id_from_key(Glib::ustring(strvalue)) );
64 return true;
65 };
66 gchar * param_writeSVGValue() const {
67 gchar * str = g_strdup( enumdataconv->get_key(value).c_str() );
68 return str;
69 };
71 E get_value() const {
72 return value;
73 }
75 void param_set_default() {
76 param_set_value(defvalue);
77 }
79 void param_set_value(E val) {
80 value = val;
81 if (regenum)
82 regenum->combobox()->set_active_by_id(value);
83 }
85 private:
86 EnumParam(const EnumParam&);
87 EnumParam& operator=(const EnumParam&);
89 UI::Widget::RegisteredEnum<E> * regenum;
90 E value;
91 E defvalue;
93 const Util::EnumDataConverter<E> * enumdataconv;
94 };
97 }; //namespace LivePathEffect
99 }; //namespace Inkscape
101 #endif