X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2Fmath_nestinset.C;h=79d058907e3ce0f105bca9010f9d95b3ddebe3d4;hb=183239b7def8ca0e51432f2d88891d4b9f055953;hp=724e8420fb71515f4b43746359d4253751dd09df;hpb=46262e6298f04c797d54d892dd574961d9ce91c6;p=lyx.git diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 724e8420fb..79d058907e 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -196,8 +196,11 @@ void MathNestInset::draw(PainterInfo & pi, int x, int y) const } -void MathNestInset::drawSelection(PainterInfo & pi, int, int) const +void MathNestInset::drawSelection(PainterInfo & pi, int x, int y) const { + // FIXME: hack to get position cache warm + draw(pi, x, y); + // this should use the x/y values given, not the cached values LCursor & cur = pi.base.bv->cursor(); if (!cur.selection()) @@ -377,7 +380,7 @@ void MathNestInset::handleFont2(LCursor & cur, string const & arg) } -void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) +void MathNestInset::doDispatch(LCursor & cur, FuncRequest & cmd) { //lyxerr << "MathNestInset: request: " << cmd << std::endl; //CursorSlice sl = cur.current(); @@ -389,7 +392,7 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) cur.message(_("Paste")); replaceSelection(cur); size_t n = 0; - istringstream is(cmd.argument.c_str()); + istringstream is(cmd.argument); is >> n; pasteSelection(cur, n); cur.clearSelection(); // bug 393 @@ -443,7 +446,7 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) cur.autocorrect() = false; cur.clearTargetX(); cur.macroModeClose(); - else if (cur.pos() != cur.lastpos() && cur.openable(cur.nextAtom())) { + if (cur.pos() != cur.lastpos() && cur.openable(cur.nextAtom())) { cur.pushLeft(*cur.nextAtom().nucleus()); cur.inset().idxFirst(cur); } else if (cur.posRight() || idxRight(cur) @@ -542,15 +545,11 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) case LFUN_PRIORSEL: case LFUN_PRIOR: - case LFUN_BEGINNINGBUFSEL: - case LFUN_BEGINNINGBUF: cmd = FuncRequest(LFUN_FINISHED_LEFT); break; case LFUN_NEXTSEL: case LFUN_NEXT: - case LFUN_ENDBUFSEL: - case LFUN_ENDBUF: cmd = FuncRequest(LFUN_FINISHED_RIGHT); break; @@ -613,7 +612,7 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) lyxerr << "LFUN_SETXY broken!" << endl; int x = 0; int y = 0; - istringstream is(cmd.argument.c_str()); + istringstream is(cmd.argument); is >> x >> y; cur.setScreenPos(x, y); break; @@ -685,6 +684,9 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) case LFUN_MATH_MODE: #if 1 + // ignore math-mode on when already in math mode + if (currentMode() == InsetBase::MATH_MODE && cmd.argument == "on") + break; cur.macroModeClose(); selClearOrDel(cur); cur.plainInsert(MathAtom(new MathMBoxInset(cur.bv()))); @@ -792,7 +794,7 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) } default: - MathDimInset::priv_dispatch(cur, cmd); + MathDimInset::doDispatch(cur, cmd); break; } } @@ -879,7 +881,7 @@ void MathNestInset::edit(LCursor & cur, bool left) } -InsetBase * MathNestInset::editXY(LCursor & cur, int x, int y) +InsetBase * MathNestInset::editXY(LCursor & cur, int x, int y) const { int idx_min = 0; int dist_min = 1000000; @@ -890,8 +892,8 @@ InsetBase * MathNestInset::editXY(LCursor & cur, int x, int y) idx_min = i; } } - MathArray & ar = cell(idx_min); - cur.push(*this); + MathArray const & ar = cell(idx_min); + cur.push(const_cast(*this)); cur.idx() = idx_min; cur.pos() = ar.x2pos(x - ar.xo()); lyxerr << "found cell : " << idx_min << " pos: " << cur.pos() << endl; @@ -901,37 +903,7 @@ InsetBase * MathNestInset::editXY(LCursor & cur, int x, int y) if (ar[i]->covers(x, y)) return ar[i].nucleus()->editXY(cur, x, y); } - return this; -} - - -void MathNestInset::lfunMouseRelease(LCursor & cur, FuncRequest & cmd) -{ - //lyxerr << "lfunMouseRelease: buttons: " << cmd.button() << endl; - - if (cmd.button() == mouse_button::button1) { - // try to dispatch to enclosed insets first - //cur.bv().stuffClipboard(cur.grabSelection()); - return; - } - - if (cmd.button() == mouse_button::button2) { - MathArray ar; - asArray(cur.bv().getClipboard(), ar); - cur.clearSelection(); - cur.setScreenPos(cmd.x, cmd.y); - cur.insert(ar); - cur.bv().update(); - return; - } - - if (cmd.button() == mouse_button::button3) { - // try to dispatch to enclosed insets first - cur.bv().owner()->getDialogs().show("mathpanel"); - return; - } - - cur.undispatched(); + return const_cast(this); } @@ -941,7 +913,6 @@ void MathNestInset::lfunMousePress(LCursor & cur, FuncRequest & cmd) if (cmd.button() == mouse_button::button1) { first_x = cmd.x; first_y = cmd.y; - //cur.setScreenPos(cmd.x + xo_, cmd.y + yo_); lyxerr << "lfunMousePress: setting cursor to: " << cur << endl; cur.resetAnchor(); cur.bv().cursor() = cur; @@ -956,16 +927,46 @@ void MathNestInset::lfunMousePress(LCursor & cur, FuncRequest & cmd) void MathNestInset::lfunMouseMotion(LCursor & cur, FuncRequest & cmd) { // only select with button 1 - if (cmd.button() != mouse_button::button1) + if (cmd.button() == mouse_button::button1) { + LCursor & bvcur = cur.bv().cursor(); + if (abs(cmd.x - first_x) + abs(cmd.y - first_y) > 4 + && bvcur.anchor_.hasPart(cur)) { + first_x = cmd.x; + first_y = cmd.y; + + bvcur.setCursor(cur); + bvcur.selection() = true; + } + } +} + + +void MathNestInset::lfunMouseRelease(LCursor & cur, FuncRequest & cmd) +{ + lyxerr << "lfunMouseRelease: buttons: " << cmd.button() << endl; + + if (cmd.button() == mouse_button::button1) { + //cur.bv().stuffClipboard(cur.grabSelection()); return; + } - if (abs(cmd.x - first_x) < 2 && abs(cmd.y - first_y) < 2) + if (cmd.button() == mouse_button::button2) { + MathArray ar; + asArray(cur.bv().getClipboard(), ar); + cur.clearSelection(); + cur.setScreenPos(cmd.x, cmd.y); + cur.insert(ar); + cur.bv().update(); return; + } - first_x = cmd.x; - first_y = cmd.y; + if (cmd.button() == mouse_button::button3) { + // try to dispatch to enclosed insets first + cur.bv().owner()->getDialogs().show("mathpanel"); + return; + } - cur.bv().cursor().setCursor(cur, true); + cur.undispatched(); } @@ -977,7 +978,6 @@ bool MathNestInset::interpret(LCursor & cur, char c) // handle macroMode if (cur.inMacroMode()) { string name = cur.macroName(); - lyxerr << "interpret macro name: '" << name << "'" << endl; /// are we currently typing '#1' or '#2' or...? if (name == "\\#") { @@ -1009,10 +1009,8 @@ bool MathNestInset::interpret(LCursor & cur, char c) cur.backspace(); cur.niceInsert(MathAtom(new MathCommentInset)); } else if (c == '#') { - lyxerr << "setting name to " << name + c << endl; BOOST_ASSERT(cur.activeMacro()); cur.activeMacro()->setName(name + c); - lyxerr << "set name to " << name + c << endl; } else { cur.backspace(); cur.niceInsert(createMathInset(string(1, c))); @@ -1148,11 +1146,8 @@ bool MathNestInset::script(LCursor & cur, bool up) lyxerr << "converting prev atom " << endl; cur.prevAtom() = MathAtom(new MathScriptInset(cur.prevAtom(), up)); } - lyxerr << "new scriptinset 2: cur:\n" << cur << endl; --cur.pos(); - lyxerr << "new scriptinset 3: cur:\n" << cur << endl; MathScriptInset * inset = cur.nextAtom().nucleus()->asScriptInset(); - lyxerr << "new scriptinset 3: inset:\n" << inset << endl; cur.push(*inset); cur.idx() = 1; cur.pos() = 0;