From 6192345f60bd77c9223c1649956d6814d48ca26b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Mon, 17 Nov 2008 11:46:07 +0000 Subject: [PATCH] add Buffer * member to DocIterator git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27603 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 27 ++++----- src/Buffer.h | 5 +- src/BufferView.cpp | 24 ++++---- src/Cursor.cpp | 81 ++++++++++++--------------- src/Cursor.h | 2 - src/CutAndPaste.cpp | 27 +++++---- src/DocIterator.cpp | 35 +++++++----- src/DocIterator.h | 38 +++++++------ src/InsetIterator.cpp | 2 +- src/LyXFunc.cpp | 2 +- src/ParIterator.cpp | 63 ++++++++++----------- src/ParIterator.h | 14 ++--- src/Text.cpp | 76 ++++++++++++------------- src/Text2.cpp | 20 +++---- src/Text3.cpp | 44 +++++++-------- src/TocBackend.h | 2 +- src/Undo.cpp | 8 +-- src/factory.cpp | 2 +- src/frontends/qt4/GuiClipboard.cpp | 2 +- src/frontends/qt4/GuiCompleter.cpp | 4 +- src/frontends/qt4/GuiErrorList.cpp | 2 +- src/frontends/qt4/GuiSpellchecker.cpp | 2 +- src/insets/InsetBox.cpp | 2 +- src/insets/InsetBranch.cpp | 2 +- src/insets/InsetERT.cpp | 2 +- src/insets/InsetFloat.cpp | 6 +- src/insets/InsetGraphics.cpp | 8 +-- src/insets/InsetInclude.cpp | 2 +- src/insets/InsetLabel.cpp | 2 +- src/insets/InsetNote.cpp | 16 +++--- src/insets/InsetTabular.cpp | 6 +- src/insets/InsetText.cpp | 6 +- src/lyxfind.cpp | 76 ++++++++++++++----------- src/mathed/InsetMathHull.cpp | 6 +- src/mathed/InsetMathNest.cpp | 6 +- src/mathed/MacroTable.cpp | 7 ++- src/mathed/MathMacroTemplate.cpp | 15 ++--- 37 files changed, 325 insertions(+), 319 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 444887bdb6..49e968fd25 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -1515,17 +1515,18 @@ bool Buffer::isMultiLingual() const DocIterator Buffer::getParFromID(int const id) const { + Buffer * buf = const_cast(this); if (id < 0) { // John says this is called with id == -1 from undo lyxerr << "getParFromID(), id: " << id << endl; - return doc_iterator_end(inset()); + return doc_iterator_end(buf); } - for (DocIterator it = doc_iterator_begin(inset()); !it.atEnd(); it.forwardPar()) + for (DocIterator it = doc_iterator_begin(buf); !it.atEnd(); it.forwardPar()) if (it.paragraph().id() == id) return it; - return doc_iterator_end(inset()); + return doc_iterator_end(buf); } @@ -1537,25 +1538,25 @@ bool Buffer::hasParWithID(int const id) const ParIterator Buffer::par_iterator_begin() { - return ParIterator(doc_iterator_begin(inset())); + return ParIterator(doc_iterator_begin(this)); } ParIterator Buffer::par_iterator_end() { - return ParIterator(doc_iterator_end(inset())); + return ParIterator(doc_iterator_end(this)); } ParConstIterator Buffer::par_iterator_begin() const { - return lyx::par_const_iterator_begin(inset()); + return ParConstIterator(doc_iterator_begin(this)); } ParConstIterator Buffer::par_iterator_end() const { - return lyx::par_const_iterator_end(inset()); + return ParConstIterator(doc_iterator_end(this)); } @@ -1737,7 +1738,7 @@ DocIterator Buffer::firstChildPosition(Buffer const * child) Impl::BufferPositionMap::iterator it; it = d->children_positions.find(child); if (it == d->children_positions.end()) - return DocIterator(); + return DocIterator(this); return it->second; } @@ -1772,11 +1773,11 @@ MacroData const * Buffer::getBufferMacro(docstring const & name, // find macro definitions for name Impl::NamePositionScopeMacroMap::iterator nameIt - = d->macros.find(name); + = d->macros.find(name); if (nameIt != d->macros.end()) { // find last definition in front of pos or at pos itself Impl::PositionScopeMacroMap::const_iterator it - = greatest_below(nameIt->second, pos); + = greatest_below(nameIt->second, pos); if (it != nameIt->second.end()) { while (true) { // scope ends behind pos? @@ -1799,7 +1800,7 @@ MacroData const * Buffer::getBufferMacro(docstring const & name, // find macros in included files Impl::PositionScopeBufferMap::const_iterator it - = greatest_below(d->position_to_children, pos); + = greatest_below(d->position_to_children, pos); if (it == d->position_to_children.end()) // no children before return bestData; @@ -2000,8 +2001,8 @@ void Buffer::updateMacroInstances() const { LYXERR(Debug::MACROS, "updateMacroInstances for " << d->filename.onlyFileName()); - DocIterator it = doc_iterator_begin(inset()); - DocIterator end = doc_iterator_end(inset()); + DocIterator it = doc_iterator_begin(this); + DocIterator end = doc_iterator_end(this); for (; it != end; it.forwardPos()) { // look for MathData cells in InsetMathNest insets Inset * inset = it.nextInset(); diff --git a/src/Buffer.h b/src/Buffer.h index 697994c985..96c0bae617 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -110,10 +110,7 @@ public: timestamp_method, ///< Use timestamp, and checksum if timestamp has changed }; - /** Constructor - \param file - \param b optional \c false by default - */ + /// Constructor explicit Buffer(std::string const & file, bool b = false); /// Destructor diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 01ee8fd0a5..1a873581c4 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -150,11 +150,13 @@ bool findInset(DocIterator & dit, vector const & codes, if (!findNextInset(tmpdit, codes, contents)) { if (dit.depth() != 1 || dit.pit() != 0 || dit.pos() != 0) { - tmpdit = doc_iterator_begin(tmpdit.bottom().inset()); + Inset * inset = &tmpdit.bottom().inset(); + tmpdit = doc_iterator_begin(&inset->buffer(), inset); if (!findNextInset(tmpdit, codes, contents)) return false; - } else + } else { return false; + } } dit = tmpdit; @@ -272,11 +274,13 @@ struct BufferView::Private BufferView::BufferView(Buffer & buf) - : width_(0), height_(0), full_screen_(false), buffer_(buf), d(new Private(*this)) + : width_(0), height_(0), full_screen_(false), buffer_(buf), + d(new Private(*this)) { d->xsel_cache_.set = false; d->intl_.initKeyMapper(lyxrc.use_kbmap); + d->cursor_.setBuffer(&buf); d->cursor_.push(buffer_.inset()); d->cursor_.resetAnchor(); d->cursor_.setCurrentFont(); @@ -564,7 +568,7 @@ void BufferView::scrollDocView(int value) // cut off at the top if (value <= d->scrollbarParameters_.min) { - DocIterator dit = doc_iterator_begin(buffer_.inset()); + DocIterator dit = doc_iterator_begin(&buffer_); showCursor(dit); LYXERR(Debug::SCROLLING, "scroll to top"); return; @@ -572,7 +576,7 @@ void BufferView::scrollDocView(int value) // cut off at the bottom if (value >= d->scrollbarParameters_.max) { - DocIterator dit = doc_iterator_end(buffer_.inset()); + DocIterator dit = doc_iterator_end(&buffer_); dit.backwardPos(); showCursor(dit); LYXERR(Debug::SCROLLING, "scroll to bottom"); @@ -596,7 +600,7 @@ void BufferView::scrollDocView(int value) return; } - DocIterator dit = doc_iterator_begin(buffer_.inset()); + DocIterator dit = doc_iterator_begin(&buffer_); dit.pit() = i; LYXERR(Debug::SCROLLING, "value = " << value << " -> scroll to pit " << i); showCursor(dit); @@ -724,7 +728,7 @@ bool BufferView::moveToPosition(pit_type bottom_pit, pos_type bottom_pos, // it will be restored to the left of the outmost inset that contains // the bookmark. if (bottom_pit < int(buffer_.paragraphs().size())) { - dit = doc_iterator_begin(buffer_.inset()); + dit = doc_iterator_begin(&buffer_); dit.pit() = bottom_pit; dit.pos() = min(bottom_pos, dit.paragraph().size()); @@ -1308,8 +1312,8 @@ bool BufferView::dispatch(FuncRequest const & cmd) from = cur.selectionBegin(); to = cur.selectionEnd(); } else { - from = doc_iterator_begin(buffer_.inset()); - to = doc_iterator_end(buffer_.inset()); + from = doc_iterator_begin(&buffer_); + to = doc_iterator_end(&buffer_); } int const words = countWords(from, to); int const chars = countChars(from, to, false); @@ -1495,7 +1499,7 @@ bool BufferView::dispatch(FuncRequest const & cmd) FuncRequest fr(LFUN_INSET_TOGGLE, action); - Inset & inset = cur.buffer().inset(); + Inset & inset = cur.buffer()->inset(); InsetIterator it = inset_iterator_begin(inset); InsetIterator const end = inset_iterator_end(inset); for (; it != end; ++it) { diff --git a/src/Cursor.cpp b/src/Cursor.cpp index 89c1cc768d..346062a470 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -205,10 +205,9 @@ bool bruteFind3(Cursor & cur, int x, int y, bool up) // << " xlow: " << xlow << " xhigh: " << xhigh // << " ylow: " << ylow << " yhigh: " << yhigh // << endl; - Inset & inset = bv.buffer().inset(); - DocIterator it = doc_iterator_begin(inset); + DocIterator it = doc_iterator_begin(cur.buffer()); it.pit() = from; - DocIterator et = doc_iterator_end(inset); + DocIterator et = doc_iterator_end(cur.buffer()); double best_dist = numeric_limits::max(); DocIterator best_cursor = et; @@ -252,8 +251,7 @@ docstring parbreak(Paragraph const & par) odocstringstream os; os << '\n'; // only add blank line if we're not in an ERT or Listings inset - if (par.ownerCode() != ERT_CODE - && par.ownerCode() != LISTINGS_CODE) + if (par.ownerCode() != ERT_CODE && par.ownerCode() != LISTINGS_CODE) os << '\n'; return os.str(); } @@ -264,7 +262,8 @@ docstring parbreak(Paragraph const & par) // be careful: this is called from the bv's constructor, too, so // bv functions are not yet available! Cursor::Cursor(BufferView & bv) - : DocIterator(), bv_(&bv), anchor_(), x_target_(-1), textTargetOffset_(0), + : DocIterator(&bv.buffer()), bv_(&bv), anchor_(), + x_target_(-1), textTargetOffset_(0), selection_(false), mark_(false), logicalpos_(false), current_font(inherit_font) {} @@ -274,7 +273,7 @@ void Cursor::reset(Inset & inset) { clear(); push_back(CursorSlice(inset)); - anchor_ = doc_iterator_begin(inset); + anchor_ = doc_iterator_begin(&inset.buffer(), &inset); anchor_.clear(); clearTargetX(); selection_ = false; @@ -346,13 +345,6 @@ BufferView & Cursor::bv() const } -Buffer & Cursor::buffer() const -{ - LASSERT(bv_, /**/); - return bv_->buffer(); -} - - void Cursor::pop() { LASSERT(depth() >= 1, /**/); @@ -363,13 +355,13 @@ void Cursor::pop() void Cursor::push(Inset & p) { push_back(CursorSlice(p)); - p.setBuffer(bv_->buffer()); + p.setBuffer(*buffer()); } void Cursor::pushBackward(Inset & p) { - LASSERT(!empty(), /**/); + LASSERT(!empty(), return); //lyxerr << "Entering inset " << t << " front" << endl; push(p); p.idxFirst(*this); @@ -378,7 +370,7 @@ void Cursor::pushBackward(Inset & p) bool Cursor::popBackward() { - LASSERT(!empty(), /**/); + LASSERT(!empty(), return false); if (depth() == 1) return false; pop(); @@ -388,7 +380,7 @@ bool Cursor::popBackward() bool Cursor::popForward() { - LASSERT(!empty(), /**/); + LASSERT(!empty(), return false); //lyxerr << "Leaving inset from in back" << endl; const pos_type lp = (depth() > 1) ? (*this)[depth() - 2].lastpos() : 0; if (depth() == 1) @@ -499,7 +491,7 @@ bool Cursor::posVisRight(bool skip_inset) // currently to the left of 'right_pos'). In order to move to the // right, it depends whether or not the character at 'right_pos' is RTL. new_pos_is_RTL = paragraph().getFontSettings( - bv().buffer().params(), right_pos).isVisibleRightToLeft(); + buffer()->params(), right_pos).isVisibleRightToLeft(); // If the character at 'right_pos' *is* LTR, then in order to move to // the right of it, we need to be *after* 'right_pos', i.e., move to // position 'right_pos' + 1. @@ -511,10 +503,10 @@ bool Cursor::posVisRight(bool skip_inset) // (this means that we're moving right to the end of an LTR chunk // which is at the end of an RTL paragraph); (new_cur.pos() == lastpos() - && paragraph().isRTL(buffer().params())) + && paragraph().isRTL(buffer()->params())) // 2. if the position *after* right_pos is RTL (we want to be // *after* right_pos, not before right_pos + 1!) - || paragraph().getFontSettings(bv().buffer().params(), + || paragraph().getFontSettings(buffer()->params(), new_cur.pos()).isVisibleRightToLeft() ) new_cur.boundary(true); @@ -591,7 +583,7 @@ bool Cursor::posVisLeft(bool skip_inset) // currently to the right of 'left_pos'). In order to move to the // left, it depends whether or not the character at 'left_pos' is RTL. new_pos_is_RTL = paragraph().getFontSettings( - bv().buffer().params(), left_pos).isVisibleRightToLeft(); + buffer()->params(), left_pos).isVisibleRightToLeft(); // If the character at 'left_pos' *is* RTL, then in order to move to // the left of it, we need to be *after* 'left_pos', i.e., move to // position 'left_pos' + 1. @@ -603,10 +595,10 @@ bool Cursor::posVisLeft(bool skip_inset) // (this means that we're moving left to the end of an RTL chunk // which is at the end of an LTR paragraph); (new_cur.pos() == lastpos() - && !paragraph().isRTL(buffer().params())) + && !paragraph().isRTL(buffer()->params())) // 2. if the position *after* left_pos is not RTL (we want to be // *after* left_pos, not before left_pos + 1!) - || !paragraph().getFontSettings(bv().buffer().params(), + || !paragraph().getFontSettings(buffer()->params(), new_cur.pos()).isVisibleRightToLeft() ) new_cur.boundary(true); @@ -641,7 +633,7 @@ void Cursor::getSurroundingPos(pos_type & left_pos, pos_type & right_pos) { // preparing bidi tables Paragraph const & par = paragraph(); - Buffer const & buf = buffer(); + Buffer const & buf = *buffer(); Row const & row = textRow(); Bidi bidi; bidi.computeTables(par, buf, row); @@ -748,7 +740,7 @@ void Cursor::getSurroundingPos(pos_type & left_pos, pos_type & right_pos) bool Cursor::posVisToNewRow(bool movingLeft) { Paragraph const & par = paragraph(); - Buffer const & buf = buffer(); + Buffer const & buf = *buffer(); Row const & row = textRow(); bool par_is_LTR = !par.isRTL(buf.params()); @@ -802,7 +794,7 @@ void Cursor::posVisToRowExtremity(bool left) { // prepare bidi tables Paragraph const & par = paragraph(); - Buffer const & buf = buffer(); + Buffer const & buf = *buffer(); Row const & row = textRow(); Bidi bidi; bidi.computeTables(par, buf, row); @@ -1445,7 +1437,7 @@ bool Cursor::macroModeClose() // macros here are still unfolded (in init mode in fact). So // we have to resolve the macro here manually and check its arity // to put the selection behind it if arity > 0. - MacroData const * data = buffer().getMacro(atomAsMacro->name()); + MacroData const * data = buffer()->getMacro(atomAsMacro->name()); if (selection.size() > 0 && data && data->numargs() - data->optionals() > 0) { macroArg = true; atomAsMacro->setDisplayMode(MathMacro::DISPLAY_INTERACTIVE_INIT, 1); @@ -2024,7 +2016,7 @@ Font Cursor::getFont() const } // get font at the position - Font font = par.getFont(bv().buffer().params(), pos, + Font font = par.getFont(buffer()->params(), pos, outerFont(sl.pit(), text.paragraphs())); return font; @@ -2052,7 +2044,7 @@ bool notifyCursorLeavesOrEnters(Cursor const & old, Cursor & cur) // update words if we just moved to another paragraph if (i == old.depth() && i == cur.depth() - && !cur.buffer().isClean() + && !cur.buffer()->isClean() && cur.inTexted() && old.inTexted() && cur.pit() != old.pit()) { old.paragraph().updateWords(old.top()); @@ -2107,7 +2099,7 @@ void Cursor::setCurrentFont() } // get font - BufferParams const & bufparams = buffer().params(); + BufferParams const & bufparams = buffer()->params(); current_font = par.getFontSettings(bufparams, cpos); real_current_font = tm.displayFont(cpit, cpos); @@ -2128,7 +2120,7 @@ bool Cursor::textUndo() { DocIterator dit = *this; // Undo::textUndo() will modify dit. - if (!bv_->buffer().undo().textUndo(dit)) + if (!buffer()->undo().textUndo(dit)) return false; // Set cursor setCursor(dit); @@ -2142,7 +2134,7 @@ bool Cursor::textRedo() { DocIterator dit = *this; // Undo::textRedo() will modify dit. - if (!bv_->buffer().undo().textRedo(dit)) + if (!buffer()->undo().textRedo(dit)) return false; // Set cursor setCursor(dit); @@ -2154,49 +2146,49 @@ bool Cursor::textRedo() void Cursor::finishUndo() const { - bv_->buffer().undo().finishUndo(); + buffer()->undo().finishUndo(); } void Cursor::beginUndoGroup() const { - bv_->buffer().undo().beginUndoGroup(); + buffer()->undo().beginUndoGroup(); } void Cursor::endUndoGroup() const { - bv_->buffer().undo().endUndoGroup(); + buffer()->undo().endUndoGroup(); } void Cursor::recordUndo(UndoKind kind, pit_type from, pit_type to) const { - bv_->buffer().undo().recordUndo(*this, kind, from, to); + buffer()->undo().recordUndo(*this, kind, from, to); } void Cursor::recordUndo(UndoKind kind, pit_type from) const { - bv_->buffer().undo().recordUndo(*this, kind, from); + buffer()->undo().recordUndo(*this, kind, from); } void Cursor::recordUndo(UndoKind kind) const { - bv_->buffer().undo().recordUndo(*this, kind); + buffer()->undo().recordUndo(*this, kind); } void Cursor::recordUndoInset(UndoKind kind) const { - bv_->buffer().undo().recordUndoInset(*this, kind); + buffer()->undo().recordUndoInset(*this, kind); } void Cursor::recordUndoFullDocument() const { - bv_->buffer().undo().recordUndoFullDocument(*this); + buffer()->undo().recordUndoFullDocument(*this); } @@ -2207,15 +2199,16 @@ void Cursor::recordUndoSelection() const recordUndoInset(); else recordUndo(); - } else - bv_->buffer().undo().recordUndo(*this, ATOMIC_UNDO, + } else { + buffer()->undo().recordUndo(*this, ATOMIC_UNDO, selBegin().pit(), selEnd().pit()); + } } void Cursor::checkBufferStructure() { - Buffer const * master = buffer().masterBuffer(); + Buffer const * master = buffer()->masterBuffer(); master->tocBackend().updateItem(*this); } diff --git a/src/Cursor.h b/src/Cursor.h index 4fc4ef937a..276bf2e989 100644 --- a/src/Cursor.h +++ b/src/Cursor.h @@ -198,8 +198,6 @@ public: void resetAnchor(); /// access to owning BufferView BufferView & bv() const; - /// access to owning Buffer - Buffer & buffer() const; /// get some interesting description of top position void info(odocstream & os) const; /// are we in math mode (2), text mode (1) or unsure (0)? diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index 22bc931e0a..0d36390bae 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -93,7 +93,7 @@ pair pasteSelectionHelper(Cursor & cur, ParagraphList const & parlist, DocumentClass const * const oldDocClass, ErrorList & errorlist) { - Buffer const & buffer = cur.buffer(); + Buffer const & buffer = *cur.buffer(); pit_type pit = cur.pit(); pos_type pos = cur.pos(); InsetText * target_inset = cur.inset().asInsetText(); @@ -623,9 +623,9 @@ void cutSelection(Cursor & cur, bool doclear, bool realcut) int endpos = cur.selEnd().pos(); - BufferParams const & bp = cur.buffer().params(); + BufferParams const & bp = cur.buffer()->params(); if (realcut) { - copySelectionHelper(cur.buffer(), + copySelectionHelper(*cur.buffer(), text->paragraphs(), begpit, endpit, cur.selBegin().pos(), endpos, @@ -658,7 +658,7 @@ void cutSelection(Cursor & cur, bool doclear, bool realcut) // need a valid cursor. (Lgb) cur.clearSelection(); - cur.buffer().updateLabels(); + cur.buffer()->updateLabels(); // tell tabular that a recent copy happened dirtyTabularStack(false); @@ -691,7 +691,7 @@ void copyInset(Cursor const & cur, Inset * inset, docstring const & plaintext) { ParagraphList pars; Paragraph par; - BufferParams const & bp = cur.buffer().params(); + BufferParams const & bp = cur.buffer()->params(); par.setLayout(bp.documentClass().plainLayout()); par.insertInset(0, inset, Change(Change::UNCHANGED)); pars.push_back(par); @@ -728,9 +728,9 @@ void copySelectionToStack(Cursor const & cur, CutStack & cutstack) (par != cur.selEnd().pit() || pos < cur.selEnd().pos())) ++pos; - copySelectionHelper(cur.buffer(), pars, par, cur.selEnd().pit(), + copySelectionHelper(*cur.buffer(), pars, par, cur.selEnd().pit(), pos, cur.selEnd().pos(), - cur.buffer().params().documentClassPtr(), cutstack); + cur.buffer()->params().documentClassPtr(), cutstack); dirtyTabularStack(false); } @@ -738,7 +738,7 @@ void copySelectionToStack(Cursor const & cur, CutStack & cutstack) //lyxerr << "copySelection in mathed" << endl; ParagraphList pars; Paragraph par; - BufferParams const & bp = cur.buffer().params(); + BufferParams const & bp = cur.buffer()->params(); // FIXME This should be the plain layout...right? par.setLayout(bp.documentClass().plainLayout()); par.insert(0, grabSelection(cur), Font(), Change(Change::UNCHANGED)); @@ -766,7 +766,7 @@ void copySelection(Cursor const & cur, docstring const & plaintext) if (cur.selBegin().idx() != cur.selEnd().idx()) { ParagraphList pars; Paragraph par; - BufferParams const & bp = cur.buffer().params(); + BufferParams const & bp = cur.buffer()->params(); par.setLayout(bp.documentClass().plainLayout()); par.insert(0, plaintext, Font(), Change(Change::UNCHANGED)); pars.push_back(par); @@ -832,7 +832,7 @@ void pasteParagraphList(Cursor & cur, ParagraphList const & parlist, boost::tie(ppp, endpit) = pasteSelectionHelper(cur, parlist, docclass, errorList); - cur.buffer().updateLabels(); + cur.buffer()->updateLabels(); cur.clearSelection(); text->setCursor(cur, ppp.first, ppp.second); } @@ -904,7 +904,7 @@ void pasteClipboardGraphics(Cursor & cur, ErrorList & /* errorList */, return; // create inset for graphic - InsetGraphics * inset = new InsetGraphics(cur.buffer()); + InsetGraphics * inset = new InsetGraphics(*cur.buffer()); InsetGraphicsParams params; params.filename = support::DocFileName(filename.absFilename()); inset->setParams(params); @@ -930,7 +930,7 @@ void replaceSelectionWithString(Cursor & cur, docstring const & str, bool backwa // Get font setting before we cut, we need a copy here, not a bare reference. Font const font = - selbeg.paragraph().getFontSettings(cur.buffer().params(), selbeg.pos()); + selbeg.paragraph().getFontSettings(cur.buffer()->params(), selbeg.pos()); // Insert the new string pos_type pos = cur.selEnd().pos(); @@ -938,7 +938,7 @@ void replaceSelectionWithString(Cursor & cur, docstring const & str, bool backwa docstring::const_iterator cit = str.begin(); docstring::const_iterator end = str.end(); for (; cit != end; ++cit, ++pos) - par.insertChar(pos, *cit, font, cur.buffer().params().trackChanges); + par.insertChar(pos, *cit, font, cur.buffer()->params().trackChanges); // Cut the selection cutSelection(cur, true, false); @@ -1075,5 +1075,4 @@ bool tabularStackDirty() } // namespace cap - } // namespace lyx diff --git a/src/DocIterator.cpp b/src/DocIterator.cpp index aacbd37fd8..40c4ae4adc 100644 --- a/src/DocIterator.cpp +++ b/src/DocIterator.cpp @@ -14,6 +14,7 @@ #include "DocIterator.h" +#include "Buffer.h" #include "InsetList.h" #include "Paragraph.h" #include "Text.h" @@ -25,7 +26,6 @@ #include "insets/InsetTabular.h" #include "support/debug.h" - #include "support/lassert.h" #include @@ -35,29 +35,37 @@ using namespace std; namespace lyx { +DocIterator::DocIterator() + : boundary_(false), inset_(0), buffer_(0) +{} + // We could be able to get rid of this if only every BufferView were // associated to a buffer on construction. -DocIterator::DocIterator() - : boundary_(false), inset_(0) +DocIterator::DocIterator(Buffer * buf) + : boundary_(false), inset_(0), buffer_(buf) {} -DocIterator::DocIterator(Inset & inset) - : boundary_(false), inset_(&inset) +DocIterator::DocIterator(Buffer * buf, Inset * inset) + : boundary_(false), inset_(inset), buffer_(buf) {} -DocIterator doc_iterator_begin(Inset & inset) +DocIterator doc_iterator_begin(const Buffer * buf0, const Inset * inset0) { - DocIterator dit(inset); + Buffer * buf = const_cast(buf0); + Inset * inset = const_cast(inset0); + DocIterator dit(buf, inset ? inset : &buf->inset()); dit.forwardPos(); return dit; } -DocIterator doc_iterator_end(Inset & inset) +DocIterator doc_iterator_end(const Buffer * buf0, const Inset * inset0) { - return DocIterator(inset); + Buffer * buf = const_cast(buf0); + Inset * inset = const_cast(inset0); + return DocIterator(buf, inset ? inset : &buf->inset()); } @@ -77,7 +85,7 @@ LyXErr & operator<<(LyXErr & os, DocIterator const & it) Inset * DocIterator::nextInset() const { - LASSERT(!empty(), /**/); + LASSERT(!empty(), return 0); if (pos() == lastpos()) return 0; if (pos() > lastpos()) { @@ -92,7 +100,7 @@ Inset * DocIterator::nextInset() const Inset * DocIterator::prevInset() const { - LASSERT(!empty(), /**/); + LASSERT(!empty(), return 0); if (pos() == 0) return 0; if (inMathed()) { @@ -556,11 +564,12 @@ StableDocIterator::StableDocIterator(DocIterator const & dit) } -DocIterator StableDocIterator::asDocIterator(Inset * inset) const +DocIterator StableDocIterator::asDocIterator(Buffer * buf) const { // this function re-creates the cache of inset pointers //lyxerr << "converting:\n" << *this << endl; - DocIterator dit = DocIterator(*inset); + Inset * inset = &buf->inset(); + DocIterator dit = DocIterator(buf, inset); for (size_t i = 0, n = data_.size(); i != n; ++i) { if (inset == 0) { // FIXME diff --git a/src/DocIterator.h b/src/DocIterator.h index ed2575ee27..737cbd3b13 100644 --- a/src/DocIterator.h +++ b/src/DocIterator.h @@ -19,16 +19,18 @@ namespace lyx { +class DocIterator; class LyXErr; class MathAtom; class Paragraph; class Text; class InsetIterator; +DocIterator doc_iterator_begin(Buffer const * buf, Inset const * inset = 0); +DocIterator doc_iterator_end(Buffer const * buf, Inset const * inset = 0); -// The public inheritance should go in favour of a suitable data member -// (or maybe private inheritance) at some point of time. -class DocIterator // : public std::vector + +class DocIterator { public: /// type for cell number in inset @@ -41,6 +43,13 @@ public: public: /// DocIterator(); + /// + explicit DocIterator(Buffer *buf); + + /// access to owning buffer + Buffer * buffer() const { return buffer_; } + /// access to owning buffer + void setBuffer(Buffer * buf) { buffer_ = buf; } /// access slice at position \p i CursorSlice const & operator[](size_t i) const { return slices_[i]; } @@ -228,10 +237,10 @@ public: private: friend class InsetIterator; - friend DocIterator doc_iterator_begin(Inset & inset); - friend DocIterator doc_iterator_end(Inset & inset); + friend DocIterator doc_iterator_begin(Buffer const * buf, Inset const * inset); + friend DocIterator doc_iterator_end(Buffer const * buf, Inset const * inset); /// - explicit DocIterator(Inset & inset); + explicit DocIterator(Buffer * buf, Inset * inset); /** * Normally, when the cursor is at position i, it is painted *before* * the character at position i. However, what if we want the cursor @@ -259,20 +268,16 @@ private: */ bool boundary_; /// - std::vector const & internalData() const { - return slices_; - } + std::vector const & internalData() const { return slices_; } /// std::vector slices_; /// Inset * inset_; + /// + Buffer * buffer_; }; -DocIterator doc_iterator_begin(Inset & inset); -DocIterator doc_iterator_end(Inset & inset); - - inline bool operator==(DocIterator const & di1, DocIterator const & di2) { return di1.slices_ == di2.slices_; @@ -322,14 +327,15 @@ bool operator>=(DocIterator const & p, DocIterator const & q) // (overwritten by 0...) part of the CursorSlice data items. So this thing // is suitable for external storage, but not for iteration as such. -class StableDocIterator { +class StableDocIterator +{ public: /// StableDocIterator() {} /// non-explicit intended StableDocIterator(const DocIterator & it); /// - DocIterator asDocIterator(Inset * start) const; + DocIterator asDocIterator(Buffer * buf) const; /// size_t size() const { return data_.size(); } /// return the position within the paragraph @@ -352,4 +358,4 @@ private: } // namespace lyx -#endif +#endif // DOCITERATOR_H diff --git a/src/InsetIterator.cpp b/src/InsetIterator.cpp index 189efa3dcd..d9ed1e3737 100644 --- a/src/InsetIterator.cpp +++ b/src/InsetIterator.cpp @@ -20,7 +20,7 @@ namespace lyx { InsetIterator::InsetIterator(Inset & inset) - : DocIterator(inset) + : DocIterator(&inset.buffer(), &inset) { } diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index d52406b395..b577b65a76 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -1806,7 +1806,7 @@ void LyXFunc::updateLayout(DocumentClass const * const oldlayout, Buffer * buf) oldlayout, buf->params().documentClassPtr(), static_cast(buf->inset()), el); - view()->setCursor(backcur.asDocIterator(&(buf->inset()))); + view()->setCursor(backcur.asDocIterator(buf)); buf->errors("Class Switch"); buf->updateLabels(); diff --git a/src/ParIterator.cpp b/src/ParIterator.cpp index 794d3ecb00..1ddf347986 100644 --- a/src/ParIterator.cpp +++ b/src/ParIterator.cpp @@ -20,32 +20,34 @@ namespace lyx { -/// -/// ParIterator -/// +////////////////////////////////////////////////////////////////////////// +// +// ParIterator +// +////////////////////////////////////////////////////////////////////////// -ParIterator::ParIterator(DocIterator const & cur) - : DocIterator(cur) +ParIterator::ParIterator(DocIterator const & dit) + : DocIterator(dit) {} -ParIterator par_iterator_begin(Inset & inset) -{ - return ParIterator(doc_iterator_begin(inset)); -} - - -ParIterator par_iterator_end(Inset & inset) -{ - return ParIterator(doc_iterator_end(inset)); -} - - ParIterator::ParIterator(ParIterator const & pi) : DocIterator(DocIterator(pi)) {} +ParIterator par_iterator_begin(Inset & inset) +{ + return ParIterator(doc_iterator_begin(&inset.buffer(), &inset)); +} + + +ParIterator par_iterator_end(Inset & inset) +{ + return ParIterator(doc_iterator_end(&inset.buffer(), &inset)); +} + + ParIterator & ParIterator::operator++() { forwardPar(); @@ -104,9 +106,16 @@ ParagraphList & ParIterator::plist() const } -/// -/// ParConstIterator -/// +////////////////////////////////////////////////////////////////////////// +// +// ParConstIterator +// +////////////////////////////////////////////////////////////////////////// + + +ParConstIterator::ParConstIterator(Buffer const * buf) + : DocIterator(const_cast(buf)) +{} ParConstIterator::ParConstIterator(DocIterator const & dit) @@ -164,18 +173,4 @@ bool operator!=(ParConstIterator const & iter1, ParConstIterator const & iter2) #endif -// FIXME: const correctness! - -ParConstIterator par_const_iterator_begin(Inset const & inset) -{ - return ParConstIterator(doc_iterator_begin(const_cast(inset))); -} - - -ParConstIterator par_const_iterator_end(Inset const & inset) -{ - return ParConstIterator(doc_iterator_end(const_cast(inset))); -} - - } // namespace lyx diff --git a/src/ParIterator.h b/src/ParIterator.h index 86ae70edd8..320493dac0 100644 --- a/src/ParIterator.h +++ b/src/ParIterator.h @@ -21,6 +21,7 @@ namespace lyx { +class Buffer; class Inset; class Text; class ParagraphList; @@ -38,10 +39,11 @@ public: typedef StdIt::reference reference; /// - ParIterator() : DocIterator() {} + /// + ParIterator(Buffer * buf) : DocIterator(buf) {} /// - ParIterator(Inset &, pit_type pit); + ParIterator(Buffer * buf, Inset &, pit_type pit); /// ParIterator(ParIterator const &); /// @@ -94,7 +96,7 @@ class ParConstIterator : public std::iteratorparams().documentClass(); Layout const & layout = cpar.layout(); // this is only allowed, if the current paragraph is not empty @@ -356,7 +357,7 @@ void Text::breakParagraph(Cursor & cur, bool inverse_logic) // Always break behind a space // It is better to erase the space (Dekel) if (cur.pos() != cur.lastpos() && cpar.isLineSeparator(cur.pos())) - cpar.eraseChar(cur.pos(), cur.buffer().params().trackChanges); + cpar.eraseChar(cur.pos(), cur.buffer()->params().trackChanges); // What should the layout for the new paragraph be? bool keep_layout = inverse_logic ? @@ -370,7 +371,7 @@ void Text::breakParagraph(Cursor & cur, bool inverse_logic) // we need to set this before we insert the paragraph. bool const isempty = cpar.allowEmpty() && cpar.empty(); - lyx::breakParagraph(cur.buffer().params(), paragraphs(), cpit, + lyx::breakParagraph(cur.buffer()->params(), paragraphs(), cpit, cur.pos(), keep_layout); // After this, neither paragraph contains any rows! @@ -391,11 +392,11 @@ void Text::breakParagraph(Cursor & cur, bool inverse_logic) } while (!pars_[next_par].empty() && pars_[next_par].isNewline(0)) { - if (!pars_[next_par].eraseChar(0, cur.buffer().params().trackChanges)) + if (!pars_[next_par].eraseChar(0, cur.buffer()->params().trackChanges)) break; // the character couldn't be deleted physically due to change tracking } - cur.buffer().updateLabels(); + cur.buffer()->updateLabels(); // A singlePar update is not enough in this case. cur.updateFlags(Update::Force); @@ -418,7 +419,7 @@ void Text::insertChar(Cursor & cur, char_type c) cur.recordUndo(INSERT_UNDO); TextMetrics const & tm = cur.bv().textMetrics(this); - Buffer const & buffer = cur.buffer(); + Buffer const & buffer = *cur.buffer(); Paragraph & par = cur.paragraph(); // try to remove this pit_type const pit = cur.pit(); @@ -538,7 +539,8 @@ void Text::insertChar(Cursor & cur, char_type c) } } - par.insertChar(cur.pos(), c, cur.current_font, cur.buffer().params().trackChanges); + par.insertChar(cur.pos(), c, cur.current_font, + cur.buffer()->params().trackChanges); cur.checkBufferStructure(); // cur.updateFlags(Update::Force); @@ -689,11 +691,9 @@ bool Text::cursorVisLeftOneWord(Cursor & cur) // we should stop when we have an LTR word on our right or an RTL word // on our left if ((left_is_letter && temp_cur.paragraph().getFontSettings( - temp_cur.bv().buffer().params(), - left_pos).isRightToLeft()) + temp_cur.buffer()->params(), left_pos).isRightToLeft()) || (right_is_letter && !temp_cur.paragraph().getFontSettings( - temp_cur.bv().buffer().params(), - right_pos).isRightToLeft())) + temp_cur.buffer()->params(), right_pos).isRightToLeft())) break; } @@ -728,10 +728,10 @@ bool Text::cursorVisRightOneWord(Cursor & cur) // we should stop when we have an LTR word on our right or an RTL word // on our left if ((left_is_letter && temp_cur.paragraph().getFontSettings( - temp_cur.bv().buffer().params(), + temp_cur.buffer()->params(), left_pos).isRightToLeft()) || (right_is_letter && !temp_cur.paragraph().getFontSettings( - temp_cur.bv().buffer().params(), + temp_cur.buffer()->params(), right_pos).isRightToLeft())) break; } @@ -809,9 +809,9 @@ void Text::acceptOrRejectChanges(Cursor & cur, ChangeOp op) pos_type right = (pit == endPit ? endPos : parSize); if (op == ACCEPT) { - pars_[pit].acceptChanges(cur.buffer().params(), left, right); + pars_[pit].acceptChanges(cur.buffer()->params(), left, right); } else { - pars_[pit].rejectChanges(cur.buffer().params(), left, right); + pars_[pit].rejectChanges(cur.buffer()->params(), left, right); } } @@ -838,7 +838,7 @@ void Text::acceptOrRejectChanges(Cursor & cur, ChangeOp op) // instead, we mark it unchanged pars_[pit].setChange(pos, Change(Change::UNCHANGED)); } else { - mergeParagraph(cur.buffer().params(), pars_, pit); + mergeParagraph(cur.buffer()->params(), pars_, pit); --endPit; --pit; } @@ -851,7 +851,7 @@ void Text::acceptOrRejectChanges(Cursor & cur, ChangeOp op) // we mark the par break at the end of the last paragraph unchanged pars_[pit].setChange(pos, Change(Change::UNCHANGED)); } else { - mergeParagraph(cur.buffer().params(), pars_, pit); + mergeParagraph(cur.buffer()->params(), pars_, pit); --endPit; --pit; } @@ -861,7 +861,7 @@ void Text::acceptOrRejectChanges(Cursor & cur, ChangeOp op) // finally, invoke the DEPM - deleteEmptyParagraphMechanism(begPit, endPit, cur.buffer().params().trackChanges); + deleteEmptyParagraphMechanism(begPit, endPit, cur.buffer()->params().trackChanges); // @@ -869,7 +869,7 @@ void Text::acceptOrRejectChanges(Cursor & cur, ChangeOp op) cur.clearSelection(); setCursorIntern(cur, begPit, begPos); cur.updateFlags(Update::Force); - cur.buffer().updateLabels(); + cur.buffer()->updateLabels(); } @@ -979,7 +979,7 @@ void Text::changeCase(Cursor & cur, TextCase action) Paragraph & par = pars_[pit]; pos_type const pos = (pit == begPit ? begPos : 0); right = (pit == endPit ? endPos : par.size()); - par.changeCase(cur.buffer().params(), pos, right, action); + par.changeCase(cur.buffer()->params(), pos, right, action); } // the selection may have changed due to logically-only deleted chars @@ -1003,7 +1003,7 @@ bool Text::handleBibitems(Cursor & cur) if (cur.pos() != 0) return false; - BufferParams const & bufparams = cur.buffer().params(); + BufferParams const & bufparams = cur.buffer()->params(); Paragraph const & par = cur.paragraph(); Cursor prevcur = cur; if (cur.pit() > 0) { @@ -1018,7 +1018,7 @@ bool Text::handleBibitems(Cursor & cur) cur.recordUndo(ATOMIC_UNDO, prevcur.pit()); mergeParagraph(bufparams, cur.text()->paragraphs(), prevcur.pit()); - cur.buffer().updateLabels(); + cur.buffer()->updateLabels(); setCursorIntern(cur, prevcur.pit(), prevcur.pos()); cur.updateFlags(Update::Force); return true; @@ -1032,7 +1032,7 @@ bool Text::handleBibitems(Cursor & cur) bool Text::erase(Cursor & cur) { - LASSERT(this == cur.text(), /**/); + LASSERT(this == cur.text(), return false); bool needsUpdate = false; Paragraph & par = cur.paragraph(); @@ -1041,12 +1041,12 @@ bool Text::erase(Cursor & cur) // any paragraphs cur.recordUndo(DELETE_UNDO); bool const was_inset = cur.paragraph().isInset(cur.pos()); - if(!par.eraseChar(cur.pos(), cur.buffer().params().trackChanges)) + if(!par.eraseChar(cur.pos(), cur.buffer()->params().trackChanges)) // the character has been logically deleted only => skip it cur.top().forwardPos(); if (was_inset) - cur.buffer().updateLabels(); + cur.buffer()->updateLabels(); else cur.checkBufferStructure(); needsUpdate = true; @@ -1054,7 +1054,7 @@ bool Text::erase(Cursor & cur) if (cur.pit() == cur.lastpit()) return dissolveInset(cur); - if (!par.isMergedOnEndOfParDeletion(cur.buffer().params().trackChanges)) { + if (!par.isMergedOnEndOfParDeletion(cur.buffer()->params().trackChanges)) { par.setChange(cur.pos(), Change(Change::DELETED)); cur.forwardPos(); needsUpdate = true; @@ -1085,7 +1085,7 @@ bool Text::backspacePos0(Cursor & cur) bool needsUpdate = false; - BufferParams const & bufparams = cur.buffer().params(); + BufferParams const & bufparams = cur.buffer()->params(); DocumentClass const & tclass = bufparams.documentClass(); ParagraphList & plist = cur.text()->paragraphs(); Paragraph const & par = cur.paragraph(); @@ -1122,7 +1122,7 @@ bool Text::backspacePos0(Cursor & cur) } if (needsUpdate) { - cur.buffer().updateLabels(); + cur.buffer()->updateLabels(); setCursorIntern(cur, prevcur.pit(), prevcur.pos()); } @@ -1140,7 +1140,7 @@ bool Text::backspace(Cursor & cur) Paragraph & prev_par = pars_[cur.pit() - 1]; - if (!prev_par.isMergedOnEndOfParDeletion(cur.buffer().params().trackChanges)) { + if (!prev_par.isMergedOnEndOfParDeletion(cur.buffer()->params().trackChanges)) { prev_par.setChange(prev_par.size(), Change(Change::DELETED)); setCursorIntern(cur, cur.pit() - 1, prev_par.size()); return true; @@ -1160,9 +1160,9 @@ bool Text::backspace(Cursor & cur) setCursorIntern(cur, cur.pit(), cur.pos() - 1, false, cur.boundary()); bool const was_inset = cur.paragraph().isInset(cur.pos()); - cur.paragraph().eraseChar(cur.pos(), cur.buffer().params().trackChanges); + cur.paragraph().eraseChar(cur.pos(), cur.buffer()->params().trackChanges); if (was_inset) - cur.buffer().updateLabels(); + cur.buffer()->updateLabels(); else cur.checkBufferStructure(); } @@ -1201,7 +1201,7 @@ bool Text::dissolveInset(Cursor & cur) if (spit == 0) spos += cur.pos(); spit += cur.pit(); - Buffer & b = cur.buffer(); + Buffer & b = *cur.buffer(); cur.paragraph().eraseChar(cur.pos(), b.params().trackChanges); if (!plist.empty()) { // ERT paragraphs have the Language latex_language. @@ -1336,7 +1336,7 @@ bool Text::read(Buffer const & buf, Lexer & lex, docstring Text::currentState(Cursor const & cur) const { LASSERT(this == cur.text(), /**/); - Buffer & buf = cur.buffer(); + Buffer & buf = *cur.buffer(); Paragraph const & par = cur.paragraph(); odocstringstream os; @@ -1542,15 +1542,15 @@ void Text::charsTranspose(Cursor & cur) // Store the characters to be transposed (including font information). char_type const char1 = par.getChar(pos1); Font const font1 = - par.getFontSettings(cur.buffer().params(), pos1); + par.getFontSettings(cur.buffer()->params(), pos1); char_type const char2 = par.getChar(pos2); Font const font2 = - par.getFontSettings(cur.buffer().params(), pos2); + par.getFontSettings(cur.buffer()->params(), pos2); // And finally, we are ready to perform the transposition. // Track the changes if Change Tracking is enabled. - bool const trackChanges = cur.buffer().params().trackChanges; + bool const trackChanges = cur.buffer()->params().trackChanges; cur.recordUndo(); diff --git a/src/Text2.cpp b/src/Text2.cpp index a224dc75eb..9db9b76036 100644 --- a/src/Text2.cpp +++ b/src/Text2.cpp @@ -234,8 +234,8 @@ void Text::setLayout(Cursor & cur, docstring const & layout) pit_type end = cur.selEnd().pit() + 1; pit_type undopit = undoSpan(end - 1); recUndo(cur, start, undopit - 1); - setLayout(cur.buffer(), start, end, layout); - cur.buffer().updateLabels(); + setLayout(*cur.buffer(), start, end, layout); + cur.buffer()->updateLabels(); } @@ -294,7 +294,7 @@ void Text::changeDepth(Cursor & cur, DEPTH_CHANGE type) } // this handles the counter labels, and also fixes up // depth values for follow-on (child) paragraphs - cur.buffer().updateLabels(); + cur.buffer()->updateLabels(); } @@ -306,13 +306,13 @@ void Text::setFont(Cursor & cur, Font const & font, bool toggleall) FontInfo layoutfont; pit_type pit = cur.pit(); if (cur.pos() < pars_[pit].beginOfBody()) - layoutfont = labelFont(cur.buffer(), pars_[pit]); + layoutfont = labelFont(*cur.buffer(), pars_[pit]); else - layoutfont = layoutFont(cur.buffer(), pit); + layoutfont = layoutFont(*cur.buffer(), pit); // Update current font cur.real_current_font.update(font, - cur.buffer().params().language, + cur.buffer()->params().language, toggleall); // Reduce to implicit settings @@ -478,7 +478,7 @@ void Text::insertInset(Cursor & cur, Inset * inset) LASSERT(this == cur.text(), /**/); LASSERT(inset, /**/); cur.paragraph().insertInset(cur.pos(), inset, cur.current_font, - Change(cur.buffer().params().trackChanges + Change(cur.buffer()->params().trackChanges ? Change::INSERTED : Change::UNCHANGED)); } @@ -486,7 +486,7 @@ void Text::insertInset(Cursor & cur, Inset * inset) // needed to insert the selection void Text::insertStringAsLines(Cursor & cur, docstring const & str) { - cur.buffer().insertStringAsLines(pars_, cur.pit(), cur.pos(), + cur.buffer()->insertStringAsLines(pars_, cur.pit(), cur.pos(), cur.current_font, str, autoBreakRows_); } @@ -815,7 +815,7 @@ bool Text::deleteEmptyParagraphMechanism(Cursor & cur, && oldpar.isLineSeparator(old.pos() - 1) && !oldpar.isDeleted(old.pos() - 1) && !oldpar.isDeleted(old.pos())) { - oldpar.eraseChar(old.pos() - 1, cur.buffer().params().trackChanges); + oldpar.eraseChar(old.pos() - 1, cur.buffer()->params().trackChanges); // FIXME: This will not work anymore when we have multiple views of the same buffer // In this case, we will have to correct also the cursors held by // other bufferviews. It will probably be easier to do that in a more @@ -870,7 +870,7 @@ bool Text::deleteEmptyParagraphMechanism(Cursor & cur, return true; } - if (oldpar.stripLeadingSpaces(cur.buffer().params().trackChanges)) { + if (oldpar.stripLeadingSpaces(cur.buffer()->params().trackChanges)) { need_anchor_change = true; // We return true here because the Paragraph contents changed and // we need a redraw before further action is processed. diff --git a/src/Text3.cpp b/src/Text3.cpp index 73398aa509..8a181f80c0 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -259,8 +259,8 @@ static bool doInsertInset(Cursor & cur, Text * text, if (!gotsel || !pastesel) return true; - pasteFromStack(cur, cur.buffer().errorList("Paste"), 0); - cur.buffer().errors("Paste"); + pasteFromStack(cur, cur.buffer()->errorList("Paste"), 0); + cur.buffer()->errors("Paste"); cur.clearSelection(); // bug 393 cur.finishUndo(); InsetText * insetText = dynamic_cast(inset); @@ -305,7 +305,7 @@ enum OutlineOp { static void outline(OutlineOp mode, Cursor & cur) { - Buffer & buf = cur.buffer(); + Buffer & buf = *cur.buffer(); pit_type & pit = cur.pit(); ParagraphList & pars = buf.text().paragraphs(); ParagraphList::iterator bgn = pars.begin(); @@ -473,7 +473,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) recUndo(cur, pit, pit + 1); cur.finishUndo(); swap(pars_[pit], pars_[pit + 1]); - cur.buffer().updateLabels(); + cur.buffer()->updateLabels(); needsUpdate = true; ++cur.pit(); break; @@ -484,7 +484,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) recUndo(cur, pit - 1, pit); cur.finishUndo(); swap(pars_[pit], pars_[pit - 1]); - cur.buffer().updateLabels(); + cur.buffer()->updateLabels(); --cur.pit(); needsUpdate = true; break; @@ -510,7 +510,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) par.params().startOfAppendix(start); // we can set the refreshing parameters now - cur.buffer().updateLabels(); + cur.buffer()->updateLabels(); break; } @@ -523,17 +523,17 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) break; case LFUN_WORD_DELETE_BACKWARD: - if (cur.selection()) { + if (cur.selection()) cutSelection(cur, true, false); - } else + else deleteWordBackward(cur); finishChange(cur, false); break; case LFUN_LINE_DELETE: - if (cur.selection()) { + if (cur.selection()) cutSelection(cur, true, false); - } else + else tm.deleteLineForward(cur); finishChange(cur, false); break; @@ -541,22 +541,20 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) case LFUN_BUFFER_BEGIN: case LFUN_BUFFER_BEGIN_SELECT: needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_BEGIN_SELECT); - if (cur.depth() == 1) { + if (cur.depth() == 1) needsUpdate |= cursorTop(cur); - } else { + else cur.undispatched(); - } cur.updateFlags(Update::FitCursor); break; case LFUN_BUFFER_END: case LFUN_BUFFER_END_SELECT: needsUpdate |= cur.selHandle(cmd.action == LFUN_BUFFER_END_SELECT); - if (cur.depth() == 1) { + if (cur.depth() == 1) needsUpdate |= cursorBottom(cur); - } else { + else cur.undispatched(); - } cur.updateFlags(Update::FitCursor); break; @@ -1841,26 +1839,26 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) case LFUN_OUTLINE_UP: outline(OutlineUp, cur); setCursor(cur, cur.pit(), 0); - cur.buffer().updateLabels(); + cur.buffer()->updateLabels(); needsUpdate = true; break; case LFUN_OUTLINE_DOWN: outline(OutlineDown, cur); setCursor(cur, cur.pit(), 0); - cur.buffer().updateLabels(); + cur.buffer()->updateLabels(); needsUpdate = true; break; case LFUN_OUTLINE_IN: outline(OutlineIn, cur); - cur.buffer().updateLabels(); + cur.buffer()->updateLabels(); needsUpdate = true; break; case LFUN_OUTLINE_OUT: outline(OutlineOut, cur); - cur.buffer().updateLabels(); + cur.buffer()->updateLabels(); needsUpdate = true; break; @@ -2028,7 +2026,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd, code = FLEX_CODE; string s = cmd.getArg(0); InsetLayout il = - cur.buffer().params().documentClass().insetLayout(from_utf8(s)); + cur.buffer()->params().documentClass().insetLayout(from_utf8(s)); if (il.lyxtype() != InsetLayout::CHARSTYLE && il.lyxtype() != InsetLayout::CUSTOM && il.lyxtype() != InsetLayout::ELEMENT && @@ -2041,7 +2039,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd, break; case LFUN_BRANCH_INSERT: code = BRANCH_CODE; - if (cur.buffer().masterBuffer()->params().branchlist().empty()) + if (cur.buffer()->masterBuffer()->params().branchlist().empty()) enable = false; break; case LFUN_LABEL_INSERT: @@ -2182,7 +2180,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd, case LFUN_INSET_DISSOLVE: if (!cmd.argument().empty()) { - InsetLayout const & il = cur.inset().getLayout(cur.buffer().params()); + InsetLayout const & il = cur.inset().getLayout(cur.buffer()->params()); InsetLayout::InsetLyXType const type = translateLyXType(to_utf8(cmd.argument())); enable = cur.inset().lyxCode() == FLEX_CODE diff --git a/src/TocBackend.h b/src/TocBackend.h index f267d3c774..284004bd0c 100644 --- a/src/TocBackend.h +++ b/src/TocBackend.h @@ -38,7 +38,7 @@ class TocItem public: /// Default constructor for STL containers. - TocItem() {} + TocItem() : dit_(0) {} /// TocItem(DocIterator const & dit, int depth, diff --git a/src/Undo.cpp b/src/Undo.cpp index 2acc1a36ba..6339cad336 100644 --- a/src/Undo.cpp +++ b/src/Undo.cpp @@ -346,7 +346,7 @@ void Undo::Private::doTextUndoOrRedo(DocIterator & cur, UndoElementStack & stack // try to return early. // We will store in otherstack the part of the document under 'undo' - DocIterator cell_dit = undo.cell.asDocIterator(&buffer_.inset()); + DocIterator cell_dit = undo.cell.asDocIterator(&buffer_); doRecordUndo(ATOMIC_UNDO, cell_dit, undo.from, cell_dit.lastpit() - undo.end, cur, @@ -354,7 +354,7 @@ void Undo::Private::doTextUndoOrRedo(DocIterator & cur, UndoElementStack & stack // This does the actual undo/redo. //LYXERR0("undo, performing: " << undo); - DocIterator dit = undo.cell.asDocIterator(&buffer_.inset()); + DocIterator dit = undo.cell.asDocIterator(&buffer_); if (undo.isFullBuffer) { LASSERT(undo.pars, /**/); // This is a full document @@ -404,7 +404,7 @@ void Undo::Private::doTextUndoOrRedo(DocIterator & cur, UndoElementStack & stack LASSERT(undo.pars == 0, /**/); LASSERT(undo.array == 0, /**/); - cur = undo.cursor.asDocIterator(&buffer_.inset()); + cur = undo.cursor.asDocIterator(&buffer_); // Now that we're done with undo, we pop it off the stack. stack.pop(); } @@ -509,7 +509,7 @@ void Undo::recordUndoFullDocument(DocIterator const & cur) beginUndoGroup(); d->doRecordUndo( ATOMIC_UNDO, - doc_iterator_begin(d->buffer_.inset()), + doc_iterator_begin(&d->buffer_), 0, d->buffer_.paragraphs().size() - 1, cur, true, diff --git a/src/factory.cpp b/src/factory.cpp index 8df13d2738..01e8c72652 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -320,7 +320,7 @@ Inset * createInsetHelper(Buffer & buf, FuncRequest const & cmd) return 0; } - } //end LFUN_INSET_INSERT + } //end LFUN_INSET_INSERT case LFUN_SPACE_INSERT: { string const name = cmd.getArg(0); diff --git a/src/frontends/qt4/GuiClipboard.cpp b/src/frontends/qt4/GuiClipboard.cpp index d801e06928..0979d1f7ad 100644 --- a/src/frontends/qt4/GuiClipboard.cpp +++ b/src/frontends/qt4/GuiClipboard.cpp @@ -138,7 +138,7 @@ FileName GuiClipboard::getPastedGraphicsFileName(Cursor const & cur, typeNames[Clipboard::JpegGraphicsType] = _("JPEG"); // find unused filename with primary extension - string document_path = cur.buffer().fileName().onlyPath().absFilename(); + string document_path = cur.buffer()->fileName().onlyPath().absFilename(); unsigned newfile_number = 0; FileName filename; do { diff --git a/src/frontends/qt4/GuiCompleter.cpp b/src/frontends/qt4/GuiCompleter.cpp index 776536acd1..884bde6d87 100644 --- a/src/frontends/qt4/GuiCompleter.cpp +++ b/src/frontends/qt4/GuiCompleter.cpp @@ -157,7 +157,7 @@ private: GuiCompleter::GuiCompleter(GuiWorkArea * gui, QObject * parent) - : QCompleter(parent), gui_(gui), updateLock_(0), + : QCompleter(parent), gui_(gui), old_cursor_(0), updateLock_(0), inlineVisible_(false), popupVisible_(false), modelActive_(false) { @@ -564,7 +564,7 @@ void GuiCompleter::showInline(Cursor & cur) void GuiCompleter::hideInline(Cursor & cur) { - gui_->bufferView().setInlineCompletion(cur, DocIterator(), docstring()); + gui_->bufferView().setInlineCompletion(cur, DocIterator(cur.buffer()), docstring()); inlineVisible_ = false; if (inline_timer_.isActive()) diff --git a/src/frontends/qt4/GuiErrorList.cpp b/src/frontends/qt4/GuiErrorList.cpp index bcab846423..dda408c721 100644 --- a/src/frontends/qt4/GuiErrorList.cpp +++ b/src/frontends/qt4/GuiErrorList.cpp @@ -107,7 +107,7 @@ bool GuiErrorList::goTo(int item) Buffer const & buf = buffer(); DocIterator dit = buf.getParFromID(err.par_id); - if (dit == doc_iterator_end(buf.inset())) { + if (dit == doc_iterator_end(&buf)) { // FIXME: Happens when loading a read-only doc with // unknown layout. Should this be the case? LYXERR0("par id " << err.par_id << " not found"); diff --git a/src/frontends/qt4/GuiSpellchecker.cpp b/src/frontends/qt4/GuiSpellchecker.cpp index be77ce0f50..9341a96e74 100644 --- a/src/frontends/qt4/GuiSpellchecker.cpp +++ b/src/frontends/qt4/GuiSpellchecker.cpp @@ -308,7 +308,7 @@ void GuiSpellchecker::check() ptrdiff_t start = 0; ptrdiff_t total = 0; - DocIterator it = doc_iterator_begin(buffer().inset()); + DocIterator it = doc_iterator_begin(&buffer()); for (start = 1; it != cur; it.forwardPos()) ++start; diff --git a/src/insets/InsetBox.cpp b/src/insets/InsetBox.cpp index 287af6efab..cc45619e0c 100644 --- a/src/insets/InsetBox.cpp +++ b/src/insets/InsetBox.cpp @@ -212,7 +212,7 @@ void InsetBox::doDispatch(Cursor & cur, FuncRequest & cmd) params_.type = cmd.getArg(1); else string2params(to_utf8(cmd.argument()), params_); - setLayout(cur.buffer().params()); + setLayout(cur.buffer()->params()); break; } diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp index f305139dbf..968abf0400 100644 --- a/src/insets/InsetBranch.cpp +++ b/src/insets/InsetBranch.cpp @@ -124,7 +124,7 @@ void InsetBranch::doDispatch(Cursor & cur, FuncRequest & cmd) InsetBranchParams params; InsetBranch::string2params(to_utf8(cmd.argument()), params); params_.branch = params.branch; - setLayout(cur.buffer().params()); + setLayout(cur.buffer()->params()); break; } diff --git a/src/insets/InsetERT.cpp b/src/insets/InsetERT.cpp index 89ba636dca..bc4756a5d8 100644 --- a/src/insets/InsetERT.cpp +++ b/src/insets/InsetERT.cpp @@ -105,7 +105,7 @@ int InsetERT::docbook(odocstream & os, OutputParams const &) const void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd) { - BufferParams const & bp = cur.buffer().params(); + BufferParams const & bp = cur.buffer()->params(); Layout const layout = bp.documentClass().plainLayout(); //lyxerr << "\nInsetERT::doDispatch (begin): cmd: " << cmd << endl; switch (cmd.action) { diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp index 0ad25cf410..32de0d2216 100644 --- a/src/insets/InsetFloat.cpp +++ b/src/insets/InsetFloat.cpp @@ -156,11 +156,11 @@ void InsetFloat::doDispatch(Cursor & cur, FuncRequest & cmd) params_.placement = params.placement; params_.wide = params.wide; params_.sideways = params.sideways; - setWide(params_.wide, cur.buffer().params(), false); - setSideways(params_.sideways, cur.buffer().params(), false); + setWide(params_.wide, cur.buffer()->params(), false); + setSideways(params_.sideways, cur.buffer()->params(), false); } - setNewLabel(cur.buffer().params()); + setNewLabel(cur.buffer()->params()); break; } diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp index 14fdddabd4..1116a5f96a 100644 --- a/src/insets/InsetGraphics.cpp +++ b/src/insets/InsetGraphics.cpp @@ -206,20 +206,18 @@ void InsetGraphics::doDispatch(Cursor & cur, FuncRequest & cmd) // if the inset is part of a graphics group, all the // other members should be updated too. if (!params_.groupId.empty()) - graphics::unifyGraphicsGroups(cur.buffer(), + graphics::unifyGraphicsGroups(buffer(), to_utf8(cmd.argument())); break; } case LFUN_INSET_DIALOG_UPDATE: - cur.bv().updateDialog("graphics", params2string(params(), - cur.bv().buffer())); + cur.bv().updateDialog("graphics", params2string(params(), buffer())); break; case LFUN_MOUSE_RELEASE: if (!cur.selection() && cmd.button() == mouse_button::button1) - cur.bv().showDialog("graphics", params2string(params(), - cur.bv().buffer()), this); + cur.bv().showDialog("graphics", params2string(params(), buffer()), this); break; default: diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index 9267d02de4..9bf3701cda 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -218,7 +218,7 @@ bool InsetInclude::isCompatibleCommand(string const & s) void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd) { - LASSERT(&cur.buffer() == &buffer(), /**/); + LASSERT(cur.buffer() == &buffer(), return); switch (cmd.action) { case LFUN_INSET_EDIT: { diff --git a/src/insets/InsetLabel.cpp b/src/insets/InsetLabel.cpp index 88d2f4f6c5..bcbae9e3a6 100644 --- a/src/insets/InsetLabel.cpp +++ b/src/insets/InsetLabel.cpp @@ -173,7 +173,7 @@ void InsetLabel::doDispatch(Cursor & cur, FuncRequest & cmd) InsetCommandParams p(REF_CODE, "ref"); p["reference"] = getParam("name"); cap::clearSelection(); - cap::copyInset(cur, new InsetRef(cur.buffer(), p), getParam("name")); + cap::copyInset(cur, new InsetRef(*cur.buffer(), p), getParam("name")); break; } diff --git a/src/insets/InsetNote.cpp b/src/insets/InsetNote.cpp index 23fdb9878a..91258a891e 100644 --- a/src/insets/InsetNote.cpp +++ b/src/insets/InsetNote.cpp @@ -181,8 +181,7 @@ void InsetNote::doDispatch(Cursor & cur, FuncRequest & cmd) case LFUN_INSET_MODIFY: string2params(to_utf8(cmd.argument()), params_); - // get a bp from cur: - setLayout(cur.buffer().params()); + setLayout(buffer().params()); break; case LFUN_INSET_DIALOG_UPDATE: @@ -370,28 +369,29 @@ void InsetNote::string2params(string const & in, InsetNoteParams & params) params.read(lex); } -bool mutateNotes(Cursor & cur, string const & source, string const &target) + +bool mutateNotes(Cursor & cur, string const & source, string const & target) { InsetNoteParams::Type typeSrc = notetranslator().find(source); InsetNoteParams::Type typeTrt = notetranslator().find(target); // syntax check of arguments - string sSrc = notetranslator().find(typeSrc); - string sTrt = notetranslator().find(typeTrt); - if ((sSrc != source) || (sTrt != target)) + string src = notetranslator().find(typeSrc); + string trt = notetranslator().find(typeTrt); + if (src != source || trt != target) return false; // did we found some conforming inset? bool ret = false; cur.beginUndoGroup(); - Inset & inset = cur.buffer().inset(); + Inset & inset = cur.buffer()->inset(); InsetIterator it = inset_iterator_begin(inset); InsetIterator const end = inset_iterator_end(inset); for (; it != end; ++it) { if (it->lyxCode() == NOTE_CODE) { InsetNote & ins = static_cast(*it); if (ins.params().type == typeSrc) { - cur.buffer().undo().recordUndo(it); + cur.buffer()->undo().recordUndo(it); FuncRequest fr(LFUN_INSET_MODIFY, "note Note " + target); ins.dispatch(cur, fr); ret = true; diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index e9e2c31033..5d2d28906b 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -4783,7 +4783,7 @@ bool InsetTabular::pasteClipboard(Cursor & cur) new InsetTableCell(*paste_tabular->cellInset(r1, c1))); tabular.setCellInset(r2, c2, inset); // FIXME: change tracking (MG) - inset->setChange(Change(cur.buffer().params().trackChanges ? + inset->setChange(Change(buffer().params().trackChanges ? Change::INSERTED : Change::UNCHANGED)); cur.pos() = 0; } @@ -4804,7 +4804,7 @@ void InsetTabular::cutSelection(Cursor & cur) for (col_type j = cs; j <= ce; ++j) { shared_ptr t = cell(tabular.cellIndex(i, j)); - if (cur.buffer().params().trackChanges) + if (buffer().params().trackChanges) // FIXME: Change tracking (MG) t->setChange(Change(Change::DELETED)); else @@ -4826,7 +4826,7 @@ bool InsetTabular::isRightToLeft(Cursor & cur) const LASSERT(cur.depth() > 1, /**/); Paragraph const & parentpar = cur[cur.depth() - 2].paragraph(); pos_type const parentpos = cur[cur.depth() - 2].pos(); - return parentpar.getFontSettings(cur.bv().buffer().params(), + return parentpar.getFontSettings(buffer().params(), parentpos).language()->rightToLeft(); } diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 078d8154db..acb296ac6e 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -529,7 +529,7 @@ void InsetText::addToToc(DocIterator const & cdit) bool InsetText::notifyCursorLeaves(Cursor const & old, Cursor & cur) { - if (cur.buffer().isClean()) + if (buffer().isClean()) return Inset::notifyCursorLeaves(old, cur); // find text inset in old cursor @@ -548,9 +548,7 @@ bool InsetText::notifyCursorLeaves(Cursor const & old, Cursor & cur) bool InsetText::completionSupported(Cursor const & cur) const { - Cursor const & bvCur = cur.bv().cursor(); - if (&bvCur.inset() != this) - return false; + //LASSERT(&cur.bv().cursor().inset() != this, return false); return text_.completionSupported(cur); } diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index d7c0fee879..6e15560f60 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -166,7 +166,7 @@ int replaceAll(BufferView * bv, int const ssize = searchstr.size(); Cursor cur(*bv); - cur.setCursor(doc_iterator_begin(buf.inset())); + cur.setCursor(doc_iterator_begin(&buf)); while (findForward(cur, match, false)) { // Backup current cursor position and font. pos_type const pos = cur.pos(); @@ -183,7 +183,7 @@ int replaceAll(BufferView * bv, } buf.updateLabels(); - bv->putSelectionAt(doc_iterator_begin(buf.inset()), 0, false); + bv->putSelectionAt(doc_iterator_begin(&buf), 0, false); if (num) buf.markDirty(); return num; @@ -707,9 +707,11 @@ docstring stringifyFromCursor(DocIterator const & cur, int len) return docstring(); } -/** Computes the LaTeX export of buf starting from cur and ending len positions after cur, - ** if len is positive, or at the paragraph or innermost inset end if len is -1. - **/ +/** Computes the LaTeX export of buf starting from cur and ending len positions + * after cur, if len is positive, or at the paragraph or innermost inset end + * if len is -1. + */ + docstring latexifyFromCursor(Buffer const & buf, DocIterator const & cur, int len) { LYXERR(Debug::DEBUG, "Latexifying with len=" << len << " from cursor at pos: " << cur); @@ -757,20 +759,22 @@ docstring latexifyFromCursor(Buffer const & buf, DocIterator const & cur, int le for (MathData::const_iterator it = md.begin() + cs.pos(); it != it_end; ++it) ods << *it; -// MathData md = cur.cell(); -// MathData::const_iterator it_end = ( ( len == -1 || cur.pos() + len > int(md.size()) ) ? md.end() : md.begin() + cur.pos() + len ); -// for (MathData::const_iterator it = md.begin() + cur.pos(); it != it_end; ++it) { -// MathAtom const & ma = *it; -// ma.nucleus()->latex(buf, ods, runparams); -// } + // MathData md = cur.cell(); + // MathData::const_iterator it_end = ( ( len == -1 || cur.pos() + len > int(md.size()) ) ? md.end() : md.begin() + cur.pos() + len ); + // for (MathData::const_iterator it = md.begin() + cur.pos(); it != it_end; ++it) { + // MathAtom const & ma = *it; + // ma.nucleus()->latex(buf, ods, runparams); + // } - // Retrieve the math environment type, and add '$' or '$]' or others (\end{equation}) accordingly + // Retrieve the math environment type, and add '$' or '$]' + // or others (\end{equation}) accordingly for (int s = cur.depth() - 1; s >= 0; --s) { CursorSlice const & cs = cur[s]; - if (cs.asInsetMath() && cs.asInsetMath() && cs.asInsetMath()->asHullInset()) { - WriteStream ws(ods); - cs.asInsetMath()->asHullInset()->footer_write(ws); - break; + InsetMath * inset = cs.asInsetMath(); + if (inset && inset->asHullInset()) { + WriteStream ws(ods); + inset->asHullInset()->footer_write(ws); + break; } } LYXERR(Debug::DEBUG, "Latexified math: '" << lyx::to_utf8(ods.str()) << "'"); @@ -786,9 +790,10 @@ docstring latexifyFromCursor(Buffer const & buf, DocIterator const & cur, int le **/ int findAdvFinalize(DocIterator & cur, MatchStringAdv const & match) { - // Search the foremost position that matches (avoids find of entire math inset when match at start of it) + // Search the foremost position that matches (avoids find of entire math + // inset when match at start of it) size_t d; - DocIterator old_cur; + DocIterator old_cur(cur.buffer()); do { LYXERR(Debug::DEBUG, "Forwarding one step (searching for innermost match)"); d = cur.depth(); @@ -806,7 +811,8 @@ int findAdvFinalize(DocIterator & cur, MatchStringAdv const & match) ++len; LYXERR(Debug::DEBUG, "verifying unmatch with len = " << len); } - int old_len = match(cur, len); // Length of matched text (different from len param) + // Length of matched text (different from len param) + int old_len = match(cur, len); int new_len; // Greedy behaviour while matching regexps while ((new_len = match(cur, len + 1)) > old_len) { @@ -820,12 +826,13 @@ int findAdvFinalize(DocIterator & cur, MatchStringAdv const & match) /// Finds forward int findForwardAdv(DocIterator & cur, MatchStringAdv const & match) { - if (! cur) + if (!cur) return 0; for (; cur; cur.forwardPos()) { -// odocstringstream ods; -// ods << _("Searching ... ") << (cur.bottom().lastpit() - cur.bottom().pit()) * 100 / total; -// cur.message(ods.str()); + // odocstringstream ods; + // ods << _("Searching ... ") + // << (cur.bottom().lastpit() - cur.bottom().pit()) * 100 / total; + // cur.message(ods.str()); if (match(cur)) return findAdvFinalize(cur, match); } @@ -833,19 +840,21 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv const & match) } /// Finds backwards -int findBackwardsAdv(DocIterator & cur, MatchStringAdv const & match) { -// if (cur.pos() > 0 || cur.depth() > 0) -// cur.backwardPos(); +int findBackwardsAdv(DocIterator & cur, MatchStringAdv const & match) +{ + // if (cur.pos() > 0 || cur.depth() > 0) + // cur.backwardPos(); DocIterator cur_orig(cur); if (match(cur_orig)) findAdvFinalize(cur_orig, match); -// int total = cur.bottom().pit() + 1; + // int total = cur.bottom().pit() + 1; for (; cur; cur.backwardPos()) { -// odocstringstream ods; -// ods << _("Searching ... ") << (total - cur.bottom().pit()) * 100 / total; -// cur.message(ods.str()); + // odocstringstream ods; + // ods << _("Searching ... ") << (total - cur.bottom().pit()) * 100 / total; + // cur.message(ods.str()); if (match(cur)) { - // Find the most backward consecutive match within same paragraph while searching backwards. + // Find the most backward consecutive match within same + // paragraph while searching backwards. int pit = cur.pit(); int old_len; DocIterator old_cur; @@ -854,7 +863,8 @@ int findBackwardsAdv(DocIterator & cur, MatchStringAdv const & match) { old_cur = cur; old_len = len; cur.backwardPos(); - LYXERR(Debug::DEBUG, "old_cur: " << old_cur << ", old_len=" << len << ", cur: " << cur); + LYXERR(Debug::DEBUG, "old_cur: " << old_cur + << ", old_len: " << len << ", cur: " << cur); } while (cur && cur.pit() == pit && match(cur) && (len = findAdvFinalize(cur, match)) > old_len); cur = old_cur; @@ -874,7 +884,7 @@ int findBackwardsAdv(DocIterator & cur, MatchStringAdv const & match) { docstring stringifyFromForSearch(FindAdvOptions const & opt, Buffer const & buf, DocIterator const & cur, int len) { - if (! opt.ignoreformat) + if (!opt.ignoreformat) return latexifyFromCursor(buf, cur, len); else return stringifyFromCursor(cur, len); diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index f65f7db3df..083a67d4fe 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -483,10 +483,10 @@ void InsetMathHull::addPreview(graphics::PreviewLoader & ploader) const bool InsetMathHull::notifyCursorLeaves(Cursor const & /*old*/, Cursor & cur) { if (RenderPreview::status() == LyXRC::PREVIEW_ON) { - Buffer const & buffer = cur.buffer(); + Buffer const * buffer = cur.buffer(); docstring const snippet = latexString(*this); - preview_->addPreview(snippet, buffer); - preview_->startLoading(buffer); + preview_->addPreview(snippet, *buffer); + preview_->startLoading(*buffer); cur.updateFlags(Update::Force); } return false; diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index 7df9cf92a8..d7d641515d 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -1437,7 +1437,7 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type const c) MathWordList const & mwl = mathedWordList(); bool star_macro = c == '*' && (mwl.find(name.substr(1) + "*") != mwl.end() - || cur.buffer().getMacro(name.substr(1) + "*", cur, true)); + || cur.buffer()->getMacro(name.substr(1) + "*", cur, true)); if (isAlphaASCII(c) || star_macro) { cur.activeMacro()->setName(name + docstring(1, c)); return true; @@ -1844,10 +1844,10 @@ MathCompletionList::MathCompletionList(Cursor const & cur) { // fill it with macros from the buffer MacroNameSet macros; - cur.buffer().listMacroNames(macros); + cur.buffer()->listMacroNames(macros); MacroNameSet::const_iterator it; for (it = macros.begin(); it != macros.end(); ++it) { - if (cur.buffer().getMacro(*it, cur, false)) + if (cur.buffer()->getMacro(*it, cur, false)) locals.push_back("\\" + *it); } sort(locals.begin(), locals.end()); diff --git a/src/mathed/MacroTable.cpp b/src/mathed/MacroTable.cpp index efb111f84f..389f82e9c1 100644 --- a/src/mathed/MacroTable.cpp +++ b/src/mathed/MacroTable.cpp @@ -67,12 +67,15 @@ void MacroData::expand(vector const & args, MathData & to) const { updateData(); - InsetMathSqrt inset; // Hack. Any inset with a cell would do. + // Hack. Any inset with a cell would do. + static Buffer buffer(""); + static InsetMathSqrt inset; + // FIXME UNICODE asArray(display_.empty() ? definition_ : display_, inset.cell(0)); //lyxerr << "MathData::expand: args: " << args << endl; //lyxerr << "MathData::expand: ar: " << inset.cell(0) << endl; - for (DocIterator it = doc_iterator_begin(inset); it; it.forwardChar()) { + for (DocIterator it = doc_iterator_begin(&buffer, &inset); it; it.forwardChar()) { if (!it.nextInset()) continue; if (it.nextInset()->lyxCode() != MATHMACROARG_CODE) diff --git a/src/mathed/MathMacroTemplate.cpp b/src/mathed/MathMacroTemplate.cpp index eb7e4d10aa..6765f01a99 100644 --- a/src/mathed/MathMacroTemplate.cpp +++ b/src/mathed/MathMacroTemplate.cpp @@ -630,8 +630,9 @@ bool MathMacroTemplate::notifyCursorLeaves(Cursor const & old, Cursor & cur) } -void MathMacroTemplate::removeArguments(Cursor & cur, int from, int to) { - for (DocIterator it = doc_iterator_begin(*this); it; it.forwardChar()) { +void MathMacroTemplate::removeArguments(Cursor & cur, int from, int to) +{ + for (DocIterator it = doc_iterator_begin(&buffer(), this); it; it.forwardChar()) { if (!it.nextInset()) continue; if (it.nextInset()->lyxCode() != MATHMACROARG_CODE) @@ -651,8 +652,9 @@ void MathMacroTemplate::removeArguments(Cursor & cur, int from, int to) { } -void MathMacroTemplate::shiftArguments(size_t from, int by) { - for (DocIterator it = doc_iterator_begin(*this); it; it.forwardChar()) { +void MathMacroTemplate::shiftArguments(size_t from, int by) +{ + for (DocIterator it = doc_iterator_begin(&buffer(), this); it; it.forwardChar()) { if (!it.nextInset()) continue; if (it.nextInset()->lyxCode() != MATHMACROARG_CODE) @@ -669,8 +671,7 @@ void MathMacroTemplate::shiftArguments(size_t from, int by) { int MathMacroTemplate::maxArgumentInDefinition() const { int maxArg = 0; - MathMacroTemplate * nonConst = const_cast(this); - DocIterator it = doc_iterator_begin(*nonConst); + DocIterator it = doc_iterator_begin(&buffer(), this); it.idx() = defIdx(); for (; it; it.forwardChar()) { if (!it.nextInset()) @@ -690,7 +691,7 @@ void MathMacroTemplate::insertMissingArguments(int maxArg) idx_type idx = cell(displayIdx()).empty() ? defIdx() : displayIdx(); // search for #n macros arguments - DocIterator it = doc_iterator_begin(*this); + DocIterator it = doc_iterator_begin(&buffer(), this); it.idx() = idx; for (; it && it[0].idx() == idx; it.forwardChar()) { if (!it.nextInset())