+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
/// 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;
///
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_;
}
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;
}
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)
{
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)
{
// 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();
}
}
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);
}