the factory stuff

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5115 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2002-08-27 10:14:56 +00:00
parent 6894562a13
commit ea8e13cd2f
6 changed files with 134 additions and 97 deletions

View File

@ -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)
{

View File

@ -145,8 +145,6 @@ private:
///
void smartQuote();
///
void insertAndEditInset(Inset *);
///
void gotoInset(std::vector<Inset::Code> const & codes,
bool same_content);
///

View File

@ -117,6 +117,8 @@ lyx_SOURCES = \
exporter.h \
gettext.C \
gettext.h \
factory.h \
factory.C \
funcrequest.h \
funcrequest.C \
importer.C \

78
src/factory.C Normal file
View File

@ -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;
}

21
src/factory.h Normal file
View File

@ -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

View File

@ -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;