}
-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();
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)
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;
}
}
}
- top_y(screen().topCursorVisible(bv_->text));
+ fitCursor();
switchKeyMap();
owner_->busy(false);
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;
// 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);
- bv_->update();
- bv_->cursor().updatePos();
+ res = bv_->cursor().innerText()->dispatch(cmd1);
+ if (bv_->fitCursor() || res.update())
+ bv_->update();
+
//return DispatchResult(true, true);
}
// see workAreaKeyPress
cursor_timeout.restart();
screen().showCursor(*bv_);
- // FIXME: we should skip these when selecting
- owner_->updateLayoutChoice();
- owner_->updateToolbar();
-// fitCursor();
+ // skip these when selecting
+ if (cmd.action != LFUN_MOUSE_MOTION) {
+ owner_->updateLayoutChoice();
+ owner_->updateToolbar();
+ }
// slight hack: this is only called currently when we
// clicked somewhere, so we force through the display
string(),
0);
}
-
bv_->cursor().innerText()->insertInset(inset);
update();
+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>
#include "lfuns.h"
#include "lyxtext.h"
#include "paragraph.h"
+#include "lyxrow.h"
#include "insets/updatableinset.h"
#include "insets/insettabular.h"
}
+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()) {
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();
///
+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
}
-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();
-
- Row & row = *text->cursorPar()->getRow(cursor.pos());
-
- 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;
- }
-
- } 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;
+ int x, y, asc, desc;
+
+ bv->cursor().getPos(x, y);
+ bv->cursor().getDim(asc, desc);
+
+ bool const big_row = h / 4 < asc + desc && asc + desc < h;
+
+ 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;
}
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();
+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:
}
-void InsetCollapsable::fitInsetCursor(BufferView * bv) const
-{
- inset.fitInsetCursor(bv);
-}
-
-
void InsetCollapsable::setLabelFont(LyXFont & f)
{
labelfont_ = f;
/// 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);
///
}
-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;
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);
}
-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()))
///
int insetInInsetY() const;
///
- void fitInsetCursor(BufferView *) const;
- ///
bool insertInset(BufferView *, InsetOld *);
///
bool insetAllowed(InsetOld::Code) const;
#include "support/lstrings.h"
+#include <boost/assert.hpp>
+
using lyx::support::strToDbl;
using lyx::support::strToInt;
}
-void UpdatableInset::fitInsetCursor(BufferView *) const
-{}
-
-
void UpdatableInset::scroll(BufferView * bv, float s) const
{
if (!s) {
return DispatchResult(false);
}
}
+
+
+void UpdatableInset::getCursorDim(BufferView *, int &, int &) const
+{
+ BOOST_ASSERT(false);
+}
///
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; }
///
+2003-11-13 Alfredo Braunstein <abraunst@lyx.org>
+
+ * formulabase.[Ch] (getCursorDim): add
2003-11-10 André Pönitz <poenitz@gmx.net>
}
-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);
}
toggleInsetSelection(bv);
if (result.dispatched()) {
- fitInsetCursor(bv);
revealCodes(bv);
cmd.view()->stuffClipboard(mathcursor->grabSelection());
} else {
/// 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;
///
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;
+ 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());
if (!lt->selection.set())
bv->haveSelection(false);
- bv->update();
+// bv->update();
bv->switchKeyMap();
}
inset->edit(bv, true);
if (gotsel && pastesel)
bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
- }
- else
+ } else
delete inset;
}
}
selection.cursor = cursor;
cursorEnd();
setSelection();
- bv->update();
bv->haveSelection(selection.set());
}
break;
break;
if (cmd.button() == mouse_button::button1) {
selectWord(lyx::WHOLE_WORD_STRICT);
- bv->update();
bv->haveSelection(selection.set());
}
break;
<< 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;
}
}
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;