parlist-13-c.diff

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6824 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2003-04-16 08:12:22 +00:00
parent 065c0d0b05
commit 68f7a50799
10 changed files with 135 additions and 87 deletions

View File

@ -1,3 +1,30 @@
2003-04-16 Lars Gullik Bjønnes <larsbj@gullik.net>
* text2.C (setCharFont): adjust
(setCounter): adjust
(insertStringAsLines): adjust
* text.C (leftMargin): adjust
(setHeightOfRow): adjust
* rowpainter.C (paintFirst): adjust
(paintLast): adjust
* paragraph_funcs.C (depthHook): ParagraphList::iterators
(outerHook): ditto
(isFirstInSequence): ditto
(getEndLabel): ditto
(outerFont): adjust
* paragraph.C (getParLanguage): comment out some hard stuff.
* buffer.C (insertStringAsLines): take a ParagraphList as arg
(sgmlError): ditto
(simpleDocBookOnePar): ditto
(makeDocBookFile): use ParagraphList::iterator
* CutAndPaste.C (pasteSelection): adjust
2003-04-16 Lars Gullik Bjønnes <larsbj@gullik.net> 2003-04-16 Lars Gullik Bjønnes <larsbj@gullik.net>
* text2.C (getFont): adjust * text2.C (getFont): adjust

View File

@ -282,7 +282,7 @@ bool CutAndPaste::pasteSelection(Paragraph ** par, Paragraph ** endpar,
tmpbuf->erase(i--); tmpbuf->erase(i--);
} }
} else { } else {
LyXFont f1 = tmpbuf->getFont(current_view->buffer()->params, i, outerFont(tmpbuf, current_view->text->ownerParagraphs())); LyXFont f1 = tmpbuf->getFont(current_view->buffer()->params, i, outerFont(tmpbuf, current_view->buffer()->paragraphs));
LyXFont f2 = f1; LyXFont f2 = f1;
if (!(*par)->checkInsertChar(f1)) { if (!(*par)->checkInsertChar(f1)) {
tmpbuf->erase(i--); tmpbuf->erase(i--);

View File

@ -434,7 +434,7 @@ Buffer::readParagraph(LyXLex & lex, string const & token,
// needed to insert the selection // needed to insert the selection
void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos, void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
LyXFont const & fn,string const & str) LyXFont const & fn,string const & str)
{ {
LyXLayout_ptr const & layout = par->layout(); LyXLayout_ptr const & layout = par->layout();
@ -452,7 +452,7 @@ void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
if (autobreakrows && (!par->empty() || layout->keepempty)) { if (autobreakrows && (!par->empty() || layout->keepempty)) {
breakParagraph(params, paragraphs, par, pos, breakParagraph(params, paragraphs, par, pos,
layout->isEnvironment()); layout->isEnvironment());
par = par->next(); ++par;
pos = 0; pos = 0;
space_inserted = true; space_inserted = true;
} else { } else {
@ -1596,7 +1596,7 @@ void Buffer::simpleLinuxDocOnePar(ostream & os,
// Print an error message. // Print an error message.
void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/, void Buffer::sgmlError(ParagraphList::iterator /*par*/, int /*pos*/,
string const & /*message*/) const string const & /*message*/) const
{ {
#ifdef WITH_WARNINGS #ifdef WITH_WARNINGS
@ -1634,8 +1634,6 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
return; return;
} }
Paragraph * par = &*(paragraphs.begin());
niceFile = nice; // this will be used by Insetincludes. niceFile = nice; // this will be used by Insetincludes.
LaTeXFeatures features(params); LaTeXFeatures features(params);
@ -1689,7 +1687,10 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
string item_name; string item_name;
string command_name; string command_name;
while (par) { ParagraphList::iterator par = paragraphs.begin();
ParagraphList::iterator pend = paragraphs.end();
for (; par != pend; ++par) {
string sgmlparam; string sgmlparam;
string c_depth; string c_depth;
string c_params; string c_params;
@ -1843,7 +1844,6 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
simpleDocBookOnePar(ofs, par, desc_on, simpleDocBookOnePar(ofs, par, desc_on,
depth + 1 + command_depth); depth + 1 + command_depth);
par = par->next();
string end_tag; string end_tag;
// write closing SGML tags // write closing SGML tags
@ -1907,7 +1907,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
void Buffer::simpleDocBookOnePar(ostream & os, void Buffer::simpleDocBookOnePar(ostream & os,
Paragraph * par, int & desc_on, ParagraphList::iterator par, int & desc_on,
Paragraph::depth_type depth) const Paragraph::depth_type depth) const
{ {
bool emph_flag = false; bool emph_flag = false;

View File

@ -117,7 +117,7 @@ public:
Paragraph::depth_type & depth); Paragraph::depth_type & depth);
/// ///
void insertStringAsLines(Paragraph *&, lyx::pos_type &, void insertStringAsLines(ParagraphList::iterator &, lyx::pos_type &,
LyXFont const &, string const &); LyXFont const &, string const &);
/// ///
Paragraph * getParFromID(int id) const; Paragraph * getParFromID(int id) const;
@ -153,7 +153,7 @@ public:
bool only_preamble = false); bool only_preamble = false);
/// ///
void simpleDocBookOnePar(std::ostream &, void simpleDocBookOnePar(std::ostream &,
Paragraph * par, int & desc_on, ParagraphList::iterator par, int & desc_on,
Paragraph::depth_type depth) const ; Paragraph::depth_type depth) const ;
/// ///
void simpleLinuxDocOnePar(std::ostream & os, Paragraph * par, void simpleLinuxDocOnePar(std::ostream & os, Paragraph * par,
@ -165,7 +165,7 @@ public:
void makeDocBookFile(string const & filename, void makeDocBookFile(string const & filename,
bool nice, bool only_body = false); bool nice, bool only_body = false);
/// ///
void sgmlError(Paragraph * par, int pos, string const & message) const; void sgmlError(ParagraphList::iterator par, int pos, string const & message) const;
/// returns the main language for the buffer (document) /// returns the main language for the buffer (document)
Language const * getLanguage() const; Language const * getLanguage() const;

View File

@ -1187,9 +1187,12 @@ Paragraph::getParLanguage(BufferParams const & bparams) const
{ {
if (!empty()) { if (!empty()) {
return getFirstFontSettings().language(); return getFirstFontSettings().language();
} else if (previous_) #warning FIXME we should check the prev par as well (Lgb)
#if 0
} else if (previous_) {
return previous_->getParLanguage(bparams); return previous_->getParLanguage(bparams);
else #endif
}else
return bparams.language; return bparams.language;
} }

View File

@ -196,66 +196,72 @@ void mergeParagraph(BufferParams const & bparams,
} }
Paragraph * depthHook(Paragraph * par, Paragraph::depth_type depth) ParagraphList::iterator depthHook(ParagraphList::iterator pit,
ParagraphList const & plist,
Paragraph::depth_type depth)
{ {
Paragraph * newpar = par; ParagraphList::iterator newpit = pit;
ParagraphList::iterator beg = plist.begin();
do { if (newpit != beg)
newpar = newpar->previous(); --newpit;
} while (newpar && newpar->getDepth() > depth);
if (!newpar) { while (newpit != beg && newpit->getDepth() > depth) {
if (par->previous() || par->getDepth()) --newpit;
lyxerr << "ERROR (Paragraph::DepthHook): "
"no hook." << endl;
newpar = par;
} }
return newpar; if (newpit->getDepth() > depth)
return pit;
return newpit;
} }
Paragraph * outerHook(Paragraph * par) ParagraphList::iterator outerHook(ParagraphList::iterator pit,
ParagraphList const & plist)
{ {
if (!par->getDepth()) if (!pit->getDepth())
return 0; return plist.end();
return depthHook(par, Paragraph::depth_type(par->getDepth() - 1)); return depthHook(pit, plist,
Paragraph::depth_type(pit->getDepth() - 1));
} }
bool isFirstInSequence(Paragraph * par) bool isFirstInSequence(ParagraphList::iterator pit,
ParagraphList const & plist)
{ {
Paragraph const * dhook = depthHook(par, par->getDepth()); ParagraphList::iterator dhook = depthHook(pit, plist, pit->getDepth());
return (dhook == par return (dhook == pit
|| dhook->layout() != par->layout() || dhook->layout() != pit->layout()
|| dhook->getDepth() != par->getDepth()); || dhook->getDepth() != pit->getDepth());
} }
int getEndLabel(Paragraph * p) int getEndLabel(ParagraphList::iterator p,
ParagraphList const & plist)
{ {
Paragraph * par = p; ParagraphList::iterator pit = p;
Paragraph::depth_type par_depth = p->getDepth(); Paragraph::depth_type par_depth = p->getDepth();
while (par) { while (pit != plist.end()) {
LyXLayout_ptr const & layout = par->layout(); LyXLayout_ptr const & layout = pit->layout();
int const endlabeltype = layout->endlabeltype; int const endlabeltype = layout->endlabeltype;
if (endlabeltype != END_LABEL_NO_LABEL) { if (endlabeltype != END_LABEL_NO_LABEL) {
if (!p->next()) if (boost::next(p) == plist.end())
return endlabeltype; return endlabeltype;
Paragraph::depth_type const next_depth = p->next()->getDepth(); Paragraph::depth_type const next_depth = boost::next(p)->getDepth();
if (par_depth > next_depth || if (par_depth > next_depth ||
(par_depth == next_depth (par_depth == next_depth &&
&& layout != p->next()->layout())) layout != boost::next(p)->layout()))
return endlabeltype; return endlabeltype;
break; break;
} }
if (par_depth == 0) if (par_depth == 0)
break; break;
par = outerHook(par); pit = outerHook(pit, plist);
if (par) if (pit != plist.end())
par_depth = par->getDepth(); par_depth = pit->getDepth();
} }
return END_LABEL_NO_LABEL; return END_LABEL_NO_LABEL;
} }
@ -1031,18 +1037,18 @@ int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex)
LyXFont const outerFont(ParagraphList::iterator pit, LyXFont const outerFont(ParagraphList::iterator pit,
ParagraphList const & /*plist*/) ParagraphList const & plist)
{ {
Paragraph::depth_type par_depth = pit->getDepth(); Paragraph::depth_type par_depth = pit->getDepth();
LyXFont tmpfont(LyXFont::ALL_INHERIT); LyXFont tmpfont(LyXFont::ALL_INHERIT);
// Resolve against environment font information // Resolve against environment font information
Paragraph * par = &*pit; while (pit != plist.end() &&
while (par && par_depth && !tmpfont.resolved()) { par_depth && !tmpfont.resolved()) {
par = outerHook(par); pit = outerHook(pit, plist);
if (par) { if (pit != plist.end()) {
tmpfont.realize(par->layout()->font); tmpfont.realize(pit->layout()->font);
par_depth = par->getDepth(); par_depth = pit->getDepth();
} }
} }

View File

@ -42,17 +42,23 @@ void mergeParagraph(BufferParams const & bparams,
ParagraphList & paragraphs, ParagraphList & paragraphs,
ParagraphList::iterator par); ParagraphList::iterator par);
/// for the environments
Paragraph * depthHook(Paragraph * par, Paragraph::depth_type depth);
Paragraph * outerHook(Paragraph * par); /// for the environments
ParagraphList::iterator depthHook(ParagraphList::iterator pit,
ParagraphList const & plist,
Paragraph::depth_type depth);
ParagraphList::iterator outerHook(ParagraphList::iterator pit,
ParagraphList const & plist);
/// Is it the first par with same depth and layout? /// Is it the first par with same depth and layout?
bool isFirstInSequence(Paragraph * par); bool isFirstInSequence(ParagraphList::iterator par,
ParagraphList const & plist);
/** Check if the current paragraph is the last paragraph in a /** Check if the current paragraph is the last paragraph in a
proof environment */ proof environment */
int getEndLabel(Paragraph * para); int getEndLabel(ParagraphList::iterator pit,
ParagraphList const & plist);
void latexParagraphs(Buffer const * buf, void latexParagraphs(Buffer const * buf,

View File

@ -674,7 +674,7 @@ void RowPainter::paintFirst()
if (layout->labeltype >= LABEL_STATIC if (layout->labeltype >= LABEL_STATIC
&& (layout->labeltype != LABEL_STATIC && (layout->labeltype != LABEL_STATIC
|| layout->latextype != LATEX_ENVIRONMENT || layout->latextype != LATEX_ENVIRONMENT
|| isFirstInSequence(&*pit_))) { || isFirstInSequence(pit_, text_.ownerParagraphs()))) {
LyXFont font = getLabelFont(); LyXFont font = getLabelFont();
if (!pit_->getLabelstring().empty()) { if (!pit_->getLabelstring().empty()) {
@ -722,7 +722,7 @@ void RowPainter::paintFirst()
// the labels at the top of an environment. // the labels at the top of an environment.
// More or less for bibliography // More or less for bibliography
} else if (isFirstInSequence(&*pit_) && } else if (isFirstInSequence(pit_, text_.ownerParagraphs()) &&
(layout->labeltype == LABEL_TOP_ENVIRONMENT || (layout->labeltype == LABEL_TOP_ENVIRONMENT ||
layout->labeltype == LABEL_BIBLIO || layout->labeltype == LABEL_BIBLIO ||
layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) { layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
@ -797,7 +797,7 @@ void RowPainter::paintLast()
} }
bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params); bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params);
int const endlabel = getEndLabel(&*pit_); int const endlabel = getEndLabel(pit_, text_.ownerParagraphs());
// draw an endlabel // draw an endlabel
switch (endlabel) { switch (endlabel) {

View File

@ -538,29 +538,33 @@ int LyXText::leftMargin(Row const & row) const
if (row.par()->layout() == tclass.defaultLayout()) { if (row.par()->layout() == tclass.defaultLayout()) {
// find the previous same level paragraph // find the previous same level paragraph
if (row.par() != ownerParagraphs().begin()) { if (row.par() != ownerParagraphs().begin()) {
Paragraph * newpar = ParagraphList::iterator newpit =
depthHook(&*row.par(), row.par()->getDepth()); depthHook(row.par(), ownerParagraphs(),
if (newpar && row.par()->getDepth());
newpar->layout()->nextnoindent) if (newpit == row.par() &&
newpit->layout()->nextnoindent)
parindent.erase(); parindent.erase();
} }
} }
} else { } else {
// find the next level paragraph // find the next level paragraph
Paragraph * newpar = outerHook(&*row.par()); ParagraphList::iterator newpar = outerHook(row.par(),
ownerParagraphs());
// make a corresponding row. Needed to call leftMargin() // make a corresponding row. Needed to call leftMargin()
// check wether it is a sufficent paragraph // check wether it is a sufficent paragraph
if (newpar && newpar->layout()->isEnvironment()) { if (newpar != ownerParagraphs().end() &&
newpar->layout()->isEnvironment()) {
Row dummyrow; Row dummyrow;
dummyrow.par(newpar); dummyrow.par(newpar);
dummyrow.pos(newpar->size()); dummyrow.pos(newpar->size());
x = leftMargin(dummyrow); x = leftMargin(dummyrow);
} }
if (newpar && row.par()->layout() == tclass.defaultLayout()) { if (newpar != ownerParagraphs().end() &&
row.par()->layout() == tclass.defaultLayout()) {
if (newpar->params().noindent()) if (newpar->params().noindent())
parindent.erase(); parindent.erase();
else { else {
@ -614,7 +618,7 @@ int LyXText::leftMargin(Row const & row) const
// theorems (JMarc) // theorems (JMarc)
|| (layout->labeltype == LABEL_STATIC || (layout->labeltype == LABEL_STATIC
&& layout->latextype == LATEX_ENVIRONMENT && layout->latextype == LATEX_ENVIRONMENT
&& !isFirstInSequence(&*row.par()))) { && !isFirstInSequence(row.par(), ownerParagraphs()))) {
x += font_metrics::signedWidth(layout->leftmargin, x += font_metrics::signedWidth(layout->leftmargin,
labelfont); labelfont);
} else if (layout->labeltype != LABEL_TOP_ENVIRONMENT } else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
@ -679,7 +683,7 @@ int LyXText::leftMargin(Row const & row) const
|| layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
|| (layout->labeltype == LABEL_STATIC || (layout->labeltype == LABEL_STATIC
&& layout->latextype == LATEX_ENVIRONMENT && layout->latextype == LATEX_ENVIRONMENT
&& !isFirstInSequence(&*row.par()))) && !isFirstInSequence(row.par(), ownerParagraphs())))
&& align == LYX_ALIGN_BLOCK && align == LYX_ALIGN_BLOCK
&& !row.par()->params().noindent() && !row.par()->params().noindent()
// in tabulars and ert paragraphs are never indented! // in tabulars and ert paragraphs are never indented!
@ -1153,7 +1157,7 @@ void LyXText::setHeightOfRow(RowList::iterator rit)
if ((layout->labeltype == LABEL_TOP_ENVIRONMENT if ((layout->labeltype == LABEL_TOP_ENVIRONMENT
|| layout->labeltype == LABEL_BIBLIO || layout->labeltype == LABEL_BIBLIO
|| layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
&& isFirstInSequence(&*pit) && isFirstInSequence(pit, ownerParagraphs())
&& !pit->getLabelstring().empty()) && !pit->getLabelstring().empty())
{ {
float spacing_val = 1.0; float spacing_val = 1.0;
@ -1174,14 +1178,15 @@ void LyXText::setHeightOfRow(RowList::iterator rit)
+ layout->labelbottomsep * defaultRowHeight()); + layout->labelbottomsep * defaultRowHeight());
} }
// and now the layout spaces, for example before and after a section, // And now the layout spaces, for example before and after
// or between the items of a itemize or enumerate environment // a section, or between the items of a itemize or enumerate
// environment.
if (!pit->params().pagebreakTop()) { if (!pit->params().pagebreakTop()) {
Paragraph * prev = pit->previous(); ParagraphList::iterator prev =
if (prev) depthHook(pit, ownerParagraphs(),
prev = depthHook(&*pit, pit->getDepth()); pit->getDepth());
if (prev && prev->layout() == layout && if (prev != pit && prev->layout() == layout &&
prev->getDepth() == pit->getDepth() && prev->getDepth() == pit->getDepth() &&
prev->getLabelWidthString() == pit->getLabelWidthString()) prev->getLabelWidthString() == pit->getLabelWidthString())
{ {
@ -1201,8 +1206,8 @@ void LyXText::setHeightOfRow(RowList::iterator rit)
layoutasc = (tmptop * defaultRowHeight()); layoutasc = (tmptop * defaultRowHeight());
} }
prev = outerHook(&*pit); prev = outerHook(pit, ownerParagraphs());
if (prev) { if (prev != ownerParagraphs().end()) {
maxasc += int(prev->layout()->parsep * defaultRowHeight()); maxasc += int(prev->layout()->parsep * defaultRowHeight());
} else if (pit != ownerParagraphs().begin()) { } else if (pit != ownerParagraphs().begin()) {
ParagraphList::iterator prior_pit = boost::prior(pit); ParagraphList::iterator prior_pit = boost::prior(pit);
@ -1250,7 +1255,7 @@ void LyXText::setHeightOfRow(RowList::iterator rit)
if (comparepit->getDepth() > nextpit->getDepth()) { if (comparepit->getDepth() > nextpit->getDepth()) {
usual = (comparepit->layout()->bottomsep * defaultRowHeight()); usual = (comparepit->layout()->bottomsep * defaultRowHeight());
comparepit = depthHook(&*comparepit, nextpit->getDepth()); comparepit = depthHook(comparepit, ownerParagraphs(), nextpit->getDepth());
if (comparepit->layout()!= nextpit->layout() if (comparepit->layout()!= nextpit->layout()
|| nextpit->getLabelWidthString() != || nextpit->getLabelWidthString() !=
comparepit->getLabelWidthString()) comparepit->getLabelWidthString())

View File

@ -230,11 +230,12 @@ void LyXText::setCharFont(Buffer const * buf, ParagraphList::iterator pit,
// Realize against environment font information // Realize against environment font information
if (pit->getDepth()) { if (pit->getDepth()) {
#warning FIXME I think I hate this outerHood stuff. ParagraphList::iterator tp = pit;
Paragraph * tp = &*pit; while (!layoutfont.resolved() &&
while (!layoutfont.resolved() && tp && tp->getDepth()) { tp != ownerParagraphs().end() &&
tp = outerHook(tp); tp->getDepth()) {
if (tp) tp = outerHook(tp, ownerParagraphs());
if (tp != ownerParagraphs().end())
layoutfont.realize(tp->layout()->font); layoutfont.realize(tp->layout()->font);
} }
} }
@ -1073,7 +1074,8 @@ void LyXText::setCounter(Buffer const * buf, ParagraphList::iterator pit)
if (pit != ownerParagraphs().begin() if (pit != ownerParagraphs().begin()
&& boost::prior(pit)->getDepth() > pit->getDepth() && boost::prior(pit)->getDepth() > pit->getDepth()
&& layout->labeltype != LABEL_BIBLIO) { && layout->labeltype != LABEL_BIBLIO) {
pit->enumdepth = depthHook(&*pit, pit->getDepth())->enumdepth; pit->enumdepth = depthHook(pit, ownerParagraphs(),
pit->getDepth())->enumdepth;
} }
if (!pit->params().labelString().empty()) { if (!pit->params().labelString().empty()) {
@ -1492,8 +1494,7 @@ void LyXText::insertStringAsLines(string const & str)
// only to be sure, should not be neccessary // only to be sure, should not be neccessary
clearSelection(); clearSelection();
Paragraph * par = &*pit; bv()->buffer()->insertStringAsLines(pit, pos, current_font, str);
bv()->buffer()->insertStringAsLines(par, pos, current_font, str);
redoParagraphs(cursor, endpit); redoParagraphs(cursor, endpit);
setCursor(cursor.par(), cursor.pos()); setCursor(cursor.par(), cursor.pos());