diff options
| author | Johan B. C. Engelen <jbc.engelen@swissonline.ch> | 2006-11-24 21:17:33 +0000 |
|---|---|---|
| committer | johanengelen <johanengelen@users.sourceforge.net> | 2006-11-24 21:17:33 +0000 |
| commit | 33db5c037b8f71858e03f585af059982178c8c86 (patch) | |
| tree | 05c5de14eee55b91f2592520bc2313d8752dc87b /src | |
| parent | Add "strip" to <link> so you can do it if linking is successful (diff) | |
| download | inkscape-33db5c037b8f71858e03f585af059982178c8c86.tar.gz inkscape-33db5c037b8f71858e03f585af059982178c8c86.zip | |
NEW: radiobuttons for extensions. See radiobutton_example.inx how to use them (they are very similar to enums)
(bzr r2031)
Diffstat (limited to 'src')
| -rw-r--r-- | src/extension/Makefile_insert | 2 | ||||
| -rw-r--r-- | src/extension/paramenum.cpp | 14 | ||||
| -rw-r--r-- | src/extension/parameter.cpp | 3 | ||||
| -rw-r--r-- | src/extension/paramradiobutton.cpp | 232 | ||||
| -rw-r--r-- | src/extension/paramradiobutton.h | 57 |
5 files changed, 296 insertions, 12 deletions
diff --git a/src/extension/Makefile_insert b/src/extension/Makefile_insert index 9540d863d..1eaa7ce5d 100644 --- a/src/extension/Makefile_insert +++ b/src/extension/Makefile_insert @@ -23,6 +23,8 @@ extension_libextension_a_SOURCES = \ extension/paramnotebook.cpp \ extension/paramenum.h \ extension/paramenum.cpp \ + extension/paramradiobutton.h \ + extension/paramradiobutton.cpp \ extension/prefdialog.cpp \ extension/prefdialog.h \ extension/system.cpp \ diff --git a/src/extension/paramenum.cpp b/src/extension/paramenum.cpp index 85656343d..849447427 100644 --- a/src/extension/paramenum.cpp +++ b/src/extension/paramenum.cpp @@ -126,8 +126,8 @@ ParamComboBox::set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * no /**
- \brief A function to get the currentpage and the parameters in a string form
- \return A string with the 'value' and all the parameters on all pages as command line arguments
+ \brief A function to get the value of the parameter in string form
+ \return A string with the 'value' as command line argument
*/
Glib::ustring *
ParamComboBox::string (void)
@@ -206,13 +206,3 @@ ParamComboBox::get_widget (SPDocument * doc, Inkscape::XML::Node * node) } /* namespace Extension */
} /* namespace Inkscape */
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
diff --git a/src/extension/parameter.cpp b/src/extension/parameter.cpp index 70f66c416..7dba1b507 100644 --- a/src/extension/parameter.cpp +++ b/src/extension/parameter.cpp @@ -33,6 +33,7 @@ #include "parameter.h" #include "paramnotebook.h" #include "paramenum.h" +#include "paramradiobutton.h" /** \brief The root directory in the preferences database for extension related parameters. */ @@ -316,6 +317,8 @@ Parameter::make (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * param = new ParamComboBox(name, guitext, desc, scope, in_ext, in_repr); } else if (!strcmp(type, "notebook")) { param = new ParamNotebook(name, guitext, desc, scope, in_ext, in_repr); + } else if (!strcmp(type, "optiongroup")) { + param = new ParamRadioButton(name, guitext, desc, scope, in_ext, in_repr); } /* Note: param could equal NULL */ diff --git a/src/extension/paramradiobutton.cpp b/src/extension/paramradiobutton.cpp new file mode 100644 index 000000000..80ec50521 --- /dev/null +++ b/src/extension/paramradiobutton.cpp @@ -0,0 +1,232 @@ +/** \file
+ * extension parameter for radiobuttons.
+ *
+ * It uses a Gtk:ComboBoxText widget in the extension UI.
+ */
+
+/*
+ * Author:
+ * Johan Engelen <johan@shouraizou.nl>
+ *
+ * Copyright (C) 2006 Author
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+
+#include <gtkmm/box.h>
+#include <gtkmm/radiobutton.h>
+#include <gtkmm/radiobuttongroup.h>
+#include <gtkmm/tooltips.h>
+#include <gtkmm/label.h>
+
+#include <glibmm/i18n.h>
+
+#include <xml/node.h>
+
+#include "extension.h"
+#include "prefs-utils.h"
+#include "document-private.h"
+#include "sp-object.h"
+
+#include "paramradiobutton.h"
+
+/** \brief The root directory in the preferences database for extension
+ related parameters. */
+#define PREF_DIR "extensions"
+
+namespace Inkscape {
+namespace Extension {
+
+ParamRadioButton::ParamRadioButton (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) :
+ Parameter(name, guitext, desc, scope, ext)
+{
+ choices = NULL;
+ _value = NULL;
+
+ // Read XML tree to add enumeration items:
+ // printf("Extension Constructor: ");
+ if (xml != NULL) {
+ Inkscape::XML::Node *child_repr = sp_repr_children(xml);
+ while (child_repr != NULL) {
+ char const * chname = child_repr->name();
+ if (!strcmp(chname, "item")) {
+ Glib::ustring * newitem = NULL;
+ const char * contents = sp_repr_children(child_repr)->content();
+ if (contents != NULL)
+ newitem = new Glib::ustring(contents);
+ if (newitem != NULL) choices = g_slist_append(choices, newitem);
+ }
+ child_repr = sp_repr_next(child_repr);
+ }
+ }
+
+ // Initialize _value with the default value from xml
+ // for simplicity : default to the contents of the first xml-child
+ const char * defaultval = NULL;
+ if (sp_repr_children(sp_repr_children(xml)) != NULL)
+ defaultval = sp_repr_children(sp_repr_children(xml))->content();
+
+ gchar * pref_name = this->pref_name();
+ const gchar * paramval = prefs_get_string_attribute(PREF_DIR, pref_name);
+ g_free(pref_name);
+
+ if (paramval != NULL)
+ defaultval = paramval;
+ if (defaultval != NULL)
+ _value = g_strdup(defaultval); // allocate space for _value
+
+ return;
+}
+
+ParamRadioButton::~ParamRadioButton (void)
+{
+ //destroy choice strings
+ for (GSList * list = choices; list != NULL; list = g_slist_next(list)) {
+ Glib::ustring * text = reinterpret_cast<Glib::ustring *>(list->data);
+ delete text;
+ }
+ g_slist_free(choices);
+
+ g_free(_value);
+}
+
+
+/** \brief A function to set the \c _value
+ \param in The value to set
+ \param doc A document that should be used to set the value.
+ \param node The node where the value may be placed
+
+ This function sets ONLY the internal value, but it also sets the value
+ in the preferences structure. To put it in the right place, \c PREF_DIR
+ and \c pref_name() are used.
+
+ To copy the data into _value the old memory must be free'd first.
+ It is important to note that \c g_free handles \c NULL just fine. Then
+ the passed in value is duplicated using \c g_strdup().
+*/
+const gchar *
+ParamRadioButton::set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node)
+{
+ if (in == NULL) return NULL; /* Can't have NULL string */
+
+ if (_value != NULL)
+ g_free(_value);
+ _value = g_strdup(in);
+
+ gchar * prefname = this->pref_name();
+ prefs_set_string_attribute(PREF_DIR, prefname, _value);
+ g_free(prefname);
+
+ return _value;
+}
+
+
+/**
+ \brief A function to get the current value of the parameter in a string form
+ \return A string with the 'value' as command line argument
+*/
+Glib::ustring *
+ParamRadioButton::string (void)
+{
+ Glib::ustring * param_string = new Glib::ustring("");
+
+ *param_string += "\"";
+ *param_string += _value;
+ *param_string += "\"";
+
+ return param_string;
+}
+
+/** \brief A special radiobutton class to use in ParamRadioButton */
+class ParamRadioButtonWdg : public Gtk::RadioButton {
+private:
+ ParamRadioButton * _pref;
+ SPDocument * _doc;
+ Inkscape::XML::Node * _node;
+public:
+ /** \brief Build a string preference for the given parameter
+ \param pref Where to put the radiobutton's string when it is selected.
+ */
+ ParamRadioButtonWdg ( Gtk::RadioButtonGroup& group, const Glib::ustring& label,
+ ParamRadioButton * pref, SPDocument * doc, Inkscape::XML::Node * node ) :
+ Gtk::RadioButton(group, label), _pref(pref), _doc(doc), _node(node) {
+ add_changesignal();
+ };
+ ParamRadioButtonWdg ( const Glib::ustring& label,
+ ParamRadioButton * pref, SPDocument * doc, Inkscape::XML::Node * node ) :
+ Gtk::RadioButton(label), _pref(pref), _doc(doc), _node(node) {
+ add_changesignal();
+ };
+ void add_changesignal() {
+ this->signal_toggled().connect(sigc::mem_fun(this, &ParamRadioButtonWdg::changed));
+ };
+ void changed (void);
+};
+
+/** \brief Respond to the selected radiobutton changing
+
+ This function responds to the radiobutton selection changing by grabbing the value
+ from the text box and putting it in the parameter.
+*/
+void
+ParamRadioButtonWdg::changed (void)
+{
+ if (this->get_active()) {
+ Glib::ustring data = this->get_label();
+ g_message(data.c_str());
+ _pref->set(data.c_str(), _doc, _node);
+ }
+}
+
+
+
+/**
+ \brief Creates a combobox widget for an enumeration parameter
+*/
+Gtk::Widget *
+ParamRadioButton::get_widget (SPDocument * doc, Inkscape::XML::Node * node)
+{
+ Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4));
+ Gtk::VBox * vbox = Gtk::manage(new Gtk::VBox(false, 0));
+
+ Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT, Gtk::ALIGN_TOP));
+ label->show();
+ hbox->pack_start(*label, false, false);
+
+ // add choice strings as radiobuttons
+ // and select last selected option (_value)
+ bool first = true;
+ ParamRadioButtonWdg * radio;
+ Gtk::RadioButtonGroup group;
+ for (GSList * list = choices; list != NULL; list = g_slist_next(list)) {
+ Glib::ustring * text = reinterpret_cast<Glib::ustring *>(list->data);
+ if (first) {
+ radio = Gtk::manage(new ParamRadioButtonWdg(*text, this, doc, node));
+ group = radio->get_group();
+ first = false;
+ } else {
+ radio = Gtk::manage(new ParamRadioButtonWdg(group, *text, this, doc, node));
+ }
+ radio->show();
+ vbox->pack_start(*radio, true, true);
+ if (!strcmp(text->c_str(), _value)) {
+ radio->set_active();
+ }
+ }
+ vbox->show();
+ hbox->pack_end(*vbox, false, false);
+ hbox->show();
+
+
+ return dynamic_cast<Gtk::Widget *>(hbox);
+}
+
+
+} /* namespace Extension */
+} /* namespace Inkscape */
+
diff --git a/src/extension/paramradiobutton.h b/src/extension/paramradiobutton.h new file mode 100644 index 000000000..bf0cd2143 --- /dev/null +++ b/src/extension/paramradiobutton.h @@ -0,0 +1,57 @@ +#ifndef __INK_EXTENSION_PARAMRADIOBUTTON_H__
+#define __INK_EXTENSION_PARAMRADIOBUTTON_H__
+
+/** \file
+ * Radiobutton parameter for extensions.
+ */
+
+/*
+ * Author:
+ * Johan Engelen <johan@shouraizou.nl>
+ *
+ * Copyright (C) 2006 Author
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include <gtkmm/widget.h>
+
+#include "xml/document.h"
+#include "extension-forward.h"
+
+#include "parameter.h"
+
+namespace Inkscape {
+namespace Extension {
+
+
+
+// \brief A class to represent a radiobutton parameter of an extension
+class ParamRadioButton : public Parameter {
+private:
+ /** \brief Internal value. This should point to a string that has
+ been allocated in memory. And should be free'd.
+ It is the value of the current selected string */
+ gchar * _value;
+
+ GSList * choices; /**< A table to store the choice strings */
+
+public:
+ ParamRadioButton(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml);
+ ~ParamRadioButton(void);
+ Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node);
+ Glib::ustring * string (void);
+
+ const gchar * get (const SPDocument * doc, const Inkscape::XML::Node * node) { return _value; }
+ const gchar * set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node);
+}; /* class ParamRadioButton */
+
+
+
+
+
+} /* namespace Extension */
+} /* namespace Inkscape */
+
+#endif /* __INK_EXTENSION_PARAMRADIOBUTTON_H__ */
+
|
