From 68f7a5079996ca36f630a70a04b24f81cefade4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Wed, 16 Apr 2003 08:12:22 +0000 Subject: [PATCH] parlist-13-c.diff git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6824 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 27 ++++++++++++++ src/CutAndPaste.C | 2 +- src/buffer.C | 16 ++++----- src/buffer.h | 6 ++-- src/paragraph.C | 7 ++-- src/paragraph_funcs.C | 82 +++++++++++++++++++++++-------------------- src/paragraph_funcs.h | 16 ++++++--- src/rowpainter.C | 6 ++-- src/text.C | 43 +++++++++++++---------- src/text2.C | 17 ++++----- 10 files changed, 135 insertions(+), 87 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index ae5100dd8f..ae2765d6a9 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,30 @@ +2003-04-16 Lars Gullik Bjønnes + + * text2.C (setCharFont): adjust + (setCounter): adjust + (insertStringAsLines): adjust + + * text.C (leftMargin): adjust + (setHeightOfRow): adjust + + * rowpainter.C (paintFirst): adjust + (paintLast): adjust + + * paragraph_funcs.C (depthHook): ParagraphList::iterators + (outerHook): ditto + (isFirstInSequence): ditto + (getEndLabel): ditto + (outerFont): adjust + + * paragraph.C (getParLanguage): comment out some hard stuff. + + * buffer.C (insertStringAsLines): take a ParagraphList as arg + (sgmlError): ditto + (simpleDocBookOnePar): ditto + (makeDocBookFile): use ParagraphList::iterator + + * CutAndPaste.C (pasteSelection): adjust + 2003-04-16 Lars Gullik Bjønnes * text2.C (getFont): adjust diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index 0b3499746a..8d76ec1df3 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -282,7 +282,7 @@ bool CutAndPaste::pasteSelection(Paragraph ** par, Paragraph ** endpar, tmpbuf->erase(i--); } } else { - LyXFont f1 = tmpbuf->getFont(current_view->buffer()->params, i, outerFont(tmpbuf, current_view->text->ownerParagraphs())); + LyXFont f1 = tmpbuf->getFont(current_view->buffer()->params, i, outerFont(tmpbuf, current_view->buffer()->paragraphs)); LyXFont f2 = f1; if (!(*par)->checkInsertChar(f1)) { tmpbuf->erase(i--); diff --git a/src/buffer.C b/src/buffer.C index aa177d7d4b..f7b0aae762 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -434,7 +434,7 @@ Buffer::readParagraph(LyXLex & lex, string const & token, // needed to insert the selection -void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos, +void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos, LyXFont const & fn,string const & str) { LyXLayout_ptr const & layout = par->layout(); @@ -452,7 +452,7 @@ void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos, if (autobreakrows && (!par->empty() || layout->keepempty)) { breakParagraph(params, paragraphs, par, pos, layout->isEnvironment()); - par = par->next(); + ++par; pos = 0; space_inserted = true; } else { @@ -1596,7 +1596,7 @@ void Buffer::simpleLinuxDocOnePar(ostream & os, // Print an error message. -void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/, +void Buffer::sgmlError(ParagraphList::iterator /*par*/, int /*pos*/, string const & /*message*/) const { #ifdef WITH_WARNINGS @@ -1634,8 +1634,6 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body) return; } - Paragraph * par = &*(paragraphs.begin()); - niceFile = nice; // this will be used by Insetincludes. LaTeXFeatures features(params); @@ -1689,7 +1687,10 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body) string item_name; string command_name; - while (par) { + ParagraphList::iterator par = paragraphs.begin(); + ParagraphList::iterator pend = paragraphs.end(); + + for (; par != pend; ++par) { string sgmlparam; string c_depth; string c_params; @@ -1843,7 +1844,6 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body) simpleDocBookOnePar(ofs, par, desc_on, depth + 1 + command_depth); - par = par->next(); string end_tag; // write closing SGML tags @@ -1907,7 +1907,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body) void Buffer::simpleDocBookOnePar(ostream & os, - Paragraph * par, int & desc_on, + ParagraphList::iterator par, int & desc_on, Paragraph::depth_type depth) const { bool emph_flag = false; diff --git a/src/buffer.h b/src/buffer.h index 9f749f4969..ea66fe9ca4 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -117,7 +117,7 @@ public: Paragraph::depth_type & depth); /// - void insertStringAsLines(Paragraph *&, lyx::pos_type &, + void insertStringAsLines(ParagraphList::iterator &, lyx::pos_type &, LyXFont const &, string const &); /// Paragraph * getParFromID(int id) const; @@ -153,7 +153,7 @@ public: bool only_preamble = false); /// void simpleDocBookOnePar(std::ostream &, - Paragraph * par, int & desc_on, + ParagraphList::iterator par, int & desc_on, Paragraph::depth_type depth) const ; /// void simpleLinuxDocOnePar(std::ostream & os, Paragraph * par, @@ -165,7 +165,7 @@ public: void makeDocBookFile(string const & filename, bool nice, bool only_body = false); /// - void sgmlError(Paragraph * par, int pos, string const & message) const; + void sgmlError(ParagraphList::iterator par, int pos, string const & message) const; /// returns the main language for the buffer (document) Language const * getLanguage() const; diff --git a/src/paragraph.C b/src/paragraph.C index dd71347f49..6f21d609c2 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -1187,9 +1187,12 @@ Paragraph::getParLanguage(BufferParams const & bparams) const { if (!empty()) { return getFirstFontSettings().language(); - } else if (previous_) +#warning FIXME we should check the prev par as well (Lgb) +#if 0 + } else if (previous_) { return previous_->getParLanguage(bparams); - else +#endif + }else return bparams.language; } diff --git a/src/paragraph_funcs.C b/src/paragraph_funcs.C index 2a3994f38c..306afd958b 100644 --- a/src/paragraph_funcs.C +++ b/src/paragraph_funcs.C @@ -196,66 +196,72 @@ void mergeParagraph(BufferParams const & bparams, } -Paragraph * depthHook(Paragraph * par, Paragraph::depth_type depth) +ParagraphList::iterator depthHook(ParagraphList::iterator pit, + ParagraphList const & plist, + Paragraph::depth_type depth) { - Paragraph * newpar = par; + ParagraphList::iterator newpit = pit; + ParagraphList::iterator beg = plist.begin(); - do { - newpar = newpar->previous(); - } while (newpar && newpar->getDepth() > depth); + if (newpit != beg) + --newpit; - if (!newpar) { - if (par->previous() || par->getDepth()) - lyxerr << "ERROR (Paragraph::DepthHook): " - "no hook." << endl; - newpar = par; + while (newpit != beg && newpit->getDepth() > depth) { + --newpit; } - return newpar; + if (newpit->getDepth() > depth) + return pit; + + return newpit; } -Paragraph * outerHook(Paragraph * par) +ParagraphList::iterator outerHook(ParagraphList::iterator pit, + ParagraphList const & plist) { - if (!par->getDepth()) - return 0; - return depthHook(par, Paragraph::depth_type(par->getDepth() - 1)); + if (!pit->getDepth()) + return plist.end(); + return depthHook(pit, plist, + Paragraph::depth_type(pit->getDepth() - 1)); } -bool isFirstInSequence(Paragraph * par) +bool isFirstInSequence(ParagraphList::iterator pit, + ParagraphList const & plist) { - Paragraph const * dhook = depthHook(par, par->getDepth()); - return (dhook == par - || dhook->layout() != par->layout() - || dhook->getDepth() != par->getDepth()); + ParagraphList::iterator dhook = depthHook(pit, plist, pit->getDepth()); + return (dhook == pit + || dhook->layout() != pit->layout() + || dhook->getDepth() != pit->getDepth()); } -int getEndLabel(Paragraph * p) +int getEndLabel(ParagraphList::iterator p, + ParagraphList const & plist) { - Paragraph * par = p; + ParagraphList::iterator pit = p; Paragraph::depth_type par_depth = p->getDepth(); - while (par) { - LyXLayout_ptr const & layout = par->layout(); + while (pit != plist.end()) { + LyXLayout_ptr const & layout = pit->layout(); int const endlabeltype = layout->endlabeltype; if (endlabeltype != END_LABEL_NO_LABEL) { - if (!p->next()) + if (boost::next(p) == plist.end()) return endlabeltype; - Paragraph::depth_type const next_depth = p->next()->getDepth(); + Paragraph::depth_type const next_depth = boost::next(p)->getDepth(); if (par_depth > next_depth || - (par_depth == next_depth - && layout != p->next()->layout())) + (par_depth == next_depth && + layout != boost::next(p)->layout())) return endlabeltype; break; } if (par_depth == 0) break; - par = outerHook(par); - if (par) - par_depth = par->getDepth(); + pit = outerHook(pit, plist); + if (pit != plist.end()) + par_depth = pit->getDepth(); } return END_LABEL_NO_LABEL; } @@ -1031,18 +1037,18 @@ int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex) LyXFont const outerFont(ParagraphList::iterator pit, - ParagraphList const & /*plist*/) + ParagraphList const & plist) { Paragraph::depth_type par_depth = pit->getDepth(); LyXFont tmpfont(LyXFont::ALL_INHERIT); // Resolve against environment font information - Paragraph * par = &*pit; - while (par && par_depth && !tmpfont.resolved()) { - par = outerHook(par); - if (par) { - tmpfont.realize(par->layout()->font); - par_depth = par->getDepth(); + while (pit != plist.end() && + par_depth && !tmpfont.resolved()) { + pit = outerHook(pit, plist); + if (pit != plist.end()) { + tmpfont.realize(pit->layout()->font); + par_depth = pit->getDepth(); } } diff --git a/src/paragraph_funcs.h b/src/paragraph_funcs.h index 433c5a04b2..3270494e65 100644 --- a/src/paragraph_funcs.h +++ b/src/paragraph_funcs.h @@ -42,17 +42,23 @@ void mergeParagraph(BufferParams const & bparams, ParagraphList & paragraphs, ParagraphList::iterator par); -/// for the environments -Paragraph * depthHook(Paragraph * par, Paragraph::depth_type depth); -Paragraph * outerHook(Paragraph * par); +/// for the environments +ParagraphList::iterator depthHook(ParagraphList::iterator pit, + ParagraphList const & plist, + Paragraph::depth_type depth); + +ParagraphList::iterator outerHook(ParagraphList::iterator pit, + ParagraphList const & plist); /// Is it the first par with same depth and layout? -bool isFirstInSequence(Paragraph * par); +bool isFirstInSequence(ParagraphList::iterator par, + ParagraphList const & plist); /** Check if the current paragraph is the last paragraph in a proof environment */ -int getEndLabel(Paragraph * para); +int getEndLabel(ParagraphList::iterator pit, + ParagraphList const & plist); void latexParagraphs(Buffer const * buf, diff --git a/src/rowpainter.C b/src/rowpainter.C index 4e10bb0ab7..708059be9d 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -674,7 +674,7 @@ void RowPainter::paintFirst() if (layout->labeltype >= LABEL_STATIC && (layout->labeltype != LABEL_STATIC || layout->latextype != LATEX_ENVIRONMENT - || isFirstInSequence(&*pit_))) { + || isFirstInSequence(pit_, text_.ownerParagraphs()))) { LyXFont font = getLabelFont(); if (!pit_->getLabelstring().empty()) { @@ -722,7 +722,7 @@ void RowPainter::paintFirst() // the labels at the top of an environment. // More or less for bibliography - } else if (isFirstInSequence(&*pit_) && + } else if (isFirstInSequence(pit_, text_.ownerParagraphs()) && (layout->labeltype == LABEL_TOP_ENVIRONMENT || layout->labeltype == LABEL_BIBLIO || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) { @@ -797,7 +797,7 @@ void RowPainter::paintLast() } bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params); - int const endlabel = getEndLabel(&*pit_); + int const endlabel = getEndLabel(pit_, text_.ownerParagraphs()); // draw an endlabel switch (endlabel) { diff --git a/src/text.C b/src/text.C index 228f46c4f4..e6e6bec91a 100644 --- a/src/text.C +++ b/src/text.C @@ -538,29 +538,33 @@ int LyXText::leftMargin(Row const & row) const if (row.par()->layout() == tclass.defaultLayout()) { // find the previous same level paragraph if (row.par() != ownerParagraphs().begin()) { - Paragraph * newpar = - depthHook(&*row.par(), row.par()->getDepth()); - if (newpar && - newpar->layout()->nextnoindent) + ParagraphList::iterator newpit = + depthHook(row.par(), ownerParagraphs(), + row.par()->getDepth()); + if (newpit == row.par() && + newpit->layout()->nextnoindent) parindent.erase(); } } } else { // find the next level paragraph - Paragraph * newpar = outerHook(&*row.par()); + ParagraphList::iterator newpar = outerHook(row.par(), + ownerParagraphs()); // make a corresponding row. Needed to call leftMargin() // check wether it is a sufficent paragraph - if (newpar && newpar->layout()->isEnvironment()) { + if (newpar != ownerParagraphs().end() && + newpar->layout()->isEnvironment()) { Row dummyrow; dummyrow.par(newpar); dummyrow.pos(newpar->size()); x = leftMargin(dummyrow); } - if (newpar && row.par()->layout() == tclass.defaultLayout()) { + if (newpar != ownerParagraphs().end() && + row.par()->layout() == tclass.defaultLayout()) { if (newpar->params().noindent()) parindent.erase(); else { @@ -614,7 +618,7 @@ int LyXText::leftMargin(Row const & row) const // theorems (JMarc) || (layout->labeltype == LABEL_STATIC && layout->latextype == LATEX_ENVIRONMENT - && !isFirstInSequence(&*row.par()))) { + && !isFirstInSequence(row.par(), ownerParagraphs()))) { x += font_metrics::signedWidth(layout->leftmargin, labelfont); } else if (layout->labeltype != LABEL_TOP_ENVIRONMENT @@ -679,7 +683,7 @@ int LyXText::leftMargin(Row const & row) const || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT || (layout->labeltype == LABEL_STATIC && layout->latextype == LATEX_ENVIRONMENT - && !isFirstInSequence(&*row.par()))) + && !isFirstInSequence(row.par(), ownerParagraphs()))) && align == LYX_ALIGN_BLOCK && !row.par()->params().noindent() // in tabulars and ert paragraphs are never indented! @@ -1153,7 +1157,7 @@ void LyXText::setHeightOfRow(RowList::iterator rit) if ((layout->labeltype == LABEL_TOP_ENVIRONMENT || layout->labeltype == LABEL_BIBLIO || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) - && isFirstInSequence(&*pit) + && isFirstInSequence(pit, ownerParagraphs()) && !pit->getLabelstring().empty()) { float spacing_val = 1.0; @@ -1174,14 +1178,15 @@ void LyXText::setHeightOfRow(RowList::iterator rit) + layout->labelbottomsep * defaultRowHeight()); } - // and now the layout spaces, for example before and after a section, - // or between the items of a itemize or enumerate environment + // And now the layout spaces, for example before and after + // a section, or between the items of a itemize or enumerate + // environment. if (!pit->params().pagebreakTop()) { - Paragraph * prev = pit->previous(); - if (prev) - prev = depthHook(&*pit, pit->getDepth()); - if (prev && prev->layout() == layout && + ParagraphList::iterator prev = + depthHook(pit, ownerParagraphs(), + pit->getDepth()); + if (prev != pit && prev->layout() == layout && prev->getDepth() == pit->getDepth() && prev->getLabelWidthString() == pit->getLabelWidthString()) { @@ -1201,8 +1206,8 @@ void LyXText::setHeightOfRow(RowList::iterator rit) layoutasc = (tmptop * defaultRowHeight()); } - prev = outerHook(&*pit); - if (prev) { + prev = outerHook(pit, ownerParagraphs()); + if (prev != ownerParagraphs().end()) { maxasc += int(prev->layout()->parsep * defaultRowHeight()); } else if (pit != ownerParagraphs().begin()) { ParagraphList::iterator prior_pit = boost::prior(pit); @@ -1250,7 +1255,7 @@ void LyXText::setHeightOfRow(RowList::iterator rit) if (comparepit->getDepth() > nextpit->getDepth()) { usual = (comparepit->layout()->bottomsep * defaultRowHeight()); - comparepit = depthHook(&*comparepit, nextpit->getDepth()); + comparepit = depthHook(comparepit, ownerParagraphs(), nextpit->getDepth()); if (comparepit->layout()!= nextpit->layout() || nextpit->getLabelWidthString() != comparepit->getLabelWidthString()) diff --git a/src/text2.C b/src/text2.C index 32c8f0c1b2..2cbbe8077c 100644 --- a/src/text2.C +++ b/src/text2.C @@ -230,11 +230,12 @@ void LyXText::setCharFont(Buffer const * buf, ParagraphList::iterator pit, // Realize against environment font information if (pit->getDepth()) { -#warning FIXME I think I hate this outerHood stuff. - Paragraph * tp = &*pit; - while (!layoutfont.resolved() && tp && tp->getDepth()) { - tp = outerHook(tp); - if (tp) + ParagraphList::iterator tp = pit; + while (!layoutfont.resolved() && + tp != ownerParagraphs().end() && + tp->getDepth()) { + tp = outerHook(tp, ownerParagraphs()); + if (tp != ownerParagraphs().end()) layoutfont.realize(tp->layout()->font); } } @@ -1073,7 +1074,8 @@ void LyXText::setCounter(Buffer const * buf, ParagraphList::iterator pit) if (pit != ownerParagraphs().begin() && boost::prior(pit)->getDepth() > pit->getDepth() && layout->labeltype != LABEL_BIBLIO) { - pit->enumdepth = depthHook(&*pit, pit->getDepth())->enumdepth; + pit->enumdepth = depthHook(pit, ownerParagraphs(), + pit->getDepth())->enumdepth; } if (!pit->params().labelString().empty()) { @@ -1492,8 +1494,7 @@ void LyXText::insertStringAsLines(string const & str) // only to be sure, should not be neccessary clearSelection(); - Paragraph * par = &*pit; - bv()->buffer()->insertStringAsLines(par, pos, current_font, str); + bv()->buffer()->insertStringAsLines(pit, pos, current_font, str); redoParagraphs(cursor, endpit); setCursor(cursor.par(), cursor.pos());