]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetminipage.C
prevent crash when inserting minipage in table cell,
[lyx.git] / src / insets / insetminipage.C
index ecd4a0070d9c8cf21ad072582f09a8013469007b..7800b273abf176b22cfb31bc4e26fe057eb5dff1 100644 (file)
@@ -24,6 +24,7 @@
 #include "lyxlex.h"
 #include "lyxtext.h"
 #include "Lsstream.h"
+#include "metricsinfo.h"
 
 #include "frontends/LyXView.h"
 #include "frontends/Dialogs.h"
@@ -32,6 +33,7 @@
 
 using std::ostream;
 using std::endl;
+using std::auto_ptr;
 
 
 // Some information about Minipages in LaTeX:
@@ -93,9 +95,9 @@ InsetMinipage::InsetMinipage(InsetMinipage const & in)
 {}
 
 
-InsetBase * InsetMinipage::clone() const
+auto_ptr<InsetBase> InsetMinipage::clone() const
 {
-       return new InsetMinipage(*this);
+       return auto_ptr<InsetBase>(new InsetMinipage(*this));
 }
 
 
@@ -119,7 +121,6 @@ dispatch_result InsetMinipage::localDispatch(FuncRequest const & cmd)
                /* FIXME: I refuse to believe we have to live
                 * with ugliness like this ... */
                inset.getLyXText(cmd.view())->fullRebreak();
-               inset.update(cmd.view(), true);
                cmd.view()->updateInset(this);
                return DISPATCHED;
        }
@@ -221,7 +222,9 @@ void InsetMinipage::metrics(MetricsInfo & mi, Dimension & dim) const
                dimension_collapsed(dim);
        else {
                Dimension d;
-               InsetCollapsable::metrics(mi, d);
+               MetricsInfo m = mi;
+               m.base.textwidth = params_.width.inPixels(mi.base.textwidth);
+               InsetCollapsable::metrics(m, d);
                switch (params_.pos) {
                case top:
                        dim.asc = d.asc;
@@ -238,6 +241,7 @@ void InsetMinipage::metrics(MetricsInfo & mi, Dimension & dim) const
                }
                dim.wid = d.wid;
        }
+       dim_ = dim;
 }
 
 
@@ -272,9 +276,9 @@ int InsetMinipage::latex(Buffer const * buf, ostream & os,
 }
 
 
-bool InsetMinipage::insetAllowed(Inset::Code code) const
+bool InsetMinipage::insetAllowed(InsetOld::Code code) const
 {
-       if (code == Inset::FLOAT_CODE || code == Inset::MARGIN_CODE)
+       if (code == InsetOld::FLOAT_CODE || code == InsetOld::MARGIN_CODE)
                return false;
 
        return InsetCollapsable::insetAllowed(code);
@@ -293,26 +297,6 @@ bool InsetMinipage::showInsetDialog(BufferView * bv) const
 }
 
 
-int InsetMinipage::getMaxWidth(BufferView * bv, UpdatableInset const * inset)
-       const
-{
-       if (owner() &&
-           static_cast<UpdatableInset*>(owner())->getMaxWidth(bv, inset) < 0) {
-               return -1;
-       }
-       if (!params_.width.zero()) {
-               int ww1 = latexTextWidth(bv);
-               int ww2 = InsetCollapsable::getMaxWidth(bv, inset);
-               if (ww2 > 0 && ww2 < ww1) {
-                       return ww2;
-               }
-               return ww1;
-       }
-       // this should not happen!
-       return InsetCollapsable::getMaxWidth(bv, inset);
-}
-
-
 int InsetMinipage::latexTextWidth(BufferView * bv) const
 {
        return params_.width.inPixels(InsetCollapsable::latexTextWidth(bv));
@@ -333,7 +317,7 @@ InsetMinipageMailer::InsetMinipageMailer(InsetMinipage & inset)
 {}
 
 
-string const InsetMinipageMailer::inset2string() const
+string const InsetMinipageMailer::inset2string(Buffer const &) const
 {
        return params2string(inset_.params());
 }
@@ -348,7 +332,7 @@ void InsetMinipageMailer::string2params(string const & in,
                return;
 
        istringstream data(STRCONV(in));
-       LyXLex lex(0,0);
+       LyXLex lex(0, 0);
        lex.setStream(data);
 
        if (lex.isOK()) {