From 5449effb05e5d837a8205d82ab6ea1b672484a1e Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Wed, 5 Mar 2003 19:46:08 +0000 Subject: [PATCH] Move the float dialog to the new scheme. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6355 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/ChangeLog | 5 + src/frontends/Dialogs.h | 3 - src/frontends/controllers/ChangeLog | 5 + src/frontends/controllers/ControlFloat.C | 32 ++--- src/frontends/controllers/ControlFloat.h | 42 +++--- src/frontends/controllers/ControlInclude.C | 5 - src/frontends/guiapi.C | 7 +- src/frontends/guiapi.h | 2 - src/frontends/qt2/ChangeLog | 10 ++ src/frontends/qt2/Dialogs.C | 1 - src/frontends/qt2/Dialogs2.C | 6 - src/frontends/qt2/Dialogs3.C | 12 +- src/frontends/qt2/Dialogs_impl.h | 7 - src/frontends/qt2/QFloat.C | 7 +- src/frontends/qt2/QFloat.h | 9 +- src/frontends/xforms/ChangeLog | 11 ++ src/frontends/xforms/Dialogs.C | 1 - src/frontends/xforms/Dialogs2.C | 6 - src/frontends/xforms/Dialogs3.C | 13 +- src/frontends/xforms/Dialogs_impl.h | 8 -- src/frontends/xforms/FormFloat.C | 6 +- src/frontends/xforms/FormFloat.h | 6 +- src/frontends/xforms/forms/form_float.fd | 26 ++-- src/insets/ChangeLog | 7 + src/insets/insetcollapsable.C | 4 + src/insets/insetfloat.C | 141 ++++++++++++++++----- src/insets/insetfloat.h | 42 ++++-- src/insets/insetinclude.C | 1 - 28 files changed, 266 insertions(+), 159 deletions(-) diff --git a/src/frontends/ChangeLog b/src/frontends/ChangeLog index 7785c5e7d5..e00717299e 100644 --- a/src/frontends/ChangeLog +++ b/src/frontends/ChangeLog @@ -1,3 +1,8 @@ +2003-03-05 Angus Leeming + + * Dialogs.h: remove showFloat. + * guiapi.[Ch]: remove gui_ShowFloat. + 2003-03-05 Angus Leeming * Dialogs.h: remove showInclude. diff --git a/src/frontends/Dialogs.h b/src/frontends/Dialogs.h index 03a8b060cc..61bbdadb33 100644 --- a/src/frontends/Dialogs.h +++ b/src/frontends/Dialogs.h @@ -23,7 +23,6 @@ class Dialog; class InsetBase; class LyXView; -class InsetFloat; class InsetWrap; class InsetGraphics; class InsetInfo; @@ -88,8 +87,6 @@ public: /// show the contents of a file. void showFile(string const &); /// - void showFloat(InsetFloat *); - /// void showWrap(InsetWrap *); /// show all forked child processes void showForks(); diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index f50390c7d7..13c5e4ccbe 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,8 @@ +2003-03-05 Angus Leeming + + * ControlFloat.[Ch]: rewrite to use the Dialog-based scheme. + * ControlInclude.C: remove unneeded header files. + 2003-03-05 Angus Leeming * ControlFloat.[Ch]: replace FloatParams with InsetFloatParams. diff --git a/src/frontends/controllers/ControlFloat.C b/src/frontends/controllers/ControlFloat.C index 79e8f1fd4c..62b1b2ce16 100644 --- a/src/frontends/controllers/ControlFloat.C +++ b/src/frontends/controllers/ControlFloat.C @@ -10,31 +10,31 @@ #include - #include "ControlFloat.h" -#include "BufferView.h" -#include "buffer.h" +#include "funcrequest.h" -ControlFloat::ControlFloat(LyXView & lv, Dialogs & d) - : ControlInset(lv, d) +ControlFloat::ControlFloat(Dialog & parent) + : Dialog::Controller(parent) {} -void ControlFloat::applyParamsToInset() +void ControlFloat::initialiseParams(string const & data) { - inset()->placement(params().placement); - inset()->wide(params().wide, bufferview()->buffer()->params); - bufferview()->updateInset(inset(), true); - + InsetFloatParams params; + InsetFloatMailer::string2params(data, params); + params_.reset(new InsetFloatParams(params)); } -void ControlFloat::applyParamsNoInset() -{} - - -InsetFloatParams const ControlFloat::getParams(InsetFloat const & inset) +void ControlFloat::clearParams() { - return inset.params(); + params_.reset(); +} + + +void ControlFloat::dispatchParams() +{ + string const lfun = InsetFloatMailer::params2string("float", params()); + kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun)); } diff --git a/src/frontends/controllers/ControlFloat.h b/src/frontends/controllers/ControlFloat.h index 0209ebda02..9566e1c146 100644 --- a/src/frontends/controllers/ControlFloat.h +++ b/src/frontends/controllers/ControlFloat.h @@ -13,39 +13,31 @@ #define CONTROLFLOAT_H -#include "ControlInset.h" +#include "Dialog.h" #include "insets/insetfloat.h" -inline -bool operator==(InsetFloatParams const & p1, InsetFloatParams const & p2) -{ - return p1.placement == p2.placement && p1.wide == p2.wide; -} - - -inline -bool operator!=(InsetFloatParams const & p1, InsetFloatParams const & p2) -{ - return !(p1 == p2); -} - /** A controller for Minipage dialogs. */ -class ControlFloat : public ControlInset { +class ControlFloat : public Dialog::Controller { public: /// - ControlFloat(LyXView &, Dialogs &); -private: - /// Dispatch the changed parameters to the kernel. - virtual void applyParamsToInset(); + ControlFloat(Dialog &); /// - virtual void applyParamsNoInset(); - /// get the parameters from the string passed to createInset. - virtual InsetFloatParams const getParams(string const &) - { return InsetFloatParams(); } - /// get the parameters from the inset passed to showInset. - virtual InsetFloatParams const getParams(InsetFloat const &); + virtual void initialiseParams(string const & data); + /// clean-up on hide. + virtual void clearParams(); + /// clean-up on hide. + virtual void dispatchParams(); + /// + virtual bool isBufferDependent() const { return true; } + /// + InsetFloatParams & params() { return *params_.get(); } + /// + InsetFloatParams const & params() const { return *params_.get(); } +private: + /// + boost::scoped_ptr params_; }; #endif diff --git a/src/frontends/controllers/ControlInclude.C b/src/frontends/controllers/ControlInclude.C index 5d8639ce90..aa9695f363 100644 --- a/src/frontends/controllers/ControlInclude.C +++ b/src/frontends/controllers/ControlInclude.C @@ -13,17 +13,12 @@ #include #include "ControlInclude.h" - #include "helper_funcs.h" -#include "BufferView.h" #include "funcrequest.h" #include "gettext.h" -#include "lyxfunc.h" #include "lyxrc.h" -#include "frontends/Alert.h" - #include "support/filetools.h" #include diff --git a/src/frontends/guiapi.C b/src/frontends/guiapi.C index bb28ee5211..14221f8afc 100644 --- a/src/frontends/guiapi.C +++ b/src/frontends/guiapi.C @@ -51,17 +51,12 @@ void gui_ShowFile(string const & f, Dialogs & d) } -void gui_ShowFloat(InsetFloat * ifl, Dialogs & d) -{ - d.showFloat(ifl); -} - - void gui_ShowWrap(InsetWrap * iw, Dialogs & d) { d.showWrap(iw); } + void gui_ShowForks(Dialogs & d) { d.showForks(); diff --git a/src/frontends/guiapi.h b/src/frontends/guiapi.h index b5d9e35a53..c1dd3cad98 100644 --- a/src/frontends/guiapi.h +++ b/src/frontends/guiapi.h @@ -16,7 +16,6 @@ #include "LString.h" class Dialogs; -class InsetFloat; class InsetWrap; class InsetGraphics; class InsetMinipage; @@ -31,7 +30,6 @@ void gui_ShowCharacter(Dialogs &); void gui_SetUserFreeFont(Dialogs &); void gui_ShowDocument(Dialogs &); void gui_ShowFile(string const &, Dialogs &); -void gui_ShowFloat(InsetFloat *, Dialogs &); void gui_ShowForks(Dialogs &); void gui_ShowGraphics(InsetGraphics *, Dialogs &); void gui_ShowLogFile(Dialogs &); diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 0ef9068b7e..a7c3398c4d 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,13 @@ +2003-03-05 Angus Leeming + + * QFloat.[Ch]: changes to use the new Dialog-based scheme. + + * Dialogs.C: + * Dialogs2.C: + * Dialogs_impl.h: remove float dialog. + + * Dialogs3.C: add float dialog. + 2003-03-05 Angus Leeming * QFloat.C (update_contents): rename FloatParams as InsetFloatParams. diff --git a/src/frontends/qt2/Dialogs.C b/src/frontends/qt2/Dialogs.C index 0b6074f985..cdd11f9679 100644 --- a/src/frontends/qt2/Dialogs.C +++ b/src/frontends/qt2/Dialogs.C @@ -31,7 +31,6 @@ Dialogs::Impl::Impl(LyXView & lv, Dialogs & d) character(lv, d), document(lv, d), file(lv, d), - floats(lv, d), graphics(lv, d), logfile(lv, d), minipage(lv, d), diff --git a/src/frontends/qt2/Dialogs2.C b/src/frontends/qt2/Dialogs2.C index d8a702bd28..9a04b489a7 100644 --- a/src/frontends/qt2/Dialogs2.C +++ b/src/frontends/qt2/Dialogs2.C @@ -51,12 +51,6 @@ void Dialogs::showFile(string const & f) } -void Dialogs::showFloat(InsetFloat * ifl) -{ - pimpl_->floats.controller().showInset(ifl); -} - - void Dialogs::showForks() {} diff --git a/src/frontends/qt2/Dialogs3.C b/src/frontends/qt2/Dialogs3.C index 26883fbb59..a9fc8d3dba 100644 --- a/src/frontends/qt2/Dialogs3.C +++ b/src/frontends/qt2/Dialogs3.C @@ -19,6 +19,7 @@ #include "ControlError.h" #include "ControlERT.h" #include "ControlExternal.h" +#include "ControlFloat.h" #include "ControlInclude.h" #include "ControlIndex.h" #include "ControlLabel.h" @@ -38,6 +39,8 @@ #include "QERTDialog.h" #include "QExternal.h" #include "QExternalDialog.h" +#include "QFloat.h" +#include "QFloatDialog.h" // Here would be an appropriate point to lecture on the evils // of the Qt headers, those most fucked up of disgusting ratholes. // But I won't. @@ -73,8 +76,9 @@ typedef ButtonController namespace { char const * const dialognames[] = { "bibitem", "bibtex", "citation", - "error", "ert", "external", "include", - "index", "label", "ref", "toc", "url" }; + "error", "ert", "external", "float", + "include", "index", "label", "ref", + "toc", "url" }; char const * const * const end_dialognames = dialognames + (sizeof(dialognames) / sizeof(char *)); @@ -130,6 +134,10 @@ Dialog * Dialogs::build(string const & name) dialog->setController(new ControlExternal(*dialog)); dialog->setView(new QExternal(*dialog)); dialog->setButtonController(new OkApplyCancelReadOnlyBC); + } else if (name == "float") { + dialog->setController(new ControlFloat(*dialog)); + dialog->setView(new QFloat(*dialog)); + dialog->setButtonController(new NoRepeatedApplyReadOnlyBC); } else if (name == "include") { dialog->setController(new ControlInclude(*dialog)); dialog->setView(new QInclude(*dialog)); diff --git a/src/frontends/qt2/Dialogs_impl.h b/src/frontends/qt2/Dialogs_impl.h index 9c2f9ea964..c7939f8af6 100644 --- a/src/frontends/qt2/Dialogs_impl.h +++ b/src/frontends/qt2/Dialogs_impl.h @@ -18,7 +18,6 @@ #include "ControlChanges.h" #include "ControlCharacter.h" #include "ControlDocument.h" -#include "ControlFloat.h" #include "ControlForks.h" #include "ControlGraphics.h" #include "insets/insetgraphicsParams.h" @@ -45,8 +44,6 @@ #include "QCharacterDialog.h" #include "QDocument.h" #include "QDocumentDialog.h" -#include "QFloat.h" -#include "QFloatDialog.h" //#include "QForks.h" // Here would be an appropriate point to lecture on the evils // of the Qt headers, those most fucked up of disgusting ratholes. @@ -109,9 +106,6 @@ DocumentDialog; typedef GUI FileDialog; -typedef GUI -FloatDialog; - typedef GUI GraphicsDialog; @@ -168,7 +162,6 @@ struct Dialogs::Impl { CharacterDialog character; DocumentDialog document; FileDialog file; - FloatDialog floats; GraphicsDialog graphics; LogFileDialog logfile; MinipageDialog minipage; diff --git a/src/frontends/qt2/QFloat.C b/src/frontends/qt2/QFloat.C index a238e5e8b8..ab87b8521c 100644 --- a/src/frontends/qt2/QFloat.C +++ b/src/frontends/qt2/QFloat.C @@ -10,7 +10,6 @@ #include - #include "ControlFloat.h" #include "QFloatDialog.h" #include "QFloat.h" @@ -22,11 +21,11 @@ #include #include -typedef Qt2CB > base_class; +typedef QController > base_class; -QFloat::QFloat() - : base_class(qt_("LyX: Float Settings")) +QFloat::QFloat(Dialog & parent) + : base_class(parent, qt_("LyX: Float Settings")) { } diff --git a/src/frontends/qt2/QFloat.h b/src/frontends/qt2/QFloat.h index 1045d69700..e95528b01f 100644 --- a/src/frontends/qt2/QFloat.h +++ b/src/frontends/qt2/QFloat.h @@ -13,20 +13,19 @@ #define QFLOAT_H -#include "Qt2Base.h" +#include "QDialogView.h" + class ControlFloat; class QFloatDialog; /// -class QFloat - : public Qt2CB > -{ +class QFloat : public QController > { public: /// friend class QFloatDialog; /// - QFloat(); + QFloat(Dialog &); private: /// Apply changes virtual void apply(); diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index a45bafa0a9..d761b08e8f 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,14 @@ +2003-03-05 Angus Leeming + + * FormFloat.[Ch]: + * forms/form_float.fd: changes to use the new Dialog-based scheme. + + * Dialogs.C: + * Dialogs2.C: + * Dialogs_impl.h: remove float dialog. + + * Dialogs3.C: add float dialog. + 2003-03-05 Angus Leeming * FormInclude.[Ch]: diff --git a/src/frontends/xforms/Dialogs.C b/src/frontends/xforms/Dialogs.C index 94fbd92e1c..985c3a7dc1 100644 --- a/src/frontends/xforms/Dialogs.C +++ b/src/frontends/xforms/Dialogs.C @@ -31,7 +31,6 @@ Dialogs::Impl::Impl(LyXView & lv, Dialogs & d) character(lv, d), document(lv, d), file(lv, d), - floats(lv, d), forks(lv, d), graphics(lv, d), logfile(lv, d), diff --git a/src/frontends/xforms/Dialogs2.C b/src/frontends/xforms/Dialogs2.C index 44fd178524..7fc7aa419e 100644 --- a/src/frontends/xforms/Dialogs2.C +++ b/src/frontends/xforms/Dialogs2.C @@ -51,12 +51,6 @@ void Dialogs::showFile(string const & f) } -void Dialogs::showFloat(InsetFloat * ifl) -{ - pimpl_->floats.controller().showInset(ifl); -} - - void Dialogs::showForks() { pimpl_->forks.controller().show(); diff --git a/src/frontends/xforms/Dialogs3.C b/src/frontends/xforms/Dialogs3.C index 68cfcb9299..f618d1dd53 100644 --- a/src/frontends/xforms/Dialogs3.C +++ b/src/frontends/xforms/Dialogs3.C @@ -39,6 +39,10 @@ #include "FormExternal.h" #include "forms/form_external.h" +#include "ControlFloat.h" +#include "FormFloat.h" +#include "forms/form_float.h" + #include "ControlInclude.h" #include "FormInclude.h" #include "forms/form_include.h" @@ -86,8 +90,9 @@ namespace { // "minipage", "ref", "tabular", "toc", // "url", "wrap" }; char const * const dialognames[] = { "bibitem", "bibtex", "citation", - "error", "ert", "external", "include", - "index", "label", "ref", "toc", "url" }; + "error", "ert", "external", "float", + "include", "index", "label", "ref", + "toc", "url" }; char const * const * const end_dialognames = dialognames + (sizeof(dialognames) / sizeof(char *)); @@ -143,6 +148,10 @@ Dialog * Dialogs::build(string const & name) dialog->setController(new ControlExternal(*dialog)); dialog->setView(new FormExternal(*dialog)); dialog->setButtonController(new OkApplyCancelReadOnlyBC); + } else if (name == "float") { + dialog->setController(new ControlFloat(*dialog)); + dialog->setView(new FormFloat(*dialog)); + dialog->setButtonController(new NoRepeatedApplyReadOnlyBC); } else if (name == "include") { dialog->setController(new ControlInclude(*dialog)); dialog->setView(new FormInclude(*dialog)); diff --git a/src/frontends/xforms/Dialogs_impl.h b/src/frontends/xforms/Dialogs_impl.h index 3d29405c15..a46075eab3 100644 --- a/src/frontends/xforms/Dialogs_impl.h +++ b/src/frontends/xforms/Dialogs_impl.h @@ -37,10 +37,6 @@ #include "FormDocument.h" #include "forms/form_document.h" -#include "ControlFloat.h" -#include "FormFloat.h" -#include "forms/form_float.h" - #include "ControlForks.h" #include "FormForks.h" #include "forms/form_forks.h" @@ -132,9 +128,6 @@ DocumentDialog; typedef GUI FileDialog; -typedef GUI -FloatDialog; - typedef GUI ForksDialog; @@ -199,7 +192,6 @@ struct Dialogs::Impl { CharacterDialog character; DocumentDialog document; FileDialog file; - FloatDialog floats; ForksDialog forks; GraphicsDialog graphics; LogFileDialog logfile; diff --git a/src/frontends/xforms/FormFloat.C b/src/frontends/xforms/FormFloat.C index 9386efb5f0..76e2b916d5 100644 --- a/src/frontends/xforms/FormFloat.C +++ b/src/frontends/xforms/FormFloat.C @@ -33,10 +33,10 @@ enum { } // namespace anon -typedef FormCB > base_class; +typedef FormController > base_class; -FormFloat::FormFloat() - : base_class(_("Float Options")) +FormFloat::FormFloat(Dialog & parent) + : base_class(parent, _("Float Options")) {} diff --git a/src/frontends/xforms/FormFloat.h b/src/frontends/xforms/FormFloat.h index 2cdf4fc543..9211cf1e82 100644 --- a/src/frontends/xforms/FormFloat.h +++ b/src/frontends/xforms/FormFloat.h @@ -13,7 +13,7 @@ #define FORMFLOAT_H -#include "FormBase.h" +#include "FormDialogView.h" #include "RadioButtonGroup.h" class ControlFloat; @@ -22,10 +22,10 @@ struct FD_float; /** This class provides an XForms implementation of the Float Dialog. */ -class FormFloat : public FormCB > { +class FormFloat : public FormController > { public: /// - FormFloat(); + FormFloat(Dialog &); private: /// Set the Params variable for the Controller. virtual void apply(); diff --git a/src/frontends/xforms/forms/form_float.fd b/src/frontends/xforms/forms/form_float.fd index 7ce6f0692e..798e210faa 100644 --- a/src/frontends/xforms/forms/form_float.fd +++ b/src/frontends/xforms/forms/form_float.fd @@ -64,7 +64,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_East FL_NoGravity name: check_page -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -82,7 +82,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_West FL_NoGravity name: check_bottom -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -100,7 +100,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_West FL_NoGravity name: check_top -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -118,7 +118,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_East FL_NoGravity name: check_here -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -136,7 +136,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthWest FL_SouthWest name: button_restore -callback: C_FormBaseRestoreCB +callback: C_FormDialogView_RestoreCB argument: 0 -------------------- @@ -154,7 +154,7 @@ shortcut: ^M resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_ok -callback: C_FormBaseOKCB +callback: C_FormDialogView_OKCB argument: 0 -------------------- @@ -172,7 +172,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_apply -callback: C_FormBaseApplyCB +callback: C_FormDialogView_ApplyCB argument: 0 -------------------- @@ -190,7 +190,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_close -callback: C_FormBaseCancelCB +callback: C_FormDialogView_CancelCB argument: 0 -------------------- @@ -208,7 +208,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthWest FL_SouthWest name: check_wide -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -226,7 +226,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_NoGravity FL_NoGravity name: check_force -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -262,7 +262,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_West FL_NoGravity name: radio_alternatives -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -280,7 +280,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_West FL_NoGravity name: radio_here_definitely -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -298,7 +298,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_West FL_NoGravity name: radio_default -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 value: 1 diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index d7d99921ac..1285dcce1b 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,10 @@ +2003-03-05 Angus Leeming + + * insetcollapsable.C (draw): cache the BufferView. + + * insetfloat.[Ch]: define a new class InsetFloatMailer and use + it to communicate with the frontend dialogs. + 2003-03-05 Angus Leeming * insetfloat.[Ch]: move the params into a separate InsetFloatParams diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 8ad264f22b..c87ad118d5 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -29,6 +29,7 @@ #include "frontends/Painter.h" #include "frontends/LyXView.h" +#include "support/LAssert.h" #include "support/LOstream.h" #include "support/lstrings.h" @@ -184,6 +185,9 @@ void InsetCollapsable::draw_collapsed(Painter & pain, void InsetCollapsable::draw(BufferView * bv, LyXFont const & f, int baseline, float & x, bool cleared) const { + lyx::Assert(bv); + cache(bv); + if (need_update != NONE) { const_cast(&inset)->update(bv, f, true); bv->text->status(bv, LyXText::CHANGED_IN_DRAW); diff --git a/src/insets/insetfloat.C b/src/insets/insetfloat.C index 87c4beb2fe..0293a80327 100644 --- a/src/insets/insetfloat.C +++ b/src/insets/insetfloat.C @@ -12,22 +12,26 @@ #include "insetfloat.h" -#include "gettext.h" -#include "lyxfont.h" +#include "insettext.h" + +#include "buffer.h" #include "BufferView.h" -#include "lyxtext.h" -#include "insets/insettext.h" -#include "support/LOstream.h" -#include "support/lstrings.h" -#include "FloatList.h" -#include "LaTeXFeatures.h" #include "debug.h" #include "Floating.h" -#include "buffer.h" +#include "FloatList.h" +#include "funcrequest.h" +#include "gettext.h" +#include "iterators.h" +#include "LaTeXFeatures.h" +#include "lyxfont.h" +#include "lyxlex.h" +#include "lyxtext.h" + +#include "support/LOstream.h" +#include "support/lstrings.h" + #include "frontends/LyXView.h" #include "frontends/Dialogs.h" -#include "lyxlex.h" -#include "iterators.h" using std::ostream; using std::endl; @@ -144,19 +148,44 @@ InsetFloat::InsetFloat(InsetFloat const & in, bool same_id) InsetFloat::~InsetFloat() { - hideDialog(); + InsetFloatMailer mailer(*this); + mailer.hideDialog(); } -void InsetFloat::writeParams(ostream & os) const +dispatch_result InsetFloat::localDispatch(FuncRequest const & cmd) +{ + Inset::RESULT result = UNDISPATCHED; + + switch (cmd.action) { + case LFUN_INSET_MODIFY: { + InsetFloatParams params; + InsetFloatMailer::string2params(cmd.argument, params); + + params_.placement = params.placement; + params_.wide = params.wide; + + cmd.view()->updateInset(this, true); + result = DISPATCHED; + } + break; + default: + result = InsetCollapsable::localDispatch(cmd); + } + + return result; +} + + +void InsetFloatParams::write(ostream & os) const { os << "Float " // getInsetName() - << params_.type << '\n'; + << type << '\n'; - if (!params_.placement.empty()) { - os << "placement " << params_.placement << "\n"; + if (!placement.empty()) { + os << "placement " << placement << "\n"; } - if (params_.wide) { + if (wide) { os << "wide true\n"; } else { os << "wide false\n"; @@ -164,21 +193,14 @@ void InsetFloat::writeParams(ostream & os) const } -void InsetFloat::write(Buffer const * buf, ostream & os) const -{ - writeParams(os); - InsetCollapsable::write(buf, os); -} - - -void InsetFloat::readParams(Buffer const * buf, LyXLex & lex) +void InsetFloatParams::read(LyXLex & lex) { if (lex.isOK()) { lex.next(); string token = lex.getString(); if (token == "placement") { lex.next(); - params_.placement = lex.getString(); + placement = lex.getString(); } else { // take countermeasures lex.pushToken(token); @@ -188,10 +210,7 @@ void InsetFloat::readParams(Buffer const * buf, LyXLex & lex) if (token == "wide") { lex.next(); string const tmptoken = lex.getString(); - if (tmptoken == "true") - wide(true, buf->params); - else - wide(false, buf->params); + wide = (tmptoken == "true"); } else { lyxerr << "InsetFloat::Read:: Missing wide!" << endl; @@ -202,9 +221,17 @@ void InsetFloat::readParams(Buffer const * buf, LyXLex & lex) } +void InsetFloat::write(Buffer const * buf, ostream & os) const +{ + params_.write(os); + InsetCollapsable::write(buf, os); +} + + void InsetFloat::read(Buffer const * buf, LyXLex & lex) { - readParams(buf, lex); + params_.read(lex); + wide(params_.wide, buf->params); InsetCollapsable::read(buf, lex); } @@ -299,7 +326,9 @@ bool InsetFloat::insetAllowed(Inset::Code code) const bool InsetFloat::showInsetDialog(BufferView * bv) const { if (!inset.showInsetDialog(bv)) { - bv->owner()->getDialogs().showFloat(const_cast(this)); + InsetFloat * tmp = const_cast(this); + InsetFloatMailer mailer(*tmp); + mailer.showDialog(); } return true; } @@ -364,3 +393,51 @@ void InsetFloat::addToToc(toc::TocList & toclist, Buffer const * buf) const } } } + + +InsetFloatMailer::InsetFloatMailer(InsetFloat & inset) + : name_("float"), inset_(inset) +{} + + +string const InsetFloatMailer::inset2string() const +{ + return params2string(name(), inset_.params()); +} + + +void InsetFloatMailer::string2params(string const & in, + InsetFloatParams & params) +{ + params = InsetFloatParams(); + + string name; + string body = split(in, name, ' '); + + if (name != "float" || body.empty()) + return; + + // This is part of the inset proper that is usually swallowed + // by Buffer::readInset + body = split(body, name, '\n'); + if (!prefixIs(name, "Float ")) + return; + + istringstream data(body); + LyXLex lex(0,0); + lex.setStream(data); + + params.read(lex); +} + + +string const +InsetFloatMailer::params2string(string const & name, + InsetFloatParams const & params) +{ + ostringstream data; + data << name << ' '; + params.write(data); + + return data.str(); +} diff --git a/src/insets/insetfloat.h b/src/insets/insetfloat.h index 39d6065769..bb12e01faf 100644 --- a/src/insets/insetfloat.h +++ b/src/insets/insetfloat.h @@ -17,14 +17,16 @@ #include "insetcollapsable.h" #include "toc.h" -#include - class Painter; struct InsetFloatParams { /// InsetFloatParams() : placement("htbp"), wide(false) {} /// + void write(std::ostream & os) const; + /// + void read(LyXLex & lex); + /// string type; /// string placement; @@ -44,6 +46,10 @@ public: InsetFloat(InsetFloat const &, bool same_id = false); /// ~InsetFloat(); + + /// + virtual dispatch_result localDispatch(FuncRequest const & cmd); + /// void write(Buffer const * buf, std::ostream & os) const; /// @@ -81,17 +87,37 @@ public: /// bool showInsetDialog(BufferView *) const; /// - boost::signal0 hideDialog; - /// InsetFloatParams const & params() const { return params_; } - /// - void writeParams(std::ostream & os) const; - /// - void readParams(Buffer const * buf, LyXLex & lex); private: /// InsetFloatParams params_; }; + +#include "mailinset.h" + + +class InsetFloatMailer : public MailInset { +public: + /// + InsetFloatMailer(InsetFloat & inset); + /// + virtual Inset & inset() const { return inset_; } + /// + virtual string const & name() const { return name_; } + /// + virtual string const inset2string() const; + /// + static void string2params(string const &, InsetFloatParams &); + /// + static string const params2string(string const & name, + InsetFloatParams const &); +private: + /// + string const name_; + /// + InsetFloat & inset_; +}; + #endif diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 1df52b8b55..9cafae74d5 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -661,4 +661,3 @@ InsetIncludeMailer::params2string(string const & name, return data.str(); } -