Code

add copy button to LPE pathparam
[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/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         enumdataconv = &c;
37         defvalue = default_value;
38         value = defvalue;
39     };
41     virtual ~EnumParam() { };
43     virtual Gtk::Widget * param_newWidget(Gtk::Tooltips * /*tooltips*/) {
44         Inkscape::UI::Widget::RegisteredEnum<E> *regenum = Gtk::manage ( 
45             new Inkscape::UI::Widget::RegisteredEnum<E>( param_label, param_tooltip,
46                        param_key, *enumdataconv, *param_wr, param_effect->getRepr(), param_effect->getSPDoc() ) );
48         regenum->set_active_by_id(value);
49         regenum->combobox()->setProgrammatically = false;
50         regenum->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change enumeration parameter"));
52         return dynamic_cast<Gtk::Widget *> (regenum);
53     };
55     bool param_readSVGValue(const gchar * strvalue) {
56         if (!strvalue) {
57             param_set_default();
58             return true;
59         }
61         param_set_value( enumdataconv->get_id_from_key(Glib::ustring(strvalue)) );
63         return true;
64     };
65     gchar * param_writeSVGValue() const {
66         gchar * str = g_strdup( enumdataconv->get_key(value).c_str() );
67         return str;
68     };
70     E get_value() const {
71         return value;
72     }
74     void param_set_default() {
75         param_set_value(defvalue);
76     }
78     void param_set_value(E val) {
79         value = val;
80     }
82 private:
83     EnumParam(const EnumParam&);
84     EnumParam& operator=(const EnumParam&);
86     E value;
87     E defvalue;
89     const Util::EnumDataConverter<E> * enumdataconv;
90 };
93 }; //namespace LivePathEffect
95 }; //namespace Inkscape
97 #endif