From c0cd5511d3b975ebe07d019c1f5528108725e438 Mon Sep 17 00:00:00 2001 From: johanengelen Date: Tue, 15 Jan 2008 14:29:14 +0000 Subject: [PATCH] prepare LPE parameter widgets to be owned by multiple dialogs, as it should be. For each parameter function that has not been re-implemented, a warning is issued. Sorry for the huge number of warnings showing when working with LPE. It is important to fix this asap. --- src/live_effects/effect.cpp | 45 +++++++--------- src/live_effects/effect.h | 4 +- src/live_effects/parameter/bool.cpp | 4 +- src/live_effects/parameter/bool.h | 2 +- src/live_effects/parameter/enum.h | 4 +- src/live_effects/parameter/parameter.cpp | 4 +- src/live_effects/parameter/parameter.h | 9 ++-- src/live_effects/parameter/path.cpp | 67 ++++++++++-------------- src/live_effects/parameter/path.h | 5 +- src/live_effects/parameter/point.cpp | 7 +-- src/live_effects/parameter/point.h | 2 +- src/live_effects/parameter/random.cpp | 4 +- src/live_effects/parameter/random.h | 2 +- src/ui/dialog/livepatheffect-editor.cpp | 5 +- src/ui/dialog/livepatheffect-editor.h | 2 + 15 files changed, 81 insertions(+), 85 deletions(-) diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 543d60fc0..bdbc4dd52 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -98,17 +98,12 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj) Effect::Effect(LivePathEffectObject *lpeobject) { - vbox = NULL; - tooltips = NULL; lpeobj = lpeobject; oncanvasedit_it = 0; } Effect::~Effect() { - if (tooltips) { - delete tooltips; - } } Glib::ustring @@ -236,30 +231,30 @@ Effect::registerParameter(Parameter * param) param_vector.push_back(param); } +/** +* This *creates* a new widget, management of deletion should be done by the caller +*/ Gtk::Widget * -Effect::getWidget() +Effect::newWidget(Gtk::Tooltips * tooltips) { - if (!vbox) { - vbox = Gtk::manage( new Gtk::VBox() ); // use manage here, because after deletion of Effect object, others might still be pointing to this widget. - //if (!tooltips) - tooltips = new Gtk::Tooltips(); - - vbox->set_border_width(5); - - std::vector::iterator it = param_vector.begin(); - while (it != param_vector.end()) { - Parameter * param = *it; - Gtk::Widget * widg = param->param_getWidget(); - Glib::ustring * tip = param->param_getTooltip(); - if (widg) { - vbox->pack_start(*widg, true, true, 2); - if (tip != NULL) { - tooltips->set_tip(*widg, *tip); - } - } + // use manage here, because after deletion of Effect object, others might still be pointing to this widget. + Gtk::VBox * vbox = Gtk::manage( new Gtk::VBox() ); - it++; + vbox->set_border_width(5); + + std::vector::iterator it = param_vector.begin(); + while (it != param_vector.end()) { + Parameter * param = *it; + Gtk::Widget * widg = param->param_newWidget(tooltips); + Glib::ustring * tip = param->param_getTooltip(); + if (widg) { + vbox->pack_start(*widg, true, true, 2); + if (tip != NULL) { + tooltips->set_tip(*widg, *tip); + } } + + it++; } return dynamic_cast(vbox); diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 535cec0b6..8354c218b 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -74,7 +74,7 @@ public: virtual void doEffect (SPCurve * curve); - virtual Gtk::Widget * getWidget(); + virtual Gtk::Widget * newWidget(Gtk::Tooltips * tooltips); virtual void resetDefaults(SPItem * item); @@ -116,8 +116,6 @@ protected: Inkscape::UI::Widget::Registry wr; - Gtk::VBox * vbox; - Gtk::Tooltips * tooltips; LivePathEffectObject *lpeobj; diff --git a/src/live_effects/parameter/bool.cpp b/src/live_effects/parameter/bool.cpp index 78ce17939..14fd88423 100644 --- a/src/live_effects/parameter/bool.cpp +++ b/src/live_effects/parameter/bool.cpp @@ -58,8 +58,10 @@ BoolParam::param_writeSVGValue() const } Gtk::Widget * -BoolParam::param_getWidget() +BoolParam::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("BoolParam::param_newWidget still needs recoding to work with multiple document views"); if (!checkwdg) { checkwdg = new Inkscape::UI::Widget::RegisteredCheckButton(); checkwdg->init(param_label, param_tooltip, param_key, *param_wr, false, param_effect->getRepr(), param_effect->getSPDoc()); diff --git a/src/live_effects/parameter/bool.h b/src/live_effects/parameter/bool.h index 13dc57b6c..38811812d 100644 --- a/src/live_effects/parameter/bool.h +++ b/src/live_effects/parameter/bool.h @@ -31,7 +31,7 @@ public: bool default_value = false); virtual ~BoolParam(); - virtual Gtk::Widget * param_getWidget(); + virtual Gtk::Widget * param_newWidget(Gtk::Tooltips * tooltips); virtual bool param_readSVGValue(const gchar * strvalue); virtual gchar * param_writeSVGValue() const; diff --git a/src/live_effects/parameter/enum.h b/src/live_effects/parameter/enum.h index 1c5384f57..f0f3b59f8 100644 --- a/src/live_effects/parameter/enum.h +++ b/src/live_effects/parameter/enum.h @@ -43,7 +43,9 @@ public: delete regenum; }; - Gtk::Widget * param_getWidget() { + 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()); diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index 893f0d7f1..ca08b2b3d 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -136,8 +136,10 @@ ScalarParam::param_make_integer(bool yes) } Gtk::Widget * -ScalarParam::param_getWidget() +ScalarParam::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("ScalarParam::param_newWidget still needs recoding to work with multiple document views"); if (!rsu) { rsu = new Inkscape::UI::Widget::RegisteredScalar(); rsu->init(param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc()); diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index e3d372706..67384a6e6 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -21,6 +21,7 @@ struct SPItem; namespace Gtk { class Widget; + class Tooltips; } namespace Inkscape { @@ -47,9 +48,9 @@ public: virtual void param_set_default() = 0; - // This returns pointer to the parameter's widget to be put in the live-effects dialog. Must also create the - // necessary widget if it does not exist yet. - virtual Gtk::Widget * param_getWidget() = 0; + // This creates a new widget (newed with Gtk::manage(new ...);) + virtual Gtk::Widget * param_newWidget(Gtk::Tooltips * tooltips) = 0; + virtual Glib::ustring * param_getTooltip() { return ¶m_tooltip; }; virtual void param_editOncanvas(SPItem * /*item*/, SPDesktop * /*dt*/) {}; @@ -96,7 +97,7 @@ public: void param_set_digits(unsigned digits); void param_set_increments(double step, double page); - virtual Gtk::Widget * param_getWidget(); + virtual Gtk::Widget * param_newWidget(Gtk::Tooltips * tooltips); inline operator gdouble() { return value; }; diff --git a/src/live_effects/parameter/path.cpp b/src/live_effects/parameter/path.cpp index 1f0e6f3be..59655d62e 100644 --- a/src/live_effects/parameter/path.cpp +++ b/src/live_effects/parameter/path.cpp @@ -42,8 +42,6 @@ PathParam::PathParam( const Glib::ustring& label, const Glib::ustring& tip, Effect* effect, const gchar * default_value) : Parameter(label, tip, key, wr, effect) { - _widget = NULL; - _tooltips = NULL; edit_button = NULL; defvalue = g_strdup(default_value); param_readSVGValue(defvalue); @@ -52,10 +50,6 @@ PathParam::PathParam( const Glib::ustring& label, const Glib::ustring& tip, PathParam::~PathParam() { - if (_tooltips) - delete _tooltips; - // _widget is managed by GTK so do not delete! - g_free(defvalue); } @@ -92,40 +86,37 @@ PathParam::param_writeSVGValue() const } Gtk::Widget * -PathParam::param_getWidget() +PathParam::param_newWidget(Gtk::Tooltips * tooltips) { - if (!_widget) { - _widget = Gtk::manage(new Gtk::HBox()); - _tooltips = new Gtk::Tooltips(); - - Gtk::Label* pLabel = Gtk::manage(new Gtk::Label(param_label)); - static_cast(_widget)->pack_start(*pLabel, true, true); - _tooltips->set_tip(*pLabel, param_tooltip); - - Gtk::Widget* pIcon = Gtk::manage( sp_icon_get_icon( "draw_node", Inkscape::ICON_SIZE_BUTTON) ); - Gtk::Button * pButton = Gtk::manage(new Gtk::Button()); - pButton->set_relief(Gtk::RELIEF_NONE); - pIcon->show(); - pButton->add(*pIcon); - pButton->show(); - pButton->signal_clicked().connect(sigc::mem_fun(*this, &PathParam::on_edit_button_click)); - static_cast(_widget)->pack_start(*pButton, true, true); - _tooltips->set_tip(*pButton, _("Edit on-canvas")); - edit_button = pButton; - - pIcon = Gtk::manage( sp_icon_get_icon( GTK_STOCK_PASTE, Inkscape::ICON_SIZE_BUTTON) ); - pButton = Gtk::manage(new Gtk::Button()); - pButton->set_relief(Gtk::RELIEF_NONE); - pIcon->show(); - pButton->add(*pIcon); - pButton->show(); - pButton->signal_clicked().connect(sigc::mem_fun(*this, &PathParam::on_paste_button_click)); - static_cast(_widget)->pack_start(*pButton, true, true); - _tooltips->set_tip(*pButton, _("Paste path")); - - static_cast(_widget)->show_all_children(); + Gtk::HBox * _widget = Gtk::manage(new Gtk::HBox()); + + Gtk::Label* pLabel = Gtk::manage(new Gtk::Label(param_label)); + static_cast(_widget)->pack_start(*pLabel, true, true); + tooltips->set_tip(*pLabel, param_tooltip); + + Gtk::Widget* pIcon = Gtk::manage( sp_icon_get_icon( "draw_node", Inkscape::ICON_SIZE_BUTTON) ); + Gtk::Button * pButton = Gtk::manage(new Gtk::Button()); + pButton->set_relief(Gtk::RELIEF_NONE); + pIcon->show(); + pButton->add(*pIcon); + pButton->show(); + pButton->signal_clicked().connect(sigc::mem_fun(*this, &PathParam::on_edit_button_click)); + static_cast(_widget)->pack_start(*pButton, true, true); + tooltips->set_tip(*pButton, _("Edit on-canvas")); + edit_button = pButton; + + pIcon = Gtk::manage( sp_icon_get_icon( GTK_STOCK_PASTE, Inkscape::ICON_SIZE_BUTTON) ); + pButton = Gtk::manage(new Gtk::Button()); + pButton->set_relief(Gtk::RELIEF_NONE); + pIcon->show(); + pButton->add(*pIcon); + pButton->show(); + pButton->signal_clicked().connect(sigc::mem_fun(*this, &PathParam::on_paste_button_click)); + static_cast(_widget)->pack_start(*pButton, true, true); + tooltips->set_tip(*pButton, _("Paste path")); + + static_cast(_widget)->show_all_children(); - } return dynamic_cast (_widget); } diff --git a/src/live_effects/parameter/path.h b/src/live_effects/parameter/path.h index 82e240310..456a9ae0b 100644 --- a/src/live_effects/parameter/path.h +++ b/src/live_effects/parameter/path.h @@ -37,7 +37,7 @@ public: const gchar * default_value = "M0,0 L1,1"); virtual ~PathParam(); - Gtk::Widget * param_getWidget(); + virtual Gtk::Widget * param_newWidget(Gtk::Tooltips * tooltips); bool param_readSVGValue(const gchar * strvalue); gchar * param_writeSVGValue() const; @@ -58,9 +58,6 @@ private: PathParam(const PathParam&); PathParam& operator=(const PathParam&); - Gtk::Widget * _widget; - Gtk::Tooltips * _tooltips; - void on_edit_button_click(); void on_paste_button_click(); diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index eea337c85..5284bc797 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -80,8 +80,10 @@ PointParam::param_writeSVGValue() const } Gtk::Widget * -PointParam::param_getWidget() +PointParam::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("PointParam::param_newWidget still needs recoding to work with multiple document views"); if (!_widget) { pointwdg = new Inkscape::UI::Widget::RegisteredPoint(); pointwdg->init(param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc()); @@ -104,8 +106,7 @@ PointParam::param_getWidget() static_cast(_widget)->pack_start(*(pointwdg->getPoint()), true, true); static_cast(_widget)->show_all_children(); - _tooltips = new Gtk::Tooltips(); - _tooltips->set_tip(*pButton, _("Edit on-canvas")); + tooltips->set_tip(*pButton, _("Edit on-canvas")); } return dynamic_cast (_widget); } diff --git a/src/live_effects/parameter/point.h b/src/live_effects/parameter/point.h index 688a50d4a..7eb1a70c1 100644 --- a/src/live_effects/parameter/point.h +++ b/src/live_effects/parameter/point.h @@ -35,7 +35,7 @@ public: Geom::Point default_value = Geom::Point(0,0)); virtual ~PointParam(); - Gtk::Widget * param_getWidget(); + virtual Gtk::Widget * param_newWidget(Gtk::Tooltips * tooltips); bool param_readSVGValue(const gchar * strvalue); gchar * param_writeSVGValue() const; diff --git a/src/live_effects/parameter/random.cpp b/src/live_effects/parameter/random.cpp index 959b21114..9ce4e41a9 100644 --- a/src/live_effects/parameter/random.cpp +++ b/src/live_effects/parameter/random.cpp @@ -130,8 +130,10 @@ RandomParam::resetRandomizer() Gtk::Widget * -RandomParam::param_getWidget() +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(); diff --git a/src/live_effects/parameter/random.h b/src/live_effects/parameter/random.h index 55171c973..1b7d4cf16 100644 --- a/src/live_effects/parameter/random.h +++ b/src/live_effects/parameter/random.h @@ -36,7 +36,7 @@ public: virtual gchar * param_writeSVGValue() const; virtual void param_set_default(); - virtual Gtk::Widget * param_getWidget(); + virtual Gtk::Widget * param_newWidget(Gtk::Tooltips * tooltips); void param_set_value(gdouble val, long newseed); void param_make_integer(bool yes = true); diff --git a/src/ui/dialog/livepatheffect-editor.cpp b/src/ui/dialog/livepatheffect-editor.cpp index b1dfda573..93e17c324 100644 --- a/src/ui/dialog/livepatheffect-editor.cpp +++ b/src/ui/dialog/livepatheffect-editor.cpp @@ -97,6 +97,7 @@ LivePathEffectEditor::~LivePathEffectEditor() { if (effectwidget) { effectcontrol_vbox.remove(*effectwidget); + delete effectwidget; effectwidget = NULL; } @@ -111,11 +112,12 @@ LivePathEffectEditor::showParams(LivePathEffect::Effect* effect) { if (effectwidget) { effectcontrol_vbox.remove(*effectwidget); + delete effectwidget; effectwidget = NULL; } explain_label.set_markup("" + effect->getName() + ""); - effectwidget = effect->getWidget(); + effectwidget = effect->newWidget(&tooltips); if (effectwidget) { effectcontrol_vbox.pack_start(*effectwidget, true, true); } @@ -130,6 +132,7 @@ LivePathEffectEditor::showText(Glib::ustring const &str) { if (effectwidget) { effectcontrol_vbox.remove(*effectwidget); + delete effectwidget; effectwidget = NULL; } diff --git a/src/ui/dialog/livepatheffect-editor.h b/src/ui/dialog/livepatheffect-editor.h index 2ec1f9d14..aed17434d 100644 --- a/src/ui/dialog/livepatheffect-editor.h +++ b/src/ui/dialog/livepatheffect-editor.h @@ -18,6 +18,7 @@ #include #include #include +#include #include "ui/widget/combo-enums.h" #include "live_effects/effect.h" @@ -60,6 +61,7 @@ private: Gtk::Frame effectcontrol_frame; Gtk::HBox effectapplication_hbox; Gtk::VBox effectcontrol_vbox; + Gtk::Tooltips tooltips; SPDesktop * current_desktop; -- 2.30.2