From 0011b84a16d6507bdebda08e49121ccf6ac2ae1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Thu, 23 Oct 2003 09:06:18 +0000 Subject: [PATCH] move width computation to helper function git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7961 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/text.C | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/text.C b/src/text.C index 14790edd13..d9df3f891c 100644 --- a/src/text.C +++ b/src/text.C @@ -75,6 +75,21 @@ extern int const LEFT_MARGIN = PAPER_MARGIN + CHANGEBAR_MARGIN; int bibitemMaxWidth(BufferView *, LyXFont const &); +namespace { + +unsigned int maxParagraphWidth(ParagraphList const & plist) +{ + unsigned int width = 0; + ParagraphList::const_iterator pit = plist.begin(); + ParagraphList::const_iterator end = plist.end(); + for (; pit != end; ++pit) + width = std::max(width, pit->width); + return width; +} + +} // namespace anon + + BufferView * LyXText::bv() { BOOST_ASSERT(bv_owner != 0); @@ -1169,15 +1184,8 @@ void LyXText::setHeightOfRow(ParagraphList::iterator pit, Row & row) row.width(maxwidth); - if (inset_owner) { - width = max(0, workWidth()); - ParagraphList::iterator pit = ownerParagraphs().begin(); - ParagraphList::iterator end = ownerParagraphs().end(); - for ( ; pit != end; ++pit) { - if (width < pit->width) - width = pit->width; - } - } + if (inset_owner) + width = max(workWidth(), int(maxParagraphWidth(ownerParagraphs()))); } @@ -2195,16 +2203,12 @@ void LyXText::metrics(MetricsInfo & mi, Dimension & dim) lyxerr << "LyXText::metrics: width: " << mi.base.textwidth << " workWidth: " << workWidth() << "\nfont: " << mi.base.font << endl; //BOOST_ASSERT(mi.base.textwidth); - - // rebuild row cache //anchor_y_ = 0; + + // rebuild row cache. This recomputes height as well. redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end()); - width = 0; - ParagraphList::iterator pit = ownerParagraphs().begin(); - ParagraphList::iterator end = ownerParagraphs().end(); - for ( ; pit != end; ++pit) - width = std::max(pit->width, width); + width = maxParagraphWidth(ownerParagraphs()); // final dimension dim.asc = firstRow()->ascent_of_text();