From e0e7a0e67ff03ef8831c6973f15c154159539357 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Mon, 31 Mar 2003 16:57:45 +0000 Subject: [PATCH] rowlist7 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6663 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 17 ++++++++++ src/RowList.C | 89 +++++++++++++++++++++++++++++++++++++++++++++------ src/RowList.h | 46 +++++++++++++++++++++++--- src/lyxtext.h | 4 +-- src/text.C | 44 +++++++++++++------------ src/text2.C | 21 ++++++------ 6 files changed, 174 insertions(+), 47 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 87f859a240..3ba04c78f6 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,22 @@ 2003-03-31 Lars Gullik Bjønnes + * text2.C (redoParagraphs): adjust + (updateCounters): adjust + (checkParagraph): adjust + (getColumnNearX): adjust and reformat a bit. + + * text.C (top_y): adjust + (workWidth): adjust + (leftMargin): adjust + (prepareToPrint): adjust + (getRow): adjust + (getRowNearY): adjust + + * lyxtext.h: make rowlist_ mutable. + + * RowList.h: add const_iterator + * RowList.C: adjust for RowList::const_iterator. + * text2.C (getCursorX): make it take a RowList::iterator as arg, adjust. diff --git a/src/RowList.C b/src/RowList.C index 70e11bb056..3693c9c048 100644 --- a/src/RowList.C +++ b/src/RowList.C @@ -79,6 +79,81 @@ bool operator!=(RowList::iterator const & i1, } +////////// The RowList::const_iterator + +RowList::const_iterator::const_iterator() + : ptr(0) +{} + + +RowList::const_iterator::const_iterator(Row * p) + : ptr(p) +{} + + +RowList::const_iterator::const_reference +RowList::const_iterator::operator*() +{ + return *ptr; +} + + +RowList::const_iterator::const_pointer +RowList::const_iterator::operator->() +{ + return ptr; +} + + +RowList::const_iterator & +RowList::const_iterator::operator++() +{ + ptr = ptr->next(); + return *this; +} + + +RowList::const_iterator +RowList::const_iterator::operator++(int) +{ + const_iterator tmp = *this; + ++*this; + return tmp; +} + + +RowList::const_iterator & +RowList::const_iterator::operator--() +{ + ptr = ptr->previous(); + return *this; +} + + +RowList::const_iterator +RowList::const_iterator::operator--(int) +{ + const_iterator tmp = *this; + --*this; + return tmp; +} + + +bool operator==(RowList::const_iterator const & i1, + RowList::const_iterator const & i2) +{ + return &(*const_cast(i1)) + == &(*const_cast(i2)); +} + + +bool operator!=(RowList::const_iterator const & i1, + RowList::const_iterator const & i2) +{ + return !(i1 == i2); +} + + ////////// The RowList proper RowList::RowList() : rowlist(0) @@ -144,9 +219,9 @@ RowList::iterator RowList::begin() } -RowList::iterator RowList::begin() const +RowList::const_iterator RowList::begin() const { - return iterator(rowlist); + return const_iterator(rowlist); } @@ -156,9 +231,9 @@ RowList::iterator RowList::end() } -RowList::iterator RowList::end() const +RowList::const_iterator RowList::end() const { - return iterator(); + return const_iterator(); } @@ -192,12 +267,6 @@ Row & RowList::back() } -void RowList::set(Row * p) -{ - rowlist = p; -} - - void RowList::push_back(Row * p) { if (!rowlist) { diff --git a/src/RowList.h b/src/RowList.h index f5a6a457f7..7fe84e322f 100644 --- a/src/RowList.h +++ b/src/RowList.h @@ -44,6 +44,39 @@ public: Row * ptr; }; /// + class const_iterator { + public: + /// + typedef std::bidirectional_iterator_tag iterator_category; + /// + typedef Row * value_type; + /// + typedef ptrdiff_t difference_type; + /// + typedef Row const * const_pointer; + /// + typedef Row const & const_reference; + /// + const_iterator(); + /// + const_iterator(value_type); + /// + const_reference operator*(); + /// + const_pointer operator->(); + /// + const_iterator & operator++(); + /// + const_iterator operator++(int); + /// + const_iterator & operator--(); + /// + const_iterator operator--(int); + private: + /// + Row * ptr; + }; + /// RowList(); /// iterator insert(iterator it, Row * row); @@ -54,13 +87,11 @@ public: /// iterator begin(); /// - iterator begin() const; + const_iterator begin() const; /// iterator end(); /// - iterator end() const; - /// - void set(Row *); + const_iterator end() const; /// void push_back(Row *); /// @@ -87,4 +118,11 @@ bool operator==(RowList::iterator const & i1, bool operator!=(RowList::iterator const & i1, RowList::iterator const & i2); +/// +bool operator==(RowList::const_iterator const & i1, + RowList::const_iterator const & i2); +/// +bool operator!=(RowList::const_iterator const & i1, + RowList::const_iterator const & i2); + #endif diff --git a/src/lyxtext.h b/src/lyxtext.h index d6e8d89137..8b3f2c0111 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -239,7 +239,7 @@ public: x is set to the real beginning of this column */ lyx::pos_type getColumnNearX(RowList::iterator rit, - int & x, bool & boundary) const; + int & x, bool & boundary) const; /** returns a pointer to a specified row. y is set to the beginning of the row @@ -490,7 +490,7 @@ public: bool bidi_InRange(lyx::pos_type pos) const; private: /// - RowList rowlist_; + mutable RowList rowlist_; /// void cursorLeftOneWord(LyXCursor &); diff --git a/src/text.C b/src/text.C index e900b46d2a..14994acc4d 100644 --- a/src/text.C +++ b/src/text.C @@ -74,13 +74,13 @@ BufferView * LyXText::bv() const int LyXText::top_y() const { - if (anchor_row_ == rows().end()) + if (anchor_row_ == rowlist_.end()) return 0; int y = 0; - RowList::iterator rit = rows().begin(); - RowList::iterator end = rows().end(); + RowList::iterator rit = rowlist_.begin(); + RowList::iterator end = rowlist_.end(); for (; rit != end && rit != anchor_row_; ++rit) { y += rit->height(); } @@ -154,7 +154,7 @@ int LyXText::workWidth(Inset * inset) const int dummy_y; RowList::iterator row = getRow(par, pos, dummy_y); RowList::iterator frow = row; - RowList::iterator beg = rows().begin(); + RowList::iterator beg = rowlist_.begin(); while (frow != beg && frow->par() == boost::prior(frow)->par()) --frow; @@ -632,12 +632,12 @@ int LyXText::leftMargin(RowList::iterator rit) const // find the first row of this paragraph RowList::iterator tmprit = rit; - while (tmprit != rows().begin() + while (tmprit != rowlist_.begin() && boost::prior(tmprit)->par() == rit->par()) --tmprit; int minfill = tmprit->fill(); - while (boost::next(tmprit) != rows().end() && + while (boost::next(tmprit) != rowlist_.end() && boost::next(tmprit)->par() == rit->par()) { ++tmprit; if (tmprit->fill() < minfill) @@ -907,7 +907,7 @@ LyXText::rowBreakPoint(Row const & row) const // returns the minimum space a row needs on the screen in pixel -int LyXText::fill(Row & row, int paper_width) const +int LyXText::fill(Row & row, int paper_width) { if (paper_width < 0) return 0; @@ -1892,13 +1892,15 @@ void LyXText::prepareToPrint(RowList::iterator rit, float & x, switch (align) { case LYX_ALIGN_BLOCK: + { ns = rit->numberOfSeparators(); - if (ns && boost::next(rit) != rows().end() && - boost::next(rit)->par() == rit->par() && - !(boost::next(rit)->par()->isNewline(boost::next(rit)->pos() - 1)) - && !(boost::next(rit)->par()->isInset(boost::next(rit)->pos()) - && boost::next(rit)->par()->getInset(boost::next(rit)->pos()) - && boost::next(rit)->par()->getInset(boost::next(rit)->pos())->display()) + RowList::iterator next_row = boost::next(rit); + if (ns && next_row != rowlist_.end() && + next_row->par() == rit->par() && + !(next_row->par()->isNewline(next_row->pos() - 1)) + && !(next_row->par()->isInset(next_row->pos()) && + next_row->par()->getInset(next_row->pos()) && + next_row->par()->getInset(next_row->pos())->display()) ) { fill_separator = w / ns; @@ -1906,6 +1908,7 @@ void LyXText::prepareToPrint(RowList::iterator rit, float & x, x += w; } break; + } case LYX_ALIGN_RIGHT: x += w; break; @@ -2783,11 +2786,11 @@ LyXText::getRow(Paragraph * par, pos_type pos, int & y) const y = 0; if (rows().empty()) - return rows().end(); + return rowlist_.end(); // find the first row of the specified paragraph - RowList::iterator rit = rows().begin(); - RowList::iterator end = rows().end(); + RowList::iterator rit = rowlist_.begin(); + RowList::iterator end = rowlist_.end(); while (boost::next(rit) != end && rit->par() != par) { y += rit->height(); ++rit; @@ -2811,17 +2814,16 @@ RowList::iterator LyXText::getRowNearY(int & y) const // If possible we should optimize this method. (Lgb) int tmpy = 0; - RowList::iterator rit = rows().begin(); - RowList::iterator end = rows().end(); + RowList::iterator rit = rowlist_.begin(); + RowList::iterator end = rowlist_.end(); while (rit != end && boost::next(rit) != end && tmpy + rit->height() <= y) { tmpy += rit->height(); ++rit; } - y = tmpy; // return the real y - - //lyxerr << "returned y = " << y << endl; + // return the real y + y = tmpy; return rit; } diff --git a/src/text2.C b/src/text2.C index 9d190a8d42..d0b793b866 100644 --- a/src/text2.C +++ b/src/text2.C @@ -750,7 +750,7 @@ void LyXText::redoParagraphs(LyXCursor const & cur, setHeightOfRow(prevrow); const_cast(this)->postPaint(y - prevrow->height()); } else { - setHeightOfRow(&*rows().begin()); + setHeightOfRow(rows().begin()); const_cast(this)->postPaint(0); } @@ -1289,7 +1289,7 @@ void LyXText::updateCounters() string const & newLabel = par->params().labelString(); if (oldLabel.empty() && !newLabel.empty()) { - removeParagraph(&*rowit); + removeParagraph(rowit); appendParagraph(rowit); } @@ -1575,7 +1575,7 @@ void LyXText::checkParagraph(Paragraph * par, pos_type pos) y -= boost::prior(row)->height(); postPaint(y); - breakAgain(&*boost::prior(row)); + breakAgain(boost::prior(row)); // set the cursor again. Otherwise // dangling pointers are possible @@ -1946,15 +1946,16 @@ LyXText::getColumnNearX(RowList::iterator rit, int & x, vc = last + 1; boundary = false; - bool const lastrow = lyxrc.rtl_support // This is not needed, but gives - // some speedup if rtl_support=false - && (boost::next(rit) == rows().end() || - boost::next(rit)->par() != rit->par()); + // This (rtl_support test) is not needed, but gives + // some speedup if rtl_support=false + bool const lastrow = lyxrc.rtl_support && + (boost::next(rit) == rowlist_.end() || + boost::next(rit)->par() != rit->par()); + // If lastrow is false, we don't need to compute + // the value of rtl. bool const rtl = (lastrow) ? rit->par()->isRightToLeftPar(bv()->buffer()->params) - : false; // If lastrow is false, we don't need to compute - // the value of rtl. - + : false; if (lastrow && ((rtl && left_side && vc == rit->pos() && x < tmpx - 5) || (!rtl && !left_side && vc == last + 1 && x > tmpx + 5))) -- 2.39.5