The ParagraphList stuff

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4937 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2002-08-12 00:15:19 +00:00
parent 83f4b0018e
commit 5bd7f9d67b
16 changed files with 361 additions and 128 deletions

View File

@ -522,7 +522,7 @@ bool BufferView::lockInset(UpdatableInset * inset)
} }
} }
// Then do a deep look of the inset and lock the right one // Then do a deep look of the inset and lock the right one
Paragraph * par = buffer()->paragraph; Paragraph * par = &*(buffer()->paragraphs.begin());
int const id = inset->id(); int const id = inset->id();
while (par) { while (par) {
InsetList::iterator it = InsetList::iterator it =

View File

@ -1,3 +1,16 @@
2002-08-12 Lars Gullik Bjønnes <larsbj@gullik.net>
* ParagraphList.[Ch]: new files
* Makefile.am (lyx_SOURCES): add ParagraphList.[Ch]
* BufferView2.C (lockInset): ParagraphList changes
* toc.C: ditto
* text2.C: ditto
* bufferlist.C: ditto
* buffer.h: ditto
* buffer.C: ditto
2002-08-11 Lars Gullik Bjønnes <larsbj@gullik.net> 2002-08-11 Lars Gullik Bjønnes <larsbj@gullik.net>
* paragraph_pimpl.h: remove inclusion of boost/array.hpp, remove * paragraph_pimpl.h: remove inclusion of boost/array.hpp, remove

View File

@ -79,6 +79,8 @@ lyx_SOURCES = \
LyXAction.h \ LyXAction.h \
MenuBackend.C \ MenuBackend.C \
MenuBackend.h \ MenuBackend.h \
ParagraphList.C \
ParagraphList.h \
ParagraphParameters.C \ ParagraphParameters.C \
ParagraphParameters.h \ ParagraphParameters.h \
ParameterStruct.h \ ParameterStruct.h \

144
src/ParagraphList.C Normal file
View File

@ -0,0 +1,144 @@
#include <config.h>
#include "ParagraphList.h"
#include "paragraph.h"
////////// The ParagraphList::iterator
ParagraphList::iterator::iterator()
: ptr(0)
{}
ParagraphList::iterator::iterator(Paragraph * p)
: ptr(p)
{}
ParagraphList::iterator::reference
ParagraphList::iterator::operator*()
{
return *ptr;
}
ParagraphList::iterator::pointer
ParagraphList::iterator::operator->()
{
return ptr;
}
ParagraphList::iterator &
ParagraphList::iterator::operator++()
{
ptr = ptr->next();
return *this;
}
ParagraphList::iterator
ParagraphList::iterator::operator++(int)
{
iterator tmp = *this;
++*this;
return tmp;
}
ParagraphList::iterator &
ParagraphList::iterator::operator--()
{
ptr = ptr->previous();
return *this;
}
ParagraphList::iterator
ParagraphList::iterator::operator--(int)
{
iterator tmp = *this;
--*this;
return tmp;
}
bool operator==(ParagraphList::iterator const & i1,
ParagraphList::iterator const & i2)
{
return &(*const_cast<ParagraphList::iterator&>(i1)) == &(*const_cast<ParagraphList::iterator&>(i2));
}
bool operator!=(ParagraphList::iterator const & i1,
ParagraphList::iterator const & i2)
{
return !(i1 == i2);
}
////////// The ParagraphList proper
ParagraphList::ParagraphList()
: parlist(0)
{}
void ParagraphList::clear()
{
while (parlist) {
Paragraph * tmp = parlist->next();
delete parlist;
parlist = tmp;
}
}
ParagraphList::iterator ParagraphList::begin()
{
return iterator(parlist);
}
ParagraphList::iterator ParagraphList::begin() const
{
return iterator(parlist);
}
ParagraphList::iterator ParagraphList::end()
{
return iterator();
}
ParagraphList::iterator ParagraphList::end() const
{
return iterator();
}
void ParagraphList::set(Paragraph * p)
{
parlist = p;
}
int ParagraphList::size() const
{
// When we switch to a std::container this will be O(1)
// instead of O(n). (Lgb)
Paragraph * tmp = parlist;
int c = 0;
while (tmp) {
++c;
tmp = tmp->next();
}
return c;
}
bool ParagraphList::empty() const
{
return parlist == 0;
}

76
src/ParagraphList.h Normal file
View File

@ -0,0 +1,76 @@
// -*- C++ -*-
#ifndef PARAGRAPH_LIST_H
#define PARAGRAPH_LIST_H
#include <iterator>
class Paragraph;
///
class ParagraphList {
public:
///
class iterator {
public:
///
typedef std::bidirectional_iterator_tag iterator_category;
///
typedef Paragraph * value_type;
///
typedef ptrdiff_t difference_type;
///
typedef Paragraph * pointer;
///
typedef Paragraph & reference;
///
iterator();
///
iterator(value_type);
///
reference operator*();
///
pointer operator->();
///
iterator & operator++();
///
iterator operator++(int);
///
iterator & operator--();
///
iterator operator--(int);
private:
///
Paragraph * ptr;
};
///
ParagraphList();
///
void clear();
///
iterator begin();
///
iterator begin() const;
///
iterator end();
///
iterator end() const;
///
void set(Paragraph *);
///
int size() const;
///
bool empty() const;
private:
///
Paragraph * parlist;
};
///
bool operator==(ParagraphList::iterator const & i1,
ParagraphList::iterator const & i2);
///
bool operator!=(ParagraphList::iterator const & i1,
ParagraphList::iterator const & i2);
#endif

View File

@ -146,14 +146,13 @@ const int LYX_FORMAT = 220;
} // namespace anon } // namespace anon
Buffer::Buffer(string const & file, bool ronly) Buffer::Buffer(string const & file, bool ronly)
: paragraph(0), niceFile(true), lyx_clean(true), bak_clean(true), : niceFile(true), lyx_clean(true), bak_clean(true),
unnamed(false), dep_clean(0), read_only(ronly), unnamed(false), dep_clean(0), read_only(ronly),
filename_(file), users(0) filename_(file), users(0)
{ {
lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl; lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
// filename = file; // filename = file;
filepath_ = OnlyPath(file); filepath_ = OnlyPath(file);
// paragraph = 0;
// lyx_clean = true; // lyx_clean = true;
// bak_clean = true; // bak_clean = true;
// dep_clean = 0; // dep_clean = 0;
@ -184,14 +183,7 @@ Buffer::~Buffer()
DestroyBufferTmpDir(tmppath); DestroyBufferTmpDir(tmppath);
} }
Paragraph * par = paragraph; paragraphs.clear();
Paragraph * tmppar;
while (par) {
tmppar = par->next();
delete par;
par = tmppar;
}
paragraph = 0;
// Remove any previewed LaTeX snippets assocoated with this buffer. // Remove any previewed LaTeX snippets assocoated with this buffer.
grfx::Previews::get().removeLoader(this); grfx::Previews::get().removeLoader(this);
@ -379,7 +371,7 @@ bool Buffer::readLyXformat2(LyXLex & lex, Paragraph * par)
if (!first_par) if (!first_par)
first_par = par; first_par = par;
paragraph = first_par; paragraphs.set(first_par);
if (unknown_layouts > 0) { if (unknown_layouts > 0) {
string s = _("Couldn't set the layout for "); string s = _("Couldn't set the layout for ");
@ -1848,7 +1840,7 @@ bool Buffer::writeFile(string const & fname) const
// this will write out all the paragraphs // this will write out all the paragraphs
// using recursive descent. // using recursive descent.
paragraph->writeFile(this, ofs, params, depth); paragraphs.begin()->writeFile(this, ofs, params, depth);
// Write marker that shows file is complete // Write marker that shows file is complete
ofs << "\n\\the_end" << endl; ofs << "\n\\the_end" << endl;
@ -2123,7 +2115,7 @@ void Buffer::writeFileAscii(string const & fname, int linelen)
void Buffer::writeFileAscii(ostream & ofs, int linelen) void Buffer::writeFileAscii(ostream & ofs, int linelen)
{ {
Paragraph * par = paragraph; Paragraph * par = &*(paragraphs.begin());
while (par) { while (par) {
ofs << asciiParagraph(par, linelen, par->previous() == 0); ofs << asciiParagraph(par, linelen, par->previous() == 0);
par = par->next(); par = par->next();
@ -2171,7 +2163,7 @@ void Buffer::makeLaTeXFile(ostream & os,
texrow.reset(); texrow.reset();
// The starting paragraph of the coming rows is the // The starting paragraph of the coming rows is the
// first paragraph of the document. (Asger) // first paragraph of the document. (Asger)
texrow.start(paragraph, 0); texrow.start(&*(paragraphs.begin()), 0);
if (!only_body && nice) { if (!only_body && nice) {
os << "%% " << lyx_docversion << " created this file. " os << "%% " << lyx_docversion << " created this file. "
@ -2598,7 +2590,7 @@ void Buffer::makeLaTeXFile(ostream & os,
texrow.newline(); texrow.newline();
} }
latexParagraphs(os, paragraph, 0, texrow); latexParagraphs(os, &*(paragraphs.begin()), 0, texrow);
// add this just in case after all the paragraphs // add this just in case after all the paragraphs
os << endl; os << endl;
@ -2800,7 +2792,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
<< " -->\n"; << " -->\n";
Paragraph::depth_type depth = 0; // paragraph depth Paragraph::depth_type depth = 0; // paragraph depth
Paragraph * par = paragraph; Paragraph * par = &*(paragraphs.begin());
string item_name; string item_name;
vector<string> environment_stack(5); vector<string> environment_stack(5);
@ -3215,7 +3207,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
return; return;
} }
Paragraph * par = paragraph; Paragraph * par = &*(paragraphs.begin());
niceFile = nice; // this will be used by Insetincludes. niceFile = nice; // this will be used by Insetincludes.
@ -3628,7 +3620,7 @@ int Buffer::runChktex()
void Buffer::validate(LaTeXFeatures & features) const void Buffer::validate(LaTeXFeatures & features) const
{ {
Paragraph * par = paragraph; Paragraph * par = &*(paragraphs.begin());
LyXTextClass const & tclass = params.getLyXTextClass(); LyXTextClass const & tclass = params.getLyXTextClass();
// AMS Style is at document level // AMS Style is at document level
@ -3733,7 +3725,7 @@ vector<pair<string, string> > const Buffer::getBibkeyList() const
} }
vector<StringPair> keys; vector<StringPair> keys;
Paragraph * par = paragraph; Paragraph * par = &*(paragraphs.begin());
while (par) { while (par) {
if (par->bibkey) { if (par->bibkey) {
string const key = par->bibkey->getContents(); string const key = par->bibkey->getContents();
@ -3833,7 +3825,7 @@ bool Buffer::dispatch(int action, string const & argument, bool * result)
void Buffer::resizeInsets(BufferView * bv) void Buffer::resizeInsets(BufferView * bv)
{ {
/// then remove all LyXText in text-insets /// then remove all LyXText in text-insets
Paragraph * par = paragraph; Paragraph * par = &*(paragraphs.begin());
for (; par; par = par->next()) { for (; par; par = par->next()) {
par->resizeInsetsLyXText(bv); par->resizeInsetsLyXText(bv);
} }
@ -3910,7 +3902,7 @@ Inset * Buffer::getInsetFromID(int id_arg) const
Paragraph * Buffer::getParFromID(int id) const Paragraph * Buffer::getParFromID(int id) const
{ {
if (id < 0) return 0; if (id < 0) return 0;
Paragraph * par = paragraph; Paragraph * par = &*(paragraphs.begin());
while (par) { while (par) {
if (par->id() == id) { if (par->id() == id) {
return par; return par;
@ -3927,7 +3919,7 @@ Paragraph * Buffer::getParFromID(int id) const
ParIterator Buffer::par_iterator_begin() ParIterator Buffer::par_iterator_begin()
{ {
return ParIterator(paragraph); return ParIterator(&*(paragraphs.begin()));
} }

View File

@ -24,6 +24,7 @@
#include "lyxvc.h" #include "lyxvc.h"
#include "bufferparams.h" #include "bufferparams.h"
#include "texrow.h" #include "texrow.h"
#include "ParagraphList.h"
#include "paragraph.h" #include "paragraph.h"
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
@ -301,7 +302,7 @@ public:
This is a linked list of paragraph, this list holds the This is a linked list of paragraph, this list holds the
whole contents of the document. whole contents of the document.
*/ */
Paragraph * paragraph; ParagraphList paragraphs;
/// LyX version control object. /// LyX version control object.
LyXVC lyxvc; LyXVC lyxvc;
@ -414,7 +415,7 @@ public:
/// ///
inset_iterator inset_iterator_begin() { inset_iterator inset_iterator_begin() {
return inset_iterator(paragraph); return inset_iterator(&*paragraphs.begin());
} }
/// ///
inset_iterator inset_iterator_end() { inset_iterator inset_iterator_end() {
@ -422,7 +423,7 @@ public:
} }
/// ///
inset_iterator inset_const_iterator_begin() const { inset_iterator inset_const_iterator_begin() const {
return inset_iterator(paragraph); return inset_iterator(&*paragraphs.begin());
} }
/// ///
inset_iterator inset_const_iterator_end() const { inset_iterator inset_const_iterator_end() const {

View File

@ -181,7 +181,7 @@ bool BufferList::close(Buffer * buf)
if (buf->getUser()) if (buf->getUser())
buf->getUser()->insetUnlock(); buf->getUser()->insetUnlock();
if (buf->paragraph && !buf->isClean() && !quitting) { if (!buf->paragraphs.empty() && !buf->isClean() && !quitting) {
if (buf->getUser()) if (buf->getUser())
buf->getUser()->owner()->prohibitInput(); buf->getUser()->owner()->prohibitInput();
string fname; string fname;
@ -476,12 +476,12 @@ Buffer * BufferList::newFile(string const & name, string tname, bool isNamed)
Alert::alert(_("Error!"), _("Unable to open template"), Alert::alert(_("Error!"), _("Unable to open template"),
MakeDisplayPath(tname)); MakeDisplayPath(tname));
// no template, start with empty buffer // no template, start with empty buffer
b->paragraph = new Paragraph; b->paragraphs.set(new Paragraph);
b->paragraph->layout(b->params.getLyXTextClass().defaultLayout()); b->paragraphs.begin()->layout(b->params.getLyXTextClass().defaultLayout());
} }
} else { // start with empty buffer } else { // start with empty buffer
b->paragraph = new Paragraph; b->paragraphs.set(new Paragraph);
b->paragraph->layout(b->params.getLyXTextClass().defaultLayout()); b->paragraphs.begin()->layout(b->params.getLyXTextClass().defaultLayout());
} }
if (!isNamed) { if (!isNamed) {

View File

@ -1,12 +1,17 @@
2002-08-12 Lars Gullik Bjønnes <larsbj@gullik.net>
* FormDocument.C (saveParamsAsDefault): ParagraphList changes
(class_apply): ditto
2002-08-08 John Levon <levon@movementarian.org> 2002-08-08 John Levon <levon@movementarian.org>
* Menubar_pimpl.C: * Menubar_pimpl.C:
* Toolbar_pimpl.C: lyxaction cleanup * Toolbar_pimpl.C: lyxaction cleanup
2002-08-08 John Levon <levon@movementarian.org> 2002-08-08 John Levon <levon@movementarian.org>
* forms/form_thesaurus.fd: allow Esc to close dialog * forms/form_thesaurus.fd: allow Esc to close dialog
2002-08-02 Angus Leeming <leeming@lyx.org> 2002-08-02 Angus Leeming <leeming@lyx.org>
* FormInclude.C: * FormInclude.C:
@ -22,18 +27,18 @@
2002-08-01 John Levon <levon@movementarian.org> 2002-08-01 John Levon <levon@movementarian.org>
* FormDocument.C: writeFile() change * FormDocument.C: writeFile() change
2002-08-01 John Levon <levon@movementarian.org> 2002-08-01 John Levon <levon@movementarian.org>
* FormPreferences.h: * FormPreferences.h:
* FormPreferences.C: * FormPreferences.C:
* guiapi.C: * guiapi.C:
* forms/form_spellchecker.fd: remove options from spellchecker * forms/form_spellchecker.fd: remove options from spellchecker
2002-07-30 John Levon <levon@movementarian.org> 2002-07-30 John Levon <levon@movementarian.org>
* lyx_gui.C: implement remove_read_callback() * lyx_gui.C: implement remove_read_callback()
2002-07-26 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr> 2002-07-26 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
* XWorkArea.C (work_area_handler): change type of * XWorkArea.C (work_area_handler): change type of

View File

@ -405,7 +405,7 @@ bool saveParamsAsDefault(BufferParams const &params)
defaults.params = params; defaults.params = params;
// add an empty paragraph. Is this enough? // add an empty paragraph. Is this enough?
defaults.paragraph = new Paragraph; defaults.paragraphs.set(new Paragraph);
return defaults.writeFile(defaults.fileName()); return defaults.writeFile(defaults.fileName());
} }
@ -746,7 +746,7 @@ bool FormDocument::class_apply()
setMinibuffer(lv_, _("Converting document to new document class...")); setMinibuffer(lv_, _("Converting document to new document class..."));
int ret = CutAndPaste::SwitchLayoutsBetweenClasses( int ret = CutAndPaste::SwitchLayoutsBetweenClasses(
old_class, params.textclass, old_class, params.textclass,
lv_->buffer()->paragraph, &*(lv_->buffer()->paragraphs.begin()),
lv_->buffer()->params); lv_->buffer()->params);
if (ret) { if (ret) {
string s; string s;

View File

@ -1,3 +1,9 @@
2002-08-12 Lars Gullik Bjønnes <larsbj@gullik.net>
* insetbib.C (bibitemMaxWidth): ParagraphList changes
(bibitemWidest): ditto
* insettext.[Ch]: ditto
2002-08-10 Lars Gullik Bjønnes <larsbj@gullik.net> 2002-08-10 Lars Gullik Bjønnes <larsbj@gullik.net>
* insettext.C, insetert.C: use Paragraph::empty where appropriate * insettext.C, insetert.C: use Paragraph::empty where appropriate

View File

@ -327,7 +327,7 @@ int bibitemMaxWidth(BufferView * bv, LyXFont const & font)
int w = 0; int w = 0;
// Ha, now we are mainly at 1.2.0 and it is still here (Jug) // Ha, now we are mainly at 1.2.0 and it is still here (Jug)
// Does look like a hack? It is! (but will change at 0.13) // Does look like a hack? It is! (but will change at 0.13)
Paragraph * par = bv->buffer()->paragraph; Paragraph * par = &*(bv->buffer()->paragraphs.begin());
while (par) { while (par) {
if (par->bibkey) { if (par->bibkey) {
@ -345,7 +345,7 @@ string const bibitemWidest(Buffer const * buffer)
{ {
int w = 0; int w = 0;
// Does look like a hack? It is! (but will change at 0.13) // Does look like a hack? It is! (but will change at 0.13)
Paragraph * par = buffer->paragraph; Paragraph * par = &*(buffer->paragraphs.begin());
InsetBibKey * bkey = 0; InsetBibKey * bkey = 0;
LyXFont font; LyXFont font;

View File

@ -76,7 +76,7 @@ extern int greek_kb_flag;
void InsetText::saveLyXTextState(LyXText * t) const void InsetText::saveLyXTextState(LyXText * t) const
{ {
// check if my paragraphs are still valid // check if my paragraphs are still valid
Paragraph * p = par; Paragraph * p = &*(paragraphs.begin());
while (p) { while (p) {
if (p == t->cursor.par()) if (p == t->cursor.par())
break; break;
@ -138,8 +138,8 @@ InsetText::InsetText(BufferParams const & bp)
: UpdatableInset(), lt(0), in_update(false), do_resize(0), : UpdatableInset(), lt(0), in_update(false), do_resize(0),
do_reinit(false) do_reinit(false)
{ {
par = new Paragraph; paragraphs.set(new Paragraph);
par->layout(bp.getLyXTextClass().defaultLayout()); paragraphs.begin()->layout(bp.getLyXTextClass().defaultLayout());
init(); init();
} }
@ -148,7 +148,6 @@ InsetText::InsetText(InsetText const & in, bool same_id)
: UpdatableInset(in, same_id), lt(0), in_update(false), do_resize(0), : UpdatableInset(in, same_id), lt(0), in_update(false), do_resize(0),
do_reinit(false) do_reinit(false)
{ {
par = 0;
init(&in, same_id); init(&in, same_id);
} }
@ -163,14 +162,14 @@ InsetText & InsetText::operator=(InsetText const & it)
void InsetText::init(InsetText const * ins, bool same_id) void InsetText::init(InsetText const * ins, bool same_id)
{ {
if (ins) { if (ins) {
setParagraphData(ins->par, same_id); setParagraphData(&*(ins->paragraphs.begin()), same_id);
autoBreakRows = ins->autoBreakRows; autoBreakRows = ins->autoBreakRows;
drawFrame_ = ins->drawFrame_; drawFrame_ = ins->drawFrame_;
frame_color = ins->frame_color; frame_color = ins->frame_color;
if (same_id) if (same_id)
id_ = ins->id_; id_ = ins->id_;
} else { } else {
Paragraph * p = par; Paragraph * p = &*(paragraphs.begin());
while (p) { while (p) {
p->setInsetOwner(this); p->setInsetOwner(this);
p = p->next(); p = p->next();
@ -205,27 +204,19 @@ InsetText::~InsetText()
// NOTE // NOTE
while (par) { paragraphs.clear();
Paragraph * tmp = par->next();
delete par;
par = tmp;
}
} }
void InsetText::clear() void InsetText::clear()
{ {
// This is a gross hack... // This is a gross hack...
LyXLayout_ptr old_layout = par->layout(); LyXLayout_ptr old_layout = paragraphs.begin()->layout();
while (par) { paragraphs.clear();
Paragraph * tmp = par->next(); paragraphs.set(new Paragraph);
delete par; paragraphs.begin()->setInsetOwner(this);
par = tmp; paragraphs.begin()->layout(old_layout);
}
par = new Paragraph;
par->setInsetOwner(this);
par->layout(old_layout);
reinitLyXText(); reinitLyXText();
need_update = INIT; need_update = INIT;
@ -247,7 +238,7 @@ void InsetText::write(Buffer const * buf, ostream & os) const
void InsetText::writeParagraphData(Buffer const * buf, ostream & os) const void InsetText::writeParagraphData(Buffer const * buf, ostream & os) const
{ {
par->writeFile(buf, os, buf->params, 0); paragraphs.begin()->writeFile(buf, os, buf->params, 0);
} }
@ -273,8 +264,10 @@ void InsetText::read(Buffer const * buf, LyXLex & lex)
break; break;
} }
Paragraph * tmp = &*(paragraphs.begin());
if (const_cast<Buffer*>(buf)-> if (const_cast<Buffer*>(buf)->
parseSingleLyXformat2Token(lex, par, return_par, parseSingleLyXformat2Token(lex, tmp, return_par,
token, pos, depth, font)) { token, pos, depth, font)) {
// the_end read this should NEVER happen // the_end read this should NEVER happen
lex.printError("\\the_end read in inset! Error in document!"); lex.printError("\\the_end read in inset! Error in document!");
@ -282,8 +275,8 @@ void InsetText::read(Buffer const * buf, LyXLex & lex)
} }
} }
if (!return_par) if (!return_par)
return_par = par; return_par = &*(paragraphs.begin());
par = return_par; paragraphs.set(return_par);
while (return_par) { while (return_par) {
return_par->setInsetOwner(this); return_par->setInsetOwner(this);
return_par = return_par->next(); return_par = return_par->next();
@ -377,7 +370,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
} }
// no draw is necessary !!! // no draw is necessary !!!
if ((drawFrame_ == LOCKED) && !locked && par->empty()) { if ((drawFrame_ == LOCKED) && !locked && paragraphs.begin()->empty()) {
top_baseline = baseline; top_baseline = baseline;
x += width(bv, f); x += width(bv, f);
if (need_update & CLEAR_FRAME) if (need_update & CLEAR_FRAME)
@ -570,7 +563,7 @@ void InsetText::update(BufferView * bv, LyXFont const & font, bool reinit)
return; return;
} }
if (!autoBreakRows && par->next()) if (!autoBreakRows && paragraphs.begin()->next())
collapseParagraphs(bv); collapseParagraphs(bv);
if (the_locking_inset) { if (the_locking_inset) {
@ -625,7 +618,7 @@ void InsetText::setUpdateStatus(BufferView * bv, int what) const
void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty) const void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty) const
{ {
if (!autoBreakRows && par->next()) if (!autoBreakRows && paragraphs.begin()->next())
collapseParagraphs(bv); collapseParagraphs(bv);
bool clear = false; bool clear = false;
if (!lt) { if (!lt) {
@ -704,7 +697,7 @@ void InsetText::edit(BufferView * bv, int x, int y, mouse_button::state button)
finishUndo(); finishUndo();
// If the inset is empty set the language of the current font to the // If the inset is empty set the language of the current font to the
// language to the surronding text (if different). // language to the surronding text (if different).
if (par->empty() && !par->next() && if (paragraphs.begin()->empty() && !paragraphs.begin()->next() &&
bv->getParentLanguage(this) != lt->current_font.language()) bv->getParentLanguage(this) != lt->current_font.language())
{ {
LyXFont font(LyXFont::ALL_IGNORE); LyXFont font(LyXFont::ALL_IGNORE);
@ -745,9 +738,9 @@ void InsetText::edit(BufferView * bv, bool front)
clear = true; clear = true;
} }
if (front) if (front)
lt->setCursor(bv, par, 0); lt->setCursor(bv, &*(paragraphs.begin()), 0);
else { else {
Paragraph * p = par; Paragraph * p = &*(paragraphs.begin());
while (p->next()) while (p->next())
p = p->next(); p = p->next();
// int const pos = (p->size() ? p->size()-1 : p->size()); // int const pos = (p->size() ? p->size()-1 : p->size());
@ -757,7 +750,7 @@ void InsetText::edit(BufferView * bv, bool front)
finishUndo(); finishUndo();
// If the inset is empty set the language of the current font to the // If the inset is empty set the language of the current font to the
// language to the surronding text (if different). // language to the surronding text (if different).
if (par->empty() && !par->next() && if (paragraphs.begin()->empty() && !paragraphs.begin()->next() &&
bv->getParentLanguage(this) != lt->current_font.language()) { bv->getParentLanguage(this) != lt->current_font.language()) {
LyXFont font(LyXFont::ALL_IGNORE); LyXFont font(LyXFont::ALL_IGNORE);
font.setLanguage(bv->getParentLanguage(this)); font.setLanguage(bv->getParentLanguage(this));
@ -807,10 +800,10 @@ void InsetText::insetUnlock(BufferView * bv)
} else } else
bv->owner()->setLayout(bv->text->cursor.par()->layout()->name()); bv->owner()->setLayout(bv->text->cursor.par()->layout()->name());
// hack for deleteEmptyParMech // hack for deleteEmptyParMech
if (!par->empty()) { if (!paragraphs.begin()->empty()) {
lt->setCursor(bv, par, 0); lt->setCursor(bv, &*(paragraphs.begin()), 0);
} else if (par->next()) { } else if (paragraphs.begin()->next()) {
lt->setCursor(bv, par->next(), 0); lt->setCursor(bv, paragraphs.begin()->next(), 0);
} }
if (clear) if (clear)
lt = 0; lt = 0;
@ -836,12 +829,12 @@ void InsetText::lockInset(BufferView * bv)
lt = getLyXText(bv); lt = getLyXText(bv);
clear = true; clear = true;
} }
lt->setCursor(bv, par, 0); lt->setCursor(bv, &*(paragraphs.begin()), 0);
lt->clearSelection(); lt->clearSelection();
finishUndo(); finishUndo();
// If the inset is empty set the language of the current font to the // If the inset is empty set the language of the current font to the
// language to the surronding text (if different). // language to the surronding text (if different).
if (par->empty() && !par->next() && if (paragraphs.begin()->empty() && !paragraphs.begin()->next() &&
bv->getParentLanguage(this) != lt->current_font.language()) { bv->getParentLanguage(this) != lt->current_font.language()) {
LyXFont font(LyXFont::ALL_IGNORE); LyXFont font(LyXFont::ALL_IGNORE);
font.setLanguage(bv->getParentLanguage(this)); font.setLanguage(bv->getParentLanguage(this));
@ -875,7 +868,7 @@ bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
if (!inset) if (!inset)
return false; return false;
if (!the_locking_inset) { if (!the_locking_inset) {
Paragraph * p = par; Paragraph * p = &*(paragraphs.begin());
int const id = inset->id(); int const id = inset->id();
while(p) { while(p) {
InsetList::iterator it = InsetList::iterator it =
@ -943,7 +936,7 @@ bool InsetText::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
bool InsetText::updateInsetInInset(BufferView * bv, Inset * inset) bool InsetText::updateInsetInInset(BufferView * bv, Inset * inset)
{ {
if (!autoBreakRows && par->next()) if (!autoBreakRows && paragraphs.begin()->next())
collapseParagraphs(bv); collapseParagraphs(bv);
if (inset == this) if (inset == this)
return true; return true;
@ -1176,7 +1169,7 @@ void InsetText::insetMotionNotify(BufferView * bv, int x, int y, mouse_button::s
UpdatableInset::RESULT UpdatableInset::RESULT
InsetText::localDispatch(BufferView * bv, FuncRequest const & ev) InsetText::localDispatch(BufferView * bv, FuncRequest const & ev)
{ {
bool was_empty = (par->empty() && !par->next()); bool was_empty = (paragraphs.begin()->empty() && !paragraphs.begin()->next());
no_selection = false; no_selection = false;
UpdatableInset::RESULT UpdatableInset::RESULT
result= UpdatableInset::localDispatch(bv, ev); result= UpdatableInset::localDispatch(bv, ev);
@ -1533,7 +1526,7 @@ InsetText::localDispatch(BufferView * bv, FuncRequest const & ev)
updateLocal(bv, updwhat, updflag); updateLocal(bv, updwhat, updflag);
/// If the action has deleted all text in the inset, we need to change the /// If the action has deleted all text in the inset, we need to change the
// language to the language of the surronding text. // language to the language of the surronding text.
if (!was_empty && par->empty() && !par->next()) { if (!was_empty && paragraphs.begin()->empty() && !paragraphs.begin()->next()) {
LyXFont font(LyXFont::ALL_IGNORE); LyXFont font(LyXFont::ALL_IGNORE);
font.setLanguage(bv->getParentLanguage(this)); font.setLanguage(bv->getParentLanguage(this));
setFont(bv, font, false); setFont(bv, font, false);
@ -1551,14 +1544,14 @@ InsetText::localDispatch(BufferView * bv, FuncRequest const & ev)
int InsetText::latex(Buffer const * buf, ostream & os, bool moving_arg, bool) const int InsetText::latex(Buffer const * buf, ostream & os, bool moving_arg, bool) const
{ {
TexRow texrow; TexRow texrow;
buf->latexParagraphs(os, par, 0, texrow, moving_arg); buf->latexParagraphs(os, &*(paragraphs.begin()), 0, texrow, moving_arg);
return texrow.rows(); return texrow.rows();
} }
int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const
{ {
Paragraph * p = par; Paragraph * p = &*(paragraphs.begin());
unsigned int lines = 0; unsigned int lines = 0;
while (p) { while (p) {
@ -1573,7 +1566,7 @@ int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const
int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const
{ {
Paragraph * p = par; Paragraph * p = &*(paragraphs.begin());
unsigned int lines = 0; unsigned int lines = 0;
vector<string> environment_stack(10); vector<string> environment_stack(10);
@ -1726,7 +1719,7 @@ int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const
void InsetText::validate(LaTeXFeatures & features) const void InsetText::validate(LaTeXFeatures & features) const
{ {
Paragraph * p = par; Paragraph * p = &*(paragraphs.begin());
while (p) { while (p) {
p->validate(features); p->validate(features);
p = p->next(); p = p->next();
@ -1966,7 +1959,7 @@ vector<string> const InsetText::getLabelList() const
{ {
vector<string> label_list; vector<string> label_list;
Paragraph * tpar = par; Paragraph * tpar = &*(paragraphs.begin());
while (tpar) { while (tpar) {
InsetList::iterator beg = tpar->insetlist.begin(); InsetList::iterator beg = tpar->insetlist.begin();
InsetList::iterator end = tpar->insetlist.end(); InsetList::iterator end = tpar->insetlist.end();
@ -1987,7 +1980,7 @@ void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
the_locking_inset->setFont(bv, font, toggleall, selectall); the_locking_inset->setFont(bv, font, toggleall, selectall);
return; return;
} }
if ((!par->next() && par->empty()) || cpar(bv)->empty()) { if ((!paragraphs.begin()->next() && paragraphs.begin()->empty()) || cpar(bv)->empty()) {
getLyXText(bv)->setFont(bv, font, toggleall); getLyXText(bv)->setFont(bv, font, toggleall);
return; return;
} }
@ -2087,15 +2080,11 @@ void InsetText::setParagraphData(Paragraph * p, bool same_id)
{ {
// we have to unlock any locked inset otherwise we're in troubles // we have to unlock any locked inset otherwise we're in troubles
the_locking_inset = 0; the_locking_inset = 0;
while (par) {
Paragraph * tmp = par->next();
delete par;
par = tmp;
}
par = new Paragraph(*p, same_id); paragraphs.clear();
par->setInsetOwner(this); paragraphs.set(new Paragraph(*p, same_id));
Paragraph * np = par; paragraphs.begin()->setInsetOwner(this);
Paragraph * np = &*(paragraphs.begin());
while (p->next()) { while (p->next()) {
p = p->next(); p = p->next();
np->next(new Paragraph(*p, same_id)); np->next(new Paragraph(*p, same_id));
@ -2111,8 +2100,8 @@ void InsetText::setParagraphData(Paragraph * p, bool same_id)
void InsetText::setText(string const & data, LyXFont const & font) void InsetText::setText(string const & data, LyXFont const & font)
{ {
clear(); clear();
for (unsigned int i=0; i < data.length(); ++i) for (unsigned int i = 0; i < data.length(); ++i)
par->insertChar(i, data[i], font); paragraphs.begin()->insertChar(i, data[i], font);
reinitLyXText(); reinitLyXText();
} }
@ -2223,7 +2212,7 @@ LyXText * InsetText::getLyXText(BufferView const * lbv,
if (recursive && the_locking_inset) if (recursive && the_locking_inset)
return the_locking_inset->getLyXText(lbv, true); return the_locking_inset->getLyXText(lbv, true);
LyXText * lt = cached_text.get(); LyXText * lt = cached_text.get();
lyx::Assert(lt && lt->firstRow()->par() == par); lyx::Assert(lt && lt->firstRow()->par() == &*(paragraphs.begin()));
return lt; return lt;
} }
// Super UGLY! (Lgb) // Super UGLY! (Lgb)
@ -2296,7 +2285,7 @@ void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
it->second.remove = true; it->second.remove = true;
if (recursive) { if (recursive) {
/// then remove all LyXText in text-insets /// then remove all LyXText in text-insets
Paragraph * p = par; Paragraph * p = &*(paragraphs.begin());
for (; p; p = p->next()) { for (; p; p = p->next()) {
p->deleteInsetsLyXText(bv); p->deleteInsetsLyXText(bv);
} }
@ -2314,7 +2303,7 @@ void InsetText::resizeLyXText(BufferView * bv, bool force) const
} }
do_resize = 0; do_resize = 0;
// lyxerr << "InsetText::resizeLyXText\n"; // lyxerr << "InsetText::resizeLyXText\n";
if (!par->next() && par->empty()) { // no data, resize not neccessary! if (!paragraphs.begin()->next() && paragraphs.begin()->empty()) { // no data, resize not neccessary!
// we have to do this as a fixed width may have changed! // we have to do this as a fixed width may have changed!
LyXText * t = getLyXText(bv); LyXText * t = getLyXText(bv);
saveLyXTextState(t); saveLyXTextState(t);
@ -2334,7 +2323,7 @@ void InsetText::resizeLyXText(BufferView * bv, bool force) const
LyXText * t = it->second.text.get(); LyXText * t = it->second.text.get();
saveLyXTextState(t); saveLyXTextState(t);
for (Paragraph * p = par; p; p = p->next()) { for (Paragraph * p = &*(paragraphs.begin()); p; p = p->next()) {
p->resizeInsetsLyXText(bv); p->resizeInsetsLyXText(bv);
} }
t->init(bv, true); t->init(bv, true);
@ -2373,7 +2362,8 @@ void InsetText::reinitLyXText() const
BufferView * bv = it->first; BufferView * bv = it->first;
saveLyXTextState(t); saveLyXTextState(t);
for (Paragraph * p = par; p; p = p->next()) { for (Paragraph * p = &*(paragraphs.begin());
p; p = p->next()) {
p->resizeInsetsLyXText(bv); p->resizeInsetsLyXText(bv);
} }
t->init(bv, true); t->init(bv, true);
@ -2398,7 +2388,7 @@ void InsetText::removeNewlines()
{ {
bool changed = false; bool changed = false;
for (Paragraph * p = par; p; p = p->next()) { for (Paragraph * p = &*(paragraphs.begin()); p; p = p->next()) {
for (int i = 0; i < p->size(); ++i) { for (int i = 0; i < p->size(); ++i) {
if (p->getChar(i) == Paragraph::META_NEWLINE) { if (p->getChar(i) == Paragraph::META_NEWLINE) {
changed = true; changed = true;
@ -2486,7 +2476,7 @@ Paragraph * InsetText::getParFromID(int id) const
} }
return result; return result;
#else #else
Paragraph * tmp = par; Paragraph * tmp = &*(paragraphs.begin());
while (tmp) { while (tmp) {
if (tmp->id() == id) { if (tmp->id() == id) {
return tmp; return tmp;
@ -2508,13 +2498,13 @@ Paragraph * InsetText::firstParagraph() const
if (the_locking_inset) if (the_locking_inset)
if ((result = the_locking_inset->firstParagraph())) if ((result = the_locking_inset->firstParagraph()))
return result; return result;
return par; return &*(paragraphs.begin());
} }
Paragraph * InsetText::getFirstParagraph(int i) const Paragraph * InsetText::getFirstParagraph(int i) const
{ {
return (i == 0) ? par : 0; return (i == 0) ? &*(paragraphs.begin()) : 0;
} }
@ -2528,7 +2518,7 @@ LyXCursor const & InsetText::cursor(BufferView * bv) const
Paragraph * InsetText::paragraph() const Paragraph * InsetText::paragraph() const
{ {
return par; return &*(paragraphs.begin());
} }
@ -2539,9 +2529,9 @@ void InsetText::paragraph(Paragraph * p)
// as we could have to insert a paragraph before this one and just // as we could have to insert a paragraph before this one and just
// link the actual to a new ones next and set it with this function // link the actual to a new ones next and set it with this function
// and are done! // and are done!
par = p; paragraphs.set(p);
// set ourself as owner for all the paragraphs inserted! // set ourself as owner for all the paragraphs inserted!
Paragraph * np = par; Paragraph * np = &*(paragraphs.begin());
while (np) { while (np) {
np->setInsetOwner(this); np->setInsetOwner(this);
np = np->next(); np = np->next();
@ -2557,7 +2547,7 @@ Inset * InsetText::getInsetFromID(int id_arg) const
if (id_arg == id()) if (id_arg == id())
return const_cast<InsetText *>(this); return const_cast<InsetText *>(this);
Paragraph * lp = par; Paragraph * lp = &*(paragraphs.begin());
while (lp) { while (lp) {
for (InsetList::iterator it = lp->insetlist.begin(), for (InsetList::iterator it = lp->insetlist.begin(),
@ -2576,7 +2566,9 @@ Inset * InsetText::getInsetFromID(int id_arg) const
} }
WordLangTuple InsetText::selectNextWordToSpellcheck(BufferView * bv, float & value) const WordLangTuple
InsetText::selectNextWordToSpellcheck(BufferView * bv,
float & value) const
{ {
bool clear = false; bool clear = false;
WordLangTuple word; WordLangTuple word;
@ -2692,7 +2684,7 @@ bool InsetText::searchBackward(BufferView * bv, string const & str,
clear = true; clear = true;
} }
if (!locked) { if (!locked) {
Paragraph * p = par; Paragraph * p = &*(paragraphs.begin());
while (p->next()) while (p->next())
p = p->next(); p = p->next();
lt->setCursor(bv, p, p->size()); lt->setCursor(bv, p, p->size());
@ -2728,25 +2720,25 @@ void InsetText::collapseParagraphs(BufferView * bv) const
BufferParams const & bparams = bv->buffer()->params; BufferParams const & bparams = bv->buffer()->params;
LyXText * llt = getLyXText(bv); LyXText * llt = getLyXText(bv);
while(par->next()) { while (paragraphs.begin()->next()) {
if (!par->empty() && !par->next()->empty() && if (!paragraphs.begin()->empty() && !paragraphs.begin()->next()->empty() &&
!par->isSeparator(par->size() - 1)) !paragraphs.begin()->isSeparator(paragraphs.begin()->size() - 1))
{ {
par->insertChar(par->size(), ' '); paragraphs.begin()->insertChar(paragraphs.begin()->size(), ' ');
} }
if (llt->selection.set()) { if (llt->selection.set()) {
if (llt->selection.start.par() == par->next()) { if (llt->selection.start.par() == paragraphs.begin()->next()) {
llt->selection.start.par(par); llt->selection.start.par(&*(paragraphs.begin()));
llt->selection.start.pos( llt->selection.start.pos(
llt->selection.start.pos() + par->size()); llt->selection.start.pos() + paragraphs.begin()->size());
} }
if (llt->selection.end.par() == par->next()) { if (llt->selection.end.par() == paragraphs.begin()->next()) {
llt->selection.end.par(par); llt->selection.end.par(&*(paragraphs.begin()));
llt->selection.end.pos( llt->selection.end.pos(
llt->selection.end.pos() + par->size()); llt->selection.end.pos() + paragraphs.begin()->size());
} }
} }
par->pasteParagraph(bparams); paragraphs.begin()->pasteParagraph(bparams);
} }
reinitLyXText(); reinitLyXText();
} }
@ -2773,7 +2765,7 @@ void InsetText::appendParagraphs(BufferParams const & bparams,
lastbuffer->next()->previous(lastbuffer); lastbuffer->next()->previous(lastbuffer);
lastbuffer = lastbuffer->next(); lastbuffer = lastbuffer->next();
} }
lastbuffer = par; lastbuffer = &*(paragraphs.begin());
while (lastbuffer->next()) while (lastbuffer->next())
lastbuffer = lastbuffer->next(); lastbuffer = lastbuffer->next();
if (!newpar->empty() && !lastbuffer->empty() && if (!newpar->empty() && !lastbuffer->empty() &&

View File

@ -22,6 +22,8 @@
#include "inset.h" #include "inset.h"
#include "LString.h" #include "LString.h"
#include "LColor.h" #include "LColor.h"
#include "ParagraphList.h"
#include "support/types.h" #include "support/types.h"
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
@ -351,7 +353,7 @@ private:
/* Private structures and variables */ /* Private structures and variables */
/// ///
Paragraph * par; ParagraphList paragraphs;
/// ///
mutable bool locked; mutable bool locked;
/// ///

View File

@ -2405,7 +2405,7 @@ Paragraph * LyXText::ownerParagraph() const
if (inset_owner) { if (inset_owner) {
return inset_owner->paragraph(); return inset_owner->paragraph();
} }
return bv_owner->buffer()->paragraph; return &*(bv_owner->buffer()->paragraphs.begin());
} }
@ -2414,7 +2414,7 @@ void LyXText::ownerParagraph(Paragraph * p) const
if (inset_owner) { if (inset_owner) {
inset_owner->paragraph(p); inset_owner->paragraph(p);
} else { } else {
bv_owner->buffer()->paragraph = p; bv_owner->buffer()->paragraphs.set(p);
} }
} }

View File

@ -72,7 +72,7 @@ TocList const getTocList(Buffer const * buf)
TocList toclist; TocList toclist;
if (!buf) if (!buf)
return toclist; return toclist;
Paragraph * par = buf->paragraph; Paragraph * par = &*(buf->paragraphs.begin());
LyXTextClass const & textclass = buf->params.getLyXTextClass(); LyXTextClass const & textclass = buf->params.getLyXTextClass();