2003-03-31 Lars Gullik Bjønnes <larsbj@gullik.net>
+ * 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.
}
+////////// 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<RowList::const_iterator&>(i1))
+ == &(*const_cast<RowList::const_iterator&>(i2));
+}
+
+
+bool operator!=(RowList::const_iterator const & i1,
+ RowList::const_iterator const & i2)
+{
+ return !(i1 == i2);
+}
+
+
////////// The RowList proper
RowList::RowList()
: rowlist(0)
}
-RowList::iterator RowList::begin() const
+RowList::const_iterator RowList::begin() const
{
- return iterator(rowlist);
+ return const_iterator(rowlist);
}
}
-RowList::iterator RowList::end() const
+RowList::const_iterator RowList::end() const
{
- return iterator();
+ return const_iterator();
}
}
-void RowList::set(Row * p)
-{
- rowlist = p;
-}
-
-
void RowList::push_back(Row * p)
{
if (!rowlist) {
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);
///
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 *);
///
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
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
bool bidi_InRange(lyx::pos_type pos) const;
private:
///
- RowList rowlist_;
+ mutable RowList rowlist_;
///
void cursorLeftOneWord(LyXCursor &);
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();
}
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;
// 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)
// 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;
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;
x += w;
}
break;
+ }
case LYX_ALIGN_RIGHT:
x += w;
break;
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;
// 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;
}
setHeightOfRow(prevrow);
const_cast<LyXText *>(this)->postPaint(y - prevrow->height());
} else {
- setHeightOfRow(&*rows().begin());
+ setHeightOfRow(rows().begin());
const_cast<LyXText *>(this)->postPaint(0);
}
string const & newLabel = par->params().labelString();
if (oldLabel.empty() && !newLabel.empty()) {
- removeParagraph(&*rowit);
+ removeParagraph(rowit);
appendParagraph(rowit);
}
y -= boost::prior(row)->height();
postPaint(y);
- breakAgain(&*boost::prior(row));
+ breakAgain(boost::prior(row));
// set the cursor again. Otherwise
// dangling pointers are possible
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)))