From: André Pönitz Date: Wed, 28 Aug 2002 12:09:19 +0000 (+0000) Subject: 100 lines moved, 33 dead. X-Git-Tag: 1.6.10~18436 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=f59571dcabc7ad977881013b3b98f097c75657b3;p=lyx.git 100 lines moved, 33 dead. Just for the record: 1.2.1: 3666 8203 85497 BufferView_pimpl.C 2693 8230 72506 text2.C 6359 16433 158003 total 1.3cvs equivalent: 1451 3413 34098 BufferView_pimpl.C 2407 7391 64931 text2.C 1588 4040 39668 text3.C 94 203 2167 factory.C 5540 15047 140864 total so we saved over 800 lines by just moving stuff around... git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5134 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BufferView.C b/src/BufferView.C index a89be01ea8..53e1ffd55c 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -110,12 +110,6 @@ void BufferView::scrollDocView(int value) } -Inset * BufferView::checkInsetHit(LyXText * text, int & x, int & y) -{ - return pimpl_->checkInsetHit(text, x, y); -} - - void BufferView::redoCurrentBuffer() { pimpl_->redoCurrentBuffer(); diff --git a/src/BufferView.h b/src/BufferView.h index 8d72e59c0c..712bdba8ba 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -78,8 +78,6 @@ public: /// void updateScrollbar(); /// - Inset * checkInsetHit(LyXText *, int & x, int & y); - /// void redoCurrentBuffer(); /// bool available() const; diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 01bbd70f64..696f9197c1 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -41,7 +41,6 @@ #include "ParagraphParameters.h" #include "undo_funcs.h" #include "funcrequest.h" -#include "box.h" #include "insets/insetbib.h" #include "insets/insettext.h" @@ -104,71 +103,6 @@ boost::signals::connection selectioncon; boost::signals::connection lostcon; - /** - * Return the on-screen dimensions of the inset at the cursor. - * Pre-condition: the cursor must be at an inset. - */ -Box insetDimensions(BufferView * bv, LyXText const & text, - LyXCursor const & cursor) -{ - Paragraph /*const*/ & par = *cursor.par(); - pos_type const pos = cursor.pos(); - - lyx::Assert(par.getInset(pos)); - - Inset const & inset(*par.getInset(pos)); - - LyXFont const & font = text.getFont(bv->buffer(), &par, pos); - - int const width = inset.width(bv, font); - int const inset_x = font.isVisibleRightToLeft() - ? (cursor.ix() - width) : cursor.ix(); - - return Box( - inset_x + inset.scroll(), - inset_x + width, - cursor.iy() - inset.ascent(bv, font), - cursor.iy() + inset.descent(bv, font)); -} - - -/** - * check if the given co-ordinates are inside an inset at the - * given cursor, if one exists. If so, the inset is returned, - * and the co-ordinates are made relative. Otherwise, 0 is returned. - */ -Inset * checkInset(BufferView * bv, LyXText const & text, - LyXCursor const & cursor, int & x, int & y) -{ - pos_type const pos = cursor.pos(); - Paragraph /*const*/ & par(*cursor.par()); - - if (pos >= par.size() || !par.isInset(pos)) { - return 0; - } - - Inset /*const*/ * inset = par.getInset(pos); - - if (!isEditableInset(inset)) - return 0; - - Box b = insetDimensions(bv, text, cursor); - - if (!b.contained(x, y)) { - lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y - << " box " << b << endl; - return 0; - } - - text.setCursor(bv, &par, pos, true); - - x -= b.x1; - // The origin of an inset is on the baseline - y -= text.cursor.iy(); - - return inset; -} - } // anon namespace @@ -514,37 +448,6 @@ void BufferView::Pimpl::selectionLost() } - -Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y) -{ - int y_tmp = y + text->first_y; - - LyXCursor cursor; - text->setCursorFromCoordinates(bv_, cursor, x, y_tmp); - - Inset * inset = checkInset(bv_, *text, cursor, x, y_tmp); - - if (inset) { - y = y_tmp; - return inset; - } - - // look at previous position - if (cursor.pos() == 0) { - return 0; - } - - // move back one - text->setCursor(bv_, cursor, cursor.par(), cursor.pos() - 1, true); - - inset = checkInset(bv_, *text, cursor, x, y_tmp); - if (inset) { - y = y_tmp; - } - return inset; -} - - void BufferView::Pimpl::workAreaResize() { static int work_area_width; diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index b1832f9b36..15f320bf8f 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -62,12 +62,6 @@ struct BufferView::Pimpl : public boost::signals::trackable { void updateScrollbar(); /// void scrollDocView(int value); - /** - * Returns an inset if inset was hit, or 0 if not. - * - * If hit, the coordinates are changed relative to the inset. - */ - Inset * checkInsetHit(LyXText *, int & x, int & y); /// wheel mouse scroll int scroll(long time); /// diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 7a8111fe2f..bb7c5221fd 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -1004,7 +1004,7 @@ void InsetText::lfunMousePress(FuncRequest const & cmd) int tmp_x = cmd.x - drawTextXOffset; int tmp_y = cmd.y + insetAscent - getLyXText(bv)->first_y; - Inset * inset = bv->checkInsetHit(getLyXText(bv), tmp_x, tmp_y); + Inset * inset = getLyXText(bv)->checkInsetHit(bv, tmp_x, tmp_y); hideInsetCursor(bv); if (the_locking_inset) { @@ -1113,7 +1113,7 @@ bool InsetText::lfunMouseRelease(FuncRequest const & cmd) int tmp_x = cmd.x - drawTextXOffset; int tmp_y = cmd.y + insetAscent - getLyXText(bv)->first_y; - Inset * inset = bv->checkInsetHit(getLyXText(bv), tmp_x, tmp_y); + Inset * inset = getLyXText(bv)->checkInsetHit(bv, tmp_x, tmp_y); bool ret = false; if (inset) { if (isHighlyEditableInset(inset)) @@ -2050,7 +2050,7 @@ bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y, x -= drawTextXOffset; int dummyx = x; int dummyy = y + insetAscent; - Inset * inset = bv->checkInsetHit(getLyXText(bv), dummyx, dummyy); + Inset * inset = getLyXText(bv)->checkInsetHit(bv, dummyx, dummyy); // we only do the edit() call if the inset was hit by the mouse // or if it is a highly editable inset. So we should call this // function from our own edit with button < 0. diff --git a/src/lyxtext.h b/src/lyxtext.h index 3f8dc0569d..01ffb481f7 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -624,6 +624,12 @@ public: void updateCounters(BufferView *) const; /// void update(BufferView * bv, bool changed = true); + /** + * Returns an inset if inset was hit, or 0 if not. + * If hit, the coordinates are changed relative to the inset. + */ + Inset * checkInsetHit(BufferView * bv, int & x, int & y) const; + private: /// void setCounter(Buffer const *, Paragraph * par) const; diff --git a/src/text2.C b/src/text2.C index 228a5039c6..984a3f4cad 100644 --- a/src/text2.C +++ b/src/text2.C @@ -2078,8 +2078,7 @@ void LyXText::cursorUp(BufferView * bview, bool selecting) const int y1 = cursor.iy() - first_y; int y2 = y1; y -= first_y; - Inset * inset_hit = - bview->checkInsetHit(const_cast(this), x, y1); + Inset * inset_hit = checkInsetHit(bview, x, y1); if (inset_hit && isHighlyEditableInset(inset_hit)) { inset_hit->edit(bview, x, y - (y2 - y1), mouse_button::none); } @@ -2102,8 +2101,7 @@ void LyXText::cursorDown(BufferView * bview, bool selecting) const int y1 = cursor.iy() - first_y; int y2 = y1; y -= first_y; - Inset * inset_hit = - bview->checkInsetHit(const_cast(this), x, y1); + Inset * inset_hit = checkInsetHit(bview, x, y1); if (inset_hit && isHighlyEditableInset(inset_hit)) { inset_hit->edit(bview, x, y - (y2 - y1), mouse_button::none); } diff --git a/src/text3.C b/src/text3.C index f4a50ab3e3..13b5db34b0 100644 --- a/src/text3.C +++ b/src/text3.C @@ -23,6 +23,7 @@ #include "gettext.h" #include "factory.h" #include "intl.h" +#include "box.h" #include "language.h" #include "support/lstrings.h" #include "frontends/LyXView.h" @@ -87,6 +88,80 @@ namespace { bv->owner()->view_state_changed(); } + // check if the given co-ordinates are inside an inset at the + // given cursor, if one exists. If so, the inset is returned, + // and the co-ordinates are made relative. Otherwise, 0 is returned. + Inset * checkInset(BufferView * bv, LyXText const & text, int & x, int & y) + { + LyXCursor const & cursor = text.cursor; + lyx::pos_type const pos = cursor.pos(); + Paragraph /*const*/ & par = *cursor.par(); + + if (pos >= par.size() || !par.isInset(pos)) + return 0; + + Inset /*const*/ * inset = par.getInset(pos); + + if (!isEditableInset(inset)) + return 0; + + // get inset dimensions + lyx::Assert(par.getInset(pos)); + + LyXFont const & font = text.getFont(bv->buffer(), &par, pos); + + int const width = inset->width(bv, font); + int const inset_x = font.isVisibleRightToLeft() + ? (cursor.ix() - width) : cursor.ix(); + + Box b( + inset_x + inset->scroll(), + inset_x + width, + cursor.iy() - inset->ascent(bv, font), + cursor.iy() + inset->descent(bv, font)); + + if (!b.contained(x, y)) { + lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y + << " box " << b << endl; + return 0; + } + + text.setCursor(bv, &par, pos, true); + + x -= b.x1; + // The origin of an inset is on the baseline + y -= text.cursor.iy(); + + return inset; + } + +} // anon namespace + + +Inset * LyXText::checkInsetHit(BufferView * bv, int & x, int & y) const +{ + int y_tmp = y + first_y; + + LyXCursor cursor; + setCursorFromCoordinates(bv, cursor, x, y_tmp); + + Inset * inset = checkInset(bv, *this, x, y_tmp); + if (inset) { + y = y_tmp; + return inset; + } + + // look at previous position + if (cursor.pos() == 0) + return 0; + + // move back one + setCursor(bv, cursor, cursor.par(), cursor.pos() - 1, true); + + inset = checkInset(bv, *this, x, y_tmp); + if (inset) + y = y_tmp; + return inset; } @@ -1231,16 +1306,15 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd) #endif // This is to allow jumping over large insets if (cursorrow == bv->text->cursor.row()) { - if (cmd.y >= int(bv->workarea().workHeight())) { + if (cmd.y >= int(bv->workarea().workHeight())) bv->text->cursorDown(bv, false); - } else if (cmd.y < 0) { + else if (cmd.y < 0) bv->text->cursorUp(bv, false); - } } + // Maybe an empty line was deleted if (!bv->text->selection.set()) - bv->update(bv->text, BufferView::UPDATE); // Maybe an empty line was deleted - + bv->update(bv->text, BufferView::UPDATE); bv->text->setSelection(bv); bv->screen().toggleToggle(bv->text, bv); bv->fitCursor(); @@ -1269,7 +1343,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd) int x = cmd.x; int y = cmd.y; - Inset * inset_hit = bv->checkInsetHit(bv->text, x, y); + Inset * inset_hit = bv->text->checkInsetHit(bv, x, y); // Middle button press pastes if we have a selection // We do this here as if the selection was inside an inset @@ -1369,7 +1443,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd) // inset, inset_hit is 0, and inset_x == x, inset_y == y. int x = cmd.x; int y = cmd.y; - Inset * inset_hit = bv->checkInsetHit(bv->text, x, y); + Inset * inset_hit = bv->text->checkInsetHit(bv, x, y); if (bv->theLockingInset()) { // We are in inset locking mode.