]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetminipage.C
fix typo that put too many include paths for most people
[lyx.git] / src / insets / insetminipage.C
index 6ee1e765f7ae83acdd1fe017b8d968ba5ad8f5ab..9440b3def18b64e82fb2206cf3a5b100dad58802 100644 (file)
@@ -1,8 +1,8 @@
 /* This file is part of
  * ======================================================
- * 
+ *
  *           LyX, The Document Processor
- *      
+ *
  *          Copyright 1998 The LyX Team.
  *
  *======================================================*/
@@ -59,9 +59,9 @@ using std::endl;
 // have to output "" for minipages.
 // (Lgb)
 
-InsetMinipage::InsetMinipage()
-       : InsetCollapsable(), pos_(center),
-         inner_pos_(inner_center)
+InsetMinipage::InsetMinipage(BufferParams const & bp)
+       : InsetCollapsable(bp), pos_(center),
+         inner_pos_(inner_center), width_(100, LyXLength::PW)
 {
        setLabel(_("minipage"));
        LyXFont font(LyXFont::ALL_SANE);
@@ -71,11 +71,18 @@ InsetMinipage::InsetMinipage()
        setLabelFont(font);
 #if 0
        setAutoCollapse(false);
+#endif
+
+#if 0
+#ifdef WITH_WARNINGS
+#warning Remove this color definitions before 1.2.0 final!
 #endif
        // just for experimentation :)
-       setBackgroundColor(LColor::red);
+       setBackgroundColor(LColor::green);
+#endif
+
+       inset.setFrameColor(0, LColor::blue);
        setInsetName("Minipage");
-       width_ = "100%"; // set default to 100% of column_width
 }
 
 
@@ -98,25 +105,25 @@ InsetMinipage::~InsetMinipage()
 }
 
 
-void InsetMinipage::write(Buffer const * buf, ostream & os) const 
+void InsetMinipage::write(Buffer const * buf, ostream & os) const
 {
        os << getInsetName() << "\n"
           << "position " << pos_ << "\n"
           << "inner_position " << inner_pos_ << "\n"
-          << "height \"" << height_ << "\"\n"
-          << "width \"" << width_ << "\"\n";
+          << "height \"" << height_.asString() << "\"\n"
+          << "width \"" << width_.asString() << "\"\n";
        InsetCollapsable::write(buf, os);
 }
 
 
 void InsetMinipage::read(Buffer const * buf, LyXLex & lex)
 {
-       if (lex.IsOK()) {
+       if (lex.isOK()) {
                lex.next();
-               string const token = lex.GetString();
+               string const token = lex.getString();
                if (token == "position") {
                        lex.next();
-                       pos_ = static_cast<Position>(lex.GetInteger());
+                       pos_ = static_cast<Position>(lex.getInteger());
                } else {
                        lyxerr << "InsetMinipage::Read: Missing 'position'-tag!"
                                   << endl;
@@ -124,12 +131,12 @@ void InsetMinipage::read(Buffer const * buf, LyXLex & lex)
                        lex.pushToken(token);
                }
        }
-       if (lex.IsOK()) {
+       if (lex.isOK()) {
                lex.next();
-               string const token = lex.GetString();
+               string const token = lex.getString();
                if (token == "inner_position") {
                        lex.next();
-                       inner_pos_ = static_cast<InnerPosition>(lex.GetInteger());
+                       inner_pos_ = static_cast<InnerPosition>(lex.getInteger());
                } else {
                        lyxerr << "InsetMinipage::Read: Missing 'inner_position'-tag!"
                                   << endl;
@@ -137,12 +144,12 @@ void InsetMinipage::read(Buffer const * buf, LyXLex & lex)
                        lex.pushToken(token);
                }
        }
-       if (lex.IsOK()) {
+       if (lex.isOK()) {
                lex.next();
-               string const token = lex.GetString();
+               string const token = lex.getString();
                if (token == "height") {
                        lex.next();
-                       height_ = lex.GetString();
+                       height_ = LyXLength(lex.getString());
                } else {
                        lyxerr << "InsetMinipage::Read: Missing 'height'-tag!"
                                   << endl;
@@ -150,12 +157,12 @@ void InsetMinipage::read(Buffer const * buf, LyXLex & lex)
                        lex.pushToken(token);
                }
        }
-       if (lex.IsOK()) {
+       if (lex.isOK()) {
                lex.next();
-               string const token = lex.GetString();
+               string const token = lex.getString();
                if (token == "width") {
                        lex.next();
-                       width_ = lex.GetString();
+                       width_ = LyXLength(lex.getString());
                } else {
                        lyxerr << "InsetMinipage::Read: Missing 'width'-tag!"
                                   << endl;
@@ -237,8 +244,8 @@ int InsetMinipage::latex(Buffer const * buf,
                break;
        }
        os << "\\begin{minipage}[" << s_pos << "]{"
-          << LyXLength(width_).asLatexString() << "}%\n";
-       
+          << width_.asLatexString() << "}%\n";
+
        int i = inset.latex(buf, os, fragile, fp);
 
        os << "\\end{minipage}%\n";
@@ -255,7 +262,7 @@ bool InsetMinipage::insetAllowed(Inset::Code code) const
 }
 
 
-InsetMinipage::Position InsetMinipage::pos() const 
+InsetMinipage::Position InsetMinipage::pos() const
 {
        return pos_;
 }
@@ -282,13 +289,13 @@ void InsetMinipage::innerPos(InsetMinipage::InnerPosition ip)
 }
 
 
-string const & InsetMinipage::height() const
+LyXLength const & InsetMinipage::pageHeight() const
 {
        return height_;
 }
 
 
-void InsetMinipage::height(string const & ll)
+void InsetMinipage::pageHeight(LyXLength const & ll)
 {
        if (height_ != ll) {
                height_ = ll;
@@ -297,13 +304,13 @@ void InsetMinipage::height(string const & ll)
 }
 
 
-string const & InsetMinipage::width() const
+LyXLength const & InsetMinipage::pageWidth() const
 {
        return width_;
 }
 
 
-void InsetMinipage::width(string const & ll)
+void InsetMinipage::pageWidth(LyXLength const & ll)
 {
        if (ll != width_) {
                width_ = ll;
@@ -320,27 +327,28 @@ bool InsetMinipage::showInsetDialog(BufferView * bv) const
 }
 
 
-void InsetMinipage::insetButtonRelease(BufferView * bv, int x, int y,
-                                       int button)
-{
-       if (button == 3) {
-               showInsetDialog(bv);
-               return;
-       }
-       InsetCollapsable::insetButtonRelease(bv, x, y, button);
-}
-
-
 int InsetMinipage::getMaxWidth(BufferView * bv, UpdatableInset const * inset)
        const
 {
-       if (!width_.empty()) {
-               int ww1 = VSpace(width_).inPixels(bv);
+       if (owner() &&
+           static_cast<UpdatableInset*>(owner())->getMaxWidth(bv, inset) < 0) {
+               return -1;
+       }
+       if (!width_.zero()) {
+               int ww1 = latexTextWidth(bv);
                int ww2 = InsetCollapsable::getMaxWidth(bv, inset);
-               if (ww2 > 0 && ww2 < ww1)
+               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 width_.inPixels(InsetCollapsable::latexTextWidth(bv),
+                              bv->text->defaultHeight());
+}