]> git.lyx.org Git - lyx.git/commitdiff
make boundary property an iterator property instead of a CursorSlice property
authorAndré Pönitz <poenitz@gmx.net>
Fri, 15 Jul 2005 15:49:40 +0000 (15:49 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 15 Jul 2005 15:49:40 +0000 (15:49 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10214 a592a061-630c-0410-9148-cb99ea01b6c8

24 files changed:
src/BufferView_pimpl.C
src/bufferview_funcs.C
src/bufferview_funcs.h
src/cursor.C
src/cursor.h
src/cursor_slice.C
src/cursor_slice.h
src/dociterator.h
src/insets/insetbase.C
src/insets/insetbase.h
src/insets/insetcollapsable.C
src/insets/insetcollapsable.h
src/insets/insettabular.C
src/insets/insettabular.h
src/insets/insettext.C
src/insets/insettext.h
src/lyxtext.h
src/mathed/math_mboxinset.C
src/mathed/math_mboxinset.h
src/mathed/math_nestinset.C
src/mathed/math_nestinset.h
src/text.C
src/text2.C
src/text3.C

index d497313e496e2cf09d8af7fee086a8667d75b88e..1c52d6e331492a1cd2398a980ab57fe763a184ee 100644 (file)
@@ -476,7 +476,7 @@ void BufferView::Pimpl::scrollDocView(int value)
                cur.clearSelection();
                break;
        case bv_funcs::CUR_INSIDE:
-               int const y = bv_funcs::getPos(cur).y_;
+               int const y = bv_funcs::getPos(cur, cur.boundary()).y_;
                int const newy = min(last, max(y, first));
                if (y != newy) {
                        cur.reset(buffer_->inset());
@@ -596,7 +596,7 @@ bool BufferView::Pimpl::fitCursor()
                LyXFont const font = cursor_.getFont();
                int const asc = font_metrics::maxAscent(font);
                int const des = font_metrics::maxDescent(font);
-               Point const p = bv_funcs::getPos(cursor_);
+               Point const p = bv_funcs::getPos(cursor_, cursor_.boundary());
                if (p.y_ - asc >= 0 && p.y_ + des < workarea().workHeight())
                        return false;
        }
@@ -766,8 +766,8 @@ void BufferView::Pimpl::center()
        bot.text()->redoParagraph(pit);
        Paragraph const & par = bot.text()->paragraphs()[pit];
        anchor_ref_ = pit;
-       offset_ref_ = bv_funcs::coordOffset(cursor_).y_ + par.ascent()
-               - workarea().workHeight() / 2;
+       offset_ref_ = bv_funcs::coordOffset(cursor_, cursor_.boundary()).y_
+               + par.ascent() - workarea().workHeight() / 2;
 }
 
 
index d550b7318475f933026e6a31f2a9dba414a5bf1e..fe13bf616012c11190fddfa14a6a3af2cb01168c 100644 (file)
@@ -152,7 +152,7 @@ bool string2font(string const & data, LyXFont & font, bool & toggle)
 // the next two should probably go elsewhere
 // this give the position relative to (0, baseline) of outermost
 // paragraph
-Point coordOffset(DocIterator const & dit)
+Point coordOffset(DocIterator const & dit, bool boundary)
 {
        int x = 0;
        int y = 0;
@@ -162,37 +162,41 @@ Point coordOffset(DocIterator const & dit)
                CursorSlice const & sl = dit[i];
                int xx = 0;
                int yy = 0;
-               sl.inset().getCursorPos(sl, xx, yy);
+               sl.inset().cursorPos(sl, boundary, xx, yy);
                x += xx;
                y += yy;
-               //lyxerr << "LCursor::getPos, i: " << i << " x: " << xx << " y: " << y << endl;
+               //lyxerr << "LCursor::getPos, i: "
+               // << i << " x: " << xx << " y: " << y << endl;
        }
 
        // Add contribution of initial rows of outermost paragraph
        CursorSlice const & sl = dit[0];
        Paragraph const & par = sl.text()->getPar(sl.pit());
        y -= par.rows()[0].ascent();
-       for (size_t rit = 0, rend = par.pos2row(sl.pos()); rit != rend; ++rit)
+       //size_t rend = par.pos2row(sl.pos() - boundary ? 1 : 0);
+       size_t rend = par.pos2row(sl.pos());
+       for (size_t rit = 0; rit != rend; ++rit)
                y += par.rows()[rit].height();
-       y += par.rows()[par.pos2row(sl.pos())].ascent();
-       x += dit.bottom().text()->cursorX(dit.bottom());
+       y += par.rows()[rend].ascent();
+       x += dit.bottom().text()->cursorX(dit.bottom(), boundary);
        // The following correction should not be there at all.
-       // The cusor looks much better with the -1, though.
+       // The cursor looks much better with the -1, though.
        --x;
        return Point(x, y);
 }
 
 
-Point getPos(DocIterator const & dit)
+Point getPos(DocIterator const & dit, bool boundary)
 {
        CursorSlice const & bot = dit.bottom();
-       CoordCache::InnerParPosCache const & cache = theCoords.getParPos().find(bot.text())->second;
+       CoordCache::InnerParPosCache const & cache =
+               theCoords.getParPos().find(bot.text())->second;
        CoordCache::InnerParPosCache::const_iterator it = cache.find(bot.pit());
        if (it == cache.end()) {
                //lyxerr << "cursor out of view" << std::endl;
                return Point(-1, -1);
        }
-       Point p = coordOffset(dit); // offset from outer paragraph
+       Point p = coordOffset(dit, boundary); // offset from outer paragraph
        p.y_ += it->second.y_;
        return p;
 }
index 291119a1ea340ba59ca3cb3068f50e25ae75b03f..7cd3f17be40ded3a19be51a69cfef23832f479c8 100644 (file)
 #include <string>
 #include <vector>
 
-class LyXFont;
-class Point;
-class DocIterator;
 class BufferView;
+class DocIterator;
 class InsetBase_code;
+class LyXFont;
+class Point;
 
 
 namespace bv_funcs {
@@ -37,7 +37,7 @@ bool string2font(std::string const & data, LyXFont & font, bool & toggle);
  */
 std::string const freefont2string();
 
-Point getPos(DocIterator const & dit);
+Point getPos(DocIterator const & dit, bool boundary);
 
 enum CurStatus {
        CUR_INSIDE,
@@ -49,7 +49,7 @@ enum CurStatus {
 CurStatus status(BufferView const * bv, DocIterator const & dit);
 
 
-Point coordOffset(DocIterator const & dit);
+Point coordOffset(DocIterator const & dit, bool boundary);
 
 /// Moves cursor to the next inset with one of the given codes.
 void gotoInset(BufferView * bv, std::vector<InsetBase_code> const & codes,
index 8e2a117d0108a3ba690799458761b01967fe3482..e72426f64753af016508c789645b98736ca49466 100644 (file)
@@ -97,9 +97,7 @@ namespace {
                for (int i = 0; ; ++i) {
                        int xo;
                        int yo;
-                       LCursor cur = c;
-                       cur.setCursor(it);
-                       cur.inset().getCursorPos(cur.top(), xo, yo);
+                       it.inset().cursorPos(it.top(), c.boundary(), 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'
@@ -134,7 +132,7 @@ namespace {
                        // avoid invalid nesting when selecting
                        if (bv_funcs::status(&cursor.bv(), it) == bv_funcs::CUR_INSIDE
                            && (!cursor.selection() || positionable(it, cursor.anchor_))) {
-                               Point p = bv_funcs::getPos(it);
+                               Point p = bv_funcs::getPos(it, false);
                                int xo = p.x_;
                                int yo = p.y_;
                                if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
@@ -167,7 +165,7 @@ namespace {
 // bv functions are not yet available!
 LCursor::LCursor(BufferView & bv)
        : DocIterator(), bv_(&bv), anchor_(), x_target_(-1),
-         selection_(false), mark_(false)
+         selection_(false), mark_(false), logicalpos_(false)
 {}
 
 
@@ -309,7 +307,7 @@ int LCursor::currentMode()
 
 void LCursor::getPos(int & x, int & y) const
 {
-       Point p = bv_funcs::getPos(*this);
+       Point p = bv_funcs::getPos(*this, boundary());
        x = p.x_;
        y = p.y_;
 }
index 773513a16192c9e8abe466e7b5c3d18ab49aaaa8..817cdd481714f67ff6cac4767163136a8b5aeac4 100644 (file)
@@ -206,6 +206,11 @@ private:
        bool selection_;
        /// are we on the way to get one?
        bool mark_;
+       /// If true, we are behind the previous char, otherwise we are in front
+       // of the next char. This only make a difference when we are in front
+       // of a big inset spanning a whole row and computing coordinates for
+       // displaying the cursor.
+       bool logicalpos_;
 
 private:
 
index b98aed8f25df35b131230be3f8201f9974426286..f4a59dfb80da84c6f3747c05fb647c7d6f2f24f9 100644 (file)
@@ -30,12 +30,12 @@ using std::endl;
 
 
 CursorSlice::CursorSlice()
-       : inset_(0), idx_(0), pit_(0), pos_(0), boundary_(false)
+       : inset_(0), idx_(0), pit_(0), pos_(0)
 {}
 
 
 CursorSlice::CursorSlice(InsetBase & p)
-       : inset_(&p), idx_(0), pit_(0), pos_(0), boundary_(false)
+       : inset_(&p), idx_(0), pit_(0), pos_(0)
 {
        BOOST_ASSERT(inset_);
 }
index 6d3508ef34f37d4194113a23912ecdb97acede16..304dceb901e0e821e36fb9c5290ab11c901c7ad3 100644 (file)
@@ -104,10 +104,6 @@ public:
        ///
        /// texted specific stuff
        ///
-       /// \sa boundary_
-       bool boundary() const { return boundary_; }
-       /// \sa boundary_
-       bool & boundary() { return boundary_; }
        /// returns text corresponding to this position
        LyXText * text();
        /// returns text corresponding to this position
@@ -156,22 +152,6 @@ private:
        bool pit_valid_;
        /// position in this cell
        pos_type pos_;
-       /**
-        * When the cursor position is i, is the cursor after the i-th char
-        * or before the i+1-th char ? Normally, these two interpretations are
-        * equivalent, except when the fonts of the i-th and i+1-th char
-        * differ.
-        * We use boundary_ to distinguish between the two options:
-        * If boundary_=true, then the cursor is after the i-th char
-        * and if boundary_=false, then the cursor is before the i+1-th char.
-        *
-        * We currently use the boundary only when the language direction of
-        * the i-th char is different than the one of the i+1-th char.
-        * In this case it is important to distinguish between the two
-        * cursor interpretations, in order to give a reasonable behavior to
-        * the user.
-        */
-       bool boundary_;
 };
 
 /// test for equality
index 393af2791e97a8f3cc3e3980cc3b290ff7c10716..5b410ae9a7c10f0596111a2c5435ddd566bf5370 100644 (file)
@@ -55,16 +55,10 @@ public:
        explicit DocIterator(InsetBase & inset);
 
        /// access slice at position \p i
-       CursorSlice const & operator[](size_t i) const {
-               return slices_[i];
-       }
-
+       CursorSlice const & operator[](size_t i) const { return slices_[i]; }
        /// access slice at position \p i
-       CursorSlice & operator[](size_t i) {
-               return slices_[i];
-       }
-
-       // What is the point of this function?
+       CursorSlice & operator[](size_t i) { return slices_[i]; }
+       /// chop a few slices from the iterator
        void resize(size_t i) { slices_.resize(i); }
 
        /// is the iterator valid?
@@ -129,6 +123,10 @@ public:
        InsetBase * prevInset();
        /// the inset just in front of the cursor
        InsetBase const * prevInset() const;
+       ///
+       bool boundary() const { return boundary_; }
+       ///
+       void boundary(bool b) { boundary_ = b; }
 
        /// are we in mathed?
        bool inMathed() const;
@@ -154,10 +152,6 @@ public:
        //
        // text-specific part
        //
-       /// \sa boundary_
-       bool boundary() const { return top().boundary(); }
-       /// \sa boundary_
-       bool & boundary() { return top().boundary(); }
        /// the paragraph we're in
        Paragraph & paragraph();
        /// the paragraph we're in
@@ -209,21 +203,41 @@ public:
        /// output
        friend std::ostream &
        operator<<(std::ostream & os, DocIterator const & cur);
+       ///
        friend bool operator==(DocIterator const &, DocIterator const &);
+       ///
        friend class StableDocIterator;
 protected:
+       ///
        void clear() { slices_.clear(); }
-       void push_back(CursorSlice const & sl) {
-               slices_.push_back(sl);
-       }
-       void pop_back() {
-               slices_.pop_back();
-       }
+       ///
+       void push_back(CursorSlice const & sl) { slices_.push_back(sl); }
+       ///
+       void pop_back() { slices_.pop_back(); }
 private:
+       /**
+        * When the cursor position is i, is the cursor after the i-th char
+        * or before the i+1-th char ? Normally, these two interpretations are
+        * equivalent, except when the fonts of the i-th and i+1-th char
+        * differ.
+        * We use boundary_ to distinguish between the two options:
+        * If boundary_=true, then the cursor is after the i-th char
+        * and if boundary_=false, then the cursor is before the i+1-th char.
+        *
+        * We currently use the boundary only when the language direction of
+        * the i-th char is different than the one of the i+1-th char.
+        * In this case it is important to distinguish between the two
+        * cursor interpretations, in order to give a reasonable behavior to
+        * the user.
+        */
+       bool boundary_;
+       ///
        std::vector<CursorSlice> const & internalData() const {
                return slices_;
        }
+       ///
        std::vector<CursorSlice> slices_;
+       ///
        InsetBase * inset_;
 };
 
index c97ec15af5707409ca5f85bbf5e8d0a2baccae5c..d775917a5e82959c534b402581cd9ca157def805 100644 (file)
@@ -261,9 +261,9 @@ void InsetBase::markErased()
 {}
 
 
-void InsetBase::getCursorPos(CursorSlice const &, int & x, int & y) const
+void InsetBase::cursorPos(CursorSlice const &, bool, int & x, int & y) const
 {
-       lyxerr << "InsetBase::getCursorPos called directly" << std::endl;
+       lyxerr << "InsetBase::cursorPos called directly" << std::endl;
        x = 100;
        y = 100;
 }
index 8ea769041005b7022961de3e8b92015e1d0043fa..b14fbd60d0ebc0ecca747c6b3afc8d3b99b710c6 100644 (file)
@@ -133,7 +133,8 @@ public:
        /// do we cover screen position x/y?
        virtual bool covers(int x, int y) const;
        /// get the screen positions of the cursor (see note in cursor.C)
-       virtual void getCursorPos(CursorSlice const & sl, int & x, int & y) const;
+       virtual void cursorPos(CursorSlice const & sl, bool boundary,
+               int & x, int & y) const;
 
        /// is this an inset that can be moved into?
        virtual bool isActive() const { return nargs() > 0; }
index acfb6d28f80ec7ce0af22c9f96d0d774db3c3c60..7967caec2a6cd84abd2bc6631ec5c5c4ceee15a1 100644 (file)
@@ -192,24 +192,23 @@ void InsetCollapsable::drawSelection(PainterInfo & pi, int x, int y) const
 }
 
 
-void InsetCollapsable::getCursorPos
-       (CursorSlice const & sl, int & x, int & y) const
+void InsetCollapsable::cursorPos
+       (CursorSlice const & sl, bool boundary, int & x, int & y) const
 {
        if (status_ == Collapsed) {
                x = xo();
                y = yo();
-               return;
-       }
-
-       InsetText::getCursorPos(sl, x, y);
-       if (status_ == Open) {
-               if (openinlined_)
-                       x += dimensionCollapsed().wid;
-               else
-                       y += dimensionCollapsed().height() - ascent() + TEXT_TO_INSET_OFFSET + textdim_.asc;
+       } else {
+               InsetText::cursorPos(sl, boundary, x, y);
+               if (status_ == Open) {
+                       if (openinlined_)
+                               x += dimensionCollapsed().wid;
+                       else
+                               y += dimensionCollapsed().height() - ascent()
+                                       + TEXT_TO_INSET_OFFSET + textdim_.asc;
+               }
+               x += TEXT_TO_INSET_OFFSET;
        }
-
-       x += TEXT_TO_INSET_OFFSET;
 }
 
 
@@ -239,7 +238,7 @@ string const InsetCollapsable::getNewLabel(string const & l) const
        pos_type const n = min(max_length, p_siz);
        pos_type i = 0;
        pos_type j = 0;
-       for; i < n && j < p_siz; ++j) {
+       for (; i < n && j < p_siz; ++j) {
                if (paragraphs().begin()->isInset(j))
                        continue;
                label += paragraphs().begin()->getChar(j);
index 3024c486f98f52e137569138bfe767214009db18..ee90a458c26b49418eecb51b39872393a091841b 100644 (file)
@@ -47,7 +47,7 @@ public:
        ///
        void drawSelection(PainterInfo & pi, int x, int y) const;
        /// return x,y of given position relative to the inset's baseline
-       void getCursorPos(CursorSlice const & sl, int & x, int & y) const;
+       void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const;
        ///
        bool hitButton(FuncRequest const &) const;
        ///
index 36ea3c0ccc7cf958b6510f60d530ff8b029710b2..a33a336fb337bfd36a9acd78017394759e98c133 100644 (file)
@@ -1084,9 +1084,10 @@ shared_ptr<InsetText> InsetTabular::cell(idx_type idx)
 }
 
 
-void InsetTabular::getCursorPos(CursorSlice const & sl, int & x, int & y) const
+void InsetTabular::cursorPos
+       (CursorSlice const & sl, bool boundary, int & x, int & y) const
 {
-       cell(sl.idx())->getCursorPos(sl, x, y);
+       cell(sl.idx())->cursorPos(sl, boundary, x, y);
 
        // y offset     correction
        int const row = tabular.row_of_cell(sl.idx());
index 206f573f5dbea6dee236695794d1c222fc9d149a..53f974eec9fe98e1ec654a745a53a4a8d0f685b0 100644 (file)
@@ -91,7 +91,7 @@ public:
        ///
        Code lyxCode() const { return InsetBase::TABULAR_CODE; }
        /// get offset of this cursor slice relative to our upper left corner
-       void getCursorPos(CursorSlice const & sl, int & x, int & y) const;
+       void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const;
        ///
        bool tabularFeatures(LCursor & cur, std::string const & what);
        ///
index 0c17b80920b3bef387c6ef373835014fc1407390..c01fc8cad1eacd79ffaafd00b5247bc22bc896b5 100644 (file)
@@ -364,10 +364,11 @@ void InsetText::validate(LaTeXFeatures & features) const
 }
 
 
-void InsetText::getCursorPos(CursorSlice const & sl, int & x, int & y) const
+void InsetText::cursorPos
+       (CursorSlice const & sl, bool boundary, int & x, int & y) const
 {
-       x = text_.cursorX(sl) + border_;
-       y = text_.cursorY(sl);
+       x = text_.cursorX(sl, boundary) + border_;
+       y = text_.cursorY(sl, boundary);
 }
 
 
index ed387ff0f25d4f5f81f85b38d154008a001bfee7..c243b34809494a235b94b7acb1c7195f14ba4f71 100644 (file)
@@ -74,7 +74,7 @@ public:
        void validate(LaTeXFeatures & features) const;
 
        /// return x,y of given position relative to the inset's baseline
-       void getCursorPos(CursorSlice const & sl, int & x, int & y) const;
+       void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const;
        ///
        Code lyxCode() const { return TEXT_CODE; }
        ///
index 882f340571c7cc1d2e08d6c76ccf265034c92ef7..504366885db4df7b156e6f3dc7fde2815052aa9f 100644 (file)
@@ -322,9 +322,9 @@ public:
        ///
        int descent() const;
        ///
-       int cursorX(CursorSlice const & cursor) const;
+       int cursorX(CursorSlice const & cursor, bool boundary) const;
        ///
-       int cursorY(CursorSlice const & cursor) const;
+       int cursorY(CursorSlice const & cursor, bool boundary) const;
 
        ///
        friend class LyXScreen;
index 9fcce755dd7600eb3cc90ba8ff3d21ef5365e2d8..bd3c93b54c21554986b5b7ef089e282034cc6282 100644 (file)
@@ -102,10 +102,11 @@ LyXText * MathMBoxInset::getText(int) const
 }
 
 
-void MathMBoxInset::getCursorPos(CursorSlice const & sl, int & x, int & y) const
+void MathMBoxInset::cursorPos
+       (CursorSlice const & sl, bool boundary, int & x, int & y) const
 {
-       x = text_.cursorX(sl);
-       y = text_.cursorY(sl);
+       x = text_.cursorX(sl, boundary);
+       y = text_.cursorY(sl, boundary);
 }
 
 
index cf0a58873debb064b62af51c3b0cc2446e05a7da..59f13be5067a324c6f9d1a8e928088b45e98c6e7 100644 (file)
@@ -41,7 +41,7 @@ public:
        ///
        LyXText * getText(int) const;
        ///
-       void getCursorPos(CursorSlice const & sl, int & x, int & y) const;
+       void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const;
 protected:
        virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
 
index 5f83787f054781e42a0c2f2cb50d6f94ed5f9b9b..0253af32b08370108c80d2793efbcbb2bd71c7b6 100644 (file)
@@ -88,7 +88,7 @@ MathArray const & MathNestInset::cell(idx_type i) const
 }
 
 
-void MathNestInset::getCursorPos(CursorSlice const & sl,
+void MathNestInset::cursorPos(CursorSlice const & sl, bool boundary,
        int & x, int & y) const
 {
 // FIXME: This is a hack. Ideally, the coord cache should not store
index 46b6abe332971ce5ea0c970c7790505a6d67c847..72bdcd453664dc5d289816e9ef67a0b8e44ba84e 100644 (file)
@@ -37,7 +37,7 @@ public:
        /// identifies NestInsets
        MathNestInset const * asNestInset() const { return this; }
        /// get cursor position
-       void getCursorPos(CursorSlice const & sl, int & x, int & y) const;
+       void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const;
        ///
        void edit(LCursor & cur, bool left);
        ///
index 61c3dd8500373b5fd8bbdccfca1d8d3033e9677e..d322ec48ba714b5a9642a44deb91e96406874287 100644 (file)
@@ -1010,7 +1010,7 @@ void LyXText::setHeightOfRow(pit_type const pit, Row & row)
        if (bv_owner->text() == this) {
                if (pit == 0 && row.pos() == 0)
                        maxasc += 20;
-               if (pit == pars_.size() - 1 && row.endpos() == par.size())
+               if (pit + 1 == pars_.size() && row.endpos() == par.size())
                        maxdesc += 20;
        }
 
@@ -1193,7 +1193,8 @@ void LyXText::insertChar(LCursor & cur, char c)
 
        current_font = rawtmpfont;
        real_current_font = realtmpfont;
-       setCursor(cur, cur.pit(), cur.pos() + 1, false, cur.boundary());
+       //setCursor(cur, cur.pit(), cur.pos() + 1, false, cur.boundary());
+       setCursor(cur, cur.pit(), cur.pos() + 1, false, true);
        charInserted();
 }
 
@@ -1793,7 +1794,7 @@ void LyXText::drawSelection(PainterInfo & pi, int x , int) const
                x2 = 0;
        } else {
                y1 = bv_funcs::getPos(beg).y_ - row1.ascent();
-               int const startx = cursorX(beg.top());
+               int const startx = cursorX(beg.top(), begin.boundary());
                x1 = isRTL(par1) ? startx : 0;
                x2 = isRTL(par1) ? 0 + dim_.wid : startx;
        }
@@ -1805,7 +1806,7 @@ void LyXText::drawSelection(PainterInfo & pi, int x , int) const
                X2 = 0;
        } else {
                y2 = bv_funcs::getPos(end).y_ + row2.descent();
-               int const endx = cursorX(end.top());
+               int const endx = cursorX(end.top(), end.boundary());
                X1 = isRTL(par2) ? 0 : endx;
                X2 = isRTL(par2) ? endx : 0 + dim_.wid;
        }
@@ -1868,9 +1869,9 @@ void LyXText::drawSelection(PainterInfo & pi, int x, int) const
                x2 = dim_.wid;
        } else {
                Row const & row1 = par1.getRow(beg.pos());
-               y1 = bv_funcs::getPos(beg).y_ - row1.ascent();
+               y1 = bv_funcs::getPos(beg, beg.boundary()).y_ - row1.ascent();
                y2 = y1 + row1.height();
-               int const startx = cursorX(beg.top());
+               int const startx = cursorX(beg.top(), beg.boundary());
                x1 = !isRTL(par1) ? startx : 0;
                x2 = !isRTL(par1) ? 0 + dim_.wid : startx;
        }
@@ -1883,9 +1884,9 @@ void LyXText::drawSelection(PainterInfo & pi, int x, int) const
                X2 = dim_.wid;
        } else {
                Row const & row2 = par2.getRow(end.pos());
-               Y1 = bv_funcs::getPos(end).y_ - row2.ascent();
+               Y1 = bv_funcs::getPos(end, end.boundary()).y_ - row2.ascent();
                Y2 = Y1 + row2.height();
-               int const endx = cursorX(end.top());
+               int const endx = cursorX(end.top(), end.boundary());
                X1 = !isRTL(par2) ? 0 : endx;
                X2 = !isRTL(par2) ? endx : 0 + dim_.wid;
        }
@@ -1910,6 +1911,7 @@ void LyXText::drawSelection(PainterInfo & pi, int x, int) const
                              Y1 - y2, LColor::selection);
 }
 
+
 bool LyXText::isLastRow(pit_type pit, Row const & row) const
 {
        return row.endpos() >= pars_[pit].size()
@@ -2045,16 +2047,20 @@ int LyXText::descent() const
 }
 
 
-int LyXText::cursorX(CursorSlice const & cur) const
+int LyXText::cursorX(CursorSlice const & sl, bool boundary) const
 {
-       pit_type const pit = cur.pit();
+       pit_type const pit = sl.pit();
        Paragraph const & par = pars_[pit];
        if (par.rows().empty())
                return 0;
 
-       Row const & row = par.getRow(cur.pos());
+       pos_type pos = sl.pos();
+       //// Correct position in front of big insets
+       //if (pos && boundary)
+       //      --pos;
+
+       Row const & row = par.getRow(pos);
 
-       pos_type pos = cur.pos();
        pos_type cursor_vpos = 0;
 
        RowMetrics const m = computeRowMetrics(pit, row);
@@ -2104,20 +2110,28 @@ int LyXText::cursorX(CursorSlice const & cur) const
                } else
                        x += singleWidth(par, pos);
        }
+       
+       // see correction above
+       //if (pos && boundary)
+       //      x += singleWidth(par, pos + 1);
+
        return int(x);
 }
 
 
-int LyXText::cursorY(CursorSlice const & cur) const
+int LyXText::cursorY(CursorSlice const & sl, bool boundary) const
 {
-       Paragraph const & par = getPar(cur.pit());
+       //lyxerr << "LyXText::cursorY: boundary: " << boundary << std::endl;
+       Paragraph const & par = getPar(sl.pit());
        int h = 0;
        h -= pars_[0].rows()[0].ascent();
-       for (pit_type pit = 0; pit < cur.pit(); ++pit)
+       for (pit_type pit = 0; pit < sl.pit(); ++pit)
                h += pars_[pit].height();
-       for (size_t rit = 0, rend = par.pos2row(cur.pos()); rit != rend; ++rit)
+       //size_t const rend = par.pos2row(sl.pos() - boundary ? 1 : 0);
+       size_t const rend = par.pos2row(sl.pos());
+       for (size_t rit = 0; rit != rend; ++rit)
                h += par.rows()[rit].height();
-       h += par.rows()[par.pos2row(cur.pos())].ascent();
+       h += par.rows()[rend].ascent();
        return h;
 }
 
@@ -2254,7 +2268,7 @@ string LyXText::getPossibleLabel(LCursor & cur) const
 
 pos_type LyXText::x2pos(pit_type pit, int row, int x) const
 {
-       BOOST_ASSERT(row < pars_[pit].rows().size());
+       BOOST_ASSERT(row < int(pars_[pit].rows().size()));
        bool bound = false;
        Row const & r = pars_[pit].rows()[row];
        return r.pos() + getColumnNearX(pit, r, x, bound);
index 75d4f4f8756b24e73832e406abd461031b9be211..8408af2041399e6a2c1a960f7d155e02b4261535 100644 (file)
@@ -660,6 +660,7 @@ bool LyXText::setCursor(LCursor & cur, pit_type par, pos_type pos,
 {
        LCursor old = cur;
        setCursorIntern(cur, par, pos, setfont, boundary);
+       cur.boundary(boundary);
        return deleteEmptyParagraphMechanism(cur, old);
 }
 
@@ -670,7 +671,6 @@ void LyXText::setCursor(CursorSlice & cur, pit_type par,
        BOOST_ASSERT(par != int(paragraphs().size()));
        cur.pit() = par;
        cur.pos() = pos;
-       cur.boundary() = boundary;
 
        // now some strict checking
        Paragraph & para = getPar(par);
@@ -928,7 +928,7 @@ InsetBase * LyXText::editXY(LCursor & cur, int x, int y)
        pos_type const pos = row.pos() + getColumnNearX(pit, row, xx, bound);
        cur.pit() = pit;
        cur.pos() = pos;
-       cur.boundary() = bound;
+       cur.boundary(bound);
        cur.x_target() = x;
 
        // try to descend into nested insets
@@ -1022,7 +1022,7 @@ bool LyXText::cursorUp(LCursor & cur)
        int const x = cur.targetX();
 
        if (!cur.selection()) {
-               int const y = bv_funcs::getPos(cur).y_;
+               int const y = bv_funcs::getPos(cur, cur.boundary()).y_;
                LCursor old = cur;
                editXY(cur, x, y - par.rows()[row].ascent() - 1);
 
@@ -1061,7 +1061,7 @@ bool LyXText::cursorDown(LCursor & cur)
        int const x = cur.targetX();
 
        if (!cur.selection()) {
-               int const y = bv_funcs::getPos(cur).y_;
+               int const y = bv_funcs::getPos(cur, cur.boundary()).y_;
                LCursor old = cur;
                editXY(cur, x, y + par.rows()[row].descent() + 1);
 
index 35fc074caf94ed8bd045b2357b98e63c9d54204f..475712a46bb977fc0bf7b9ca9bcfd12386619d17 100644 (file)
@@ -406,8 +406,8 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
 
        case LFUN_RIGHT:
        case LFUN_RIGHTSEL:
-               lyxerr << BOOST_CURRENT_FUNCTION
-                      << " LFUN_RIGHT[SEL]:\n" << cur << endl;
+               //lyxerr << BOOST_CURRENT_FUNCTION
+               //       << " LFUN_RIGHT[SEL]:\n" << cur << endl;
                cur.selHandle(cmd.action == LFUN_RIGHTSEL);
                if (isRTL(cur.paragraph()))
                        needsUpdate = cursorLeft(cur);
@@ -819,8 +819,8 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                break;
 
        case LFUN_GETXY:
-               cur.message(convert<string>(cursorX(cur.top())) + ' '
-                         + convert<string>(cursorY(cur.top())));
+               cur.message(convert<string>(cursorX(cur.top(), cur.boundary())) + ' '
+                         + convert<string>(cursorY(cur.top(), cur.boundary())));
                break;
 
        case LFUN_SETXY: {