- setCurrentFont(cur);
-}
-
-
-void Text::setCurrentFont(Cursor & cur)
-{
- BOOST_ASSERT(this == cur.text());
- pos_type pos = cur.pos();
- Paragraph & par = cur.paragraph();
-
- // are we behind previous char in fact? -> go to that char
- if (pos > 0 && cur.boundary())
- --pos;
-
- // find position to take the font from
- if (pos != 0) {
- // paragraph end? -> font of last char
- if (pos == cur.lastpos())
- --pos;
- // on space? -> look at the words in front of space
- else if (pos > 0 && par.isSeparator(pos)) {
- // abc| def -> font of c
- // abc |[WERBEH], i.e. boundary==true -> font of c
- // abc [WERBEH]| def, font of the space
- if (!isRTLBoundary(cur.buffer(), par, pos))
- --pos;
- }
- }
-
- // get font
- BufferParams const & bufparams = cur.buffer().params();
- current_font = par.getFontSettings(bufparams, pos);
- real_current_font = getFont(cur.buffer(), par, pos);
-
- // special case for paragraph end
- if (cur.pos() == cur.lastpos()
- && isRTLBoundary(cur.buffer(), par, cur.pos())
- && !cur.boundary()) {
- Language const * lang = par.getParLanguage(bufparams);
- current_font.setLanguage(lang);
- current_font.setNumber(Font::OFF);
- real_current_font.setLanguage(lang);
- real_current_font.setNumber(Font::OFF);
- }
-}
-
-// y is screen coordinate
-pit_type Text::getPitNearY(BufferView & bv, int y) const
-{
- BOOST_ASSERT(!paragraphs().empty());
- BOOST_ASSERT(bv.coordCache().getParPos().find(this) != bv.coordCache().getParPos().end());
- CoordCache::InnerParPosCache const & cc = bv.coordCache().getParPos().find(this)->second;
- LYXERR(Debug::DEBUG)
- << BOOST_CURRENT_FUNCTION
- << ": y: " << y << " cache size: " << cc.size()
- << endl;
-
- // look for highest numbered paragraph with y coordinate less than given y
- pit_type pit = 0;
- int yy = -1;
- CoordCache::InnerParPosCache::const_iterator it = cc.begin();
- CoordCache::InnerParPosCache::const_iterator et = cc.end();
- CoordCache::InnerParPosCache::const_iterator last = et; last--;
-
- TextMetrics & tm = bv.textMetrics(this);
- ParagraphMetrics const & pm = tm.parMetrics(it->first);
-
- // If we are off-screen (before the visible part)
- if (y < 0
- // and even before the first paragraph in the cache.
- && y < it->second.y_ - int(pm.ascent())) {
- // and we are not at the first paragraph in the inset.
- if (it->first == 0)
- return 0;
- // then this is the paragraph we are looking for.
- pit = it->first - 1;
- // rebreak it and update the CoordCache.
- tm.redoParagraph(pit);
- bv.coordCache().parPos()[this][pit] =
- Point(0, it->second.y_ - pm.descent());
- return pit;
- }
-
- ParagraphMetrics const & pm_last = bv.parMetrics(this, last->first);
-
- // If we are off-screen (after the visible part)
- if (y > bv.workHeight()
- // and even after the first paragraph in the cache.
- && y >= last->second.y_ + int(pm_last.descent())) {
- pit = last->first + 1;
- // and we are not at the last paragraph in the inset.
- if (pit == int(pars_.size()))
- return last->first;
- // then this is the paragraph we are looking for.
- // rebreak it and update the CoordCache.
- tm.redoParagraph(pit);
- bv.coordCache().parPos()[this][pit] =
- Point(0, last->second.y_ + pm_last.ascent());
- return pit;
- }
-
- for (; it != et; ++it) {
- LYXERR(Debug::DEBUG)
- << BOOST_CURRENT_FUNCTION
- << " examining: pit: " << it->first
- << " y: " << it->second.y_
- << endl;
-
- ParagraphMetrics const & pm = bv.parMetrics(this, it->first);
-
- if (it->first >= pit && int(it->second.y_) - int(pm.ascent()) <= y) {
- pit = it->first;
- yy = it->second.y_;
- }
- }
-
- LYXERR(Debug::DEBUG)
- << BOOST_CURRENT_FUNCTION
- << ": found best y: " << yy << " for pit: " << pit
- << endl;
-
- return pit;
-}
-
-
-Row const & Text::getRowNearY(BufferView const & bv, int y, pit_type pit) const
-{
- ParagraphMetrics const & pm = bv.parMetrics(this, pit);
-
- int yy = bv.coordCache().get(this, pit).y_ - pm.ascent();
- BOOST_ASSERT(!pm.rows().empty());
- RowList::const_iterator rit = pm.rows().begin();
- RowList::const_iterator const rlast = boost::prior(pm.rows().end());
- for (; rit != rlast; yy += rit->height(), ++rit)
- if (yy + rit->height() > y)
- break;
- return *rit;
-}
-
-
-// x,y are absolute screen coordinates
-// sets cursor recursively descending into nested editable insets
-Inset * Text::editXY(Cursor & cur, int x, int y)
-{
- if (lyxerr.debugging(Debug::WORKAREA)) {
- lyxerr << "Text::editXY(cur, " << x << ", " << y << ")" << std::endl;
- cur.bv().coordCache().dump();
- }
- pit_type pit = getPitNearY(cur.bv(), y);
- BOOST_ASSERT(pit != -1);
-
- Row const & row = getRowNearY(cur.bv(), y, pit);
- bool bound = false;
-
- TextMetrics const & tm = cur.bv().textMetrics(this);
- int xx = x; // is modified by getColumnNearX
- pos_type const pos = row.pos()
- + tm.getColumnNearX(pit, row, xx, bound);
- cur.pit() = pit;
- cur.pos() = pos;
- cur.boundary(bound);
- cur.setTargetX(x);
-
- // try to descend into nested insets
- Inset * inset = checkInsetHit(cur.bv(), x, y);
- //lyxerr << "inset " << inset << " hit at x: " << x << " y: " << y << endl;
- if (!inset) {
- // Either we deconst editXY or better we move current_font
- // and real_current_font to Cursor
- setCurrentFont(cur);
- return 0;
- }
-
- Inset * insetBefore = pos? pars_[pit].getInset(pos - 1): 0;
- //Inset * insetBehind = pars_[pit].getInset(pos);
-
- // This should be just before or just behind the
- // cursor position set above.
- BOOST_ASSERT((pos != 0 && inset == insetBefore)
- || inset == pars_[pit].getInset(pos));
-
- // Make sure the cursor points to the position before
- // this inset.
- if (inset == insetBefore) {
- --cur.pos();
- cur.boundary(false);
- }
-
- // Try to descend recursively inside the inset.
- inset = inset->editXY(cur, x, y);
-
- if (cur.top().text() == this)
- setCurrentFont(cur);
- return inset;