]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetert.C
Enable the external inset to handle unknown templates gracefully.
[lyx.git] / src / insets / insetert.C
index 0e53c9db9ced9656d26f70f448f22ee509a41c91..4a6888091f1e5aca24a0a23463045ef511755fdb 100644 (file)
@@ -31,7 +31,7 @@
 
 #include "support/LOstream.h"
 #include "support/LAssert.h"
-#include "support/lstrings.h"
+#include "support/tostr.h"
 
 
 using std::ostream;
@@ -63,16 +63,16 @@ InsetERT::InsetERT(BufferParams const & bp, bool collapsed)
 }
 
 
-InsetERT::InsetERT(InsetERT const & in, bool same_id)
-       : InsetCollapsable(in, same_id), status_(in.status_)
+InsetERT::InsetERT(InsetERT const & in)
+       : InsetCollapsable(in), status_(in.status_)
 {
        init();
 }
 
 
-Inset * InsetERT::clone(Buffer const &, bool same_id) const
+Inset * InsetERT::clone() const
 {
-       return new InsetERT(*const_cast<InsetERT *>(this), same_id);
+       return new InsetERT(*this);
 }
 
 
@@ -266,22 +266,6 @@ void InsetERT::updateStatus(BufferView * bv, bool swap) const
        }
 }
 
-void InsetERT::edit(BufferView * bv, int x, int y, mouse_button::state button)
-{
-       if (button == mouse_button::button3)
-               return;
-
-       if (status_ == Inlined) {
-               if (!bv->lockInset(this))
-                       return;
-               inset.edit(bv, x, y, button);
-       } else {
-               InsetCollapsable::edit(bv, x, y, button);
-       }
-       set_latex_font(bv);
-       updateStatus(bv);
-}
-
 
 Inset::EDITABLE InsetERT::editable() const
 {
@@ -291,14 +275,6 @@ Inset::EDITABLE InsetERT::editable() const
 }
 
 
-void InsetERT::edit(BufferView * bv, bool front)
-{
-       InsetCollapsable::edit(bv, front);
-       updateStatus(0);
-       set_latex_font(bv);
-}
-
-
 void InsetERT::lfunMousePress(FuncRequest const & cmd)
 {
        if (status_ == Inlined)
@@ -330,7 +306,7 @@ bool InsetERT::lfunMouseRelease(FuncRequest const & cmd)
                if (status_ == Inlined)
                        inset.localDispatch(cmd1);
                else if (!collapsed_ && (cmd.y > button_bottom_y)) {
-                       cmd1.y -= ascent_collapsed() + descent_collapsed();
+                       cmd1.y -= height_collapsed();
                        inset.localDispatch(cmd1);
                }
        }
@@ -347,8 +323,8 @@ void InsetERT::lfunMouseMotion(FuncRequest const & cmd)
 }
 
 
-int InsetERT::latex(Buffer const *, ostream & os, bool /*fragile*/,
-                   bool /*free_spc*/) const
+int InsetERT::latex(Buffer const *, ostream & os,
+                   LatexRunParams const &) const
 {
        ParagraphList::iterator par = inset.paragraphs.begin();
        ParagraphList::iterator end = inset.paragraphs.end();
@@ -370,8 +346,8 @@ int InsetERT::latex(Buffer const *, ostream & os, bool /*fragile*/,
                }
                ++par;
                if (par != end) {
-                       os << "\n\n";
-                       lines += 2;
+                       os << "\n";
+                       ++lines;
                }
        }
 
@@ -449,6 +425,21 @@ Inset::RESULT InsetERT::localDispatch(FuncRequest const & cmd)
        }
 
        switch (cmd.action) {
+
+       case LFUN_INSET_EDIT:
+               if (cmd.button() == mouse_button::button3)
+                       break;
+               if (status_ == Inlined) {
+                       if (!bv->lockInset(this))
+                               break;
+                       result = inset.localDispatch(cmd);
+               } else {
+                       result = InsetCollapsable::localDispatch(cmd);
+               }
+               set_latex_font(bv);
+               updateStatus(bv);
+               break;
+
        case LFUN_INSET_MODIFY: {
                InsetERT::ERTStatus status_;
                InsetERTMailer::string2params(cmd.argument, status_);
@@ -561,37 +552,18 @@ bool InsetERT::checkInsertChar(LyXFont & /* font */)
 }
 
 
-int InsetERT::ascent(BufferView * bv, LyXFont const & font) const
-{
-       if (!inlined())
-               return InsetCollapsable::ascent(bv, font);
-
-       return inset.ascent(bv, font);
-}
-
-
-int InsetERT::descent(BufferView * bv, LyXFont const & font) const
-{
-       if (!inlined())
-               return InsetCollapsable::descent(bv, font);
-
-       return inset.descent(bv, font);
-}
-
-
-int InsetERT::width(BufferView * bv, LyXFont const & font) const
+void InsetERT::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       if (!inlined())
-               return InsetCollapsable::width(bv, font);
-
-       return inset.width(bv, font);
+       if (inlined())
+               inset.metrics(mi, dim);
+       else
+               InsetCollapsable::metrics(mi, dim);
 }
 
 
-void InsetERT::draw(BufferView * bv, LyXFont const & f,
-                   int baseline, float & x) const
+void InsetERT::draw(PainterInfo & pi, int x, int y) const
 {
-       InsetCollapsable::draw(bv, f, baseline, x, inlined());
+       InsetCollapsable::draw(pi, x, y, inlined());
 }