]> git.lyx.org Git - features.git/commitdiff
get rid of ownerPar(), which was super slow; fix tabular crash due to recently introd...
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 16 Aug 2004 00:32:04 +0000 (00:32 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 16 Aug 2004 00:32:04 +0000 (00:32 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8951 a592a061-630c-0410-9148-cb99ea01b6c8

15 files changed:
src/BufferView.C
src/BufferView.h
src/ChangeLog
src/insets/ChangeLog
src/insets/insettabular.C
src/insets/insettabular.h
src/insets/insettext.C
src/insets/insettext.h
src/output_plaintext.C
src/outputparams.C
src/outputparams.h
src/paragraph_funcs.C
src/paragraph_funcs.h
src/tabular.C
src/text2.C

index 30d6327240fd81a2bc3a1cafaf05a31351bec327..88f6ea25303a16963a7a076ec59765d28689bbec 100644 (file)
@@ -316,14 +316,6 @@ LyXText * BufferView::getLyXText() const
 }
 
 
-Language const * BufferView::getParentLanguage(InsetOld * inset) const
-{
-       Paragraph const & par = ownerPar(*buffer(), inset);
-       return par.getFontSettings(buffer()->params(),
-                                  par.getPositionOfInset(inset)).language();
-}
-
-
 void BufferView::haveSelection(bool sel)
 {
        pimpl_->workarea().haveSelection(sel);
index e4ef2e55482c0a4af25fff4d838f41d887eece4d..e9a8101e6f9abd8dc2a62c1b78aba06bbc87564e 100644 (file)
@@ -108,9 +108,6 @@ public:
        /// return the lyxtext we are using
        LyXText * getLyXText() const;
 
-       /// return the parent language of the given inset
-       Language const * getParentLanguage(InsetOld * inset) const;
-
        /// simple replacing. Use the font of the first selected character
        void replaceSelectionWithString(std::string const & str);
 
index 3817d1e3682bdbb8fedb4f521957431782687129..80aba7d6f6c343293cb1fad713cef384e6bf3775 100644 (file)
@@ -1,3 +1,20 @@
+2004-08-16  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
+
+       * tabular.C (asciiBottomHLine, asciiPrintCell, asciiTopHLine): fix
+       crash
+
+       * output_plaintext.C (asciiParagraph): set depth correctly
+
+       * outputparams.h: add member depth
+
+       * paragraph_funcs.C (ownerPar): remove.
+
+       * text2.C (setCounter): remove first_pit; comment out some
+       non-working code that uses ownerPar
+
+       * BufferView.C (getParentLanguage): remove. Not used anymore, and
+       uses ownerPar
+
 2004-08-16  José Matos  <jamatos@lyx.org>
 
        * text.C (readParToken, readParagraph, read): report all unknown tokens.
index b07de9e33f6e988d2f8c14835420cc97fee20860..003a03ba20ef1633c512cbe378b4594d0416a576 100644 (file)
@@ -1,3 +1,17 @@
+2004-08-16  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
+
+       * insettabular.C (plaintext): do not use ownerPar to get the
+       paragraph depth
+
+       * insettext.C (sanitizeEmptyText): remove. Not sure what it does,
+       and it calls getParentLanguage (which calls ownerPar)
+       (edit): do not call sanitizeEmptyText
+       (priv_dispatch): remove code resetting font on empty inset, for
+       the same reasons as above.
+
+       * insettabular.C (isRightToLeft): instead of using
+       BufferView::getParentLanguage, use the data from the cursor
+
 2004-08-15  Lars Gullik Bjonnes  <larsbj@gullik.net>
 
        * pch.h: new file
index 98d39ea7fbc7df00eb21f21e7bd309342764cec2..ab3e9a3f0fc35b2a977a0f13cf5a1b4ef674a55a 100644 (file)
@@ -376,6 +376,7 @@ void InsetTabular::edit(LCursor & cur, bool left)
        lyxerr << "InsetTabular::edit: " << this << endl;
        finishUndo();
        int cell;
+       cur.push(*this);
        if (left) {
                if (isRightToLeft(cur))
                        cell = tabular.getLastCellInRow(0);
@@ -391,7 +392,6 @@ void InsetTabular::edit(LCursor & cur, bool left)
        // this accesses the position cache before it is initialized
        //resetPos(cur);
        //cur.bv().fitCursor();
-       cur.push(*this);
        cur.idx() = cell;
 }
 
@@ -892,7 +892,7 @@ int InsetTabular::latex(Buffer const & buf, ostream & os,
 int InsetTabular::plaintext(Buffer const & buf, ostream & os,
                        OutputParams const & runparams) const
 {
-       int dp = runparams.linelen ? ownerPar(buf, this).params().depth() : 0;
+       int dp = runparams.linelen ? runparams.depth : 0;
        return tabular.plaintext(buf, os, runparams, dp, false, 0);
 }
 
@@ -1562,9 +1562,13 @@ void InsetTabular::cutSelection(LCursor & cur)
 }
 
 
-bool InsetTabular::isRightToLeft(LCursor & cur)
+bool InsetTabular::isRightToLeft(LCursor & cur) const
 {
-       return cur.bv().getParentLanguage(this)->RightToLeft();
+       BOOST_ASSERT(cur.size() > 1);
+       Paragraph const & parentpar = cur[cur.size() - 2].paragraph();
+       LCursor::pos_type const parentpos = cur[cur.size() - 2].pos();
+       return parentpar.getFontSettings(cur.bv().buffer()->params(), 
+                                        parentpos).language()->RightToLeft();
 }
 
 
index 712fbe4b61ddefce94a949beac034d7ba6370e27..1cba92dfde61dbff35daeb06ac98028f65085fa3 100644 (file)
@@ -180,7 +180,7 @@ private:
        ///
        void cutSelection(LCursor & cur);
        ///
-       bool isRightToLeft(LCursor & cur);
+       bool isRightToLeft(LCursor & cur) const;
        ///
        void getSelection(LCursor & cur,
                int & rs, int & re, int & cs, int & ce) const;
index 677218706281aa150e01248d8cbf3b75072256a3..01428d15a43d9570f5acb376af437f77a50d7c0f 100644 (file)
@@ -273,18 +273,6 @@ string const InsetText::editMessage() const
 }
 
 
-void InsetText::sanitizeEmptyText(BufferView & bv)
-{
-       if (paragraphs().size() == 1
-           && paragraphs().begin()->empty()
-           && bv.getParentLanguage(this) != text_.current_font.language()) {
-               LyXFont font(LyXFont::ALL_IGNORE);
-               font.setLanguage(bv.getParentLanguage(this));
-               text_.setFont(bv.cursor(), font, false);
-       }
-}
-
-
 void InsetText::edit(LCursor & cur, bool left)
 {
        //lyxerr << "InsetText: edit left/right" << endl;
@@ -295,7 +283,6 @@ void InsetText::edit(LCursor & cur, bool left)
        text_.setCursor(cur.top(), par, pos);
        cur.clearSelection();
        finishUndo();
-       sanitizeEmptyText(cur.bv());
 #ifdef WITH_WARNINGS
 #warning can someone check if/when this is needed?
 #endif
@@ -321,16 +308,6 @@ void InsetText::priv_dispatch(LCursor & cur, FuncRequest & cmd)
        bool was_empty = paragraphs().begin()->empty() && paragraphs().size() == 1;
        text_.dispatch(cur, cmd);
 
-       // If the action has deleted all text in the inset, we need
-       // to change the language to the language of the surronding
-       // text.
-       // Why this cleverness? (Andre')
-       if (!was_empty && paragraphs().begin()->empty() &&
-           paragraphs().size() == 1) {
-               LyXFont font(LyXFont::ALL_IGNORE);
-               font.setLanguage(cur.bv().getParentLanguage(this));
-               text_.setFont(cur, font, false);
-       }
 }
 
 
index a44fadf1538646994d0ce8bdc66260ffe874b713..fe4e93230c6c5cd591632dc497479584f3064109 100644 (file)
@@ -150,9 +150,6 @@ private:
        void updateLocal(LCursor &);
        ///
        void init();
-       // If the inset is empty set the language of the current font to the
-       // language to the surronding text (if different).
-       void sanitizeEmptyText(BufferView &);
        ///
        void setCharFont(Buffer const &, int pos, LyXFont const & font);
        ///
index d29f5024ed2607a611d197ca18aaa9f57a0a9292..d0da1d04dc56c3310efd38fc54b6169842dce883 100644 (file)
@@ -206,7 +206,9 @@ void asciiParagraph(Buffer const & buf,
                                currlinelen += word.length();
                                word.erase();
                        }
-                       if (inset->plaintext(buf, os, runparams)) {
+                       OutputParams rp = runparams;
+                       rp.depth = par.params().depth();
+                       if (inset->plaintext(buf, os, rp)) {
                                // to be sure it breaks paragraph
                                currlinelen += runparams.linelen;
                        }
index 1cf785b0639cf18315fee0aabc0cc5d3853379f0..1f3dc1502bc94ba82cacc284398ded238b8f66d5 100644 (file)
@@ -17,7 +17,7 @@
 OutputParams::OutputParams()
        : flavor(LATEX), nice(false), moving_arg(false),
          free_spacing(false), use_babel(false),
-         mixed_content(false), linelen(0),
+         mixed_content(false), linelen(0), depth(0),
          exportdata(new ExportData)
 {}
 
index 54029f58d94f8e0546ac6ccc53cb1bc738b7a176..7102597b42ffaa3f6503b8a031261450cb2a9bd9 100644 (file)
@@ -75,10 +75,15 @@ struct OutputParams {
        */
        bool mixed_content;
 
-       /** Line length to use with ascii export.
+       /** Line length to use with plaintext export.
        */
        lyx::size_type linelen;
 
+       /** The depth of the current paragraph, set for plaintext
+        *  export and used by InsetTabular
+        */
+       int depth;
+
        /** Export data filled in by the latex(), docbook() etc methods.
            This is a hack: Make it possible to add stuff to constant
            OutputParams instances.
index cb8aad1ba2035694a2c4a079570d197df6085180..384b819e122f19785f0537e87927269a781f015f 100644 (file)
@@ -340,29 +340,6 @@ par_type outerPar(Buffer const & buf, InsetBase const * inset)
 }
 
 
-Paragraph const & ownerPar(Buffer const & buf, InsetBase const * inset)
-{
-       ParConstIterator pit = buf.par_iterator_begin();
-       ParConstIterator end = buf.par_iterator_end();
-       for ( ; pit != end; ++pit) {
-               LyXText * text;
-               // the second '=' below is intentional
-               for (int i = 0; (text = inset->getText(i)); ++i)
-                       if (&text->paragraphs() == &pit.plist())
-                               return *pit;
-
-               InsetList::const_iterator ii = pit->insetlist.begin();
-               InsetList::const_iterator iend = pit->insetlist.end();
-               for ( ; ii != iend; ++ii)
-                       if (ii->inset == inset)
-                               return *pit;
-       }
-       lyxerr << "ownerPar: should not happen" << endl;
-       BOOST_ASSERT(false);
-       return buf.paragraphs().front(); // shut up compiler
-}
-
-
 /// return the range of pars [beg, end[ owning the range of y [ystart, yend]
 void getParsInRange(ParagraphList & pars, int ystart, int yend,
        par_type & beg, par_type & end)
index 6a573f458fc35dbe4dcd22db83586828951fa533..a0feb358efe72ae32d0845884b2a63ac876201c5 100644 (file)
@@ -61,9 +61,6 @@ LyXFont const outerFont(lyx::par_type par, ParagraphList const & plist);
 /// find outermost paragraph containing an inset
 lyx::par_type outerPar(Buffer const & buf, InsetBase const * inset);
 
-/// find owning paragraph containing an inset
-Paragraph const & ownerPar(Buffer const & buf, InsetBase const * inset);
-
 /// return the range of pars [beg, end[ owning the range of y [ystart, yend]
 void getParsInRange(ParagraphList & plist,
                                int ystart, int yend,
index 73850324109eef5ec9a14a0a2617bbb53fd6f509..87e8e09edab5303f923761a2ee6e772038717f5e 100644 (file)
@@ -2341,7 +2341,8 @@ int LyXTabular::asciiTopHLine(ostream & os, int row,
                }
                int column = column_of_cell(i);
                int len = clen[column];
-               while (isPartOfMultiColumn(row, ++column))
+               while (column < columns_ - 1  
+                      && isPartOfMultiColumn(row, ++column))
                        len += clen[column] + 4;
                os << string(len, ch);
                if (topLine(i)) {
@@ -2388,7 +2389,8 @@ int LyXTabular::asciiBottomHLine(ostream & os, int row,
                }
                int column = column_of_cell(i);
                int len = clen[column];
-               while (isPartOfMultiColumn(row, ++column))
+               while (column < columns_ -1
+                      && isPartOfMultiColumn(row, ++column))
                        len += clen[column] + 4;
                os << string(len, ch);
                if (bottomLine(i)) {
@@ -2426,7 +2428,8 @@ int LyXTabular::asciiPrintCell(Buffer const & buf, ostream & os,
 
        unsigned int len1 = sstr.str().length();
        unsigned int len2 = clen[column];
-       while (isPartOfMultiColumn(row, ++column))
+       while (column < columns_ -1
+              && isPartOfMultiColumn(row, ++column))
                len2 += clen[column] + 4;
        len2 -= len1;
 
index ec027406f1b4cdefe0c9f6eed3a1b8c400af195e..129ac6aa1276fda0a8e42233b39fb3756961d121 100644 (file)
@@ -712,13 +712,12 @@ void LyXText::setCounter(Buffer const & buf, par_type pit)
        BufferParams const & bufparams = buf.params();
        LyXTextClass const & textclass = bufparams.getLyXTextClass();
        LyXLayout_ptr const & layout = par.layout();
-       par_type first_pit = 0;
        Counters & counters = textclass.counters();
 
        // Always reset
        par.itemdepth = 0;
 
-       if (pit == first_pit) {
+       if (pit == 0) {
                par.params().appendix(par.params().startOfAppendix());
        } else {
                par.params().appendix(pars_[pit - 1].params().appendix());
@@ -729,7 +728,7 @@ void LyXText::setCounter(Buffer const & buf, par_type pit)
                }
 
                // Maybe we have to increment the item depth.
-               incrementItemDepth(pars_, pit, first_pit);
+               incrementItemDepth(pars_, pit, 0);
        }
 
        // erase what was there before
@@ -774,7 +773,7 @@ void LyXText::setCounter(Buffer const & buf, par_type pit)
                par.params().labelString(itemlabel);
        } else if (layout->labeltype == LABEL_ENUMERATE) {
                // Maybe we have to reset the enumeration counter.
-               resetEnumCounterIfNeeded(pars_, pit, first_pit, counters);
+               resetEnumCounterIfNeeded(pars_, pit, 0, counters);
 
                // FIXME
                // Yes I know this is a really, really! bad solution
@@ -823,13 +822,25 @@ void LyXText::setCounter(Buffer const & buf, par_type pit)
                                    in->lyxCode() == InsetBase::WRAP_CODE) {
                                        isOK = true;
                                        break;
-                               } else {
+                               } 
+#ifdef WITH_WARNINGS
+#warning replace this code by something that works
+// This code does not work because we have currently no way to move up
+// in the hierarchy of insets (JMarc 16/08/2004)
+#endif
+#if 0
+/* I think this code is supposed to be useful when one has a caption
+ * in a minipage in a figure inset. We need to go up to be able to see
+ * that the caption sould use "Figure" as label
+ */
+                               else {
                                        Paragraph const * owner = &ownerPar(buf, in);
-                                       tmppit = first_pit;
+                                       tmppit = 0;
                                        for ( ; tmppit != end; ++tmppit)
                                                if (&pars_[tmppit] == owner)
                                                        break;
                                }
+#endif
                        }
 
                        if (isOK) {
@@ -893,7 +904,7 @@ void LyXText::updateCounters()
 }
 
 
-// this really should just inset the inset and not move the cursor.
+// this really should just insert the inset and not move the cursor.
 void LyXText::insertInset(LCursor & cur, InsetBase * inset)
 {
        BOOST_ASSERT(this == cur.text());