parlist-10-a.diff + a bit more

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6805 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2003-04-14 18:35:29 +00:00
parent 2da34093a2
commit b94ed208a5
9 changed files with 97 additions and 175 deletions

View File

@ -1,3 +1,31 @@
2003-04-14 Lars Gullik Bjønnes <larsbj@gullik.net>
* text2.C (setCharFont): adjust
(setCounter): adjust
* text.C (leftMargin): adjust
(setHeightOfRow): adjust
* rowpainter.C (paintFirst): adjust
(paintLast): adjust
* paragraph_pimpl.C (realizeFont): adjust
* paragraph.C (isFirstInSequence): move from here...
* paragraph_funcs.C (isFirstInSequence): ...to here
* paragraph.C (outerHook): move from here...
* paragraph_funcs.C (outerHook): ...to here
* paragraph.C (depthHook): move from here...
* paragraph_funcs.C (depthHook): ...to here
* paragraph.C (getEndLabel): move from here...
* paragraph_funcs.C (getEndLabel): ...to here
* text2.C (realizeFont): move from here...
* paragraph_funcs.C (realizeFont): ...to here
2003-04-14 Lars Gullik Bjønnes <larsbj@gullik.net> 2003-04-14 Lars Gullik Bjønnes <larsbj@gullik.net>
* text3.C (gotoNextInset): use separate tmp vars for par and pos. * text3.C (gotoNextInset): use separate tmp vars for par and pos.

View File

@ -24,6 +24,7 @@
#include "ParameterStruct.h" #include "ParameterStruct.h"
#include "gettext.h" #include "gettext.h"
#include "changes.h" #include "changes.h"
#include "paragraph_funcs.h"
#include "insets/insetbibitem.h" #include "insets/insetbibitem.h"
#include "insets/insetoptarg.h" #include "insets/insetoptarg.h"
@ -689,35 +690,6 @@ bool Paragraph::hasSameLayout(Paragraph const * par) const
} }
int Paragraph::getEndLabel() const
{
Paragraph const * par = this;
depth_type par_depth = getDepth();
while (par) {
LyXLayout_ptr const & layout = par->layout();
int const endlabeltype = layout->endlabeltype;
if (endlabeltype != END_LABEL_NO_LABEL) {
if (!next_)
return endlabeltype;
depth_type const next_depth = next_->getDepth();
if (par_depth > next_depth ||
(par_depth == next_depth
&& layout != next_->layout()))
return endlabeltype;
break;
}
if (par_depth == 0)
break;
par = par->outerHook();
if (par)
par_depth = par->getDepth();
}
return END_LABEL_NO_LABEL;
}
Paragraph::depth_type Paragraph::getDepth() const Paragraph::depth_type Paragraph::getDepth() const
{ {
return params().depth(); return params().depth();
@ -805,60 +777,6 @@ int Paragraph::beginningOfBody() const
} }
Paragraph * Paragraph::depthHook(depth_type depth)
{
Paragraph * newpar = this;
do {
newpar = newpar->previous();
} while (newpar && newpar->getDepth() > depth);
if (!newpar) {
if (previous() || getDepth())
lyxerr << "ERROR (Paragraph::DepthHook): "
"no hook." << endl;
newpar = this;
}
return newpar;
}
Paragraph const * Paragraph::depthHook(depth_type depth) const
{
Paragraph const * newpar = this;
do {
newpar = newpar->previous();
} while (newpar && newpar->getDepth() > depth);
if (!newpar) {
if (previous() || getDepth())
lyxerr << "ERROR (Paragraph::DepthHook): "
"no hook." << endl;
newpar = this;
}
return newpar;
}
Paragraph * Paragraph::outerHook()
{
if (!getDepth())
return 0;
return depthHook(depth_type(getDepth() - 1));
}
Paragraph const * Paragraph::outerHook() const
{
if (!getDepth())
return 0;
return depthHook(depth_type(getDepth() - 1));
}
// returns -1 if inset not found // returns -1 if inset not found
int Paragraph::getPositionOfInset(Inset const * inset) const int Paragraph::getPositionOfInset(Inset const * inset) const
{ {
@ -1487,15 +1405,6 @@ void Paragraph::layout(LyXLayout_ptr const & new_layout)
} }
bool Paragraph::isFirstInSequence() const
{
Paragraph const * dhook = depthHook(getDepth());
return (dhook == this
|| dhook->layout() != layout()
|| dhook->getDepth() != getDepth());
}
Inset * Paragraph::inInset() const Inset * Paragraph::inInset() const
{ {
return pimpl_->inset_owner; return pimpl_->inset_owner;

View File

@ -112,12 +112,6 @@ public:
/// ///
void makeSameLayout(Paragraph const * par); void makeSameLayout(Paragraph const * par);
/// Is it the first par with same depth and layout?
bool isFirstInSequence() const;
/** Check if the current paragraph is the last paragraph in a
proof environment */
int getEndLabel() const;
/// ///
Inset * inInset() const; Inset * inInset() const;
/// ///
@ -200,15 +194,6 @@ public:
/// mark whole par as erased /// mark whole par as erased
void markErased(); void markErased();
/// for the environments
Paragraph * depthHook(depth_type depth);
/// for the environments
Paragraph const * depthHook(depth_type depth) const;
///
Paragraph * outerHook();
///
Paragraph const * outerHook() const;
/// Paragraphs can contain "manual labels", for example, Description environment. /// Paragraphs can contain "manual labels", for example, Description environment.
/// The text for this user-editable label is stored in the paragraph alongside /// The text for this user-editable label is stored in the paragraph alongside
/// the text of the rest of the paragraph (the body). This function returns /// the text of the rest of the paragraph (the body). This function returns

View File

@ -196,7 +196,6 @@ void mergeParagraph(BufferParams const & bparams,
} }
#if 0
Paragraph * depthHook(Paragraph * par, Paragraph::depth_type depth) Paragraph * depthHook(Paragraph * par, Paragraph::depth_type depth)
{ {
Paragraph * newpar = par; Paragraph * newpar = par;
@ -207,10 +206,11 @@ Paragraph * depthHook(Paragraph * par, Paragraph::depth_type depth)
if (!newpar) { if (!newpar) {
if (par->previous() || par->getDepth()) if (par->previous() || par->getDepth())
lyxerr << "Error (depthHook): " lyxerr << "ERROR (Paragraph::DepthHook): "
<< "no hook." << endl; "no hook." << endl;
newpar = par; newpar = par;
} }
return newpar; return newpar;
} }
@ -227,39 +227,38 @@ bool isFirstInSequence(Paragraph * par)
{ {
Paragraph const * dhook = depthHook(par, par->getDepth()); Paragraph const * dhook = depthHook(par, par->getDepth());
return (dhook == par return (dhook == par
|| dhook->getLayout() != par->getLayout() || dhook->layout() != par->layout()
|| dhook->getDepth() != par->getDepth()); || dhook->getDepth() != par->getDepth());
} }
int getEndLabel(Paragraph * para, BufferParams const & bparams) int getEndLabel(Paragraph * p)
{ {
Paragraph * par = para; Paragraph * par = p;
Paragraph::depth_type par_depth = p->getDepth();
while (par) { while (par) {
Paragraph::depth_type par_depth = par->getDepth(); LyXLayout_ptr const & layout = par->layout();
layout_type layout = par->getLayout(); int const endlabeltype = layout->endlabeltype;
int const endlabeltype =
textclasslist.Style(bparams.textclass,
layout).endlabeltype;
if (endlabeltype != END_LABEL_NO_LABEL) { if (endlabeltype != END_LABEL_NO_LABEL) {
if (!para->next()) if (!p->next())
return endlabeltype; return endlabeltype;
Paragraph::depth_type const next_depth = Paragraph::depth_type const next_depth = p->next()->getDepth();
para->next()->getDepth();
if (par_depth > next_depth || if (par_depth > next_depth ||
(par_depth == next_depth (par_depth == next_depth
&& layout != para->next()->getLayout())) && layout != p->next()->layout()))
return endlabeltype; return endlabeltype;
break; break;
} }
if (par_depth == 0) if (par_depth == 0)
break; break;
par = outerHook(par); par = outerHook(par);
if (par)
par_depth = par->getDepth();
} }
return END_LABEL_NO_LABEL; return END_LABEL_NO_LABEL;
} }
#endif
namespace { namespace {
@ -1024,3 +1023,29 @@ int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex)
return unknown; return unknown;
} }
LyXFont const realizeFont(LyXFont const & font,
Buffer const * buf,
ParagraphList & /*plist*/,
ParagraphList::iterator pit)
{
LyXTextClass const & tclass = buf->params.getLyXTextClass();
LyXFont tmpfont(font);
Paragraph::depth_type par_depth = pit->getDepth();
Paragraph * par = &*pit;
// Resolve against environment font information
while (par && par_depth && !tmpfont.resolved()) {
par = outerHook(par);
if (par) {
tmpfont.realize(par->layout()->font);
par_depth = par->getDepth();
}
}
tmpfont.realize(tclass.defaultfont());
return tmpfont;
}

View File

@ -13,11 +13,11 @@
#define PARAGRAPH_FUNCS_H #define PARAGRAPH_FUNCS_H
#include "ParagraphList.h" #include "ParagraphList.h"
#include "paragraph.h"
#include "support/types.h" #include "support/types.h"
class Buffer; class Buffer;
class BufferParams; class BufferParams;
class Paragraph;
class TexRow; class TexRow;
class LyXLex; class LyXLex;
@ -42,8 +42,6 @@ void mergeParagraph(BufferParams const & bparams,
ParagraphList & paragraphs, ParagraphList & paragraphs,
ParagraphList::iterator par); ParagraphList::iterator par);
#if 0
/// for the environments /// for the environments
Paragraph * depthHook(Paragraph * par, Paragraph::depth_type depth); Paragraph * depthHook(Paragraph * par, Paragraph::depth_type depth);
@ -54,8 +52,7 @@ bool isFirstInSequence(Paragraph * par);
/** 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, BufferParams const & bparams); int getEndLabel(Paragraph * para);
#endif
void latexParagraphs(Buffer const * buf, void latexParagraphs(Buffer const * buf,
@ -69,4 +66,9 @@ void latexParagraphs(Buffer const * buf,
/// read a paragraph from a .lyx file. Returns number of unrecognised tokens /// read a paragraph from a .lyx file. Returns number of unrecognised tokens
int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex); int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex);
LyXFont const realizeFont(LyXFont const & font,
Buffer const * buf,
ParagraphList & /*plist*/,
ParagraphList::iterator pit);
#endif // PARAGRAPH_FUNCS_H #endif // PARAGRAPH_FUNCS_H

View File

@ -18,6 +18,7 @@
#include "encoding.h" #include "encoding.h"
#include "lyxrc.h" #include "lyxrc.h"
#include "debug.h" #include "debug.h"
#include "paragraph_funcs.h"
#include "support/LAssert.h" #include "support/LAssert.h"
@ -859,12 +860,12 @@ LyXFont const Paragraph::Pimpl::realizeFont(LyXFont const & font,
LyXFont tmpfont(font); LyXFont tmpfont(font);
// check for environment font information // check for environment font information
char par_depth = owner_->getDepth(); depth_type par_depth = owner_->getDepth();
Paragraph const * par = owner_; Paragraph * par = owner_;
LyXTextClass const & tclass = bparams.getLyXTextClass(); LyXTextClass const & tclass = bparams.getLyXTextClass();
while (par && par->getDepth() && !tmpfont.resolved()) { while (par && par->getDepth() && !tmpfont.resolved()) {
par = par->outerHook(); par = outerHook(par);
if (par) { if (par) {
tmpfont.realize(par->layout()->font); tmpfont.realize(par->layout()->font);
par_depth = par->getDepth(); par_depth = par->getDepth();

View File

@ -18,6 +18,7 @@
#include "frontends/font_metrics.h" #include "frontends/font_metrics.h"
#include "support/LAssert.h" #include "support/LAssert.h"
#include "paragraph.h" #include "paragraph.h"
#include "paragraph_funcs.h"
#include "support/textutils.h" #include "support/textutils.h"
#include "insets/insettext.h" #include "insets/insettext.h"
@ -673,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
|| pit_->isFirstInSequence())) { || isFirstInSequence(&*pit_))) {
LyXFont font = getLabelFont(); LyXFont font = getLabelFont();
if (!pit_->getLabelstring().empty()) { if (!pit_->getLabelstring().empty()) {
@ -721,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 (pit_->isFirstInSequence() && } else if (isFirstInSequence(&*pit_) &&
(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)) {
@ -796,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 = pit_->getEndLabel(); int const endlabel = getEndLabel(&*pit_);
// draw an endlabel // draw an endlabel
switch (endlabel) { switch (endlabel) {

View File

@ -538,8 +538,8 @@ 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 = row.par() Paragraph * newpar =
->depthHook(row.par()->getDepth()); depthHook(&*row.par(), row.par()->getDepth());
if (newpar && if (newpar &&
newpar->layout()->nextnoindent) newpar->layout()->nextnoindent)
parindent.erase(); parindent.erase();
@ -548,7 +548,7 @@ int LyXText::leftMargin(Row const & row) const
} else { } else {
// find the next level paragraph // find the next level paragraph
Paragraph * newpar = row.par()->outerHook(); Paragraph * newpar = outerHook(&*row.par());
// make a corresponding row. Needed to call leftMargin() // make a corresponding row. Needed to call leftMargin()
@ -614,7 +614,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
&& ! row.par()->isFirstInSequence())) { && !isFirstInSequence(&*row.par()))) {
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 +679,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
&& ! row.par()->isFirstInSequence())) && !isFirstInSequence(&*row.par())))
&& 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 +1153,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)
&& pit->isFirstInSequence() && isFirstInSequence(&*pit)
&& !pit->getLabelstring().empty()) && !pit->getLabelstring().empty())
{ {
float spacing_val = 1.0; float spacing_val = 1.0;
@ -1180,7 +1180,7 @@ void LyXText::setHeightOfRow(RowList::iterator rit)
if (!pit->params().pagebreakTop()) { if (!pit->params().pagebreakTop()) {
Paragraph * prev = pit->previous(); Paragraph * prev = pit->previous();
if (prev) if (prev)
prev = pit->depthHook(pit->getDepth()); prev = depthHook(&*pit, pit->getDepth());
if (prev && prev->layout() == layout && if (prev && prev->layout() == layout &&
prev->getDepth() == pit->getDepth() && prev->getDepth() == pit->getDepth() &&
prev->getLabelWidthString() == pit->getLabelWidthString()) prev->getLabelWidthString() == pit->getLabelWidthString())
@ -1201,7 +1201,7 @@ void LyXText::setHeightOfRow(RowList::iterator rit)
layoutasc = (tmptop * defaultRowHeight()); layoutasc = (tmptop * defaultRowHeight());
} }
prev = pit->outerHook(); prev = outerHook(&*pit);
if (prev) { if (prev) {
maxasc += int(prev->layout()->parsep * defaultRowHeight()); maxasc += int(prev->layout()->parsep * defaultRowHeight());
} else if (pit != ownerParagraphs().begin()) { } else if (pit != ownerParagraphs().begin()) {
@ -1250,7 +1250,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 = comparepit->depthHook(nextpit->getDepth()); comparepit = depthHook(&*comparepit, nextpit->getDepth());
if (comparepit->layout()!= nextpit->layout() if (comparepit->layout()!= nextpit->layout()
|| nextpit->getLabelWidthString() != || nextpit->getLabelWidthString() !=
comparepit->getLabelWidthString()) comparepit->getLabelWidthString())

View File

@ -30,6 +30,7 @@
#include "ParagraphParameters.h" #include "ParagraphParameters.h"
#include "counters.h" #include "counters.h"
#include "lyxrow_funcs.h" #include "lyxrow_funcs.h"
#include "paragraph_funcs.h"
#include "insets/insetbibitem.h" #include "insets/insetbibitem.h"
#include "insets/insetfloat.h" #include "insets/insetfloat.h"
@ -99,36 +100,6 @@ void LyXText::init(BufferView * bview, bool reinit)
} }
namespace {
LyXFont const realizeFont(LyXFont const & font,
Buffer const * buf,
ParagraphList & /*plist*/,
ParagraphList::iterator pit)
{
LyXTextClass const & tclass = buf->params.getLyXTextClass();
LyXFont tmpfont(font);
Paragraph::depth_type par_depth = pit->getDepth();
Paragraph * par = &*pit;
// Resolve against environment font information
while (par && par_depth && !tmpfont.resolved()) {
par = par->outerHook();
if (par) {
tmpfont.realize(par->layout()->font);
par_depth = par->getDepth();
}
}
tmpfont.realize(tclass.defaultfont());
return tmpfont;
}
}
// Gets the fully instantiated font at a given position in a paragraph // Gets the fully instantiated font at a given position in a paragraph
// Basically the same routine as Paragraph::getFont() in paragraph.C. // Basically the same routine as Paragraph::getFont() in paragraph.C.
// The difference is that this one is used for displaying, and thus we // The difference is that this one is used for displaying, and thus we
@ -251,7 +222,7 @@ void LyXText::setCharFont(Buffer const * buf, ParagraphList::iterator pit,
#warning FIXME I think I hate this outerHood stuff. #warning FIXME I think I hate this outerHood stuff.
Paragraph * tp = &*pit; Paragraph * tp = &*pit;
while (!layoutfont.resolved() && tp && tp->getDepth()) { while (!layoutfont.resolved() && tp && tp->getDepth()) {
tp = tp->outerHook(); tp = outerHook(tp);
if (tp) if (tp)
layoutfont.realize(tp->layout()->font); layoutfont.realize(tp->layout()->font);
} }
@ -1091,7 +1062,7 @@ 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 = pit->depthHook(pit->getDepth())->enumdepth; pit->enumdepth = depthHook(&*pit, pit->getDepth())->enumdepth;
} }
if (!pit->params().labelString().empty()) { if (!pit->params().labelString().empty()) {