From 28ed6c5e800be8a1593eb808f3027d17c6cfcd33 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Vigna?= Date: Thu, 9 Mar 2000 16:04:28 +0000 Subject: [PATCH] Various fixes look at ChangeLog git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@595 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 24 ++- src/BufferView.C | 8 +- src/insets/insetcollapsable.C | 26 +-- src/insets/insetcollapsable.h | 2 +- src/insets/insettext.C | 290 ++++++++++++++++++++-------------- src/support/lyxalgo.h | 2 +- 6 files changed, 215 insertions(+), 137 deletions(-) diff --git a/ChangeLog b/ChangeLog index e94c6eaad0..62d092d026 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2000-03-09 Juergen Vigna + + * 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 + + * 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 * lib/layouts/literate-scrap.inc: Fixed initial comment. Now we @@ -123,10 +143,6 @@ (search_kw): use lower_bound instead of manually implemented binary search. -2000-03-08 Juergen Vigna - - * src/lyxfunc.C (Dispatch): forgot a break in the LFUN_INSET_ERT - 2000-03-08 Jean-Marc Lasgouttes * src/insets/insetcollapsable.h: fix Clone() declaration. diff --git a/src/BufferView.C b/src/BufferView.C index 1fd4c3cd4a..f65392994c 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -995,10 +995,10 @@ Inset * BufferView::checkInsetHit(int & x, int & y) } } - if (cursor.pos - 1 >= 0 - && cursor.par->GetChar(cursor.pos - 1) == LyXParagraph::META_INSET - && cursor.par->GetInset(cursor.pos - 1) - && cursor.par->GetInset(cursor.pos - 1)->Editable()) { + if ((cursor.pos - 1 >= 0) && + (cursor.par->GetChar(cursor.pos-1) == LyXParagraph::META_INSET) && + (cursor.par->GetInset(cursor.pos - 1)) && + (cursor.par->GetInset(cursor.pos - 1)->Editable())) { text->CursorLeft(); Inset * tmpinset = cursor.par->GetInset(cursor.pos); LyXFont font = text->GetFont(cursor.par, cursor.pos); diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 1a218c4ba2..f64a6fc636 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -27,7 +27,8 @@ InsetCollapsable::InsetCollapsable(Buffer * bf): InsetText(bf) autocolapse = true; autoBreakRows = true; 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) 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_baseline = baseline; 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; x += 2; @@ -171,12 +174,7 @@ void InsetCollapsable::UpdateLocal(BufferView *bv, bool flag) void InsetCollapsable::InsetButtonPress(BufferView *bv,int x,int y,int button) { - if ((x < button_x) && - (y < (labelfont.maxDescent()+labelfont.maxAscent()))) { - collapsed = true; - UpdateLocal(bv, false); - bv->unlockInset(this); - } else if (x >= button_x) { + if ((x >= button_x) && (y >= button_top_y)) { 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) { - 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); + } } 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); + } } diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index ec92ccb988..da93bc8266 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -95,7 +95,7 @@ private: /// mutable int top_baseline, top_x, - button_x; + button_x, button_top_y, button_bottom_y; }; #endif diff --git a/src/insets/insettext.C b/src/insets/insettext.C index f7703842b4..1176130eff 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -271,6 +271,35 @@ void InsetText::drawRowText(Painter & pain, int startpos, int endpos, LyXFont font = GetFont(par,p); if (IsFloatChar(ch)) { // 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) { Inset * tmpinset = par->GetInset(p); if (tmpinset) @@ -457,36 +486,36 @@ InsetText::LocalDispatch(BufferView * bv, } HideInsetCursor(bv); switch (action) { - // Normal chars - case -1: - par->InsertChar(actpos,arg[0]); - par->SetFont(actpos,real_current_font); - UpdateLocal(bv, true); - ++actpos; - selection_start = selection_end = actpos; - resetPos(bv); - break; + // Normal chars + case -1: + par->InsertChar(actpos,arg[0]); + par->SetFont(actpos,real_current_font); + UpdateLocal(bv, true); + ++actpos; + selection_start = selection_end = actpos; + resetPos(bv); + break; // --- Cursor Movements --------------------------------------------- - case LFUN_RIGHTSEL: - moveRight(bv, false); - selection_end = actpos; - UpdateLocal(bv, false); - break; - case LFUN_RIGHT: - result= DISPATCH_RESULT(moveRight(bv)); - if (hasSelection()) { - selection_start = selection_end = actpos; - UpdateLocal(bv, false); - } else { - selection_start = selection_end = actpos; - } - break; - case LFUN_LEFTSEL: - moveLeft(bv, false); - selection_end = actpos; - UpdateLocal(bv, false); - break; - case LFUN_LEFT: + case LFUN_RIGHTSEL: + moveRight(bv, false); + selection_end = actpos; + UpdateLocal(bv, false); + break; + case LFUN_RIGHT: + result= DISPATCH_RESULT(moveRight(bv)); + if (hasSelection()) { + selection_start = selection_end = actpos; + UpdateLocal(bv, false); + } else { + selection_start = selection_end = actpos; + } + break; + case LFUN_LEFTSEL: + moveLeft(bv, false); + selection_end = actpos; + UpdateLocal(bv, false); + break; + case LFUN_LEFT: result= DISPATCH_RESULT(moveLeft(bv)); if (hasSelection()) { selection_start = selection_end = actpos; @@ -495,85 +524,98 @@ InsetText::LocalDispatch(BufferView * bv, selection_start = selection_end = actpos; } break; - case LFUN_DOWNSEL: - moveDown(bv, false); - selection_end = actpos; - UpdateLocal(bv, false); - break; - case LFUN_DOWN: - result= DISPATCH_RESULT(moveDown(bv)); - if (hasSelection()) { - selection_start = selection_end = actpos; - UpdateLocal(bv, false); - } else { - selection_start = selection_end = actpos; - } - break; - case LFUN_UPSEL: - moveUp(bv, false); - selection_end = actpos; - UpdateLocal(bv, false); - break; - case LFUN_UP: - result= DISPATCH_RESULT(moveUp(bv)); - if (hasSelection()) { - selection_start = selection_end = actpos; - UpdateLocal(bv, false); - } else { - selection_start = selection_end = actpos; - } - break; - case LFUN_BACKSPACE: - if (!actpos || par->IsNewline(actpos-1)) { - if (hasSelection()) { - selection_start = selection_end = actpos; - UpdateLocal(bv, false); - } - break; - } - moveLeft(bv); - case LFUN_DELETE: - if (Delete()) { // we need update - selection_start = selection_end = actpos; - UpdateLocal(bv, true); - } else if (hasSelection()) { - selection_start = selection_end = actpos; - UpdateLocal(bv, false); - } - break; - case LFUN_HOME: - for(; actpos > rows[actrow].pos; --actpos) - cx -= SingleWidth(bv->getPainter(), par, actpos); - cx -= SingleWidth(bv->getPainter(), par, actpos); - if (hasSelection()) { - selection_start = selection_end = actpos; - UpdateLocal(bv, false); - } else { - selection_start = selection_end = actpos; - } - break; - case LFUN_END: - for(; actpos < rows[actrow + 1].pos; ++actpos) - cx += SingleWidth(bv->getPainter(), par, actpos); - if (hasSelection()) { - selection_start = selection_end = actpos; - UpdateLocal(bv, false); - } else { - selection_start = selection_end = actpos; - } - break; - case LFUN_MATH_MODE: // Open or create a math inset - InsertInset(bv, new InsetFormula); - if (hasSelection()) { - selection_start = selection_end = actpos; - UpdateLocal(bv, false); - } else { - selection_start = selection_end = actpos; - } - return DISPATCHED; - default: - result = UNDISPATCHED; - break; + case LFUN_DOWNSEL: + moveDown(bv, false); + selection_end = actpos; + UpdateLocal(bv, false); + break; + case LFUN_DOWN: + result= DISPATCH_RESULT(moveDown(bv)); + if (hasSelection()) { + selection_start = selection_end = actpos; + UpdateLocal(bv, false); + } else { + selection_start = selection_end = actpos; + } + break; + case LFUN_UPSEL: + moveUp(bv, false); + selection_end = actpos; + UpdateLocal(bv, false); + break; + case LFUN_UP: + result= DISPATCH_RESULT(moveUp(bv)); + if (hasSelection()) { + selection_start = selection_end = actpos; + UpdateLocal(bv, false); + } else { + selection_start = selection_end = actpos; + } + break; + case LFUN_BACKSPACE: + if (!actpos || par->IsNewline(actpos-1)) { + if (hasSelection()) { + selection_start = selection_end = actpos; + UpdateLocal(bv, false); + } + break; + } + moveLeft(bv); + case LFUN_DELETE: + if (Delete()) { // we need update + selection_start = selection_end = actpos; + UpdateLocal(bv, true); + } else if (hasSelection()) { + selection_start = selection_end = actpos; + UpdateLocal(bv, false); + } + break; + case LFUN_HOME: + for(; actpos > rows[actrow].pos; --actpos) + cx -= SingleWidth(bv->getPainter(), par, actpos); + cx -= SingleWidth(bv->getPainter(), par, actpos); + if (hasSelection()) { + selection_start = selection_end = actpos; + UpdateLocal(bv, false); + } else { + selection_start = selection_end = actpos; + } + break; + case LFUN_END: + { + int checkpos = (int)rows[actrow + 1].pos; + if ((actrow + 2) < (int)rows.size()) + --checkpos; + for(; actpos < checkpos; ++actpos) + cx += SingleWidth(bv->getPainter(), par, actpos); + if (hasSelection()) { + selection_start = selection_end = actpos; + UpdateLocal(bv, false); + } else { + selection_start = selection_end = actpos; + } + } + break; + case LFUN_MATH_MODE: // Open or create a math inset + InsertInset(bv, new InsetFormula); + if (hasSelection()) { + selection_start = selection_end = actpos; + UpdateLocal(bv, false); + } else { + 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 (!the_locking_inset) @@ -808,8 +850,8 @@ void InsetText::HideInsetCursor(BufferView * bv) void InsetText::setPos(BufferView * bv, int x, int y, bool activate_inset) { - int ox = x; - int oy = y; + int ox = x; + int oy = y; // search right X-pos x==0 -> top_x actpos = actrow = 0; @@ -826,10 +868,16 @@ void InsetText::setPos(BufferView * bv, int x, int y, bool activate_inset) x += top_x; 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) 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; ++actpos; sw = swh = SingleWidth(bv->getPainter(), par,actpos); @@ -914,7 +962,8 @@ void InsetText::resetPos(BufferView * bv) cy = top_baseline; 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; actrow = i; } @@ -1083,7 +1132,7 @@ void InsetText::computeTextRows(Painter & pain, float x) const int cw, lastWordWidth = 0; - maxWidth = UpdatableInset::getMaxWidth(pain) - widthOffset; + maxWidth = getMaxWidth(pain) - widthOffset; for(p = 0; p < par->Last(); ++p) { cw = SingleWidth(pain, par, p); width += cw; @@ -1091,6 +1140,17 @@ void InsetText::computeTextRows(Painter & pain, float x) const SingleHeight(pain, par, p, asc, desc); wordAscent = max(wordAscent, asc); 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; if (((p + 1) < par->Last()) && (par->GetChar(p + 1)==LyXParagraph::META_INSET)) @@ -1123,7 +1183,6 @@ void InsetText::computeTextRows(Painter & pain, float x) const oasc = odesc = width = lastWordWidth = 0; is_first_word_in_row = true; wordAscent = wordDescent = 0; -// x = 0.0; continue; } else if (par->IsSeparator(p)) { if (width >= maxWidth - x) { @@ -1145,7 +1204,6 @@ void InsetText::computeTextRows(Painter & pain, float x) const } wordAscent = wordDescent = lastWordWidth = 0; nwp = p + 1; -// x = 0.0; continue; } owidth = width; diff --git a/src/support/lyxalgo.h b/src/support/lyxalgo.h index 27cae60bb5..8e243bd506 100644 --- a/src/support/lyxalgo.h +++ b/src/support/lyxalgo.h @@ -5,7 +5,7 @@ #include -using std::less; +// using std::less; // Both these functions should ideally be placed into namespace lyx. // Also the using std::less should not be used. -- 2.39.2