anchorRow

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6526 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John Levon 2003-03-18 16:47:18 +00:00
parent 73a37f0b2d
commit 3ea0a9e5f4
4 changed files with 45 additions and 19 deletions

View File

@ -1,3 +1,9 @@
2003-03-18 Alfredo Braunstein <abraunst@libero.it>
* lyxtext.h:
* text.C:
* text2.C: anchor row on setCursor
2003-03-18 Alfredo Braunstein <abraunst@libero.it>
* lyxtext.h: remove almost all mutable keywords

View File

@ -84,17 +84,20 @@ public:
/// the current font
LyXFont real_current_font;
private:
/** the first visible row on screen
/** the 'anchor' row: the position of this row remains constant
* with respect to the top of the screen
*/
Row * top_row_;
Row * anchor_row_;
/** the pixel offset with respect to this row of top_y
*/
int top_row_offset_;
int anchor_row_offset_;
public:
/// get the y coord. of the top of the screen (relative to doc start)
int top_y() const;
/// set it
/// set the y coord. of the top of the screen (relative to doc start)
void top_y(int newy);
/// set the anchoring row. top_y will be computed relative to this
void anchor_row(Row * row);
///
InsetText * inset_owner;
///

View File

@ -74,14 +74,15 @@ BufferView * LyXText::bv() const
int LyXText::top_y() const
{
if (!top_row_)
if (!anchor_row_)
return 0;
int y = 0;
for (Row * row = firstrow; row && row != top_row_; row = row->next()) {
for (Row * row = firstrow;
row && row != anchor_row_; row = row->next()) {
y += row->height();
}
return y + top_row_offset_;
return y + anchor_row_offset_;
}
@ -92,10 +93,22 @@ void LyXText::top_y(int newy)
lyxerr[Debug::GUI] << "setting top y = " << newy << endl;
int y = newy;
top_row_ = getRowNearY(y);
top_row_offset_ = newy - y;
lyxerr[Debug::GUI] << "changing reference to row: " << top_row_
<< " offset: " << top_row_offset_ << endl;
anchor_row_ = getRowNearY(y);
anchor_row_offset_ = newy - y;
lyxerr[Debug::GUI] << "changing reference to row: " << anchor_row_
<< " offset: " << anchor_row_offset_ << endl;
}
void LyXText::anchor_row(Row * row)
{
int old_y = top_y();
anchor_row_offset_ = 0;
anchor_row_ = row;
anchor_row_offset_ = old_y - top_y();
lyxerr[Debug::GUI] << "anchor_row(): changing reference to row: "
<< anchor_row_ << " offset: " << anchor_row_offset_
<< endl;
}

View File

@ -52,7 +52,7 @@ using lyx::pos_type;
LyXText::LyXText(BufferView * bv)
: height(0), width(0), top_row_(0), top_row_offset_(0),
: height(0), width(0), anchor_row_(0), anchor_row_offset_(0),
inset_owner(0), the_locking_inset(0), need_break_row(0),
bv_owner(bv), firstrow(0), lastrow(0)
{
@ -61,7 +61,7 @@ LyXText::LyXText(BufferView * bv)
LyXText::LyXText(BufferView * bv, InsetText * inset)
: height(0), width(0), top_row_(0), top_row_offset_(0),
: height(0), width(0), anchor_row_(0), anchor_row_offset_(0),
inset_owner(inset), the_locking_inset(0), need_break_row(0),
bv_owner(bv), firstrow(0), lastrow(0)
{
@ -331,13 +331,13 @@ void LyXText::removeRow(Row * row)
// what about refresh_y
}
if (top_row_ == row) {
if (row->next()) {
top_row_ = row->next();
top_row_offset_ -= row->height();
if (anchor_row_ == row) {
if (row_prev) {
anchor_row_ = row_prev;
anchor_row_offset_ = 0;
} else {
top_row_ = row_prev;
top_row_offset_ = 0;
anchor_row_ = row->next();
anchor_row_offset_ -= row->height();
}
}
@ -1793,6 +1793,10 @@ void LyXText::setCursor(LyXCursor & cur, Paragraph * par,
cur.ix(int(x));
} else
cur.ix(cur.x());
//if the cursor is in a visible row, anchor to it
int topy = top_y();
if (topy < y && y < topy + bv()->workHeight())
anchor_row(row);
}