From: johanengelen Date: Wed, 16 Jan 2008 20:12:15 +0000 (+0000) Subject: RegisteredEnum is now subclassed from RegisteredWidget instead of old RegisteredWdg X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=fd5e7b511a23f6228ce4cd3ef54795664811e615;p=inkscape.git RegisteredEnum is now subclassed from RegisteredWidget instead of old RegisteredWdg --- diff --git a/src/live_effects/lpe-curvestitch.cpp b/src/live_effects/lpe-curvestitch.cpp index 19513f531..de7d5ce7c 100644 --- a/src/live_effects/lpe-curvestitch.cpp +++ b/src/live_effects/lpe-curvestitch.cpp @@ -114,7 +114,7 @@ LPECurveStitch::doEffect_path (std::vector & path_in) transform.setTranslation( start ); Piecewise > pwd2_out = (strokepath-stroke_origin) * transform; // add stuff to one big pw > and then outside the loop convert to path? - std::vector result = Geom::path_from_piecewise(pwd2_out, LPE_CONVERSION_TOLERANCE); + std::vector result = Geom::path_from_piecewise(pwd2_out, LPE_CONVERSION_TOLERANCE); path_out[i] = result[0]; gdouble sv = spacing_variation; tA += incrementA * (1 + sv - spacing_variation.get_value()/2); @@ -140,7 +140,7 @@ LPECurveStitch::resetDefaults(SPItem * item) // set the stroke path to run horizontally in the middle of the bounding box of the original path Piecewise > pwd2; - std::vector temppath = SVGD_to_2GeomPath( SP_OBJECT_REPR(item)->attribute("inkscape:original-d")); + std::vector temppath = SVGD_to_2GeomPath( SP_OBJECT_REPR(item)->attribute("inkscape:original-d")); for (unsigned int i=0; i < temppath.size(); i++) { pwd2.concat( temppath[i].toPwSb() ); } diff --git a/src/live_effects/lpe-pathalongpath.cpp b/src/live_effects/lpe-pathalongpath.cpp index ef6373274..b3d0fdd4c 100644 --- a/src/live_effects/lpe-pathalongpath.cpp +++ b/src/live_effects/lpe-pathalongpath.cpp @@ -179,7 +179,7 @@ LPEPathAlongPath::resetDefaults(SPItem * item) // set the bend path to run horizontally in the middle of the bounding box of the original path Piecewise > pwd2; - std::vector temppath = SVGD_to_2GeomPath( SP_OBJECT_REPR(item)->attribute("inkscape:original-d")); + std::vector temppath = SVGD_to_2GeomPath( SP_OBJECT_REPR(item)->attribute("inkscape:original-d")); for (unsigned int i=0; i < temppath.size(); i++) { pwd2.concat( temppath[i].toPwSb() ); } diff --git a/src/live_effects/parameter/enum.h b/src/live_effects/parameter/enum.h index f0f3b59f8..1778af8f1 100644 --- a/src/live_effects/parameter/enum.h +++ b/src/live_effects/parameter/enum.h @@ -33,26 +33,22 @@ public: E default_value) : Parameter(label, tip, key, wr, effect) { - regenum = NULL; enumdataconv = &c; defvalue = default_value; value = defvalue; }; - virtual ~EnumParam() { - if (regenum) - delete regenum; - }; + + virtual ~EnumParam() { }; virtual Gtk::Widget * 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("EnumParam::param_newWidget still needs recoding to work with multiple document views"); - if (!regenum) { - regenum = new Inkscape::UI::Widget::RegisteredEnum(); - regenum->init(param_label, param_tooltip, param_key, *enumdataconv, *param_wr, param_effect->getRepr(), param_effect->getSPDoc()); - regenum->combobox()->set_active_by_id(value); - regenum->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change enum parameter")); - } - return dynamic_cast (regenum->labelled); + Inkscape::UI::Widget::RegisteredEnum *regenum = Gtk::manage ( + new Inkscape::UI::Widget::RegisteredEnum( param_label, param_tooltip, + param_key, *enumdataconv, *param_wr, param_effect->getRepr(), param_effect->getSPDoc() ) ); + + regenum->set_active_by_id(value); + regenum->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change enum parameter")); + + return dynamic_cast (regenum); }; bool param_readSVGValue(const gchar * strvalue) { @@ -80,15 +76,12 @@ public: void param_set_value(E val) { value = val; - if (regenum) - regenum->combobox()->set_active_by_id(value); } private: EnumParam(const EnumParam&); EnumParam& operator=(const EnumParam&); - UI::Widget::RegisteredEnum * regenum; E value; E defvalue; diff --git a/src/ui/widget/registered-enums.h b/src/ui/widget/registered-enums.h index e3c72e821..739745817 100644 --- a/src/ui/widget/registered-enums.h +++ b/src/ui/widget/registered-enums.h @@ -19,70 +19,43 @@ namespace Inkscape { namespace UI { namespace Widget { -template class RegisteredEnum : public RegisteredWdg +template class RegisteredEnum : public RegisteredWidget< LabelledComboBoxEnum > { public: - RegisteredEnum() { - labelled = NULL; - } - - ~RegisteredEnum() { + virtual ~RegisteredEnum() { _changed_connection.disconnect(); - if (labelled) - delete labelled; } - void init ( const Glib::ustring& label, + RegisteredEnum ( const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, const Util::EnumDataConverter& c, Registry& wr, - Inkscape::XML::Node* repr_in, - SPDocument *doc_in) + Inkscape::XML::Node* repr_in = NULL, + SPDocument *doc_in = NULL ) + : RegisteredWidget< LabelledComboBoxEnum >(label, tip, c) { - init_parent(key, wr, repr_in, doc_in); - - labelled = new LabelledComboBoxEnum (label, tip, c); + RegisteredWidget< LabelledComboBoxEnum >::init_parent(key, wr, repr_in, doc_in); _changed_connection = combobox()->signal_changed().connect (sigc::mem_fun (*this, &RegisteredEnum::on_changed)); } - inline void init ( const Glib::ustring& label, - const Glib::ustring& key, - Registry& wr) - { - init(label, key, wr, NULL, NULL); - } - void set_active_by_id (E id) { - ComboBoxEnum * cb = combobox(); - if (cb) - cb->set_active_by_id(id); + combobox()->set_active_by_id(id); }; void set_active_by_key (const Glib::ustring& key) { - ComboBoxEnum * cb = combobox(); - if (cb) - cb->set_active_by_key(key); + combobox()->set_active_by_key(key); } inline const Util::EnumData* get_active_data() { - ComboBoxEnum * cb = combobox(); - if (cb) - return cb->get_active_data(); - else - return NULL; + combobox()->get_active_data(); } ComboBoxEnum * combobox() { - if (labelled) { - return labelled->getCombobox(); - } else { - return NULL; - } + return LabelledComboBoxEnum::getCombobox(); } - LabelledComboBoxEnum * labelled; sigc::connection _changed_connection; protected: @@ -92,16 +65,17 @@ protected: return; } - if (_wr->isUpdating()) + if (RegisteredWidget< LabelledComboBoxEnum >::_wr->isUpdating()) return; - _wr->setUpdating (true); + + RegisteredWidget< LabelledComboBoxEnum >::_wr->setUpdating (true); const Util::EnumData* data = combobox()->get_active_data(); if (data) { - write_to_xml(data->key.c_str()); + RegisteredWidget< LabelledComboBoxEnum >::write_to_xml(data->key.c_str()); } - _wr->setUpdating (false); + RegisteredWidget< LabelledComboBoxEnum >::_wr->setUpdating (false); } }; diff --git a/src/ui/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp index dfa42107e..f471dc40d 100644 --- a/src/ui/widget/registered-widget.cpp +++ b/src/ui/widget/registered-widget.cpp @@ -32,11 +32,6 @@ #include "svg/svg-color.h" #include "svg/stringstream.h" -#include "inkscape.h" -#include "document.h" -#include "desktop-handles.h" -#include "sp-namedview.h" - #include "verbs.h" // for interruptability bug: @@ -48,37 +43,6 @@ namespace Widget { //=================================================== -//--------------------------------------------------- - - - -template -void RegisteredWidget::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 RegisteredWdg::write_to_xml(const char * svgstr) { diff --git a/src/ui/widget/registered-widget.h b/src/ui/widget/registered-widget.h index 9a0ba46fc..900eaafbb 100644 --- a/src/ui/widget/registered-widget.h +++ b/src/ui/widget/registered-widget.h @@ -23,6 +23,11 @@ #include "ui/widget/point.h" #include "ui/widget/random.h" +#include "inkscape.h" + +#include "document.h" +#include "desktop-handles.h" +#include "sp-namedview.h" class SPUnit; class SPDocument; @@ -79,7 +84,31 @@ protected: g_warning("Initialization of registered widget using defined repr but with doc==NULL"); } - void write_to_xml(const char * svgstr); + void 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); + } + } Registry * _wr; Glib::ustring _key;