"Main body" is now just "body"

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6397 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John Levon 2003-03-09 12:37:22 +00:00
parent 8c2af0660c
commit 27deed6ea3
7 changed files with 99 additions and 91 deletions

View File

@ -1,3 +1,13 @@
2003-03-08 John Levon <levon@movementarian.org>
* lyxrow.C:
* paragraph.C:
* paragraph.h:
* rowpainter.C:
* text.C:
* text2.C: Remove the "main" bit from the "main body"
notion.
2003-03-08 John Levon <levon@movementarian.org>
* text.C (leftMargin): The left margin of an empty

View File

@ -189,7 +189,7 @@ pos_type Row::lastPrintablePos() const
int Row::numberOfSeparators() const
{
pos_type const last = lastPrintablePos();
pos_type p = max(pos(), par()->beginningOfMainBody());
pos_type p = max(pos(), par()->beginningOfBody());
int n = 0;
for (; p <= last; ++p) {
@ -213,7 +213,7 @@ int Row::numberOfHfills() const
}
}
first = max(first, par()->beginningOfMainBody());
first = max(first, par()->beginningOfBody());
int n = 0;
@ -237,7 +237,7 @@ int Row::numberOfLabelHfills() const
++first;
}
last = min(last, par()->beginningOfMainBody());
last = min(last, par()->beginningOfBody());
int n = 0;
// last, because the end is ignored!
@ -273,7 +273,7 @@ bool Row::hfillExpansion(pos_type pos) const
// in some labels it does not count
if (par()->layout()->margintype != MARGIN_MANUAL
&& pos < par()->beginningOfMainBody())
&& pos < par()->beginningOfBody())
return false;
// if there is anything between the first char of the row and

View File

@ -505,10 +505,10 @@ LyXFont const Paragraph::getFont(BufferParams const & bparams,
LyXLayout_ptr const & lout = layout();
pos_type const main_body = beginningOfMainBody();
pos_type const body_pos = beginningOfBody();
LyXFont layoutfont;
if (pos < main_body)
if (pos < body_pos)
layoutfont = lout->labelfont;
else
layoutfont = lout->font;
@ -841,14 +841,7 @@ void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
}
// if the layout of a paragraph contains a manual label, the beginning of the
// main body is the beginning of the second word. This is what the par-
// function returns. If the layout does not contain a label, the main
// body always starts with position 0. This differentiation is necessary,
// because there cannot be a newline or a blank <= the beginning of the
// main body in TeX.
int Paragraph::beginningOfMainBody() const
int Paragraph::beginningOfBody() const
{
if (layout()->labeltype != LABEL_MANUAL)
return 0;
@ -1099,19 +1092,19 @@ bool Paragraph::simpleTeXOnePar(Buffer const * buf,
LyXFont basefont;
// Maybe we have to create a optional argument.
pos_type main_body;
pos_type body_pos;
// FIXME: can we actually skip this check and just call
// beginningOfMainBody() ??
// beginningOfBody() ??
if (style->labeltype != LABEL_MANUAL) {
main_body = 0;
body_pos = 0;
} else {
main_body = beginningOfMainBody();
body_pos = beginningOfBody();
}
unsigned int column = 0;
if (main_body > 0) {
if (body_pos > 0) {
os << '[';
++column;
basefont = getLabelFont(bparams);
@ -1144,8 +1137,8 @@ bool Paragraph::simpleTeXOnePar(Buffer const * buf,
for (pos_type i = 0; i < size(); ++i) {
++column;
// First char in paragraph or after label?
if (i == main_body) {
if (main_body > 0) {
if (i == body_pos) {
if (body_pos > 0) {
if (open_font) {
column += running_font.latexWriteEndChanges(os, basefont, basefont);
open_font = false;
@ -1190,7 +1183,7 @@ bool Paragraph::simpleTeXOnePar(Buffer const * buf,
{
column += running_font.latexWriteEndChanges(os,
basefont,
(i == main_body-1) ? basefont : font);
(i == body_pos-1) ? basefont : font);
running_font = basefont;
open_font = false;
}
@ -1198,7 +1191,7 @@ bool Paragraph::simpleTeXOnePar(Buffer const * buf,
// Blanks are printed before start of fontswitch
if (c == ' ') {
// Do not print the separation of the optional argument
if (i != main_body - 1) {
if (i != body_pos - 1) {
pimpl_->simpleTeXBlanks(os, texrow, i,
column, font, *style);
}
@ -1207,7 +1200,7 @@ bool Paragraph::simpleTeXOnePar(Buffer const * buf,
// Do we need to change font?
if ((font != running_font ||
font.language() != running_font.language()) &&
i != main_body - 1)
i != body_pos - 1)
{
column += font.latexWriteStartChanges(os, basefont,
last_font);
@ -1280,7 +1273,7 @@ bool Paragraph::simpleTeXOnePar(Buffer const * buf,
}
// Needed if there is an optional argument but no contents.
if (main_body > 0 && main_body == size()) {
if (body_pos > 0 && body_pos == size()) {
os << "]~";
return_value = false;
}

View File

@ -203,8 +203,13 @@ public:
Paragraph * outerHook();
///
Paragraph const * outerHook() const;
///
int beginningOfMainBody() const;
/// Paragraphs can contain "manual labels", for example, Description environment.
/// 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 starting position of the body of the text in the paragraph.
int beginningOfBody() const;
///
string const & getLabelstring() const;

View File

@ -470,26 +470,26 @@ void RowPainter::paintSelection()
if ((startrow != row && !is_rtl) || (endrow != row && is_rtl))
pain_.fillRectangle(xo_, yo_, int(x_), row_.height(), LColor::selection);
pos_type const main_body = par_.beginningOfMainBody();
pos_type const body_pos = par_.beginningOfBody();
pos_type const last = row_.lastPrintablePos();
float tmpx = x_;
for (pos_type vpos = row_.pos(); vpos <= last; ++vpos) {
pos_type pos = text_.vis2log(vpos);
float const old_tmpx = tmpx;
if (main_body > 0 && pos == main_body - 1) {
if (body_pos > 0 && pos == body_pos - 1) {
LyXLayout_ptr const & layout = par_.layout();
LyXFont const lfont = getLabelFont();
tmpx += label_hfill_ + font_metrics::width(layout->labelsep, lfont);
if (par_.isLineSeparator(main_body - 1))
tmpx -= singleWidth(main_body - 1);
if (par_.isLineSeparator(body_pos - 1))
tmpx -= singleWidth(body_pos - 1);
}
if (row_.hfillExpansion(pos)) {
tmpx += singleWidth(pos);
if (pos >= main_body)
if (pos >= body_pos)
tmpx += hfill_;
else
tmpx += label_hfill_;
@ -497,7 +497,7 @@ void RowPainter::paintSelection()
else if (par_.isSeparator(pos)) {
tmpx += singleWidth(pos);
if (pos >= main_body)
if (pos >= body_pos)
tmpx += separator_;
} else {
tmpx += singleWidth(pos);
@ -930,11 +930,11 @@ void RowPainter::paintLast()
bool RowPainter::paintText()
{
pos_type const last = row_.lastPrintablePos();
pos_type main_body = par_.beginningOfMainBody();
if (main_body > 0 &&
(main_body - 1 > last ||
!par_.isLineSeparator(main_body - 1))) {
main_body = 0;
pos_type body_pos = par_.beginningOfBody();
if (body_pos > 0 &&
(body_pos - 1 > last ||
!par_.isLineSeparator(body_pos - 1))) {
body_pos = 0;
}
LyXLayout_ptr const & layout = par_.layout();
@ -975,12 +975,12 @@ bool RowPainter::paintText()
running_strikeout = false;
}
if (main_body > 0 && pos == main_body - 1) {
if (body_pos > 0 && pos == body_pos - 1) {
int const lwidth = font_metrics::width(layout->labelsep,
getLabelFont());
x_ += label_hfill_ + lwidth
- singleWidth(main_body - 1);
- singleWidth(body_pos - 1);
}
if (par_.isHfill(pos)) {
@ -995,7 +995,7 @@ bool RowPainter::paintText()
if (row_.hfillExpansion(pos)) {
int const y2 = (y0 + y1) / 2;
if (pos >= main_body) {
if (pos >= body_pos) {
pain_.line(int(x_), y2,
int(x_ + hfill_), y2,
LColor::added_space,
@ -1016,7 +1016,7 @@ bool RowPainter::paintText()
++vpos;
} else if (par_.isSeparator(pos)) {
x_ += singleWidth(pos);
if (pos >= main_body)
if (pos >= body_pos)
x_ += separator_;
++vpos;
} else {

View File

@ -298,7 +298,7 @@ void LyXText::computeBidiTables(Buffer const * buf, Row * row) const
int level = 0;
bool rtl = false;
bool rtl0 = false;
pos_type const main_body = row->par()->beginningOfMainBody();
pos_type const body_pos = row->par()->beginningOfBody();
for (pos_type lpos = bidi_start; lpos <= bidi_end; ++lpos) {
bool is_space = row->par()->isLineSeparator(lpos);
@ -321,8 +321,8 @@ void LyXText::computeBidiTables(Buffer const * buf, Row * row) const
bool new_rtl0 = font.isRightToLeft();
int new_level;
if (lpos == main_body - 1
&& row->pos() < main_body - 1
if (lpos == body_pos - 1
&& row->pos() < body_pos - 1
&& is_space) {
new_level = (rtl_par) ? 1 : 0;
new_rtl = new_rtl0 = rtl_par;
@ -498,7 +498,7 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
case MARGIN_MANUAL:
x += font_metrics::signedWidth(layout->labelindent, labelfont);
// The width of an empty par, even with manual label, should be 0
if (!row->par()->empty() && row->pos() >= row->par()->beginningOfMainBody()) {
if (!row->par()->empty() && row->pos() >= row->par()->beginningOfBody()) {
if (!row->par()->getLabelWidthString().empty()) {
x += font_metrics::width(row->par()->getLabelWidthString(),
labelfont);
@ -512,7 +512,7 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
break;
case MARGIN_FIRST_DYNAMIC:
if (layout->labeltype == LABEL_MANUAL) {
if (row->pos() >= row->par()->beginningOfMainBody()) {
if (row->pos() >= row->par()->beginningOfBody()) {
x += font_metrics::signedWidth(layout->leftmargin,
labelfont);
} else {
@ -668,7 +668,7 @@ int LyXText::labelEnd(BufferView & bview, Row const & row) const
if (row.par()->layout()->margintype == MARGIN_MANUAL) {
Row tmprow = row;
tmprow.pos(row.par()->size());
// just the beginning of the main body
// return the beginning of the body
return leftMargin(&bview, &tmprow);
}
@ -694,7 +694,7 @@ LyXText::nextBreakPoint(BufferView * bview, Row const * row, int width) const
pos_type last_separator = -1;
width -= rightMargin(*bview->buffer(), *row);
pos_type const main_body = par->beginningOfMainBody();
pos_type const body_pos = par->beginningOfBody();
LyXLayout_ptr const & layout = par->layout();
pos_type i = pos;
@ -734,7 +734,7 @@ LyXText::nextBreakPoint(BufferView * bview, Row const * row, int width) const
if (in->display() &&
(layout->isCommand() ||
(layout->labeltype == LABEL_MANUAL
&& i < par->beginningOfMainBody())))
&& i < par->beginningOfBody())))
{
// display istn't allowd
in->display(false);
@ -770,7 +770,7 @@ LyXText::nextBreakPoint(BufferView * bview, Row const * row, int width) const
x += singleWidth(bview, par, i, c);
}
++i;
if (i == main_body) {
if (i == body_pos) {
x += font_metrics::width(layout->labelsep,
getLabelFont(bview->buffer(), par));
if (par->isLineSeparator(i - 1))
@ -796,8 +796,8 @@ LyXText::nextBreakPoint(BufferView * bview, Row const * row, int width) const
}
// manual labels cannot be broken in LaTeX, do not care
if (main_body && last_separator < main_body)
last_separator = main_body - 1;
if (body_pos && last_separator < body_pos)
last_separator = body_pos - 1;
return last_separator;
}
@ -825,11 +825,11 @@ int LyXText::fill(BufferView & bview, Row & row, int paper_width) const
Paragraph * par = row.par();
LyXLayout_ptr const & layout = par->layout();
pos_type const main_body = par->beginningOfMainBody();
pos_type const body_pos = par->beginningOfBody();
pos_type i = row.pos();
while (i <= last) {
if (main_body > 0 && i == main_body) {
if (body_pos > 0 && i == body_pos) {
w += font_metrics::width(layout->labelsep, getLabelFont(bview.buffer(), par));
if (par->isLineSeparator(i - 1))
w -= singleWidth(&bview, par, i - 1);
@ -840,7 +840,7 @@ int LyXText::fill(BufferView & bview, Row & row, int paper_width) const
w += singleWidth(&bview, par, i);
++i;
}
if (main_body > 0 && main_body > last) {
if (body_pos > 0 && body_pos > last) {
w += font_metrics::width(layout->labelsep, getLabelFont(bview.buffer(), par));
if (last >= 0 && par->isLineSeparator(last))
w -= singleWidth(&bview, par, last);
@ -857,7 +857,7 @@ int LyXText::fill(BufferView & bview, Row & row, int paper_width) const
// returns the minimum space a manual label needs on the screen in pixel
int LyXText::labelFill(BufferView & bview, Row const & row) const
{
pos_type last = row.par()->beginningOfMainBody();
pos_type last = row.par()->beginningOfBody();
lyx::Assert(last > 0);
@ -1572,7 +1572,7 @@ void LyXText::insertChar(BufferView * bview, char c)
return;
}
} else if (IsNewlineChar(c)) {
if (cursor.pos() <= cursor.par()->beginningOfMainBody()) {
if (cursor.pos() <= cursor.par()->beginningOfBody()) {
charInserted();
return;
}
@ -1775,11 +1775,11 @@ void LyXText::prepareToPrint(BufferView * bview,
nlh = row->numberOfLabelHfills();
// A manual label par (e.g. List) has an auto-hfill
// between the label text and the "main body" of the
// between the label text and the body of the
// paragraph too.
// But we don't want to do this auto hfill if the par
// is empty.
if (row->par()->size())
if (!row->par()->empty())
++nlh;
if (nlh && !row->par()->getLabelWidthString().empty()) {
@ -1849,15 +1849,15 @@ void LyXText::prepareToPrint(BufferView * bview,
computeBidiTables(bview->buffer(), row);
if (is_rtl) {
pos_type main_body = row->par()->beginningOfMainBody();
pos_type body_pos = row->par()->beginningOfBody();
pos_type last = row->lastPos();
if (main_body > 0 &&
(main_body - 1 > last ||
!row->par()->isLineSeparator(main_body - 1))) {
if (body_pos > 0 &&
(body_pos - 1 > last ||
!row->par()->isLineSeparator(body_pos - 1))) {
x += font_metrics::width(layout->labelsep,
getLabelFont(bview->buffer(), row->par()));
if (main_body - 1 <= last)
if (body_pos - 1 <= last)
x += fill_label_hfill;
}
}
@ -2586,7 +2586,7 @@ void LyXText::backspace(BufferView * bview)
// delete newlines at the beginning of paragraphs
while (!cursor.par()->empty() &&
cursor.par()->isNewline(cursor.pos()) &&
cursor.pos() == cursor.par()->beginningOfMainBody()) {
cursor.pos() == cursor.par()->beginningOfBody()) {
cursor.par()->erase(cursor.pos());
// refresh the positions
tmprow = row;
@ -2734,13 +2734,13 @@ LyXText::getColumnNearX(BufferView * bview, Row * row, int & x,
bool left_side = false;
pos_type main_body = row->par()->beginningOfMainBody();
pos_type body_pos = row->par()->beginningOfBody();
float last_tmpx = tmpx;
if (main_body > 0 &&
(main_body - 1 > last ||
!row->par()->isLineSeparator(main_body - 1)))
main_body = 0;
if (body_pos > 0 &&
(body_pos - 1 > last ||
!row->par()->isLineSeparator(body_pos - 1)))
body_pos = 0;
// check for empty row
if (!row->par()->size()) {
@ -2751,23 +2751,23 @@ LyXText::getColumnNearX(BufferView * bview, Row * row, int & x,
while (vc <= last && tmpx <= x) {
c = vis2log(vc);
last_tmpx = tmpx;
if (main_body > 0 && c == main_body-1) {
if (body_pos > 0 && c == body_pos-1) {
tmpx += fill_label_hfill +
font_metrics::width(layout->labelsep,
getLabelFont(bview->buffer(), row->par()));
if (row->par()->isLineSeparator(main_body - 1))
tmpx -= singleWidth(bview, row->par(), main_body-1);
if (row->par()->isLineSeparator(body_pos - 1))
tmpx -= singleWidth(bview, row->par(), body_pos-1);
}
if (row->hfillExpansion(c)) {
tmpx += singleWidth(bview, row->par(), c);
if (c >= main_body)
if (c >= body_pos)
tmpx += fill_hfill;
else
tmpx += fill_label_hfill;
} else if (row->par()->isSeparator(c)) {
tmpx += singleWidth(bview, row->par(), c);
if (c >= main_body)
if (c >= body_pos)
tmpx+= fill_separator;
} else {
tmpx += singleWidth(bview, row->par(), c);

View File

@ -158,7 +158,7 @@ LyXFont const LyXText::getFont(Buffer const * buf, Paragraph * par,
// We specialize the 95% common case:
if (!par->getDepth()) {
if (layout->labeltype == LABEL_MANUAL
&& pos < par->beginningOfMainBody()) {
&& pos < par->beginningOfBody()) {
// 1% goes here
LyXFont f = par->getFontSettings(buf->params, pos);
if (par->inInset())
@ -176,7 +176,7 @@ LyXFont const LyXText::getFont(Buffer const * buf, Paragraph * par,
LyXFont layoutfont;
if (pos < par->beginningOfMainBody()) {
if (pos < par->beginningOfBody()) {
// 1% goes here
layoutfont = layout->labelfont;
} else {
@ -251,7 +251,7 @@ void LyXText::setCharFont(Buffer const * buf, Paragraph * par,
// Get concrete layout font to reduce against
LyXFont layoutfont;
if (pos < par->beginningOfMainBody())
if (pos < par->beginningOfBody())
layoutfont = layout->labelfont;
else
layoutfont = layout->font;
@ -425,7 +425,7 @@ void LyXText::makeFontEntriesLayoutSpecific(Buffer const & buf,
LyXFont layoutfont;
for (pos_type pos = 0; pos < par.size(); ++pos) {
if (pos < par.beginningOfMainBody())
if (pos < par.beginningOfBody())
layoutfont = layout->labelfont;
else
layoutfont = layout->font;
@ -641,7 +641,7 @@ void LyXText::setFont(BufferView * bview, LyXFont const & font, bool toggleall)
if (!selection.set()) {
// Determine basis font
LyXFont layoutfont;
if (cursor.pos() < cursor.par()->beginningOfMainBody()) {
if (cursor.pos() < cursor.par()->beginningOfBody()) {
layoutfont = getLabelFont(bview->buffer(),
cursor.par());
} else {
@ -1836,33 +1836,33 @@ float LyXText::getCursorX(BufferView * bview, Row * row,
cursor_vpos = (bidi_level(pos) % 2 == 0)
? log2vis(pos) : log2vis(pos) + 1;
pos_type main_body = row->par()->beginningOfMainBody();
if ((main_body > 0) &&
((main_body-1 > last) ||
!row->par()->isLineSeparator(main_body-1)))
main_body = 0;
pos_type body_pos = row->par()->beginningOfBody();
if ((body_pos > 0) &&
((body_pos-1 > last) ||
!row->par()->isLineSeparator(body_pos-1)))
body_pos = 0;
for (pos_type vpos = row->pos(); vpos < cursor_vpos; ++vpos) {
pos_type pos = vis2log(vpos);
if (main_body > 0 && pos == main_body - 1) {
if (body_pos > 0 && pos == body_pos - 1) {
x += fill_label_hfill +
font_metrics::width(
row->par()->layout()->labelsep,
getLabelFont(bview->buffer(),
row->par()));
if (row->par()->isLineSeparator(main_body - 1))
if (row->par()->isLineSeparator(body_pos - 1))
x -= singleWidth(bview,
row->par(), main_body - 1);
row->par(), body_pos - 1);
}
if (row->hfillExpansion(pos)) {
x += singleWidth(bview, row->par(), pos);
if (pos >= main_body)
if (pos >= body_pos)
x += fill_hfill;
else
x += fill_label_hfill;
} else if (row->par()->isSeparator(pos)) {
x += singleWidth(bview, row->par(), pos);
if (pos >= main_body)
if (pos >= body_pos)
x += fill_separator;
} else
x += singleWidth(bview, row->par(), pos);