Fix for wrong cursor.x pos when before a fullRow inset (added ix), small

perfomance fix in LyXText's raw drawing, fix for adding paragraph in insets
when not allowed to do so (bug in Michaels list not on lyxbugs.).


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3990 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Vigna 2002-04-12 15:59:03 +00:00
parent 3ee9f0ac7d
commit ba21e6498c
11 changed files with 136 additions and 31 deletions

View File

@ -547,12 +547,12 @@ void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
cursor.par(), cursor.pos());
int width = bv_->theLockingInset()->width(bv_, font);
int inset_x = font.isVisibleRightToLeft()
? cursor.x() - width : cursor.x();
? cursor.ix() - width : cursor.ix();
int start_x = inset_x + bv_->theLockingInset()->scroll();
bv_->theLockingInset()->
insetMotionNotify(bv_,
x - start_x,
y - cursor.y() + bv_->text->first_y,
y - cursor.iy() + bv_->text->first_y,
state);
return;
}

View File

@ -1,7 +1,21 @@
2002-04-12 Juergen Vigna <jug@sad.it>
* BufferView_pimpl.C (workAreaMotionNotify): use new ix() cursor pos.
* text2.C (getCursorX): new helper function
(setCursor): compute also ix_
(setCursorFromCoordinates): set also ix.
* lyxcursor.h: added ix_ and helper functions.
* BufferView_pimpl.C (workAreaMotionNotify): forgot to use iy().
* buffer.C (insertStringAsLines): dont break paragraph if the this
paragraph is inside an inset which does not permit it!
* text.C (breakParagraph): honor keepempty flag and break the paragraph
also with no chars on this paragraph.
(paintRowText): only paint stuff if it's inside the workarea!
* paragraph.C (breakParagraph): honor keepempty flag and break the
paragraph always below not above.

View File

@ -1400,10 +1400,12 @@ void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
par->checkInsertChar(font);
// insert the string, don't insert doublespace
bool space_inserted = true;
bool autobreakrows = !par->inInset() ||
static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
for(string::const_iterator cit = str.begin();
cit != str.end(); ++cit) {
if (*cit == '\n') {
if (par->size() || layout.keepempty) {
if (autobreakrows && (par->size() || layout.keepempty)) {
par->breakParagraph(params, pos,
layout.isEnvironment());
par = par->next();

View File

@ -1,3 +1,7 @@
2002-04-12 Juergen Vigna <jug@sad.it>
* insettext.h: added cix() helper function and use it where appropriate
2002-04-12 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
* insetgraphics.C (prepareFile): fix bug when graphics is a
@ -6,6 +10,9 @@
2002-04-12 Juergen Vigna <jug@sad.it>
* insettext.C (insertInset): remove unneeded code!
(updateLocal): fitCursor() fixes.
(collapseParagraphs): fix a possible problem when having a selection
and collapsing the paragraphs.
2002-04-08 Herbert Voss <voss@perce.de>

View File

@ -424,7 +424,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
if (the_locking_inset && (cpar(bv) == inset_par)
&& (cpos(bv) == inset_pos)) {
inset_x = cx(bv) - top_x + drawTextXOffset;
inset_x = cix(bv) - top_x + drawTextXOffset;
inset_y = ciy(bv) + drawTextYOffset;
}
if (!cleared && (need_update == CURSOR)
@ -555,10 +555,10 @@ void InsetText::update(BufferView * bv, LyXFont const & font, bool reinit)
}
if (!autoBreakRows && par->next())
collapseParagraphs(bv->buffer()->params);
collapseParagraphs(bv);
if (the_locking_inset) {
inset_x = cx(bv) - top_x + drawTextXOffset;
inset_x = cix(bv) - top_x + drawTextXOffset;
inset_y = ciy(bv) + drawTextYOffset;
the_locking_inset->update(bv, font, reinit);
}
@ -610,7 +610,7 @@ void InsetText::setUpdateStatus(BufferView * bv, int what) const
void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty) const
{
if (!autoBreakRows && par->next())
collapseParagraphs(bv->buffer()->params);
collapseParagraphs(bv);
bool clear = false;
if (!lt) {
lt = getLyXText(bv);
@ -625,8 +625,15 @@ void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty) const
lt->selection.cursor = lt->cursor;
if (clear)
lt = 0;
#if 0
// IMO this is not anymore needed as we do this in fitInsetCursor!
// and we always get "true" as returnvalue of this function in the
// case of a locking inset (Jug 20020412)
if (locked && (need_update & CURSOR) && bv->fitCursor())
need_update |= FULL;
#else
bv->fitCursor();
#endif
if (flag)
bv->updateInset(const_cast<InsetText *>(this), mark_dirty);
@ -785,7 +792,7 @@ void InsetText::insetUnlock(BufferView * bv)
void InsetText::lockInset(BufferView * bv, UpdatableInset * inset)
{
the_locking_inset = inset;
inset_x = cx(bv) - top_x + drawTextXOffset;
inset_x = cix(bv) - top_x + drawTextXOffset;
inset_y = ciy(bv) + drawTextYOffset;
inset_pos = cpos(bv);
inset_par = cpar(bv);
@ -831,7 +838,7 @@ bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
} else if (the_locking_inset && (the_locking_inset == inset)) {
if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
lyxerr[Debug::INSETS] << "OK" << endl;
inset_x = cx(bv) - top_x + drawTextXOffset;
inset_x = cix(bv) - top_x + drawTextXOffset;
inset_y = ciy(bv) + drawTextYOffset;
} else {
lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
@ -870,7 +877,7 @@ bool InsetText::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
bool InsetText::updateInsetInInset(BufferView * bv, Inset * inset)
{
if (!autoBreakRows && par->next())
collapseParagraphs(bv->buffer()->params);
collapseParagraphs(bv);
if (inset == this)
return true;
bool clear = false;
@ -909,7 +916,7 @@ bool InsetText::updateInsetInInset(BufferView * bv, Inset * inset)
if (the_locking_inset &&
cpar(bv) == inset_par && cpos(bv) == inset_pos)
{
inset_x = cx(bv) - top_x + drawTextXOffset;
inset_x = cix(bv) - top_x + drawTextXOffset;
inset_y = ciy(bv) + drawTextYOffset;
}
}
@ -942,7 +949,7 @@ void InsetText::insetButtonPress(BufferView * bv, int x, int y, int button)
else if (inset) {
// otherwise unlock the_locking_inset and lock the new inset
the_locking_inset->insetUnlock(bv);
inset_x = cx(bv) - top_x + drawTextXOffset;
inset_x = cix(bv) - top_x + drawTextXOffset;
inset_y = ciy(bv) + drawTextYOffset;
the_locking_inset = 0;
inset->insetButtonPress(bv, x - inset_x,
@ -1043,7 +1050,7 @@ bool InsetText::insetButtonRelease(BufferView * bv, int x, int y, int button)
ret = inset->insetButtonRelease(bv, x - inset_x,
y - inset_y, button);
} else {
inset_x = cx(bv) - top_x + drawTextXOffset;
inset_x = cix(bv) - top_x + drawTextXOffset;
inset_y = ciy(bv) + drawTextYOffset;
ret = inset->insetButtonRelease(bv, x - inset_x,
y - inset_y, button);
@ -2009,7 +2016,7 @@ bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
x = insetWidth;
if (y < 0)
y = insetDescent;
inset_x = cx(bv) - top_x + drawTextXOffset;
inset_x = cix(bv) - top_x + drawTextXOffset;
inset_y = ciy(bv) + drawTextYOffset;
inset->edit(bv, x - inset_x, y - inset_y, button);
if (!the_locking_inset)
@ -2120,6 +2127,21 @@ int InsetText::cx(BufferView * bv) const
}
int InsetText::cix(BufferView * bv) const
{
// we do nothing dangerous so we use a local cache
LyXText * llt = getLyXText(bv);
int x = llt->cursor.ix() + top_x + TEXT_TO_INSET_OFFSET;
if (the_locking_inset) {
LyXFont font = llt->getFont(bv->buffer(), llt->cursor.par(),
llt->cursor.pos());
if (font.isVisibleRightToLeft())
x -= the_locking_inset->width(bv, font);
}
return x;
}
int InsetText::cy(BufferView * bv) const
{
LyXFont font;
@ -2282,7 +2304,7 @@ void InsetText::resizeLyXText(BufferView * bv, bool force) const
t->init(bv, true);
restoreLyXTextState(bv, t);
if (the_locking_inset) {
inset_x = cx(bv) - top_x + drawTextXOffset;
inset_x = cix(bv) - top_x + drawTextXOffset;
inset_y = ciy(bv) + drawTextYOffset;
}
@ -2323,7 +2345,7 @@ void InsetText::reinitLyXText() const
t->init(bv, true);
restoreLyXTextState(bv, t);
if (the_locking_inset) {
inset_x = cx(bv) - top_x + drawTextXOffset;
inset_x = cix(bv) - top_x + drawTextXOffset;
inset_y = ciy(bv) + drawTextYOffset;
}
if (bv->screen()) {
@ -2656,14 +2678,29 @@ bool InsetText::checkInsertChar(LyXFont & font)
}
void InsetText::collapseParagraphs(BufferParams const & bparams) const
void InsetText::collapseParagraphs(BufferView * bv) const
{
BufferParams const & bparams = bv->buffer()->params;
LyXText * llt = getLyXText(bv);
while(par->next()) {
if (par->size() && par->next()->size() &&
!par->isSeparator(par->size()-1))
{
par->insertChar(par->size(), ' ');
}
if (llt->selection.set()) {
if (llt->selection.start.par() == par->next()) {
llt->selection.start.par(par);
llt->selection.start.pos(
llt->selection.start.pos() + par->size());
}
if (llt->selection.end.par() == par->next()) {
llt->selection.end.par(par);
llt->selection.end.pos(
llt->selection.end.pos() + par->size());
}
}
par->pasteParagraph(bparams);
}
reinitLyXText();

View File

@ -321,6 +321,8 @@ private:
///
int cx(BufferView *) const;
///
int cix(BufferView *) const;
///
int cy(BufferView *) const;
///
int ciy(BufferView *) const;
@ -345,7 +347,7 @@ private:
///
void reinitLyXText() const;
///
void collapseParagraphs(BufferParams const & bparams) const;
void collapseParagraphs(BufferView *) const;
/* Private structures and variables */
///

View File

@ -19,7 +19,7 @@
LyXCursor::LyXCursor()
: par_(0), pos_(0), boundary_(false),
x_(0), x_fix_(0), y_(0), iy_(0), row_(0)
x_(0), ix_(0), x_fix_(0), y_(0), iy_(0), row_(0)
{}
@ -70,6 +70,17 @@ int LyXCursor::x() const
}
void LyXCursor::ix(int n)
{
ix_ = n;
}
int LyXCursor::ix() const
{
return ix_;
}
void LyXCursor::x_fix(int i)
{
x_fix_ = i;

View File

@ -44,6 +44,10 @@ public:
///
int x() const;
///
void ix(int i);
///
int ix() const;
///
void x_fix(int i);
///
int x_fix() const;
@ -68,6 +72,9 @@ private:
bool boundary_;
///
int x_;
/// the x position of the position before the inset when we put
/// the cursor on the end of the row before, otherwise equal to x.
int ix_;
///
int x_fix_;
///

View File

@ -321,6 +321,9 @@ public:
bool setfont = true,
bool boundary = false) const;
///
float getCursorX(BufferView *, Row *, lyx::pos_type pos,
lyx::pos_type last, bool boundary) const;
///
void setCurrentFont(BufferView *) const;
///

View File

@ -3609,7 +3609,14 @@ void LyXText::paintRowText(DrawRowParams & p)
pos_type vpos = p.row->pos();
while (vpos <= last) {
if (p.x > p.bv->workWidth())
break;
pos_type pos = vis2log(vpos);
if (p.x + singleWidth(p.bv, par, pos) < 0) {
p.x += singleWidth(p.bv, par, pos);
++vpos;
continue;
}
if (main_body > 0 && pos == main_body - 1) {
int const lwidth = lyxfont::width(layout.labelsep,
getLabelFont(buffer, par));

View File

@ -2083,14 +2083,6 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
// y is now the cursor baseline
cur.y(y);
// now get the cursors x position
float x;
float fill_separator;
float fill_hfill;
float fill_label_hfill;
prepareToPrint(bview, row, x, fill_separator, fill_hfill,
fill_label_hfill);
pos_type cursor_vpos = 0;
pos_type last = rowLastPrintable(old_row);
if (pos > last + 1) {
@ -2102,6 +2094,30 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
cur.pos(pos);
}
// now get the cursors x position
float x = getCursorX(bview, row, pos, last, boundary);
cur.x(int(x));
cur.x_fix(cur.x());
if (old_row != row) {
x = getCursorX(bview, old_row, pos, last, boundary);
cur.ix(int(x));
} else
cur.ix(cur.x());
}
float LyXText::getCursorX(BufferView * bview, Row * row,
pos_type pos, pos_type last, bool boundary) const
{
pos_type cursor_vpos = 0;
float x;
float fill_separator;
float fill_hfill;
float fill_label_hfill;
// This call HAS to be here because of the BidiTables!!!
prepareToPrint(bview, row, x, fill_separator, fill_hfill,
fill_label_hfill);
if (last < row->pos())
cursor_vpos = row->pos();
else if (pos > last && !boundary)
@ -2125,7 +2141,7 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
main_body = 0;
for (pos_type vpos = row->pos(); vpos < cursor_vpos; ++vpos) {
pos = vis2log(vpos);
pos_type pos = vis2log(vpos);
if (main_body > 0 && pos == main_body - 1) {
x += fill_label_hfill +
lyxfont::width(textclasslist[
@ -2149,9 +2165,7 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
} else
x += singleWidth(bview, row->par(), pos);
}
cur.x(int(x));
cur.x_fix(cur.x());
return x;
}
@ -2248,6 +2262,7 @@ void LyXText::setCursorFromCoordinates(BufferView * bview, LyXCursor & cur,
cur.par(row->par());
cur.pos(row->pos() + column);
cur.x(x);
cur.ix(x);
cur.y(y + row->baseline());
Inset * ins;
if (row->next() && cur.pos() &&