diff options
| author | Ted Gould <ted@gould.cx> | 2008-04-04 04:55:24 +0000 |
|---|---|---|
| committer | gouldtj <gouldtj@users.sourceforge.net> | 2008-04-04 04:55:24 +0000 |
| commit | 8a2ba4f29d0304fef7631e0efec8b10a2dc99121 (patch) | |
| tree | 0eb2b0987084a55191da506c6c7e870bbe2d903d /src/extension/paramradiobutton.cpp | |
| parent | * packaging/macosx/ScriptExec/main.c: Add a comment to clarify what looks (diff) | |
| download | inkscape-8a2ba4f29d0304fef7631e0efec8b10a2dc99121.tar.gz inkscape-8a2ba4f29d0304fef7631e0efec8b10a2dc99121.zip | |
r18381@shi: ted | 2008-03-07 20:11:34 -0800
New work branch
r18391@shi: ted | 2008-03-08 21:36:03 -0800
Moving the parameters around to clean up the directories.
r18392@shi: ted | 2008-03-08 21:57:14 -0800
Moving the 'get' function to cpp
r18870@shi: ted | 2008-04-03 21:10:20 -0700
Adding in to the parameter prototype the ability to have a gui-tip and a gui-hidden parameter
r18871@shi: ted | 2008-04-03 21:17:39 -0700
Using the _gui-hidden parameter to block the creation of the widget if set.
r18890@shi: ted | 2008-04-03 21:53:55 -0700
Merge from r18024 which got lost in the shuffle.
(bzr r5322)
Diffstat (limited to 'src/extension/paramradiobutton.cpp')
| -rw-r--r-- | src/extension/paramradiobutton.cpp | 269 |
1 files changed, 0 insertions, 269 deletions
diff --git a/src/extension/paramradiobutton.cpp b/src/extension/paramradiobutton.cpp deleted file mode 100644 index 5fce66910..000000000 --- a/src/extension/paramradiobutton.cpp +++ /dev/null @@ -1,269 +0,0 @@ -/** \file - * extension parameter for radiobuttons. - * - * It uses a Gtk:ComboBoxText widget in the extension UI. - */ - -/* - * Author: - * Johan Engelen <johan@shouraizou.nl> - * - * Copyright (C) 2006-2007 Johan Engelen - * - * 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 { - -/* For internal use only. - Note that value and guitext MUST be non-NULL. This is ensured by newing only at one location in the code where non-NULL checks are made. */ -class optionentry { -public: - optionentry (Glib::ustring * val, Glib::ustring * text) { - value = val; - guitext = text; - } - ~optionentry() { - delete value; - delete guitext; - } - - Glib::ustring * value; - Glib::ustring * guitext; -}; - -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, "option") || !strcmp(chname, "_option")) { - Glib::ustring * newguitext = NULL; - Glib::ustring * newvalue = NULL; - const char * contents = sp_repr_children(child_repr)->content(); - if (contents != NULL) - // don't translate when 'option' but do translate when '_option' - newguitext = new Glib::ustring( !strcmp(chname, "_option") ? _(contents) : contents ); - else - continue; - - const char * val = child_repr->attribute("value"); - if (val != NULL) - newvalue = new Glib::ustring(val); - else - newvalue = new Glib::ustring(contents); - - if ( (newguitext) && (newvalue) ) { // logical error if this is not true here - choices = g_slist_append( choices, new optionentry(newvalue, newguitext) ); - } - } - 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 (choices) - defaultval = ((optionentry*) choices->data)->value->c_str(); - - 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)) { - delete (reinterpret_cast<optionentry *>(list->data)); - } - 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 */ - - Glib::ustring * settext = NULL; - for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { - optionentry * entr = reinterpret_cast<optionentry *>(list->data); - if ( !entr->guitext->compare(in) ) { - settext = entr->value; - break; // break out of for loop - } - } - if (settext) { - if (_value != NULL) g_free(_value); - _value = g_strdup(settext->c_str()); - 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 -*/ -void -ParamRadioButton::string (std::string &string) -{ - string += _value; - return; -} - -/** \brief A special radiobutton class to use in ParamRadioButton */ -class ParamRadioButtonWdg : public Gtk::RadioButton { -private: - ParamRadioButton * _pref; - SPDocument * _doc; - Inkscape::XML::Node * _node; - sigc::signal<void> * _changeSignal; -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, sigc::signal<void> * changeSignal ) : - Gtk::RadioButton(group, label), _pref(pref), _doc(doc), _node(node), _changeSignal(changeSignal) { - add_changesignal(); - }; - ParamRadioButtonWdg ( const Glib::ustring& label, - ParamRadioButton * pref, SPDocument * doc, Inkscape::XML::Node * node , sigc::signal<void> * changeSignal) : - Gtk::RadioButton(label), _pref(pref), _doc(doc), _node(node), _changeSignal(changeSignal) { - 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(); - _pref->set(data.c_str(), _doc, _node); - } - if (_changeSignal != NULL) { - _changeSignal->emit(); - } -} - - - -/** - \brief Creates a combobox widget for an enumeration parameter -*/ -Gtk::Widget * -ParamRadioButton::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) -{ - 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)) { - optionentry * entr = reinterpret_cast<optionentry *>(list->data); - Glib::ustring * text = entr->guitext; - if (first) { - radio = Gtk::manage(new ParamRadioButtonWdg(*text, this, doc, node, changeSignal)); - group = radio->get_group(); - first = false; - } else { - radio = Gtk::manage(new ParamRadioButtonWdg(group, *text, this, doc, node, changeSignal)); - } - radio->show(); - vbox->pack_start(*radio, true, true); - if (!entr->value->compare(_value)) { - radio->set_active(); - } - } - - vbox->show(); - hbox->pack_end(*vbox, false, false); - hbox->show(); - - - return dynamic_cast<Gtk::Widget *>(hbox); -} - - -} /* namespace Extension */ -} /* namespace Inkscape */ - |
