diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index b4e9f5c6c1..d167010f8e 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -260,9 +260,9 @@ int BufferView::Pimpl::resizeCurrentBuffer() { lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl; - Paragraph * par = 0; - Paragraph * selstartpar = 0; - Paragraph * selendpar = 0; + ParagraphList::iterator par; + ParagraphList::iterator selstartpar; + ParagraphList::iterator selendpar; UpdatableInset * the_locking_inset = 0; pos_type pos = 0; @@ -276,11 +276,11 @@ int BufferView::Pimpl::resizeCurrentBuffer() owner_->message(_("Formatting document...")); if (bv_->text) { - par = &*bv_->text->cursor.par(); + par = bv_->text->cursor.par(); pos = bv_->text->cursor.pos(); - selstartpar = &*bv_->text->selection.start.par(); + selstartpar = bv_->text->selection.start.par(); selstartpos = bv_->text->selection.start.pos(); - selendpar = &*bv_->text->selection.end.par(); + selendpar = bv_->text->selection.end.par(); selendpos = bv_->text->selection.end.pos(); selection = bv_->text->selection.set(); mark_set = bv_->text->selection.mark(); @@ -311,9 +311,13 @@ int BufferView::Pimpl::resizeCurrentBuffer() bv_->text->init(bv_); //buffer_->resizeInsets(bv_); } + + par = bv_->text->ownerParagraphs().end(); + selstartpar = bv_->text->ownerParagraphs().end(); + selendpar = bv_->text->ownerParagraphs().end(); } - if (par) { + if (par != bv_->text->ownerParagraphs().end()) { bv_->text->selection.set(true); // At this point just to avoid the Delete-Empty-Paragraph- // Mechanism when setting the cursor. diff --git a/src/ChangeLog b/src/ChangeLog index 39d56ec09c..9ac1eaa903 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,22 @@ +2003-05-27 Lars Gullik Bjønnes + + * text3.C: adjust + + * text2.C (cursorBottom): adjust + (setCounter): use ParagraphList::find, adjust + + * text.C (workWidth): use ParagraphList::find, adjust + + * lyxcursor.C (LyXCursor): adjust + + * buffer.C (inset_iterator): adjust + + * ParagraphList.h: make iterator(value_type) private, make + ParagraphList a friend of iterator. + + * ParagraphList.C (find): new function + + * BufferView_pimpl.C (resizeCurrentBuffer): adjust 2003-05-27 André Pönitz diff --git a/src/ParagraphList.C b/src/ParagraphList.C index 0c70bee13d..d9884aa316 100644 --- a/src/ParagraphList.C +++ b/src/ParagraphList.C @@ -315,4 +315,17 @@ bool ParagraphList::empty() const return parlist == 0; } + +ParagraphList::iterator ParagraphList::find(Paragraph const & p) +{ + iterator it = begin(); + iterator last = end(); + for (;it != last; ++it) { + if (&*it == &p) + break; + } + return it; +} + + #endif diff --git a/src/ParagraphList.h b/src/ParagraphList.h index 688d551465..a4bba61552 100644 --- a/src/ParagraphList.h +++ b/src/ParagraphList.h @@ -26,6 +26,7 @@ public: /// class iterator { public: + friend class ParagraphList; /// typedef std::bidirectional_iterator_tag iterator_category; /// @@ -39,8 +40,6 @@ public: /// iterator(); /// - iterator(value_type); - /// reference operator*(); /// pointer operator->(); @@ -53,6 +52,8 @@ public: /// iterator operator--(int); private: + /// + iterator(value_type); /// Paragraph * ptr; }; @@ -98,6 +99,8 @@ public: int size() const; /// bool empty() const; + /// + iterator find(Paragraph const &); private: /// Paragraph * parlist; diff --git a/src/buffer.C b/src/buffer.C index 03974c0439..d1291f503b 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -2383,7 +2383,7 @@ void Buffer::setParentName(string const & name) Buffer::inset_iterator::inset_iterator() - : pit(0), pend(0) + : pit(), pend() {} diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 6808d777e8..39f33a15e5 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,14 @@ +2003-05-27 Lars Gullik Bjønnes + + * insettext.C (saveLyXTextState): adjust + (restoreLyXTextState): adjust + (init): adjust + (lockInset): adjust + (unlockInsetInInset): adjust + (localDispatch): adjust + (getLyXText): adjust + + * insettabular.C (insertAsciiString): adjust 2003-05-27 André Pönitz diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index d22eb5de66..fa971302aa 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -2811,7 +2811,7 @@ bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf, if (cols < columns) { InsetText * ti = loctab->GetCellInset(cell); LyXFont const font = ti->getLyXText(bv)-> - getFont(bv->buffer(), &*ti->paragraphs.begin(), 0); + getFont(bv->buffer(), ti->paragraphs.begin(), 0); ti->setText(buf.substr(op, p - op), font); ++cols; ++cell; @@ -2822,7 +2822,7 @@ bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf, if (cols < columns) { InsetText * ti = loctab->GetCellInset(cell); LyXFont const font = ti->getLyXText(bv)-> - getFont(bv->buffer(), &*ti->paragraphs.begin(), 0); + getFont(bv->buffer(), ti->paragraphs.begin(), 0); ti->setText(buf.substr(op, p - op), font); } cols = ocol; @@ -2838,7 +2838,7 @@ bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf, if ((cell < cells) && (op < len)) { InsetText * ti = loctab->GetCellInset(cell); LyXFont const font = ti->getLyXText(bv)-> - getFont(bv->buffer(), &*ti->paragraphs.begin(), 0); + getFont(bv->buffer(), ti->paragraphs.begin(), 0); ti->setText(buf.substr(op, len - op), font); } diff --git a/src/insets/insettext.C b/src/insets/insettext.C index ffcd351f4f..703563b036 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -82,31 +82,31 @@ void InsetText::saveLyXTextState(LyXText * t) const ParagraphList::iterator it = paragraphs.begin(); ParagraphList::iterator end = paragraphs.end(); for (; it != end; ++it) { - if (&*it == t->cursor.par()) + if (it == t->cursor.par()) break; } if (it != end && t->cursor.pos() <= it->size()) { - sstate.lpar = &*t->cursor.par(); + sstate.lpar = t->cursor.par(); sstate.pos = t->cursor.pos(); sstate.boundary = t->cursor.boundary(); - sstate.selstartpar = &*t->selection.start.par(); + sstate.selstartpar = t->selection.start.par(); sstate.selstartpos = t->selection.start.pos(); sstate.selstartboundary = t->selection.start.boundary(); - sstate.selendpar = &*t->selection.end.par(); + sstate.selendpar = t->selection.end.par(); sstate.selendpos = t->selection.end.pos(); sstate.selendboundary = t->selection.end.boundary(); sstate.selection = t->selection.set(); sstate.mark_set = t->selection.mark(); } else { - sstate.lpar = 0; + sstate.lpar = paragraphs.end(); } } void InsetText::restoreLyXTextState(LyXText * t) const { - if (!sstate.lpar) + if (sstate.lpar == paragraphs.end()) return; t->selection.set(true); @@ -193,10 +193,10 @@ void InsetText::init(InsetText const * ins) drawTextXOffset = 0; drawTextYOffset = 0; locked = false; - old_par = 0; + old_par = paragraphs.end(); last_drawn_width = -1; cached_bview = 0; - sstate.lpar = 0; + sstate.lpar = paragraphs.end(); in_insetAllowed = false; } @@ -671,8 +671,8 @@ void InsetText::lockInset(BufferView * bv) the_locking_inset = 0; inset_pos = inset_x = inset_y = 0; inset_boundary = false; - inset_par = 0; - old_par = 0; + inset_par = paragraphs.end(); + old_par = paragraphs.end(); bool clear = false; if (!lt) { lt = getLyXText(bv); @@ -774,7 +774,7 @@ bool InsetText::unlockInsetInInset(BufferView * bv, UpdatableInset * inset, the_locking_inset = 0; if (lr) moveRightIntern(bv, true, false); - old_par = 0; // force layout setting + old_par = paragraphs.end(); // force layout setting if (scroll()) scroll(bv, 0.0F); else @@ -1029,8 +1029,8 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & cmd) the_locking_inset = 0; inset_pos = inset_x = inset_y = 0; inset_boundary = false; - inset_par = 0; - old_par = 0; + inset_par = paragraphs.end(); + old_par = paragraphs.end(); bool clear = false; if (!lt) { @@ -2204,7 +2204,7 @@ LyXText * InsetText::getLyXText(BufferView const * lbv, if (locked) { saveLyXTextState(it->second.text.get()); } else { - sstate.lpar = 0; + sstate.lpar = paragraphs.end(); } } // diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 2f2c2886df..e54ec3c309 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -386,9 +386,9 @@ private: mutable boost::shared_ptr cached_text; /// struct save_state { - Paragraph * lpar; - Paragraph * selstartpar; - Paragraph * selendpar; + ParagraphList::iterator lpar; + ParagraphList::iterator selstartpar; + ParagraphList::iterator selendpar; lyx::pos_type pos; lyx::pos_type selstartpos; lyx::pos_type selendpos; diff --git a/src/lyxcursor.C b/src/lyxcursor.C index 46234269c2..03ef301756 100644 --- a/src/lyxcursor.C +++ b/src/lyxcursor.C @@ -12,7 +12,7 @@ LyXCursor::LyXCursor() - : par_(0), pos_(0), boundary_(false), + : par_(), pos_(0), boundary_(false), x_(0), ix_(0), x_fix_(0), y_(0), iy_(0), row_(0) {} diff --git a/src/text.C b/src/text.C index 29bd502203..1e7e38d760 100644 --- a/src/text.C +++ b/src/text.C @@ -147,8 +147,8 @@ int LyXText::workWidth() const int LyXText::workWidth(Inset const * inset) const { - Paragraph * par = inset->parOwner(); - lyx::Assert(par); + ParagraphList::iterator par = ownerParagraphs().find(*inset->parOwner()); + //lyx::Assert(par); pos_type pos = par->getPositionOfInset(inset); lyx::Assert(pos != -1); diff --git a/src/text2.C b/src/text2.C index e164b666f4..dc33e0a4e9 100644 --- a/src/text2.C +++ b/src/text2.C @@ -885,8 +885,14 @@ void LyXText::cursorBottom() { #warning FIXME // This is how it should be: - // ParagraphList::iterator lastpit = boost::prior(ownerParagraphs().end()); - ParagraphList::iterator lastpit = &ownerParagraphs().back(); +#ifndef NO_STD_LIST + ParagraphList::iterator lastpit = boost::prior(ownerParagraphs().end()); +#else + ParagraphList::iterator lastpit = ownerParagraphs().begin(); + ParagraphList::iterator end = ownerParagraphs().end(); + while (boost::next(lastpit) != end) + ++lastpit; +#endif int pos = lastpit->size(); setCursor(lastpit, pos); } @@ -1191,7 +1197,7 @@ void LyXText::setCounter(Buffer const * buf, ParagraphList::iterator pit) isOK = true; break; } else { - tmppit = in->parOwner(); + tmppit = ownerParagraphs().find(*in->parOwner()); } } diff --git a/src/text3.C b/src/text3.C index 016abfe7bf..98998c59ad 100644 --- a/src/text3.C +++ b/src/text3.C @@ -95,20 +95,20 @@ namespace { LyXCursor const & cur, int & x, int & y) { lyx::pos_type const pos = cur.pos(); - Paragraph /*const*/ & par = *cur.par(); + ParagraphList::iterator par = cur.par(); - if (pos >= par.size() || !par.isInset(pos)) + if (pos >= par->size() || !par->isInset(pos)) return 0; - Inset /*const*/ * inset = par.getInset(pos); + Inset /*const*/ * inset = par->getInset(pos); if (!isEditableInset(inset)) return 0; // get inset dimensions - lyx::Assert(par.getInset(pos)); + lyx::Assert(par->getInset(pos)); - LyXFont const & font = text.getFont(bv->buffer(), &par, pos); + LyXFont const & font = text.getFont(bv->buffer(), par, pos); int const width = inset->width(bv, font); int const inset_x = font.isVisibleRightToLeft() @@ -128,7 +128,7 @@ namespace { return 0; } - text.setCursor(&par, pos, true); + text.setCursor(par, pos, true); x -= b.x1; // The origin of an inset is on the baseline