#include "insetinclude.h"
#include "buffer.h"
+#include "buffer_funcs.h"
#include "bufferlist.h"
#include "BufferView.h"
#include "debug.h"
#include "Lsstream.h"
#include "lyxlex.h"
#include "lyxrc.h"
-#include "Lsstream.h"
+#include "metricsinfo.h"
+#include "dimension.h"
#include "frontends/Dialogs.h"
#include "frontends/LyXView.h"
#include <cstdlib>
+using namespace lyx::support;
+
using std::ostream;
using std::endl;
using std::vector;
using std::pair;
+using std::auto_ptr;
+
extern BufferList bufferlist;
-class InsetInclude::PreviewImpl : public grfx::PreviewedInset {
+class InsetInclude::PreviewImpl : public lyx::graphics::PreviewedInset {
public:
///
PreviewImpl(InsetInclude & p) : PreviewedInset(p) {}
InsetInclude::InsetInclude(Params const & p)
: params_(p), include_label(uniqueID()),
- preview_(new PreviewImpl(*this))
+ preview_(new PreviewImpl(*this)),
+ set_label_(false)
{}
InsetInclude::InsetInclude(InsetCommandParams const & p, Buffer const & b)
: include_label(uniqueID()),
- preview_(new PreviewImpl(*this))
+ preview_(new PreviewImpl(*this)),
+ set_label_(false)
{
params_.cparams = p;
params_.masterFilename_ = b.fileName();
}
+InsetInclude::InsetInclude(InsetInclude const & other)
+ : InsetOld(other),
+ params_(other.params_),
+ include_label(other.include_label),
+ preview_(new PreviewImpl(*this)),
+ set_label_(other.set_label_)
+{}
+
+
InsetInclude::~InsetInclude()
{
InsetIncludeMailer mailer(*this);
return DISPATCHED;
}
- case LFUN_INSET_DIALOG_UPDATE:
+ case LFUN_INSET_DIALOG_UPDATE:
InsetIncludeMailer(*this).updateDialog(cmd.view());
return DISPATCHED;
return DISPATCHED;
default:
- return UNDISPATCHED;
+ return InsetOld::localDispatch(cmd);
}
}
if (preview_->monitoring())
preview_->stopMonitoring();
- if (grfx::PreviewedInset::activated() && params_.flag == INPUT)
+ if (lyx::graphics::PreviewedInset::activated() && params_.flag == INPUT)
preview_->generatePreview();
}
-Inset * InsetInclude::clone(Buffer const & buffer, bool) const
+auto_ptr<InsetBase> InsetInclude::clone() const
{
- Params p(params_);
- p.masterFilename_ = buffer.fileName();
+ //Params p(params_);
+ //p.masterFilename_ = buffer.fileName();
+#warning FIXME: broken cross-doc copy/paste - must fix
- return new InsetInclude(p);
+ return auto_ptr<InsetBase>(new InsetInclude(params_));
}
FileInfo finfo(getFileName());
if (!finfo.isOK())
return false;
-
- return bufferlist.loadLyXFile(getFileName(), false) != 0;
+ return loadLyXFile(bufferlist.newBuffer(getFileName()),
+ getFileName());
}
int InsetInclude::latex(Buffer const * buffer, ostream & os,
- LatexRunParams const & runparams,
- bool /*fragile*/, bool /*fs*/) const
+ LatexRunParams const & runparams) const
{
string incfile(params_.cparams.getContents());
tmp->markDepClean(buffer->tmppath);
tmp->makeLaTeXFile(writefile, OnlyPath(getMasterFilename()),
- runparams, true);
+ runparams, false);
}
if (isVerbatim()) {
}
-vector<string> const InsetInclude::getLabelList() const
+void InsetInclude::getLabelList(std::vector<string> & list) const
{
- vector<string> l;
-
if (loadIfNeeded()) {
Buffer * tmp = bufferlist.getBuffer(getFileName());
tmp->setParentName("");
- l = tmp->getLabelList();
+ tmp->getLabelList(list);
tmp->setParentName(getMasterFilename());
}
-
- return l;
}
-void InsetInclude::fillWithBibKeys(vector<pair<string,string> > & keys) const
+void InsetInclude::fillWithBibKeys(std::vector<std::pair<string,string> > & keys) const
{
if (loadIfNeeded()) {
Buffer * tmp = bufferlist.getBuffer(getFileName());
}
-int InsetInclude::ascent(BufferView * bv, LyXFont const & font) const
-{
- return preview_->previewReady() ?
- preview_->pimage()->ascent() : InsetButton::ascent(bv, font);
-}
-
-
-int InsetInclude::descent(BufferView * bv, LyXFont const & font) const
+void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
{
- return preview_->previewReady() ?
- preview_->pimage()->descent() : InsetButton::descent(bv, font);
-}
-
-
-int InsetInclude::width(BufferView * bv, LyXFont const & font) const
-{
- return preview_->previewReady() ?
- preview_->pimage()->width() : InsetButton::width(bv, font);
+ if (preview_->previewReady()) {
+ dim.asc = preview_->pimage()->ascent();
+ dim.des = preview_->pimage()->descent();
+ dim.wid = preview_->pimage()->width();
+ } else {
+ if (!set_label_) {
+ set_label_ = true;
+ button_.update(getScreenLabel(mi.base.bv->buffer()),
+ editable() != NOT_EDITABLE);
+ }
+ button_.metrics(mi, dim);
+ }
+ dim_ = dim;
}
-void InsetInclude::draw(BufferView * bv, LyXFont const & font, int y,
- float & xx) const
+void InsetInclude::draw(PainterInfo & pi, int x, int y) const
{
- cache(bv);
+ cache(pi.base.bv);
if (!preview_->previewReady()) {
- InsetButton::draw(bv, font, y, xx);
+ button_.draw(pi, x, y);
return;
}
if (!preview_->monitoring())
preview_->startMonitoring();
- int const x = int(xx);
- int const w = width(bv, font);
- int const d = descent(bv, font);
- int const a = ascent(bv, font);
- int const h = a + d;
-
- bv->painter().image(x, y - a, w, h,
+ pi.pain.image(x, y - dim_.asc, dim_.wid, dim_.height(),
*(preview_->pimage()->image()));
+}
- xx += w;
+
+BufferView * InsetInclude::view() const
+{
+ return button_.view();
}
// preview stuff
//
-void InsetInclude::addPreview(grfx::PreviewLoader & ploader) const
+void InsetInclude::addPreview(lyx::graphics::PreviewLoader & ploader) const
{
preview_->addPreview(ploader);
}
ostringstream os;
LatexRunParams runparams;
runparams.flavor = LatexRunParams::LATEX;
- parent().latex(view()->buffer(), os, runparams, false, false);
+ parent().latex(view()->buffer(), os, runparams);
return STRCONV(os.str());
}
{}
-string const InsetIncludeMailer::inset2string() const
+string const InsetIncludeMailer::inset2string(Buffer const &) const
{
return params2string(inset_.params());
}
if (in.empty())
return;
-
+
istringstream data(STRCONV(in));
LyXLex lex(0,0);
lex.setStream(data);