fitCursor work

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8079 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Alfredo Braunstein 2003-11-13 08:50:26 +00:00
parent 59fefa0759
commit 79ae54d4c0
22 changed files with 113 additions and 216 deletions

View File

@ -369,25 +369,6 @@ void BufferView::replaceWord(string const & replacestring)
}
bool BufferView::fitLockedInsetCursor(int x, int y, int asc, int desc)
{
lyxerr << "BufferView::fitLockedInsetCursor x: " << x
<< " y: " << y << std::endl;
UpdatableInset * tli =
static_cast<UpdatableInset *>(cursor().innerInset());
if (tli && available()) {
lyxerr << " text->cursor.y: " << text->cursor.y() << std::endl;
lyxerr << " insetInInsetY: " << tli->insetInInsetY() << std::endl;
y += text->cursor.y() + tli->insetInInsetY();
if (screen().fitManualCursor(this, text, x, y, asc, desc)) {
updateScrollbar();
return true;
}
}
return false;
}
void BufferView::hideCursor()
{
screen().hideCursor();

View File

@ -313,7 +313,7 @@ void BufferView::Pimpl::buffer(Buffer * b)
resizeCurrentBuffer();
// FIXME: needed when ?
top_y(screen().topCursorVisible(bv_->text));
fitCursor();
// Buffer-dependent dialogs should be updated or
// hidden. This should go here because some dialogs (eg ToC)
@ -343,42 +343,11 @@ void BufferView::Pimpl::buffer(Buffer * b)
bool BufferView::Pimpl::fitCursor()
{
lyxerr << "BufferView::Pimpl::fitCursor." << endl;
int x,y;
bv_->cursor().getPos(x, y);
if (y < top_y() || y > top_y() + workarea().workHeight()) {
int newtop = y - workarea().workHeight() / 2;
newtop = std::max(0, newtop);
top_y(newtop);
if (screen().fitCursor(bv_)) {
updateScrollbar();
return true;
}
return false;
// dead code below
bool ret;
#if 0
UpdatableInset * tli =
static_cast<UpdatableInset *>(cursor_.innerInset());
if (tli) {
tli->fitInsetCursor(bv_);
ret = true;
} else {
ret = screen().fitCursor(bv_->text, bv_);
}
#endif
#if 0
ret = screen().fitCursor(bv_->text, bv_);
#endif
//dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
// We need to always update, in case we did a
// paste and we stayed anchored to a row, but
// the actual height of the doc changed ...
updateScrollbar();
return ret;
}
@ -446,7 +415,7 @@ void BufferView::Pimpl::resizeCurrentBuffer()
}
}
top_y(screen().topCursorVisible(bv_->text));
fitCursor();
switchKeyMap();
owner_->busy(false);
@ -973,8 +942,8 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd)
theTempCursor.pop();
bv_->cursor() = theTempCursor;
bv_->cursor().innerText()->setCursorFromCoordinates(cmd.x, top_y() + cmd.y);
bv_->cursor().updatePos();
bv_->fitCursor();
if (bv_->fitCursor())
bv_->update();
return true;
default:
lyxerr << "not dispatched by inner inset val: " << res.val() << endl;
@ -984,24 +953,26 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd)
// otherwise set cursor to surrounding LyXText
if (!res.dispatched()) {
lyxerr << "cursor is: " << bv_->cursor() << endl;
lyxerr << "temp cursor is: " << theTempCursor << endl;
lyxerr << "dispatching " << cmd1
<< " to surrounding LyXText "
<< bv_->cursor().innerText() << endl;
<< theTempCursor.innerText() << endl;
bv_->cursor() = theTempCursor;
theTempCursor.dispatch(cmd1);
res = bv_->cursor().innerText()->dispatch(cmd1);
if (bv_->fitCursor() || res.update())
bv_->update();
bv_->cursor().updatePos();
//return DispatchResult(true, true);
}
// see workAreaKeyPress
cursor_timeout.restart();
screen().showCursor(*bv_);
// FIXME: we should skip these when selecting
// skip these when selecting
if (cmd.action != LFUN_MOUSE_MOTION) {
owner_->updateLayoutChoice();
owner_->updateToolbar();
// fitCursor();
}
// slight hack: this is only called currently when we
// clicked somewhere, so we force through the display
@ -1295,7 +1266,6 @@ bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout)
string(),
0);
}
bv_->cursor().innerText()->insertInset(inset);
update();

View File

@ -1,3 +1,10 @@
2003-11-13 Alfredo Braunstein <abraunst@lyx.org>
* BufferView_pimpl.C (fitCursor): call screen().fitCursor()
* BufferView.C (fitLockedInsetCursor): remove
* cursor.[Ch] (getDim): add
* text.C (getRowNearY): add faster version
* text3.C: remove some update calls
2003-11-12 Martin Vermeer <martin.vermeer@hut.fi>

View File

@ -20,6 +20,7 @@
#include "lfuns.h"
#include "lyxtext.h"
#include "paragraph.h"
#include "lyxrow.h"
#include "insets/updatableinset.h"
#include "insets/insettabular.h"
@ -164,6 +165,19 @@ void LCursor::updatePos()
}
void LCursor::getDim(int & asc, int & desc) const
{
LyXText * txt = innerText();
if (txt) {
Row const & row = *txt->cursorRow();
asc = row.baseline();
desc = row.height() - asc;
} else
innerInset()->getCursorDim(bv_, asc, desc);
}
void LCursor::getPos(int & x, int & y) const
{
if (data_.empty()) {

View File

@ -75,6 +75,8 @@ public:
LyXText * innerText() const;
/// returns x,y position
void getPos(int & x, int & y) const;
/// returns cursor dimension
void getDim(int & asc, int & desc) const;
/// cache the absolute coordinate from the top inset
void updatePos();
///

View File

@ -1,3 +1,10 @@
2003-11-13 Alfredo Braunstein <abraunst@lyx.org>
* screen.[Ch] (fitCursor): use LCursor::getDim, simplify
(fitManualCursor): remove
(topCursorVisible): remove
2003-11-11 Alfredo Braunstein <abraunst@libero.it>
* screen.C (showCursor): use absolute coords form LCursor

View File

@ -204,70 +204,39 @@ void LyXScreen::toggleCursor(BufferView & bv)
}
bool LyXScreen::fitManualCursor(BufferView * bv, LyXText *,
int x, int y, int asc, int desc)
bool LyXScreen::fitCursor(BufferView * bv)
{
lyxerr << "LyXScreen::fitManualCursor x: " << x << " y: " << y << std::endl;
int const vheight = workarea().workHeight();
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 < topy && topy > 0)
newtop = y - vheight / 4;
newtop = max(newtop, 0); // can newtop ever be < 0? (Lgb)
if (newtop == topy)
return false;
bv->top_y(newtop);
return true;
}
unsigned int LyXScreen::topCursorVisible(LyXText * text)
{
LyXCursor const & cursor = text->cursor;
int top_y = text->bv()->top_y();
int const top_y = bv->top_y();
int const h = workarea().workHeight();
int newtop = top_y;
unsigned int const vheight = workarea().workHeight();
int x, y, asc, desc;
Row & row = *text->cursorPar()->getRow(cursor.pos());
bv->cursor().getPos(x, y);
bv->cursor().getDim(asc, desc);
if (int(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;
}
bool const big_row = h / 4 < asc + desc && asc + desc < h;
} else if (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;
if (y + desc - top_y >= h) {
if (big_row)
newtop = y + desc - h;
else
newtop = y - h / 2;
} else if (top_y > max(y - asc, 0)) {
if (big_row)
newtop = y - asc;
else {
newtop = y - h / 2;
newtop = min(newtop, top_y);
}
}
return max(newtop, 0);
}
newtop = max(newtop, 0);
if (newtop == top_y)
return false;
bool LyXScreen::fitCursor(LyXText * text, BufferView * bv)
{
// Is a change necessary?
int const newtop = topCursorVisible(text);
bool const result = (newtop != bv->top_y());
bv->top_y(newtop);
return result;
return true;
}

View File

@ -36,42 +36,17 @@ public:
virtual ~LyXScreen();
/**
* fit the cursor onto the visible work area, scrolling if necessary
* @param bv the buffer view
* @param vheight the height of the visible region
* @param base_y the top of the lyxtext to look at
* @param x the new x position
* @param y the new y position
* @param a ascent of the cursor's row
* @param d descent of the cursor's row
* @return true if the work area needs scrolling as a result
*/
bool fitManualCursor(BufferView * bv, LyXText * text,
int x, int y, int a, int d);
/// redraw the screen, without using existing pixmap
virtual void redraw(BufferView & bv);
/**
* topCursorVisible - get a new "top" to make the cursor visible
* in a LyXText
*
* This helper function calculates a new y co-ordinate for
* the top of the containing region such that the cursor contained
* within the LyXText is "nicely" visible.
*/
virtual unsigned int topCursorVisible(LyXText *);
/**
* fitCursor - fit the cursor onto the work area
* @param text the text containing the cursor
* @param bv the bufferview
* @return true if a change was necessary
*
* Scrolls the screen so that the cursor is visible
*/
virtual bool fitCursor(LyXText *, BufferView *);
virtual bool fitCursor(BufferView *);
/// hide the visible cursor, if it is visible
void hideCursor();

View File

@ -1,3 +1,11 @@
2003-11-13 Alfredo Braunstein <abraunst@lyx.org>
* insetcollapsable.[Ch] (fitInsetCursor): remove
* insettabular.[Ch] (fitInsetCursor): remove
* insettext.[Ch] (fitInsetCursor): remove
* updatableinset.[Ch] (fitInsetCursor): remove
(getCursorDIm): add virtual
2003-11-12 Martin Vermeer <martin.vermeer@hut.fi>
* src/insets/Makefile.am:

View File

@ -433,12 +433,6 @@ bool InsetCollapsable::insetAllowed(InsetOld::Code code) const
}
void InsetCollapsable::fitInsetCursor(BufferView * bv) const
{
inset.fitInsetCursor(bv);
}
void InsetCollapsable::setLabelFont(LyXFont & f)
{
labelfont_ = f;

View File

@ -79,8 +79,6 @@ public:
/// get the screen x,y of the cursor
void getCursorPos(BufferView *, int & x, int & y) const;
///
void fitInsetCursor(BufferView * bv) const;
///
void setFont(BufferView *, LyXFont const &, bool toggleall = false,
bool selectall = false);
///

View File

@ -973,22 +973,6 @@ void InsetTabular::getCursorPos(BufferView *, int & x, int & y) const
}
void InsetTabular::fitInsetCursor(BufferView * bv) const
{
if (the_locking_inset) {
the_locking_inset->fitInsetCursor(bv);
return;
}
LyXFont font;
int const asc = font_metrics::maxAscent(font);
int const desc = font_metrics::maxDescent(font);
resetPos(bv);
bv->fitLockedInsetCursor(cursorx_, cursory_, asc, desc);
}
void InsetTabular::setPos(BufferView * bv, int x, int y) const
{
cursory_ = 0;

View File

@ -196,8 +196,6 @@ private:
void drawCellSelection(Painter &, int x, int baseline,
int row, int column, int cell) const;
///
void fitInsetCursor(BufferView *) const;
///
void setPos(BufferView *, int x, int y) const;
///
DispatchResult moveRight(BufferView *, bool lock);

View File

@ -699,15 +699,6 @@ int InsetText::insetInInsetY() const
}
void InsetText::fitInsetCursor(BufferView * bv) const
{
LyXFont const font = text_.getFont(cpar(), cpos());
int const asc = font_metrics::maxAscent(font);
int const desc = font_metrics::maxDescent(font);
bv->fitLockedInsetCursor(cx(), cy(), asc, desc);
}
DispatchResult InsetText::moveRight(BufferView * bv)
{
if (text_.cursorPar()->isRightToLeftPar(bv->buffer()->params()))

View File

@ -93,8 +93,6 @@ public:
///
int insetInInsetY() const;
///
void fitInsetCursor(BufferView *) const;
///
bool insertInset(BufferView *, InsetOld *);
///
bool insetAllowed(InsetOld::Code) const;

View File

@ -23,6 +23,8 @@
#include "support/lstrings.h"
#include <boost/assert.hpp>
using lyx::support::strToDbl;
using lyx::support::strToInt;
@ -35,10 +37,6 @@ InsetOld::EDITABLE UpdatableInset::editable() const
}
void UpdatableInset::fitInsetCursor(BufferView *) const
{}
void UpdatableInset::scroll(BufferView * bv, float s) const
{
if (!s) {
@ -107,3 +105,9 @@ UpdatableInset::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &)
return DispatchResult(false);
}
}
void UpdatableInset::getCursorDim(BufferView *, int &, int &) const
{
BOOST_ASSERT(false);
}

View File

@ -29,10 +29,10 @@ public:
///
virtual EDITABLE editable() const;
///
virtual void fitInsetCursor(BufferView *) const;
/// FIXME
/// return the cursor pos, relative to the inset pos
virtual void getCursorPos(BufferView *, int &, int &) const {}
/// return the cursor dim
virtual void getCursorDim(BufferView *, int &, int &) const;
///
virtual bool insertInset(BufferView *, InsetOld *) { return false; }
///

View File

@ -1,3 +1,6 @@
2003-11-13 Alfredo Braunstein <abraunst@lyx.org>
* formulabase.[Ch] (getCursorDim): add
2003-11-10 André Pönitz <poenitz@gmx.net>

View File

@ -186,18 +186,14 @@ void InsetFormulaBase::getCursorPos(BufferView *, int & x, int & y) const
}
void InsetFormulaBase::fitInsetCursor(BufferView * bv) const
void InsetFormulaBase::getCursorDim(BufferView * bv,
int & asc, int & desc) const
{
if (!mathcursor)
return;
int x, y, asc, des;
asc = 10;
des = 2;
desc = 2;
//math_font_max_dim(font_, asc, des);
getCursorPos(bv, x, y);
//y += yo_;
//lyxerr << "fitInsetCursor: x: " << x << " y: " << y << " yo: " << yo_ << endl;
bv->fitLockedInsetCursor(x, y, asc, des);
}
@ -745,7 +741,6 @@ InsetFormulaBase::priv_dispatch(FuncRequest const & cmd,
toggleInsetSelection(bv);
if (result.dispatched()) {
fitInsetCursor(bv);
revealCodes(bv);
cmd.view()->stuffClipboard(mathcursor->grabSelection());
} else {

View File

@ -45,9 +45,9 @@ public:
/// what appears in the minibuffer when opening
virtual std::string const editMessage() const;
///
virtual void fitInsetCursor(BufferView *) const;
/// FIXME
virtual void getCursorPos(BufferView *, int &, int &) const;
///
virtual void getCursorDim(BufferView *, int &, int &) const;
/// get the absolute document x,y of the cursor
virtual void getCursor(BufferView & bv, int & x, int & y) const;
///

View File

@ -1467,18 +1467,20 @@ RowList::iterator
LyXText::getRowNearY(int y, ParagraphList::iterator & pit) const
{
//lyxerr << "getRowNearY: y " << y << endl;
#if 0
ParagraphList::iterator const pend = ownerParagraphs().end();
#if 1
ParagraphList::iterator const
pend = boost::prior(ownerParagraphs().end());
pit = ownerParagraphs().begin();
while (int(pit->y + pit->height) < y && pit != pend)
++pit;
RowList::iterator rit = pit->rows.begin();
RowList::iterator const rend = pit->rows.end();
while (int(pit->y + rit->y_offset()) < y && rit != rend)
++rit;
return rit;
RowList::iterator rit = pit->rows.end();
RowList::iterator const rbegin = pit->rows.begin();
do {
--rit;
} while (rit != rbegin && int(pit->y + rit->y_offset()) > y);
return rit;
#else
pit = boost::prior(ownerParagraphs().end());

View File

@ -227,7 +227,7 @@ namespace {
if (!lt->selection.set())
bv->haveSelection(false);
bv->update();
// bv->update();
bv->switchKeyMap();
}
@ -495,8 +495,7 @@ void doInsertInset(LyXText * lt, FuncRequest const & cmd,
inset->edit(bv, true);
if (gotsel && pastesel)
bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
}
else
} else
delete inset;
}
}
@ -1290,7 +1289,6 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
selection.cursor = cursor;
cursorEnd();
setSelection();
bv->update();
bv->haveSelection(selection.set());
}
break;
@ -1300,7 +1298,6 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
break;
if (cmd.button() == mouse_button::button1) {
selectWord(lyx::WHOLE_WORD_STRICT);
bv->update();
bv->haveSelection(selection.set());
}
break;
@ -1352,15 +1349,15 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
<< bv->text->cursor.y() << endl;
#endif
// This is to allow jumping over large insets
if (cursorrow == bv->text->cursorRow()) {
if (cursorrow == cursorRow()) {
if (cmd.y >= bv->workHeight())
bv->text->cursorDown(false);
cursorDown(false);
else if (cmd.y < 0)
bv->text->cursorUp(false);
cursorUp(false);
}
bv->text->setSelection();
bv->update();
// bv->update();
break;
}
@ -1428,13 +1425,13 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
}
case LFUN_MOUSE_RELEASE: {
// do nothing if we used the mouse wheel
if (!bv->buffer())
break;
// do nothing if we used the mouse wheel
if (cmd.button() == mouse_button::button4
|| cmd.button() == mouse_button::button5)
break;
return DispatchResult(true, false);
selection_possible = false;