}
-/* This is also a buffer property (ale) */
+// This is also a buffer property (ale)
// Not so sure about that. a goto Label function can not be buffer local, just
-// think how this will work in a multiwindo/buffer environment, all the
+// think how this will work in a multiwindow/buffer environment, all the
// cursors in all the views showing this buffer will move. (Lgb)
// OK, then no cursor action should be allowed in buffer. (ale)
bool BufferView::gotoLabel(string const & label)
-
{
for (Buffer::inset_iterator it = buffer()->inset_iterator_begin();
it != buffer()->inset_iterator_end(); ++it) {
- vector<string> labels = (*it)->getLabelList();
+ vector<string> labels = it->getLabelList();
if (find(labels.begin(),labels.end(),label)
!= labels.end()) {
beforeChange(text);
Inset * BufferView::Pimpl::getInsetByCode(Inset::Code code)
{
+#if 0
LyXCursor cursor = bv_->getLyXText()->cursor;
Buffer::inset_iterator it =
find_if(Buffer::inset_iterator(
buffer_->inset_iterator_end(),
lyx::compare_memfun(&Inset::lyxCode, code));
return it != buffer_->inset_iterator_end() ? (*it) : 0;
+#else
+ // Ok, this is a little bit too brute force but it
+ // should work for now. Better infrastructure is comming. (Lgb)
+
+ Buffer * b = bv_->buffer();
+ LyXCursor cursor = bv_->getLyXText()->cursor;
+
+ Buffer::inset_iterator beg = b->inset_iterator_begin();
+ Buffer::inset_iterator end = b->inset_iterator_end();
+
+ bool cursor_par_seen = false;
+
+ for (; beg != end; ++beg) {
+ if (beg.getPar() == cursor.par()) {
+ cursor_par_seen = true;
+ }
+ if (cursor_par_seen) {
+ if (beg.getPar() == cursor.par()
+ && beg.getPos() >= cursor.pos()) {
+ break;
+ } else if (beg.getPar() != cursor.par()) {
+ break;
+ }
+ }
+
+ }
+ if (beg != end) {
+ // Now find the first inset that matches code.
+ for (; beg != end; ++beg) {
+ if (beg->lyxCode() == code) {
+ return &(*beg);
+ }
+ }
+ }
+ return 0;
+#endif
}
+
+2002-08-20 André Pönitz <poenitz@gmx.net>
+
+ * buffer.[Ch]: move inline functions to .C
+
+ * BufferView2.C:
+ * BufferView_pimpl.C:
+ * text.C:
+ * buffer.[Ch]: use improved inset_iterator
+
2002-08-20 Dekel Tsur <dekelts@tau.ac.il>
* BufferView_pimpl.C (dispatch): Insert insetbibtex with "plain"
}
-string const Buffer::asciiParagraph(Paragraph const * par,
+string const Buffer::asciiParagraph(Paragraph const & par,
unsigned int linelen,
bool noparbreak) const
{
}
}
#else
- depth = par->params().depth();
+ depth = par.params().depth();
#endif
// First write the layout
- string const & tmp = par->layout()->name();
+ string const & tmp = par.layout()->name();
if (compare_no_case(tmp, "itemize") == 0) {
ltype = 1;
ltype_depth = depth + 1;
// lyxerr << "Should this ever happen?" << endl;
// }
- // linelen <= 0 is special and means we don't have pargraph breaks
+ // linelen <= 0 is special and means we don't have paragraph breaks
string::size_type currlinelen = 0;
break;
default:
{
- string const parlab = par->params().labelString();
+ string const parlab = par.params().labelString();
buffer << parlab << " ";
currlinelen += parlab.length() + 1;
}
string word;
- for (pos_type i = 0; i < par->size(); ++i) {
- char c = par->getUChar(params, i);
+ for (pos_type i = 0; i < par.size(); ++i) {
+ char c = par.getUChar(params, i);
switch (c) {
case Paragraph::META_INSET:
{
- Inset const * inset = par->getInset(i);
+ Inset const * inset = par.getInset(i);
if (inset) {
if (linelen > 0) {
buffer << word;
}
-void Buffer::writeFileAscii(ostream & ofs, int linelen)
+void Buffer::writeFileAscii(ostream & os, int linelen)
{
ParagraphList::iterator beg = paragraphs.begin();
ParagraphList::iterator end = paragraphs.end();
ParagraphList::iterator it = beg;
for (; it != end; ++it) {
- ofs << asciiParagraph(&*it, linelen, it == beg);
+ os << asciiParagraph(*it, linelen, it == beg);
}
- ofs << "\n";
+ os << "\n";
}
while (par != endpar) {
Inset * in = par->inInset();
// well we have to check if we are in an inset with unlimited
- // lenght (all in one row) if that is true then we don't allow
+ // length (all in one row) if that is true then we don't allow
// any special options in the paragraph and also we don't allow
// any environment other then "Standard" to be valid!
if ((in == 0) || !in->forceDefaultParagraphs(in)) {
string lst;
for (inset_iterator it = inset_iterator_begin();
it != inset_iterator_end(); ++it) {
- if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
- InsetInclude * insetinc =
- static_cast<InsetInclude *>(*it);
- if (insetinc->isIncludeOnly()) {
+ if (it->lyxCode() == Inset::INCLUDE_CODE) {
+ InsetInclude & inc = static_cast<InsetInclude &>(*it);
+ if (inc.isIncludeOnly()) {
if (!lst.empty())
lst += delim;
- lst += insetinc->getRelFileBaseName();
+ lst += inc.getRelFileBaseName();
}
}
}
vector<string> label_list;
for (inset_iterator it = inset_const_iterator_begin();
it != inset_const_iterator_end(); ++it) {
- vector<string> const l = (*it)->getLabelList();
+ vector<string> const l = it->getLabelList();
label_list.insert(label_list.end(), l.begin(), l.end());
}
return label_list;
for (inset_iterator it = inset_const_iterator_begin();
it != inset_const_iterator_end(); ++it) {
// Search for Bibtex or Include inset
- if ((*it)->lyxCode() == Inset::BIBTEX_CODE) {
+ if (it->lyxCode() == Inset::BIBTEX_CODE) {
vector<StringPair> tmp =
- static_cast<InsetBibtex*>(*it)->getKeys(this);
+ static_cast<InsetBibtex &>(*it).getKeys(this);
keys.insert(keys.end(), tmp.begin(), tmp.end());
- } else if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
+ } else if (it->lyxCode() == Inset::INCLUDE_CODE) {
vector<StringPair> const tmp =
- static_cast<InsetInclude*>(*it)->getKeys();
+ static_cast<InsetInclude &>(*it).getKeys();
keys.insert(keys.end(), tmp.begin(), tmp.end());
}
}
}
-Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
- : par(paragraph)
-{
- it = par->insetlist.insetIterator(pos);
- if (it == par->insetlist.end()) {
- par = par->next();
- setParagraph();
- }
-}
-
-
void Buffer::inset_iterator::setParagraph()
{
- while (par) {
- it = par->insetlist.begin();
- if (it != par->insetlist.end())
+ while (pit != pend) {
+ it = pit->insetlist.begin();
+ if (it != pit->insetlist.end())
return;
- par = par->next();
+ ++pit;
}
- //it = 0;
- // We maintain an invariant that whenever par = 0 then it = 0
}
for (inset_iterator it = inset_const_iterator_begin();
it != inset_const_iterator_end(); ++it)
{
- if ((*it)->id() == id_arg)
- return *it;
- Inset * in = (*it)->getInsetFromID(id_arg);
+ if (it->id() == id_arg)
+ return &(*it);
+ Inset * in = it->getInsetFromID(id_arg);
if (in)
return in;
}
{
return ParIterator();
}
+
+
+void Buffer::addUser(BufferView * u)
+{
+ users = u;
+}
+
+
+void Buffer::delUser(BufferView *)
+{
+ users = 0;
+}
+
+
+Language const * Buffer::getLanguage() const
+{
+ return params.language;
+}
+
+
+bool Buffer::isClean() const
+{
+ return lyx_clean;
+}
+
+
+bool Buffer::isBakClean() const
+{
+ return bak_clean;
+}
+
+
+void Buffer::markClean() const
+{
+ if (!lyx_clean) {
+ lyx_clean = true;
+ updateTitles();
+ }
+ // if the .lyx file has been saved, we don't need an
+ // autosave
+ bak_clean = true;
+}
+
+
+void Buffer::markBakClean()
+{
+ bak_clean = true;
+}
+
+
+void Buffer::setUnnamed(bool flag)
+{
+ unnamed = flag;
+}
+
+
+bool Buffer::isUnnamed()
+{
+ return unnamed;
+}
+
+
+void Buffer::markDirty()
+{
+ if (lyx_clean) {
+ lyx_clean = false;
+ updateTitles();
+ }
+ bak_clean = false;
+ DEPCLEAN * tmp = dep_clean;
+ while (tmp) {
+ tmp->clean = false;
+ tmp = tmp->next;
+ }
+}
+
+
+string const & Buffer::fileName() const
+{
+ return filename_;
+}
+
+
+string const & Buffer::filePath() const
+{
+ return filepath_;
+}
+
+
+bool Buffer::isReadonly() const
+{
+ return read_only;
+}
+
+
+BufferView * Buffer::getUser() const
+{
+ return users;
+}
+
+
+void Buffer::setParentName(string const & name)
+{
+ params.parentname = name;
+}
+
+
+Buffer::inset_iterator::inset_iterator()
+ : pit(0), pend(0)
+{}
+
+
+Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
+ : pit(p), pend(e)
+{
+ setParagraph();
+}
+
+
+Buffer::inset_iterator & Buffer::inset_iterator::operator++()
+{
+ if (pit != pend) {
+ ++it;
+ if (it == pit->insetlist.end()) {
+ ++pit;
+ setParagraph();
+ }
+ }
+ return *this;
+}
+
+
+Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
+{
+ inset_iterator tmp = *this;
+ ++*this;
+ return tmp;
+}
+
+
+Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
+{
+ return *it.getInset();
+}
+
+
+Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
+{
+ return it.getInset();
+}
+
+
+Paragraph * Buffer::inset_iterator::getPar()
+{
+ return &(*pit);
+}
+
+
+lyx::pos_type Buffer::inset_iterator::getPos() const
+{
+ return it.getPos();
+}
+
+
+bool operator==(Buffer::inset_iterator const & iter1,
+ Buffer::inset_iterator const & iter2)
+{
+ return iter1.pit == iter2.pit
+ && (iter1.pit == iter1.pend || iter1.it == iter2.it);
+}
+
+
+bool operator!=(Buffer::inset_iterator const & iter1,
+ Buffer::inset_iterator const & iter2)
+{
+ return !(iter1 == iter2);
+}
+
///
void writeFileAscii(std::ostream &, int);
///
- string const asciiParagraph(Paragraph const *, unsigned int linelen,
+ string const asciiParagraph(Paragraph const &, unsigned int linelen,
bool noparbreak = false) const;
/// Just a wrapper for the method below, first creating the ofstream.
void makeLaTeXFile(string const & filename,
typedef ptrdiff_t difference_type;
typedef Inset * pointer;
typedef Inset & reference;
-
-
- ///
- inset_iterator() : par(0) /*, it(0)*/ {}
- //
- inset_iterator(Paragraph * paragraph) : par(paragraph) {
- setParagraph();
- }
- ///
- inset_iterator(Paragraph * paragraph, lyx::pos_type pos);
+ typedef ParagraphList::iterator base_type;
+
+ ///
+ inset_iterator();
+ ///
+ inset_iterator(base_type p, base_type e);
+ ///
+ inset_iterator(base_type p, lyx::pos_type pos, base_type e);
+
+ /// prefix ++
+ inset_iterator & operator++();
+ /// postfix ++
+ inset_iterator operator++(int);
///
- inset_iterator & operator++() { // prefix ++
- if (par) {
- ++it;
- if (it == par->insetlist.end()) {
- par = par->next();
- setParagraph();
- }
- }
- return *this;
- }
+ reference operator*();
///
- inset_iterator operator++(int) { // postfix ++
- inset_iterator tmp(par, it.getPos());
- if (par) {
- ++it;
- if (it == par->insetlist.end()) {
- par = par->next();
- setParagraph();
- }
- }
- return tmp;
- }
+ pointer operator->();
///
- Inset * operator*() { return it.getInset(); }
-
- ///
- Paragraph * getPar() { return par; }
+ Paragraph * getPar();
///
- lyx::pos_type getPos() const { return it.getPos(); }
+ lyx::pos_type getPos() const;
///
friend
bool operator==(inset_iterator const & iter1,
///
void setParagraph();
///
- Paragraph * par;
+ ParagraphList::iterator pit;
+ ///
+ ParagraphList::iterator pend;
///
InsetList::iterator it;
};
///
inset_iterator inset_iterator_begin() {
- return inset_iterator(&*paragraphs.begin());
+ return inset_iterator(paragraphs.begin(), paragraphs.end());
}
+
///
inset_iterator inset_iterator_end() {
return inset_iterator();
}
+
///
inset_iterator inset_const_iterator_begin() const {
- return inset_iterator(&*paragraphs.begin());
+ return inset_iterator(paragraphs.begin(), paragraphs.end());
}
+
///
inset_iterator inset_const_iterator_end() const {
return inset_iterator();
Inset * getInsetFromID(int id_arg) const;
};
-
-inline
-void Buffer::addUser(BufferView * u)
-{
- users = u;
-}
-
-
-inline
-void Buffer::delUser(BufferView *)
-{
- users = 0;
-}
-
-
-inline
-Language const * Buffer::getLanguage() const
-{
- return params.language;
-}
-
-
-inline
-bool Buffer::isClean() const
-{
- return lyx_clean;
-}
-
-
-inline
-bool Buffer::isBakClean() const
-{
- return bak_clean;
-}
-
-
-inline
-void Buffer::markClean() const
-{
- if (!lyx_clean) {
- lyx_clean = true;
- updateTitles();
- }
- // if the .lyx file has been saved, we don't need an
- // autosave
- bak_clean = true;
-}
-
-
-inline
-void Buffer::markBakClean()
-{
- bak_clean = true;
-}
-
-
-inline
-void Buffer::setUnnamed(bool flag)
-{
- unnamed = flag;
-}
-
-
-inline
-bool Buffer::isUnnamed()
-{
- return unnamed;
-}
-
-
-inline
-void Buffer::markDirty()
-{
- if (lyx_clean) {
- lyx_clean = false;
- updateTitles();
- }
- bak_clean = false;
- DEPCLEAN * tmp = dep_clean;
- while (tmp) {
- tmp->clean = false;
- tmp = tmp->next;
- }
-}
-
-
-inline
-string const & Buffer::fileName() const
-{
- return filename_;
-}
-
-
-inline
-string const & Buffer::filePath() const
-{
- return filepath_;
-}
-
-
-inline
-bool Buffer::isReadonly() const
-{
- return read_only;
-}
-
-
-inline
-BufferView * Buffer::getUser() const
-{
- return users;
-}
-
-
-inline
-void Buffer::setParentName(string const & name)
-{
- params.parentname = name;
-}
-
-
-///
-inline
-bool operator==(Buffer::inset_iterator const & iter1,
- Buffer::inset_iterator const & iter2)
-{
- return iter1.par == iter2.par
- && (iter1.par == 0 || iter1.it == iter2.it);
-}
-
-
-///
-inline
-bool operator!=(Buffer::inset_iterator const & iter1,
- Buffer::inset_iterator const & iter2)
-{
- return !(iter1 == iter2);
-}
-
#endif
Buffer::inset_iterator it = buffer_.inset_const_iterator_begin();
Buffer::inset_iterator end = buffer_.inset_const_iterator_end();
- for (; it != end; ++it) {
- if ((*it)->lyxCode() == Inset::MATHMACRO_CODE) {
- (*it)->latex(&buffer_, os, true, true);
- }
- }
+ for (; it != end; ++it)
+ if (it->lyxCode() == Inset::MATHMACRO_CODE)
+ it->latex(&buffer_, os, true, true);
// All equation lables appear as "(#)" + preview.sty's rendering of
// the label name
Buffer::inset_iterator it = buffer.inset_const_iterator_begin();
Buffer::inset_iterator end = buffer.inset_const_iterator_end();
- for (; it != end; ++it) {
- (*it)->addPreview(ploader);
- }
+ for (; it != end; ++it)
+ it->addPreview(ploader);
ploader.startLoading();
}
for (string::size_type i = 0; i < text.length(); ++i) {
if (text[i] == ' ')
w += font_metrics::width('i', font);
- else if (i == 0 || text[i] != text[i-1])
+ else if (i == 0 || text[i] != text[i - 1])
w += font_metrics::width(text[i], font);
else
w += font_metrics::width(',', font);
ParagraphList::iterator end = paragraphs.end();
ParagraphList::iterator it = beg;
for (; it != end; ++it) {
- string const tmp = buf->asciiParagraph(&*it, linelen, it == beg);
+ string const tmp = buf->asciiParagraph(*it, linelen, it == beg);
lines += lyx::count(tmp.begin(), tmp.end(), '\n');
os << tmp;
}
Buffer::inset_iterator it = bview->buffer()->inset_iterator_begin();
Buffer::inset_iterator end = bview->buffer()->inset_iterator_end();
for (; it != end; ++it) {
- if (*it == inset) {
+ if (&(*it) == inset) {
par = it.getPar();
pos = it.getPos();
break;
} else {
// find the next level paragraph
- Paragraph * newpar =
- row->par()->outerHook();
+ Paragraph * newpar = row->par()->outerHook();
// make a corresponding row. Needed to call LeftMargin()