]> git.lyx.org Git - lyx.git/commitdiff
proper cursor up/down for centered and right aligned grid columns
authorAndré Pönitz <poenitz@gmx.net>
Wed, 8 Aug 2001 09:31:36 +0000 (09:31 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Wed, 8 Aug 2001 09:31:36 +0000 (09:31 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2450 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/formula.C
src/mathed/math_cursor.C
src/mathed/math_cursor.h
src/mathed/math_gridinset.C
src/mathed/math_gridinset.h
src/mathed/math_inset.h

index 88dacdbed85c116473fd9143eb4e823102e85845..3dba3bc58466bb2a8647a6e27dceeba9171c3421 100644 (file)
@@ -172,9 +172,6 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
 
                case LFUN_BREAKLINE: 
                        bv->lockedInsetStoreUndo(Undo::INSERT);
-                       int x;
-                       int y;
-                       mathcursor->getPos(x, y);
                        mathcursor->breakLine();
                        mathcursor->normalize();
                        updateLocal(bv, true);
index b78c6a74058c871846d676a896db639eb4a09a78..6efdbdf294c24d755891d1da28b36986f5444d5c 100644 (file)
@@ -906,6 +906,9 @@ void MathCursor::handleNest(MathInset * p)
 
 void MathCursor::getPos(int & x, int & y)
 {
+#ifdef WITH_WARNINGS
+#warning This should probably take cellXOffset and cellYOffset into account
+#endif
        x = xarray().xo() + xarray().pos2x(pos());
        y = xarray().yo();
 }
@@ -1142,19 +1145,6 @@ MathXArray & MathCursor::xarray() const
 }
 
 
-int MathCursor::xpos() const 
-{
-       normalize();
-       return xarray().pos2x(pos());
-}
-
-
-void MathCursor::gotoX(int x)
-{
-       pos() = xarray().x2pos(x);      
-}
-
-
 void MathCursor::idxNext()
 {
        par()->idxNext(idx(), pos());
@@ -1305,22 +1295,53 @@ MathCursorPos MathCursor::normalAnchor() const
 }
 
 
+int MathCursor::cellXOffset() const
+{
+       return par()->cellXOffset(idx());
+}
+
+
+int MathCursor::cellYOffset() const
+{
+       return par()->cellYOffset(idx());
+}
+
+
+int MathCursor::xpos() const
+{
+       return cellXOffset() + xarray().pos2x(pos());
+}
+
+
+int MathCursor::ypos() const
+{
+       return cellYOffset();
+}
+
+
+
+void MathCursor::gotoX(int x) 
+{
+       pos() = xarray().x2pos(x - cellXOffset());
+}
+
+
 bool MathCursor::idxUp()
 {
-       int x = xarray().pos2x(pos());
+       int x = xpos();
        if (!par()->idxUp(idx(), pos()))
                return false;
-       pos() = xarray().x2pos(x);
+       gotoX(x);
        return true;
 }
 
 
 bool MathCursor::idxDown()
 {
-       int x = xarray().pos2x(pos());
+       int x = xpos();
        if (!par()->idxDown(idx(), pos()))
                return false;
-       pos() = xarray().x2pos(x);
+       gotoX(x);
        return true;
 }
 
index 6404f494279a1d34f010bb962ad42cce4cf58593..8e700b943ac916a23e4a3b05add50349f6e40852 100644 (file)
@@ -245,11 +245,6 @@ public:
        ///
        void dump(char const * str) const;
 
-       ///
-       int xpos() const;
-       ///
-       void gotoX(int x);
-
        ///
        void merge(MathArray const & arr);
        ///
@@ -265,6 +260,16 @@ private:
        int & pos();
        ///
        int & idx();
+       /// x-offset of current cell relative to par xo
+       int cellXOffset() const;
+       /// y-offset of current cell relative to par yo
+       int cellYOffset() const;
+       /// current x position relative to par xo
+       int xpos() const;
+       /// current y position relative to par yo
+       int ypos() const;
+       /// adjust position in current cell according to x. idx is not changed.
+       void gotoX(int x);
 
        ///
        InsetFormulaBase * const formula_;
index 2648283d11a26a7099f93968757380a78ecfc67f..5cb230c18ce77ba80d1ba098db818f9141346cb2 100644 (file)
@@ -193,22 +193,13 @@ void MathGridInset::metrics(MathStyles st) const
 */
 }
 
+
 void MathGridInset::draw(Painter & pain, int x, int y) const
 {
        xo(x);
        yo(y);
-       for (int row = 0; row < nrows(); ++row) {
-               int yy = y + rowinfo_[row].offset_;
-               for (int col = 0; col < ncols(); ++col) {
-                       int xx = x + colinfo_[col].offset_;
-                       char align = colinfo_[col].h_align_;
-                       if (align == 'r' || align == 'R')
-                               xx += colinfo_[col].width_ - xcell(index(row, col)).width(); 
-                       if (align == 'c' || align == 'C')
-                               xx += (colinfo_[col].width_ - xcell(index(row, col)).width()) / 2; 
-                       xcell(index(row, col)).draw(pain, xx, yy);
-               }
-       }
+       for (int idx = 0; idx < nargs(); ++idx)
+               xcell(idx).draw(pain, x + cellXOffset(idx), y + cellYOffset(idx));
 }
 
 
@@ -283,6 +274,24 @@ void MathGridInset::delCol(int col)
 }
 
 
+int MathGridInset::cellXOffset(int idx) const
+{
+       int c = col(idx);
+       int x = colinfo_[c].offset_;
+       char align = colinfo_[c].h_align_;
+       if (align == 'r' || align == 'R')
+               x += colinfo_[c].width_ - xcell(idx).width(); 
+       if (align == 'c' || align == 'C')
+               x += (colinfo_[c].width_ - xcell(idx).width()) / 2; 
+       return x;
+}
+
+
+int MathGridInset::cellYOffset(int idx) const
+{
+       return rowinfo_[row(idx)].offset_;
+}
+
 bool MathGridInset::idxUp(int & idx, int & pos) const
 {
        if (idx < ncols())
index b3a7e9c522c567bdc7c0f099a0f3e71cfce47cbc..1b4e4ca2697da803489f9b9801553761682dee49 100644 (file)
@@ -86,6 +86,10 @@ public:
        int col(int idx) const { return idx % ncols(); }
        ///
        int row(int idx) const { return idx / ncols(); }
+       ///
+       int cellXOffset(int idx) const;
+       ///
+       int cellYOffset(int idx) const;
 
        ///
        bool idxUp(int &, int &) const;
index c2475b1d142fc6ee6d3b6c710fc26a4bf9e26394..6ff7f6c33884651f667e69c22b56b65f7331bf4a 100644 (file)
@@ -150,6 +150,10 @@ public:
        ///
        virtual int row(int) const { return 0; }
        ///
+       virtual int cellXOffset(int) const { return 0; }
+       ///
+       virtual int cellYOffset(int) const { return 0; }
+       ///
        virtual void addRow(int) {}
        ///
        virtual void delRow(int) {}