Various fixes look at ChangeLog

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@595 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Vigna 2000-03-09 16:04:28 +00:00
parent 132fe5e132
commit 28ed6c5e80
6 changed files with 215 additions and 137 deletions

View File

@ -1,3 +1,23 @@
2000-03-09 Juergen Vigna <jug@sad.it>
* src/insets/insettext.C (setPos): fixed various cursor positioning
problems (via mouse and cursor-keys)
(LocalDispatch): added posibility to add a Ctrl-Enter inside a text
inset (still a small display problem but it works ;)
* src/insets/insetcollapsable.C (draw): added button_top_y and
button_bottom_y to have correct values for clicking on the inset.
* src/support/lyxalgo.h: commented out 'using std::less'
2000-03-08 Juergen Vigna <jug@sad.it>
* src/insets/insetcollapsable.C (InsetButtonRelease): Now a
Button-Release event closes as it is alos the Release-Event
which opens it.
* src/lyxfunc.C (Dispatch): forgot a break in the LFUN_INSET_ERT
2000-03-07 Kayvan A. Sylvan <kayvan@camel.internal.sylvan.com> 2000-03-07 Kayvan A. Sylvan <kayvan@camel.internal.sylvan.com>
* lib/layouts/literate-scrap.inc: Fixed initial comment. Now we * lib/layouts/literate-scrap.inc: Fixed initial comment. Now we
@ -123,10 +143,6 @@
(search_kw): use lower_bound instead of manually implemented (search_kw): use lower_bound instead of manually implemented
binary search. binary search.
2000-03-08 Juergen Vigna <jug@sad.it>
* src/lyxfunc.C (Dispatch): forgot a break in the LFUN_INSET_ERT
2000-03-08 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr> 2000-03-08 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* src/insets/insetcollapsable.h: fix Clone() declaration. * src/insets/insetcollapsable.h: fix Clone() declaration.

View File

@ -995,10 +995,10 @@ Inset * BufferView::checkInsetHit(int & x, int & y)
} }
} }
if (cursor.pos - 1 >= 0 if ((cursor.pos - 1 >= 0) &&
&& cursor.par->GetChar(cursor.pos - 1) == LyXParagraph::META_INSET (cursor.par->GetChar(cursor.pos-1) == LyXParagraph::META_INSET) &&
&& cursor.par->GetInset(cursor.pos - 1) (cursor.par->GetInset(cursor.pos - 1)) &&
&& cursor.par->GetInset(cursor.pos - 1)->Editable()) { (cursor.par->GetInset(cursor.pos - 1)->Editable())) {
text->CursorLeft(); text->CursorLeft();
Inset * tmpinset = cursor.par->GetInset(cursor.pos); Inset * tmpinset = cursor.par->GetInset(cursor.pos);
LyXFont font = text->GetFont(cursor.par, cursor.pos); LyXFont font = text->GetFont(cursor.par, cursor.pos);

View File

@ -27,7 +27,8 @@ InsetCollapsable::InsetCollapsable(Buffer * bf): InsetText(bf)
autocolapse = true; autocolapse = true;
autoBreakRows = true; autoBreakRows = true;
framecolor = LColor::footnoteframe; framecolor = LColor::footnoteframe;
widthOffset = 7; widthOffset = 10;
button_x = button_top_y = button_bottom_y = top_x = -1;
} }
@ -87,7 +88,7 @@ int InsetCollapsable::width(Painter & pain, LyXFont const & font) const
if (collapsed) if (collapsed)
return width_collapsed(pain, font); return width_collapsed(pain, font);
return getMaxWidth(pain); return getMaxWidth(pain) - widthOffset + 2;
} }
@ -111,7 +112,9 @@ void InsetCollapsable::draw(Painter & pain, LyXFont const & f,
top_x = int(x); top_x = int(x);
top_baseline = baseline; top_baseline = baseline;
draw_collapsed(pain, f, baseline, x); draw_collapsed(pain, f, baseline, x);
button_x = int(x - top_x); button_x = int(x);
button_top_y = -ascent_collapsed(pain, f);
button_bottom_y = descent_collapsed(pain, f);
maxWidth = getMaxWidth(pain) - button_x; maxWidth = getMaxWidth(pain) - button_x;
x += 2; x += 2;
@ -171,12 +174,7 @@ void InsetCollapsable::UpdateLocal(BufferView *bv, bool flag)
void InsetCollapsable::InsetButtonPress(BufferView *bv,int x,int y,int button) void InsetCollapsable::InsetButtonPress(BufferView *bv,int x,int y,int button)
{ {
if ((x < button_x) && if ((x >= button_x) && (y >= button_top_y)) {
(y < (labelfont.maxDescent()+labelfont.maxAscent()))) {
collapsed = true;
UpdateLocal(bv, false);
bv->unlockInset(this);
} else if (x >= button_x) {
InsetText::InsetButtonPress(bv, x-top_x, y, button); InsetText::InsetButtonPress(bv, x-top_x, y, button);
} }
} }
@ -184,13 +182,19 @@ void InsetCollapsable::InsetButtonPress(BufferView *bv,int x,int y,int button)
void InsetCollapsable::InsetButtonRelease(BufferView *bv, int x, int y, int button) void InsetCollapsable::InsetButtonRelease(BufferView *bv, int x, int y, int button)
{ {
if (x >= button_x) if ((x < button_x) && (y >= button_top_y) && (y <= button_bottom_y)) {
collapsed = true;
UpdateLocal(bv, false);
bv->unlockInset(this);
} else if ((x >= button_x) && (y >= button_top_y)) {
InsetText::InsetButtonRelease(bv, x-top_x, y, button); InsetText::InsetButtonRelease(bv, x-top_x, y, button);
}
} }
void InsetCollapsable::InsetMotionNotify(BufferView *bv, int x, int y, int button) void InsetCollapsable::InsetMotionNotify(BufferView *bv, int x, int y, int button)
{ {
if (x >= button_x) if ((x >= button_x) && (y >= button_top_y)) {
InsetText::InsetMotionNotify(bv, x-top_x, y, button); InsetText::InsetMotionNotify(bv, x-top_x, y, button);
}
} }

View File

@ -95,7 +95,7 @@ private:
/// ///
mutable int mutable int
top_baseline, top_x, top_baseline, top_x,
button_x; button_x, button_top_y, button_bottom_y;
}; };
#endif #endif

View File

@ -271,6 +271,35 @@ void InsetText::drawRowText(Painter & pain, int startpos, int endpos,
LyXFont font = GetFont(par,p); LyXFont font = GetFont(par,p);
if (IsFloatChar(ch)) { if (IsFloatChar(ch)) {
// skip for now // skip for now
} else if (par->IsNewline(p)) {
// Draw end-of-line marker
int wid = font.width('n');
int asc = font.maxAscent();
int y = baseline;
int xp[3], yp[3];
xp[0] = int(x + wid * 0.375);
yp[0] = int(y - 0.875 * asc * 0.75);
xp[1] = int(x);
yp[1] = int(y - 0.500 * asc * 0.75);
xp[2] = int(x + wid * 0.375);
yp[2] = int(y - 0.125 * asc * 0.75);
pain.lines(xp, yp, 3, LColor::eolmarker);
xp[0] = int(x);
yp[0] = int(y - 0.500 * asc * 0.75);
xp[1] = int(x + wid);
yp[1] = int(y - 0.500 * asc * 0.75);
xp[2] = int(x + wid);
yp[2] = int(y - asc * 0.75);
pain.lines(xp, yp, 3, LColor::eolmarker);
x += wid;
} else if (ch == LyXParagraph::META_INSET) { } else if (ch == LyXParagraph::META_INSET) {
Inset * tmpinset = par->GetInset(p); Inset * tmpinset = par->GetInset(p);
if (tmpinset) if (tmpinset)
@ -457,36 +486,36 @@ InsetText::LocalDispatch(BufferView * bv,
} }
HideInsetCursor(bv); HideInsetCursor(bv);
switch (action) { switch (action) {
// Normal chars // Normal chars
case -1: case -1:
par->InsertChar(actpos,arg[0]); par->InsertChar(actpos,arg[0]);
par->SetFont(actpos,real_current_font); par->SetFont(actpos,real_current_font);
UpdateLocal(bv, true); UpdateLocal(bv, true);
++actpos; ++actpos;
selection_start = selection_end = actpos; selection_start = selection_end = actpos;
resetPos(bv); resetPos(bv);
break; break;
// --- Cursor Movements --------------------------------------------- // --- Cursor Movements ---------------------------------------------
case LFUN_RIGHTSEL: case LFUN_RIGHTSEL:
moveRight(bv, false); moveRight(bv, false);
selection_end = actpos; selection_end = actpos;
UpdateLocal(bv, false); UpdateLocal(bv, false);
break; break;
case LFUN_RIGHT: case LFUN_RIGHT:
result= DISPATCH_RESULT(moveRight(bv)); result= DISPATCH_RESULT(moveRight(bv));
if (hasSelection()) { if (hasSelection()) {
selection_start = selection_end = actpos; selection_start = selection_end = actpos;
UpdateLocal(bv, false); UpdateLocal(bv, false);
} else { } else {
selection_start = selection_end = actpos; selection_start = selection_end = actpos;
} }
break; break;
case LFUN_LEFTSEL: case LFUN_LEFTSEL:
moveLeft(bv, false); moveLeft(bv, false);
selection_end = actpos; selection_end = actpos;
UpdateLocal(bv, false); UpdateLocal(bv, false);
break; break;
case LFUN_LEFT: case LFUN_LEFT:
result= DISPATCH_RESULT(moveLeft(bv)); result= DISPATCH_RESULT(moveLeft(bv));
if (hasSelection()) { if (hasSelection()) {
selection_start = selection_end = actpos; selection_start = selection_end = actpos;
@ -495,85 +524,98 @@ InsetText::LocalDispatch(BufferView * bv,
selection_start = selection_end = actpos; selection_start = selection_end = actpos;
} }
break; break;
case LFUN_DOWNSEL: case LFUN_DOWNSEL:
moveDown(bv, false); moveDown(bv, false);
selection_end = actpos; selection_end = actpos;
UpdateLocal(bv, false); UpdateLocal(bv, false);
break; break;
case LFUN_DOWN: case LFUN_DOWN:
result= DISPATCH_RESULT(moveDown(bv)); result= DISPATCH_RESULT(moveDown(bv));
if (hasSelection()) { if (hasSelection()) {
selection_start = selection_end = actpos; selection_start = selection_end = actpos;
UpdateLocal(bv, false); UpdateLocal(bv, false);
} else { } else {
selection_start = selection_end = actpos; selection_start = selection_end = actpos;
} }
break; break;
case LFUN_UPSEL: case LFUN_UPSEL:
moveUp(bv, false); moveUp(bv, false);
selection_end = actpos; selection_end = actpos;
UpdateLocal(bv, false); UpdateLocal(bv, false);
break; break;
case LFUN_UP: case LFUN_UP:
result= DISPATCH_RESULT(moveUp(bv)); result= DISPATCH_RESULT(moveUp(bv));
if (hasSelection()) { if (hasSelection()) {
selection_start = selection_end = actpos; selection_start = selection_end = actpos;
UpdateLocal(bv, false); UpdateLocal(bv, false);
} else { } else {
selection_start = selection_end = actpos; selection_start = selection_end = actpos;
} }
break; break;
case LFUN_BACKSPACE: case LFUN_BACKSPACE:
if (!actpos || par->IsNewline(actpos-1)) { if (!actpos || par->IsNewline(actpos-1)) {
if (hasSelection()) { if (hasSelection()) {
selection_start = selection_end = actpos; selection_start = selection_end = actpos;
UpdateLocal(bv, false); UpdateLocal(bv, false);
} }
break; break;
} }
moveLeft(bv); moveLeft(bv);
case LFUN_DELETE: case LFUN_DELETE:
if (Delete()) { // we need update if (Delete()) { // we need update
selection_start = selection_end = actpos; selection_start = selection_end = actpos;
UpdateLocal(bv, true); UpdateLocal(bv, true);
} else if (hasSelection()) { } else if (hasSelection()) {
selection_start = selection_end = actpos; selection_start = selection_end = actpos;
UpdateLocal(bv, false); UpdateLocal(bv, false);
} }
break; break;
case LFUN_HOME: case LFUN_HOME:
for(; actpos > rows[actrow].pos; --actpos) for(; actpos > rows[actrow].pos; --actpos)
cx -= SingleWidth(bv->getPainter(), par, actpos); cx -= SingleWidth(bv->getPainter(), par, actpos);
cx -= SingleWidth(bv->getPainter(), par, actpos); cx -= SingleWidth(bv->getPainter(), par, actpos);
if (hasSelection()) { if (hasSelection()) {
selection_start = selection_end = actpos; selection_start = selection_end = actpos;
UpdateLocal(bv, false); UpdateLocal(bv, false);
} else { } else {
selection_start = selection_end = actpos; selection_start = selection_end = actpos;
} }
break; break;
case LFUN_END: case LFUN_END:
for(; actpos < rows[actrow + 1].pos; ++actpos) {
cx += SingleWidth(bv->getPainter(), par, actpos); int checkpos = (int)rows[actrow + 1].pos;
if (hasSelection()) { if ((actrow + 2) < (int)rows.size())
selection_start = selection_end = actpos; --checkpos;
UpdateLocal(bv, false); for(; actpos < checkpos; ++actpos)
} else { cx += SingleWidth(bv->getPainter(), par, actpos);
selection_start = selection_end = actpos; if (hasSelection()) {
} selection_start = selection_end = actpos;
break; UpdateLocal(bv, false);
case LFUN_MATH_MODE: // Open or create a math inset } else {
InsertInset(bv, new InsetFormula); selection_start = selection_end = actpos;
if (hasSelection()) { }
selection_start = selection_end = actpos; }
UpdateLocal(bv, false); break;
} else { case LFUN_MATH_MODE: // Open or create a math inset
selection_start = selection_end = actpos; InsertInset(bv, new InsetFormula);
} if (hasSelection()) {
return DISPATCHED; selection_start = selection_end = actpos;
default: UpdateLocal(bv, false);
result = UNDISPATCHED; } else {
break; selection_start = selection_end = actpos;
}
return DISPATCHED;
case LFUN_BREAKLINE:
par->InsertChar(actpos,LyXParagraph::META_NEWLINE);
par->SetFont(actpos,real_current_font);
UpdateLocal(bv, true);
++actpos;
selection_start = selection_end = actpos;
resetPos(bv);
break;
default:
result = UNDISPATCHED;
break;
} }
if (result != FINISHED) { if (result != FINISHED) {
if (!the_locking_inset) if (!the_locking_inset)
@ -808,8 +850,8 @@ void InsetText::HideInsetCursor(BufferView * bv)
void InsetText::setPos(BufferView * bv, int x, int y, bool activate_inset) void InsetText::setPos(BufferView * bv, int x, int y, bool activate_inset)
{ {
int ox = x; int ox = x;
int oy = y; int oy = y;
// search right X-pos x==0 -> top_x // search right X-pos x==0 -> top_x
actpos = actrow = 0; actpos = actrow = 0;
@ -826,10 +868,16 @@ void InsetText::setPos(BufferView * bv, int x, int y, bool activate_inset)
x += top_x; x += top_x;
int swh; int swh;
int sw = swh = SingleWidth(bv->getPainter(), par,actpos); int sw;
int checkpos;
sw = swh = SingleWidth(bv->getPainter(), par,actpos);
if (par->GetChar(actpos)!=LyXParagraph::META_INSET) if (par->GetChar(actpos)!=LyXParagraph::META_INSET)
swh /= 2; swh /= 2;
while ((actpos < (rows[actrow + 1].pos - 1)) && ((cx + swh) < x)) { checkpos = rows[actrow + 1].pos;
if ((actrow+2) < (int)rows.size())
--checkpos;
while ((actpos < checkpos) && ((cx + swh) < x)) {
cx += sw; cx += sw;
++actpos; ++actpos;
sw = swh = SingleWidth(bv->getPainter(), par,actpos); sw = swh = SingleWidth(bv->getPainter(), par,actpos);
@ -914,7 +962,8 @@ void InsetText::resetPos(BufferView * bv)
cy = top_baseline; cy = top_baseline;
actrow = 0; actrow = 0;
for(int i = 0; rows[i].pos <= actpos; ++i) { for(unsigned int i = 0; (i < (rows.size()-1)) && (rows[i].pos <= actpos);
++i) {
cy = rows[i].baseline; cy = rows[i].baseline;
actrow = i; actrow = i;
} }
@ -1083,7 +1132,7 @@ void InsetText::computeTextRows(Painter & pain, float x) const
int cw, lastWordWidth = 0; int cw, lastWordWidth = 0;
maxWidth = UpdatableInset::getMaxWidth(pain) - widthOffset; maxWidth = getMaxWidth(pain) - widthOffset;
for(p = 0; p < par->Last(); ++p) { for(p = 0; p < par->Last(); ++p) {
cw = SingleWidth(pain, par, p); cw = SingleWidth(pain, par, p);
width += cw; width += cw;
@ -1091,6 +1140,17 @@ void InsetText::computeTextRows(Painter & pain, float x) const
SingleHeight(pain, par, p, asc, desc); SingleHeight(pain, par, p, asc, desc);
wordAscent = max(wordAscent, asc); wordAscent = max(wordAscent, asc);
wordDescent = max(wordDescent, desc); wordDescent = max(wordDescent, desc);
if (par->IsNewline(p)) {
rows.back().asc = wordAscent;
rows.back().desc = wordDescent;
row.pos = p+1;
rows.push_back(row);
SingleHeight(pain, par, p, oasc, odesc);
width = lastWordWidth = 0;
is_first_word_in_row = true;
wordAscent = wordDescent = 0;
continue;
}
Inset const * inset = 0; Inset const * inset = 0;
if (((p + 1) < par->Last()) && if (((p + 1) < par->Last()) &&
(par->GetChar(p + 1)==LyXParagraph::META_INSET)) (par->GetChar(p + 1)==LyXParagraph::META_INSET))
@ -1123,7 +1183,6 @@ void InsetText::computeTextRows(Painter & pain, float x) const
oasc = odesc = width = lastWordWidth = 0; oasc = odesc = width = lastWordWidth = 0;
is_first_word_in_row = true; is_first_word_in_row = true;
wordAscent = wordDescent = 0; wordAscent = wordDescent = 0;
// x = 0.0;
continue; continue;
} else if (par->IsSeparator(p)) { } else if (par->IsSeparator(p)) {
if (width >= maxWidth - x) { if (width >= maxWidth - x) {
@ -1145,7 +1204,6 @@ void InsetText::computeTextRows(Painter & pain, float x) const
} }
wordAscent = wordDescent = lastWordWidth = 0; wordAscent = wordDescent = lastWordWidth = 0;
nwp = p + 1; nwp = p + 1;
// x = 0.0;
continue; continue;
} }
owidth = width; owidth = width;

View File

@ -5,7 +5,7 @@
#include <algorithm> #include <algorithm>
using std::less; // using std::less;
// Both these functions should ideally be placed into namespace lyx. // Both these functions should ideally be placed into namespace lyx.
// Also the using std::less should not be used. // Also the using std::less should not be used.