add Buffer * member to DocIterator

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27603 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2008-11-17 11:46:07 +00:00
parent 90a4256e03
commit 6192345f60
37 changed files with 325 additions and 319 deletions

View File

@ -1515,17 +1515,18 @@ bool Buffer::isMultiLingual() const
DocIterator Buffer::getParFromID(int const id) const
{
Buffer * buf = const_cast<Buffer *>(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;
}
@ -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();

View File

@ -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

View File

@ -150,12 +150,14 @@ bool findInset(DocIterator & dit, vector<InsetCode> 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;
return true;
@ -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) {

View File

@ -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<double>::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);
}

View File

@ -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)?

View File

@ -93,7 +93,7 @@ pair<PitPosPair, pit_type>
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

View File

@ -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 <ostream>
@ -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<Buffer *>(buf0);
Inset * inset = const_cast<Inset *>(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<Buffer *>(buf0);
Inset * inset = const_cast<Inset *>(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

View File

@ -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<CursorSlice>
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<CursorSlice> const & internalData() const {
return slices_;
}
std::vector<CursorSlice> const & internalData() const { return slices_; }
///
std::vector<CursorSlice> 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

View File

@ -20,7 +20,7 @@ namespace lyx {
InsetIterator::InsetIterator(Inset & inset)
: DocIterator(inset)
: DocIterator(&inset.buffer(), &inset)
{
}

View File

@ -1806,7 +1806,7 @@ void LyXFunc::updateLayout(DocumentClass const * const oldlayout, Buffer * buf)
oldlayout, buf->params().documentClassPtr(),
static_cast<InsetText &>(buf->inset()), el);
view()->setCursor(backcur.asDocIterator(&(buf->inset())));
view()->setCursor(backcur.asDocIterator(buf));
buf->errors("Class Switch");
buf->updateLabels();

View File

@ -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<Buffer *>(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 &>(inset)));
}
ParConstIterator par_const_iterator_end(Inset const & inset)
{
return ParConstIterator(doc_iterator_end(const_cast<Inset &>(inset)));
}
} // namespace lyx

View File

@ -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::iterator<std::forward_iterator_tag,
{
public:
///
ParConstIterator() : DocIterator() {}
ParConstIterator(Buffer const * buf);
///
ParConstIterator(ParConstIterator const &);
///
@ -118,12 +120,6 @@ public:
//bool operator!=(ParConstIterator const & it1, ParConstIterator const & it2);
ParConstIterator par_const_iterator_begin(Inset const & inset);
ParConstIterator par_const_iterator_end(Inset const & inset);
} // namespace lyx
#endif

View File

@ -293,7 +293,8 @@ class TextCompletionList : public CompletionList
public:
///
TextCompletionList(Cursor const & cur)
: buf_(cur.buffer()), pos_(0) {}
: buffer_(cur.buffer()), pos_(0)
{}
///
virtual ~TextCompletionList() {}
@ -312,7 +313,7 @@ public:
private:
///
Buffer const & buf_;
Buffer const * buffer_;
///
size_t pos_;
};
@ -341,7 +342,7 @@ void Text::breakParagraph(Cursor & cur, bool inverse_logic)
Paragraph & cpar = cur.paragraph();
pit_type cpit = cur.pit();
DocumentClass const & tclass = cur.buffer().params().documentClass();
DocumentClass const & tclass = cur.buffer()->params().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();

View File

@ -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.

View File

@ -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<InsetText *>(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

View File

@ -38,7 +38,7 @@ class TocItem
public:
/// Default constructor for STL containers.
TocItem() {}
TocItem() : dit_(0) {}
///
TocItem(DocIterator const & dit,
int depth,

View File

@ -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,

View File

@ -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 {

View File

@ -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())

View File

@ -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");

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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) {

View File

@ -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;
}

View File

@ -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:

View File

@ -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: {

View File

@ -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;
}

View File

@ -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)
{
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<InsetNote &>(*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;

View File

@ -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<InsetTableCell> 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();
}

View File

@ -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);
}

View File

@ -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);
@ -764,12 +766,14 @@ docstring latexifyFromCursor(Buffer const & buf, DocIterator const & cur, int le
// 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()) {
InsetMath * inset = cs.asInsetMath();
if (inset && inset->asHullInset()) {
WriteStream ws(ods);
cs.asInsetMath()->asHullInset()->footer_write(ws);
inset->asHullInset()->footer_write(ws);
break;
}
}
@ -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) {
@ -824,7 +830,8 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv const & match)
return 0;
for (; cur; cur.forwardPos()) {
// odocstringstream ods;
// ods << _("Searching ... ") << (cur.bottom().lastpit() - cur.bottom().pit()) * 100 / total;
// ods << _("Searching ... ")
// << (cur.bottom().lastpit() - cur.bottom().pit()) * 100 / total;
// cur.message(ods.str());
if (match(cur))
return findAdvFinalize(cur, match);
@ -833,7 +840,8 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv const & match)
}
/// Finds backwards
int findBackwardsAdv(DocIterator & cur, MatchStringAdv const & match) {
int findBackwardsAdv(DocIterator & cur, MatchStringAdv const & match)
{
// if (cur.pos() > 0 || cur.depth() > 0)
// cur.backwardPos();
DocIterator cur_orig(cur);
@ -845,7 +853,8 @@ int findBackwardsAdv(DocIterator & cur, MatchStringAdv const & match) {
// 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;

View File

@ -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;

View File

@ -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());

View File

@ -67,12 +67,15 @@ void MacroData::expand(vector<MathData> 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)

View File

@ -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<MathMacroTemplate *>(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())