]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetBox.cpp
* src/paragraph_funcs.cpp (breakParagraph): change parameter 'flag' to
[lyx.git] / src / insets / InsetBox.cpp
index 9d7ebac301273cc4c544ee5c63d8471918dc48ed..2b10cd663d6e75229cb49fcd5fcb105cb837b28f 100644 (file)
@@ -25,7 +25,6 @@
 #include "Color.h"
 #include "Lexer.h"
 #include "MetricsInfo.h"
-#include "TextMetrics.h"
 
 #include "support/Translator.h"
 
@@ -34,7 +33,6 @@
 
 namespace lyx {
 
-using std::auto_ptr;
 using std::string;
 using std::istringstream;
 using std::ostream;
@@ -113,9 +111,9 @@ InsetBox::~InsetBox()
 }
 
 
-auto_ptr<Inset> InsetBox::doClone() const
+Inset * InsetBox::clone() const
 {
-       return auto_ptr<Inset>(new InsetBox(*this));
+       return new InsetBox(*this);
 }
 
 
@@ -173,20 +171,15 @@ bool InsetBox::hasFixedWidth() const
 }
 
 
-bool InsetBox::metrics(MetricsInfo & m, Dimension & dim) const
+void InsetBox::metrics(MetricsInfo & m, Dimension & dim) const
 {
-       MetricsInfo mi = m;
-       // first round in order to know the minimum size.
-       InsetCollapsable::metrics(mi, dim);
-       TextMetrics & tm = mi.base.bv->textMetrics(&text_);
+       // back up textwidth.
+       int textwidth_backup = m.base.textwidth;
        if (hasFixedWidth())
-               mi.base.textwidth =
-                       std::max(tm.width() + 2 * border_ + (int) (2.5 * TEXT_TO_INSET_OFFSET),
-                                params_.width.inPixels(m.base.textwidth));
-       InsetCollapsable::metrics(mi, dim);
-       bool const changed = dim_ != dim;
-       dim_ = dim;
-       return changed;
+               m.base.textwidth = params_.width.inPixels(m.base.textwidth);
+       InsetCollapsable::metrics(m, dim);
+       // retore textwidth.
+       m.base.textwidth = textwidth_backup;
 }
 
 
@@ -340,14 +333,20 @@ int InsetBox::latex(Buffer const & buf, odocstream & os,
                os << "[" << params_.pos << "]";
                if (params_.height_special == "none") {
                        // FIXME UNICODE
-                       os << '[' << from_ascii(params_.height.asLatexString())
-                          << ']';
+                       os << "[" << from_ascii(params_.height.asLatexString()) << "]";
                } else {
                        // Special heights
-                       // FIXME UNICODE
-                       os << "[" << params_.height.value()
-                          << '\\' << from_utf8(params_.height_special)
-                          << ']';
+                       // set no optional argument when the value is the default "1\height"
+                       // (special units like \height are handled as "in")
+                       // but when the user has chosen a non-default inner_pos, the height
+                       // must be given: \minipage[pos][height][inner-pos]{width}
+                       if ((params_.height != Length("1in") ||
+                                params_.height_special != "totalheight") ||
+                               params_.inner_pos != params_.pos) {
+                               // FIXME UNICODE
+                               os << "[" << params_.height.value()
+                                       << "\\" << from_utf8(params_.height_special) << "]";
+                       }
                }
                if (params_.inner_pos != params_.pos)
                        os << "[" << params_.inner_pos << "]";