mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-30 05:12:40 +00:00
code cleanup
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2890 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
873de089f0
commit
c804ecd29a
@ -1,3 +1,21 @@
|
|||||||
|
2001-10-16 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
|
||||||
|
|
||||||
|
* text2.C (setCursorFromCoordinates): use Paragraph::size_type
|
||||||
|
|
||||||
|
* lyxtext.h: change type of refresh_pos to Paragraph::size_type;
|
||||||
|
change return type of getColumnNearX.
|
||||||
|
|
||||||
|
|
||||||
|
* text.C (changeRegionCase): use uppercase/lowercase instead of
|
||||||
|
toupper/tolower.
|
||||||
|
(leftMargin):
|
||||||
|
(rightMargin): simplify code by factoring out the uses of
|
||||||
|
textclasslist.
|
||||||
|
(labelFill):
|
||||||
|
(numberOfHfills):
|
||||||
|
(setHeightOfRow):
|
||||||
|
(appendParagraph): use Paragraph::size_type
|
||||||
|
|
||||||
2001-10-15 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
|
2001-10-15 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
|
||||||
|
|
||||||
* vspace.C (asLatexString): add a missing break
|
* vspace.C (asLatexString): add a missing break
|
||||||
|
@ -194,7 +194,7 @@ public:
|
|||||||
///
|
///
|
||||||
mutable Row * refresh_row;
|
mutable Row * refresh_row;
|
||||||
///
|
///
|
||||||
int refresh_pos;
|
Paragraph::size_type refresh_pos;
|
||||||
|
|
||||||
/// give and set the LyXText status
|
/// give and set the LyXText status
|
||||||
text_status status() const;
|
text_status status() const;
|
||||||
@ -217,7 +217,7 @@ public:
|
|||||||
/** returns the column near the specified x-coordinate of the row
|
/** returns the column near the specified x-coordinate of the row
|
||||||
x is set to the real beginning of this column
|
x is set to the real beginning of this column
|
||||||
*/
|
*/
|
||||||
int getColumnNearX(BufferView *, Row * row,
|
Paragraph::size_type getColumnNearX(BufferView *, Row * row,
|
||||||
int & x, bool & boundary) const;
|
int & x, bool & boundary) const;
|
||||||
|
|
||||||
/** returns a pointer to a specified row. y is set to the beginning
|
/** returns a pointer to a specified row. y is set to the beginning
|
||||||
|
101
src/text.C
101
src/text.C
@ -9,8 +9,8 @@
|
|||||||
* ====================================================== */
|
* ====================================================== */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <cstdlib>
|
//#include <cstdlib> //these two do not seem useful anymore (JMarc)
|
||||||
#include <cctype>
|
//#include <cctype>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "lyxtext.h"
|
#include "lyxtext.h"
|
||||||
@ -595,20 +595,15 @@ void LyXText::draw(BufferView * bview, Row const * row,
|
|||||||
// exactly the label-width.
|
// exactly the label-width.
|
||||||
int LyXText::leftMargin(BufferView * bview, Row const * row) const
|
int LyXText::leftMargin(BufferView * bview, Row const * row) const
|
||||||
{
|
{
|
||||||
LyXLayout const & layout =
|
LyXTextClass const & tclass =
|
||||||
textclasslist.Style(bview->buffer()->params.textclass,
|
textclasslist.TextClass(bview->buffer()->params.textclass);
|
||||||
row->par()->getLayout());
|
LyXLayout const & layout = tclass[row->par()->getLayout()];
|
||||||
|
|
||||||
string parindent = layout.parindent;
|
string parindent = layout.parindent;
|
||||||
|
|
||||||
int x = LYX_PAPER_MARGIN;
|
int x = LYX_PAPER_MARGIN;
|
||||||
|
|
||||||
x += lyxfont::signedWidth(textclasslist
|
x += lyxfont::signedWidth(tclass.leftmargin(), tclass.defaultfont());
|
||||||
.TextClass(bview->buffer()->params.textclass)
|
|
||||||
.leftmargin(),
|
|
||||||
textclasslist
|
|
||||||
.TextClass(bview->buffer()->params.textclass)
|
|
||||||
.defaultfont());
|
|
||||||
|
|
||||||
// this is the way, LyX handles the LaTeX-Environments.
|
// this is the way, LyX handles the LaTeX-Environments.
|
||||||
// I have had this idea very late, so it seems to be a
|
// I have had this idea very late, so it seems to be a
|
||||||
@ -620,9 +615,7 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
|
|||||||
Paragraph * newpar = row->par()
|
Paragraph * newpar = row->par()
|
||||||
->depthHook(row->par()->getDepth());
|
->depthHook(row->par()->getDepth());
|
||||||
if (newpar &&
|
if (newpar &&
|
||||||
textclasslist.Style(bview->buffer()->params.textclass,
|
tclass[newpar->getLayout()].nextnoindent)
|
||||||
newpar->getLayout())
|
|
||||||
.nextnoindent)
|
|
||||||
parindent.erase();
|
parindent.erase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -636,9 +629,7 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
|
|||||||
|
|
||||||
// check wether it is a sufficent paragraph
|
// check wether it is a sufficent paragraph
|
||||||
if (newpar
|
if (newpar
|
||||||
&& textclasslist
|
&& tclass[newpar->getLayout()].isEnvironment()) {
|
||||||
.Style(bview->buffer()->params.textclass,
|
|
||||||
newpar->getLayout()).isEnvironment()) {
|
|
||||||
Row dummyrow;
|
Row dummyrow;
|
||||||
dummyrow.par(newpar);
|
dummyrow.par(newpar);
|
||||||
dummyrow.pos(newpar->size());
|
dummyrow.pos(newpar->size());
|
||||||
@ -655,9 +646,7 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
|
|||||||
if (newpar->params().noindent())
|
if (newpar->params().noindent())
|
||||||
parindent.erase();
|
parindent.erase();
|
||||||
else
|
else
|
||||||
parindent = textclasslist
|
parindent = tclass[newpar->getLayout()].parindent;
|
||||||
.Style(bview->buffer()->params.textclass,
|
|
||||||
newpar->getLayout()).parindent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -667,10 +656,7 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
|
|||||||
case MARGIN_DYNAMIC:
|
case MARGIN_DYNAMIC:
|
||||||
if (!layout.leftmargin.empty()) {
|
if (!layout.leftmargin.empty()) {
|
||||||
x += lyxfont::signedWidth(layout.leftmargin,
|
x += lyxfont::signedWidth(layout.leftmargin,
|
||||||
textclasslist
|
tclass.defaultfont());
|
||||||
.TextClass(bview->buffer()->params.
|
|
||||||
textclass)
|
|
||||||
.defaultfont());
|
|
||||||
}
|
}
|
||||||
if (!row->par()->getLabelstring().empty()) {
|
if (!row->par()->getLabelstring().empty()) {
|
||||||
x += lyxfont::signedWidth(layout.labelindent,
|
x += lyxfont::signedWidth(layout.labelindent,
|
||||||
@ -691,7 +677,7 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MARGIN_STATIC:
|
case MARGIN_STATIC:
|
||||||
x += lyxfont::signedWidth(layout.leftmargin, textclasslist.TextClass(bview->buffer()->params.textclass).defaultfont()) * 4
|
x += lyxfont::signedWidth(layout.leftmargin, tclass.defaultfont()) * 4
|
||||||
/ (row->par()->getDepth() + 4);
|
/ (row->par()->getDepth() + 4);
|
||||||
break;
|
break;
|
||||||
case MARGIN_FIRST_DYNAMIC:
|
case MARGIN_FIRST_DYNAMIC:
|
||||||
@ -743,15 +729,13 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
x += lyxfont::signedWidth(layout.leftmargin,
|
x += lyxfont::signedWidth(layout.leftmargin,
|
||||||
textclasslist
|
tclass.defaultfont());
|
||||||
.TextClass(bview->buffer()->params.textclass)
|
|
||||||
.defaultfont());
|
|
||||||
x += minfill;
|
x += minfill;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int align; // wrong type
|
LyXAlignment align; // wrong type
|
||||||
|
|
||||||
if (row->par()->params().align() == LYX_ALIGN_LAYOUT)
|
if (row->par()->params().align() == LYX_ALIGN_LAYOUT)
|
||||||
align = layout.align;
|
align = layout.align;
|
||||||
@ -772,16 +756,10 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
|
|||||||
bview->buffer()->params.paragraph_separation ==
|
bview->buffer()->params.paragraph_separation ==
|
||||||
BufferParams::PARSEP_INDENT))
|
BufferParams::PARSEP_INDENT))
|
||||||
x += lyxfont::signedWidth(parindent,
|
x += lyxfont::signedWidth(parindent,
|
||||||
textclasslist
|
tclass.defaultfont());
|
||||||
.TextClass(bview->buffer()->params
|
|
||||||
.textclass)
|
|
||||||
.defaultfont());
|
|
||||||
else if (layout.labeltype == LABEL_BIBLIO) {
|
else if (layout.labeltype == LABEL_BIBLIO) {
|
||||||
// ale970405 Right width for bibitems
|
// ale970405 Right width for bibitems
|
||||||
x += bibitemMaxWidth(bview,textclasslist
|
x += bibitemMaxWidth(bview, tclass.defaultfont());
|
||||||
.TextClass(bview->buffer()->params
|
|
||||||
.textclass)
|
|
||||||
.defaultfont());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return x;
|
return x;
|
||||||
@ -790,17 +768,13 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
|
|||||||
|
|
||||||
int LyXText::rightMargin(Buffer const * buf, Row const * row) const
|
int LyXText::rightMargin(Buffer const * buf, Row const * row) const
|
||||||
{
|
{
|
||||||
LyXLayout const & layout =
|
LyXTextClass const & tclass =
|
||||||
textclasslist.Style(buf->params.textclass,
|
textclasslist.TextClass(buf->params.textclass);
|
||||||
row->par()->getLayout());
|
LyXLayout const & layout = tclass[row->par()->getLayout()];
|
||||||
|
|
||||||
int x = LYX_PAPER_MARGIN
|
int x = LYX_PAPER_MARGIN
|
||||||
+ lyxfont::signedWidth(textclasslist
|
+ lyxfont::signedWidth(tclass.rightmargin(),
|
||||||
.TextClass(buf->params.textclass)
|
tclass.defaultfont());
|
||||||
.rightmargin(),
|
|
||||||
textclasslist
|
|
||||||
.TextClass(buf->params.textclass)
|
|
||||||
.defaultfont());
|
|
||||||
|
|
||||||
// this is the way, LyX handles the LaTeX-Environments.
|
// this is the way, LyX handles the LaTeX-Environments.
|
||||||
// I have had this idea very late, so it seems to be a
|
// I have had this idea very late, so it seems to be a
|
||||||
@ -819,9 +793,7 @@ int LyXText::rightMargin(Buffer const * buf, Row const * row) const
|
|||||||
|
|
||||||
// check wether it is a sufficent paragraph
|
// check wether it is a sufficent paragraph
|
||||||
if (newpar
|
if (newpar
|
||||||
&& textclasslist.Style(buf->params.textclass,
|
&& tclass[newpar->getLayout()].isEnvironment()) {
|
||||||
newpar->getLayout())
|
|
||||||
.isEnvironment()) {
|
|
||||||
Row dummyrow;
|
Row dummyrow;
|
||||||
dummyrow.par(newpar);
|
dummyrow.par(newpar);
|
||||||
dummyrow.pos(0);
|
dummyrow.pos(0);
|
||||||
@ -836,10 +808,8 @@ int LyXText::rightMargin(Buffer const * buf, Row const * row) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
//lyxerr << "rightmargin: " << layout->rightmargin << endl;
|
//lyxerr << "rightmargin: " << layout->rightmargin << endl;
|
||||||
x += lyxfont::signedWidth(layout.rightmargin, textclasslist
|
x += lyxfont::signedWidth(layout.rightmargin, tclass.defaultfont())
|
||||||
.TextClass(buf->params.textclass)
|
* 4 / (row->par()->getDepth() + 4);
|
||||||
.defaultfont()) * 4 / (row->par()->getDepth()
|
|
||||||
+ 4);
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -881,7 +851,8 @@ LyXText::nextBreakPoint(BufferView * bview, Row const * row, int width) const
|
|||||||
Paragraph::size_type const main_body =
|
Paragraph::size_type const main_body =
|
||||||
beginningOfMainBody(bview->buffer(), par);
|
beginningOfMainBody(bview->buffer(), par);
|
||||||
LyXLayout const & layout =
|
LyXLayout const & layout =
|
||||||
textclasslist.Style(bview->buffer()->params.textclass, par->getLayout());
|
textclasslist.Style(bview->buffer()->params.textclass,
|
||||||
|
par->getLayout());
|
||||||
Paragraph::size_type i = pos;
|
Paragraph::size_type i = pos;
|
||||||
|
|
||||||
if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
|
if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) {
|
||||||
@ -1053,7 +1024,7 @@ int LyXText::labelFill(BufferView * bview, Row const * row) const
|
|||||||
--last;
|
--last;
|
||||||
|
|
||||||
int w = 0;
|
int w = 0;
|
||||||
int i = row->pos();
|
Paragraph::size_type i = row->pos();
|
||||||
while (i <= last) {
|
while (i <= last) {
|
||||||
w += singleWidth(bview, row->par(), i);
|
w += singleWidth(bview, row->par(), i);
|
||||||
++i;
|
++i;
|
||||||
@ -1102,7 +1073,8 @@ int LyXText::numberOfHfills(Buffer const * buf, Row const * row) const
|
|||||||
|
|
||||||
first = max(first, beginningOfMainBody(buf, row->par()));
|
first = max(first, beginningOfMainBody(buf, row->par()));
|
||||||
int n = 0;
|
int n = 0;
|
||||||
for (int p = first; p <= last; ++p) { // last, because the end is ignored!
|
for (Paragraph::size_type p = first; p <= last; ++p) {
|
||||||
|
// last, because the end is ignored!
|
||||||
if (row->par()->isHfill(p)) {
|
if (row->par()->isHfill(p)) {
|
||||||
++n;
|
++n;
|
||||||
}
|
}
|
||||||
@ -1233,12 +1205,12 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row_ptr) const
|
|||||||
int maxdesc = int(lyxfont::maxDescent(font) *
|
int maxdesc = int(lyxfont::maxDescent(font) *
|
||||||
layout.spacing.getValue() *
|
layout.spacing.getValue() *
|
||||||
spacing_val);
|
spacing_val);
|
||||||
int const pos_end = rowLast(row_ptr);
|
Paragraph::size_type const pos_end = rowLast(row_ptr);
|
||||||
int labeladdon = 0;
|
int labeladdon = 0;
|
||||||
int maxwidth = 0;
|
int maxwidth = 0;
|
||||||
|
|
||||||
// Check if any insets are larger
|
// Check if any insets are larger
|
||||||
for (int pos = row_ptr->pos(); pos <= pos_end; ++pos) {
|
for (Paragraph::size_type pos = row_ptr->pos(); pos <= pos_end; ++pos) {
|
||||||
if (row_ptr->par()->getChar(pos) == Paragraph::META_INSET) {
|
if (row_ptr->par()->getChar(pos) == Paragraph::META_INSET) {
|
||||||
tmpfont = getFont(bview->buffer(), row_ptr->par(), pos);
|
tmpfont = getFont(bview->buffer(), row_ptr->par(), pos);
|
||||||
tmpinset = row_ptr->par()->getInset(pos);
|
tmpinset = row_ptr->par()->getInset(pos);
|
||||||
@ -1506,10 +1478,10 @@ void LyXText::appendParagraph(BufferView * bview, Row * row) const
|
|||||||
|
|
||||||
// The last character position of a paragraph is an invariant so we can
|
// The last character position of a paragraph is an invariant so we can
|
||||||
// safely get it here. (Asger)
|
// safely get it here. (Asger)
|
||||||
int const lastposition = row->par()->size();
|
Paragraph::size_type const lastposition = row->par()->size();
|
||||||
do {
|
do {
|
||||||
// Get the next breakpoint
|
// Get the next breakpoint
|
||||||
int z = nextBreakPoint(bview, row, workWidth(bview));
|
Paragraph::size_type z = nextBreakPoint(bview, row, workWidth(bview));
|
||||||
|
|
||||||
Row * tmprow = row;
|
Row * tmprow = row;
|
||||||
|
|
||||||
@ -2505,14 +2477,14 @@ void LyXText::changeRegionCase(BufferView * bview,
|
|||||||
if (!IsInsetChar(c) && !IsHfillChar(c)) {
|
if (!IsInsetChar(c) && !IsHfillChar(c)) {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case text_lowercase:
|
case text_lowercase:
|
||||||
c = tolower(c);
|
c = lowercase(c);
|
||||||
break;
|
break;
|
||||||
case text_capitalization:
|
case text_capitalization:
|
||||||
c = toupper(c);
|
c = uppercase(c);
|
||||||
action = text_lowercase;
|
action = text_lowercase;
|
||||||
break;
|
break;
|
||||||
case text_uppercase:
|
case text_uppercase:
|
||||||
c = toupper(c);
|
c = uppercase(c);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3567,7 +3539,8 @@ int LyXText::defaultHeight() const
|
|||||||
|
|
||||||
/* returns the column near the specified x-coordinate of the row
|
/* returns the column near the specified x-coordinate of the row
|
||||||
* x is set to the real beginning of this column */
|
* x is set to the real beginning of this column */
|
||||||
int LyXText::getColumnNearX(BufferView * bview, Row * row, int & x,
|
Paragraph::size_type
|
||||||
|
LyXText::getColumnNearX(BufferView * bview, Row * row, int & x,
|
||||||
bool & boundary) const
|
bool & boundary) const
|
||||||
{
|
{
|
||||||
float tmpx = 0.0;
|
float tmpx = 0.0;
|
||||||
|
11
src/text2.C
11
src/text2.C
@ -1760,16 +1760,16 @@ void LyXText::cutSelection(BufferView * bview, bool doclear, bool realcut)
|
|||||||
int pos = selection.end.pos();
|
int pos = selection.end.pos();
|
||||||
CutAndPaste::cutSelection(selection.start.par(), &endpar,
|
CutAndPaste::cutSelection(selection.start.par(), &endpar,
|
||||||
selection.start.pos(), pos,
|
selection.start.pos(), pos,
|
||||||
bview->buffer()->params.textclass, doclear,
|
bview->buffer()->params.textclass,
|
||||||
realcut);
|
doclear, realcut);
|
||||||
selection.end.pos(pos);
|
selection.end.pos(pos);
|
||||||
} else {
|
} else {
|
||||||
endpar = selection.end.par();
|
endpar = selection.end.par();
|
||||||
int pos = selection.end.pos();
|
int pos = selection.end.pos();
|
||||||
CutAndPaste::cutSelection(selection.start.par(), &endpar,
|
CutAndPaste::cutSelection(selection.start.par(), &endpar,
|
||||||
selection.start.pos(), pos,
|
selection.start.pos(), pos,
|
||||||
bview->buffer()->params.textclass, doclear,
|
bview->buffer()->params.textclass,
|
||||||
realcut);
|
doclear, realcut);
|
||||||
cursor.par(endpar);
|
cursor.par(endpar);
|
||||||
selection.end.par(endpar);
|
selection.end.par(endpar);
|
||||||
selection.end.pos(pos);
|
selection.end.pos(pos);
|
||||||
@ -2273,7 +2273,8 @@ void LyXText::setCursorFromCoordinates(BufferView * bview, LyXCursor & cur,
|
|||||||
|
|
||||||
Row * row = getRowNearY(y);
|
Row * row = getRowNearY(y);
|
||||||
bool bound = false;
|
bool bound = false;
|
||||||
int const column = getColumnNearX(bview, row, x, bound);
|
Paragraph::size_type const column = getColumnNearX(bview, row, x,
|
||||||
|
bound);
|
||||||
|
|
||||||
cur.par(row->par());
|
cur.par(row->par());
|
||||||
cur.pos(row->pos() + column);
|
cur.pos(row->pos() + column);
|
||||||
|
Loading…
Reference in New Issue
Block a user