summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c0cd551)
raw | patch | inline | side by side (parent: c0cd551)
author | johanengelen <johanengelen@users.sourceforge.net> | |
Tue, 15 Jan 2008 16:33:29 +0000 (16:33 +0000) | ||
committer | johanengelen <johanengelen@users.sourceforge.net> | |
Tue, 15 Jan 2008 16:33:29 +0000 (16:33 +0000) |
The *new* RegisteredWidget is a template class and should be subclassed (eventually) from Gtk::Widget, for example RegisteredWidget<Scalar> will be subclassed from Scalar, which is subclassed from Labelled, => Gtk::HBox => Gtk::Widget. This way, a RegisteredWidget<T> can be directly used as Gtk::Widget, and gtk::manage works, etc! This all should solve the problem of having multiple widgets for the same parameters.
index 9ce4e41a935a3d4baf7b4ae4b29efc5ce8d3aba5..850bb1a7584506dde2e0da47d84be6ba72cbd790 100644 (file)
min = -NR_HUGE;
max = NR_HUGE;
integer = false;
- regrandom = NULL;
defseed = default_seed;
startseed = defseed;
RandomParam::~RandomParam()
{
- if (regrandom)
- delete regrandom;
}
bool
startseed = setup_seed(newseed);
seed = startseed;
-
- if (regrandom)
- regrandom->setValue(value, startseed);
}
void
{
this->min = min;
this->max = max;
- if (regrandom)
- regrandom->getR()->setRange(min, max);
-
- param_set_value(value, startseed); // reset value, to check whether it is in range
}
void
RandomParam::param_make_integer(bool yes)
{
integer = yes;
- if (regrandom) {
- regrandom->getR()->setDigits(0);
- regrandom->getR()->setIncrements(1, 10);
- }
}
void
Gtk::Widget *
RandomParam::param_newWidget(Gtk::Tooltips * tooltips)
{
- // WIDGET TODO: This implementation is incorrect, it should create a *new* widget for the caller, not just return an already created widget
- g_warning("RandomParam::param_newWidget still needs recoding to work with multiple document views");
- // TODO: add a button to set a different startseed
- if (!regrandom) {
- regrandom = new Inkscape::UI::Widget::RegisteredRandom();
- regrandom->init(param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc());
- regrandom->setValue(value, startseed);
- if (integer)
- param_make_integer();
-
- regrandom->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change random parameter"));
+ Inkscape::UI::Widget::RegisteredRandom* regrandom = Gtk::manage(
+ new Inkscape::UI::Widget::RegisteredRandom( param_label,
+ param_tooltip,
+ param_key,
+ *param_wr,
+ param_effect->getRepr(),
+ param_effect->getSPDoc() ) );
+
+ regrandom->setValue(value, startseed);
+ if (integer) {
+ regrandom->setDigits(0);
+ regrandom->setIncrements(1, 10);
}
- return dynamic_cast<Gtk::Widget *> (regrandom->getR());
+ regrandom->setRange(min, max);
+
+ regrandom->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change random parameter"));
+
+ return dynamic_cast<Gtk::Widget *> (regrandom);
}
RandomParam::operator gdouble()
index 1b7d4cf16d3f248ea14222640525a7e027423315..6583ca55624d86a4097b11e3c186ba56959fe4ed 100644 (file)
#include <2geom/path.h>
#include "ui/widget/registry.h"
-#include "ui/widget/registered-widget.h"
namespace Inkscape {
bool integer;
gdouble defvalue;
- Inkscape::UI::Widget::RegisteredRandom * regrandom;
-
private:
long setup_seed(long);
gdouble rand();
index 0a17aeca369936230a335e657dc5a50bb33afef8..e3c72e821d3e9b1a6bd696590b5d7080cde15fc1 100644 (file)
namespace UI {
namespace Widget {
-template<typename E> class RegisteredEnum : public RegisteredWidget
+template<typename E> class RegisteredEnum : public RegisteredWdg
{
public:
RegisteredEnum() {
index 1364e5a2aa161131e0f8c01df745e835fddb16a1..a54c89292e17ead789cc6aedddf67e282ce8094b 100644 (file)
# include <config.h>
#endif
+#include "registered-widget.h"
#include "ui/widget/color-picker.h"
#include "ui/widget/registry.h"
#include "desktop-handles.h"
#include "sp-namedview.h"
-#include "registered-widget.h"
#include "verbs.h"
// for interruptability bug:
//---------------------------------------------------
+
+template<class W>
+void RegisteredWidget<W>::write_to_xml(const char * svgstr)
+{
+ // Use local repr here. When repr is specified, use that one, but
+ // if repr==NULL, get the repr of namedview of active desktop.
+ Inkscape::XML::Node *local_repr = repr;
+ SPDocument *local_doc = doc;
+ if (!local_repr) {
+ // no repr specified, use active desktop's namedview's repr
+ SPDesktop* dt = SP_ACTIVE_DESKTOP;
+ local_repr = SP_OBJECT_REPR (sp_desktop_namedview(dt));
+ local_doc = sp_desktop_document(dt);
+ }
+
+ bool saved = sp_document_get_undo_sensitive (local_doc);
+ sp_document_set_undo_sensitive (local_doc, false);
+ if (!write_undo) local_repr->setAttribute(_key.c_str(), svgstr);
+ sp_document_set_undo_sensitive (local_doc, saved);
+
+ local_doc->setModifiedSinceSave();
+ if (write_undo) {
+ local_repr->setAttribute(_key.c_str(), svgstr);
+ sp_document_done (local_doc, event_type, event_description);
+ }
+}
+
void
-RegisteredWidget::write_to_xml(const char * svgstr)
+RegisteredWdg::write_to_xml(const char * svgstr)
{
// Use local repr here. When repr is specified, use that one, but
// if repr==NULL, get the repr of namedview of active desktop.
* Registered RANDOM
*/
-RegisteredRandom::RegisteredRandom()
-{
- _widget = NULL;
-}
-
RegisteredRandom::~RegisteredRandom()
{
- if (_widget)
- delete _widget;
-
_value_changed_connection.disconnect();
_reseeded_connection.disconnect();
}
-void
-RegisteredRandom::init ( const Glib::ustring& label, const Glib::ustring& tip,
+RegisteredRandom::RegisteredRandom ( const Glib::ustring& label, const Glib::ustring& tip,
const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in,
SPDocument * doc_in )
+ : RegisteredWidget<Random> (label, tip)
{
init_parent(key, wr, repr_in, doc_in);
- _widget = new Random (label, tip);
- _widget->setRange (-1e6, 1e6);
- _widget->setDigits (2);
- _widget->setIncrements(0.1, 1.0);
- _value_changed_connection = _widget->signal_value_changed().connect (sigc::mem_fun (*this, &RegisteredRandom::on_value_changed));
- _reseeded_connection = _widget->signal_reseeded.connect(sigc::mem_fun(*this, &RegisteredRandom::on_value_changed));
-}
-
-Random*
-RegisteredRandom::getR()
-{
- return _widget;
+ setRange (-1e6, 1e6);
+ setDigits (2);
+ setIncrements(0.1, 1.0);
+ _value_changed_connection = signal_value_changed().connect (sigc::mem_fun (*this, &RegisteredRandom::on_value_changed));
+ _reseeded_connection = signal_reseeded.connect(sigc::mem_fun(*this, &RegisteredRandom::on_value_changed));
}
void
RegisteredRandom::setValue (double val, long startseed)
{
- if (!_widget)
- return;
-
- _widget->setValue (val);
- _widget->setStartSeed(startseed);
+ static_cast<Scalar*>(this)->setValue (val);
+ setStartSeed(startseed);
}
void
RegisteredRandom::on_value_changed()
{
- if (_widget->setProgrammatically) {
- _widget->setProgrammatically = false;
+ if (setProgrammatically) {
+ setProgrammatically = false;
return;
}
_wr->setUpdating (true);
Inkscape::SVGOStringStream os;
- os << _widget->getValue() << ';' << _widget->getStartSeed();
+ os << getValue() << ';' << getStartSeed();
- _widget->set_sensitive(false);
+ set_sensitive(false);
write_to_xml(os.str().c_str());
- _widget->set_sensitive(true);
+ set_sensitive(true);
_wr->setUpdating (false);
}
-
} // namespace Dialog
} // namespace UI
} // namespace Inkscape
index 90fb449831ac3c4c4cd74c9081750720a6f5b01c..1a55014270228019a12c4bd94e2b9e3a7dc798bf 100644 (file)
#include "xml/node.h"
#include "registry.h"
+#include "ui/widget/random.h"
+
class SPUnit;
class SPDocument;
class ScalarUnit;
class UnitMenu;
class Point;
-class Random;
-class RegisteredWidget {
+template <class W>
+class RegisteredWidget : public W {
+public:
+ void set_undo_parameters(const unsigned int _event_type, Glib::ustring _event_description)
+ {
+ event_type = _event_type;
+ event_description = _event_description;
+ write_undo = true;
+ }
+
+ bool is_updating() {if (_wr) return _wr->isUpdating(); else return false;}
+
+protected:
+ RegisteredWidget() : W() { construct(); }
+ template< typename A >
+ explicit RegisteredWidget( A& a ): W( a ) { construct(); }
+ template< typename A, typename B >
+ RegisteredWidget( A& a, B& b ): W( a, b ) { construct(); }
+ template< typename A, typename B, typename C >
+ RegisteredWidget( A& a, B& b, C& c ): W( a, b, c ) { construct(); }
+
+ virtual ~RegisteredWidget() {};
+
+ void init_parent(const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument *doc_in)
+ {
+ _wr = ≀
+ _key = key;
+ repr = repr_in;
+ doc = doc_in;
+ if (repr && !doc) // doc cannot be NULL when repr is not NULL
+ g_warning("Initialization of registered widget using defined repr but with doc==NULL");
+ }
+
+ void write_to_xml(const char * svgstr);
+
+ Registry * _wr;
+ Glib::ustring _key;
+ Inkscape::XML::Node * repr;
+ SPDocument * doc;
+ unsigned int event_type;
+ Glib::ustring event_description;
+ bool write_undo;
+
+private:
+ void construct() {
+ _wr = NULL;
+ repr = NULL;
+ doc = NULL;
+ write_undo = false;
+ }
+};
+
+class RegisteredWdg {
public:
void set_undo_parameters(const unsigned int _event_type, Glib::ustring _event_description)
{
bool is_updating() {if (_wr) return _wr->isUpdating(); else return false;}
protected:
- RegisteredWidget()
+ RegisteredWdg()
{
_wr = NULL;
repr = NULL;
//#######################################################
-class RegisteredCheckButton : public RegisteredWidget {
+class RegisteredCheckButton : public RegisteredWdg {
public:
RegisteredCheckButton();
~RegisteredCheckButton();
void on_toggled();
};
-class RegisteredUnitMenu : public RegisteredWidget {
+class RegisteredUnitMenu : public RegisteredWdg {
public:
RegisteredUnitMenu();
~RegisteredUnitMenu();
void on_changed();
};
-class RegisteredScalarUnit : public RegisteredWidget {
+class RegisteredScalarUnit : public RegisteredWdg {
public:
RegisteredScalarUnit();
~RegisteredScalarUnit();
void on_value_changed();
};
-class RegisteredScalar : public RegisteredWidget {
+class RegisteredScalar : public RegisteredWdg {
public:
RegisteredScalar();
~RegisteredScalar();
void on_value_changed();
};
-class RegisteredColorPicker : public RegisteredWidget {
+class RegisteredColorPicker : public RegisteredWdg {
public:
RegisteredColorPicker();
~RegisteredColorPicker();
sigc::connection _changed_connection;
};
-class RegisteredSuffixedInteger : public RegisteredWidget {
+class RegisteredSuffixedInteger : public RegisteredWdg {
public:
RegisteredSuffixedInteger();
~RegisteredSuffixedInteger();
void on_value_changed();
};
-class RegisteredRadioButtonPair : public RegisteredWidget {
+class RegisteredRadioButtonPair : public RegisteredWdg {
public:
RegisteredRadioButtonPair();
~RegisteredRadioButtonPair();
void on_value_changed();
};
-class RegisteredPoint : public RegisteredWidget {
+class RegisteredPoint : public RegisteredWdg {
public:
RegisteredPoint();
~RegisteredPoint();
void on_value_changed();
};
-class RegisteredRandom : public RegisteredWidget {
+
+class RegisteredRandom : public RegisteredWidget<Random> {
public:
- RegisteredRandom();
- ~RegisteredRandom();
- void init (const Glib::ustring& label,
- const Glib::ustring& tip,
- const Glib::ustring& key,
- Registry& wr,
- Inkscape::XML::Node* repr_in,
- SPDocument *doc_in);
- inline void init ( const Glib::ustring& label,
+ virtual ~RegisteredRandom();
+ RegisteredRandom ( const Glib::ustring& label,
const Glib::ustring& tip,
const Glib::ustring& key,
- Registry& wr)
- { init(label, tip, key, wr, NULL, NULL); };
+ Registry& wr,
+ Inkscape::XML::Node* repr_in = NULL,
+ SPDocument *doc_in = NULL);
- Random* getR();
void setValue (double val, long startseed);
protected:
- Random *_widget;
sigc::connection _value_changed_connection;
sigc::connection _reseeded_connection;
void on_value_changed();