diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index ed0516ace3..121e8c6327 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -41,6 +41,7 @@ #include "undo_funcs.h" #include "funcrequest.h" #include "language.h" +#include "factory.h" #include "insets/insetbib.h" #include "insets/insettext.h" @@ -50,22 +51,11 @@ #include "insets/insetref.h" #include "insets/insetparent.h" #include "insets/insetindex.h" -#include "insets/insetnote.h" #include "insets/insetinclude.h" #include "insets/insetcite.h" -#include "insets/insetert.h" -#include "insets/insetexternal.h" #include "insets/insetgraphics.h" -#include "insets/insetfoot.h" #include "insets/insetmarginal.h" -#include "insets/insetminipage.h" -#include "insets/insetfloat.h" #include "insets/insettabular.h" -#include "insets/insetoptarg.h" -#if 0 -#include "insets/insettheorem.h" -#include "insets/insetlist.h" -#endif #include "insets/insetcaption.h" #include "insets/insetfloatlist.h" @@ -1626,67 +1616,41 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev) } break; - case LFUN_INSET_ERT: - insertAndEditInset(new InsetERT(buffer_->params)); - break; - - case LFUN_INSET_EXTERNAL: - insertAndEditInset(new InsetExternal); - break; - - case LFUN_INSET_FOOTNOTE: - insertAndEditInset(new InsetFoot(buffer_->params)); - break; - - case LFUN_INSET_MARGINAL: - insertAndEditInset(new InsetMarginal(buffer_->params)); - break; - - case LFUN_INSET_MINIPAGE: - insertAndEditInset(new InsetMinipage(buffer_->params)); - break; - - case LFUN_INSERT_NOTE: - insertAndEditInset(new InsetNote(buffer_->params)); - break; - - case LFUN_INSET_OPTARG: - insertAndEditInset(new InsetOptArg(buffer_->params)); - break; - - case LFUN_INSET_FLOAT: - // check if the float type exist - if (floatList.typeExist(ev.argument)) { - insertAndEditInset(new InsetFloat(buffer_->params, - ev.argument)); - } else { - lyxerr << "Non-existent float type: " - << ev.argument << endl; - } - break; - - case LFUN_INSET_WIDE_FLOAT: - // check if the float type exist - if (floatList.typeExist(ev.argument)) { - InsetFloat * new_inset = - new InsetFloat(buffer_->params, ev.argument); - new_inset->wide(true); - insertAndEditInset(new_inset); - } else { - lyxerr << "Non-existent float type: " - << ev.argument << endl; - } - break; - #if 0 case LFUN_INSET_LIST: - insertAndEditInset(new InsetList); - break; - case LFUN_INSET_THEOREM: - insertAndEditInset(new InsetTheorem); - break; #endif + case LFUN_INSERT_NOTE: + case LFUN_INSET_ERT: + case LFUN_INSET_EXTERNAL: + case LFUN_INSET_FLOAT: + case LFUN_INSET_FOOTNOTE: + case LFUN_INSET_MARGINAL: + case LFUN_INSET_MINIPAGE: + case LFUN_INSET_OPTARG: + case LFUN_INSET_WIDE_FLOAT: + { + FuncRequest cmd = ev; + cmd.setView(bv_); + Inset * inset = createInset(cmd); + if (inset) { + bool gotsel = false; + + if (bv_->getLyXText()->selection.set()) { + bv_->getLyXText()->cutSelection(bv_, true, false); + gotsel = true; + } + + if (insertInset(inset)) { + inset->edit(bv_); + if (gotsel) + owner_->dispatch(FuncRequest(LFUN_PASTESELECTION)); + } + else + delete inset; + } + break; + } case LFUN_INSET_CAPTION: { @@ -1994,32 +1958,6 @@ void BufferView::Pimpl::smartQuote() } -void BufferView::Pimpl::insertAndEditInset(Inset * inset) -{ -#if 0 - if (insertInset(inset)) - inset->edit(bv_); - else - delete inset; -#else - bool gotsel = false; - - if (bv_->getLyXText()->selection.set()) { - bv_->getLyXText()->cutSelection(bv_, true, false); - gotsel = true; - } - - if (insertInset(inset)) { - inset->edit(bv_); - if (gotsel) - owner_->dispatch(FuncRequest(LFUN_PASTESELECTION)); - } - else - delete inset; -#endif -} - - // Open and lock an updatable inset bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind) { diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index c8c626d429..bd0bd26605 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -145,8 +145,6 @@ private: /// void smartQuote(); /// - void insertAndEditInset(Inset *); - /// void gotoInset(std::vector const & codes, bool same_content); /// diff --git a/src/Makefile.am b/src/Makefile.am index 24ddada57c..5e2aef1602 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -117,6 +117,8 @@ lyx_SOURCES = \ exporter.h \ gettext.C \ gettext.h \ + factory.h \ + factory.C \ funcrequest.h \ funcrequest.C \ importer.C \ diff --git a/src/factory.C b/src/factory.C new file mode 100644 index 0000000000..6decdacca2 --- /dev/null +++ b/src/factory.C @@ -0,0 +1,78 @@ + +#include "funcrequest.h" +#include "bufferparams.h" +#include "buffer.h" +#include "FloatList.h" +#include "debug.h" +#include "BufferView.h" +#include "insets/insetert.h" +#include "insets/insetexternal.h" +#include "insets/insetfloat.h" +#include "insets/insetfoot.h" +#include "insets/insetmarginal.h" +#include "insets/insetminipage.h" +#include "insets/insetnote.h" +#include "insets/insetoptarg.h" +#include "insets/insetparent.h" +#include "insets/insetref.h" +#include "insets/insettext.h" + + +Inset * createInset(FuncRequest const & cmd) +{ + BufferParams const & params = cmd.view()->buffer()->params; + + switch (cmd.action) { + + case LFUN_INSET_MINIPAGE: + return new InsetMinipage(params); + + case LFUN_INSERT_NOTE: + return new InsetNote(params); + + case LFUN_INSET_ERT: + return new InsetERT(params); + + case LFUN_INSET_EXTERNAL: + return new InsetExternal; + + case LFUN_INSET_FOOTNOTE: + return new InsetFoot(params); + + case LFUN_INSET_MARGINAL: + return new InsetMarginal(params); + + case LFUN_INSET_OPTARG: + return new InsetOptArg(params); + + case LFUN_INSET_FLOAT: + // check if the float type exist + if (floatList.typeExist(cmd.argument)) + return new InsetFloat(params, cmd.argument); + lyxerr << "Non-existent float type: " << cmd.argument << endl; + return 0; + + case LFUN_INSET_WIDE_FLOAT: + // check if the float type exist + if (floatList.typeExist(cmd.argument)) { + InsetFloat * p = new InsetFloat(params, cmd.argument); + p->wide(true); + } + lyxerr << "Non-existent float type: " << cmd.argument << endl; + return 0; + + #if 0 + case LFUN_INSET_LIST: + return new InsetList; + + case LFUN_INSET_THEOREM: + return new InsetTheorem; + #endif + + default: + break; + } + return 0; +} + + diff --git a/src/factory.h b/src/factory.h new file mode 100644 index 0000000000..65da9ce2c6 --- /dev/null +++ b/src/factory.h @@ -0,0 +1,21 @@ +// -*- C++ -*- +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 2002 The LyX Team. + * + * ====================================================== */ + +#ifndef FACTORY_H +#define FACTORY_H + +class Inset; +class FuncRequest; + +/// creates inset according to 'cmd' +Inset * createInset(FuncRequest const & cmd); + +#endif + diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 5bbd64be6c..4b8a9eaa76 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -230,7 +230,7 @@ void InsetFormula::draw(BufferView * bv, LyXFont const & font, //pi.pain.rectangle(x, y - a, w, h, LColor::mathframe); } - par_->draw(pi, x + 1, y); + par_->draw(pi, x, y); } xx += w;