-bool Text::cursorUp(Cursor & cur)
-{
- // Tell BufferView to test for FitCursor in any case!
- cur.updateFlags(Update::FitCursor);
-
- TextMetrics const & tm = cur.bv().textMetrics(this);
- ParagraphMetrics const & pm = tm.parMetrics(cur.pit());
-
- int row;
- if (cur.pos() && cur.boundary())
- row = pm.pos2row(cur.pos()-1);
- else
- row = pm.pos2row(cur.pos());
-
- // remember current position only if we are not at the end of a row.
- if (cur.pos() != pm.rows()[row].endpos())
- cur.setTargetX();
- int const x = cur.targetX();
-
- if (!cur.selection()) {
- int const y = bv_funcs::getPos(cur.bv(), cur, cur.boundary()).y_;
- Cursor old = cur;
- // Go to middle of previous row. 16 found to work OK;
- // 12 = top/bottom margin of display math
- int const margin = 3 * InsetMathHull::displayMargin() / 2;
- editXY(cur, x, y - pm.rows()[row].ascent() - margin);
- cur.clearSelection();
-
- // This happens when you move out of an inset.
- // And to give the DEPM the possibility of doing
- // something we must provide it with two different
- // cursors. (Lgb)
- Cursor dummy = cur;
- if (dummy == old)
- ++dummy.pos();
-
- cur.bv().checkDepm(dummy, old);
- return false;
- }
-
- bool updateNeeded = false;
-
- if (row > 0) {
- updateNeeded |= setCursor(cur, cur.pit(),
- tm.x2pos(cur.pit(), row - 1, x));
- } else if (cur.pit() > 0) {
- --cur.pit();
- //cannot use 'par' now
- ParagraphMetrics const & pmcur = cur.bv().parMetrics(this, cur.pit());
- updateNeeded |= setCursor(cur, cur.pit(),
- tm.x2pos(cur.pit(), pmcur.rows().size() - 1, x));
- }
-
- cur.x_target() = x;
-
- return updateNeeded;
-}
-
-
-bool Text::cursorDown(Cursor & cur)
-{
- // Tell BufferView to test for FitCursor in any case!
- cur.updateFlags(Update::FitCursor);
-
- TextMetrics const & tm = cur.bv().textMetrics(this);
- ParagraphMetrics const & pm = tm.parMetrics(cur.pit());
-
- int row;
- if (cur.pos() && cur.boundary())
- row = pm.pos2row(cur.pos()-1);
- else
- row = pm.pos2row(cur.pos());
-
- // remember current position only if we are not at the end of a row.
- if (cur.pos() != pm.rows()[row].endpos())
- cur.setTargetX();
- int const x = cur.targetX();
-
- if (!cur.selection()) {
- int const y = bv_funcs::getPos(cur.bv(), cur, cur.boundary()).y_;
- Cursor old = cur;
- // To middle of next row
- int const margin = 3 * InsetMathHull::displayMargin() / 2;
- editXY(cur, x, y + pm.rows()[row].descent() + margin);
- cur.clearSelection();
-
- // This happens when you move out of an inset.
- // And to give the DEPM the possibility of doing
- // something we must provide it with two different
- // cursors. (Lgb)
- Cursor dummy = cur;
- if (dummy == old)
- ++dummy.pos();
-
- bool const changed = cur.bv().checkDepm(dummy, old);
-
- // Make sure that cur gets back whatever happened to dummy(Lgb)
- if (changed)
- cur = dummy;
-
- return false;
- }
-
- bool updateNeeded = false;
-
- if (row + 1 < int(pm.rows().size())) {
- updateNeeded |= setCursor(cur, cur.pit(),
- tm.x2pos(cur.pit(), row + 1, x));
- } else if (cur.pit() + 1 < int(paragraphs().size())) {
- ++cur.pit();
- updateNeeded |= setCursor(cur, cur.pit(),
- tm.x2pos(cur.pit(), 0, x));
- }
-
- cur.x_target() = x;
-
- return updateNeeded;
-}
-
-