mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 10:00:33 +00:00
the pariterator stuff
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8554 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
979a4d8ecf
commit
3e80b0b318
@ -25,13 +25,13 @@
|
||||
#include "funcrequest.h"
|
||||
#include "gettext.h"
|
||||
#include "insetiterator.h"
|
||||
#include "iterators.h"
|
||||
#include "language.h"
|
||||
#include "lyxlayout.h"
|
||||
#include "lyxtext.h"
|
||||
#include "lyxtextclass.h"
|
||||
#include "paragraph.h"
|
||||
#include "paragraph_funcs.h"
|
||||
#include "pariterator.h"
|
||||
#include "texrow.h"
|
||||
#include "undo.h"
|
||||
#include "WordLangTuple.h"
|
||||
@ -368,13 +368,7 @@ LyXText * BufferView::text() const
|
||||
void BufferView::setCursor(ParIterator const & par, lyx::pos_type pos)
|
||||
{
|
||||
LCursor & cur = cursor();
|
||||
cur.reset(buffer()->inset());
|
||||
ParIterator::PosHolder const & positions = par.positions();
|
||||
int const last = par.size() - 1;
|
||||
for (int i = 0; i < last; ++i)
|
||||
(*positions[i].it)->inset->edit(cur, true);
|
||||
cur.resetAnchor();
|
||||
par.text(*buffer())->setCursor(cur, par.pit(), pos);
|
||||
cur.setCursor(makeDocumentIterator(par, pos), false);
|
||||
}
|
||||
|
||||
|
||||
@ -393,20 +387,20 @@ Ab.
|
||||
*/
|
||||
|
||||
void BufferView::putSelectionAt(DocumentIterator const & cur,
|
||||
int length, bool backwards)
|
||||
int length, bool backwards)
|
||||
{
|
||||
ParIterator par(cur);
|
||||
|
||||
cursor().clearSelection();
|
||||
|
||||
LyXText * text = par.text(*buffer());
|
||||
LyXText & text = *par.text();
|
||||
setCursor(par, cur.pos());
|
||||
|
||||
// hack for the chicken and egg problem
|
||||
if (par.inset())
|
||||
top_y(text->getPar(par.outerPar()).y);
|
||||
top_y(text.getPar(par.outerPar()).y);
|
||||
|
||||
update();
|
||||
text->setCursor(cursor(), cur.par(), cur.pos());
|
||||
text.setCursor(cursor(), cur.par(), cur.pos());
|
||||
cursor().updatePos();
|
||||
|
||||
if (length) {
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include "funcrequest.h"
|
||||
#include "gettext.h"
|
||||
#include "intl.h"
|
||||
#include "iterators.h"
|
||||
#include "insetiterator.h"
|
||||
#include "lyx_cb.h" // added for Dispatch functions
|
||||
#include "lyx_main.h"
|
||||
@ -43,6 +42,7 @@
|
||||
#include "paragraph.h"
|
||||
#include "paragraph_funcs.h"
|
||||
#include "ParagraphParameters.h"
|
||||
#include "pariterator.h"
|
||||
#include "undo.h"
|
||||
#include "vspace.h"
|
||||
|
||||
|
@ -1,4 +1,21 @@
|
||||
|
||||
2004-03-28 Alfredo Braunstein <abraunst@lyx.org>
|
||||
|
||||
* dociterator.C: implement forwardPar
|
||||
* iterators.[Ch]: remove, replaced by
|
||||
* pariterator.[Ch]: this. derive ParIterator from DocumentIterator
|
||||
* BufferView.C:
|
||||
* BufferView_pimpl.C:
|
||||
* CutAndPaste.C:
|
||||
* buffer.C:
|
||||
* bufferview_funcs.C:
|
||||
* cursor.C:
|
||||
* lyxfind.C
|
||||
* lyxfunc.C
|
||||
* paragraph_funcs.C
|
||||
* toc.C:
|
||||
* Makefile.am: adjust
|
||||
|
||||
2004-03-28 Alfredo Braunstein <abraunst@lyx.org>
|
||||
|
||||
* CutAndPaste.C (pasteSelection): fix 2 crashes
|
||||
|
@ -21,13 +21,13 @@
|
||||
#include "cursor.h"
|
||||
#include "errorlist.h"
|
||||
#include "gettext.h"
|
||||
#include "iterators.h"
|
||||
#include "lyxtext.h"
|
||||
#include "lyxtextclasslist.h"
|
||||
#include "paragraph.h"
|
||||
#include "paragraph_funcs.h"
|
||||
#include "ParagraphParameters.h"
|
||||
#include "ParagraphList_fwd.h"
|
||||
#include "pariterator.h"
|
||||
#include "undo.h"
|
||||
|
||||
#include "insets/insettabular.h"
|
||||
@ -81,8 +81,12 @@ int SwitchLayoutsBetweenClasses(textclass_type c1, textclass_type c2,
|
||||
|
||||
LyXTextClass const & tclass1 = textclasslist[c1];
|
||||
LyXTextClass const & tclass2 = textclasslist[c2];
|
||||
ParIterator end = ParIterator(pars.size(), pars);
|
||||
for (ParIterator it = ParIterator(0, pars); it != end; ++it) {
|
||||
|
||||
InsetText in;
|
||||
std::swap(in.paragraphs(), pars);
|
||||
|
||||
ParIterator end = ParIterator(in, pars.size());
|
||||
for (ParIterator it = ParIterator(in, 0); it != end; ++it) {
|
||||
string const name = it->layout()->name();
|
||||
bool hasLayout = tclass2.hasLayout(name);
|
||||
|
||||
@ -103,6 +107,7 @@ int SwitchLayoutsBetweenClasses(textclass_type c1, textclass_type c2,
|
||||
it->size()));
|
||||
}
|
||||
}
|
||||
std::swap(in.paragraphs(), pars);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -301,8 +306,11 @@ pasteSelection(Buffer const & buffer, ParagraphList & pars,
|
||||
|
||||
// Prepare the paragraphs and insets for insertion.
|
||||
// A couple of insets store buffer references so need updating.
|
||||
ParIterator fpit(0, insertion);
|
||||
ParIterator fend(insertion.size(), insertion);
|
||||
InsetText in;
|
||||
std::swap(in.paragraphs(), insertion);
|
||||
|
||||
ParIterator fpit(in, 0);
|
||||
ParIterator fend(in, insertion.size());
|
||||
|
||||
for (; fpit != fend; ++fpit) {
|
||||
InsetList::iterator lit = fpit->insetlist.begin();
|
||||
@ -321,7 +329,8 @@ pasteSelection(Buffer const & buffer, ParagraphList & pars,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::swap(in.paragraphs(), insertion);
|
||||
|
||||
// Split the paragraph for inserting the buf if necessary.
|
||||
bool did_split = false;
|
||||
if (pars[pit].size() || pit + 1 == par_type(pars.size())) {
|
||||
|
@ -165,8 +165,6 @@ lyx_SOURCES = \
|
||||
importer.h \
|
||||
intl.C \
|
||||
intl.h \
|
||||
iterators.C \
|
||||
iterators.h \
|
||||
insetiterator.C \
|
||||
insetiterator.h \
|
||||
kbmap.C \
|
||||
@ -243,6 +241,8 @@ lyx_SOURCES = \
|
||||
paragraph_funcs.h \
|
||||
paragraph_pimpl.C \
|
||||
paragraph_pimpl.h \
|
||||
pariterator.C \
|
||||
pariterator.h \
|
||||
SpellBase.h \
|
||||
ispell.C \
|
||||
ispell.h \
|
||||
|
10
src/buffer.C
10
src/buffer.C
@ -26,7 +26,6 @@
|
||||
#include "funcrequest.h"
|
||||
#include "gettext.h"
|
||||
#include "insetiterator.h"
|
||||
#include "iterators.h"
|
||||
#include "language.h"
|
||||
#include "LaTeX.h"
|
||||
#include "LaTeXFeatures.h"
|
||||
@ -44,6 +43,7 @@
|
||||
#include "paragraph.h"
|
||||
#include "paragraph_funcs.h"
|
||||
#include "ParagraphParameters.h"
|
||||
#include "pariterator.h"
|
||||
#include "sgml.h"
|
||||
#include "texrow.h"
|
||||
#include "undo.h"
|
||||
@ -1344,25 +1344,25 @@ bool Buffer::hasParWithID(int id) const
|
||||
|
||||
ParIterator Buffer::par_iterator_begin()
|
||||
{
|
||||
return ParIterator(0, paragraphs());
|
||||
return ParIterator(inset(), 0);
|
||||
}
|
||||
|
||||
|
||||
ParIterator Buffer::par_iterator_end()
|
||||
{
|
||||
return ParIterator(paragraphs().size(), paragraphs());
|
||||
return ParIterator(DocumentIterator());
|
||||
}
|
||||
|
||||
|
||||
ParConstIterator Buffer::par_iterator_begin() const
|
||||
{
|
||||
return ParConstIterator(0, paragraphs());
|
||||
return ParConstIterator(inset(), 0);
|
||||
}
|
||||
|
||||
|
||||
ParConstIterator Buffer::par_iterator_end() const
|
||||
{
|
||||
return ParConstIterator(paragraphs().size(), paragraphs());
|
||||
return ParConstIterator(DocumentIterator());
|
||||
}
|
||||
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include "lyxrow.h"
|
||||
#include "paragraph.h"
|
||||
#include "ParagraphParameters.h"
|
||||
#include "iterators.h"
|
||||
#include "pariterator.h"
|
||||
|
||||
#include "frontends/Alert.h"
|
||||
#include "frontends/LyXView.h"
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include "dispatchresult.h"
|
||||
#include "encoding.h"
|
||||
#include "funcrequest.h"
|
||||
#include "iterators.h"
|
||||
#include "language.h"
|
||||
#include "lfuns.h"
|
||||
#include "lyxfont.h"
|
||||
@ -30,6 +29,7 @@
|
||||
#include "lyxtext.h"
|
||||
#include "paragraph.h"
|
||||
#include "paragraph_funcs.h"
|
||||
#include "pariterator.h"
|
||||
|
||||
#include "insets/updatableinset.h"
|
||||
#include "insets/insettabular.h"
|
||||
|
@ -294,11 +294,19 @@ void DocumentIterator::forwardPos()
|
||||
}
|
||||
|
||||
|
||||
void DocumentIterator::forwardPar()
|
||||
{
|
||||
forwardPos();
|
||||
while (!empty() && (!inTexted() || pos() != 0))
|
||||
forwardPos();
|
||||
}
|
||||
|
||||
|
||||
void DocumentIterator::forwardChar()
|
||||
{
|
||||
forwardPos();
|
||||
forwardPos();
|
||||
while (size() != 0 && pos() == lastpos())
|
||||
forwardPos();
|
||||
forwardPos();
|
||||
}
|
||||
|
||||
|
||||
@ -317,62 +325,6 @@ void DocumentIterator::backwardChar()
|
||||
}
|
||||
|
||||
|
||||
void DocumentIterator::forwardPar()
|
||||
{
|
||||
CursorSlice & top = back();
|
||||
lyxerr << "XXX " << *this << endl;
|
||||
|
||||
// move into an inset to the right if possible
|
||||
InsetBase * n = 0;
|
||||
if (top.pos() != lastpos()) {
|
||||
// this is impossible for pos() == size()
|
||||
if (inMathed()) {
|
||||
n = (top.cell().begin() + top.pos())->nucleus();
|
||||
} else {
|
||||
if (paragraph().isInset(top.pos()))
|
||||
n = paragraph().getInset(top.pos());
|
||||
}
|
||||
}
|
||||
|
||||
if (n && n->isActive()) {
|
||||
lyxerr << "... descend" << endl;
|
||||
push_back(CursorSlice(*n));
|
||||
return;
|
||||
}
|
||||
|
||||
// otherwise move on one cell back if possible
|
||||
if (top.pos() < lastpos()) {
|
||||
lyxerr << "... next pos" << endl;
|
||||
++top.pos();
|
||||
return;
|
||||
}
|
||||
|
||||
// otherwise move on one cell back if possible
|
||||
if (top.par() < lastpar()) {
|
||||
lyxerr << "... next par" << endl;
|
||||
++top.par();
|
||||
top.pos() = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// otherwise try to move on one cell if possible
|
||||
while (top.idx() < top.lastidx()) {
|
||||
lyxerr << "... next idx"
|
||||
<< " was: " << top.idx() << " max: " << top.lastidx() << endl;
|
||||
++top.idx();
|
||||
top.par() = 0;
|
||||
top.pos() = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// otherwise leave inset an jump over inset as a whole
|
||||
pop_back();
|
||||
// 'top' is invalid now...
|
||||
if (size())
|
||||
++back().pos();
|
||||
}
|
||||
|
||||
|
||||
std::ostream & operator<<(std::ostream & os, DocumentIterator const & dit)
|
||||
{
|
||||
for (size_t i = 0, n = dit.size(); i != n; ++i)
|
||||
|
@ -1,3 +1,8 @@
|
||||
2004-03-28 Alfredo Braunstein <abraunst@lyx.org>
|
||||
|
||||
* ControlDocument.C:
|
||||
* ControlErrorList.C: adjust to ParIterator change
|
||||
|
||||
2004-03-28 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* ControlPrint.[Ch]: converted to the dialog-based scheme.
|
||||
|
@ -20,14 +20,15 @@
|
||||
#include "BufferView.h"
|
||||
#include "CutAndPaste.h"
|
||||
#include "errorlist.h"
|
||||
#include "funcrequest.h"
|
||||
#include "gettext.h"
|
||||
#include "iterators.h"
|
||||
#include "language.h"
|
||||
#include "LColor.h"
|
||||
#include "lyxtextclasslist.h"
|
||||
#include "paragraph.h"
|
||||
#include "funcrequest.h"
|
||||
#include "lfuns.h"
|
||||
#include "paragraph.h"
|
||||
#include "ParagraphList_fwd.h"
|
||||
#include "pariterator.h"
|
||||
|
||||
#include "frontends/Alert.h"
|
||||
#include "frontends/LyXView.h"
|
||||
|
@ -14,9 +14,9 @@
|
||||
#include "buffer.h"
|
||||
#include "BufferView.h"
|
||||
#include "debug.h"
|
||||
#include "iterators.h"
|
||||
#include "lyxtext.h"
|
||||
#include "paragraph.h"
|
||||
#include "pariterator.h"
|
||||
|
||||
using std::endl;
|
||||
using std::string;
|
||||
|
@ -1,4 +1,14 @@
|
||||
|
||||
2004-03-28 Alfredo Braunstein <abraunst@lyx.org>
|
||||
|
||||
* insettext.[Ch]: add a default ctor. implement const version of
|
||||
paragraphs()
|
||||
* insetcharstyle.C:
|
||||
* insetert.C:
|
||||
* insetfloat.C:
|
||||
* insetlabel.C:
|
||||
* insetwrap.C: adjust
|
||||
|
||||
2004-03-28 Alfredo Braunstein <abraunst@lyx.org>
|
||||
|
||||
* insettext.h: add insetAllowed returning true by default (fixing
|
||||
|
@ -166,8 +166,8 @@ namespace {
|
||||
int outputVerbatim(std::ostream & os, InsetText const & inset)
|
||||
{
|
||||
int lines = 0;
|
||||
ParagraphList::iterator par = inset.paragraphs().begin();
|
||||
ParagraphList::iterator end = inset.paragraphs().end();
|
||||
ParagraphList::const_iterator par = inset.paragraphs().begin();
|
||||
ParagraphList::const_iterator end = inset.paragraphs().end();
|
||||
while (par != end) {
|
||||
lyx::pos_type siz = par->size();
|
||||
for (lyx::pos_type i = 0; i < siz; ++i) {
|
||||
|
@ -116,8 +116,8 @@ string const InsetERT::editMessage() const
|
||||
int InsetERT::latex(Buffer const &, ostream & os,
|
||||
OutputParams const &) const
|
||||
{
|
||||
ParagraphList::iterator par = paragraphs().begin();
|
||||
ParagraphList::iterator end = paragraphs().end();
|
||||
ParagraphList::const_iterator par = paragraphs().begin();
|
||||
ParagraphList::const_iterator end = paragraphs().end();
|
||||
|
||||
int lines = 0;
|
||||
while (par != end) {
|
||||
@ -155,8 +155,8 @@ int InsetERT::plaintext(Buffer const &, ostream &,
|
||||
int InsetERT::linuxdoc(Buffer const &, ostream & os,
|
||||
OutputParams const &) const
|
||||
{
|
||||
ParagraphList::iterator par = paragraphs().begin();
|
||||
ParagraphList::iterator end = paragraphs().end();
|
||||
ParagraphList::const_iterator par = paragraphs().begin();
|
||||
ParagraphList::const_iterator end = paragraphs().end();
|
||||
|
||||
int lines = 0;
|
||||
while (par != end) {
|
||||
@ -183,8 +183,8 @@ int InsetERT::linuxdoc(Buffer const &, ostream & os,
|
||||
int InsetERT::docbook(Buffer const &, ostream & os,
|
||||
OutputParams const &) const
|
||||
{
|
||||
ParagraphList::iterator par = paragraphs().begin();
|
||||
ParagraphList::iterator end = paragraphs().end();
|
||||
ParagraphList::const_iterator par = paragraphs().begin();
|
||||
ParagraphList::const_iterator end = paragraphs().end();
|
||||
|
||||
int lines = 0;
|
||||
while (par != end) {
|
||||
|
@ -23,12 +23,12 @@
|
||||
#include "FloatList.h"
|
||||
#include "funcrequest.h"
|
||||
#include "gettext.h"
|
||||
#include "iterators.h"
|
||||
#include "LaTeXFeatures.h"
|
||||
#include "LColor.h"
|
||||
#include "lyxlex.h"
|
||||
#include "outputparams.h"
|
||||
#include "paragraph.h"
|
||||
#include "pariterator.h"
|
||||
|
||||
#include "support/lstrings.h"
|
||||
#include "support/tostr.h"
|
||||
@ -379,8 +379,8 @@ void InsetFloat::wide(bool w, BufferParams const & bp)
|
||||
|
||||
void InsetFloat::addToToc(lyx::toc::TocList & toclist, Buffer const & buf) const
|
||||
{
|
||||
ParIterator pit(0, paragraphs());
|
||||
ParIterator end(paragraphs().size(), paragraphs());
|
||||
ParConstIterator pit(*this, 0);
|
||||
ParConstIterator end = ParConstIterator(DocumentIterator());
|
||||
|
||||
// Find a caption layout in one of the (child inset's) pars
|
||||
for (; pit != end; ++pit) {
|
||||
|
@ -17,9 +17,9 @@
|
||||
#include "dispatchresult.h"
|
||||
#include "funcrequest.h"
|
||||
#include "InsetList.h"
|
||||
#include "iterators.h"
|
||||
#include "lyxtext.h"
|
||||
#include "paragraph.h"
|
||||
#include "pariterator.h"
|
||||
|
||||
#include "frontends/LyXView.h"
|
||||
|
||||
|
@ -88,6 +88,10 @@ InsetText::InsetText(InsetText const & in)
|
||||
}
|
||||
|
||||
|
||||
InsetText::InsetText() : text_(0)
|
||||
{}
|
||||
|
||||
|
||||
void InsetText::operator=(InsetText const & in)
|
||||
{
|
||||
UpdatableInset::operator=(in);
|
||||
@ -514,7 +518,13 @@ void InsetText::addPreview(PreviewLoader & loader) const
|
||||
}
|
||||
|
||||
|
||||
ParagraphList & InsetText::paragraphs() const
|
||||
ParagraphList const & InsetText::paragraphs() const
|
||||
{
|
||||
return const_cast<ParagraphList &>(text_.paragraphs());
|
||||
return text_.paragraphs();
|
||||
}
|
||||
|
||||
|
||||
ParagraphList & InsetText::paragraphs()
|
||||
{
|
||||
return text_.paragraphs();
|
||||
}
|
||||
|
@ -50,6 +50,8 @@ public:
|
||||
///
|
||||
explicit InsetText(BufferParams const &);
|
||||
///
|
||||
explicit InsetText();
|
||||
///
|
||||
InsetText(InsetText const &);
|
||||
///
|
||||
virtual std::auto_ptr<InsetBase> clone() const;
|
||||
@ -141,7 +143,9 @@ public:
|
||||
/// number of cells in this inset
|
||||
size_t nargs() const { return 1; }
|
||||
///
|
||||
ParagraphList & paragraphs() const;
|
||||
ParagraphList & paragraphs();
|
||||
///
|
||||
ParagraphList const & paragraphs() const;
|
||||
///
|
||||
bool insetAllowed(Code) const { return true; }
|
||||
|
||||
|
@ -223,8 +223,8 @@ bool InsetWrap::showInsetDialog(BufferView * bv) const
|
||||
void InsetWrap::addToToc(lyx::toc::TocList & toclist, Buffer const & buf) const
|
||||
{
|
||||
// Now find the caption in the float...
|
||||
ParagraphList::iterator tmp = paragraphs().begin();
|
||||
ParagraphList::iterator end = paragraphs().end();
|
||||
ParagraphList::const_iterator tmp = paragraphs().begin();
|
||||
ParagraphList::const_iterator end = paragraphs().end();
|
||||
|
||||
for (; tmp != end; ++tmp) {
|
||||
if (tmp->layout()->name() == caplayout) {
|
||||
|
350
src/iterators.C
350
src/iterators.C
@ -1,350 +0,0 @@
|
||||
/* \file iterators.C
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author unknown
|
||||
* \author Lars Gullik Bjønnes
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "iterators.h"
|
||||
#include "paragraph.h"
|
||||
#include "cursor.h"
|
||||
#include "buffer.h"
|
||||
#include "BufferView.h"
|
||||
#include "dispatchresult.h"
|
||||
|
||||
#include "insets/inset.h"
|
||||
#include "insets/updatableinset.h"
|
||||
#include "insets/insettext.h"
|
||||
|
||||
#include <boost/next_prior.hpp>
|
||||
|
||||
using lyx::par_type;
|
||||
|
||||
using boost::next;
|
||||
|
||||
///
|
||||
/// ParPosition
|
||||
///
|
||||
|
||||
|
||||
ParPosition::ParPosition(par_type p, ParagraphList const & pl)
|
||||
: pit(p), plist(&pl)
|
||||
{
|
||||
if (p != par_type(pl.size()))
|
||||
it.reset(const_cast<InsetList&>(pl[p].insetlist).begin());
|
||||
}
|
||||
|
||||
|
||||
bool operator==(ParPosition const & pos1, ParPosition const & pos2)
|
||||
{
|
||||
return pos1.pit == pos2.pit;
|
||||
}
|
||||
|
||||
|
||||
bool operator!=(ParPosition const & pos1, ParPosition const & pos2)
|
||||
{
|
||||
return !(pos1 == pos2);
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// ParIterator
|
||||
///
|
||||
|
||||
ParIterator::ParIterator(par_type pit, ParagraphList const & pl)
|
||||
{
|
||||
positions_.push_back(ParPosition(pit, pl));
|
||||
}
|
||||
|
||||
|
||||
ParIterator::~ParIterator()
|
||||
{}
|
||||
|
||||
|
||||
ParIterator::ParIterator(ParIterator const & pi)
|
||||
: positions_(pi.positions_)
|
||||
{}
|
||||
|
||||
|
||||
void ParIterator::operator=(ParIterator const & pi)
|
||||
{
|
||||
ParIterator tmp(pi);
|
||||
swap(positions_, tmp.positions_);
|
||||
}
|
||||
|
||||
|
||||
ParIterator & ParIterator::operator++()
|
||||
{
|
||||
while (!positions_.empty()) {
|
||||
ParPosition & p = positions_.back();
|
||||
|
||||
// Does the current inset contain more "cells" ?
|
||||
if (p.index) {
|
||||
++(*p.index);
|
||||
if (LyXText * text = (*p.it)->inset->getText(*p.index)) {
|
||||
ParagraphList & plist = text->paragraphs();
|
||||
if (!plist.empty()) {
|
||||
positions_.push_back(ParPosition(0, plist));
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
++(*p.it);
|
||||
} else {
|
||||
// The following line is needed because the value of
|
||||
// p.it may be invalid if inset was added/removed to
|
||||
// the paragraph pointed by the iterator
|
||||
p.it.reset(const_cast<InsetList&>((*p.plist)[p.pit].insetlist).begin());
|
||||
}
|
||||
|
||||
// Try to find the next inset that contains paragraphs
|
||||
InsetList::iterator end =
|
||||
const_cast<InsetList&>((*p.plist)[p.pit].insetlist).end();
|
||||
for (; *p.it != end; ++(*p.it)) {
|
||||
if (LyXText * text = (*p.it)->inset->getText(0)) {
|
||||
ParagraphList & plist = text->paragraphs();
|
||||
if (!plist.empty()) {
|
||||
p.index.reset(0);
|
||||
positions_.push_back(ParPosition(0, plist));
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Try to go to the next paragarph
|
||||
if (p.pit + 1 != par_type(p.plist->size()) ||
|
||||
positions_.size() == 1) {
|
||||
++p.pit;
|
||||
p.index.reset();
|
||||
p.it.reset();
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Drop end and move up in the stack.
|
||||
positions_.pop_back();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
LyXText * ParIterator::text(Buffer & buf) const
|
||||
{
|
||||
//lyxerr << "positions.size: " << positions.size() << std::endl;
|
||||
if (positions_.size() <= 1)
|
||||
return &buf.text();
|
||||
|
||||
ParPosition const & pos = positions_[positions_.size() - 2];
|
||||
return (*pos.it)->inset->getText(*pos.index);
|
||||
}
|
||||
|
||||
|
||||
InsetBase * ParIterator::inset() const
|
||||
{
|
||||
//lyxerr << "positions.size: " << positions.size() << std::endl;
|
||||
if (positions_.size() <= 1)
|
||||
return 0;
|
||||
|
||||
ParPosition const & pos = positions_[positions_.size() - 2];
|
||||
return (*pos.it)->inset;
|
||||
}
|
||||
|
||||
|
||||
int ParIterator::index() const
|
||||
{
|
||||
if (positions_.size() <= 1)
|
||||
return 0;
|
||||
|
||||
return *(positions_[positions_.size() - 2].index);
|
||||
}
|
||||
|
||||
|
||||
Paragraph & ParIterator::operator*() const
|
||||
{
|
||||
return plist()[positions_.back().pit];
|
||||
}
|
||||
|
||||
|
||||
par_type ParIterator::pit() const
|
||||
{
|
||||
return positions_.back().pit;
|
||||
}
|
||||
|
||||
|
||||
Paragraph * ParIterator::operator->() const
|
||||
{
|
||||
return &plist()[positions_.back().pit];
|
||||
}
|
||||
|
||||
|
||||
par_type ParIterator::outerPar() const
|
||||
{
|
||||
return positions_[0].pit;
|
||||
}
|
||||
|
||||
|
||||
size_t ParIterator::size() const
|
||||
{
|
||||
return positions_.size();
|
||||
}
|
||||
|
||||
|
||||
ParagraphList & ParIterator::plist() const
|
||||
{
|
||||
return *const_cast<ParagraphList*>(positions_.back().plist);
|
||||
}
|
||||
|
||||
|
||||
ParIterator::ParIterator(DocumentIterator const & cur)
|
||||
{
|
||||
int const size = cur.size();
|
||||
|
||||
for (int i = 0; i < size; ++i) {
|
||||
CursorSlice sl = cur[i];
|
||||
ParPosition pp(sl.par(), sl.text()->paragraphs());
|
||||
if (i < size - 1) {
|
||||
Paragraph & par = sl.text()->paragraphs()[sl.par()];
|
||||
InsetBase * inset = par.getInset(sl.pos());
|
||||
BOOST_ASSERT(inset);
|
||||
InsetList::iterator beg = par.insetlist.begin();
|
||||
InsetList::iterator end = par.insetlist.end();
|
||||
for ( ; beg != end && beg->inset != inset; ++beg)
|
||||
;
|
||||
pp.it.reset(beg);
|
||||
pp.index.reset(sl.idx() - 1);
|
||||
}
|
||||
positions_.push_back(pp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool operator==(ParIterator const & iter1, ParIterator const & iter2)
|
||||
{
|
||||
return iter1.positions() == iter2.positions();
|
||||
}
|
||||
|
||||
|
||||
bool operator!=(ParIterator const & iter1, ParIterator const & iter2)
|
||||
{
|
||||
return !(iter1 == iter2);
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// ParConstIterator
|
||||
///
|
||||
|
||||
|
||||
ParConstIterator::ParConstIterator(par_type pit, ParagraphList const & pl)
|
||||
{
|
||||
positions_.push_back(ParPosition(pit, pl));
|
||||
}
|
||||
|
||||
|
||||
ParConstIterator::~ParConstIterator()
|
||||
{}
|
||||
|
||||
|
||||
ParConstIterator::ParConstIterator(ParConstIterator const & pi)
|
||||
: positions_(pi.positions_)
|
||||
{}
|
||||
|
||||
|
||||
ParConstIterator & ParConstIterator::operator++()
|
||||
{
|
||||
while (!positions_.empty()) {
|
||||
ParPosition & p = positions_.back();
|
||||
|
||||
// Does the current inset contain more "cells" ?
|
||||
if (p.index) {
|
||||
++(*p.index);
|
||||
if (LyXText * text = (*p.it)->inset->getText(*p.index)) {
|
||||
ParagraphList & plist = text->paragraphs();
|
||||
if (!plist.empty()) {
|
||||
positions_.push_back(ParPosition(0, plist));
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
++(*p.it);
|
||||
} else {
|
||||
// The following line is needed because the value of
|
||||
// p.it may be invalid if inset was added/removed to
|
||||
// the paragraph pointed by the iterator
|
||||
p.it.reset(const_cast<InsetList&>((*p.plist)[p.pit].insetlist).begin());
|
||||
}
|
||||
|
||||
// Try to find the next inset that contains paragraphs
|
||||
InsetList::iterator end =
|
||||
const_cast<InsetList&>((*p.plist)[p.pit].insetlist).end();
|
||||
for (; *p.it != end; ++(*p.it)) {
|
||||
if (LyXText * text = (*p.it)->inset->getText(0)) {
|
||||
ParagraphList & plist = text->paragraphs();
|
||||
if (!plist.empty()) {
|
||||
p.index.reset(0);
|
||||
positions_.push_back(ParPosition(0, plist));
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Try to go to the next paragarph
|
||||
if (p.pit + 1 != par_type(p.plist->size()) ||
|
||||
positions_.size() == 1) {
|
||||
++p.pit;
|
||||
p.index.reset();
|
||||
p.it.reset();
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Drop end and move up in the stack.
|
||||
positions_.pop_back();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Paragraph const & ParConstIterator::operator*() const
|
||||
{
|
||||
return plist()[positions_.back().pit];
|
||||
}
|
||||
|
||||
|
||||
par_type ParConstIterator::pit() const
|
||||
{
|
||||
return positions_.back().pit;
|
||||
}
|
||||
|
||||
|
||||
Paragraph const * ParConstIterator::operator->() const
|
||||
{
|
||||
return &plist()[positions_.back().pit];
|
||||
}
|
||||
|
||||
|
||||
ParagraphList const & ParConstIterator::plist() const
|
||||
{
|
||||
return *positions_.back().plist;
|
||||
}
|
||||
|
||||
|
||||
size_t ParConstIterator::size() const
|
||||
{
|
||||
return positions_.size();
|
||||
}
|
||||
|
||||
|
||||
bool operator==(ParConstIterator const & iter1, ParConstIterator const & iter2)
|
||||
{
|
||||
return iter1.positions() == iter2.positions();
|
||||
}
|
||||
|
||||
|
||||
bool operator!=(ParConstIterator const & iter1, ParConstIterator const & iter2)
|
||||
{
|
||||
return !(iter1 == iter2);
|
||||
}
|
@ -20,11 +20,11 @@
|
||||
#include "CutAndPaste.h"
|
||||
#include "BufferView.h"
|
||||
#include "debug.h"
|
||||
#include "iterators.h"
|
||||
#include "funcrequest.h"
|
||||
#include "gettext.h"
|
||||
#include "lyxtext.h"
|
||||
#include "paragraph.h"
|
||||
#include "pariterator.h"
|
||||
#include "undo.h"
|
||||
|
||||
#include "frontends/Alert.h"
|
||||
|
@ -37,7 +37,6 @@
|
||||
#include "gettext.h"
|
||||
#include "importer.h"
|
||||
#include "intl.h"
|
||||
#include "iterators.h"
|
||||
#include "kbmap.h"
|
||||
#include "LColor.h"
|
||||
#include "lyx_cb.h"
|
||||
@ -48,6 +47,7 @@
|
||||
#include "lyxserver.h"
|
||||
#include "lyxvc.h"
|
||||
#include "paragraph.h"
|
||||
#include "pariterator.h"
|
||||
#include "ParagraphParameters.h"
|
||||
#include "undo.h"
|
||||
|
||||
|
@ -18,11 +18,11 @@
|
||||
#include "debug.h"
|
||||
#include "encoding.h"
|
||||
#include "gettext.h"
|
||||
#include "iterators.h"
|
||||
#include "language.h"
|
||||
#include "lyxtext.h"
|
||||
#include "outputparams.h"
|
||||
#include "paragraph_pimpl.h"
|
||||
#include "pariterator.h"
|
||||
#include "sgml.h"
|
||||
#include "texrow.h"
|
||||
#include "vspace.h"
|
||||
|
163
src/pariterator.C
Normal file
163
src/pariterator.C
Normal file
@ -0,0 +1,163 @@
|
||||
/* \file iterators.C
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author unknown
|
||||
* \author Lars Gullik Bjønnes
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
|
||||
#include "pariterator.h"
|
||||
|
||||
#include "ParagraphList_fwd.h"
|
||||
#include "paragraph.h"
|
||||
#include "lyxtext.h"
|
||||
|
||||
#include "insets/inset.h"
|
||||
|
||||
using lyx::par_type;
|
||||
|
||||
///
|
||||
/// ParIterator
|
||||
///
|
||||
|
||||
ParIterator::ParIterator(DocumentIterator const & cur) : DocumentIterator(cur)
|
||||
{}
|
||||
|
||||
|
||||
ParIterator::ParIterator(InsetBase & in, par_type pit) : DocumentIterator(in)
|
||||
{
|
||||
par() = pit;
|
||||
}
|
||||
|
||||
|
||||
ParIterator::ParIterator(ParIterator const & pi)
|
||||
: DocumentIterator(DocumentIterator(pi))
|
||||
{}
|
||||
|
||||
|
||||
ParIterator & ParIterator::operator++()
|
||||
{
|
||||
forwardPar();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
ParIterator & ParIterator::operator--()
|
||||
{
|
||||
// DocumentIterator::backwardPar();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Paragraph & ParIterator::operator*() const
|
||||
{
|
||||
return text()->getPar(par());
|
||||
}
|
||||
|
||||
|
||||
par_type ParIterator::pit() const
|
||||
{
|
||||
return par();
|
||||
}
|
||||
|
||||
|
||||
Paragraph * ParIterator::operator->() const
|
||||
{
|
||||
return &text()->getPar(par());
|
||||
}
|
||||
|
||||
|
||||
par_type ParIterator::outerPar() const
|
||||
{
|
||||
return bottom().par();
|
||||
}
|
||||
|
||||
|
||||
ParagraphList & ParIterator::plist() const
|
||||
{
|
||||
return text()->paragraphs();
|
||||
}
|
||||
|
||||
|
||||
bool operator==(ParIterator const & iter1, ParIterator const & iter2)
|
||||
{
|
||||
return DocumentIterator(iter1) == DocumentIterator(iter2);
|
||||
}
|
||||
|
||||
|
||||
bool operator!=(ParIterator const & iter1, ParIterator const & iter2)
|
||||
{
|
||||
return !(iter1 == iter2);
|
||||
}
|
||||
|
||||
DocumentIterator
|
||||
makeDocumentIterator(ParIterator const & par, lyx::pos_type pos)
|
||||
{
|
||||
DocumentIterator dit(par);
|
||||
dit.pos() = pos;
|
||||
return dit;
|
||||
}
|
||||
|
||||
///
|
||||
/// ParConstIterator
|
||||
///
|
||||
|
||||
|
||||
ParConstIterator::ParConstIterator(InsetBase const & in, par_type pit)
|
||||
: DocumentIterator(const_cast<InsetBase &>(in))
|
||||
{
|
||||
par() = pit;
|
||||
}
|
||||
|
||||
|
||||
ParConstIterator::ParConstIterator(DocumentIterator const & dit)
|
||||
: DocumentIterator(dit)
|
||||
{}
|
||||
|
||||
|
||||
ParConstIterator::ParConstIterator(ParConstIterator const & pi)
|
||||
: DocumentIterator(DocumentIterator(pi))
|
||||
{}
|
||||
|
||||
|
||||
ParConstIterator & ParConstIterator::operator++()
|
||||
{
|
||||
DocumentIterator::forwardPar();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Paragraph const & ParConstIterator::operator*() const
|
||||
{
|
||||
return text()->getPar(par());
|
||||
}
|
||||
|
||||
|
||||
Paragraph const * ParConstIterator::operator->() const
|
||||
{
|
||||
return &text()->getPar(par());
|
||||
}
|
||||
|
||||
|
||||
ParagraphList const & ParConstIterator::plist() const
|
||||
{
|
||||
return text()->paragraphs();
|
||||
}
|
||||
|
||||
|
||||
bool operator==(ParConstIterator const & iter1, ParConstIterator const & iter2)
|
||||
{
|
||||
return DocumentIterator(iter1) == DocumentIterator(iter2);
|
||||
}
|
||||
|
||||
|
||||
bool operator!=(ParConstIterator const & iter1, ParConstIterator const & iter2)
|
||||
{
|
||||
return !(iter1 == iter2);
|
||||
}
|
@ -12,8 +12,7 @@
|
||||
#ifndef ITERATORS_H
|
||||
#define ITERATORS_H
|
||||
|
||||
#include "InsetList.h"
|
||||
#include "ParagraphList_fwd.h" // only for ParagraphList::value_type
|
||||
#include "dociterator.h"
|
||||
|
||||
#include "support/types.h"
|
||||
|
||||
@ -21,45 +20,31 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
class Buffer;
|
||||
class Cursor;
|
||||
|
||||
|
||||
class InsetBase;
|
||||
class LyXText;
|
||||
class DocumentIterator;
|
||||
class ParagraphList;
|
||||
|
||||
|
||||
class ParPosition {
|
||||
class ParIterator : public std::iterator<std::forward_iterator_tag, Paragraph>,
|
||||
public DocumentIterator
|
||||
{
|
||||
public:
|
||||
///
|
||||
ParPosition(lyx::par_type p, ParagraphList const & pl);
|
||||
///
|
||||
lyx::par_type pit;
|
||||
///
|
||||
ParagraphList const * plist;
|
||||
///
|
||||
boost::optional<InsetList::iterator> it;
|
||||
///
|
||||
boost::optional<int> index;
|
||||
};
|
||||
|
||||
|
||||
class ParIterator : public std::iterator<
|
||||
std::forward_iterator_tag,
|
||||
ParagraphList::value_type> {
|
||||
public:
|
||||
///
|
||||
ParIterator(lyx::par_type pit, ParagraphList const & pl);
|
||||
///
|
||||
~ParIterator();
|
||||
ParIterator(InsetBase &, lyx::par_type pit);
|
||||
///
|
||||
ParIterator(ParIterator const &);
|
||||
///
|
||||
ParIterator(DocumentIterator const &);
|
||||
|
||||
///
|
||||
void operator=(ParIterator const &);
|
||||
///
|
||||
ParIterator & operator++();
|
||||
///
|
||||
ParIterator & operator--();
|
||||
///
|
||||
Paragraph & operator*() const;
|
||||
///
|
||||
Paragraph * operator->() const;
|
||||
@ -69,24 +54,14 @@ public:
|
||||
lyx::par_type pit() const;
|
||||
///
|
||||
ParagraphList & plist() const;
|
||||
/// returns 'innermost' LyXText
|
||||
LyXText * text(Buffer &) const;
|
||||
/// returns innermost inset
|
||||
InsetBase * inset() const;
|
||||
/// returns index of cell in innermost inset
|
||||
int index() const;
|
||||
///
|
||||
size_t size() const;
|
||||
|
||||
typedef std::vector<ParPosition> PosHolder;
|
||||
PosHolder const & positions() const
|
||||
{
|
||||
return positions_;
|
||||
}
|
||||
private:
|
||||
PosHolder positions_;
|
||||
};
|
||||
|
||||
|
||||
DocumentIterator makeDocumentIterator(ParIterator const &, lyx::pos_type);
|
||||
|
||||
|
||||
|
||||
|
||||
///
|
||||
bool operator==(ParIterator const & iter1, ParIterator const & iter2);
|
||||
|
||||
@ -94,37 +69,28 @@ bool operator==(ParIterator const & iter1, ParIterator const & iter2);
|
||||
bool operator!=(ParIterator const & iter1, ParIterator const & iter2);
|
||||
|
||||
|
||||
class ParConstIterator : public std::iterator<
|
||||
std::forward_iterator_tag,
|
||||
ParagraphList::value_type> {
|
||||
class ParConstIterator : public std::iterator<std::forward_iterator_tag,
|
||||
Paragraph>,
|
||||
public DocumentIterator
|
||||
{
|
||||
public:
|
||||
///
|
||||
ParConstIterator(lyx::par_type pit, ParagraphList const & pl);
|
||||
///
|
||||
~ParConstIterator();
|
||||
ParConstIterator(InsetBase const &, lyx::par_type pit);
|
||||
///
|
||||
ParConstIterator(ParConstIterator const &);
|
||||
///
|
||||
ParConstIterator(DocumentIterator const &);
|
||||
///
|
||||
|
||||
ParConstIterator & operator++();
|
||||
///
|
||||
lyx::par_type pit() const;
|
||||
ParConstIterator & operator--();
|
||||
///
|
||||
Paragraph const & operator*() const;
|
||||
///
|
||||
Paragraph const * operator->() const;
|
||||
///
|
||||
ParagraphList const & plist() const;
|
||||
|
||||
/// depth of nesting
|
||||
size_t size() const;
|
||||
///
|
||||
typedef std::vector<ParPosition> PosHolder;
|
||||
///
|
||||
PosHolder const & positions() const { return positions_; }
|
||||
|
||||
private:
|
||||
///
|
||||
PosHolder positions_;
|
||||
};
|
||||
|
||||
bool operator==(ParConstIterator const & iter1,
|
Loading…
Reference in New Issue
Block a user