]> 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 eae86d044070dd31e5f71832495f8d908f525f7a..2b10cd663d6e75229cb49fcd5fcb105cb837b28f 100644 (file)
 #include "InsetBox.h"
 
 #include "BufferView.h"
-#include "cursor.h"
-#include "dispatchresult.h"
+#include "Cursor.h"
+#include "DispatchResult.h"
 #include "debug.h"
 #include "FuncStatus.h"
-#include "funcrequest.h"
+#include "FuncRequest.h"
 #include "gettext.h"
 #include "LaTeXFeatures.h"
-#include "LColor.h"
-#include "lyxlex.h"
-#include "metricsinfo.h"
-#include "paragraph.h"
-#include "TextMetrics.h"
+#include "Color.h"
+#include "Lexer.h"
+#include "MetricsInfo.h"
 
-#include "support/translator.h"
+#include "support/Translator.h"
 
 #include <sstream>
 
 
 namespace lyx {
 
-using std::auto_ptr;
 using std::string;
 using std::istringstream;
 using std::ostream;
@@ -90,7 +87,6 @@ BoxTranslatorLoc const & boxtranslator_loc()
 
 void InsetBox::init()
 {
-       setInsetName(from_ascii("Box"));
        setButtonLabel();
 }
 
@@ -115,9 +111,9 @@ InsetBox::~InsetBox()
 }
 
 
-auto_ptr<InsetBase> InsetBox::doClone() const
+Inset * InsetBox::clone() const
 {
-       return auto_ptr<InsetBase>(new InsetBox(*this));
+       return new InsetBox(*this);
 }
 
 
@@ -134,7 +130,7 @@ void InsetBox::write(Buffer const & buf, ostream & os) const
 }
 
 
-void InsetBox::read(Buffer const & buf, LyXLex & lex)
+void InsetBox::read(Buffer const & buf, Lexer & lex)
 {
        params_.read(lex);
        InsetCollapsable::read(buf, lex);
@@ -144,7 +140,7 @@ void InsetBox::read(Buffer const & buf, LyXLex & lex)
 
 void InsetBox::setButtonLabel()
 {
-       LyXFont font(LyXFont::ALL_SANE);
+       Font font(Font::ALL_SANE);
        font.decSize();
        font.decSize();
 
@@ -164,8 +160,7 @@ void InsetBox::setButtonLabel()
 
        setLabel(label);
 
-       font.setColor(LColor::foreground);
-       setBackgroundColor(LColor::background);
+       font.setColor(Color::foreground);
        setLabelFont(font);
 }
 
@@ -176,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;
 }
 
 
@@ -206,7 +196,7 @@ bool InsetBox::showInsetDialog(BufferView * bv) const
 }
 
 
-void InsetBox::doDispatch(LCursor & cur, FuncRequest & cmd)
+void InsetBox::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
 
@@ -236,7 +226,7 @@ void InsetBox::doDispatch(LCursor & cur, FuncRequest & cmd)
 }
 
 
-bool InsetBox::getStatus(LCursor & cur, FuncRequest const & cmd,
+bool InsetBox::getStatus(Cursor & cur, FuncRequest const & cmd,
                FuncStatus & flag) const
 {
        switch (cmd.action) {
@@ -260,7 +250,7 @@ bool InsetBox::getStatus(LCursor & cur, FuncRequest const & cmd,
 
 
 int InsetBox::latex(Buffer const & buf, odocstream & os,
-                    OutputParams const & runparams) const
+                   OutputParams const & runparams) const
 {
        BoxType btype = boxtranslator().find(params_.type);
 
@@ -343,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 << "]";
@@ -397,7 +393,7 @@ int InsetBox::latex(Buffer const & buf, odocstream & os,
 
 
 int InsetBox::plaintext(Buffer const & buf, odocstream & os,
-                        OutputParams const & runparams) const
+                       OutputParams const & runparams) const
 {
        BoxType const btype = boxtranslator().find(params_.type);
 
@@ -427,7 +423,7 @@ int InsetBox::plaintext(Buffer const & buf, odocstream & os,
 
 
 int InsetBox::docbook(Buffer const & buf, odocstream & os,
-                      OutputParams const & runparams) const
+                     OutputParams const & runparams) const
 {
        return InsetText::docbook(buf, os, runparams);
 }
@@ -485,7 +481,7 @@ void InsetBoxMailer::string2params(string const & in,
                return;
 
        istringstream data(in);
-       LyXLex lex(0,0);
+       Lexer lex(0,0);
        lex.setStream(data);
 
        string name;
@@ -494,7 +490,7 @@ void InsetBoxMailer::string2params(string const & in,
                return print_mailer_error("InsetBoxMailer", in, 1, name_);
 
        // This is part of the inset proper that is usually swallowed
-       // by LyXText::readInset
+       // by Text::readInset
        string id;
        lex >> id;
        if (!lex || id != "Box")
@@ -508,12 +504,12 @@ InsetBoxParams::InsetBoxParams(string const & label)
        : type(label),
          use_parbox(false),
          inner_box(true),
-         width(LyXLength("100col%")),
+         width(Length("100col%")),
          special("none"),
          pos('t'),
          hor_pos('c'),
          inner_pos('t'),
-         height(LyXLength("1in")),
+         height(Length("1in")),
          height_special("totalheight") // default is 1\\totalheight
 {}
 
@@ -533,7 +529,7 @@ void InsetBoxParams::write(ostream & os) const
 }
 
 
-void InsetBoxParams::read(LyXLex & lex)
+void InsetBoxParams::read(Lexer & lex)
 {
        if (!lex.isOK())
                return;
@@ -614,7 +610,7 @@ void InsetBoxParams::read(LyXLex & lex)
                return;
        if (token == "width") {
                lex.next();
-               width = LyXLength(lex.getString());
+               width = Length(lex.getString());
        } else {
                lyxerr << "InsetBox::Read: Missing 'width'-tag!" << endl;
                lex.pushToken(token);
@@ -638,7 +634,7 @@ void InsetBoxParams::read(LyXLex & lex)
                return;
        if (token == "height") {
                lex.next();
-               height = LyXLength(lex.getString());
+               height = Length(lex.getString());
        } else {
                lyxerr << "InsetBox::Read: Missing 'height'-tag!" << endl;
                lex.pushToken(token);