From 2813e744ac367849e7ac7c450fa1be08bf82314d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Thu, 10 Apr 2003 12:10:04 +0000 Subject: [PATCH] More ParagraphList::iterator work. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6763 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 12 ++++++++- src/lyxtext.h | 13 ++++++---- src/text.C | 42 +++++++++++++++---------------- src/text2.C | 68 ++++++++++++++++++++++++++++----------------------- 4 files changed, 77 insertions(+), 58 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index d73285477c..e505b288bb 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2003-04-10 Lars Gullik Bjønnes + + * text2.C: adjust several funcs. + (realizeFont): take a ParagraphList::iterator as arg. + (getLayoutFont): ditto + (getLabelFont): ditto + (setCharFont): ditto + + * text.C: adjust several funcs. + 2003-04-09 Alfredo Braunstein * text.C (selectNextWordToSpellcheck): don't accidentally @@ -10,7 +20,7 @@ 2003-04-09 Alfredo Braunstein - * text2.C (cursorRight): a getChar assert fixed + * text2.C (cursorRight): a getChar assert fixed 2003-04-09 Lars Gullik Bjønnes diff --git a/src/lyxtext.h b/src/lyxtext.h index 5cf8229de0..6dd09b6237 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -105,14 +105,17 @@ public: LyXFont const getFont(Buffer const *, ParagraphList::iterator pit, lyx::pos_type pos) const; /// - LyXFont const getLayoutFont(Buffer const *, Paragraph * par) const; + LyXFont const getLayoutFont(Buffer const *, + ParagraphList::iterator pit) const; /// - LyXFont const getLabelFont(Buffer const *, Paragraph * par) const; + LyXFont const getLabelFont(Buffer const *, + ParagraphList::iterator pit) const; /// - void setCharFont(Buffer const *, Paragraph * par, + void setCharFont(Buffer const *, ParagraphList::iterator pit, lyx::pos_type pos, LyXFont const & font); - void setCharFont(Paragraph * par, - lyx::pos_type pos, LyXFont const & font, bool toggleall); + void setCharFont(ParagraphList::iterator pit, + lyx::pos_type pos, + LyXFont const & font, bool toggleall); /// void breakAgainOneRow(RowList::iterator rit); diff --git a/src/text.C b/src/text.C index 24e3c11d02..a85c76515c 100644 --- a/src/text.C +++ b/src/text.C @@ -561,7 +561,7 @@ int LyXText::leftMargin(Row const & row) const } } - LyXFont const labelfont = getLabelFont(bv()->buffer(), &*row.par()); + LyXFont const labelfont = getLabelFont(bv()->buffer(), row.par()); switch (layout->margintype) { case MARGIN_DYNAMIC: if (!layout->leftmargin.empty()) { @@ -797,7 +797,7 @@ LyXText::rowBreakPoint(Row const & row) const // add the auto-hfill from label end to the body if (body_pos && i == body_pos) { thiswidth += font_metrics::width(layout->labelsep, - getLabelFont(bv()->buffer(), &*pit)); + getLabelFont(bv()->buffer(), pit)); if (pit->isLineSeparator(i - 1)) thiswidth -= singleWidth(pit, i - 1); } @@ -894,7 +894,7 @@ int LyXText::fill(RowList::iterator row, int paper_width) const while (i <= last) { if (body_pos > 0 && i == body_pos) { - w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), &*pit)); + w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), pit)); if (pit->isLineSeparator(i - 1)) w -= singleWidth(pit, i - 1); int left_margin = labelEnd(*row); @@ -905,7 +905,7 @@ int LyXText::fill(RowList::iterator row, int paper_width) const ++i; } if (body_pos > 0 && body_pos > last) { - w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), &*pit)); + w += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), pit)); if (last >= 0 && pit->isLineSeparator(last)) w -= singleWidth(pit, last); int const left_margin = labelEnd(*row); @@ -943,7 +943,7 @@ int LyXText::labelFill(Row const & row) const int fill = 0; string const & labwidstr = row.par()->params().labelWidthString(); if (!labwidstr.empty()) { - LyXFont const labfont = getLabelFont(bv()->buffer(), &*row.par()); + LyXFont const labfont = getLabelFont(bv()->buffer(), row.par()); int const labwidth = font_metrics::width(labwidstr, labfont); fill = max(labwidth - w, 0); } @@ -991,13 +991,13 @@ void LyXText::setHeightOfRow(RowList::iterator rit) // as max get the first character of this row then it can increase but not // decrease the height. Just some point to start with so we don't have to // do the assignment below too often. - LyXFont font = getFont(bv()->buffer(), &*pit, rit->pos()); + LyXFont font = getFont(bv()->buffer(), pit, rit->pos()); LyXFont::FONT_SIZE const tmpsize = font.size(); - font = getLayoutFont(bv()->buffer(), &*pit); + font = getLayoutFont(bv()->buffer(), pit); LyXFont::FONT_SIZE const size = font.size(); font.setSize(tmpsize); - LyXFont labelfont = getLabelFont(bv()->buffer(), &*pit); + LyXFont labelfont = getLabelFont(bv()->buffer(), pit); float spacing_val = 1.0; if (!rit->par()->params().spacing().isDefault()) { @@ -1022,7 +1022,7 @@ void LyXText::setHeightOfRow(RowList::iterator rit) // Check if any insets are larger for (pos_type pos = rit->pos(); pos <= pos_end; ++pos) { if (rit->par()->isInset(pos)) { - tmpfont = getFont(bv()->buffer(), &*rit->par(), pos); + tmpfont = getFont(bv()->buffer(), rit->par(), pos); tmpinset = rit->par()->getInset(pos); if (tmpinset) { #if 1 // this is needed for deep update on initialitation @@ -1096,7 +1096,7 @@ void LyXText::setHeightOfRow(RowList::iterator rit) if (firstpit->params().lineTop()) maxasc += 2 * font_metrics::ascent('x', getFont(bv()->buffer(), - &*firstpit, 0)); + firstpit, 0)); // and now the pagebreaks if (firstpit->params().pagebreakTop()) maxasc += 3 * defaultRowHeight(); @@ -1210,7 +1210,7 @@ void LyXText::setHeightOfRow(RowList::iterator rit) if (firstpit->params().lineBottom()) maxdesc += 2 * font_metrics::ascent('x', getFont(bv()->buffer(), - &*pit, + pit, max(pos_type(0), pit->size() - 1))); // and now the pagebreaks @@ -1548,10 +1548,10 @@ void LyXText::insertChar(char c) cursor.pos() >= 1 && cursor.pos() < cursor.par()->size() && getFont(bv()->buffer(), - &*cursor.par(), + cursor.par(), cursor.pos()).number() == LyXFont::ON && getFont(bv()->buffer(), - &*cursor.par(), + cursor.par(), cursor.pos() - 1).number() == LyXFont::ON) ) number(bv()); // Set current_font.number to OFF @@ -1573,10 +1573,10 @@ void LyXText::insertChar(char c) } else if (contains(number_seperators, c) && cursor.pos() >= 2 && getFont(bv()->buffer(), - &*cursor.par(), + cursor.par(), cursor.pos() - 2).number() == LyXFont::ON) { setCharFont(bv()->buffer(), - &*cursor.par(), + cursor.par(), cursor.pos() - 1, current_font); } @@ -1906,7 +1906,7 @@ void LyXText::prepareToPrint(RowList::iterator rit, float & x, !rit->par()->isLineSeparator(body_pos - 1))) { x += font_metrics::width(layout->labelsep, getLabelFont(bv()->buffer(), - &*rit->par())); + rit->par())); if (body_pos - 1 <= last) x += fill_label_hfill; } @@ -2161,11 +2161,11 @@ LyXText::selectNextWordToSpellcheck(float & value) bool const is_good_inset = cpit->isInset(cpos) && cpit->getInset(cpos)->allowSpellcheck(); - - if (!isDeletedText(*cpit, cpos) + + if (!isDeletedText(*cpit, cpos) && (is_good_inset || cpit->isLetter(cpos))) - break; - + break; + cursor.pos(cpos + 1); } @@ -2189,7 +2189,7 @@ LyXText::selectNextWordToSpellcheck(float & value) selection.cursor = cursor; string lang_code( - getFont(bv()->buffer(), &*cursor.par(), cursor.pos()) + getFont(bv()->buffer(), cursor.par(), cursor.pos()) .language()->code()); // and find the end of the word (insets like optional hyphens // and ligature break are part of a word) diff --git a/src/text2.C b/src/text2.C index 2ba74b7660..764fc073dc 100644 --- a/src/text2.C +++ b/src/text2.C @@ -84,15 +84,15 @@ void LyXText::init(BufferView * bview, bool reinit) } else if (!rowlist_.empty()) return; - ParagraphList::iterator par = ownerParagraphs().begin(); + ParagraphList::iterator pit = ownerParagraphs().begin(); ParagraphList::iterator end = ownerParagraphs().end(); - current_font = getFont(bview->buffer(), &*par, 0); + current_font = getFont(bview->buffer(), pit, 0); - for (; par != end; ++par) { - insertParagraph(&*par, rowlist_.end()); + for (; pit != end; ++pit) { + insertParagraph(&*pit, rowlist_.end()); } - setCursorIntern(&*rowlist_.begin()->par(), 0); + setCursorIntern(rowlist_.begin()->par(), 0); selection.cursor = cursor; updateCounters(); @@ -103,11 +103,14 @@ namespace { LyXFont const realizeFont(LyXFont const & font, Buffer const * buf, - Paragraph * par) + ParagraphList & /*plist*/, + ParagraphList::iterator pit) { LyXTextClass const & tclass = buf->params.getLyXTextClass(); LyXFont tmpfont(font); - Paragraph::depth_type par_depth = par->getDepth(); + Paragraph::depth_type par_depth = pit->getDepth(); + + Paragraph * par = &*pit; // Resolve against environment font information while (par && par_depth && !tmpfont.resolved()) { @@ -175,44 +178,46 @@ LyXFont const LyXText::getFont(Buffer const * buf, ParagraphList::iterator pit, if (pit->inInset()) pit->inInset()->getDrawFont(tmpfont); - return realizeFont(tmpfont, buf, &*pit); + return realizeFont(tmpfont, buf, ownerParagraphs(), pit); } -LyXFont const LyXText::getLayoutFont(Buffer const * buf, Paragraph * par) const +LyXFont const LyXText::getLayoutFont(Buffer const * buf, + ParagraphList::iterator pit) const { - LyXLayout_ptr const & layout = par->layout(); + LyXLayout_ptr const & layout = pit->layout(); - if (!par->getDepth()) { + if (!pit->getDepth()) { return layout->resfont; } - return realizeFont(layout->font, buf, par); + return realizeFont(layout->font, buf, ownerParagraphs(), pit); } -LyXFont const LyXText::getLabelFont(Buffer const * buf, Paragraph * par) const +LyXFont const LyXText::getLabelFont(Buffer const * buf, + ParagraphList::iterator pit) const { - LyXLayout_ptr const & layout = par->layout(); + LyXLayout_ptr const & layout = pit->layout(); - if (!par->getDepth()) { + if (!pit->getDepth()) { return layout->reslabelfont; } - return realizeFont(layout->labelfont, buf, par); + return realizeFont(layout->labelfont, buf, ownerParagraphs(), pit); } -void LyXText::setCharFont(Paragraph * par, +void LyXText::setCharFont(ParagraphList::iterator pit, pos_type pos, LyXFont const & fnt, bool toggleall) { Buffer const * buf = bv()->buffer(); - LyXFont font = getFont(buf, par, pos); + LyXFont font = getFont(buf, pit, pos); font.update(fnt, buf->params.language, toggleall); // Let the insets convert their font - if (par->isInset(pos)) { - Inset * inset = par->getInset(pos); + if (pit->isInset(pos)) { + Inset * inset = pit->getInset(pos); if (isEditableInset(inset)) { UpdatableInset * uinset = static_cast(inset); @@ -221,29 +226,30 @@ void LyXText::setCharFont(Paragraph * par, } // Plug thru to version below: - setCharFont(buf, par, pos, font); + setCharFont(buf, pit, pos, font); } -void LyXText::setCharFont(Buffer const * buf, Paragraph * par, +void LyXText::setCharFont(Buffer const * buf, ParagraphList::iterator pit, pos_type pos, LyXFont const & fnt) { LyXFont font(fnt); LyXTextClass const & tclass = buf->params.getLyXTextClass(); - LyXLayout_ptr const & layout = par->layout(); + LyXLayout_ptr const & layout = pit->layout(); // Get concrete layout font to reduce against LyXFont layoutfont; - if (pos < par->beginningOfBody()) + if (pos < pit->beginningOfBody()) layoutfont = layout->labelfont; else layoutfont = layout->font; // Realize against environment font information - if (par->getDepth()) { - Paragraph * tp = par; + if (pit->getDepth()) { +#warning FIXME I think I hate this outerHood stuff. + Paragraph * tp = &*pit; while (!layoutfont.resolved() && tp && tp->getDepth()) { tp = tp->outerHook(); if (tp) @@ -256,7 +262,7 @@ void LyXText::setCharFont(Buffer const * buf, Paragraph * par, // Now, reduce font against full layout font font.reduce(layoutfont); - par->setFont(pos, font); + pit->setFont(pos, font); } @@ -546,10 +552,10 @@ void LyXText::setFont(LyXFont const & font, bool toggleall) LyXFont layoutfont; if (cursor.pos() < cursor.par()->beginningOfBody()) { layoutfont = getLabelFont(bv()->buffer(), - &*cursor.par()); + cursor.par()); } else { layoutfont = getLayoutFont(bv()->buffer(), - &*cursor.par()); + cursor.par()); } // Update current font real_current_font.update(font, @@ -1768,7 +1774,7 @@ float LyXText::getCursorX(RowList::iterator rit, font_metrics::width( rit->par()->layout()->labelsep, getLabelFont(bv()->buffer(), - &*rit->par())); + rit->par())); if (rit->par()->isLineSeparator(body_pos - 1)) x -= singleWidth(rit->par(), body_pos - 1); } @@ -1847,7 +1853,7 @@ void LyXText::setCurrentFont() current_font = cursor.par()->getFontSettings(bv()->buffer()->params, pos); - real_current_font = getFont(bv()->buffer(), &*cursor.par(), pos); + real_current_font = getFont(bv()->buffer(), cursor.par(), pos); if (cursor.pos() == cursor.par()->size() && isBoundary(bv()->buffer(), &*cursor.par(), cursor.pos()) && -- 2.39.5