From: Jean-Marc Lasgouttes Date: Mon, 16 Aug 2004 00:32:04 +0000 (+0000) Subject: get rid of ownerPar(), which was super slow; fix tabular crash due to recently introd... X-Git-Tag: 1.6.10~15046 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=d194cfffa5f68f425cff20770956f81c74cf9d0f;p=features.git get rid of ownerPar(), which was super slow; fix tabular crash due to recently introduced BOOST_ASSERTs git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8951 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BufferView.C b/src/BufferView.C index 30d6327240..88f6ea2530 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -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); diff --git a/src/BufferView.h b/src/BufferView.h index e4ef2e5548..e9a8101e6f 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -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); diff --git a/src/ChangeLog b/src/ChangeLog index 3817d1e368..80aba7d6f6 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,20 @@ +2004-08-16 Jean-Marc Lasgouttes + + * 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 * text.C (readParToken, readParagraph, read): report all unknown tokens. diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index b07de9e33f..003a03ba20 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,17 @@ +2004-08-16 Jean-Marc Lasgouttes + + * 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 * pch.h: new file diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 98d39ea7fb..ab3e9a3f0f 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -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(); } diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index 712fbe4b61..1cba92dfde 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -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; diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 6772187062..01428d15a4 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -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); - } } diff --git a/src/insets/insettext.h b/src/insets/insettext.h index a44fadf153..fe4e93230c 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -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); /// diff --git a/src/output_plaintext.C b/src/output_plaintext.C index d29f5024ed..d0da1d04dc 100644 --- a/src/output_plaintext.C +++ b/src/output_plaintext.C @@ -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; } diff --git a/src/outputparams.C b/src/outputparams.C index 1cf785b063..1f3dc1502b 100644 --- a/src/outputparams.C +++ b/src/outputparams.C @@ -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) {} diff --git a/src/outputparams.h b/src/outputparams.h index 54029f58d9..7102597b42 100644 --- a/src/outputparams.h +++ b/src/outputparams.h @@ -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. diff --git a/src/paragraph_funcs.C b/src/paragraph_funcs.C index cb8aad1ba2..384b819e12 100644 --- a/src/paragraph_funcs.C +++ b/src/paragraph_funcs.C @@ -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) diff --git a/src/paragraph_funcs.h b/src/paragraph_funcs.h index 6a573f458f..a0feb358ef 100644 --- a/src/paragraph_funcs.h +++ b/src/paragraph_funcs.h @@ -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, diff --git a/src/tabular.C b/src/tabular.C index 7385032410..87e8e09eda 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -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; diff --git a/src/text2.C b/src/text2.C index ec027406f1..129ac6aa12 100644 --- a/src/text2.C +++ b/src/text2.C @@ -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());