mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-23 05:25:26 +00:00
some \parbox improvements
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4796 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
d0cc00980d
commit
c6b1b59008
@ -1145,19 +1145,24 @@ bool MathCursor::goUpDown(bool up)
|
||||
while (1) {
|
||||
///lyxerr << "updown: We are in " << *par() << " idx: " << idx() << '\n';
|
||||
// ask inset first
|
||||
if (par()->idxUpDown(idx(), up)) {
|
||||
if (par()->idxUpDown(idx(), pos(), up)) {
|
||||
#ifdef WITH_WARNINGS
|
||||
#warning this code should be moved to individual insets that handle this
|
||||
#endif
|
||||
// position might have changed, so re-compute it
|
||||
getPos(xo, yo);
|
||||
// we found a cell that thinks it has something "below" us.
|
||||
///lyxerr << "updown: found inset that handles UpDown\n";
|
||||
//lyxerr << "updown: found inset that handles UpDown\n";
|
||||
xarray().boundingBox(xlow, xhigh, ylow, yhigh);
|
||||
// project (xo,yo) onto proper box
|
||||
///lyxerr << "\n xo: " << xo << " yo: " << yo
|
||||
/// << "\n xlow: " << xlow << " ylow: " << ylow
|
||||
/// << "\n xhigh: " << xhigh << " yhigh: " << yhigh;
|
||||
//lyxerr << "\n xo: " << xo << " yo: " << yo
|
||||
// << "\n xlow: " << xlow << " ylow: " << ylow
|
||||
// << "\n xhigh: " << xhigh << " yhigh: " << yhigh;
|
||||
xo = min(max(xo, xlow), xhigh);
|
||||
yo = min(max(yo, ylow), yhigh);
|
||||
///lyxerr << "\n xo2: " << xo << " yo2: " << yo << "\n";
|
||||
//lyxerr << "\n xo2: " << xo << " yo2: " << yo << "\n";
|
||||
bruteFind(xo, yo, xlow, xhigh, ylow, yhigh);
|
||||
///lyxerr << "updown: handled by final brute find\n";
|
||||
//lyxerr << "updown: handled by final brute find\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1194,9 +1199,8 @@ bool MathCursor::bruteFind
|
||||
while (1) {
|
||||
// avoid invalid nesting when selecting
|
||||
if (!selection_ || positionable(it.cursor(), Anchor_)) {
|
||||
MathCursorPos const & top = it.position();
|
||||
int xo = top.xpos();
|
||||
int yo = top.ypos();
|
||||
int xo, yo;
|
||||
it.position().getPos(xo, yo);
|
||||
if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
|
||||
double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
|
||||
// '<=' in order to take the last possible position
|
||||
|
@ -23,7 +23,7 @@ bool MathFracbaseInset::idxLeft(idx_type &, pos_type &) const
|
||||
}
|
||||
|
||||
|
||||
bool MathFracbaseInset::idxUpDown(idx_type & idx, bool up) const
|
||||
bool MathFracbaseInset::idxUpDown(idx_type & idx, pos_type &, bool up) const
|
||||
{
|
||||
MathInset::idx_type target = !up; // up ? 0 : 1, since upper cell has idx 0
|
||||
if (idx == target)
|
||||
|
@ -13,11 +13,11 @@ public:
|
||||
///
|
||||
MathFracbaseInset();
|
||||
///
|
||||
bool idxUpDown(idx_type &, bool up) const;
|
||||
bool idxUpDown(idx_type & idx, pos_type & pos, bool up) const;
|
||||
///
|
||||
bool idxLeft(idx_type &, pos_type &) const;
|
||||
bool idxLeft(idx_type & idx, pos_type & pos) const;
|
||||
///
|
||||
bool idxRight(idx_type &, pos_type &) const;
|
||||
bool idxRight(idx_type & idx, pos_type & pos) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -630,7 +630,7 @@ int MathGridInset::cellYOffset(idx_type idx) const
|
||||
}
|
||||
|
||||
|
||||
bool MathGridInset::idxUpDown(idx_type & idx, bool up) const
|
||||
bool MathGridInset::idxUpDown(idx_type & idx, pos_type &, bool up) const
|
||||
{
|
||||
if (up) {
|
||||
if (idx < ncols())
|
||||
|
@ -132,36 +132,36 @@ public:
|
||||
int cellYOffset(idx_type idx) const;
|
||||
|
||||
///
|
||||
bool idxUpDown(idx_type &, bool) const;
|
||||
bool idxUpDown(idx_type & idx, pos_type & pos, bool) const;
|
||||
///
|
||||
bool idxLeft(idx_type &, pos_type &) const;
|
||||
bool idxLeft(idx_type & idx, pos_type & pos) const;
|
||||
///
|
||||
bool idxRight(idx_type &, pos_type &) const;
|
||||
bool idxRight(idx_type & idx, pos_type & pos) const;
|
||||
///
|
||||
bool idxFirst(idx_type &, pos_type &) const;
|
||||
bool idxFirst(idx_type & idx, pos_type & pos) const;
|
||||
///
|
||||
bool idxLast(idx_type &, pos_type &) const;
|
||||
bool idxLast(idx_type & idx, pos_type & pos) const;
|
||||
///
|
||||
bool idxHome(idx_type &, pos_type &) const;
|
||||
bool idxHome(idx_type & idx, pos_type & pos) const;
|
||||
///
|
||||
bool idxEnd(idx_type &, pos_type &) const;
|
||||
bool idxEnd(idx_type & idx, pos_type & pos) const;
|
||||
///
|
||||
bool idxDelete(idx_type &);
|
||||
bool idxDelete(idx_type & idx);
|
||||
/// pulls cell after pressing erase
|
||||
void idxGlue(idx_type idx);
|
||||
|
||||
///
|
||||
virtual void addRow(row_type);
|
||||
virtual void addRow(row_type r);
|
||||
///
|
||||
virtual void delRow(row_type);
|
||||
virtual void delRow(row_type r);
|
||||
///
|
||||
virtual void addFancyRow(row_type r) { addRow(r); }
|
||||
///
|
||||
virtual void delFancyRow(row_type r) { addRow(r); }
|
||||
///
|
||||
virtual void addCol(col_type);
|
||||
virtual void addCol(col_type c);
|
||||
///
|
||||
virtual void delCol(col_type);
|
||||
virtual void delCol(col_type c);
|
||||
///
|
||||
virtual void addFancyCol(col_type c) { addCol(c); }
|
||||
///
|
||||
@ -169,7 +169,7 @@ public:
|
||||
///
|
||||
virtual void appendRow();
|
||||
///
|
||||
idx_type index(row_type row, col_type col) const;
|
||||
idx_type index(row_type r, col_type c) const;
|
||||
///
|
||||
std::vector<idx_type> idxBetween(idx_type from, idx_type to) const;
|
||||
///
|
||||
|
@ -143,7 +143,7 @@ bool MathInset::idxLeft(idx_type &, pos_type &) const
|
||||
}
|
||||
|
||||
|
||||
bool MathInset::idxUpDown(idx_type &, bool) const
|
||||
bool MathInset::idxUpDown(idx_type &, pos_type &, bool) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -128,11 +128,9 @@ public:
|
||||
virtual void dimensions(Dimension & dim) const;
|
||||
/// total height (== ascent + descent)
|
||||
virtual int height() const;
|
||||
/// get cursor position
|
||||
virtual void getPos(idx_type idx, pos_type pos, int & x, int & y) const;
|
||||
|
||||
/// Where should we go when we press the up or down cursor key?
|
||||
virtual bool idxUpDown(idx_type & idx, bool up) const;
|
||||
virtual bool idxUpDown(idx_type & idx, pos_type & pos, bool up) const;
|
||||
/// The left key
|
||||
virtual bool idxLeft(idx_type & idx, pos_type & pos) const;
|
||||
/// The right key
|
||||
@ -189,6 +187,8 @@ public:
|
||||
virtual int cellYOffset(idx_type) const { return 0; }
|
||||
/// can we enter this cell?
|
||||
virtual bool validCell(idx_type) const { return true; }
|
||||
/// get coordinates
|
||||
virtual void getPos(idx_type idx, pos_type pos, int & x, int & y) const;
|
||||
|
||||
/// identifies certain types of insets
|
||||
virtual MathAMSArrayInset * asAMSArrayInset() { return 0; }
|
||||
|
@ -160,7 +160,7 @@ void MathMacro::dump() const
|
||||
}
|
||||
|
||||
|
||||
bool MathMacro::idxUpDown(idx_type & idx, bool up) const
|
||||
bool MathMacro::idxUpDown(idx_type & idx, pos_type &, bool up) const
|
||||
{
|
||||
pos_type pos;
|
||||
return
|
||||
|
@ -51,11 +51,11 @@ public:
|
||||
void dump() const;
|
||||
|
||||
///
|
||||
bool idxUpDown(idx_type &, bool up) const;
|
||||
bool idxUpDown(idx_type & idx, pos_type & pos, bool up) const;
|
||||
///
|
||||
bool idxLeft(idx_type &, pos_type &) const;
|
||||
bool idxLeft(idx_type & idx, pos_type & pos) const;
|
||||
///
|
||||
bool idxRight(idx_type &, pos_type &) const;
|
||||
bool idxRight(idx_type & idx, pos_type & pos) const;
|
||||
|
||||
///
|
||||
void validate(LaTeXFeatures &) const;
|
||||
|
@ -50,10 +50,11 @@ MathArray const & MathNestInset::cell(idx_type i) const
|
||||
|
||||
void MathNestInset::getPos(idx_type idx, pos_type pos, int & x, int & y) const
|
||||
{
|
||||
x = cells_[idx].xo() + cells_[idx].pos2x(pos);
|
||||
y = cells_[idx].yo();
|
||||
MathXArray const & ar = xcell(idx);
|
||||
x = ar.xo() + ar.pos2x(pos);
|
||||
y = ar.yo();
|
||||
// move cursor visually into empty cells ("blue rectangles");
|
||||
if (!cells_[idx].data().size())
|
||||
if (cell(idx).empty())
|
||||
x += 2;
|
||||
}
|
||||
|
||||
|
@ -35,10 +35,16 @@ void MathParboxInset::setWidth(string const & w)
|
||||
}
|
||||
|
||||
|
||||
int MathParboxInset::screenrows() const
|
||||
{
|
||||
return rows_.size();
|
||||
}
|
||||
|
||||
|
||||
int MathParboxInset::pos2row(pos_type pos) const
|
||||
{
|
||||
for (int r = 0, n = rows_.size(); r < n; ++r)
|
||||
if (pos >= rows_[r].begin && pos < rows_[r].end)
|
||||
if (pos >= rows_[r].begin && pos <= rows_[r].end)
|
||||
return r;
|
||||
lyxerr << "illegal row for pos " << pos << "\n";
|
||||
return 0;
|
||||
@ -48,12 +54,33 @@ int MathParboxInset::pos2row(pos_type pos) const
|
||||
void MathParboxInset::getPos(idx_type idx, pos_type pos, int & x, int & y) const
|
||||
{
|
||||
int const r = pos2row(pos);
|
||||
//lyxerr << "found cursor at pos " << pos << " in row " << r << "\n";
|
||||
x = cells_[0].xo() + cells_[0].pos2x(rows_[r].begin, pos, rows_[r].glue);
|
||||
y = cells_[0].yo() + rows_[r].yo;
|
||||
MathXArray const & ar = cells_[idx];
|
||||
x = ar.xo() + ar.pos2x(rows_[r].begin, pos, rows_[r].glue);
|
||||
y = ar.yo() + rows_[r].yo;
|
||||
// move cursor visually into empty cells ("blue rectangles");
|
||||
if (cell(0).empty())
|
||||
x += 2;
|
||||
//lyxerr << "getPos cursor at pos " << pos << " in row " << r
|
||||
// << " x: " << x << " y: " << y << "\n";
|
||||
}
|
||||
|
||||
|
||||
bool MathParboxInset::idxUpDown(idx_type & idx, pos_type & pos, bool up) const
|
||||
{
|
||||
// try to move only one screen row up or down if possible
|
||||
int row = pos2row(pos);
|
||||
int const x = cells_[idx].pos2x(rows_[row].begin, pos, rows_[row].glue);
|
||||
if (up) {
|
||||
if (row == 0)
|
||||
return false;
|
||||
--row;
|
||||
} else {
|
||||
++row;
|
||||
if (row == screenrows())
|
||||
return false;
|
||||
}
|
||||
pos = xcell(0).x2pos(rows_[row].begin, x, rows_[row].glue);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -120,13 +147,16 @@ void MathParboxInset::metrics(MathMetricsInfo & mi) const
|
||||
if (spaces) {
|
||||
// but we had a space break before this position.
|
||||
// so retreat to this position
|
||||
int glue = lyx_width_ - safe.w + dims[safepos].w;
|
||||
row.dim = safe;
|
||||
row.glue = (lyx_width_ - safe.w) / spaces;
|
||||
row.glue = glue / spaces;
|
||||
row.begin = begin;
|
||||
row.end = safepos; // this is position of the safe space
|
||||
i = safepos; // i gets incremented at end of loop
|
||||
begin = i + 1; // next chunk starts after the space
|
||||
//lyxerr << "... but had safe pos. glue: " << row.glue << "\n";
|
||||
//lyxerr << " safe.w: " << safe.w
|
||||
// << " dim.w: " << dims[safepos].w << " spaces: " << spaces << "\n";
|
||||
spaces = 0;
|
||||
} else {
|
||||
lyxerr << "... without safe pos\n";
|
||||
@ -160,6 +190,7 @@ void MathParboxInset::metrics(MathMetricsInfo & mi) const
|
||||
dim_.a = rows_.front().dim.a;
|
||||
dim_.d = rows_.back().dim.d + yo;
|
||||
metricsMarkers();
|
||||
xcell(0).setDim(dim_);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,11 @@ public:
|
||||
void setWidth(string const & width);
|
||||
///
|
||||
void setPosition(string const & pos);
|
||||
/// moves cursor up or down
|
||||
bool idxUpDown(idx_type &, pos_type & pos, bool up) const;
|
||||
private:
|
||||
/// number of rows on screen
|
||||
int screenrows() const;
|
||||
/// row corresponding to given position
|
||||
int pos2row(pos_type pos) const;
|
||||
/// width on screen
|
||||
|
@ -51,15 +51,9 @@ MathXArray & MathCursorPos::xcell() const
|
||||
}
|
||||
|
||||
|
||||
int MathCursorPos::xpos() const
|
||||
void MathCursorPos::getPos(int & x, int & y) const
|
||||
{
|
||||
return xcell().xo() + xcell().pos2x(pos_);
|
||||
}
|
||||
|
||||
|
||||
int MathCursorPos::ypos() const
|
||||
{
|
||||
return xcell().yo();
|
||||
par_->getPos(idx_, pos_, x, y);
|
||||
}
|
||||
|
||||
|
||||
|
@ -21,10 +21,8 @@ public:
|
||||
MathXArray & xcell() const;
|
||||
/// returns xcell corresponding to this position
|
||||
MathXArray & xcell(MathArray::idx_type idx) const;
|
||||
///
|
||||
int xpos() const;
|
||||
///
|
||||
int ypos() const;
|
||||
/// gets screen position of the thing
|
||||
void getPos(int & x, int & y) const;
|
||||
|
||||
public:
|
||||
/// pointer to an inset
|
||||
|
@ -43,13 +43,13 @@ void MathRootInset::metrics(MathMetricsInfo & mi) const
|
||||
}
|
||||
|
||||
|
||||
void MathRootInset::draw(MathPainterInfo & pain, int x, int y) const
|
||||
void MathRootInset::draw(MathPainterInfo & pi, int x, int y) const
|
||||
{
|
||||
int const w = xcell(0).width();
|
||||
// the "exponent"
|
||||
xcell(0).draw(pain, x, y - 5 - xcell(0).descent());
|
||||
xcell(0).draw(pi, x, y - 5 - xcell(0).descent());
|
||||
// the "base"
|
||||
xcell(1).draw(pain, x + w + 8, y);
|
||||
xcell(1).draw(pi, x + w + 8, y);
|
||||
int const a = ascent();
|
||||
int const d = descent();
|
||||
int xp[5];
|
||||
@ -59,7 +59,7 @@ void MathRootInset::draw(MathPainterInfo & pain, int x, int y) const
|
||||
xp[2] = x + w; yp[2] = y + d;
|
||||
xp[3] = x + w - 2; yp[3] = y + (d - a)/2 + 2;
|
||||
xp[4] = x; yp[4] = y + (d - a)/2 + 2;
|
||||
pain.pain.lines(xp, yp, 5, LColor::math);
|
||||
pi.pain.lines(xp, yp, 5, LColor::math);
|
||||
}
|
||||
|
||||
|
||||
@ -75,7 +75,7 @@ void MathRootInset::normalize(NormalStream & os) const
|
||||
}
|
||||
|
||||
|
||||
bool MathRootInset::idxUpDown(idx_type & idx, bool up) const
|
||||
bool MathRootInset::idxUpDown(idx_type & idx, pos_type &, bool up) const
|
||||
{
|
||||
bool target = !up; // up ? 0 : 1;
|
||||
if (idx == target)
|
||||
|
@ -32,11 +32,11 @@ public:
|
||||
///
|
||||
MathInset * clone() const;
|
||||
///
|
||||
bool idxUpDown(idx_type & idx, bool up) const;
|
||||
bool idxUpDown(idx_type & idx, pos_type & pos, bool up) const;
|
||||
///
|
||||
void metrics(MathMetricsInfo & st) const;
|
||||
void metrics(MathMetricsInfo & mi) const;
|
||||
///
|
||||
void draw(MathPainterInfo &, int x, int y) const;
|
||||
void draw(MathPainterInfo & pi, int x, int y) const;
|
||||
|
||||
///
|
||||
void write(WriteStream & os) const;
|
||||
|
@ -42,7 +42,7 @@ Dimension const & MathXArray::metrics(MathMetricsInfo & mi) const
|
||||
|
||||
if (data_.empty()) {
|
||||
mathed_char_dim(mi.base.font, 'I', dim_);
|
||||
return dim_;;
|
||||
return dim_;
|
||||
}
|
||||
|
||||
dim_.clear();
|
||||
@ -98,7 +98,6 @@ void MathXArray::metricsExternal(MathMetricsInfo & mi,
|
||||
v.push_back(d);
|
||||
}
|
||||
}
|
||||
|
||||
//for (int i = 0; i < data_.size(); ++i)
|
||||
// lyxerr << "i: " << i << " dim: " << v[i] << endl;
|
||||
//lyxerr << "MathXArray::metrics(): '" << dim_ << "\n";
|
||||
@ -241,6 +240,7 @@ int MathXArray::pos2x(size_type pos) const
|
||||
return pos2x(0, pos, 0);
|
||||
}
|
||||
|
||||
|
||||
int MathXArray::pos2x(size_type pos1, size_type pos2, int glue) const
|
||||
{
|
||||
int x = 0;
|
||||
@ -266,26 +266,34 @@ int MathXArray::pos2x(size_type pos1, size_type pos2, int glue) const
|
||||
|
||||
MathArray::size_type MathXArray::x2pos(int targetx) const
|
||||
{
|
||||
const_iterator it = begin();
|
||||
return x2pos(0, targetx, 0);
|
||||
}
|
||||
|
||||
|
||||
MathArray::size_type MathXArray::x2pos(size_type startpos, int targetx,
|
||||
int glue) const
|
||||
{
|
||||
const_iterator it = begin() + startpos;
|
||||
int lastx = 0;
|
||||
int currx = 0;
|
||||
for (; currx < targetx && it < end(); ++it) {
|
||||
size_type pos = it - begin();
|
||||
lastx = currx;
|
||||
|
||||
int wid = 0;
|
||||
MathInset const * p = it->nucleus();
|
||||
if (p->getChar() == ' ')
|
||||
currx += glue;
|
||||
MathScriptInset const * q = 0;
|
||||
if (it + 1 != end())
|
||||
q = asScript(it);
|
||||
if (q) {
|
||||
wid = q->width2(p);
|
||||
currx += q->width2(p);
|
||||
++it;
|
||||
} else
|
||||
wid = p->width();
|
||||
|
||||
currx += wid;
|
||||
} else {
|
||||
currx += p->width();
|
||||
}
|
||||
}
|
||||
if (abs(lastx - targetx) < abs(currx - targetx) && it != begin())
|
||||
if (abs(lastx - targetx) < abs(currx - targetx) && it != begin() + startpos)
|
||||
--it;
|
||||
return it - begin();
|
||||
}
|
||||
|
@ -77,6 +77,8 @@ public:
|
||||
int pos2x(size_type pos1, size_type pos2, int glue) const;
|
||||
/// returns position of given x coordinate
|
||||
size_type x2pos(int pos) const;
|
||||
/// returns position of given x coordinate fstarting from a certain pos
|
||||
size_type x2pos(size_type startpos, int targetx, int glue) const;
|
||||
/// returns distance of this cell to the point given by x and y
|
||||
// assumes valid position and size cache
|
||||
int dist(int x, int y) const;
|
||||
@ -91,6 +93,8 @@ public:
|
||||
int width() const { return dim_.w; }
|
||||
/// dimensions of cell
|
||||
Dimension const & dim() const { return dim_; }
|
||||
/// dimensions of cell
|
||||
void setDim(Dimension const & d) const { dim_ = d; }
|
||||
/// bounding box of this cell
|
||||
void boundingBox(int & xlow, int & xhigh, int & ylow, int & yhigh);
|
||||
/// find best position to do things
|
||||
|
Loading…
Reference in New Issue
Block a user