Code

r11146@tres: ted | 2006-03-27 22:27:01 -0800
[inkscape.git] / src / extension / parameter.cpp
1 /** \file
2  * Parameters for extensions.
3  */
5 /*
6  * Authors:
7  *   Ted Gould <ted@gould.cx>
8  *
9  * Copyright (C) 2005 Authors
10  *
11  * Released under GNU GPL, read the file 'COPYING' for more information
12  */
14 #ifdef HAVE_CONFIG_H
15 # include "config.h"
16 #endif
19 #include <gtkmm/adjustment.h>
20 #include <gtkmm/box.h>
21 #include <gtkmm/spinbutton.h>
23 #include <glibmm/i18n.h>
25 #include "extension.h"
26 #include "prefs-utils.h"
28 #include "parameter.h"
30 /** \brief  The root directory in the preferences database for extension
31             related parameters. */
32 #define PREF_DIR "extensions"
34 namespace Inkscape {
35 namespace Extension {
37 /*
38 template <typename T> class ParamSpecific : public Parameter {
39 private:
40     T _value;
41 public:
42     ParamSpecific (const gchar * name, const gchar * guitext, Inkscape::Extension * ext, Inkscape::XML::Node * xml);
43     T get (const Inkscape::XML::Document * doc, const Inkscape::XML::Node * node);
44     T set (T in, Inkscape::XML::Document * doc, Inkscape::XML::Node * node);
45     Gtk::Widget * get_widget(void);
46     Glib::ustring * string (void);
47 };
49 bool
50 ParamSpecific<bool>::get (const Inkscape::XML::Document * doc, const Inkscape::XML::Node * node)
51 {
52     return _value;
53 }
55 int
56 ParamSpecific<int>::get (const Inkscape::XML::Document * doc, const Inkscape::XML::Node * node)
57 {
58     return _value;
59 }
60 */
62 /** \brief  A boolean parameter */
63 class ParamBool : public Parameter {
64 private:
65     /** \brief  Internal value. */
66     bool _value;
67 public:
68     ParamBool(const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml);
69     /** \brief  Returns \c _value */
70     bool get (const Inkscape::XML::Document * doc, const Inkscape::XML::Node * node) { return _value; }
71     bool set (bool in, Inkscape::XML::Document * doc, Inkscape::XML::Node * node);
72     Gtk::Widget * get_widget(void);
73     Glib::ustring * string (void);
74 };
76 /** \brief  Use the superclass' allocator and set the \c _value */
77 ParamBool::ParamBool (const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) :
78         Parameter(name, guitext, ext), _value(false)
79 {
80     const char * defaultval = NULL;
81     if (sp_repr_children(xml) != NULL)
82         defaultval = sp_repr_children(xml)->content();
84     if (defaultval != NULL && (!strcmp(defaultval, "TRUE") || !strcmp(defaultval, "true") || !strcmp(defaultval, "1"))) {
85         _value = true;
86     } else {
87         _value = false;
88     }
90     gchar * pref_name = this->pref_name();
91     _value = (bool)prefs_get_int_attribute(PREF_DIR, pref_name, _value);
92     g_free(pref_name);
94     return;
95 }
97 class ParamInt : public Parameter {
98 private:
99     /** \brief  Internal value. */
100     int _value;
101     int _min;
102     int _max;
103 public:
104     ParamInt (const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml);
105     /** \brief  Returns \c _value */
106     int get (const Inkscape::XML::Document * doc, const Inkscape::XML::Node * node) { return _value; }
107     int set (int in, Inkscape::XML::Document * doc, Inkscape::XML::Node * node);
108     int max (void) { return _max; }
109     int min (void) { return _min; }
110     Gtk::Widget * get_widget(void);
111     Glib::ustring * string (void);
112 };
114 /** \brief  Use the superclass' allocator and set the \c _value */
115 ParamInt::ParamInt (const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) :
116         Parameter(name, guitext, ext), _value(0), _min(0), _max(10)
118     const char * defaultval = NULL;
119     if (sp_repr_children(xml) != NULL)
120         defaultval = sp_repr_children(xml)->content();
121     if (defaultval != NULL) {
122         _value = atoi(defaultval);
123     }
125     const char * maxval = xml->attribute("max");
126     if (maxval != NULL)
127         _max = atoi(maxval);
129     const char * minval = xml->attribute("min");
130     if (minval != NULL)
131         _min = atoi(minval);
133     /* We're handling this by just killing both values */
134     if (_max < _min) {
135         _max = 10;
136         _min = 0;
137     }
139     gchar * pref_name = this->pref_name();
140     _value = prefs_get_int_attribute(PREF_DIR, pref_name, _value);
141     g_free(pref_name);
143     // std::cout << "New Int::  value: " << _value << "  max: " << _max << "  min: " << _min << std::endl;
145     if (_value > _max) _value = _max;
146     if (_value < _min) _value = _min;
148     return;
151 class ParamFloat : public Parameter {
152 private:
153     /** \brief  Internal value. */
154     float _value;
155     float _min;
156     float _max;
157 public:
158     ParamFloat (const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml);
159     /** \brief  Returns \c _value */
160     float get (const Inkscape::XML::Document * doc, const Inkscape::XML::Node * node) { return _value; }
161     float set (float in, Inkscape::XML::Document * doc, Inkscape::XML::Node * node);
162     float max (void) { return _max; }
163     float min (void) { return _min; }
164     Gtk::Widget * get_widget(void);
165     Glib::ustring * string (void);
166 };
168 /** \brief  Use the superclass' allocator and set the \c _value */
169 ParamFloat::ParamFloat (const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) :
170         Parameter(name, guitext, ext), _value(0.0), _min(0.0), _max(10.0)
172     const char * defaultval = NULL;
173     if (sp_repr_children(xml) != NULL)
174         defaultval = sp_repr_children(xml)->content();
175     if (defaultval != NULL) {
176         _value = atof(defaultval);
177     }
179     const char * maxval = xml->attribute("max");
180     if (maxval != NULL)
181         _max = atof(maxval);
183     const char * minval = xml->attribute("min");
184     if (minval != NULL)
185         _min = atof(minval);
187     /* We're handling this by just killing both values */
188     if (_max < _min) {
189         _max = 10.0;
190         _min = 0.0;
191     }
193     gchar * pref_name = this->pref_name();
194     _value = prefs_get_double_attribute(PREF_DIR, pref_name, _value);
195     g_free(pref_name);
197     // std::cout << "New Float::  value: " << _value << "  max: " << _max << "  min: " << _min << std::endl;
199     if (_value > _max) _value = _max;
200     if (_value < _min) _value = _min;
202     return;
205 class ParamString : public Parameter {
206 private:
207     /** \brief  Internal value.  This should point to a string that has
208                 been allocated in memory.  And should be free'd. */
209     gchar * _value;
210 public:
211     ParamString(const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml);
212     ~ParamString(void);
213     /** \brief  Returns \c _value, with a \i const to protect it. */
214     const gchar * get (const Inkscape::XML::Document * doc, const Inkscape::XML::Node * node) { return _value; }
215     const gchar * set (const gchar * in, Inkscape::XML::Document * doc, Inkscape::XML::Node * node);
216     Gtk::Widget * get_widget(void);
217     Glib::ustring * string (void);
218 };
220 /**
221     \return None
222     \brief  This function creates a parameter that can be used later.  This
223             is typically done in the creation of the extension and defined
224             in the XML file describing the extension (it's private so people
225             have to use the system) :)
226     \param  in_repr  The XML describing the parameter
228     This function first grabs all of the data out of the Repr and puts
229     it into local variables.  Actually, these are just pointers, and the
230     data is not duplicated so we need to be careful with it.  If there
231     isn't a name or a type in the XML, then no parameter is created as
232     the function just returns.
234     From this point on, we're pretty committed as we've allocated an
235     object and we're starting to fill it.  The name is set first, and
236     is created with a strdup to actually allocate memory for it.  Then
237     there is a case statement (roughly because strcmp requires 'ifs')
238     based on what type of parameter this is.  Depending which type it
239     is, the value is interpreted differently, but they are relatively
240     straight forward.  In all cases the value is set to the default
241     value from the XML and the type is set to the interpreted type.
242 */
243 Parameter *
244 Parameter::make (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * in_ext)
246     const char * name;
247     const char * type;
248     const char * guitext;
250     name = in_repr->attribute("name");
251     type = in_repr->attribute("type");
252     guitext = in_repr->attribute("gui-text");
253     if (guitext == NULL)
254         guitext = in_repr->attribute("_gui-text");
256     /* In this case we just don't have enough information */
257     if (name == NULL || type == NULL) {
258         return NULL;
259     }
261     Parameter * param = NULL;
262     if (!strcmp(type, "boolean")) {
263         param = new ParamBool(name, guitext, in_ext, in_repr);
264     } else if (!strcmp(type, "int")) {
265         param = new ParamInt(name, guitext, in_ext, in_repr);
266     } else if (!strcmp(type, "float")) {
267         param = new ParamFloat(name, guitext, in_ext, in_repr);
268     } else if (!strcmp(type, "string")) {
269         param = new ParamString(name, guitext, in_ext, in_repr);
270     }
272     /* Note: param could equal NULL */
273     return param;
276 /** \brief  A function to set the \c _value
277     \param  in   The value to set to
278     \param  doc  A document that should be used to set the value.
279     \param  node The node where the value may be placed
281     This function sets the internal value, but it also sets the value
282     in the preferences structure.  To put it in the right place, \c PREF_DIR
283     and \c pref_name() are used.
284 */
285 bool
286 ParamBool::set (bool in, Inkscape::XML::Document * doc, Inkscape::XML::Node * node)
288     _value = in;
290     gchar * prefname = this->pref_name();
291     prefs_set_int_attribute(PREF_DIR, prefname, _value == true ? 1 : 0);
292     g_free(prefname);
294     return _value;
297 /** \brief  A function to set the \c _value
298     \param  in   The value to set to
299     \param  doc  A document that should be used to set the value.
300     \param  node The node where the value may be placed
302     This function sets the internal value, but it also sets the value
303     in the preferences structure.  To put it in the right place, \c PREF_DIR
304     and \c pref_name() are used.
305 */
306 int
307 ParamInt::set (int in, Inkscape::XML::Document * doc, Inkscape::XML::Node * node)
309     _value = in;
310     if (_value > _max) _value = _max;
311     if (_value < _min) _value = _min;
313     gchar * prefname = this->pref_name();
314     prefs_set_int_attribute(PREF_DIR, prefname, _value);
315     g_free(prefname);
317     return _value;
320 /** \brief  A function to set the \c _value
321     \param  in   The value to set to
322     \param  doc  A document that should be used to set the value.
323     \param  node The node where the value may be placed
325     This function sets the internal value, but it also sets the value
326     in the preferences structure.  To put it in the right place, \c PREF_DIR
327     and \c pref_name() are used.
328 */
329 float
330 ParamFloat::set (float in, Inkscape::XML::Document * doc, Inkscape::XML::Node * node)
332     _value = in;
333     if (_value > _max) _value = _max;
334     if (_value < _min) _value = _min;
336     gchar * prefname = this->pref_name();
337     prefs_set_double_attribute(PREF_DIR, prefname, _value);
338     g_free(prefname);
340     return _value;
343 /** \brief  A function to set the \c _value
344     \param  in   The value to set to
345     \param  doc  A document that should be used to set the value.
346     \param  node The node where the value may be placed
348     This function sets the internal value, but it also sets the value
349     in the preferences structure.  To put it in the right place, \c PREF_DIR
350     and \c pref_name() are used.
352     To copy the data into _value the old memory must be free'd first.
353     It is important to note that \c g_free handles \c NULL just fine.  Then
354     the passed in value is duplicated using \c g_strdup().
355 */
356 const gchar *
357 ParamString::set (const gchar * in, Inkscape::XML::Document * doc, Inkscape::XML::Node * node)
359     if (in == NULL) return NULL; /* Can't have NULL string */
361     if (_value != NULL)
362         g_free(_value);
363     _value = g_strdup(in);
365     gchar * prefname = this->pref_name();
366     prefs_set_string_attribute(PREF_DIR, prefname, _value);
367     g_free(prefname);
369     return _value;
372 /** \brief  Wrapper to cast to the object and use it's function.  */
373 bool
374 Parameter::get_bool (const Inkscape::XML::Document * doc, const Inkscape::XML::Node * node)
376     ParamBool * boolpntr;
377     boolpntr = dynamic_cast<ParamBool *>(this);
378     if (boolpntr == NULL)
379         throw Extension::param_wrong_type();
380     return boolpntr->get(doc, node);
383 /** \brief  Wrapper to cast to the object and use it's function.  */
384 int
385 Parameter::get_int (const Inkscape::XML::Document * doc, const Inkscape::XML::Node * node)
387     ParamInt * intpntr;
388     intpntr = dynamic_cast<ParamInt *>(this);
389     if (intpntr == NULL)
390         throw Extension::param_wrong_type();
391     return intpntr->get(doc, node);
394 /** \brief  Wrapper to cast to the object and use it's function.  */
395 float
396 Parameter::get_float (const Inkscape::XML::Document * doc, const Inkscape::XML::Node * node)
398     ParamFloat * floatpntr;
399     floatpntr = dynamic_cast<ParamFloat *>(this);
400     if (floatpntr == NULL)
401         throw Extension::param_wrong_type();
402     return floatpntr->get(doc, node);
405 /** \brief  Wrapper to cast to the object and use it's function.  */
406 const gchar *
407 Parameter::get_string (const Inkscape::XML::Document * doc, const Inkscape::XML::Node * node)
409     ParamString * stringpntr;
410     stringpntr = dynamic_cast<ParamString *>(this);
411     if (stringpntr == NULL)
412         throw Extension::param_wrong_type();
413     return stringpntr->get(doc, node);
416 /** \brief  Wrapper to cast to the object and use it's function.  */
417 bool
418 Parameter::set_bool (bool in, Inkscape::XML::Document * doc, Inkscape::XML::Node * node)
420     ParamBool * boolpntr;
421     boolpntr = dynamic_cast<ParamBool *>(this);
422     if (boolpntr == NULL)
423         throw Extension::param_wrong_type();
424     return boolpntr->set(in, doc, node);
427 /** \brief  Wrapper to cast to the object and use it's function.  */
428 int
429 Parameter::set_int (int in, Inkscape::XML::Document * doc, Inkscape::XML::Node * node)
431     ParamInt * intpntr;
432     intpntr = dynamic_cast<ParamInt *>(this);
433     if (intpntr == NULL)
434         throw Extension::param_wrong_type();
435     return intpntr->set(in, doc, node);
438 /** \brief  Wrapper to cast to the object and use it's function.  */
439 float
440 Parameter::set_float (float in, Inkscape::XML::Document * doc, Inkscape::XML::Node * node)
442     ParamFloat * floatpntr;
443     floatpntr = dynamic_cast<ParamFloat *>(this);
444     if (floatpntr == NULL)
445         throw Extension::param_wrong_type();
446     return floatpntr->set(in, doc, node);
449 /** \brief  Wrapper to cast to the object and use it's function.  */
450 const gchar *
451 Parameter::set_string (const gchar * in, Inkscape::XML::Document * doc, Inkscape::XML::Node * node)
453     ParamString * stringpntr;
454     stringpntr = dynamic_cast<ParamString *>(this);
455     if (stringpntr == NULL)
456         throw Extension::param_wrong_type();
457     return stringpntr->set(in, doc, node);
460 /** \brief  Initialize the object, to do that, copy the data. */
461 ParamString::ParamString (const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) :
462     Parameter(name, guitext, ext), _value(NULL)
464     const char * defaultval = NULL;
465     if (sp_repr_children(xml) != NULL)
466         defaultval = sp_repr_children(xml)->content();
468     gchar * pref_name = this->pref_name();
469     const gchar * paramval = prefs_get_string_attribute(PREF_DIR, pref_name);
470     g_free(pref_name);
472     if (paramval != NULL)
473         defaultval = paramval;
474     if (defaultval != NULL)
475         _value = g_strdup(defaultval);
477     return;
480 /** \brief  Free the allocated data. */
481 ParamString::~ParamString(void)
483     g_free(_value);
486 /** \brief  Oop, now that we need a parameter, we need it's name.  */
487 Parameter::Parameter (const gchar * name, const gchar * guitext, Inkscape::Extension::Extension * ext) :
488     extension(ext), _name(NULL), _text(NULL)
490     _name = g_strdup(name);
491     if (guitext != NULL)
492         _text = g_strdup(guitext);
493     else
494         _text = g_strdup(name);
497 /** \brief  Just free the allocated name. */
498 Parameter::~Parameter (void)
500     g_free(_name);
501     g_free(_text);
504 /** \brief  Build the name to write the parameter from the extension's
505             ID and the name of this parameter. */
506 gchar *
507 Parameter::pref_name (void)
509     return g_strdup_printf("%s.%s", extension->get_id(), _name);
512 /** \brief  Basically, if there is no widget pass a NULL. */
513 Gtk::Widget *
514 Parameter::get_widget (void)
516     return NULL;
519 /** \brief  If I'm not sure which it is, just don't return a value. */
520 Glib::ustring *
521 Parameter::string (void)
523     Glib::ustring * mystring = new Glib::ustring("");
524     return mystring;
527 /** \brief  A class to make an adjustment that uses Extension params */
528 class ParamFloatAdjustment : public Gtk::Adjustment {
529     /** The parameter to adjust */
530     ParamFloat * _pref;
531 public:
532     /** \brief  Make the adjustment using an extension and the string
533                 describing the parameter. */
534     ParamFloatAdjustment (ParamFloat * param) :
535             Gtk::Adjustment(0.0, param->min(), param->max(), 0.1), _pref(param) {
536         this->set_value(_pref->get(NULL, NULL) /* \todo fix */);
537         this->signal_value_changed().connect(sigc::mem_fun(this, &ParamFloatAdjustment::val_changed));
538         return;
539     };
541     void val_changed (void);
542 }; /* class ParamFloatAdjustment */
544 /** \brief  A function to respond to the value_changed signal from the
545             adjustment.
547     This function just grabs the value from the adjustment and writes
548     it to the parameter.  Very simple, but yet beautiful.
549 */
550 void
551 ParamFloatAdjustment::val_changed (void)
553     // std::cout << "Value Changed to: " << this->get_value() << std::endl;
554     _pref->set(this->get_value(), NULL /* \todo fix */, NULL);
555     return;
558 /** \brief  A class to make an adjustment that uses Extension params */
559 class ParamIntAdjustment : public Gtk::Adjustment {
560     /** The parameter to adjust */
561     ParamInt * _pref;
562 public:
563     /** \brief  Make the adjustment using an extension and the string
564                 describing the parameter. */
565     ParamIntAdjustment (ParamInt * param) :
566             Gtk::Adjustment(0.0, param->min(), param->max(), 1.0), _pref(param) {
567         this->set_value(_pref->get(NULL, NULL) /* \todo fix */);
568         this->signal_value_changed().connect(sigc::mem_fun(this, &ParamIntAdjustment::val_changed));
569         return;
570     };
572     void val_changed (void);
573 }; /* class ParamIntAdjustment */
575 /** \brief  A function to respond to the value_changed signal from the
576             adjustment.
578     This function just grabs the value from the adjustment and writes
579     it to the parameter.  Very simple, but yet beautiful.
580 */
581 void
582 ParamIntAdjustment::val_changed (void)
584     // std::cout << "Value Changed to: " << this->get_value() << std::endl;
585     _pref->set((int)this->get_value(), NULL /* \todo fix */, NULL);
586     return;
589 /**
590     \brief  Creates a Float Adjustment for a float parameter
592     Builds a hbox with a label and a float adjustment in it.
593 */
594 Gtk::Widget *
595 ParamFloat::get_widget (void)
597     Gtk::HBox * hbox = new Gtk::HBox();
599     Gtk::Label * label = new Gtk::Label(_(_text), Gtk::ALIGN_LEFT);
600     label->show();
601     hbox->pack_start(*label, true, true);
603     ParamFloatAdjustment * fadjust = new ParamFloatAdjustment(this);
604     Gtk::SpinButton * spin = new Gtk::SpinButton(*fadjust, 0.1, 1);
605     spin->show();
606     hbox->pack_start(*spin, false, false);
608     hbox->show();
610     return dynamic_cast<Gtk::Widget *>(hbox);
613 /**
614     \brief  Creates a Int Adjustment for a int parameter
616     Builds a hbox with a label and a int adjustment in it.
617 */
618 Gtk::Widget *
619 ParamInt::get_widget (void)
621     Gtk::HBox * hbox = new Gtk::HBox();
623     Gtk::Label * label = new Gtk::Label(_(_text), Gtk::ALIGN_LEFT);
624     label->show();
625     hbox->pack_start(*label, true, true);
627     ParamIntAdjustment * fadjust = new ParamIntAdjustment(this);
628     Gtk::SpinButton * spin = new Gtk::SpinButton(*fadjust, 1.0, 0);
629     spin->show();
630     hbox->pack_start(*spin, false, false);
632     hbox->show();
634     return dynamic_cast<Gtk::Widget *>(hbox);
637 /** \brief  A check button which is Param aware.  It works with the
638             parameter to change it's value as the check button changes
639             value. */
640 class ParamBoolCheckButton : public Gtk::CheckButton {
641 private:
642     /** \brief  Param to change */
643     ParamBool * _pref;
644 public:
645     /** \brief  Initialize the check button
646         \param  param  Which parameter to adjust on changing the check button
648         This function sets the value of the checkbox to be that of the
649         parameter, and then sets up a callback to \c on_toggle.
650     */
651     ParamBoolCheckButton (ParamBool * param) :
652             Gtk::CheckButton(), _pref(param) {
653         this->set_active(_pref->get(NULL, NULL) /**\todo fix */);
654         this->signal_toggled().connect(sigc::mem_fun(this, &ParamBoolCheckButton::on_toggle));
655         return;
656     }
657     void on_toggle (void);
658 };
660 /**
661     \brief  A function to respond to the check box changing
663     Adjusts the value of the preference to match that in the check box.
664 */
665 void
666 ParamBoolCheckButton::on_toggle (void)
668     _pref->set(this->get_active(), NULL /**\todo fix this */, NULL);
669     return;
672 /**
673     \brief  Creates a bool check button for a bool parameter
675     Builds a hbox with a label and a check button in it.
676 */
677 Gtk::Widget *
678 ParamBool::get_widget (void)
680     Gtk::HBox * hbox = new Gtk::HBox();
682     Gtk::Label * label = new Gtk::Label(_(_text), Gtk::ALIGN_LEFT);
683     label->show();
684     hbox->pack_start(*label, true, true);
686     ParamBoolCheckButton * checkbox = new ParamBoolCheckButton(this);
687     checkbox->show();
688     hbox->pack_start(*checkbox, false, false);
690     hbox->show();
692     return dynamic_cast<Gtk::Widget *>(hbox);
695 /** \brief  A special category of Gtk::Entry to handle string parameteres */
696 class ParamStringEntry : public Gtk::Entry {
697 private:
698     ParamString * _pref;
699 public:
700     /** \brief  Build a string preference for the given parameter
701         \param  pref  Where to get the string from, and where to put it
702                       when it changes.
703     */
704     ParamStringEntry (ParamString * pref) :
705         Gtk::Entry(), _pref(pref) {
706         if (_pref->get(NULL, NULL) != NULL)
707             this->set_text(Glib::ustring(_pref->get(NULL, NULL)));
708         this->signal_changed().connect(sigc::mem_fun(this, &ParamStringEntry::changed_text));
709     };
710     void changed_text (void);
711 };
713 /** \brief  Respond to the text box changing
715     This function responds to the box changing by grabbing the value
716     from the text box and putting it in the parameter.
717 */
718 void
719 ParamStringEntry::changed_text (void)
721     Glib::ustring data = this->get_text();
722     _pref->set(data.c_str(), NULL, NULL);
723     return;
726 /**
727     \brief  Creates a text box for the string parameter
729     Builds a hbox with a label and a text box in it.
730 */
731 Gtk::Widget *
732 ParamString::get_widget (void)
734     Gtk::HBox * hbox = new Gtk::HBox();
736     Gtk::Label * label = new Gtk::Label(_(_text), Gtk::ALIGN_LEFT);
737     label->show();
738     hbox->pack_start(*label, true, true);
740     ParamStringEntry * textbox = new ParamStringEntry(this);
741     textbox->show();
742     hbox->pack_start(*textbox, false, false);
744     hbox->show();
746     return dynamic_cast<Gtk::Widget *>(hbox);
749 /** \brief  Return 'true' or 'false' */
750 Glib::ustring *
751 ParamBool::string (void)
753     Glib::ustring * mystring;
755     if (_value)
756         mystring = new Glib::ustring("true");
757     else
758         mystring = new Glib::ustring("false");
760     return mystring;
763 /** \brief  Return the value as a string */
764 Glib::ustring *
765 ParamInt::string (void)
767     char startstring[32];
768     sprintf(startstring, "%d", _value);
769     Glib::ustring * mystring = new Glib::ustring(startstring);
770     return mystring;
773 /** \brief  Return the value as a string */
774 Glib::ustring *
775 ParamFloat::string (void)
777     char startstring[G_ASCII_DTOSTR_BUF_SIZE];
778     g_ascii_dtostr(startstring, G_ASCII_DTOSTR_BUF_SIZE, _value);
779     Glib::ustring * mystring = new Glib::ustring(startstring);
780     return mystring;
783 /** \brief  Return the value as a string */
784 Glib::ustring *
785 ParamString::string (void)
787     Glib::ustring * mystring = new Glib::ustring("");
788     *mystring += "\"";
789     *mystring += _value;
790     *mystring += "\"";
791     return mystring;
795 }  /* namespace Extension */
796 }  /* namespace Inkscape */
798 /*
799   Local Variables:
800   mode:c++
801   c-file-style:"stroustrup"
802   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
803   indent-tabs-mode:nil
804   fill-column:99
805   End:
806 */
807 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :