From 311e5951ee41a57dd8b8860497a774d1dbedc3f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Wed, 2 Apr 2003 21:19:35 +0000 Subject: [PATCH] parlist-2-a.diff git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6689 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 10 ++++ src/ParagraphList.C | 50 ++++++++++---------- src/buffer.C | 31 ++++++------- src/insets/ChangeLog | 15 ++++++ src/insets/insettext.C | 102 ++++++++++++++++++++++++----------------- src/paragraph.h | 8 ++++ src/text2.C | 2 +- 7 files changed, 132 insertions(+), 86 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index dd7f32e31e..24a82cea5a 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2003-04-02 Lars Gullik Bjønnes + + * paragraph.h: make ParagraphList and ParagraphList::iterator + friends of Paragraph. + + * buffer.C (makeLinuxDocFile): move towards ParagraphList + + * ParagraphList.C: Use the private next_ and previous_ from + Paragraph. + 2003-04-01 John Levon * ToolbarBackend.h: diff --git a/src/ParagraphList.C b/src/ParagraphList.C index 7684800399..13e5b50cf0 100644 --- a/src/ParagraphList.C +++ b/src/ParagraphList.C @@ -33,7 +33,7 @@ ParagraphList::iterator::operator->() ParagraphList::iterator & ParagraphList::iterator::operator++() { - ptr = ptr->next(); + ptr = ptr->next_; return *this; } @@ -50,7 +50,7 @@ ParagraphList::iterator::operator++(int) ParagraphList::iterator & ParagraphList::iterator::operator--() { - ptr = ptr->previous(); + ptr = ptr->previous_; return *this; } @@ -89,20 +89,20 @@ ParagraphList::iterator ParagraphList::insert(ParagraphList::iterator it, Paragraph * par) { if (it != end()) { - Paragraph * prev = it->previous(); - par->next(&*it); - par->previous(prev); - prev->next(par); - it->previous(par); + Paragraph * prev = it->previous_; + par->next_ = &*it; + par->previous_ = prev; + prev->next_ = par; + it->previous_ = par; } else if (parlist == 0) { parlist = par; } else { // Find last par. Paragraph * last = parlist; - while (last->next()) - last = last->next(); - last->next(par); - par->previous(last); + while (last->next_) + last = last->next_; + last->next_ = par; + par->previous_ = last; } return iterator(par); } @@ -111,7 +111,7 @@ ParagraphList::insert(ParagraphList::iterator it, Paragraph * par) void ParagraphList::clear() { while (parlist) { - Paragraph * tmp = parlist->next(); + Paragraph * tmp = parlist->next_; delete parlist; parlist = tmp; } @@ -120,16 +120,16 @@ void ParagraphList::clear() void ParagraphList::erase(ParagraphList::iterator it) { - Paragraph * prev = it->previous(); - Paragraph * next = it->next(); + Paragraph * prev = it->previous_; + Paragraph * next = it->next_; if (prev) - prev->next(next); + prev->next_ = next; else parlist = next; if (next) - next->previous(prev); + next->previous_ = prev; delete &*it; } @@ -174,8 +174,8 @@ Paragraph & ParagraphList::front() Paragraph const & ParagraphList::back() const { Paragraph * tmp = parlist; - while (tmp->next()) - tmp = tmp->next(); + while (tmp->next_) + tmp = tmp->next_; return *tmp; } @@ -183,8 +183,8 @@ Paragraph const & ParagraphList::back() const Paragraph & ParagraphList::back() { Paragraph * tmp = parlist; - while (tmp->next()) - tmp = tmp->next(); + while (tmp->next_) + tmp = tmp->next_; return *tmp; } @@ -203,10 +203,10 @@ void ParagraphList::push_back(Paragraph * p) } Paragraph * pos = parlist; - while (pos->next()) - pos = pos->next(); - pos->next(p); - p->previous(pos); + while (pos->next_) + pos = pos->next_; + pos->next_ = p; + p->previous_ = pos; } @@ -218,7 +218,7 @@ int ParagraphList::size() const int c = 0; while (tmp) { ++c; - tmp = tmp->next(); + tmp = tmp->next_; } return c; } diff --git a/src/buffer.C b/src/buffer.C index 4d4d025cf9..e658afd73a 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -1211,27 +1211,26 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only) << " -->\n"; Paragraph::depth_type depth = 0; // paragraph depth - Paragraph * par = &*(paragraphs.begin()); string item_name; vector environment_stack(5); - while (par) { - LyXLayout_ptr const & style = par->layout(); + ParagraphList::iterator pit = paragraphs.begin(); + ParagraphList::iterator pend = paragraphs.end(); + for (; pit != pend; ++pit) { + LyXLayout_ptr const & style = pit->layout(); // treat as a special case for compatibility with old code - if (par->isInset(0)) { - Inset * inset = par->getInset(0); + if (pit->isInset(0)) { + Inset * inset = pit->getInset(0); Inset::Code lyx_code = inset->lyxCode(); if (lyx_code == Inset::TOC_CODE) { string const temp = "toc"; sgml::openTag(ofs, depth, false, temp); - - par = par->next(); continue; } } // environment tag closing - for (; depth > par->params().depth(); --depth) { + for (; depth > pit->params().depth(); --depth) { sgml::closeTag(ofs, depth, false, environment_stack[depth]); environment_stack[depth].erase(); } @@ -1239,7 +1238,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only) // write opening SGML tags switch (style->latextype) { case LATEX_PARAGRAPH: - if (depth == par->params().depth() + if (depth == pit->params().depth() && !environment_stack[depth].empty()) { sgml::closeTag(ofs, depth, false, environment_stack[depth]); environment_stack[depth].erase(); @@ -1252,8 +1251,8 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only) break; case LATEX_COMMAND: - if (depth!= 0) - sgmlError(par, 0, + if (depth != 0) + sgmlError(&*pit, 0, _("Error: Wrong depth for LatexType Command.\n")); if (!environment_stack[depth].empty()) { @@ -1271,14 +1270,14 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only) { string const & latexname = style->latexname(); - if (depth == par->params().depth() + if (depth == pit->params().depth() && environment_stack[depth] != latexname) { sgml::closeTag(ofs, depth, false, environment_stack[depth]); environment_stack[depth].erase(); } - if (depth < par->params().depth()) { - depth = par->params().depth(); + if (depth < pit->params().depth()) { + depth = pit->params().depth(); environment_stack[depth].erase(); } if (environment_stack[depth] != latexname) { @@ -1311,9 +1310,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only) break; } - simpleLinuxDocOnePar(ofs, par, depth); - - par = par->next(); + simpleLinuxDocOnePar(ofs, &*pit, depth); ofs << "\n"; // write closing SGML tags diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 72d22b0eac..9e96459142 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,5 +1,20 @@ 2003-04-02 Lars Gullik Bjønnes + * insettext.C (update): move towards ParagraphList + (updateLocal): ditto + (edit): ditto + (insetUnlock): ditto + (lockInset): ditto + (lockInsetInInset): ditto + (updateInsetInInset): ditto + (localDispatch): ditto + (docbook): ditto + (setFont): ditto + (resizeLyXText): ditto + (searchBackward): ditto + (collapseParagraphs): ditto + (addPreview): ditto + * insetwrap.C (InsetWrap): adjust (addToToc): adjust and rewrite loop diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 0d1858322f..e85a5ca925 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -482,7 +482,8 @@ void InsetText::update(BufferView * bv, bool reinit) return; } - if (!autoBreakRows && paragraphs.begin()->next()) + if (!autoBreakRows && + boost::next(paragraphs.begin()) != paragraphs.end()) collapseParagraphs(bv); if (the_locking_inset) { @@ -544,7 +545,8 @@ void InsetText::setUpdateStatus(BufferView * bv, int what) const void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty) { - if (!autoBreakRows && paragraphs.begin()->next()) + if (!autoBreakRows && + boost::next(paragraphs.begin()) != paragraphs.end()) collapseParagraphs(bv); bool clear = false; if (!lt) { @@ -620,7 +622,8 @@ void InsetText::edit(BufferView * bv, int x, int y, mouse_button::state button) finishUndo(); // If the inset is empty set the language of the current font to the // language to the surronding text (if different). - if (paragraphs.begin()->empty() && !paragraphs.begin()->next() && + if (paragraphs.begin()->empty() && + boost::next(paragraphs.begin()) == paragraphs.end()&& bv->getParentLanguage(this) != lt->current_font.language()) { LyXFont font(LyXFont::ALL_IGNORE); @@ -674,7 +677,8 @@ void InsetText::edit(BufferView * bv, bool front) finishUndo(); // If the inset is empty set the language of the current font to the // language to the surronding text (if different). - if (paragraphs.begin()->empty() && !paragraphs.begin()->next() && + if (paragraphs.begin()->empty() && + boost::next(paragraphs.begin()) == paragraphs.end() && bv->getParentLanguage(this) != lt->current_font.language()) { LyXFont font(LyXFont::ALL_IGNORE); font.setLanguage(bv->getParentLanguage(this)); @@ -718,8 +722,8 @@ void InsetText::insetUnlock(BufferView * bv) // hack for deleteEmptyParMech if (!paragraphs.begin()->empty()) { lt->setCursor(&*(paragraphs.begin()), 0); - } else if (paragraphs.begin()->next()) { - lt->setCursor(paragraphs.begin()->next(), 0); + } else if (boost::next(paragraphs.begin()) != paragraphs.end()) { + lt->setCursor(&*boost::next(paragraphs.begin()), 0); } if (clear) lt = 0; @@ -750,7 +754,8 @@ void InsetText::lockInset(BufferView * bv) finishUndo(); // If the inset is empty set the language of the current font to the // language to the surronding text (if different). - if (paragraphs.begin()->empty() && !paragraphs.begin()->next() && + if (paragraphs.begin()->empty() && + boost::next(paragraphs.begin()) == paragraphs.end() && bv->getParentLanguage(this) != lt->current_font.language()) { LyXFont font(LyXFont::ALL_IGNORE); font.setLanguage(bv->getParentLanguage(this)); @@ -784,26 +789,27 @@ bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset) if (!inset) return false; if (!the_locking_inset) { - Paragraph * p = &*(paragraphs.begin()); + ParagraphList::iterator pit = paragraphs.begin(); + ParagraphList::iterator pend = paragraphs.end(); + int const id = inset->id(); - while(p) { + for (; pit != pend; ++pit) { InsetList::iterator it = - p->insetlist.begin(); + pit->insetlist.begin(); InsetList::iterator const end = - p->insetlist.end(); + pit->insetlist.end(); for (; it != end; ++it) { if (it.getInset() == inset) { - getLyXText(bv)->setCursorIntern(p, it.getPos()); + getLyXText(bv)->setCursorIntern(&*pit, it.getPos()); lockInset(bv, inset); return true; } if (it.getInset()->getInsetFromID(id)) { - getLyXText(bv)->setCursorIntern(p, it.getPos()); + getLyXText(bv)->setCursorIntern(&*pit, it.getPos()); it.getInset()->edit(bv); return the_locking_inset->lockInsetInInset(bv, inset); } } - p = p->next(); } return false; } @@ -852,7 +858,8 @@ bool InsetText::unlockInsetInInset(BufferView * bv, UpdatableInset * inset, bool InsetText::updateInsetInInset(BufferView * bv, Inset * inset) { - if (!autoBreakRows && paragraphs.begin()->next()) + if (!autoBreakRows && + boost::next(paragraphs.begin()) != paragraphs.end()) collapseParagraphs(bv); if (inset == this) return true; @@ -1097,7 +1104,8 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev) break; } - bool was_empty = (paragraphs.begin()->empty() && !paragraphs.begin()->next()); + bool was_empty = (paragraphs.begin()->empty() && + boost::next(paragraphs.begin()) == paragraphs.end()); no_selection = false; RESULT result = UpdatableInset::localDispatch(ev); if (result != UNDISPATCHED) @@ -1469,7 +1477,8 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev) updateLocal(bv, updwhat, updflag); /// If the action has deleted all text in the inset, we need to change the // language to the language of the surronding text. - if (!was_empty && paragraphs.begin()->empty() && !paragraphs.begin()->next()) { + if (!was_empty && paragraphs.begin()->empty() && + boost::next(paragraphs.begin()) == paragraphs.end()) { LyXFont font(LyXFont::ALL_IGNORE); font.setLanguage(bv->getParentLanguage(this)); setFont(bv, font, false); @@ -1513,7 +1522,6 @@ int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const { - Paragraph * p = &*(paragraphs.begin()); unsigned int lines = 0; vector environment_stack(10); @@ -1524,14 +1532,17 @@ int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const Paragraph::depth_type depth = 0; // paragraph depth - while (p) { + ParagraphList::iterator pit = paragraphs.begin(); + ParagraphList::iterator pend = paragraphs.end(); + + for (; pit != pend; ++pit) { string sgmlparam; int desc_on = 0; // description mode - LyXLayout_ptr const & style = p->layout(); + LyXLayout_ptr const & style = pit->layout(); // environment tag closing - for (; depth > p->params().depth(); --depth) { + for (; depth > pit->params().depth(); --depth) { if (environment_inner[depth] != "!-- --") { item_name = "listitem"; lines += sgml::closeTag(os, command_depth + depth, mixcont, item_name); @@ -1543,7 +1554,7 @@ int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const environment_inner[depth].erase(); } - if (depth == p->params().depth() + if (depth == pit->params().depth() && environment_stack[depth] != style->latexname() && !environment_stack[depth].empty()) { if (environment_inner[depth] != "!-- --") { @@ -1566,14 +1577,14 @@ int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const break; case LATEX_COMMAND: - buf->sgmlError(p, 0, _("Error: LatexType Command not allowed here.\n")); + buf->sgmlError(&*pit, 0, _("Error: LatexType Command not allowed here.\n")); return -1; break; case LATEX_ENVIRONMENT: case LATEX_ITEM_ENVIRONMENT: - if (depth < p->params().depth()) { - depth = p->params().depth(); + if (depth < pit->params().depth()) { + depth = pit->params().depth(); environment_stack[depth].erase(); } @@ -1618,8 +1629,7 @@ int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const break; } - buf->simpleDocBookOnePar(os, p, desc_on, depth + 1 + command_depth); - p = p->next(); + buf->simpleDocBookOnePar(os, &*pit, desc_on, depth + 1 + command_depth); string end_tag; // write closing SGML tags @@ -1915,7 +1925,8 @@ void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall, the_locking_inset->setFont(bv, font, toggleall, selectall); return; } - if ((!paragraphs.begin()->next() && paragraphs.begin()->empty()) || cpar(bv)->empty()) { + if ((boost::next(paragraphs.begin()) == paragraphs.end() && + paragraphs.begin()->empty()) || cpar(bv)->empty()) { getLyXText(bv)->setFont(font, toggleall); return; } @@ -2250,7 +2261,8 @@ void InsetText::resizeLyXText(BufferView * bv, bool force) const return; } do_resize = 0; - if (!paragraphs.begin()->next() && paragraphs.begin()->empty()) { // no data, resize not neccessary! + if (boost::next(paragraphs.begin()) == paragraphs.end() && + paragraphs.begin()->empty()) { // no data, resize not neccessary! // we have to do this as a fixed width may have changed! LyXText * t = getLyXText(bv); saveLyXTextState(t); @@ -2617,10 +2629,13 @@ bool InsetText::searchBackward(BufferView * bv, string const & str, clear = true; } if (!locked) { - Paragraph * p = &*(paragraphs.begin()); - while (p->next()) - p = p->next(); - lt->setCursor(p, p->size()); + ParagraphList::iterator pit = paragraphs.begin(); + ParagraphList::iterator pend = paragraphs.end(); + + while (boost::next(pit) != pend) + ++pit; + + lt->setCursor(&*pit, pit->size()); } lyxfind::SearchResult result = lyxfind::LyXFind(bv, lt, str, false, cs, mw); @@ -2652,19 +2667,20 @@ void InsetText::collapseParagraphs(BufferView * bv) { LyXText * llt = getLyXText(bv); - while (paragraphs.begin()->next()) { - if (!paragraphs.begin()->empty() && !paragraphs.begin()->next()->empty() && + while (boost::next(paragraphs.begin()) != paragraphs.end()) { + if (!paragraphs.begin()->empty() && + !boost::next(paragraphs.begin())->empty() && !paragraphs.begin()->isSeparator(paragraphs.begin()->size() - 1)) { paragraphs.begin()->insertChar(paragraphs.begin()->size(), ' '); } if (llt->selection.set()) { - if (llt->selection.start.par() == paragraphs.begin()->next()) { + if (llt->selection.start.par() == boost::next(paragraphs.begin())) { llt->selection.start.par(&*(paragraphs.begin())); llt->selection.start.pos( llt->selection.start.pos() + paragraphs.begin()->size()); } - if (llt->selection.end.par() == paragraphs.begin()->next()) { + if (llt->selection.end.par() == boost::next(paragraphs.begin())) { llt->selection.end.par(&*(paragraphs.begin())); llt->selection.end.pos( llt->selection.end.pos() + paragraphs.begin()->size()); @@ -2725,14 +2741,14 @@ void InsetText::appendParagraphs(Buffer * buffer, void InsetText::addPreview(grfx::PreviewLoader & loader) const { - Paragraph * par = getFirstParagraph(0); - while (par) { - InsetList::iterator it = par->insetlist.begin(); - InsetList::iterator end = par->insetlist.end(); + ParagraphList::iterator pit = paragraphs.begin(); + ParagraphList::iterator pend = paragraphs.end(); + + for (; pit != pend; ++pit) { + InsetList::iterator it = pit->insetlist.begin(); + InsetList::iterator end = pit->insetlist.end(); for (; it != end; ++it) { it.getInset()->addPreview(loader); } - - par = par->next(); } } diff --git a/src/paragraph.h b/src/paragraph.h index 383a4c8ea2..faf75b9958 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -18,6 +18,7 @@ #include "support/types.h" #include "changes.h" +#include "ParagraphList.h" #include "LString.h" class BufferParams; @@ -37,6 +38,10 @@ class TexRow; /// A Paragraph holds all text, attributes and insets in a text paragraph class Paragraph { public: + // Remove this whan ParagraphList transition is over. (Lgb) + friend class ParagraphList; + friend class ParagraphList::iterator; + /// enum META_KIND { /// Note that this is 1 right now to avoid @@ -334,6 +339,9 @@ private: Paragraph * next_; /// Paragraph * previous_; +#else + Paragraph * next_par_; + Paragraph * prev_par_; #endif struct Pimpl; /// diff --git a/src/text2.C b/src/text2.C index 4e33c6e43a..3202c54f24 100644 --- a/src/text2.C +++ b/src/text2.C @@ -489,7 +489,7 @@ void LyXText::incDepth() if (pit == end) break; - + ++pit; }