cursor work + absolute coords for lyxtext

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8107 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Alfredo Braunstein 2003-11-20 10:38:12 +00:00
parent c8507b7fcd
commit 614fbe566c
9 changed files with 51 additions and 114 deletions

View File

@ -1,3 +1,9 @@
2003-11-20 Alfredo Braunstein <abraunst@lyx.org>
* lyxtext.h: add x0_, y0_
* text3.C (cursorPrevious, cursorNext): rewrite (using x0_, y0_)
* text2.C (cursorDown, cursorUp): rewrite (using x0_, y0_)
2003-11-18 Alfredo Braunstein <abraunst@lyx.org>
* text2.C (setCursorIntern): move the x_target update here *

View File

@ -1,3 +1,7 @@
2003-11-20 Alfredo Braunstein <abraunst@lyx.org>
* insettext.C (draw): sets LyXText absolute coordinates
2003-11-20 Angus Leeming <leeming@lyx.org>
* insetcharstyle.C (latex, linuxdoc, docbook, plaintext): squash warnings

View File

@ -283,6 +283,7 @@ void InsetCollapsable::edit(BufferView * bv, int x, int y)
else
inset.edit(bv, x, ascent() + y - height_collapsed() + inset.ascent());
}
bv->cursor().push(this);
}

View File

@ -38,6 +38,7 @@
#include "paragraph_funcs.h"
#include "ParagraphParameters.h"
#include "rowpainter.h"
#include "lyxrow.h"
#include "sgml.h"
#include "texrow.h"
#include "undo.h"
@ -257,6 +258,9 @@ void InsetText::draw(PainterInfo & pi, int x, int y) const
x += TEXT_TO_INSET_OFFSET;
text_.x0_ = x;
text_.y0_ = y - text_.firstRow()->ascent_of_text() + bv->top_y();
paintTextInset(*bv, text_, x, y);
if (drawFrame_ == ALWAYS || drawFrame_ == LOCKED)
@ -340,10 +344,8 @@ void InsetText::edit(BufferView * bv, int x, int y)
lyxerr << "InsetText::edit xy" << endl;
old_par = -1;
sanitizeEmptyText(bv);
text_.setCursorFromCoordinates(x, y + dim_.asc);
text_.cursor.x(text_.cursor.x());
bv->x_target(text_.cursor.x());
text_.setCursorFromCoordinates(x - text_.x0_, y + bv->top_y()
- text_.y0_);
text_.clearSelection();
finishUndo();

View File

@ -1409,6 +1409,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
if (view()->available()) {
view()->fitCursor();
view()->update();
view()->cursor().updatePos();
// if we executed a mutating lfun, mark the buffer as dirty
if (!getStatus(func).disabled()

View File

@ -461,19 +461,19 @@ public:
///
bool checkAndActivateInset(bool front);
private:
/** Cursor related data.
Later this variable has to be removed. There should be now internal
cursor in a text */
///
///TextCursor cursor_;
/// prohibit this as long as there are back pointers...
LyXText(LyXText const &);
// cache for cursorPar()
mutable ParagraphList::iterator cache_par_;
mutable int cache_pos_;
public:
/// absolute document pixel coordinates of this LyXText
int x0_;
int y0_;
};
/// return the default height of a row in pixels, considering font zoom

View File

@ -74,7 +74,7 @@ LyXText::LyXText(BufferView * bv, InsetText * inset, bool ininset,
ParagraphList & paragraphs)
: height(0), width(0), inset_owner(inset), bv_owner(bv),
in_inset_(ininset), paragraphs_(&paragraphs),
cache_pos_(-1)
cache_pos_(-1), x0_(0), y0_(0)
{}
@ -1404,7 +1404,7 @@ void LyXText::setCursorIntern(paroffset_type par,
pos_type pos, bool setfont, bool boundary)
{
setCursor(cursor, par, pos, boundary);
bv()->x_target(cursor.x());
bv()->x_target(cursor.x() + x0_);
if (setfont)
setCurrentFont();
}
@ -1562,7 +1562,7 @@ void LyXText::setCursorFromCoordinates(int x, int y)
deleteEmptyParagraphMechanism(old_cursor);
}
//gets LyXText coordinates
void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y)
{
// Get the row first.
@ -1710,24 +1710,16 @@ void LyXText::cursorUp(bool selecting)
{
ParagraphList::iterator cpit = cursorPar();
Row const & crow = *cpit->getRow(cursor.pos());
#if 1
int x = bv()->x_target();
int x = bv()->x_target() - x0_;
int y = cursor.y() - crow.baseline() - 1;
setCursorFromCoordinates(x, y);
if (!selecting) {
int topy = bv()->top_y();
int y1 = cursor.y() - topy;
y -= topy;
InsetOld * inset_hit = checkInsetHit(x, y1);
y += y0_ - bv()->top_y();
lyxerr << "y:" << y << " y0: " << y0_ << endl;
InsetOld * inset_hit = checkInsetHit(bv()->x_target(), y);
if (inset_hit && isHighlyEditableInset(inset_hit))
inset_hit->edit(bv(), x, y);
}
#else
lyxerr << "cursorUp: y " << cursor.y() << " bl: " <<
crow.baseline() << endl;
setCursorFromCoordinates(bv()->x_target(),
cursor.y() - crow.baseline() - 1);
#endif
}
@ -1735,22 +1727,15 @@ void LyXText::cursorDown(bool selecting)
{
ParagraphList::iterator cpit = cursorPar();
Row const & crow = *cpit->getRow(cursor.pos());
#if 1
int x = bv()->x_target();
int x = bv()->x_target() - x0_;
int y = cursor.y() - crow.baseline() + crow.height() + 1;
setCursorFromCoordinates(x, y);
if (!selecting) {
int topy = bv()->top_y();
int y1 = cursor.y() - topy;
y -= topy;
InsetOld * inset_hit = checkInsetHit(x, y1);
y += y0_ - bv()->top_y();
InsetOld * inset_hit = checkInsetHit(bv()->x_target(), y);
if (inset_hit && isHighlyEditableInset(inset_hit))
inset_hit->edit(bv(), x, y);
}
#else
setCursorFromCoordinates(bv()->x_target(),
cursor.y() - crow.baseline() + crow.height() + 1);
#endif
}

View File

@ -362,103 +362,40 @@ void LyXText::gotoInset(InsetOld::Code code, bool same_content)
void LyXText::cursorPrevious()
{
int y = bv()->top_y();
ParagraphList::iterator cpit = cursorPar();
RowList::iterator crit = cpit->getRow(cursor.pos());
RowList::iterator crit = cursorRow();
if (isFirstRow(cpit, *crit)) {
if (y > 0)
bv()->updateScrollbar();
return;
}
int x = bv()->x_target() - x0_;
int y = bv()->top_y() - y0_;
setCursorFromCoordinates(x, y);
setCursorFromCoordinates(bv()->x_target(), y);
finishUndo();
if (crit == bv()->text->cursorRow()) {
if (crit == cursorRow()) {
// we have a row which is taller than the workarea. The
// simplest solution is to move to the previous row instead.
cursorUp(true);
return;
}
int new_y = + crit->height() - bv()->workHeight() + 1;
if (inset_owner) {
new_y += bv()->text->cursor.y()
+ bv()->cursor().innerInset()->insetInInsetY()
+ y;
} else {
new_y += cursor.y() - crit->baseline();
}
previousRow(cpit, crit);
LyXCursor cur;
setCursor(cur, parOffset(cpit), crit->pos(), false);
if (cur.y() > bv()->top_y())
cursorUp(true);
bv()->updateScrollbar();
finishUndo();
}
void LyXText::cursorNext()
{
int topy = bv()->top_y();
RowList::iterator crit = cursorRow();
ParagraphList::iterator cpit = cursorPar();
RowList::iterator crit = cpit->getRow(cursor.pos());
int x = bv()->x_target() - x0_;
int y = bv()->top_y() + bv()->workHeight() - y0_;
setCursorFromCoordinates(x, y);
if (isLastRow(cpit, *crit)) {
int y = cursor.y() - crit->baseline() + crit->height();
if (y > topy + bv()->workHeight())
bv()->updateScrollbar();
return;
}
int y = topy + bv()->workHeight();
if (inset_owner && !topy) {
y += - bv()->text->cursor.y()
+ bv()->top_y()
- bv()->cursor().innerInset()->insetInInsetY();
}
ParagraphList::iterator dummypit;
Row const & row = *getRowNearY(y, dummypit);
y = dummypit->y + row.y_offset();
setCursorFromCoordinates(bv()->x_target(), y);
// + bv->workHeight());
finishUndo();
int new_y;
if (crit == bv()->text->cursorRow()) {
if (crit == cursorRow()) {
// we have a row which is taller than the workarea. The
// simplest solution is to move to the next row instead.
cursorDown(true);
return;
// 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->top_y() + bv->workHeight();
#endif
}
if (inset_owner) {
new_y = bv()->text->cursor.y()
+ bv()->cursor().innerInset()->insetInInsetY()
+ y - crit->baseline();
} else {
new_y = cursor.y() - crit->baseline();
}
nextRow(cpit, crit);
LyXCursor cur;
setCursor(cur, parOffset(cpit), crit->pos(), false);
if (cur.y() < bv()->top_y() + bv()->workHeight())
cursorDown(true);
bv()->updateScrollbar();
finishUndo();
}
@ -1355,7 +1292,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
setCursorFromCoordinates(cmd.x, cmd.y);
selection.cursor = cursor;
finishUndo();
bv->x_target(cursor.x());
bv->x_target(cursor.x() + x0_);
if (bv->fitCursor())
selection_possible = false;
@ -1596,11 +1533,12 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
case LFUN_FINISHED_UP:
lyxerr << "swallow LFUN_FINISHED_UP" << endl;
cursorUp(true);
break;
case LFUN_FINISHED_DOWN:
lyxerr << "swallow LFUN_FINISHED_DOWN" << endl;
cursorRight(true);
cursorDown(true);
break;
default: