More textinset fixes! Now also undo works and I removed some unneeded

computation. Please test and tell me if there are more problems you see.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@683 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Vigna 2000-04-20 13:48:34 +00:00
parent ff5ca3cd82
commit 054dd779e6
5 changed files with 98 additions and 54 deletions

View File

@ -1,3 +1,16 @@
2000-04-20 Juergen Vigna <jug@sad.it>
* src/insets/insettext.C (cutSelection):
(copySelection): Fixed with selection from right to left.
(draw): now the rows are not recalculated at every draw.
(computeTextRows): for now reset the inset-owner here (this is
important for an undo or copy where the inset-owner is not set
automatically!)
* src/BufferView_pimpl.C (workAreaMotionNotify): when passing the
motion to the_locking_inset screen->first was forgotten, this was
not important till we got multiline insets.
2000-04-19 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* src/mathed/formulamacro.C (Latex): remove CHECK comment, since

View File

@ -561,7 +561,7 @@ void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
bv_->the_locking_inset->
InsetMotionNotify(bv_,
x - cursor.x,
y - cursor.y,
y - cursor.y + screen->first,
state);
return;
}
@ -973,7 +973,9 @@ Inset * BufferView::Pimpl::checkInsetHit(int & x, int & y, unsigned int /* butto
if (x > start_x && x < end_x
&& y_tmp > cursor.y - tmpinset->ascent(bv_->painter(), font)
&& y_tmp < cursor.y + tmpinset->descent(bv_->painter(), font)) {
#if 0
if (move_cursor && (tmpinset != bv_->the_locking_inset))
#endif
bv_->text->SetCursor(cursor.par,cursor.pos,true);
x = x - start_x;
// The origin of an inset is on the baseline
@ -1001,8 +1003,10 @@ Inset * BufferView::Pimpl::checkInsetHit(int & x, int & y, unsigned int /* butto
if (x > start_x && x < end_x
&& y_tmp > cursor.y - tmpinset->ascent(bv_->painter(), font)
&& y_tmp < cursor.y + tmpinset->descent(bv_->painter(), font)) {
#if 0
if (move_cursor && (tmpinset != bv_->the_locking_inset))
bv_->text->SetCursor(cursor.par,cursor.pos,true);
#endif
bv_->text->SetCursor(cursor.par,cursor.pos-1,true);
x = x - start_x;
// The origin of an inset is on the baseline
y = y_tmp - (bv_->text->cursor.y);

View File

@ -30,6 +30,14 @@ using std::pair;
// in and some method of choosing beween them (based on the first few chars
// in the selection probably.) This would be a nice feature and quite
// easy to implement. (Lgb)
//
// Sure but I just cleaned up this code for now with the same functionality
// as before. I also want to add a XClipboard function so that we can copy
// text from LyX to some other X-application in the form of ASCII or in the
// form of LaTeX (or Docbook depending on the document-class!). Think how nice
// it could be to select a math-inset do a "Copy to X-Clipboard as LaTeX" and
// then do a middle mouse button click in the application you want and have
// the whole formula there in LaTeX-Code. (Jug)
static LyXParagraph * buf = 0;
static LyXTextClassList::size_type textclass = 0;
@ -41,16 +49,17 @@ static LyXTextClassList::size_type textclass = 0;
static
void DeleteBuffer()
{
if (!buf) return;
if (!buf)
return;
LyXParagraph * tmppar;
LyXParagraph * tmppar;
while (buf) {
tmppar = buf;
buf = buf->next;
delete tmppar;
}
buf = 0;
while (buf) {
tmppar = buf;
buf = buf->next;
delete tmppar;
}
buf = 0;
}

View File

@ -142,11 +142,12 @@ void UpdatableInset::Edit(BufferView * bv, int, int, unsigned int)
void UpdatableInset::draw(Painter &, LyXFont const &,
int baseline, float & x) const
int /* baseline */, float & x) const
{
if (scx) x += float(scx);
top_x = int(x);
top_baseline = baseline;
// ATTENTION: this is not good doing here
// top_x = int(x);
// top_baseline = baseline;
}

View File

@ -208,10 +208,15 @@ void InsetText::draw(Painter & pain, LyXFont const & f,
xpos = x;
UpdatableInset::draw(pain, f, baseline, x);
top_x = int(x);
top_baseline = baseline;
computeTextRows(pain, x);
computeBaselines(baseline);
if (init_inset || (baseline != top_baseline) || (top_x != int(x))) {
top_baseline = baseline;
if (init_inset || (top_x != int(x))) {
top_x = int(x);
computeTextRows(pain, x);
init_inset = false;
}
computeBaselines(baseline);
}
if (the_locking_inset && (cursor.pos == inset_pos)) {
resetPos(pain);
inset_x = cursor.x - top_x + drawTextXOffset;
@ -1287,7 +1292,7 @@ void InsetText::computeTextRows(Painter & pain, float x) const
}
rows.back().asc = wordAscent;
rows.back().desc = wordDescent;
row.pos = ++p; // +1;
row.pos = ++p;
rows.push_back(row);
SingleHeight(pain, par, p, oasc, odesc);
insetWidth = max(insetWidth, owidth);
@ -1297,39 +1302,42 @@ void InsetText::computeTextRows(Painter & pain, float x) const
nwp = p;
continue;
}
Inset const * inset = 0;
Inset * inset = 0;
if (((p + 1) < par->Last()) &&
(par->GetChar(p + 1)==LyXParagraph::META_INSET))
inset = par->GetInset(p + 1);
if (inset && inset->display()) {
if (!is_first_word_in_row && (width >= maxWidth)) {
// we have to split also the row above
rows.back().asc = oasc;
rows.back().desc = odesc;
row.pos = nwp;
rows.push_back(row);
oasc = wordAscent;
odesc = wordDescent;
insetWidth = max(insetWidth, owidth);
width = lastWordWidth;
lastWordWidth = 0;
} else {
if (inset) {
inset->setOwner(this);
if (inset->display()) {
if (!is_first_word_in_row && (width >= maxWidth)) {
// we have to split also the row above
rows.back().asc = oasc;
rows.back().desc = odesc;
row.pos = nwp;
rows.push_back(row);
oasc = wordAscent;
odesc = wordDescent;
insetWidth = max(insetWidth, owidth);
width = lastWordWidth;
lastWordWidth = 0;
} else {
oasc = max(oasc, wordAscent);
odesc = max(odesc, wordDescent);
}
rows.back().asc = oasc;
rows.back().desc = odesc;
row.pos = ++p;
rows.push_back(row);
SingleHeight(pain, par, p, asc, desc);
rows.back().asc = asc;
rows.back().desc = desc;
row.pos = nwp = p + 1;
rows.push_back(row);
oasc = odesc = width = lastWordWidth = 0;
is_first_word_in_row = true;
wordAscent = wordDescent = 0;
continue;
}
rows.back().asc = oasc;
rows.back().desc = odesc;
row.pos = ++p;
rows.push_back(row);
SingleHeight(pain, par, p, asc, desc);
rows.back().asc = asc;
rows.back().desc = desc;
row.pos = nwp = p + 1;
rows.push_back(row);
oasc = odesc = width = lastWordWidth = 0;
is_first_word_in_row = true;
wordAscent = wordDescent = 0;
continue;
} else if (par->IsSeparator(p)) {
if (width >= maxWidth) {
if (is_first_word_in_row) {
@ -1402,7 +1410,6 @@ void InsetText::computeBaselines(int baseline) const
void InsetText::UpdateLocal(BufferView *bv, bool flag)
{
#if 1
if (flag) {
computeTextRows(bv->painter(), xpos);
computeBaselines(top_baseline);
@ -1410,10 +1417,6 @@ void InsetText::UpdateLocal(BufferView *bv, bool flag)
bv->updateInset(this, flag);
if (flag)
resetPos(bv->painter());
#else
init_inset = flag;
bv->updateInset(this, flag);
#endif
}
bool InsetText::cutSelection()
@ -1424,9 +1427,16 @@ bool InsetText::cutSelection()
CutAndPaste cap;
LyXParagraph *endpar = par;
int start, end;
if (selection_start > selection_end) {
start = selection_end;
end = selection_start;
} else {
start = selection_start;
end = selection_end;
}
return cap.cutSelection(par, &endpar, selection_start, selection_end,
buffer->params.textclass);
return cap.cutSelection(par, &endpar, start, end,buffer->params.textclass);
}
bool InsetText::copySelection()
@ -1436,8 +1446,15 @@ bool InsetText::copySelection()
CutAndPaste cap;
return cap.copySelection(par, par, selection_start, selection_end,
buffer->params.textclass);
int start, end;
if (selection_start > selection_end) {
start = selection_end;
end = selection_start;
} else {
start = selection_start;
end = selection_end;
}
return cap.copySelection(par, par, start, end, buffer->params.textclass);
}
bool InsetText::pasteSelection()