Code

Make text widget for TextParams work and re-enable it
[inkscape.git] / src / live_effects / parameter / text.cpp
1 #define INKSCAPE_LIVEPATHEFFECT_PARAMETER_TEXT_CPP
3 /*
4  * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
5  *
6  * Authors:
7  *   Maximilian Albert
8  *   Johan Engelen
9  *
10  * Released under GNU GPL, read the file 'COPYING' for more information
11  */
13 #include "live_effects/parameter/text.h"
14 #include "live_effects/effect.h"
15 #include "svg/svg.h"
16 #include "svg/stringstream.h"
17 #include <gtkmm.h>
18 #include "widgets/icon.h"
19 #include "ui/widget/registered-widget.h"
20 #include "inkscape.h"
21 #include "verbs.h"
23 namespace Inkscape {
25 namespace LivePathEffect {
27 TextParam::TextParam( const Glib::ustring& label, const Glib::ustring& tip,
28                       const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
29                       Effect* effect, const Glib::ustring default_value )
30     : Parameter(label, tip, key, wr, effect),
31       value(default_value),
32       defvalue(default_value)
33 {
34     canvas_text = (SPCanvasText *) sp_canvastext_new(sp_desktop_tempgroup(inkscape_active_desktop()), Geom::Point(0,0), "");
35     sp_canvastext_set_text (canvas_text, default_value.c_str());
36     sp_canvastext_set_coords (canvas_text, 0, 0);
37 }
39 TextParam::~TextParam()
40 {
41 }
43 void
44 TextParam::param_set_default()
45 {
46     param_setValue(defvalue);
47 }
49 void
50 TextParam::setPos(Geom::Point pos)
51 {
52     sp_canvastext_set_coords (canvas_text, pos);
53 }
55 void
56 TextParam::setAnchor(double x_value, double y_value)
57 {
58     anchor_x = x_value;
59     anchor_y = y_value;
60     sp_canvastext_set_anchor (canvas_text, anchor_x, anchor_y);
61 }
63 bool
64 TextParam::param_readSVGValue(const gchar * strvalue)
65 {
66     param_setValue(strvalue);
67     return true;
68 }
70 gchar *
71 TextParam::param_getSVGValue() const
72 {
73     return (gchar *) value.c_str();
74 }
76 Gtk::Widget *
77 TextParam::param_newWidget(Gtk::Tooltips * /*tooltips*/)
78 {
79     Inkscape::UI::Widget::RegisteredText *rsu = Gtk::manage(new Inkscape::UI::Widget::RegisteredText(
80         param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc()));
82     rsu->setText(value.c_str());
83     rsu->setProgrammatically = false;
85     rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change text parameter"));
87     return dynamic_cast<Gtk::Widget *> (rsu);
88 }
90 void
91 TextParam::param_setValue(const Glib::ustring newvalue)
92 {
93     value = newvalue;
95     sp_canvastext_set_text (canvas_text, newvalue.c_str());
96 }
98 } /* namespace LivePathEffect */
100 } /* namespace Inkscape */
102 /*
103   Local Variables:
104   mode:c++
105   c-file-style:"stroustrup"
106   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
107   indent-tabs-mode:nil
108   fill-column:99
109   End:
110 */
111 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :