]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetinclude.C
Enable the external inset to handle unknown templates gracefully.
[lyx.git] / src / insets / insetinclude.C
index fa8bd85bf81c4e90b16f9c0f7a9d0a9fd96d710e..6b25e65864ae634917b44f4720f1e97f1a453e60 100644 (file)
@@ -22,7 +22,8 @@
 #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"
@@ -126,7 +127,7 @@ dispatch_result InsetInclude::localDispatch(FuncRequest const & cmd)
                return DISPATCHED;
        }
 
-       case LFUN_INSET_DIALOG_UPDATE: 
+       case LFUN_INSET_DIALOG_UPDATE:
                InsetIncludeMailer(*this).updateDialog(cmd.view());
                return DISPATCHED;
 
@@ -136,7 +137,7 @@ dispatch_result InsetInclude::localDispatch(FuncRequest const & cmd)
                return DISPATCHED;
 
        default:
-               return UNDISPATCHED;
+               return InsetButton::localDispatch(cmd);
        }
 }
 
@@ -191,12 +192,13 @@ void InsetInclude::set(Params const & p)
 }
 
 
-Inset * InsetInclude::clone(Buffer const & buffer, bool) const
+Inset * 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 new InsetInclude(params_);
 }
 
 
@@ -286,8 +288,7 @@ bool InsetInclude::loadIfNeeded() const
 
 
 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());
 
@@ -313,8 +314,7 @@ int InsetInclude::latex(Buffer const * buffer, ostream & os,
                // write it to a file (so far the complete file)
                string writefile = ChangeExtension(getFileName(), ".tex");
 
-               if (!buffer->tmppath.empty()
-                   && !buffer->niceFile) {
+               if (!buffer->tmppath.empty() && !runparams.nice) {
                        incfile = subst(incfile, '/','@');
 #ifdef __EMX__
                        incfile = subst(incfile, ':', '$');
@@ -328,10 +328,8 @@ int InsetInclude::latex(Buffer const * buffer, ostream & os,
 
                tmp->markDepClean(buffer->tmppath);
 
-               tmp->makeLaTeXFile(writefile,
-                                  OnlyPath(getMasterFilename()),
-                                  runparams,
-                                  buffer->niceFile, true);
+               tmp->makeLaTeXFile(writefile, OnlyPath(getMasterFilename()),
+                                  runparams, true);
        }
 
        if (isVerbatim()) {
@@ -506,49 +504,32 @@ void InsetInclude::fillWithBibKeys(vector<pair<string,string> > & keys) const
 }
 
 
-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
-{
-       return preview_->previewReady() ?
-               preview_->pimage()->descent() : InsetButton::descent(bv, font);
-}
-
-
-int InsetInclude::width(BufferView * bv, LyXFont const & font) const
+void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) 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 {
+               InsetButton::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);
+               InsetButton::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;
 }
 
 
@@ -578,7 +559,7 @@ string const InsetInclude::PreviewImpl::latexString() const
        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());
 }
@@ -622,7 +603,7 @@ void InsetIncludeMailer::string2params(string const & in,
 
        if (in.empty())
                return;
-       
+
        istringstream data(STRCONV(in));
        LyXLex lex(0,0);
        lex.setStream(data);