]> git.lyx.org Git - features.git/commitdiff
Make InsetMinipage work better and rewritten compatibility-buffer-read.
authorJürgen Vigna <jug@sad.it>
Thu, 22 Mar 2001 15:45:15 +0000 (15:45 +0000)
committerJürgen Vigna <jug@sad.it>
Thu, 22 Mar 2001 15:45:15 +0000 (15:45 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1805 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/buffer.C
src/insets/ChangeLog
src/insets/insetcollapsable.C
src/insets/insetminipage.C
src/insets/insetminipage.h

index a9378204d83c5756d33699dd7772f930fc56a8e9..f05a22dda414dc2dacfb6c75c534551953c9e96e 100644 (file)
@@ -1,3 +1,8 @@
+2001-03-22  Juergen Vigna  <jug@sad.it>
+
+       * buffer.C (parseSingleLyXformat2Token): redone the minipage
+       compatibility read a bit.
+
 2001-03-21  José Abílio Matos  <jamatos@fep.up.pt>
 
        * buffer.C (pop_tag): removed.
index 59900ad400facaa551627260680000d33d66fb8e..ba47d0ab52907607b5c410d6d99be3690d11363a 100644 (file)
@@ -378,20 +378,27 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
 #endif
        )
 {
+       bool the_end_read = false;
+#ifndef NO_PEXTRA_REALLY
 #ifdef NEW_INSETS
        // This is super temporary but is needed to get the compability
        // mode for minipages work correctly together with new tabulars.
        static int call_depth = 0;
        ++call_depth;
 #endif
-       bool the_end_read = false;
+       bool checkminipage = false;
+       static LyXParagraph * minipar = 0;
+       static LyXParagraph * parBeforeMinipage = 0;
+#endif
        
        if (token[0] != '\\') {
                for (string::const_iterator cit = token.begin();
-                    cit != token.end(); ++cit) {
+                    cit != token.end(); ++cit)
+               {
                        par->InsertChar(pos, (*cit), font);
                        ++pos;
                }
+               checkminipage = true;
        } else if (token == "\\i") {
                Inset * inset = new InsetLatexAccent;
                inset->Read(this, lex);
@@ -491,188 +498,6 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                        ++pos;
                } else {
 #endif
-#ifndef NO_PEXTRA_REALLY
-                       // BEGIN pextra_minipage compability
-                       // This should be removed in 1.3.x (Lgb)
-                       
-                       // This compability code is not perfect. In a couple
-                       // of rand cases it fails. When the minipage par is
-                       // the first par in the document, and when there are
-                       // none or only one regular paragraphs after the
-                       // minipage. Currently I am not investing any effort
-                       // in fixing those cases.
-                       static LyXParagraph * minipar = 0;
-                       //lyxerr << "Call depth: " << call_depth << endl;
-                       if (call_depth == 1) {
-                               
-                       if (minipar
-                           && par->params.pextraType() == LyXParagraph::PEXTRA_MINIPAGE) {
-                               lyxerr << "minipages in a row" << endl;
-                               if (par->params.pextraStartMinipage()) {
-                                       lyxerr << "start new minipage" << endl;
-                                       // minipages in a row
-                                       par->previous()->next(0);
-                                       par->previous(minipar->previous());
-                                       minipar->previous()->next(par);
-                                       minipar->previous(0);
-                                       
-                                       // Before we insert the list of
-                                       // minipages into the inset we have
-                                       // to clean up a bit.
-                                       // This is not quite correct yet since
-                                       // we do want to use some of these
-                                       // parameters to set options in the
-                                       // minipage inset.
-                                       InsetMinipage::Position imp = static_cast<InsetMinipage::Position>(minipar->params.pextraAlignment());
-                                       string pextraWidth = minipar->params.pextraWidth();
-                                       string pextraWidthp = minipar->params.pextraWidthp();
-                                       bool pextraHfill = minipar->params.pextraHfill();
-#if 1
-                                       bool startNew = minipar->params.pextraStartMinipage();
-#endif
-                                       
-                                       LyXParagraph * tmp = minipar;
-                                       while (tmp) {
-                                               tmp->params.pextraType(0);
-                                               tmp->params.pextraWidth(string());
-                                               tmp->params.pextraWidthp(string());
-                                               tmp->params.pextraAlignment(0);
-                                               tmp->params.pextraHfill(false);
-                                               tmp->params.pextraStartMinipage(false);
-                                               tmp = tmp->next();
-                                       }
-                                       
-                                       InsetMinipage * mini = new InsetMinipage;
-                                       mini->pos(imp);
-                                       mini->width(pextraWidth);
-                                       mini->widthp(pextraWidthp);
-                                       mini->inset->par = minipar;
-
-#if 1
-                                       if (!startNew || !pextraHfill) {
-                                               // To minimize problems for
-                                               // the users we will insert
-                                               // the first minipage in
-                                               // a sequence of minipages
-                                               // in its own paragraph.
-                                               LyXParagraph * p = new LyXParagraph;
-                                               p->layout = 0;
-                                               // Insert this after par->prev, but
-                                               // before par.
-                                               p->previous(par->previous());
-                                               p->next(par);
-                                               par->previous()->next(p);
-                                               par->previous(p);
-                                       }
-                                       
-#endif
-                                       // Insert the minipage last in the
-                                       // previous paragraph.
-                                       LyXParagraph * prev = par->previous();
-                                       if (pextraHfill) {
-                                               prev->InsertChar(prev->size(),
-                                                                LyXParagraph::META_HFILL);
-                                       }
-                                       prev->InsertInset(prev->size(), mini);
-                                       
-                                       minipar = par;
-                               } else {
-                                       lyxerr << "new minipage par" << endl;
-                                       //nothing to do just continue reading
-                               }
-                               
-                       } else if (minipar) {
-                               lyxerr << "last minipage par read" << endl;
-                               // The last paragraph read was not part of a
-                               // minipage but the par linked list is...
-                               // So we need to remove the last par from the
-                               // rest, insert the rest of the paragraphs into
-                               // a InsetMinipage, insert this minipage into
-                               // prevpar, append the current par to prevpar
-                               // and continue...
-
-                               LyXParagraph * lp = minipar;
-                               int pcount = 0;
-                               while (lp) {
-                                       ++pcount;
-                                       lp = lp->next();
-                               }
-                               lyxerr << "Minipar count: " << pcount << endl;
-                               lyxerr << "Par: " << (void*)par << endl;
-                               lyxerr << "Par->prev: " << (void*)par->previous() << endl;
-
-                               if (par->previous())
-                                       par->previous()->next(0);
-                               par->previous(minipar->previous());
-                               minipar->previous()->next(par);
-                               minipar->previous(0);
-                               
-                               // Before we insert the list of
-                               // minipages into the inset we have
-                               // to clean up a bit.
-                               // This is not quite correct yet since we
-                               // do want to use some of these parameters
-                               // to set options in the minipage inset.
-                               InsetMinipage::Position imp = static_cast<InsetMinipage::Position>(minipar->params.pextraAlignment());
-                               string pextraWidth = minipar->params.pextraWidth();
-                               string pextraWidthp = minipar->params.pextraWidthp();
-                               bool pextraHfill = minipar->params.pextraHfill();
-#if 1
-                               bool startNew = minipar->params.pextraStartMinipage();
-#endif
-                               LyXParagraph * tmp = minipar;
-                               while (tmp) {
-                                       tmp->params.pextraType(0);
-                                       tmp->params.pextraWidth(string());
-                                       tmp->params.pextraWidthp(string());
-                                       tmp->params.pextraAlignment(0);
-                                       tmp->params.pextraHfill(false);
-                                       tmp->params.pextraStartMinipage(false);
-                                       tmp = tmp->next();
-                               }
-                               
-                               InsetMinipage * mini = new InsetMinipage;
-                               mini->pos(imp);
-                               mini->width(pextraWidth);
-                               mini->widthp(pextraWidthp);
-                               mini->inset->par = minipar;
-                               
-#if 1
-                               if (!startNew || !pextraHfill) {
-                                       // To minimize problems for the users
-                                       // we will insert the first minipage
-                                       // in a sequence of minipages in its
-                                       // own paragraph.
-                                       LyXParagraph * p = new LyXParagraph;
-                                       p->layout = 0;
-                                       // Insert this after par->prev, but
-                                       // before par.
-                                       p->previous(par->previous());
-                                       p->next(par);
-                                       par->previous()->next(p);
-                                       par->previous(p);
-                               }
-#endif
-                               
-                               LyXParagraph * prev = par->previous();
-                               if (pextraHfill) {
-                                       prev->InsertChar(prev->size(),
-                                                        LyXParagraph::META_HFILL);
-                                       }
-                               prev->InsertInset(prev->size(), mini);
-
-                               minipar = 0;
-                       } else if (par->params.pextraType() == LyXParagraph::PEXTRA_MINIPAGE) {
-                               
-                               // par is the first paragraph in a minipage
-                               lyxerr << "begin minipage" << endl;
-                               minipar = par;
-                               
-                       }
-                       }
-                       
-                       // End of pextra_minipage compability
-#endif 
                        if (!return_par)
                                return_par = par;
                        else {
@@ -1230,6 +1055,9 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                inset->Read(this, lex);
                par->InsertInset(pos, inset, font);
                ++pos;
+               // because of OLD_TABULAR_READ where tabulars have been
+               // one paragraph.
+               checkminipage = true;
        } else if (token == "\\hfill") {
                par->InsertChar(pos, LyXParagraph::META_HFILL, font);
                ++pos;
@@ -1259,6 +1087,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                ++pos;
        } else if (token == "\\the_end") {
                the_end_read = true;
+               minipar = parBeforeMinipage = 0;
        } else {
                // This should be insurance for the future: (Asger)
                lex.printError("Unknown token `$$Token'. "
@@ -1270,6 +1099,138 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
                        ++pos;
                }
        }
+#ifndef NO_PEXTRA_REALLY
+       // now check if we have a minipage paragraph as at this
+       // point we already read all the necessary data!
+       // this cannot be done in layout because there we did
+       // not read yet the paragraph PEXTRA-params (Jug)
+       //
+       // BEGIN pextra_minipage compability
+       // This should be removed in 1.3.x (Lgb)
+       
+       // This compability code is not perfect. In a couple
+       // of rand cases it fails. When the minipage par is
+       // the first par in the document, and when there are
+       // none or only one regular paragraphs after the
+       // minipage. Currently I am not investing any effort
+       // in fixing those cases.
+
+       //lyxerr << "Call depth: " << call_depth << endl;
+       if (checkminipage && (call_depth == 1)) {
+       checkminipage = false;
+       if (minipar && (minipar != par) &&
+           (par->params.pextraType()==LyXParagraph::PEXTRA_MINIPAGE))
+       {
+               lyxerr << "minipages in a row" << endl;
+               if (par->params.pextraStartMinipage()) {
+                       lyxerr << "start new minipage" << endl;
+                       // minipages in a row
+                       par->previous()->next(0);
+                       par->previous(0);
+                               
+                       LyXParagraph * tmp = minipar;
+                       while (tmp) {
+                               tmp->params.pextraType(0);
+                               tmp->params.pextraWidth(string());
+                               tmp->params.pextraWidthp(string());
+                               tmp->params.pextraAlignment(0);
+                               tmp->params.pextraHfill(false);
+                               tmp->params.pextraStartMinipage(false);
+                               tmp = tmp->next();
+                       }
+                       // create a new paragraph to insert the
+                       // minipages in the following case
+                       if (par->params.pextraStartMinipage() &&
+                           !par->params.pextraHfill())
+                       {
+                               LyXParagraph * p = new LyXParagraph;
+                               p->layout = 0;
+                               p->previous(parBeforeMinipage);
+                               parBeforeMinipage->next(p);
+                               p->next(0);
+                               parBeforeMinipage = p;
+                       }
+                       InsetMinipage * mini = new InsetMinipage;
+                       mini->pos(static_cast<InsetMinipage::Position>(par->params.pextraAlignment()));
+                       mini->width(par->params.pextraWidth());
+                       mini->widthp(par->params.pextraWidthp());
+                       mini->inset->par = par;
+                       // Insert the minipage last in the
+                       // previous paragraph.
+                       if (par->params.pextraHfill()) {
+                               parBeforeMinipage->InsertChar
+                                       (parBeforeMinipage->size(), LyXParagraph::META_HFILL);
+                       }
+                       parBeforeMinipage->InsertInset
+                               (parBeforeMinipage->size(), mini);
+                               
+                       minipar = par;
+               } else {
+                       lyxerr << "new minipage par" << endl;
+                       //nothing to do just continue reading
+               }
+                       
+       } else if (minipar && (minipar != par)) {
+               lyxerr << "last minipage par read" << endl;
+               // The last paragraph read was not part of a
+               // minipage but the par linked list is...
+               // So we need to remove the last par from the
+               // rest
+               if (par->previous())
+                       par->previous()->next(0);
+               par->previous(parBeforeMinipage);
+               parBeforeMinipage->next(par);
+               LyXParagraph * tmp = minipar;
+               while (tmp) {
+                       tmp->params.pextraType(0);
+                       tmp->params.pextraWidth(string());
+                       tmp->params.pextraWidthp(string());
+                       tmp->params.pextraAlignment(0);
+                       tmp->params.pextraHfill(false);
+                       tmp->params.pextraStartMinipage(false);
+                       tmp = tmp->next();
+               }
+               minipar = parBeforeMinipage = 0;
+       } else if (!minipar &&
+                  (par->params.pextraType() == LyXParagraph::PEXTRA_MINIPAGE))
+       {
+               // par is the first paragraph in a minipage
+               lyxerr << "begin minipage" << endl;
+               // To minimize problems for
+               // the users we will insert
+               // the first minipage in
+               // a sequence of minipages
+               // in its own paragraph.
+               LyXParagraph * p = new LyXParagraph;
+               p->layout = 0;
+               p->previous(par->previous());
+               p->next(0);
+               if (par->previous())
+                       par->previous()->next(p);
+               par->previous(0);
+               parBeforeMinipage = p;
+               minipar = par;
+               if (!return_par || (return_par == par))
+                       return_par = p;
+
+               InsetMinipage * mini = new InsetMinipage;
+               mini->pos(static_cast<InsetMinipage::Position>(minipar->params.pextraAlignment()));
+               mini->width(minipar->params.pextraWidth());
+               mini->widthp(minipar->params.pextraWidthp());
+               mini->inset->par = minipar;
+                       
+               // Insert the minipage last in the
+               // previous paragraph.
+               if (minipar->params.pextraHfill()) {
+                       parBeforeMinipage->InsertChar
+                               (parBeforeMinipage->size(),LyXParagraph::META_HFILL);
+               }
+               parBeforeMinipage->InsertInset
+                       (parBeforeMinipage->size(), mini);
+       }
+       }
+       // End of pextra_minipage compability
+#endif
        --call_depth;
        return the_end_read;
 }
index 2ea7ef90dbbf3f87bf13bc7523a8deb09b923be7..04656d5ba253b597c78bc2fc0818a403c9762820 100644 (file)
@@ -1,3 +1,12 @@
+2001-03-22  Juergen Vigna  <jug@sad.it>
+
+       * insetminipage.C (getMaxWidth): added function to set the drawing
+       width!
+       (Read): should work now!
+
+       * insetcollapsable.C (InsetCollapsable): default is now NOT collapsed
+       if we create a new inset.
+
 2001-03-20  Angus Leeming  <a.leeming@ic.ac.uk>
 
        * figinset.C (fl_set_preemptive_callback): moved definition outside
index ea7757dc01fc3ca09b5ce9bb443d58daac5818a2..f5599fb6f2383c1c6ab12e1ef741895714d618ed 100644 (file)
@@ -36,7 +36,7 @@ InsetCollapsable::InsetCollapsable()
 {
        //inset = new InsetText;
     inset->setOwner(this);
-    collapsed = true;
+    collapsed = false;
     label = "Label";
     autocollapse = true;
     inset->SetAutoBreakRows(true);
index bd5e6ba1ad2545709a3f72f4f55df325f5eb7c5a..255085306b486b4a0d88c5af31371a45f9cc181a 100644 (file)
@@ -69,7 +69,7 @@ InsetMinipage::InsetMinipage()
        setLabelFont(font);
        setAutoCollapse(false);
        setInsetName("Minipage");
-       collapsed = false;
+       widthp_ = 100; // set default to 100% of column_width
 }
 
 
@@ -84,26 +84,86 @@ void InsetMinipage::Write(Buffer const * buf, ostream & os) const
        os << getInsetName() << "\n"
           << "position " << pos_ << "\n"
           << "inner_position " << inner_pos_ << "\n"
-//        << "height " << height_ << "\n"
-          << "width " << widthp_ << "\n";
+          << "height \"" << height_ << "\"\n"
+          << "width \"" << width_ << "\"\n"
+          << "widthp " << widthp_ << "\n";
        InsetCollapsable::Write(buf, os);
 }
 
 
 void InsetMinipage::Read(Buffer const * buf, LyXLex & lex)
 {
-       #warning Read and set args correctly. (Lgb)
-       lex.next();
-       string token = lex.GetString();
-       lyxerr << "minipage token: " << token << endl;
-       lex.next(); lex.next();
-       lex.next();
-       lex.next();
+    string token;
+
+    if (lex.IsOK()) {
        lex.next();
        token = lex.GetString();
-       lyxerr << "minipage token: " << token << endl;
-       
-       InsetCollapsable::Read(buf, lex);
+       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;
+       }
+    }
+    if (lex.IsOK()) {
+       if (token.empty()) {
+           lex.next();
+           token = lex.GetString();
+       }
+       if (token == "widthp") {
+           lex.next();
+           widthp_ = lex.GetInteger();
+           token = string();
+       } else {
+               lyxerr << "InsetMinipage::Read: Missing 'widthp_'-tag!"
+                      << endl;
+       }
+    }
+    InsetCollapsable::Read(buf, lex);
 }
 
 
@@ -139,8 +199,13 @@ int InsetMinipage::Latex(Buffer const * buf,
                break;
        }
        
-       os << "\\begin{minipage}[" << s_pos << "]{."
-          << widthp_ << "\\columnwidth}%\n";
+       if (width_.empty()) {
+           os << "\\begin{minipage}[" << s_pos << "]{."
+              << widthp_ << "\\columnwidth}%\n";
+       } else {
+           os << "\\begin{minipage}[" << s_pos << "]{"
+              << width_ << "}%\n";
+       }
        
        int i = inset->Latex(buf, os, fragile, fp);
        os << "\\end{minipage}%\n";
@@ -183,13 +248,13 @@ 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;
 }
@@ -244,3 +309,11 @@ void InsetMinipage::InsetButtonRelease(BufferView * bv, int x, int y,
     }
     InsetCollapsable::InsetButtonRelease(bv, x, y, button);
 }
+
+int InsetMinipage::getMaxWidth(Painter & pain, UpdatableInset const * inset)
+    const
+{
+    if (!width_.empty())
+       return VSpace(width_).inPixels(0, 0);
+    return InsetCollapsable::getMaxWidth(pain, inset) / 100 * widthp_;
+}
index a38e6c66ed6137101221ab45a771feb42ad23835..dff48efd76b7e703ee98ef2a3b24052506438448 100644 (file)
@@ -65,9 +65,9 @@ public:
        ///
        void innerPos(InnerPosition);
        ///
-       LyXLength const & height() const;
+       string const & height() const;
        ///
-       void height(LyXLength const &);
+       void height(string const &);
        ///
        string const & width() const;
        ///
@@ -82,6 +82,11 @@ public:
        SigC::Signal0<void> hideDialog;
        ///
        void InsetButtonRelease(BufferView * bv, int x, int y, int button);
+       ///
+       int getMaxWidth(Painter &, UpdatableInset const *) const;
+       ///
+       bool needFullRow() const { return false; }
+       
 
 private:
        ///
@@ -89,7 +94,7 @@ private:
        ///
        InnerPosition inner_pos_;
        ///
-       LyXLength height_;
+       string height_;
        ///
        string width_;
        ///