moves top_y from lyxtext to BufferView

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7616 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Alfredo Braunstein 2003-08-27 14:55:20 +00:00
parent 7338f3b980
commit cf6549229d
14 changed files with 108 additions and 87 deletions

View File

@ -225,6 +225,18 @@ void BufferView::center()
}
int BufferView::top_y() const
{
return pimpl_->top_y();
}
void BufferView::top_y(int y)
{
pimpl_->top_y(y);
}
string const BufferView::getClipboard() const
{
return pimpl_->workarea().getClipboard();

View File

@ -64,6 +64,12 @@ public:
/// return the owning main view
LyXView * owner() const;
/// return the visible top y
int top_y() const;
/// set the visible top y
void top_y(int);
/// resize event has happened
void resize();

View File

@ -273,6 +273,18 @@ Painter & BufferView::Pimpl::painter() const
}
void BufferView::Pimpl::top_y(int y)
{
top_y_ = y;
}
int BufferView::Pimpl::top_y() const
{
return top_y_;
}
void BufferView::Pimpl::buffer(Buffer * b)
{
lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
@ -293,6 +305,8 @@ void BufferView::Pimpl::buffer(Buffer * b)
// set current buffer
buffer_ = b;
top_y_ = 0;
// if we're quitting lyx, don't bother updating stuff
if (quitting)
return;
@ -310,7 +324,7 @@ void BufferView::Pimpl::buffer(Buffer * b)
resizeCurrentBuffer();
// FIXME: needed when ?
bv_->text->top_y(screen().topCursorVisible(bv_->text));
top_y(screen().topCursorVisible(bv_->text));
// Buffer-dependent dialogs should be updated or
// hidden. This should go here because some dialogs (eg ToC)
@ -461,7 +475,7 @@ void BufferView::Pimpl::resizeCurrentBuffer()
bv_->theLockingInset(the_locking_inset);
}
bv_->text->top_y(screen().topCursorVisible(bv_->text));
top_y(screen().topCursorVisible(bv_->text));
switchKeyMap();
owner_->busy(false);
@ -484,9 +498,9 @@ void BufferView::Pimpl::updateScrollbar()
LyXText const & t = *bv_->text;
lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", top_y() "
<< t.top_y() << ", default height " << defaultRowHeight() << endl;
<< top_y() << ", default height " << defaultRowHeight() << endl;
workarea().setScrollbarParams(t.height, t.top_y(), defaultRowHeight());
workarea().setScrollbarParams(t.height, top_y(), defaultRowHeight());
}
@ -499,15 +513,15 @@ void BufferView::Pimpl::scrollDocView(int value)
screen().hideCursor();
bv_->text->top_y(value);
top_y(value);
screen().redraw(*bv_);
if (!lyxrc.cursor_follows_scrollbar)
return;
int const height = defaultRowHeight();
int const first = int((bv_->text->top_y() + height));
int const last = int((bv_->text->top_y() + workarea().workHeight() - height));
int const first = top_y() + height;
int const last = top_y() + workarea().workHeight() - height;
LyXText * text = bv_->text;
if (text->cursor.y() < first)
@ -529,7 +543,7 @@ void BufferView::Pimpl::scroll(int lines)
int const line_height = defaultRowHeight();
// The new absolute coordinate
int new_top_y = t->top_y() + lines * line_height;
int new_top_y = top_y() + lines * line_height;
// Restrict to a valid value
new_top_y = std::min(t->height - 4 * line_height, new_top_y);
@ -538,7 +552,7 @@ void BufferView::Pimpl::scroll(int lines)
scrollDocView(new_top_y);
// Update the scrollbar.
workarea().setScrollbarParams(t->height, t->top_y(), defaultRowHeight());
workarea().setScrollbarParams(t->height, top_y(), defaultRowHeight());
}
@ -797,7 +811,7 @@ void BufferView::Pimpl::center()
// and also might have moved top_y() must make sure to call
// updateScrollbar() currently. Never mind that this is a
// pretty obfuscated way of updating t->top_y()
text->top_y(new_y);
top_y(new_y);
//screen().draw();
update();
}

View File

@ -106,7 +106,13 @@ struct BufferView::Pimpl : public boost::signals::trackable {
bool workAreaDispatch(FuncRequest const & ev);
/// a function should be executed
bool dispatch(FuncRequest const & ev);
///
int top_y() const;
///
void top_y(int y);
private:
/// the y coordinate of the top of the screen
int top_y_;
/// An error list (replaces the error insets)
ErrorList errorlist_;
/// add an error to the list

View File

@ -1,3 +1,17 @@
2003-08-27 Alfredo Braunstein <abraunst@libero.it>
* lyxtext.h (top_y): move top_y from here
* text.C:
* text2.C:
* text3.C:
* BufferView.[Ch]:
* BufferView_pimpl.[Ch]: to here
* frontends/screen.C:
* insets/insettabular.C:
* insets/insettext.C: adjust
* rowpainter.[Ch] (paintRows): remove LyXText & argument
2003-08-27 Alfredo Braunstein <abraunst@libero.it>
* BufferView.[Ch]:

View File

@ -163,7 +163,7 @@ void LyXScreen::showCursor(BufferView & bv)
int h = ascent + descent;
int x = 0;
int y = 0;
int const top_y = bv.text->top_y();
int const top_y = bv.top_y();
if (bv.theLockingInset()) {
// Would be nice to clean this up to make some understandable sense...
@ -220,23 +220,25 @@ void LyXScreen::toggleCursor(BufferView & bv)
}
bool LyXScreen::fitManualCursor(BufferView * /*bv*/, LyXText * text,
bool LyXScreen::fitManualCursor(BufferView * bv, LyXText * text,
int /*x*/, int y, int asc, int desc)
{
int const vheight = workarea().workHeight();
int newtop = text->top_y();
if (y + desc - text->top_y() >= vheight)
int const topy = bv->top_y();
int newtop = topy;
if (y + desc - topy >= vheight)
newtop = y - 3 * vheight / 4; // the scroll region must be so big!!
else if (y - asc < text->top_y() && text->top_y() > 0)
else if (y - asc < topy && topy > 0)
newtop = y - vheight / 4;
newtop = max(newtop, 0); // can newtop ever be < 0? (Lgb)
if (newtop == text->top_y())
if (newtop == topy)
return false;
text->top_y(newtop);
bv->top_y(newtop);
return true;
}
@ -244,7 +246,7 @@ bool LyXScreen::fitManualCursor(BufferView * /*bv*/, LyXText * text,
unsigned int LyXScreen::topCursorVisible(LyXText * text)
{
LyXCursor const & cursor = text->cursor;
int top_y = text->top_y();
int top_y = text->bv()->top_y();
int newtop = top_y;
int const vheight = workarea().workHeight();
@ -279,8 +281,8 @@ bool LyXScreen::fitCursor(LyXText * text, BufferView * bv)
{
// Is a change necessary?
int const newtop = topCursorVisible(text);
bool const result = (newtop != text->top_y());
text->top_y(newtop);
bool const result = (newtop != bv->top_y());
bv->top_y(newtop);
return result;
}
@ -298,7 +300,7 @@ void LyXScreen::redraw(BufferView & bv)
hideCursor();
int const y = paintText(bv, *bv.text);
int const y = paintText(bv);
// maybe we have to clear the screen at the bottom
int const y2 = workarea().workHeight();

View File

@ -860,10 +860,10 @@ InsetOld::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
clearSelection();
int column = actcol;
unlockInsetInInset(bv, the_locking_inset);
if (bv->text->top_y() + bv->painter().paperHeight() <
if (bv->top_y() + bv->painter().paperHeight() <
top_baseline + tabular.getHeightOfTabular())
{
bv->scrollDocView(bv->text->top_y() + bv->painter().paperHeight());
bv->scrollDocView(bv->top_y() + bv->painter().paperHeight());
actcell = tabular.getCellBelow(first_visible_cell) + column;
} else {
actcell = tabular.getFirstCellInRow(tabular.rows() - 1) + column;
@ -878,7 +878,7 @@ InsetOld::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
int column = actcol;
unlockInsetInInset(bv, the_locking_inset);
if (top_baseline < 0) {
bv->scrollDocView(bv->text->top_y() - bv->painter().paperHeight());
bv->scrollDocView(bv->top_y() - bv->painter().paperHeight());
if (top_baseline > 0)
actcell = column;
else

View File

@ -489,7 +489,7 @@ void InsetText::lfunMousePress(FuncRequest const & cmd)
lockInset(bv);
int tmp_x = cmd.x - drawTextXOffset;
int tmp_y = cmd.y + dim_.asc - getLyXText(bv)->top_y();
int tmp_y = cmd.y + dim_.asc - bv->top_y();
InsetOld * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y);
if (the_locking_inset) {
@ -524,7 +524,7 @@ void InsetText::lfunMousePress(FuncRequest const & cmd)
localDispatch(FuncRequest(bv, LFUN_COPY));
paste_internally = true;
}
int old_top_y = text_.top_y();
int old_top_y = bv->top_y();
text_.setCursorFromCoordinates(cmd.x - drawTextXOffset,
cmd.y + dim_.asc);
@ -538,7 +538,7 @@ void InsetText::lfunMousePress(FuncRequest const & cmd)
bv->owner()->setLayout(cpar()->layout()->name());
// we moved the view we cannot do mouse selection in this case!
if (getLyXText(bv)->top_y() != old_top_y)
if (bv->top_y() != old_top_y)
no_selection = true;
old_par = cpar();
// Insert primary selection with middle mouse
@ -568,7 +568,7 @@ bool InsetText::lfunMouseRelease(FuncRequest const & cmd)
return the_locking_inset->localDispatch(cmd1);
int tmp_x = cmd.x - drawTextXOffset;
int tmp_y = cmd.y + dim_.asc - getLyXText(bv)->top_y();
int tmp_y = cmd.y + dim_.asc - bv->top_y();
InsetOld * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y);
bool ret = false;
if (inset) {

View File

@ -70,12 +70,6 @@ private:
public:
/// update all cached row positions
void updateRowPositions();
/// get the y coord. of the top of the screen (relative to doc start)
int top_y() const;
/// 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(RowList::iterator rit);
///
InsetText * inset_owner;
///

View File

@ -1062,7 +1062,7 @@ int paintRows(BufferView const & bv, LyXText const & text,
if (row == rit)
active = true;
if (active) {
RowPainter painter(bv, text, pit, row, y + yo, xo, y + text.top_y());
RowPainter painter(bv, text, pit, row, y + yo, xo, y + bv.top_y());
painter.paint();
y += row->height();
if (yy + y >= y2)
@ -1080,13 +1080,13 @@ int paintRows(BufferView const & bv, LyXText const & text,
} // namespace anon
int paintText(BufferView & bv, LyXText & text)
int paintText(BufferView & bv)
{
int const topy = text.top_y();
int const topy = bv.top_y();
ParagraphList::iterator pit;
RowList::iterator rit = text.getRowNearY(topy, pit);
RowList::iterator rit = bv.text->getRowNearY(topy, pit);
int y = rit->y() - topy;
return paintRows(bv, text, pit, rit, 0, y, y, 0);
return paintRows(bv, *bv.text, pit, rit, 0, y, y, 0);
}
@ -1102,13 +1102,10 @@ void paintTextInset(BufferView & bv, LyXText & text, int x, int baseline)
y += rit->height();
text.nextRow(pit, rit);
}
if (y_offset < 0) {
text.top_y(-y_offset);
if (y_offset < 0)
paintRows(bv, text, pit, rit, x, 0, y, y);
} else {
text.top_y(y - y_offset);
else
paintRows(bv, text, pit, rit, x, 0, y_offset, y_offset);
}
}

View File

@ -21,7 +21,7 @@ class VSpace;
int getLengthMarkerHeight(BufferView const & bv, VSpace const & vsp);
/// paint the rows of the main text, return last drawn y value
int paintText(BufferView & bv, LyXText & text);
int paintText(BufferView & bv);
/// paint the rows of a text inset
void paintTextInset(BufferView & bv, LyXText & text, int x, int y);

View File

@ -103,19 +103,6 @@ void LyXText::updateRowPositions()
}
int LyXText::top_y() const
{
return anchor_y_;
}
void LyXText::top_y(int newy)
{
anchor_y_ = newy;
lyxerr[Debug::GUI] << "changing reference to offset: " << anchor_y_ << endl;
}
int LyXText::workWidth() const
{
return inset_owner ? inset_owner->textWidth() : bv()->workWidth();

View File

@ -1399,17 +1399,6 @@ void LyXText::setCursor(LyXCursor & cur, ParagraphList::iterator pit,
cur.ix(int(x));
} else
cur.ix(cur.x());
/* We take out this for the time being because 1) the redraw code is not
prepared to this yet and 2) because some good policy has yet to be decided
while editting: for instance how to act on rows being created/deleted
because of DEPM.
*/
#if 0
//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);
#endif
}
@ -1694,7 +1683,7 @@ void LyXText::cursorUp(bool selecting)
int y = cursor.y() - cursorRow()->baseline() - 1;
setCursorFromCoordinates(x, y);
if (!selecting) {
int topy = top_y();
int topy = bv_owner->top_y();
int y1 = cursor.iy() - topy;
int y2 = y1;
y -= topy;
@ -1720,7 +1709,7 @@ void LyXText::cursorDown(bool selecting)
int y = cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1;
setCursorFromCoordinates(x, y);
if (!selecting && cursorRow() == cursorIRow()) {
int topy = top_y();
int topy = bv_owner->top_y();
int y1 = cursor.iy() - topy;
int y2 = y1;
y -= topy;

View File

@ -146,7 +146,7 @@ namespace {
InsetOld * LyXText::checkInsetHit(int & x, int & y)
{
int y_tmp = y + top_y();
int y_tmp = y + bv_owner->top_y();
LyXCursor cur;
setCursorFromCoordinates(cur, x, y_tmp);
@ -243,7 +243,7 @@ void LyXText::gotoInset(InsetOld::Code code, bool same_content)
void LyXText::cursorPrevious()
{
int y = top_y();
int y = bv_owner->top_y();
RowList::iterator rit = cursorRow();
@ -282,7 +282,7 @@ void LyXText::cursorPrevious()
ParagraphList::iterator pit = cursor.par();
previousRow(pit, rit);
setCursor(cur, pit, rit->pos(), false);
if (cur.y() > top_y())
if (cur.y() > bv_owner->top_y())
cursorUp(true);
bv()->updateScrollbar();
}
@ -290,21 +290,21 @@ void LyXText::cursorPrevious()
void LyXText::cursorNext()
{
int topy = top_y();
int topy = bv_owner->top_y();
RowList::iterator rit = cursorRow();
if (rit == lastRow()) {
int y = cursor.y() - rit->baseline() + cursorRow()->height();
if (y > topy + bv()->workHeight())
bv()->updateScrollbar();
bv_owner->updateScrollbar();
return;
}
int y = topy + bv()->workHeight();
int y = topy + bv_owner->workHeight();
if (inset_owner && !topy) {
y -= (bv()->text->cursor.iy()
- bv()->text->top_y()
+ bv()->theLockingInset()->insetInInsetY());
y -= (bv_owner->text->cursor.iy()
- bv_owner->top_y()
+ bv_owner->theLockingInset()->insetInInsetY());
}
ParagraphList::iterator dummypit;
@ -315,7 +315,7 @@ void LyXText::cursorNext()
finishUndo();
int new_y;
if (rit == bv()->text->cursorRow()) {
if (rit == bv_owner->text->cursorRow()) {
// we have a row which is taller than the workarea. The
// simplest solution is to move to the next row instead.
cursorDown(true);
@ -323,7 +323,7 @@ void LyXText::cursorNext()
// This is what we used to do, so we wouldn't skip right past
// tall rows, but it's not working right now.
#if 0
new_y = bv->text->top_y() + bv->workHeight();
new_y = bv->top_y() + bv->workHeight();
#endif
} else {
if (inset_owner) {
@ -339,7 +339,7 @@ void LyXText::cursorNext()
nextRow(pit, rit);
LyXCursor cur;
setCursor(cur, pit, rit->pos(), false);
if (cur.y() < top_y() + bv()->workHeight())
if (cur.y() < bv_owner->top_y() + bv()->workHeight())
cursorDown(true);
bv()->updateScrollbar();
}
@ -1218,7 +1218,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
int start_x = inset_x + tli->scroll();
FuncRequest cmd1 = cmd;
cmd1.x = cmd.x - start_x;
cmd1.y = cmd.y - cursor.iy() + bv->text->top_y();
cmd1.y = cmd.y - cursor.iy() + bv->top_y();
tli->localDispatch(cmd1);
break;
}
@ -1233,7 +1233,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
}
RowList::iterator cursorrow = bv->text->cursorRow();
bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->text->top_y());
bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->top_y());
#if 0
// sorry for this but I have a strange error that the y value jumps at
// a certain point. This seems like an error in my xforms library or
@ -1289,7 +1289,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
paste_internally = true;
}
int const screen_first = bv->text->top_y();
int const screen_first = bv->top_y();
if (bv->theLockingInset()) {
// We are in inset locking mode