This is the previous patch + use absolute coords in the inset coord cache - insetcollapsable / insettext seems to work ok. - didn't touch tabular yet (to be done) - cannot test math insets because they crash on mouse clicks.
Alfredo
? DviOut-1.4.0.lyx ? Markers.C ? Markers.h ? PosIterator.C-bold ? PosIterator.h-bold ? lyxrow_funcs.C-bad1 ? paragraph.C-bad1 ? text.C-bad1 ? text.C-good ? text.C-goood ? text.C-save Index: text.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v retrieving revision 1.531 diff -u -p -u -r1.531 text.C --- text.C 6 Feb 2004 11:12:48 -0000 1.531 +++ text.C 6 Feb 2004 12:10:38 -0000 @@ -1414,9 +1414,12 @@ ParagraphList::iterator LyXText::getPar( } +// y is relative to this LyXText's top RowList::iterator LyXText::getRowNearY(int y, ParagraphList::iterator & pit) const { + BOOST_ASSERT(!paragraphs().empty()); + BOOST_ASSERT(!paragraphs().begin()->rows.empty()); #if 1 ParagraphList::iterator const pend = boost::prior(paragraphs().end()); Index: text2.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v retrieving revision 1.539 diff -u -p -u -r1.539 text2.C --- text2.C 4 Feb 2004 11:23:23 -0000 1.539 +++ text2.C 6 Feb 2004 12:10:41 -0000 @@ -1207,7 +1207,7 @@ void LyXText::setCurrentFont() } } - +// x is an absolute screen coord // returns the column near the specified x-coordinate of the row // x is set to the real beginning of this column pos_type LyXText::getColumnNearX(ParagraphList::iterator pit, @@ -1327,7 +1327,8 @@ void LyXText::setCursorFromCoordinates(C ParagraphList::iterator pit; Row const & row = *getRowNearY(y, pit); bool bound = false; - pos_type const pos = row.pos() + getColumnNearX(pit, row, x, bound); + int xx = x + xo_; // getRowNearX get absolute x coords + pos_type const pos = row.pos() + getColumnNearX(pit, row, xx, bound); cur.par() = parOffset(pit); cur.pos() = pos; cur.boundary() = bound; @@ -1337,10 +1338,11 @@ void LyXText::setCursorFromCoordinates(C // x,y are absolute screen coordinates void LyXText::edit(LCursor & cur, int x, int y) { - int xx = x; // is modified by getColumnNearX ParagraphList::iterator pit; - Row const & row = *getRowNearY(y, pit); + Row const & row = *getRowNearY(y - yo_, pit); bool bound = false; + + int xx = x; // is modified by getColumnNearX pos_type const pos = row.pos() + getColumnNearX(pit, row, xx, bound); cur.par() = parOffset(pit); cur.pos() = pos; @@ -1349,11 +1351,12 @@ void LyXText::edit(LCursor & cur, int x, // try to descend into nested insets InsetBase * inset = checkInsetHit(x, y); if (inset) { - // This should be just before or just behind the cursor position - // set above. + // This should be just before or just behind the + // cursor position set above. BOOST_ASSERT((pos != 0 && inset == pit->getInset(pos - 1)) || inset == pit->getInset(pos)); - // Make sure the cursor points to the position before this inset. + // Make sure the cursor points to the position before + // this inset. if (inset == pit->getInset(pos - 1)) --cur.pos(); inset->edit(cur, x, y); Index: text3.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v retrieving revision 1.216 diff -u -p -u -r1.216 text3.C --- text3.C 4 Feb 2004 11:23:24 -0000 1.216 +++ text3.C 6 Feb 2004 12:10:43 -0000 @@ -246,14 +246,15 @@ string const freefont2string() } +//takes absolute x,y coordinates InsetBase * LyXText::checkInsetHit(int x, int y) { ParagraphList::iterator pit; ParagraphList::iterator end; getParsInRange(paragraphs(), - bv()->top_y(), - bv()->top_y() + bv()->workHeight(), + bv()->top_y() - yo_, + bv()->top_y() - yo_ + bv()->workHeight(), pit, end); lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl; @@ -269,7 +270,7 @@ InsetBase * LyXText::checkInsetHit(int x << " yo: " << inset->yo() - inset->ascent() << "..." << inset->yo() + inset->descent() << endl; #endif - if (inset->covers(x, y - bv()->top_y())) { + if (inset->covers(x, y)) { lyxerr << "Hit inset: " << inset << endl; return inset; } @@ -1228,7 +1229,8 @@ DispatchResult LyXText::dispatch(LCursor break; } - setCursorFromCoordinates(cur.current(), cmd.x, cmd.y); + setCursorFromCoordinates(cur.current(), cmd.x - xo_, + cmd.y - yo_); cur.resetAnchor(); finishUndo(); cur.x_target() = cursorX(cur.current()); Index: insets/inset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/inset.C,v retrieving revision 1.125 diff -u -p -u -r1.125 inset.C --- insets/inset.C 3 Feb 2004 16:44:57 -0000 1.125 +++ insets/inset.C 6 Feb 2004 12:10:46 -0000 @@ -21,7 +21,7 @@ #include "gettext.h" #include "lyxtext.h" #include "LColor.h" - +#include "metricsinfo.h" using std::string; @@ -87,9 +87,9 @@ int InsetOld::scroll(bool recursive) con } -void InsetOld::setPosCache(PainterInfo const &, int x, int y) const +void InsetOld::setPosCache(PainterInfo const & pi, int x, int y) const { //lyxerr << "InsetOld:: position cache to " << x << " " << y << std::endl; xo_ = x; - yo_ = y; + yo_ = y + pi.base.bv->top_y(); } Index: insets/insetcollapsable.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcollapsable.C,v retrieving revision 1.234 diff -u -p -u -r1.234 insetcollapsable.C --- insets/insetcollapsable.C 6 Feb 2004 11:12:49 -0000 1.234 +++ insets/insetcollapsable.C 6 Feb 2004 12:10:46 -0000 @@ -170,8 +170,8 @@ void InsetCollapsable::draw(PainterInfo int const aa = ascent(); button_dim.x1 = x + 0; button_dim.x2 = x + dimc.width(); - button_dim.y1 = y - aa; - button_dim.y2 = y - aa + dimc.height(); + button_dim.y1 = y - aa + pi.base.bv->top_y(); + button_dim.y2 = y - aa + pi.base.bv->top_y() + dimc.height(); draw_collapsed(pi, x, y); if (status_ == Open) { @@ -217,15 +217,17 @@ InsetCollapsable::lfunMouseRelease(LCurs edit(cur, true); return DispatchResult(true, true); - case Open: - if (hitButton(cmd)) { + case Open: { + FuncRequest cmd1 = cmd; +// cmd1.y -= cur.bv().top_y(); + if (hitButton(cmd1)) { lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl; setStatus(Collapsed); return DispatchResult(false, FINISHED_RIGHT); } lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl; return inset.dispatch(cur, cmd); - + } case Inlined: return inset.dispatch(cur, cmd); } @@ -310,10 +312,10 @@ void InsetCollapsable::edit(LCursor & cu //we are not calling edit(x,y) because there are no coordinates in the //inset yet. I personally think it's ok. (ab) } else { - if (y <= button_dim.y2) - y = 0; - else - y += inset.ascent() - height_collapsed(); +// if (y <= yo() + inset.ascent() + button_dim.y2) +// y = yo(); +// else +// y += inset.ascent() - height_collapsed(); inset.edit(cur, x, y); } @@ -329,14 +331,16 @@ InsetCollapsable::priv_dispatch(LCursor case LFUN_MOUSE_PRESS: if (status_ == Inlined) inset.dispatch(cur, cmd); - else if (status_ == Open && cmd.y > button_dim.y2) + else if (status_ == Open + && cmd.y > button_dim.y2) inset.dispatch(cur, cmd); return DispatchResult(true, true); case LFUN_MOUSE_MOTION: if (status_ == Inlined) inset.dispatch(cur, cmd); - else if (status_ == Open && cmd.y > button_dim.y2) + else if (status_ == Open + && cmd.y > button_dim.y2) inset.dispatch(cur, cmd); return DispatchResult(true, true); Index: insets/insettext.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.C,v retrieving revision 1.574 diff -u -p -u -r1.574 insettext.C --- insets/insettext.C 6 Feb 2004 11:12:49 -0000 1.574 +++ insets/insettext.C 6 Feb 2004 12:10:47 -0000 @@ -191,6 +191,7 @@ void InsetText::metrics(MetricsInfo & mi void InsetText::draw(PainterInfo & pi, int x, int y) const { + BOOST_ASSERT(!text_.paragraphs().begin()->rows.empty()); // update our idea of where we are setPosCache(pi, x, y); @@ -209,7 +210,7 @@ void InsetText::draw(PainterInfo & pi, i text_.draw(pi, x, y); if (drawFrame_ == ALWAYS || drawFrame_ == LOCKED) - drawFrame(pi.pain, xo_); + drawFrame(pi.pain, xo_, yo_ - bv->top_y()); } @@ -219,11 +220,11 @@ void InsetText::drawSelection(PainterInf } -void InsetText::drawFrame(Painter & pain, int x) const +void InsetText::drawFrame(Painter & pain, int x, int y) const { int const ttoD2 = TEXT_TO_INSET_OFFSET / 2; int const frame_x = x + ttoD2; - int const frame_y = yo_ - dim_.asc + ttoD2; + int const frame_y = y - dim_.asc + ttoD2; int const frame_w = dim_.wid - TEXT_TO_INSET_OFFSET; int const frame_h = dim_.asc + dim_.des - TEXT_TO_INSET_OFFSET; pain.rectangle(frame_x, frame_y, frame_w, frame_h, frameColor()); @@ -281,9 +282,6 @@ void InsetText::sanitizeEmptyText(Buffer text_.setFont(font, false); } } - - -extern CursorBase theTempCursor; void InsetText::edit(LCursor & cur, bool left) Index: insets/insettext.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.h,v retrieving revision 1.245 diff -u -p -u -r1.245 insettext.h --- insets/insettext.h 6 Feb 2004 11:12:49 -0000 1.245 +++ insets/insettext.h 6 Feb 2004 12:10:48 -0000 @@ -170,7 +170,7 @@ private: /// void removeNewlines(); /// - void drawFrame(Painter &, int x) const; + void drawFrame(Painter &, int x, int y) const; /// void clearInset(Painter &, int x, int y) const;