From bbcd13990a5fb0687043e554d5ca7344fc11cab3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Mon, 15 Dec 2003 15:33:15 +0000 Subject: [PATCH] split functions into logical pieces git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8253 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/insets/insettabular.C | 123 ++++++++++++++++++++------------------ src/insets/insettabular.h | 24 ++++++-- src/insets/insettext.C | 18 +++--- 3 files changed, 91 insertions(+), 74 deletions(-) diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 92b4b0300e..e54fcf8c8b 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -489,11 +489,10 @@ DispatchResult InsetTabular::priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos) { - lyxerr << "# InsetTabular::dispatch: " << cmd << endl; + //lyxerr << "# InsetTabular::dispatch: " << cmd << endl; DispatchResult result(true, true); BufferView * bv = cmd.view(); - lyxerr << "# cursor: " << bv->cursor() << endl; switch (cmd.action) { @@ -522,34 +521,29 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, << "here" << endl; } - lyxerr << "# InsetTabular::dispatch 1: " << cmd << endl; result = tabular.getCellInset(cell).dispatch(cmd, idx, pos); switch (result.val()) { case FINISHED: - lyxerr << "# handle FINISHED_LEFT, act: " << actcell << endl; - if (movePrevCell(bv, false)) + if (movePrevCell(bv)) result = DispatchResult(true, true); else result = DispatchResult(false, FINISHED); break; case FINISHED_RIGHT: - lyxerr << "# handle FINISHED_RIGHT, act: " << actcell << endl; - if (moveNextCell(bv, false)) + if (moveNextCell(bv)) result = DispatchResult(true, true); else result = DispatchResult(false, FINISHED_RIGHT); break; case FINISHED_UP: - lyxerr << "# handle FINISHED_UP, act: " << actcell << endl; - result = moveUp(bv, true); + result = moveUpLock(bv); break; case FINISHED_DOWN: - lyxerr << "# handle FINISHED_DOWN, act: " << actcell << endl; - result = moveDown(bv, true); + result = moveDownLock(bv); break; default: @@ -557,7 +551,6 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, break; } - lyxerr << "# InsetTabular::dispatch 2: " << cmd << endl; return result; } @@ -567,9 +560,9 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, case LFUN_CELL_BACKWARD: case LFUN_CELL_FORWARD: if (cmd.action == LFUN_CELL_FORWARD) - moveNextCell(bv, false); + moveNextCell(bv); else - movePrevCell(bv, false); + movePrevCell(bv); clearSelection(); return result; @@ -594,7 +587,7 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, // if we are starting a selection, only select // the current cell at the beginning if (hasSelection()) { - moveRight(bv, false); + moveRight(bv); end = actcell; } setSelection(start, end); @@ -602,7 +595,7 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, } case LFUN_RIGHT: - result = moveRight(bv, true); + result = moveRightLock(bv); clearSelection(); break; @@ -617,7 +610,7 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, // if we are starting a selection, only select // the current cell at the beginning if (hasSelection()) { - moveLeft(bv, false); + moveLeft(bv); end = actcell; } setSelection(start, end); @@ -625,7 +618,7 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, } case LFUN_LEFT: - result = moveLeft(bv, true); + result = moveLeftLock(bv); clearSelection(); break; @@ -635,7 +628,7 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, // if we are starting a selection, only select // the current cell at the beginning if (hasSelection()) { - moveDown(bv, false); + moveDown(bv); if (ocell == sel_cell_end || tabular.column_of_cell(ocell) > tabular.column_of_cell(actcell)) setSelection(start, tabular.getCellBelow(sel_cell_end)); @@ -648,7 +641,7 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, } case LFUN_DOWN: - result = moveDown(bv, false); + result = moveDown(bv); clearSelection(); break; @@ -658,7 +651,7 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, // if we are starting a selection, only select // the current cell at the beginning if (hasSelection()) { - moveUp(bv, false); + moveUp(bv); if (ocell == sel_cell_end || tabular.column_of_cell(ocell) > tabular.column_of_cell(actcell)) setSelection(start, tabular.getCellAbove(sel_cell_end)); @@ -671,7 +664,7 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, } case LFUN_UP: - result = moveUp(bv, false); + result = moveUp(bv); clearSelection(); break; @@ -1079,62 +1072,93 @@ void InsetTabular::resetPos(BufferView * bv) const } -DispatchResult InsetTabular::moveRight(BufferView * bv, bool lock) +DispatchResult InsetTabular::moveRight(BufferView * bv) { bool moved = isRightToLeft(bv) ? movePrevCell(bv) : moveNextCell(bv); if (!moved) return DispatchResult(false, FINISHED_RIGHT); - if (lock) { - activateCellInset(bv, actcell, false); - return DispatchResult(true, true); - } resetPos(bv); return DispatchResult(true); } -DispatchResult InsetTabular::moveLeft(BufferView * bv, bool lock) +DispatchResult InsetTabular::moveRightLock(BufferView * bv) +{ + bool moved = isRightToLeft(bv) ? movePrevCell(bv) : moveNextCell(bv); + if (!moved) + return DispatchResult(false, FINISHED_RIGHT); + activateCellInset(bv, actcell, false); + return DispatchResult(true, true); +} + + +DispatchResult InsetTabular::moveLeft(BufferView * bv) { bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv); if (!moved) return DispatchResult(false, FINISHED); - // behind the inset - if (lock) { - activateCellInset(bv, actcell, true); - return DispatchResult(true, true); - } resetPos(bv); return DispatchResult(true); } -DispatchResult InsetTabular::moveUp(BufferView * bv, bool lock) +DispatchResult InsetTabular::moveLeftLock(BufferView * bv) +{ + bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv); + if (!moved) + return DispatchResult(false, FINISHED); + activateCellInset(bv, actcell, true); + return DispatchResult(true, true); +} + + +DispatchResult InsetTabular::moveUp(BufferView * bv) { int const ocell = actcell; actcell = tabular.getCellAbove(actcell); if (actcell == ocell) // we moved out of the inset return DispatchResult(false, FINISHED_UP); resetPos(bv); - if (lock) - activateCellInset(bv, actcell, bv->x_target(), 0); return DispatchResult(true, true); } -DispatchResult InsetTabular::moveDown(BufferView * bv, bool lock) +DispatchResult InsetTabular::moveUpLock(BufferView * bv) +{ + int const ocell = actcell; + actcell = tabular.getCellAbove(actcell); + if (actcell == ocell) // we moved out of the inset + return DispatchResult(false, FINISHED_UP); + resetPos(bv); + activateCellInset(bv, actcell, bv->x_target(), 0); + return DispatchResult(true, true); +} + + +DispatchResult InsetTabular::moveDown(BufferView * bv) { int const ocell = actcell; actcell = tabular.getCellBelow(actcell); if (actcell == ocell) // we moved out of the inset return DispatchResult(false, FINISHED_DOWN); resetPos(bv); - if (lock) - activateCellInset(bv, actcell, bv->x_target()); return DispatchResult(true, true); } -bool InsetTabular::moveNextCell(BufferView * bv, bool lock) +DispatchResult InsetTabular::moveDownLock(BufferView * bv) +{ + int const ocell = actcell; + actcell = tabular.getCellBelow(actcell); + if (actcell == ocell) // we moved out of the inset + return DispatchResult(false, FINISHED_DOWN); + resetPos(bv); + activateCellInset(bv, actcell, bv->x_target()); + return DispatchResult(true, true); +} + + +bool InsetTabular::moveNextCell(BufferView * bv) { lyxerr << "InsetTabular::moveNextCell 1 actcell: " << actcell << endl; if (isRightToLeft(bv)) { @@ -1155,21 +1179,14 @@ bool InsetTabular::moveNextCell(BufferView * bv, bool lock) ++actcell; } lyxerr << "InsetTabular::moveNextCell 2 actcell: " << actcell << endl; - if (lock) { - bool rtl = tabular.getCellInset(actcell).paragraphs().begin()-> - isRightToLeftPar(bv->buffer()->params()); - activateCellInset(bv, actcell, !rtl); - } resetPos(bv); return true; } -bool InsetTabular::movePrevCell(BufferView * bv, bool lock) +bool InsetTabular::movePrevCell(BufferView * bv) { - lyxerr << "move prevcell 1" << endl; if (isRightToLeft(bv)) { - lyxerr << "move prevcell a" << endl; if (tabular.isLastCellInRow(actcell)) { int row = tabular.row_of_cell(actcell); if (row == 0) @@ -1182,20 +1199,11 @@ bool InsetTabular::movePrevCell(BufferView * bv, bool lock) ++actcell; } } else { - lyxerr << "move prevcell b" << endl; if (actcell == 0) // first cell return false; --actcell; } - lyxerr << "move prevcell 2" << endl; - if (lock) { - bool rtl = tabular.getCellInset(actcell).paragraphs().begin()-> - isRightToLeftPar(bv->buffer()->params()); - activateCellInset(bv, actcell, !rtl); - } - lyxerr << "move prevcell 3" << endl; resetPos(bv); - lyxerr << "move prevcell 4" << endl; return true; } @@ -1224,6 +1232,7 @@ bool InsetTabular::tabularFeatures(BufferView * bv, string const & what) return true; } + namespace { void checkLongtableSpecial(LyXTabular::ltType & ltt, diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index a84ce256f4..457852a066 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -179,17 +179,29 @@ private: /// void setPos(BufferView *, int x, int y) const; /// - DispatchResult moveRight(BufferView *, bool lock); + DispatchResult moveRight(BufferView *); /// - DispatchResult moveLeft(BufferView *, bool lock); + DispatchResult moveLeft(BufferView *); /// - DispatchResult moveUp(BufferView *, bool lock); + DispatchResult moveUp(BufferView *); /// - DispatchResult moveDown(BufferView *, bool lock); + DispatchResult moveDown(BufferView *); + + /// + DispatchResult moveRightLock(BufferView *); + /// + DispatchResult moveLeftLock(BufferView *); + /// + DispatchResult moveUpLock(BufferView *); /// - bool moveNextCell(BufferView *, bool lock = false); + DispatchResult moveDownLock(BufferView *); + + /// + bool moveNextCell(BufferView *); /// - bool movePrevCell(BufferView *, bool lock = false); + bool movePrevCell(BufferView *); + + /// int getCellXPos(int cell) const; /// diff --git a/src/insets/insettext.C b/src/insets/insettext.C index c5677f9ab6..5c0996c237 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -274,12 +274,11 @@ void InsetText::edit(BufferView * bv, bool left) lyxerr << "InsetText: edit left/right" << endl; old_par = -1; setViewCache(bv); - - if (left) - text_.setCursorIntern(0, 0); - else - text_.setCursor(paragraphs().size() - 1, paragraphs().back().size()); - + int const par = left ? 0 : paragraphs().size() - 1; + int const pos = left ? 0 : paragraphs().back().size(); + text_.setCursor(par, pos); + text_.clearSelection(); + finishUndo(); sanitizeEmptyText(bv); updateLocal(bv); bv->updateParagraphDialog(); @@ -290,13 +289,10 @@ void InsetText::edit(BufferView * bv, int x, int y) { lyxerr << "InsetText::edit xy" << endl; old_par = -1; - - sanitizeEmptyText(bv); - text_.setCursorFromCoordinates(x - text_.xo_, y + bv->top_y() - - text_.yo_); + text_.setCursorFromCoordinates(x - text_.xo_, y + bv->top_y() - text_.yo_); text_.clearSelection(); finishUndo(); - + sanitizeEmptyText(bv); updateLocal(bv); bv->updateParagraphDialog(); } -- 2.39.2