]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetminipage.C
fix compilation pb ; update eu.po
[lyx.git] / src / insets / insetminipage.C
index aafab15c0e4579e9ef3405ddcea7eba1bdce1116..d0d9ea13157a37d3a07c9a775f997dbb4960db1f 100644 (file)
 #include "gettext.h"
 #include "lyxfont.h"
 #include "BufferView.h"
+#include "LyXView.h"
+#include "frontends/Dialogs.h"
 #include "lyxtext.h"
 #include "insets/insettext.h"
 #include "support/LOstream.h"
+#include "support/lstrings.h"
 #include "debug.h"
+#include "gettext.h"
 
 using std::ostream;
 using std::endl;
@@ -66,26 +70,175 @@ InsetMinipage::InsetMinipage()
        setLabelFont(font);
        setAutoCollapse(false);
        setInsetName("Minipage");
+       width_ = "100%"; // set default to 100% of column_width
+}
+
+
+InsetMinipage::~InsetMinipage()
+{
+       hideDialog();
 }
 
 
 void InsetMinipage::Write(Buffer const * buf, ostream & os) const 
 {
-       os << getInsetName() << "\n";
+       os << getInsetName() << "\n"
+          << "position " << pos_ << "\n"
+          << "inner_position " << inner_pos_ << "\n"
+          << "height \"" << height_ << "\"\n"
+          << "width \"" << width_ << "\"\n";
        InsetCollapsable::Write(buf, os);
 }
 
 
+void InsetMinipage::Read(Buffer const * buf, LyXLex & lex)
+{
+    string token;
+
+    if (lex.IsOK()) {
+       lex.next();
+       token = lex.GetString();
+       if (token == "position") {
+           lex.next();
+           pos_ = static_cast<Position>(lex.GetInteger());
+           token = string();
+       } else {
+               lyxerr << "InsetMinipage::Read: Missing 'position'-tag!"
+                      << endl;
+       }
+    }
+    if (lex.IsOK()) {
+       if (token.empty()) {
+           lex.next();
+           token = lex.GetString();
+       }
+       if (token == "inner_position") {
+           lex.next();
+           inner_pos_ = static_cast<InnerPosition>(lex.GetInteger());
+           token = string();
+       } else {
+               lyxerr << "InsetMinipage::Read: Missing 'inner_position'-tag!"
+                      << endl;
+       }
+    }
+    if (lex.IsOK()) {
+       if (token.empty()) {
+           lex.next();
+           token = lex.GetString();
+       }
+       if (token == "height") {
+           lex.next();
+           height_ = lex.GetString();
+           token = string();
+       } else {
+               lyxerr << "InsetMinipage::Read: Missing 'height'-tag!"
+                      << endl;
+       }
+    }
+    if (lex.IsOK()) {
+       if (token.empty()) {
+           lex.next();
+           token = lex.GetString();
+       }
+       if (token == "width") {
+           lex.next();
+           width_ = lex.GetString();
+           token = string();
+       } else {
+               lyxerr << "InsetMinipage::Read: Missing 'width'-tag!"
+                      << endl;
+       }
+    }
+#ifdef WITH_WARNINGS
+#warning Remove me before final 1.2.0 (Jug)
+#warning Can we please remove this as soon as possible? (Lgb)
+#endif
+    // this is only for compatibility to the intermediate format and should
+    // vanish till the final 1.2.0!
+    if (lex.IsOK()) {
+       if (token.empty()) {
+           lex.next();
+           token = lex.GetString();
+       }
+       if (token == "widthp") {
+           lex.next();
+           // only do this if the width_-string was not already set!
+           if (width_.empty())
+               width_ = lex.GetString() + "%";
+           token = string();
+       } else {
+               lyxerr << "InsetMinipage::Read: Missing 'widthp_'-tag!"
+                      << endl;
+       }
+    }
+    if (!token.empty())
+       lex.pushToken(token);
+    InsetCollapsable::Read(buf, lex);
+}
+
+
 Inset * InsetMinipage::Clone(Buffer const &) const
 {
        InsetMinipage * result = new InsetMinipage;
-       result->inset->init(inset);
+       result->inset.init(&inset);
        
        result->collapsed = collapsed;
+       result->pos_ = pos_;
+       result->inner_pos_ = inner_pos_;
+       result->height_ = height_;
+       result->width_ = width_;
        return result;
 }
 
 
+int InsetMinipage::ascent(BufferView * bv, LyXFont const & font) const
+{
+       if (collapsed)
+               return ascent_collapsed(bv->painter(), font);
+       else {
+               // Take placement into account.
+               int i = 0;
+               switch (pos_) {
+               case top:
+                       i = InsetCollapsable::ascent(bv, font);
+                       break;
+               case center:
+                       i = (InsetCollapsable::ascent(bv, font)
+                            + InsetCollapsable::descent(bv, font)) / 2;
+                       break;
+               case bottom:
+                       i = InsetCollapsable::descent(bv, font);
+                       break;
+               }
+               return i;
+       }
+}
+
+
+int InsetMinipage::descent(BufferView * bv, LyXFont const & font) const
+{
+       if (collapsed)
+               return descent_collapsed(bv->painter(), font);
+       else {
+               // Take placement into account.
+               int i = 0;
+               switch (pos_) {
+               case top:
+                       i = InsetCollapsable::descent(bv, font);
+                       break;
+               case center:
+                       i = (InsetCollapsable::ascent(bv, font)
+                            + InsetCollapsable::descent(bv, font)) / 2;
+                       break;
+               case bottom:
+                       i = InsetCollapsable::ascent(bv, font);
+                       break;
+               }
+               return i;
+       }
+}
+
+
 string const InsetMinipage::EditMessage() const
 {
        return _("Opened Minipage Inset");
@@ -95,11 +248,24 @@ string const InsetMinipage::EditMessage() const
 int InsetMinipage::Latex(Buffer const * buf,
                         ostream & os, bool fragile, bool fp) const
 {
-       os << "\\begin{minipage}{\\columnwidth}%\n";
+       string s_pos;
+       switch (pos_) {
+       case top:
+               s_pos += "t";
+               break;
+       case center:
+               s_pos += "c";
+               break;
+       case bottom:
+               s_pos += "b";
+               break;
+       }
+       os << "\\begin{minipage}[" << s_pos << "]{"
+          << LyXLength(width_).asLatexString() << "}%\n";
        
-       int i = inset->Latex(buf, os, fragile, fp);
+       int i = inset.Latex(buf, os, fragile, fp);
+
        os << "\\end{minipage}%\n";
-       
        return i + 2;
 }
 
@@ -138,25 +304,54 @@ void InsetMinipage::innerPos(InsetMinipage::InnerPosition ip)
 }
 
 
-LyXLength const & InsetMinipage::height() const
+string const & InsetMinipage::height() const
 {
        return height_;
 }
 
 
-void InsetMinipage::height(LyXLength const & ll)
+void InsetMinipage::height(string const & ll)
 {
        height_ = ll;
 }
 
 
-LyXLength const & InsetMinipage::width() const
+string const & InsetMinipage::width() const
 {
        return width_;
 }
 
 
-void InsetMinipage::width(LyXLength const & ll)
+void InsetMinipage::width(string const & ll)
 {
        width_ = ll;
 }
+
+
+bool InsetMinipage::ShowInsetDialog(BufferView * bv) const
+{
+    if (!inset.ShowInsetDialog(bv))
+       bv->owner()->getDialogs()->showMinipage(const_cast<InsetMinipage *>(this));
+    return true;
+}
+
+
+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())
+       return VSpace(width_).inPixels(bv);
+    // this should not happen!
+    return InsetCollapsable::getMaxWidth(bv, inset);
+}