-
-bool LCursor::bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh)
-{
- BOOST_ASSERT(!empty());
- par_type beg, end;
- CursorSlice bottom = operator[](0);
- LyXText * text = bottom.text();
- BOOST_ASSERT(text);
- getParsInRange(text->paragraphs(), ylow, yhigh, beg, end);
-
- DocIterator it = doc_iterator_begin(bv().buffer()->inset());
- DocIterator et = doc_iterator_end(bv().buffer()->inset());
- //lyxerr << "x: " << x << " y: " << y << endl;
- //lyxerr << "xlow: " << xlow << " ylow: " << ylow << endl;
- //lyxerr << "xhigh: " << xhigh << " yhigh: " << yhigh << endl;
-
- it.par() = beg;
- //et.par() = text->parOffset(end);
-
- double best_dist = 10e10;
- DocIterator best_cursor = it;
-
- for ( ; it != et; it.forwardPos()) {
- // avoid invalid nesting when selecting
- if (!selection() || positionable(it, anchor_)) {
- int xo = 0, yo = 0;
- LCursor cur = *this;
- cur.setCursor(it, false);
- cur.inset().getCursorPos(cur, xo, yo);
- if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
- double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
- //lyxerr << "xo: " << xo << " yo: " << yo << " d: " << d << endl;
- // '<=' in order to take the last possible position
- // this is important for clicking behind \sum in e.g. '\sum_i a'
- if (d <= best_dist) {
- //lyxerr << "*" << endl;
- best_dist = d;
- best_cursor = it;
- }
- }
- }
- }
-
- //lyxerr << "best_dist: " << best_dist << " cur:\n" << best_cursor << endl;
- if (best_dist < 1e10)
- setCursor(best_cursor, false);
- return best_dist < 1e10;
-}
-
-
-void LCursor::bruteFind2(int x, int y)
-{
- double best_dist = 1e10;
-
- DocIterator it = *this;
- it.back().pos() = 0;
- DocIterator et = *this;
- et.back().pos() = et.back().asMathInset()->cell(et.back().idx()).size();
- for (int i = 0; ; ++i) {
- int xo, yo;
- LCursor cur = *this;
- cur.setCursor(it, false);
- cur.inset().getCursorPos(cur, xo, yo);
- double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
- // '<=' in order to take the last possible position
- // this is important for clicking behind \sum in e.g. '\sum_i a'
- lyxerr << "i: " << i << " d: " << d << " best: " << best_dist << endl;
- if (d <= best_dist) {
- best_dist = d;
- setCursor(it, false);
- }
- if (it == et)
- break;
- it.forwardPos();
- }