]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetbox.C
* In the process of fixing the math background color bug, this commit transfer backgr...
[lyx.git] / src / insets / insetbox.C
index 13495a6018ede88ac12da75d1645b592a069070f..6e07db2cac7ef45c712d93b0eb10b0d2a07a0ffe 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "insetbox.h"
 
+#include "BufferView.h"
 #include "cursor.h"
 #include "dispatchresult.h"
 #include "debug.h"
@@ -25,6 +26,7 @@
 #include "lyxlex.h"
 #include "metricsinfo.h"
 #include "paragraph.h"
+#include "TextMetrics.h"
 
 #include "support/translator.h"
 
@@ -177,8 +179,13 @@ bool InsetBox::hasFixedWidth() const
 bool 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_);
        if (hasFixedWidth())
-               mi.base.textwidth = params_.width.inPixels(m.base.textwidth);
+               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;
@@ -407,7 +414,7 @@ int InsetBox::plaintext(Buffer const & buf, odocstream & os,
 
        int len = 0;
        switch (btype) {
-               case Frameless: break;
+               case Frameless: os << "\n";            break;
                case Boxed:     os << "\n]";  len = 1; break;
                case ovalbox:   os << "\n)";  len = 1; break;
                case Ovalbox:   os << "\n))"; len = 2; break;
@@ -428,16 +435,18 @@ int InsetBox::docbook(Buffer const & buf, odocstream & os,
 
 void InsetBox::validate(LaTeXFeatures & features) const
 {
-       features.require("calc");
        BoxType btype = boxtranslator().find(params_.type);
        switch (btype) {
        case Frameless:
+               break;
        case Boxed:
+               features.require("calc");
                break;
        case ovalbox:
        case Ovalbox:
        case Shadowbox:
        case Doublebox:
+               features.require("calc");
                features.require("fancybox");
                break;
        }
@@ -529,15 +538,17 @@ void InsetBoxParams::read(LyXLex & lex)
        if (!lex.isOK())
                return;
 
-       if (lex.isOK()) {
-               lex.next();
-               type = lex.getString();
-       }
-       if (!lex.isOK())
+       lex.next();
+       type = lex.getString();
+
+       if (!lex)
                return;
+
        lex.next();
        string token;
        token = lex.getString();
+       if (!lex)
+               return;
        if (token == "position") {
                lex.next();
                // The [0] is needed. We need the first and only char in
@@ -547,10 +558,11 @@ void InsetBoxParams::read(LyXLex & lex)
                lyxerr << "InsetBox::Read: Missing 'position'-tag!" << token << endl;
                lex.pushToken(token);
        }
-       if (!lex.isOK())
-               return;
+
        lex.next();
        token = lex.getString();
+       if (!lex)
+               return;
        if (token == "hor_pos") {
                lex.next();
                hor_pos = lex.getString()[0];
@@ -558,10 +570,11 @@ void InsetBoxParams::read(LyXLex & lex)
                lyxerr << "InsetBox::Read: Missing 'hor_pos'-tag!" << token << endl;
                lex.pushToken(token);
        }
-       if (!lex.isOK())
-               return;
+
        lex.next();
        token = lex.getString();
+       if (!lex)
+               return;
        if (token == "has_inner_box") {
                lex.next();
                inner_box = lex.getInteger();
@@ -570,10 +583,10 @@ void InsetBoxParams::read(LyXLex & lex)
                lex.pushToken(token);
        }
 
-       if (!lex.isOK())
-               return;
        lex.next();
        token = lex.getString();
+       if (!lex)
+               return;
        if (token == "inner_pos") {
                lex.next();
                inner_pos = lex.getString()[0];
@@ -582,10 +595,11 @@ void InsetBoxParams::read(LyXLex & lex)
                        << token << endl;
                lex.pushToken(token);
        }
-       if (!lex.isOK())
-               return;
+
        lex.next();
        token = lex.getString();
+       if (!lex)
+               return;
        if (token == "use_parbox") {
                lex.next();
                use_parbox = lex.getInteger();
@@ -593,10 +607,11 @@ void InsetBoxParams::read(LyXLex & lex)
                lyxerr << "InsetBox::Read: Missing 'use_parbox'-tag!" << endl;
                lex.pushToken(token);
        }
-       if (!lex.isOK())
-               return;
+
        lex.next();
        token = lex.getString();
+       if (!lex)
+               return;
        if (token == "width") {
                lex.next();
                width = LyXLength(lex.getString());
@@ -604,10 +619,11 @@ void InsetBoxParams::read(LyXLex & lex)
                lyxerr << "InsetBox::Read: Missing 'width'-tag!" << endl;
                lex.pushToken(token);
        }
-       if (!lex.isOK())
-               return;
+
        lex.next();
        token = lex.getString();
+       if (!lex)
+               return;
        if (token == "special") {
                lex.next();
                special = lex.getString();
@@ -615,10 +631,11 @@ void InsetBoxParams::read(LyXLex & lex)
                lyxerr << "InsetBox::Read: Missing 'special'-tag!" << endl;
                lex.pushToken(token);
        }
-       if (!lex.isOK())
-               return;
+
        lex.next();
        token = lex.getString();
+       if (!lex)
+               return;
        if (token == "height") {
                lex.next();
                height = LyXLength(lex.getString());
@@ -626,10 +643,11 @@ void InsetBoxParams::read(LyXLex & lex)
                lyxerr << "InsetBox::Read: Missing 'height'-tag!" << endl;
                lex.pushToken(token);
        }
-       if (!lex.isOK())
-               return;
+
        lex.next();
        token = lex.getString();
+       if (!lex)
+               return;
        if (token == "height_special") {
                lex.next();
                height_special = lex.getString();