From: André Pönitz Date: Sat, 14 Aug 2004 21:56:40 +0000 (+0000) Subject: make all cached positions screen-absolute X-Git-Tag: 1.6.10~15061 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=b4b6c8b0785e89735c5a565019b1c62be63387fa;p=features.git make all cached positions screen-absolute git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8936 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/coordcache.h b/src/coordcache.h index ac89bd251e..639563036d 100644 --- a/src/coordcache.h +++ b/src/coordcache.h @@ -63,6 +63,12 @@ public: return data_.find(thing) != data_.end(); } +// T * find(int x, int y) const +// { +// T * +// cache_type iter +// } + private: friend class CoordCache; @@ -74,7 +80,8 @@ private: } } - std::map data_; + typedef std::map cache_type; + cache_type data_; }; diff --git a/src/insets/inset.C b/src/insets/inset.C index 0f8bbc739e..1f60140025 100644 --- a/src/insets/inset.C +++ b/src/insets/inset.C @@ -85,5 +85,5 @@ int InsetOld::scroll(bool) const void InsetOld::setPosCache(PainterInfo const & pi, int x, int y) const { //lyxerr << "InsetOld:: position cache to " << x << " " << y << std::endl; - theCoords.insets_.add(this, x, y + pi.base.bv->top_y()); + theCoords.insets_.add(this, x, y); } diff --git a/src/paragraph.C b/src/paragraph.C index 33c4eb1b8e..1dd00d4dee 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -1736,25 +1736,6 @@ void Paragraph::rejectChange(pos_type start, pos_type end) } -//Paragraph::value_type Paragraph::getChar(pos_type pos) const -//{ -// // This is in the critical path! -// pos_type const siz = text_.size(); -// -// BOOST_ASSERT(0 <= pos); -// BOOST_ASSERT(pos <= siz); -// -// if (pos == siz) { -// lyxerr << "getChar() on pos " << pos << " in par id " -// << id() << " of size " << siz -// << " is a bit silly !" << endl; -// BOOST_ASSERT(false); -// } -// -// return text_[pos]; -//} - - int Paragraph::id() const { return pimpl_->id_; diff --git a/src/rowpainter.C b/src/rowpainter.C index 9f970230c3..7c765847e3 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -544,9 +544,9 @@ void RowPainter::paintDepthBar() for (Paragraph::depth_type i = 1; i <= depth; ++i) { int const w = nestMargin() / 5; - int x = xo_ + w * i; - // only consider the changebar space if we're drawing outer left - if (xo_ == 0) + int x = int(xo_) + w * i; + // only consider the changebar space if we're drawing outermost text + if (text_.isMainText()) x += changebarMargin(); int const h = yo_ + row_.height() - 1 - (i - next_depth - 1) * 3; diff --git a/src/text.C b/src/text.C index 23748129f5..7021b6929c 100644 --- a/src/text.C +++ b/src/text.C @@ -1680,26 +1680,6 @@ Paragraph & LyXText::getPar(par_type par) const } -// y is relative to this LyXText's top -Row const & LyXText::getRowNearY(int y, par_type & pit) const -{ - BOOST_ASSERT(!paragraphs().empty()); - BOOST_ASSERT(!paragraphs().begin()->rows.empty()); - par_type const pend = paragraphs().size() - 1; - pit = 0; - while (int(pars_[pit].y + pars_[pit].height) < y && pit != pend) - ++pit; - - RowList::iterator rit = pars_[pit].rows.end(); - RowList::iterator const rbegin = pars_[pit].rows.begin(); - do { - --rit; - } while (rit != rbegin && int(pars_[pit].y + rit->y_offset()) > y); - - return *rit; -} - - Row const & LyXText::firstRow() const { return *paragraphs().front().rows.begin(); diff --git a/src/text2.C b/src/text2.C index f15294a1ee..2cf60136e7 100644 --- a/src/text2.C +++ b/src/text2.C @@ -113,6 +113,8 @@ InsetBase * LyXText::checkInsetHit(int x, int y) const bv()->top_y() - yo_ + bv()->workHeight(), pit, end); + // convert to screen-absolute y coordinate + y -= bv()->top_y(); lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl; lyxerr << " pit: " << pit << " end: " << end << endl; for (; pit != end; ++pit) { @@ -1162,6 +1164,27 @@ pos_type LyXText::getColumnNearX(par_type pit, } +// y is relative to this LyXText's top +// this is only used in the two functions below +Row const & LyXText::getRowNearY(int y, par_type & pit) const +{ + BOOST_ASSERT(!paragraphs().empty()); + BOOST_ASSERT(!paragraphs().begin()->rows.empty()); + par_type const pend = paragraphs().size() - 1; + pit = 0; + while (int(pars_[pit].y + pars_[pit].height) < y && pit != pend) + ++pit; + + RowList::iterator rit = pars_[pit].rows.end(); + RowList::iterator const rbegin = pars_[pit].rows.begin(); + do { + --rit; + } while (rit != rbegin && int(pars_[pit].y + rit->y_offset()) > y); + + return *rit; +} + + // x,y are absolute coordinates // sets cursor only within this LyXText void LyXText::setCursorFromCoordinates(LCursor & cur, int x, int y) diff --git a/src/text3.C b/src/text3.C index 0b230da156..869cda8b7b 100644 --- a/src/text3.C +++ b/src/text3.C @@ -1129,25 +1129,24 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) // ignore motions deeper nested than the real anchor LCursor & bvcur = cur.bv().cursor(); - if (!bvcur.anchor_.hasPart(cur)) - break; - - CursorSlice old = cur.top(); - setCursorFromCoordinates(cur, cmd.x, cmd.y); + if (bvcur.anchor_.hasPart(cur)) { + CursorSlice old = cur.top(); + setCursorFromCoordinates(cur, cmd.x, cmd.y); + + // This is to allow jumping over large insets + // FIXME: shouldn't be top-text-specific + if (isMainText() && cur.top() == old) { + if (cmd.y - bv->top_y() >= bv->workHeight()) + cursorDown(cur); + else if (cmd.y - bv->top_y() < 0) + cursorUp(cur); + } - // This is to allow jumping over large insets - // FIXME: shouldn't be top-text-specific - if (isMainText() && cur.top() == old) { - if (cmd.y - bv->top_y() >= bv->workHeight()) - cursorDown(cur); - else if (cmd.y - bv->top_y() < 0) - cursorUp(cur); + // don't set anchor_ + bv->cursor().setCursor(cur); + bv->cursor().selection() = true; + lyxerr << "MOTION: " << bv->cursor() << endl; } - - // don't set anchor_ - bv->cursor().setCursor(cur); - bv->cursor().selection() = true; - lyxerr << "MOTION: " << bv->cursor() << endl; break; }