make boundary property an iterator property instead of a CursorSlice property

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10214 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2005-07-15 15:49:40 +00:00
parent d825686252
commit 41ecabf519
24 changed files with 143 additions and 125 deletions

View File

@ -476,7 +476,7 @@ void BufferView::Pimpl::scrollDocView(int value)
cur.clearSelection(); cur.clearSelection();
break; break;
case bv_funcs::CUR_INSIDE: case bv_funcs::CUR_INSIDE:
int const y = bv_funcs::getPos(cur).y_; int const y = bv_funcs::getPos(cur, cur.boundary()).y_;
int const newy = min(last, max(y, first)); int const newy = min(last, max(y, first));
if (y != newy) { if (y != newy) {
cur.reset(buffer_->inset()); cur.reset(buffer_->inset());
@ -596,7 +596,7 @@ bool BufferView::Pimpl::fitCursor()
LyXFont const font = cursor_.getFont(); LyXFont const font = cursor_.getFont();
int const asc = font_metrics::maxAscent(font); int const asc = font_metrics::maxAscent(font);
int const des = font_metrics::maxDescent(font); int const des = font_metrics::maxDescent(font);
Point const p = bv_funcs::getPos(cursor_); Point const p = bv_funcs::getPos(cursor_, cursor_.boundary());
if (p.y_ - asc >= 0 && p.y_ + des < workarea().workHeight()) if (p.y_ - asc >= 0 && p.y_ + des < workarea().workHeight())
return false; return false;
} }
@ -766,8 +766,8 @@ void BufferView::Pimpl::center()
bot.text()->redoParagraph(pit); bot.text()->redoParagraph(pit);
Paragraph const & par = bot.text()->paragraphs()[pit]; Paragraph const & par = bot.text()->paragraphs()[pit];
anchor_ref_ = pit; anchor_ref_ = pit;
offset_ref_ = bv_funcs::coordOffset(cursor_).y_ + par.ascent() offset_ref_ = bv_funcs::coordOffset(cursor_, cursor_.boundary()).y_
- workarea().workHeight() / 2; + par.ascent() - workarea().workHeight() / 2;
} }

View File

@ -152,7 +152,7 @@ bool string2font(string const & data, LyXFont & font, bool & toggle)
// the next two should probably go elsewhere // the next two should probably go elsewhere
// this give the position relative to (0, baseline) of outermost // this give the position relative to (0, baseline) of outermost
// paragraph // paragraph
Point coordOffset(DocIterator const & dit) Point coordOffset(DocIterator const & dit, bool boundary)
{ {
int x = 0; int x = 0;
int y = 0; int y = 0;
@ -162,37 +162,41 @@ Point coordOffset(DocIterator const & dit)
CursorSlice const & sl = dit[i]; CursorSlice const & sl = dit[i];
int xx = 0; int xx = 0;
int yy = 0; int yy = 0;
sl.inset().getCursorPos(sl, xx, yy); sl.inset().cursorPos(sl, boundary, xx, yy);
x += xx; x += xx;
y += yy; y += yy;
//lyxerr << "LCursor::getPos, i: " << i << " x: " << xx << " y: " << y << endl; //lyxerr << "LCursor::getPos, i: "
// << i << " x: " << xx << " y: " << y << endl;
} }
// Add contribution of initial rows of outermost paragraph // Add contribution of initial rows of outermost paragraph
CursorSlice const & sl = dit[0]; CursorSlice const & sl = dit[0];
Paragraph const & par = sl.text()->getPar(sl.pit()); Paragraph const & par = sl.text()->getPar(sl.pit());
y -= par.rows()[0].ascent(); y -= par.rows()[0].ascent();
for (size_t rit = 0, rend = par.pos2row(sl.pos()); rit != rend; ++rit) //size_t rend = par.pos2row(sl.pos() - boundary ? 1 : 0);
size_t rend = par.pos2row(sl.pos());
for (size_t rit = 0; rit != rend; ++rit)
y += par.rows()[rit].height(); y += par.rows()[rit].height();
y += par.rows()[par.pos2row(sl.pos())].ascent(); y += par.rows()[rend].ascent();
x += dit.bottom().text()->cursorX(dit.bottom()); x += dit.bottom().text()->cursorX(dit.bottom(), boundary);
// The following correction should not be there at all. // The following correction should not be there at all.
// The cusor looks much better with the -1, though. // The cursor looks much better with the -1, though.
--x; --x;
return Point(x, y); return Point(x, y);
} }
Point getPos(DocIterator const & dit) Point getPos(DocIterator const & dit, bool boundary)
{ {
CursorSlice const & bot = dit.bottom(); CursorSlice const & bot = dit.bottom();
CoordCache::InnerParPosCache const & cache = theCoords.getParPos().find(bot.text())->second; CoordCache::InnerParPosCache const & cache =
theCoords.getParPos().find(bot.text())->second;
CoordCache::InnerParPosCache::const_iterator it = cache.find(bot.pit()); CoordCache::InnerParPosCache::const_iterator it = cache.find(bot.pit());
if (it == cache.end()) { if (it == cache.end()) {
//lyxerr << "cursor out of view" << std::endl; //lyxerr << "cursor out of view" << std::endl;
return Point(-1, -1); return Point(-1, -1);
} }
Point p = coordOffset(dit); // offset from outer paragraph Point p = coordOffset(dit, boundary); // offset from outer paragraph
p.y_ += it->second.y_; p.y_ += it->second.y_;
return p; return p;
} }

View File

@ -17,11 +17,11 @@
#include <string> #include <string>
#include <vector> #include <vector>
class BufferView;
class DocIterator;
class InsetBase_code;
class LyXFont; class LyXFont;
class Point; class Point;
class DocIterator;
class BufferView;
class InsetBase_code;
namespace bv_funcs { namespace bv_funcs {
@ -37,7 +37,7 @@ bool string2font(std::string const & data, LyXFont & font, bool & toggle);
*/ */
std::string const freefont2string(); std::string const freefont2string();
Point getPos(DocIterator const & dit); Point getPos(DocIterator const & dit, bool boundary);
enum CurStatus { enum CurStatus {
CUR_INSIDE, CUR_INSIDE,
@ -49,7 +49,7 @@ enum CurStatus {
CurStatus status(BufferView const * bv, DocIterator const & dit); CurStatus status(BufferView const * bv, DocIterator const & dit);
Point coordOffset(DocIterator const & dit); Point coordOffset(DocIterator const & dit, bool boundary);
/// Moves cursor to the next inset with one of the given codes. /// Moves cursor to the next inset with one of the given codes.
void gotoInset(BufferView * bv, std::vector<InsetBase_code> const & codes, void gotoInset(BufferView * bv, std::vector<InsetBase_code> const & codes,

View File

@ -97,9 +97,7 @@ namespace {
for (int i = 0; ; ++i) { for (int i = 0; ; ++i) {
int xo; int xo;
int yo; int yo;
LCursor cur = c; it.inset().cursorPos(it.top(), c.boundary(), xo, yo);
cur.setCursor(it);
cur.inset().getCursorPos(cur.top(), xo, yo);
double d = (x - xo) * (x - xo) + (y - yo) * (y - yo); double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
// '<=' in order to take the last possible position // '<=' in order to take the last possible position
// this is important for clicking behind \sum in e.g. '\sum_i a' // this is important for clicking behind \sum in e.g. '\sum_i a'
@ -134,7 +132,7 @@ namespace {
// avoid invalid nesting when selecting // avoid invalid nesting when selecting
if (bv_funcs::status(&cursor.bv(), it) == bv_funcs::CUR_INSIDE if (bv_funcs::status(&cursor.bv(), it) == bv_funcs::CUR_INSIDE
&& (!cursor.selection() || positionable(it, cursor.anchor_))) { && (!cursor.selection() || positionable(it, cursor.anchor_))) {
Point p = bv_funcs::getPos(it); Point p = bv_funcs::getPos(it, false);
int xo = p.x_; int xo = p.x_;
int yo = p.y_; int yo = p.y_;
if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) { if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
@ -167,7 +165,7 @@ namespace {
// bv functions are not yet available! // bv functions are not yet available!
LCursor::LCursor(BufferView & bv) LCursor::LCursor(BufferView & bv)
: DocIterator(), bv_(&bv), anchor_(), x_target_(-1), : DocIterator(), bv_(&bv), anchor_(), x_target_(-1),
selection_(false), mark_(false) selection_(false), mark_(false), logicalpos_(false)
{} {}
@ -309,7 +307,7 @@ int LCursor::currentMode()
void LCursor::getPos(int & x, int & y) const void LCursor::getPos(int & x, int & y) const
{ {
Point p = bv_funcs::getPos(*this); Point p = bv_funcs::getPos(*this, boundary());
x = p.x_; x = p.x_;
y = p.y_; y = p.y_;
} }

View File

@ -206,6 +206,11 @@ private:
bool selection_; bool selection_;
/// are we on the way to get one? /// are we on the way to get one?
bool mark_; bool mark_;
/// If true, we are behind the previous char, otherwise we are in front
// of the next char. This only make a difference when we are in front
// of a big inset spanning a whole row and computing coordinates for
// displaying the cursor.
bool logicalpos_;
private: private:

View File

@ -30,12 +30,12 @@ using std::endl;
CursorSlice::CursorSlice() CursorSlice::CursorSlice()
: inset_(0), idx_(0), pit_(0), pos_(0), boundary_(false) : inset_(0), idx_(0), pit_(0), pos_(0)
{} {}
CursorSlice::CursorSlice(InsetBase & p) CursorSlice::CursorSlice(InsetBase & p)
: inset_(&p), idx_(0), pit_(0), pos_(0), boundary_(false) : inset_(&p), idx_(0), pit_(0), pos_(0)
{ {
BOOST_ASSERT(inset_); BOOST_ASSERT(inset_);
} }

View File

@ -104,10 +104,6 @@ public:
/// ///
/// texted specific stuff /// texted specific stuff
/// ///
/// \sa boundary_
bool boundary() const { return boundary_; }
/// \sa boundary_
bool & boundary() { return boundary_; }
/// returns text corresponding to this position /// returns text corresponding to this position
LyXText * text(); LyXText * text();
/// returns text corresponding to this position /// returns text corresponding to this position
@ -156,22 +152,6 @@ private:
bool pit_valid_; bool pit_valid_;
/// position in this cell /// position in this cell
pos_type pos_; pos_type pos_;
/**
* When the cursor position is i, is the cursor after the i-th char
* or before the i+1-th char ? Normally, these two interpretations are
* equivalent, except when the fonts of the i-th and i+1-th char
* differ.
* We use boundary_ to distinguish between the two options:
* If boundary_=true, then the cursor is after the i-th char
* and if boundary_=false, then the cursor is before the i+1-th char.
*
* We currently use the boundary only when the language direction of
* the i-th char is different than the one of the i+1-th char.
* In this case it is important to distinguish between the two
* cursor interpretations, in order to give a reasonable behavior to
* the user.
*/
bool boundary_;
}; };
/// test for equality /// test for equality

View File

@ -55,16 +55,10 @@ public:
explicit DocIterator(InsetBase & inset); explicit DocIterator(InsetBase & inset);
/// access slice at position \p i /// access slice at position \p i
CursorSlice const & operator[](size_t i) const { CursorSlice const & operator[](size_t i) const { return slices_[i]; }
return slices_[i];
}
/// access slice at position \p i /// access slice at position \p i
CursorSlice & operator[](size_t i) { CursorSlice & operator[](size_t i) { return slices_[i]; }
return slices_[i]; /// chop a few slices from the iterator
}
// What is the point of this function?
void resize(size_t i) { slices_.resize(i); } void resize(size_t i) { slices_.resize(i); }
/// is the iterator valid? /// is the iterator valid?
@ -129,6 +123,10 @@ public:
InsetBase * prevInset(); InsetBase * prevInset();
/// the inset just in front of the cursor /// the inset just in front of the cursor
InsetBase const * prevInset() const; InsetBase const * prevInset() const;
///
bool boundary() const { return boundary_; }
///
void boundary(bool b) { boundary_ = b; }
/// are we in mathed? /// are we in mathed?
bool inMathed() const; bool inMathed() const;
@ -154,10 +152,6 @@ public:
// //
// text-specific part // text-specific part
// //
/// \sa boundary_
bool boundary() const { return top().boundary(); }
/// \sa boundary_
bool & boundary() { return top().boundary(); }
/// the paragraph we're in /// the paragraph we're in
Paragraph & paragraph(); Paragraph & paragraph();
/// the paragraph we're in /// the paragraph we're in
@ -209,21 +203,41 @@ public:
/// output /// output
friend std::ostream & friend std::ostream &
operator<<(std::ostream & os, DocIterator const & cur); operator<<(std::ostream & os, DocIterator const & cur);
///
friend bool operator==(DocIterator const &, DocIterator const &); friend bool operator==(DocIterator const &, DocIterator const &);
///
friend class StableDocIterator; friend class StableDocIterator;
protected: protected:
///
void clear() { slices_.clear(); } void clear() { slices_.clear(); }
void push_back(CursorSlice const & sl) { ///
slices_.push_back(sl); void push_back(CursorSlice const & sl) { slices_.push_back(sl); }
} ///
void pop_back() { void pop_back() { slices_.pop_back(); }
slices_.pop_back();
}
private: private:
/**
* When the cursor position is i, is the cursor after the i-th char
* or before the i+1-th char ? Normally, these two interpretations are
* equivalent, except when the fonts of the i-th and i+1-th char
* differ.
* We use boundary_ to distinguish between the two options:
* If boundary_=true, then the cursor is after the i-th char
* and if boundary_=false, then the cursor is before the i+1-th char.
*
* We currently use the boundary only when the language direction of
* the i-th char is different than the one of the i+1-th char.
* In this case it is important to distinguish between the two
* cursor interpretations, in order to give a reasonable behavior to
* the user.
*/
bool boundary_;
///
std::vector<CursorSlice> const & internalData() const { std::vector<CursorSlice> const & internalData() const {
return slices_; return slices_;
} }
///
std::vector<CursorSlice> slices_; std::vector<CursorSlice> slices_;
///
InsetBase * inset_; InsetBase * inset_;
}; };

View File

@ -261,9 +261,9 @@ void InsetBase::markErased()
{} {}
void InsetBase::getCursorPos(CursorSlice const &, int & x, int & y) const void InsetBase::cursorPos(CursorSlice const &, bool, int & x, int & y) const
{ {
lyxerr << "InsetBase::getCursorPos called directly" << std::endl; lyxerr << "InsetBase::cursorPos called directly" << std::endl;
x = 100; x = 100;
y = 100; y = 100;
} }

View File

@ -133,7 +133,8 @@ public:
/// do we cover screen position x/y? /// do we cover screen position x/y?
virtual bool covers(int x, int y) const; virtual bool covers(int x, int y) const;
/// get the screen positions of the cursor (see note in cursor.C) /// get the screen positions of the cursor (see note in cursor.C)
virtual void getCursorPos(CursorSlice const & sl, int & x, int & y) const; virtual void cursorPos(CursorSlice const & sl, bool boundary,
int & x, int & y) const;
/// is this an inset that can be moved into? /// is this an inset that can be moved into?
virtual bool isActive() const { return nargs() > 0; } virtual bool isActive() const { return nargs() > 0; }

View File

@ -192,25 +192,24 @@ void InsetCollapsable::drawSelection(PainterInfo & pi, int x, int y) const
} }
void InsetCollapsable::getCursorPos void InsetCollapsable::cursorPos
(CursorSlice const & sl, int & x, int & y) const (CursorSlice const & sl, bool boundary, int & x, int & y) const
{ {
if (status_ == Collapsed) { if (status_ == Collapsed) {
x = xo(); x = xo();
y = yo(); y = yo();
return; } else {
} InsetText::cursorPos(sl, boundary, x, y);
InsetText::getCursorPos(sl, x, y);
if (status_ == Open) { if (status_ == Open) {
if (openinlined_) if (openinlined_)
x += dimensionCollapsed().wid; x += dimensionCollapsed().wid;
else else
y += dimensionCollapsed().height() - ascent() + TEXT_TO_INSET_OFFSET + textdim_.asc; y += dimensionCollapsed().height() - ascent()
+ TEXT_TO_INSET_OFFSET + textdim_.asc;
} }
x += TEXT_TO_INSET_OFFSET; x += TEXT_TO_INSET_OFFSET;
} }
}
InsetBase::EDITABLE InsetCollapsable::editable() const InsetBase::EDITABLE InsetCollapsable::editable() const

View File

@ -47,7 +47,7 @@ public:
/// ///
void drawSelection(PainterInfo & pi, int x, int y) const; void drawSelection(PainterInfo & pi, int x, int y) const;
/// return x,y of given position relative to the inset's baseline /// return x,y of given position relative to the inset's baseline
void getCursorPos(CursorSlice const & sl, int & x, int & y) const; void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const;
/// ///
bool hitButton(FuncRequest const &) const; bool hitButton(FuncRequest const &) const;
/// ///

View File

@ -1084,9 +1084,10 @@ shared_ptr<InsetText> InsetTabular::cell(idx_type idx)
} }
void InsetTabular::getCursorPos(CursorSlice const & sl, int & x, int & y) const void InsetTabular::cursorPos
(CursorSlice const & sl, bool boundary, int & x, int & y) const
{ {
cell(sl.idx())->getCursorPos(sl, x, y); cell(sl.idx())->cursorPos(sl, boundary, x, y);
// y offset correction // y offset correction
int const row = tabular.row_of_cell(sl.idx()); int const row = tabular.row_of_cell(sl.idx());

View File

@ -91,7 +91,7 @@ public:
/// ///
Code lyxCode() const { return InsetBase::TABULAR_CODE; } Code lyxCode() const { return InsetBase::TABULAR_CODE; }
/// get offset of this cursor slice relative to our upper left corner /// get offset of this cursor slice relative to our upper left corner
void getCursorPos(CursorSlice const & sl, int & x, int & y) const; void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const;
/// ///
bool tabularFeatures(LCursor & cur, std::string const & what); bool tabularFeatures(LCursor & cur, std::string const & what);
/// ///

View File

@ -364,10 +364,11 @@ void InsetText::validate(LaTeXFeatures & features) const
} }
void InsetText::getCursorPos(CursorSlice const & sl, int & x, int & y) const void InsetText::cursorPos
(CursorSlice const & sl, bool boundary, int & x, int & y) const
{ {
x = text_.cursorX(sl) + border_; x = text_.cursorX(sl, boundary) + border_;
y = text_.cursorY(sl); y = text_.cursorY(sl, boundary);
} }

View File

@ -74,7 +74,7 @@ public:
void validate(LaTeXFeatures & features) const; void validate(LaTeXFeatures & features) const;
/// return x,y of given position relative to the inset's baseline /// return x,y of given position relative to the inset's baseline
void getCursorPos(CursorSlice const & sl, int & x, int & y) const; void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const;
/// ///
Code lyxCode() const { return TEXT_CODE; } Code lyxCode() const { return TEXT_CODE; }
/// ///

View File

@ -322,9 +322,9 @@ public:
/// ///
int descent() const; int descent() const;
/// ///
int cursorX(CursorSlice const & cursor) const; int cursorX(CursorSlice const & cursor, bool boundary) const;
/// ///
int cursorY(CursorSlice const & cursor) const; int cursorY(CursorSlice const & cursor, bool boundary) const;
/// ///
friend class LyXScreen; friend class LyXScreen;

View File

@ -102,10 +102,11 @@ LyXText * MathMBoxInset::getText(int) const
} }
void MathMBoxInset::getCursorPos(CursorSlice const & sl, int & x, int & y) const void MathMBoxInset::cursorPos
(CursorSlice const & sl, bool boundary, int & x, int & y) const
{ {
x = text_.cursorX(sl); x = text_.cursorX(sl, boundary);
y = text_.cursorY(sl); y = text_.cursorY(sl, boundary);
} }

View File

@ -41,7 +41,7 @@ public:
/// ///
LyXText * getText(int) const; LyXText * getText(int) const;
/// ///
void getCursorPos(CursorSlice const & sl, int & x, int & y) const; void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const;
protected: protected:
virtual void doDispatch(LCursor & cur, FuncRequest & cmd); virtual void doDispatch(LCursor & cur, FuncRequest & cmd);

View File

@ -88,7 +88,7 @@ MathArray const & MathNestInset::cell(idx_type i) const
} }
void MathNestInset::getCursorPos(CursorSlice const & sl, void MathNestInset::cursorPos(CursorSlice const & sl, bool boundary,
int & x, int & y) const int & x, int & y) const
{ {
// FIXME: This is a hack. Ideally, the coord cache should not store // FIXME: This is a hack. Ideally, the coord cache should not store

View File

@ -37,7 +37,7 @@ public:
/// identifies NestInsets /// identifies NestInsets
MathNestInset const * asNestInset() const { return this; } MathNestInset const * asNestInset() const { return this; }
/// get cursor position /// get cursor position
void getCursorPos(CursorSlice const & sl, int & x, int & y) const; void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const;
/// ///
void edit(LCursor & cur, bool left); void edit(LCursor & cur, bool left);
/// ///

View File

@ -1010,7 +1010,7 @@ void LyXText::setHeightOfRow(pit_type const pit, Row & row)
if (bv_owner->text() == this) { if (bv_owner->text() == this) {
if (pit == 0 && row.pos() == 0) if (pit == 0 && row.pos() == 0)
maxasc += 20; maxasc += 20;
if (pit == pars_.size() - 1 && row.endpos() == par.size()) if (pit + 1 == pars_.size() && row.endpos() == par.size())
maxdesc += 20; maxdesc += 20;
} }
@ -1193,7 +1193,8 @@ void LyXText::insertChar(LCursor & cur, char c)
current_font = rawtmpfont; current_font = rawtmpfont;
real_current_font = realtmpfont; real_current_font = realtmpfont;
setCursor(cur, cur.pit(), cur.pos() + 1, false, cur.boundary()); //setCursor(cur, cur.pit(), cur.pos() + 1, false, cur.boundary());
setCursor(cur, cur.pit(), cur.pos() + 1, false, true);
charInserted(); charInserted();
} }
@ -1793,7 +1794,7 @@ void LyXText::drawSelection(PainterInfo & pi, int x , int) const
x2 = 0; x2 = 0;
} else { } else {
y1 = bv_funcs::getPos(beg).y_ - row1.ascent(); y1 = bv_funcs::getPos(beg).y_ - row1.ascent();
int const startx = cursorX(beg.top()); int const startx = cursorX(beg.top(), begin.boundary());
x1 = isRTL(par1) ? startx : 0; x1 = isRTL(par1) ? startx : 0;
x2 = isRTL(par1) ? 0 + dim_.wid : startx; x2 = isRTL(par1) ? 0 + dim_.wid : startx;
} }
@ -1805,7 +1806,7 @@ void LyXText::drawSelection(PainterInfo & pi, int x , int) const
X2 = 0; X2 = 0;
} else { } else {
y2 = bv_funcs::getPos(end).y_ + row2.descent(); y2 = bv_funcs::getPos(end).y_ + row2.descent();
int const endx = cursorX(end.top()); int const endx = cursorX(end.top(), end.boundary());
X1 = isRTL(par2) ? 0 : endx; X1 = isRTL(par2) ? 0 : endx;
X2 = isRTL(par2) ? endx : 0 + dim_.wid; X2 = isRTL(par2) ? endx : 0 + dim_.wid;
} }
@ -1868,9 +1869,9 @@ void LyXText::drawSelection(PainterInfo & pi, int x, int) const
x2 = dim_.wid; x2 = dim_.wid;
} else { } else {
Row const & row1 = par1.getRow(beg.pos()); Row const & row1 = par1.getRow(beg.pos());
y1 = bv_funcs::getPos(beg).y_ - row1.ascent(); y1 = bv_funcs::getPos(beg, beg.boundary()).y_ - row1.ascent();
y2 = y1 + row1.height(); y2 = y1 + row1.height();
int const startx = cursorX(beg.top()); int const startx = cursorX(beg.top(), beg.boundary());
x1 = !isRTL(par1) ? startx : 0; x1 = !isRTL(par1) ? startx : 0;
x2 = !isRTL(par1) ? 0 + dim_.wid : startx; x2 = !isRTL(par1) ? 0 + dim_.wid : startx;
} }
@ -1883,9 +1884,9 @@ void LyXText::drawSelection(PainterInfo & pi, int x, int) const
X2 = dim_.wid; X2 = dim_.wid;
} else { } else {
Row const & row2 = par2.getRow(end.pos()); Row const & row2 = par2.getRow(end.pos());
Y1 = bv_funcs::getPos(end).y_ - row2.ascent(); Y1 = bv_funcs::getPos(end, end.boundary()).y_ - row2.ascent();
Y2 = Y1 + row2.height(); Y2 = Y1 + row2.height();
int const endx = cursorX(end.top()); int const endx = cursorX(end.top(), end.boundary());
X1 = !isRTL(par2) ? 0 : endx; X1 = !isRTL(par2) ? 0 : endx;
X2 = !isRTL(par2) ? endx : 0 + dim_.wid; X2 = !isRTL(par2) ? endx : 0 + dim_.wid;
} }
@ -1910,6 +1911,7 @@ void LyXText::drawSelection(PainterInfo & pi, int x, int) const
Y1 - y2, LColor::selection); Y1 - y2, LColor::selection);
} }
bool LyXText::isLastRow(pit_type pit, Row const & row) const bool LyXText::isLastRow(pit_type pit, Row const & row) const
{ {
return row.endpos() >= pars_[pit].size() return row.endpos() >= pars_[pit].size()
@ -2045,16 +2047,20 @@ int LyXText::descent() const
} }
int LyXText::cursorX(CursorSlice const & cur) const int LyXText::cursorX(CursorSlice const & sl, bool boundary) const
{ {
pit_type const pit = cur.pit(); pit_type const pit = sl.pit();
Paragraph const & par = pars_[pit]; Paragraph const & par = pars_[pit];
if (par.rows().empty()) if (par.rows().empty())
return 0; return 0;
Row const & row = par.getRow(cur.pos()); pos_type pos = sl.pos();
//// Correct position in front of big insets
//if (pos && boundary)
// --pos;
Row const & row = par.getRow(pos);
pos_type pos = cur.pos();
pos_type cursor_vpos = 0; pos_type cursor_vpos = 0;
RowMetrics const m = computeRowMetrics(pit, row); RowMetrics const m = computeRowMetrics(pit, row);
@ -2104,20 +2110,28 @@ int LyXText::cursorX(CursorSlice const & cur) const
} else } else
x += singleWidth(par, pos); x += singleWidth(par, pos);
} }
// see correction above
//if (pos && boundary)
// x += singleWidth(par, pos + 1);
return int(x); return int(x);
} }
int LyXText::cursorY(CursorSlice const & cur) const int LyXText::cursorY(CursorSlice const & sl, bool boundary) const
{ {
Paragraph const & par = getPar(cur.pit()); //lyxerr << "LyXText::cursorY: boundary: " << boundary << std::endl;
Paragraph const & par = getPar(sl.pit());
int h = 0; int h = 0;
h -= pars_[0].rows()[0].ascent(); h -= pars_[0].rows()[0].ascent();
for (pit_type pit = 0; pit < cur.pit(); ++pit) for (pit_type pit = 0; pit < sl.pit(); ++pit)
h += pars_[pit].height(); h += pars_[pit].height();
for (size_t rit = 0, rend = par.pos2row(cur.pos()); rit != rend; ++rit) //size_t const rend = par.pos2row(sl.pos() - boundary ? 1 : 0);
size_t const rend = par.pos2row(sl.pos());
for (size_t rit = 0; rit != rend; ++rit)
h += par.rows()[rit].height(); h += par.rows()[rit].height();
h += par.rows()[par.pos2row(cur.pos())].ascent(); h += par.rows()[rend].ascent();
return h; return h;
} }
@ -2254,7 +2268,7 @@ string LyXText::getPossibleLabel(LCursor & cur) const
pos_type LyXText::x2pos(pit_type pit, int row, int x) const pos_type LyXText::x2pos(pit_type pit, int row, int x) const
{ {
BOOST_ASSERT(row < pars_[pit].rows().size()); BOOST_ASSERT(row < int(pars_[pit].rows().size()));
bool bound = false; bool bound = false;
Row const & r = pars_[pit].rows()[row]; Row const & r = pars_[pit].rows()[row];
return r.pos() + getColumnNearX(pit, r, x, bound); return r.pos() + getColumnNearX(pit, r, x, bound);

View File

@ -660,6 +660,7 @@ bool LyXText::setCursor(LCursor & cur, pit_type par, pos_type pos,
{ {
LCursor old = cur; LCursor old = cur;
setCursorIntern(cur, par, pos, setfont, boundary); setCursorIntern(cur, par, pos, setfont, boundary);
cur.boundary(boundary);
return deleteEmptyParagraphMechanism(cur, old); return deleteEmptyParagraphMechanism(cur, old);
} }
@ -670,7 +671,6 @@ void LyXText::setCursor(CursorSlice & cur, pit_type par,
BOOST_ASSERT(par != int(paragraphs().size())); BOOST_ASSERT(par != int(paragraphs().size()));
cur.pit() = par; cur.pit() = par;
cur.pos() = pos; cur.pos() = pos;
cur.boundary() = boundary;
// now some strict checking // now some strict checking
Paragraph & para = getPar(par); Paragraph & para = getPar(par);
@ -928,7 +928,7 @@ InsetBase * LyXText::editXY(LCursor & cur, int x, int y)
pos_type const pos = row.pos() + getColumnNearX(pit, row, xx, bound); pos_type const pos = row.pos() + getColumnNearX(pit, row, xx, bound);
cur.pit() = pit; cur.pit() = pit;
cur.pos() = pos; cur.pos() = pos;
cur.boundary() = bound; cur.boundary(bound);
cur.x_target() = x; cur.x_target() = x;
// try to descend into nested insets // try to descend into nested insets
@ -1022,7 +1022,7 @@ bool LyXText::cursorUp(LCursor & cur)
int const x = cur.targetX(); int const x = cur.targetX();
if (!cur.selection()) { if (!cur.selection()) {
int const y = bv_funcs::getPos(cur).y_; int const y = bv_funcs::getPos(cur, cur.boundary()).y_;
LCursor old = cur; LCursor old = cur;
editXY(cur, x, y - par.rows()[row].ascent() - 1); editXY(cur, x, y - par.rows()[row].ascent() - 1);
@ -1061,7 +1061,7 @@ bool LyXText::cursorDown(LCursor & cur)
int const x = cur.targetX(); int const x = cur.targetX();
if (!cur.selection()) { if (!cur.selection()) {
int const y = bv_funcs::getPos(cur).y_; int const y = bv_funcs::getPos(cur, cur.boundary()).y_;
LCursor old = cur; LCursor old = cur;
editXY(cur, x, y + par.rows()[row].descent() + 1); editXY(cur, x, y + par.rows()[row].descent() + 1);

View File

@ -406,8 +406,8 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
case LFUN_RIGHT: case LFUN_RIGHT:
case LFUN_RIGHTSEL: case LFUN_RIGHTSEL:
lyxerr << BOOST_CURRENT_FUNCTION //lyxerr << BOOST_CURRENT_FUNCTION
<< " LFUN_RIGHT[SEL]:\n" << cur << endl; // << " LFUN_RIGHT[SEL]:\n" << cur << endl;
cur.selHandle(cmd.action == LFUN_RIGHTSEL); cur.selHandle(cmd.action == LFUN_RIGHTSEL);
if (isRTL(cur.paragraph())) if (isRTL(cur.paragraph()))
needsUpdate = cursorLeft(cur); needsUpdate = cursorLeft(cur);
@ -819,8 +819,8 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
break; break;
case LFUN_GETXY: case LFUN_GETXY:
cur.message(convert<string>(cursorX(cur.top())) + ' ' cur.message(convert<string>(cursorX(cur.top(), cur.boundary())) + ' '
+ convert<string>(cursorY(cur.top()))); + convert<string>(cursorY(cur.top(), cur.boundary())));
break; break;
case LFUN_SETXY: { case LFUN_SETXY: {