Code

add CMakeLists.txt files for live_effects
[inkscape.git] / src / live_effects / parameter / enum.h
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/registered-enums.h"
15 #include <gtkmm/tooltips.h>
17 #include "live_effects/parameter/parameter.h"
18 #include "verbs.h"
20 namespace Inkscape {
22 namespace LivePathEffect {
24 template<typename E> class EnumParam : public Parameter {
25 public:
26     EnumParam(  const Glib::ustring& label,
27                 const Glib::ustring& tip,
28                 const Glib::ustring& key,
29                 const Util::EnumDataConverter<E>& c,
30                 Inkscape::UI::Widget::Registry* wr,
31                 Effect* effect,
32                 E default_value)
33         : Parameter(label, tip, key, wr, effect)
34     {
35         enumdataconv = &c;
36         defvalue = default_value;
37         value = defvalue;
38     };
40     virtual ~EnumParam() { };
42     virtual Gtk::Widget * param_newWidget(Gtk::Tooltips * /*tooltips*/) {
43         Inkscape::UI::Widget::RegisteredEnum<E> *regenum = Gtk::manage ( 
44             new Inkscape::UI::Widget::RegisteredEnum<E>( param_label, param_tooltip,
45                        param_key, *enumdataconv, *param_wr, param_effect->getRepr(), param_effect->getSPDoc() ) );
47         regenum->set_active_by_id(value);
48         regenum->combobox()->setProgrammatically = false;
49         regenum->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change enumeration parameter"));
51         return dynamic_cast<Gtk::Widget *> (regenum);
52     };
54     bool param_readSVGValue(const gchar * strvalue) {
55         if (!strvalue) {
56             param_set_default();
57             return true;
58         }
60         param_set_value( enumdataconv->get_id_from_key(Glib::ustring(strvalue)) );
62         return true;
63     };
64     gchar * param_writeSVGValue() const {
65         gchar * str = g_strdup( enumdataconv->get_key(value).c_str() );
66         return str;
67     };
69     E get_value() const {
70         return value;
71     }
73     void param_set_default() {
74         param_set_value(defvalue);
75     }
77     void param_set_value(E val) {
78         value = val;
79     }
81 private:
82     EnumParam(const EnumParam&);
83     EnumParam& operator=(const EnumParam&);
85     E value;
86     E defvalue;
88     const Util::EnumDataConverter<E> * enumdataconv;
89 };
92 }; //namespace LivePathEffect
94 }; //namespace Inkscape
96 #endif