From 299b6e315aec062d10e0c293e62fcf2073bae58f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 6 Feb 2004 16:50:29 +0000 Subject: [PATCH] a bit of selection is back git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8415 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView_pimpl.C | 5 ++- src/cursor.C | 13 +++----- src/mathed/math_nestinset.C | 8 ++--- src/text3.C | 63 ++++++++++++++++--------------------- 4 files changed, 39 insertions(+), 50 deletions(-) diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index a46e035d29..9a3f2a948e 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -890,7 +890,9 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0) cmd.y += bv_->top_y(); //lyxerr << "*** workAreaDispatch: request: " << cmd << std::endl; LCursor cur(*bv_); + cur.selection() = bv_->cursor().selection(); switch (cmd.action) { + #if 0 case LFUN_MOUSE_MOTION: { if (!available()) @@ -910,9 +912,10 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0) } return true; } +#else + case LFUN_MOUSE_MOTION: #endif - case LFUN_MOUSE_MOTION: case LFUN_MOUSE_PRESS: case LFUN_MOUSE_RELEASE: case LFUN_MOUSE_DOUBLE: diff --git a/src/cursor.C b/src/cursor.C index d5914a5d44..b6eae936b8 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -80,12 +80,10 @@ DispatchResult LCursor::dispatch(FuncRequest const & cmd0) lyxerr << "\nLCursor::dispatch: cmd: " << cmd0 << endl << *this << endl; FuncRequest cmd = cmd0; for (current_ = cursor_.size() - 1; current_ >= 1; --current_) { - lyxerr << "trying to dispatch to inset " << inset() << endl; DispatchResult res = inset()->dispatch(*this, cmd); - if (res.dispatched()) { - lyxerr << " successfully dispatched to inset " << inset() << endl; + if (res.dispatched()) return DispatchResult(true, true); - } + // "Mutate" the request for semi-handled requests that need // additional handling in outer levels. switch (res.val()) { @@ -108,8 +106,6 @@ DispatchResult LCursor::dispatch(FuncRequest const & cmd0) } } BOOST_ASSERT(current_ == 0); - //lyxerr << "trying to dispatch to main text " << bv_->text() - // << " with cursor: " << *this << endl; DispatchResult res = bv_->text()->dispatch(*this, cmd); //lyxerr << " result: " << res.val() << endl; return res; @@ -736,10 +732,11 @@ void LCursor::selClearOrDel() std::ostream & operator<<(std::ostream & os, LCursor const & cur) { - os << "\n"; for (size_t i = 0, n = cur.cursor_.size(); i != n; ++i) os << " (" << cur.cursor_[i] << " | " << cur.anchor_[i] << "\n"; - return os << "current: " << cur.current_ << endl; + os << " current: " << cur.current_ << endl; + os << " selection: " << cur.selection_ << endl; + return os; } diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index a8c931a9f2..4365383e75 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -803,7 +803,6 @@ MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd) void MathNestInset::edit(LCursor & cur, bool left) { - lyxerr << "XXX Called MathNestInset::edit" << endl; cur.push(this); cur.idx() = left ? 0 : cur.lastidx(); cur.pos() = left ? 0 : cur.lastpos(); @@ -813,8 +812,6 @@ void MathNestInset::edit(LCursor & cur, bool left) void MathNestInset::edit(LCursor & cur, int x, int y) { - lyxerr << "XXX Called MathNestInset::edit with '" - << x << ' ' << y << "'" << endl; int idx_min = 0; int dist_min = 1000000; for (idx_type i = 0; i < nargs(); ++i) { @@ -911,7 +908,8 @@ MathNestInset::lfunMouseMotion(LCursor & cur, FuncRequest const & cmd) if (!cur.selection()) cur.selBegin(); - cur.setScreenPos(cmd.x + xo_, cmd.y + yo_); - cur.bv().update(); + //cur.setScreenPos(cmd.x + xo_, cmd.y + yo_); + cur.bv().cursor().cursor_ = cur.cursor_; + cur.bv().cursor().selection() = true; return DispatchResult(true, true); } diff --git a/src/text3.C b/src/text3.C index d10dbbb65b..6cebcfb88c 100644 --- a/src/text3.C +++ b/src/text3.C @@ -587,15 +587,12 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) break; case LFUN_BREAKLINE: { - lyx::pos_type body = cursorPar()->beginOfBody(); - // Not allowed by LaTeX (labels or empty par) - if (cursor().pos() <= body) - break; - - replaceSelection(bv->getLyXText()); - insertInset(new InsetNewline); - moveCursor(cur, false); + if (cursor().pos() > cursorPar()->beginOfBody()) { + replaceSelection(this); + insertInset(new InsetNewline); + moveCursor(cur, false); + } break; } @@ -661,7 +658,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) break; case LFUN_BREAKPARAGRAPH: - replaceSelection(bv->getLyXText()); + replaceSelection(this); breakParagraph(bv->buffer()->paragraphs(), 0); bv->update(); cur.resetAnchor(); @@ -670,7 +667,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) break; case LFUN_BREAKPARAGRAPHKEEPLAYOUT: - replaceSelection(bv->getLyXText()); + replaceSelection(this); breakParagraph(bv->buffer()->paragraphs(), 1); bv->update(); cur.resetAnchor(); @@ -684,7 +681,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) // Otherwise, do the same as LFUN_BREAKPARAGRAPH. #warning look here // CursorSlice cur = cursor(); - replaceSelection(bv->getLyXText()); + replaceSelection(this); if (cur.pos() == 0) { ParagraphParameters & params = getPar(cur.current())->params(); setParagraph( @@ -824,7 +821,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) case LFUN_PASTE: cur.message(_("Paste")); - replaceSelection(bv->getLyXText()); + replaceSelection(this); #warning FIXME Check if the arg is in the domain of available selections. if (isStrUnsignedInt(cmd.argument)) pasteSelection(strToUnsignedInt(cmd.argument)); @@ -985,7 +982,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) } case LFUN_QUOTE: { - replaceSelection(bv->getLyXText()); + replaceSelection(this); ParagraphList::iterator pit = cursorPar(); lyx::pos_type pos = cursor().pos(); char c; @@ -1008,7 +1005,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) } case LFUN_DATE_INSERT: { - replaceSelection(bv->getLyXText()); + replaceSelection(this); time_t now_time_t = time(NULL); struct tm * now_tm = localtime(&now_time_t); setlocale(LC_TIME, ""); @@ -1030,7 +1027,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) } case LFUN_MOUSE_TRIPLE: - if (bv->buffer() && cmd.button() == mouse_button::button1) { + if (cmd.button() == mouse_button::button1) { selection_possible = true; cursorHome(); cur.resetAnchor(); @@ -1041,7 +1038,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) break; case LFUN_MOUSE_DOUBLE: - if (bv->buffer() && cmd.button() == mouse_button::button1) { + if (cmd.button() == mouse_button::button1) { selection_possible = true; selectWord(lyx::WHOLE_WORD_STRICT); bv->haveSelection(cur.selection()); @@ -1049,15 +1046,9 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) break; case LFUN_MOUSE_MOTION: { -#if 0 // Only use motion with button 1 //if (ev.button() != mouse_button::button1) // return false; - // don't set anchor_ - bv->cursor().cursor_ = cur.cursor_; - - if (!bv->buffer()) - break; // The test for not selection possible is needed, that // only motion events are used, where the bottom press // event was on the drawing area too @@ -1068,6 +1059,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) } RowList::iterator cursorrow = cursorRow(); +#warning setCursorFromCoordinates(cmd.x, cmd.y); // This is to allow jumping over large insets @@ -1078,16 +1070,16 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) else if (cmd.y - bv->top_y() < 0) cursorUp(true); } - cur.setSelection(); -#endif + + // don't set anchor_ + bv->cursor().cursor_ = cur.cursor_; + bv->cursor().setSelection(); + break; } // Single-click on work area case LFUN_MOUSE_PRESS: { - if (!bv->buffer()) - break; - // ok ok, this is a hack (for xforms) // We shouldn't go further down as we really should only do the // scrolling and be done with this. Otherwise we may open some @@ -1096,11 +1088,19 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) bv->scroll(-lyxrc.wheel_jump); break; } + if (cmd.button() == mouse_button::button5) { bv->scroll(lyxrc.wheel_jump); break; } + // Right click on a footnote flag opens float menu + if (cmd.button() == mouse_button::button3) { + cur.clearSelection(); + selection_possible = false; + break; + } + // Middle button press pastes if we have a selection // We do this here as if the selection was inside an inset // it could get cleared on the unlocking of the inset so @@ -1116,12 +1116,6 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) // Clear the selection cur.clearSelection(); - // Right click on a footnote flag opens float menu - if (cmd.button() == mouse_button::button3) { - selection_possible = false; - break; - } - setCursorFromCoordinates(cur.current(), cmd.x - xo_, cmd.y - yo_); cur.resetAnchor(); @@ -1148,9 +1142,6 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) } case LFUN_MOUSE_RELEASE: { - if (!bv->buffer()) - break; - // do nothing if we used the mouse wheel if (cmd.button() == mouse_button::button4 || cmd.button() == mouse_button::button5)