- LyXCursor const & cursor = text->cursor;
- int top_y = text->top_y();
- int newtop = top_y;
- int const vheight = workarea().workHeight();
-
- RowList::iterator row = text->cursorRow();
-
-#warning SUPER HACK DISABLED (Lgb)
-#if 0
- // Is this a hack? Yes, probably... (Lgb)
- if (!row)
- return max(newtop, 0);
-#endif
- if (cursor.y() - row->baseline() + row->height() - top_y >= vheight) {
- if (row->height() < vheight
- && row->height() > vheight / 4) {
- newtop = cursor.y()
- + row->height()
- - row->baseline() - vheight;
- } else {
- // scroll down, the scroll region must be so big!!
- newtop = cursor.y() - vheight / 2;
- }
-
- } else if (static_cast<int>((cursor.y()) - row->baseline()) <
- top_y && top_y > 0) {
- if (row->height() < vheight
- && row->height() > vheight / 4) {
- newtop = cursor.y() - row->baseline();
- } else {
- // scroll up
- newtop = cursor.y() - vheight / 2;
- newtop = min(newtop, top_y);
- }
- }
-
- newtop = max(newtop, 0);
-
- return newtop;
-}
-
-
-bool LyXScreen::fitCursor(LyXText * text, BufferView * bv)
-{
- // Is a change necessary?
- int const newtop = topCursorVisible(text);
- bool const result = (newtop != text->top_y());
- if (result) {
- draw(text, bv, newtop);
- }
-
- return result;
-}
-
-
-void LyXScreen::update(BufferView & bv, int yo, int xo)
-{
- LyXText * text = bv.text;
-
- workarea().getPainter().start();
-
- if (text->needRefresh()) {
- int const vwidth = workarea().workWidth();
- int const vheight = workarea().workHeight();
- text->updateRowPositions();
- int const y = max(int(text->refresh_y - text->top_y()), 0);
- drawFromTo(text, &bv, y, vheight, yo, xo);
- expose(0, y, vwidth, vheight - y);
- }
-
- workarea().getPainter().end();
-}
-
-
-void LyXScreen::toggleSelection(LyXText * text, BufferView * bv,
- bool kill_selection,
- int yo, int xo)
-{
- // only if there is a selection
- if (!text->selection.set()) return;
-
- int const bottom = min(
- max(static_cast<int>(text->selection.end.y()
- - text->getRow(text->selection.end)->baseline()
- + text->getRow(text->selection.end)->height()),
- text->top_y()),
- static_cast<int>(text->top_y() + workarea().workHeight()));
- int const top = min(
- max(static_cast<int>(text->selection.start.y() -
- text->getRow(text->selection.start)->baseline()),
- text->top_y()),
- static_cast<int>(text->top_y() + workarea().workHeight()));
-
- if (kill_selection)
- text->selection.set(false);
-
- workarea().getPainter().start();
-
- drawFromTo(text, bv, top - text->top_y(), bottom - text->top_y(),
- yo, xo);
- expose(0, top - text->top_y(),
- workarea().workWidth(),
- bottom - text->top_y() - (top - text->top_y()));
-
- workarea().getPainter().end();
-}
-
-
-void LyXScreen::toggleToggle(LyXText * text, BufferView * bv,
- int yo, int xo)
-{
- if (text->toggle_cursor.par() == text->toggle_end_cursor.par()
- && text->toggle_cursor.pos() == text->toggle_end_cursor.pos())
- return;
-
- int const top_tmp = text->toggle_cursor.y()
- - text->getRow(text->toggle_cursor)->baseline();
- int const bottom_tmp = text->toggle_end_cursor.y()
- - text->getRow(text->toggle_end_cursor)->baseline()
- + text->getRow(text->toggle_end_cursor)->height();
-
- int const offset = yo < 0 ? yo : 0;
- int const bottom = min(max(bottom_tmp, text->top_y()),
- static_cast<int>(text->top_y() + workarea().workHeight())) - offset;
- int const top = min(max(top_tmp, text->top_y()),
- static_cast<int>(text->top_y() + workarea().workHeight())) - offset;
-
- workarea().getPainter().start();
-
- drawFromTo(text, bv, top - text->top_y(), bottom - text->top_y(), yo, xo);
- expose(0, top - text->top_y(), workarea().workWidth(),
- bottom - text->top_y() - (top - text->top_y()));
-
- workarea().getPainter().end();