]> git.lyx.org Git - lyx.git/commitdiff
everything is an inset. sizeof(MathInset) == 36 on IA32
authorAndré Pönitz <poenitz@gmx.net>
Fri, 3 Aug 2001 17:10:22 +0000 (17:10 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 3 Aug 2001 17:10:22 +0000 (17:10 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2413 a592a061-630c-0410-9148-cb99ea01b6c8

34 files changed:
src/mathed/BUGS
src/mathed/Makefile.am
src/mathed/array.C
src/mathed/array.h
src/mathed/math_cursor.C
src/mathed/math_cursor.h
src/mathed/math_decorationinset.C
src/mathed/math_decorationinset.h
src/mathed/math_deliminset.C
src/mathed/math_deliminset.h
src/mathed/math_fracinset.C
src/mathed/math_fracinset.h
src/mathed/math_funcinset.C
src/mathed/math_gridinset.C
src/mathed/math_gridinset.h
src/mathed/math_inset.C
src/mathed/math_inset.h
src/mathed/math_macro.C
src/mathed/math_macro.h
src/mathed/math_macrotemplate.C
src/mathed/math_macrotemplate.h
src/mathed/math_matrixinset.C
src/mathed/math_nestinset.C [new file with mode: 0644]
src/mathed/math_nestinset.h [new file with mode: 0644]
src/mathed/math_parser.C
src/mathed/math_rootinset.C
src/mathed/math_rootinset.h
src/mathed/math_scriptinset.C
src/mathed/math_scriptinset.h
src/mathed/math_sizeinset.C
src/mathed/math_sizeinset.h
src/mathed/math_sqrtinset.C
src/mathed/math_sqrtinset.h
src/mathed/xarray.C

index 419221a85909f2f0c56640df58b59849b2c1cab9..c19a7f63d6338d93faf96cda65137a5fe9a76aae 100644 (file)
@@ -105,6 +105,8 @@ Misc:
 - Just moving the cursor in a math inset causes changing the buffer status
   to (changed).
 
+- disable the insert->label menu item when in inline formula.
+
 
 Eran Tromer:
 
@@ -157,6 +159,12 @@ Rainer Dorsch:
 - Entering \mathbf{c} in math mode is displayed as written (without
   backslash)
 
+- I know the latex code of a lot of math symbols displayed by lyx,
+  but not all of them. Thus I have to use the math panel for only a single
+  symbol in a formula. I think it would be very useful, if the latex code
+  of the symbol would be displayed as a hint, if the mouse positioned over
+  it.
+
 
 Marcus (Suran@gmx.net) 
 
index 05126bf7c07a6c389e007c2edfd72f3808c057b0..827b50c3c8c0860b46b11317d349eb1d3eb15bf8 100644 (file)
@@ -20,6 +20,8 @@ libmathed_la_SOURCES = \
        formulamacro.h \
        math_arrayinset.C \
        math_arrayinset.h \
+       math_charinset.C \
+       math_charinset.h \
        math_cursor.C \
        math_cursor.h \
        math_decorationinset.C \
@@ -48,6 +50,8 @@ libmathed_la_SOURCES = \
        math_macrotable.h \
        math_matrixinset.C \
        math_matrixinset.h \
+       math_nestinset.C \
+       math_nestinset.h \
        math_parser.C \
        math_parser.h \
        math_rootinset.C \
index 47e6d32ccbd6c5311533c05602e53e5e0b8511c6..9ba5cb6af162a722bfea7be064363a8bb6608d35 100644 (file)
@@ -1,13 +1,12 @@
-
 #ifdef __GNUG__
 #pragma implementation
 #endif
 
 #include "math_inset.h"
+#include "math_charinset.h"
 #include "debug.h"
 #include "array.h"
 #include "math_scriptinset.h"
-#include "math_parser.h"
 #include "mathed/support.h"
 
 using std::ostream;
@@ -39,11 +38,8 @@ MathArray::MathArray(MathArray const & array, int from, int to)
 
 void MathArray::deep_copy(int pos1, int pos2)
 {
-       for (int pos = pos1; pos < pos2; next(pos)) 
-               if (isInset(pos)) {
-                       MathInset * p = nextInset(pos)->clone();
-                       memcpy(&bf_[pos + 1], &p, sizeof(p));
-               }
+       for (int pos = pos1; pos < pos2; ++pos) 
+               bf_[pos] = bf_[pos]->clone();
 }
 
 
@@ -52,7 +48,7 @@ bool MathArray::next(int & pos) const
        if (pos >= size() - 1)
                return false;
 
-       pos += item_size(pos);
+       ++pos;
        return true;
 }
 
@@ -62,7 +58,7 @@ bool MathArray::prev(int & pos) const
        if (pos == 0)
                return false;
 
-       pos -= item_size(pos - 1);
+       --pos;
        return true;
 }
 
@@ -74,21 +70,11 @@ bool MathArray::last(int & pos) const
 }
 
 
-int MathArray::item_size(int pos) const
-{
-       return 2 + (isInset(pos) ? sizeof(MathInset*) : 1);
-}
-
-
 void MathArray::substitute(MathMacro const & m)
 {
        MathArray tmp;
-       for (int pos = 0; pos < size(); next(pos)) {
-               if (isInset(pos)) 
-                       nextInset(pos)->substitute(tmp, m);
-               else 
-                       tmp.push_back(getChar(pos), getCode(pos));
-       }
+       for (int pos = 0; pos < size(); ++pos) 
+               bf_[pos]->substitute(tmp, m);
        swap(tmp);
 }
 
@@ -103,28 +89,23 @@ MathArray & MathArray::operator=(MathArray const & array)
 
 MathInset * MathArray::nextInset(int pos) const
 {
-       if (!isInset(pos))
-               return 0;
-       MathInset * p;
-       memcpy(&p, &bf_[0] + pos + 1, sizeof(p));
-       return p;
+       return (pos == size()) ? 0 : bf_[pos];
 }
 
 
 MathInset * MathArray::prevInset(int pos) const
 {
-       if (!prev(pos))
-               return 0;
-       return nextInset(pos);
+       return (pos == 0) ? 0 : bf_[pos - 1];
 }
 
 
 unsigned char MathArray::getChar(int pos) const
 {
-       return pos < size() ? bf_[pos + 1] : '\0';
+       return (pos == size()) ? 0 : (bf_[pos]->getChar());
 }
 
 
+/*
 string MathArray::getString(int & pos) const
 {
        string s;
@@ -139,35 +120,30 @@ string MathArray::getString(int & pos) const
 
        return s;
 }
+*/
 
 
 MathTextCodes MathArray::getCode(int pos) const
 {
-       return pos < size() ? MathTextCodes(bf_[pos]) : LM_TC_MIN;
+       return pos < size() ? (bf_[pos]->code()) : LM_TC_MIN;
 }
 
 
 void MathArray::setCode(int pos, MathTextCodes t)
 {
-       if (pos > size() || isInset(pos))
-               return;
-       bf_[pos] = t;
-       bf_[pos + 2] = t;
+       bf_[pos]->code(t);
 }
 
 
-
 void MathArray::insert(int pos, MathInset * p)
 {
-       bf_.insert(bf_.begin() + pos, 2 + sizeof(p), LM_TC_INSET);
-       memcpy(&bf_[pos + 1], &p, sizeof(p));
+       bf_.insert(bf_.begin() + pos, p);
 }
 
 
 void MathArray::insert(int pos, unsigned char b, MathTextCodes t)
 {
-       bf_.insert(bf_.begin() + pos, 3, t);
-       bf_[pos + 1] = b;
+       bf_.insert(bf_.begin() + pos, new MathCharInset(b, t));
 }
 
 
@@ -229,29 +205,20 @@ void MathArray::erase()
 
 void MathArray::erase(int pos)
 {
-       if (pos < static_cast<int>(bf_.size()))
-               erase(pos, pos + item_size(pos));
+       if (pos < size())
+               bf_.erase(bf_.begin() + pos);
 }
 
 
 void MathArray::erase(int pos1, int pos2)
 {
-       for (int pos = pos1; pos < pos2; next(pos))
-               if (isInset(pos))
-                       delete nextInset(pos);
+       for (int pos = pos1; pos < pos2; ++pos)
+               delete nextInset(pos);
        bf_.erase(bf_.begin() + pos1, bf_.begin() + pos2);
 }
 
 
-bool MathArray::isInset(int pos) const
-{
-       if (pos >= size())
-               return false;
-       return MathIsInset(static_cast<MathTextCodes>(bf_[pos]));
-}
-
-
-MathInset * MathArray::back_inset() const
+MathInset * MathArray::back() const
 {
        return prevInset(size());
 }
@@ -267,12 +234,8 @@ void MathArray::dump2(ostream & os) const
 
 void MathArray::dump(ostream & os) const
 {
-       for (int pos = 0; pos < size(); next(pos)) {
-               if (isInset(pos)) 
-                       os << "<inset: " << nextInset(pos) << ">";
-               else 
-                       os << "<" << int(bf_[pos]) << " " << int(bf_[pos+1]) << ">";
-       }
+       for (int pos = 0; pos < size(); ++pos)
+               os << "<" << nextInset(pos) << ">";
 }
 
 
@@ -285,61 +248,8 @@ std::ostream & operator<<(std::ostream & os, MathArray const & ar)
 
 void MathArray::write(ostream & os, bool fragile) const
 {
-       if (empty())
-               return;
-
-       int brace = 0;
-       
-       for (int pos = 0; pos < size(); next(pos)) {
-               if (isInset(pos)) {
-
-                       nextInset(pos)->write(os, fragile);
-
-               } else {
-
-                       MathTextCodes fcode = getCode(pos);
-                       unsigned char c = getChar(pos);
-
-                       if (MathIsSymbol(fcode)) {
-                               latexkeys const * l = lm_get_key_by_id(c, LM_TK_SYM);
-
-                               if (l == 0) {
-                                       l = lm_get_key_by_id(c, LM_TK_BIGSYM);
-                               }
-
-                               if (l) {
-                                       os << '\\' << l->name << ' ';
-                               } else {
-                                       lyxerr << "Could not find the LaTeX name for  " << c << " and fcode " << fcode << "!" << std::endl;
-                               }
-                       } else {
-                               if (fcode >= LM_TC_RM && fcode <= LM_TC_TEXTRM) 
-                                       os << '\\' << math_font_name[fcode - LM_TC_RM] << '{';
-
-                               // Is there a standard logical XOR?
-                               if ((fcode == LM_TC_TEX && c != '{' && c != '}') ||
-                                               (fcode == LM_TC_SPECIAL))
-                                       os << '\\';
-                               else {
-                                       if (c == '{')
-                                               ++brace;
-                                       if (c == '}')
-                                               --brace;
-                               }
-                               if (c == '}' && fcode == LM_TC_TEX && brace < 0) 
-                                       lyxerr <<"Math warning: Unexpected closing brace.\n";
-                               else           
-                                       os << c;
-                       }
-
-                       if (fcode >= LM_TC_RM && fcode <= LM_TC_TEXTRM)
-                               os << '}';
-                       
-               }
-       }
-
-       if (brace > 0)
-               os << string(brace, '}');
+       for (int pos = 0; pos < size(); ++pos)
+               nextInset(pos)->write(os, fragile);
 }
 
 
@@ -356,9 +266,8 @@ void MathArray::writeNormal(ostream & os) const
 
 void MathArray::validate(LaTeXFeatures & features) const
 {
-       for (int pos = 0; pos < size(); next(pos)) 
-               if (isInset(pos)) 
-                       nextInset(pos)->validate(features);
+       for (int pos = 0; pos < size(); ++pos)
+               nextInset(pos)->validate(features);
 }
 
 
index f9c7e9bc3055ea1b413910ed3333ded63a69cd1f..bcbe00a9976b88e38525fb21a40945e0edff8e06 100644 (file)
@@ -92,7 +92,7 @@ public:
        ///
        void pop_back();
        ///
-       MathInset * back_inset() const;
+       MathInset * back() const;
 
        ///
        void dump(std::ostream &) const;
@@ -116,8 +116,6 @@ public:
        ///
        void setCode(int pos, MathTextCodes t);
        ///
-       bool isInset(int pos) const;
-       ///
        void write(std::ostream &, bool) const;
        ///
        void writeNormal(std::ostream &) const;
@@ -125,12 +123,7 @@ public:
        void validate(LaTeXFeatures &) const;
 private:
        ///
-       typedef std::vector<unsigned char>           buffer_type;
-       ///
-       typedef unsigned char                        value_type;
-
-       ///
-       int item_size(int pos) const;
+       typedef std::vector<MathInset *>           buffer_type;
        ///
        void deep_copy(int pos1, int pos2);
        /// Buffer
index c788404cd40a3b98b3c7397955519823d356c2b2..7eca200b1e66a6e81e9cd164a827dae80ef81d81 100644 (file)
@@ -259,9 +259,9 @@ bool MathCursor::left(bool sel)
 }
 
 
-bool MathCursor::plainRight()
+void MathCursor::plainRight()
 {
-       return array().next(cursor().pos_);
+       ++cursor().pos_;
 }
 
 
@@ -419,7 +419,7 @@ void MathCursor::insert(MathInset * p)
        }
 
        array().insert(cursor().pos_, p);
-       array().next(cursor().pos_);
+       ++cursor().pos_;
 }
 
 
@@ -731,7 +731,7 @@ void MathCursor::macroModeOpen()
        if (!imacro_) {
                imacro_ = new MathFuncInset("");
                array().insert(cursor().pos_, imacro_);
-               array().next(cursor().pos_);
+               ++cursor().pos_;
                //insert(imacro_);
        } else
                lyxerr << "Math Warning: Already in macro mode" << endl;
@@ -856,8 +856,8 @@ void MathCursor::handleFont(MathTextCodes t)
                getSelection(i1, i2); 
                if (i1.idx_ == i2.idx_) {
                        MathArray & ar = i1.cell();
-                       for (int pos = i1.pos_; pos != i2.pos_; ar.next(pos))
-                               if (!ar.isInset(pos) && isalnum(ar.getChar(pos))) { 
+                       for (int pos = i1.pos_; pos != i2.pos_; ++pos)
+                               if (isalnum(ar.getChar(pos))) { 
                                        MathTextCodes c = ar.getCode(pos) == t ? LM_TC_VAR : t;
                                        ar.setCode(pos, c);
                                }
index 80e8a606fbff6060c1b2ee2e23a761f5d0057e5f..f68bb114b6ae55bf235778e28dda90e932ce91e4 100644 (file)
@@ -99,7 +99,7 @@ public:
        ///
        bool plainLeft();
        ///
-       bool plainRight();
+       void plainRight();
        ///
        void plainErase();
        ///
index dd87a10ec530a141d780a12cff92d1e0a267d7d4..9f2d73989d96c18da2a8a179f58c0734eac2705b 100644 (file)
@@ -12,7 +12,7 @@ using std::ostream;
 
 
 MathDecorationInset::MathDecorationInset(latexkeys const * key)
-       : MathInset(1), key_(key)
+       : MathNestInset(1), key_(key)
 {
        upper_ = key_->id != LM_underline && key_->id != LM_underbrace;
 }
index cf90fb1df9a14dc3dd5c233c487aaa4c97ab164f..657f93bf535f05ec551810148dc3bf7a76d46708 100644 (file)
@@ -2,7 +2,7 @@
 #ifndef MATH_DECORATIONINSET_H
 #define MATH_DECORATIONINSET_H
 
-#include "math_inset.h"
+#include "math_nestinset.h"
 
 #ifdef __GNUG__
 #pragma interface
@@ -14,7 +14,7 @@
 
 struct latexkeys;
 
-class MathDecorationInset : public MathInset {
+class MathDecorationInset : public MathNestInset {
 public:
        ///
        explicit MathDecorationInset(latexkeys const *);
index 7db35162a4001114e4b2db615579323d407885b9..914f1635f95dea3adbd849f8d2867eb241164fb8 100644 (file)
@@ -10,7 +10,7 @@
 
 
 MathDelimInset::MathDelimInset(int l, int r)
-       : MathInset(1), left_(l), right_(r)
+       : MathNestInset(1), left_(l), right_(r)
 {}
 
 
index 6dde45708809bc699eaf6f58d5352d2cf9fffafd..30b98208aa613d6939c60276095f13804f13c301 100644 (file)
@@ -2,7 +2,7 @@
 #ifndef MATH_DELIMINSET_H
 #define MATH_DELIMINSET_H
 
-#include "math_inset.h"
+#include "math_nestinset.h"
 
 #ifdef __GNUG__
 #pragma interface
@@ -11,7 +11,7 @@
 /** A delimiter
     \author Alejandro Aguilar Sierra
 */
-class MathDelimInset : public MathInset {
+class MathDelimInset : public MathNestInset {
 public:
        ///
        MathDelimInset(int, int);
index 2f195276fa503f6b0d2c30715ba41577bcf666c0..911cc3394ee0632445077bdd03c57e65e0f814b0 100644 (file)
@@ -9,7 +9,7 @@
 
 
 MathFracInset::MathFracInset(string const & name)
-       : MathInset(2, name)
+       : MathNestInset(2, name)
 {}
 
 
index bbbeea420af1c0bca5fa5ac726d1fbe67bb65086..e90e95abebdee7b914e475bd8cad1279a68d09b3 100644 (file)
@@ -2,7 +2,7 @@
 #ifndef MATH_FRACINSET_H
 #define MATH_FRACINSET_H
 
-#include "math_inset.h"
+#include "math_nestinset.h"
 
 #ifdef __GNUG__
 #pragma interface
@@ -11,7 +11,7 @@
 /** Fraction like objects (frac, stackrel, binom)
     \author Alejandro Aguilar Sierra
  */
-class MathFracInset : public MathInset {
+class MathFracInset : public MathNestInset {
 public:
        ///
        explicit MathFracInset(const string & name);
index 0f72e2988777c83f95255f1b7f226d2b4dda3408..32537b799d025edb9b49db74b99b0f36b3170289 100644 (file)
@@ -15,7 +15,7 @@ extern LyXFont WhichFont(short type, int size);
 
 
 MathFuncInset::MathFuncInset(string const & nm)
-       : MathInset(0, nm)
+       : MathInset(nm)
 {}
 
 
index b7629ad227d38ab059962c87bfb54f808f214a2b..44bd4816acbac89fed82ae9e6504e7ce661be56c 100644 (file)
@@ -30,7 +30,7 @@ MathGridInset::ColInfo::ColInfo()
 
 
 MathGridInset::MathGridInset(int m, int n, string const & nm)
-       : MathInset(m * n, nm), rowinfo_(n), colinfo_(m), v_align_('c')
+       : MathNestInset(m * n, nm), rowinfo_(n), colinfo_(m), v_align_('c')
 {
        if (m <= 0)
                lyxerr << "positve number of columns expected\n";
@@ -77,7 +77,7 @@ char MathGridInset::valign() const
 void MathGridInset::metrics(MathStyles st)
 {
        // let the cells adjust themselves
-       MathInset::metrics(st);
+       MathNestInset::metrics(st);
        size_ = st;
 
        // adjust vertical structure
index d867d70113574c149b9fe805991814e98160082a..6216e55780108cc811aa556a85d5a98e326eb052 100644 (file)
@@ -2,7 +2,7 @@
 #ifndef MATH_GRID_H
 #define MATH_GRID_H
 
-#include "math_inset.h"
+#include "math_nestinset.h"
 
 #ifdef __GNUG__
 #pragma interface
@@ -14,7 +14,7 @@
     \author André Pönitz 2001
 */
 
-class MathGridInset : public MathInset {
+class MathGridInset : public MathNestInset {
 
        /// additional per-row information
        struct RowInfo {
index aee6d232c9afb2a7539d99b2f7ad38ca71f4b0ac..8d58533d40a47b2ecd5691de6c39263c50911720 100644 (file)
@@ -26,9 +26,9 @@
 int MathInset::workwidth;
 
 
-MathInset::MathInset(int nargs, string const & name)
+MathInset::MathInset(string const & name)
        : name_(name), width_(0), ascent_(0), descent_(0),
-               size_(LM_ST_DISPLAY), code_(LM_TC_MIN), cells_(nargs), xo_(0), yo_(0)
+               size_(LM_ST_DISPLAY), code_(LM_TC_MIN), xo_(0), yo_(0)
 {}
 
 
@@ -113,89 +113,67 @@ void MathInset::yo(int y)
 
 int MathInset::nargs() const
 {
-       return cells_.size();
+       return 0;
 }
 
 
-MathXArray & MathInset::xcell(int i)
-{
-       return cells_[i];
-}
-
+MathXArray dummyCell;
 
-MathXArray const & MathInset::xcell(int i) const
+MathXArray & MathInset::xcell(int)
 {
-       return cells_[i];
+       lyxerr << "I don't have a cell\n";
+       return dummyCell;
 }
 
 
-MathArray & MathInset::cell(int i)
+MathXArray const & MathInset::xcell(int) const
 {
-       return cells_[i].data_;
+       lyxerr << "I don't have a cell\n";
+       return dummyCell;
 }
 
 
-MathArray const & MathInset::cell(int i) const
+MathArray & MathInset::cell(int)
 {
-       return cells_[i].data_;
+       lyxerr << "I don't have a cell\n";
+       return dummyCell.data_;
 }
 
 
-void MathInset::substitute(MathArray & array, MathMacro const & m) const
+MathArray const & MathInset::cell(int) const
 {
-       MathInset * p = clone();
-       for (int i = 0; i < nargs(); ++i)
-               p->cell(i).substitute(m);
-       array.push_back(p);
+       lyxerr << "I don't have a cell\n";
+       return dummyCell.data_;
 }
 
 
-void MathInset::metrics(MathStyles st)
+void MathInset::substitute(MathArray & array, MathMacro const &) const
 {
-       size_ = st;
-       for (int i = 0; i < nargs(); ++i)
-               xcell(i).metrics(st);
+       array.push_back(clone());
 }
 
 
-void MathInset::draw(Painter & pain, int x, int y)
+bool MathInset::idxNext(int &, int &) const
 {
-       xo_ = x;
-       yo_ = y;
-       for (int i = 0; i < nargs(); ++i)
-               xcell(i).draw(pain, x + xcell(i).xo(), y + xcell(i).yo());
-}
-
-
-bool MathInset::idxNext(int & idx, int & pos) const
-{
-       if (idx + 1 >= nargs())
-               return false;
-       ++idx;
-       pos = 0;
-       return true;
+       return false;
 }
 
 
-bool MathInset::idxRight(int & idx, int & pos) const
+bool MathInset::idxRight(int &, int &) const
 {
-       return idxNext(idx, pos);
+       return false;
 }
 
 
-bool MathInset::idxPrev(int & idx, int & pos) const
+bool MathInset::idxPrev(int &, int &) const
 {
-       if (idx == 0)
-               return false;
-       --idx;
-       pos = cell(idx).size();
-       return true;
+       return false;
 }
 
 
-bool MathInset::idxLeft(int & idx, int & pos) const
+bool MathInset::idxLeft(int &, int &) const
 {
-       return idxPrev(idx, pos);
+       return false;
 }
 
 
@@ -211,42 +189,27 @@ bool MathInset::idxDown(int &, int &) const
 }
 
 
-bool MathInset::idxFirst(int & i, int & pos) const
+bool MathInset::idxFirst(int &, int &) const
 {
-       if (nargs() == 0)
-               return false;
-       i = 0;
-       pos = 0;
-       return true;
+       return false;
 }
 
 
-bool MathInset::idxLast(int & i, int & pos) const
+bool MathInset::idxLast(int &, int &) const
 {
-       if (nargs() == 0)
-               return false;
-       i = nargs() - 1;
-       pos = cell(i).size();
-       return true;
+       return false;
 }
 
 
-bool MathInset::idxHome(int & /* idx */, int & pos) const
+bool MathInset::idxHome(int &, int &) const
 {
-       if (pos == 0)
-               return false;
-       pos = 0;
-       return true;
+       return false;
 }
 
 
-bool MathInset::idxEnd(int & idx, int & pos) const
+bool MathInset::idxEnd(int &, int &) const
 {
-       if (pos == cell(idx).size())
-               return false;
-
-       pos = cell(idx).size();
-       return true;
+       return false;
 }
 
 
@@ -312,28 +275,19 @@ void MathInset::dump() const
 {
        lyxerr << "---------------------------------------------\n";
        write(lyxerr, false);
-       lyxerr << "\n";
-       for (int i = 0; i < nargs(); ++i)
-               lyxerr << cell(i) << "\n";
-       lyxerr << "---------------------------------------------\n";
+       lyxerr << "\n---------------------------------------------\n";
 }
 
 
-void MathInset::push_back(unsigned char ch, MathTextCodes fcode)
+void MathInset::push_back(unsigned char, MathTextCodes)
 {
-       if (nargs())
-               cells_.back().data_.push_back(ch, fcode);
-       else
-               lyxerr << "can't push without a cell\n";
+       lyxerr << "can't push without a cell\n";
 }
 
 
 void MathInset::push_back(MathInset * p)
 {
-       if (nargs())
-               cells_.back().data_.push_back(p);
-       else
-               lyxerr << "can't push without a cell\n";
+       lyxerr << "can't push without a cell\n";
 }
 
 
@@ -347,11 +301,8 @@ bool MathInset::covers(int x, int y) const
 }
 
 
-void MathInset::validate(LaTeXFeatures & features) const
-{
-       for (int i = 0; i < nargs(); ++i)
-               cell(i).validate(features);
-}
+void MathInset::validate(LaTeXFeatures &) const
+{}
 
 
 std::vector<int> MathInset::idxBetween(int from, int to) const
index f054bb21d57420a896b0e9be56656dc381811e11..bd97f31d3375a9d0d950336ef4d9642296ad447c 100644 (file)
@@ -44,7 +44,7 @@ class LaTeXFeatures;
 class MathInset {
 public: 
        ///
-       explicit MathInset(int na = 0, string const & nm = string());
+       explicit MathInset(string const & nm = string());
 
        /// the virtual base destructor
        virtual ~MathInset() {}
@@ -74,7 +74,7 @@ public:
        ///
        virtual void setName(string const & n);
        ///
-       MathStyles size() const;
+       virtual MathStyles size() const;
 
        /// Where should we go when we press the up cursor key?
        virtual bool idxUp(int & idx, int & pos) const;
@@ -116,29 +116,29 @@ public:
        // deletes a cell range and moves the cursor 
        virtual void idxDeleteRange(int from, int to);
        // returns list of cell indices that are "between" from and to for
-       // selction purposes
+       // selection purposes
        virtual std::vector<int> idxBetween(int from, int to) const;
 
        ///
-       int nargs() const;
+       virtual int nargs() const;
 
        ///
-       MathArray & cell(int);
+       virtual MathArray & cell(int);
        ///
-       MathArray const & cell(int) const;
+       virtual MathArray const & cell(int) const;
        ///
-       MathXArray & xcell(int);
+       virtual MathXArray & xcell(int);
        ///
-       MathXArray const & xcell(int) const;
+       virtual MathXArray const & xcell(int) const;
                        
        ///
-       int xo() const;
+       virtual int xo() const;
        ///
-       int yo() const;
+       virtual int yo() const;
        ///
-       void xo(int tx);
+       virtual void xo(int tx);
        ///
-       void yo(int ty);
+       virtual void yo(int ty);
        ///
 
        ///
@@ -162,9 +162,9 @@ public:
        virtual void userSetSize(MathStyles &) {}
 
        ///
-       void getXY(int & x, int & y) const;
+       virtual void getXY(int & x, int & y) const;
        ///
-       bool covers(int x, int y) const;
+       virtual bool covers(int x, int y) const;
        /// identifies things that can get scripts
        virtual bool isScriptable() const { return false; }
        /// identifies ScriptInsets
@@ -175,28 +175,30 @@ public:
        virtual bool isGrid() const { return false; }
        /// identifies ArrayInsets
        virtual bool isArray() const { return false; }
+       /// identifies Charinsets
+       virtual bool isCharInset() const { return false; }
        ///
        virtual bool isActive() const { return nargs() > 0; }
-       /// identifies insets that display scripts directly above and below
-
+       ///
+       virtual char getChar() const { return 0; }
 
        ///
-       void push_back(MathInset *);
+       virtual void push_back(MathInset *);
        ///
-       void push_back(unsigned char ch, MathTextCodes fcode);
+       virtual void push_back(unsigned char ch, MathTextCodes fcode);
        ///
-       void dump() const;
+       virtual void dump() const;
 
        ///
-       void validate(LaTeXFeatures & features) const;
+       virtual void validate(LaTeXFeatures & features) const;
 
        ///
        static int workwidth;
 
        /// the inherited text style
-       MathTextCodes code() const;
+       virtual MathTextCodes code() const;
        ///
-       void code(MathTextCodes t);
+       virtual void code(MathTextCodes t);
 
 protected:
        /// usually the LaTeX name of the thingy
@@ -214,15 +216,6 @@ protected:
        /// the inherited text style
        MathTextCodes code_;
 
-protected:
-       ///
-       typedef std::vector<MathXArray> cells_type;
-       /**
-        * The contents of the inset are contained here.
-        * Each inset is build from a number of insets.
-        */
-       cells_type cells_;
-
 private:
        /// the following are used for positioning the cursor with the mouse
        /// cached cursor start position in pixels from the document left
index 49fcd7032dbbf8eef579b6d15a0a560c01740b19..13b439d41aca32450130a8a69505d3d29899aa41 100644 (file)
 using std::endl;
 
 MathMacro::MathMacro(MathMacroTemplate const & t)
-       : MathInset(t.numargs(), t.name()), tmplate_(&t)
+       : MathNestInset(t.numargs(), t.name()), tmplate_(&t)
 {}
 
 
 MathMacro::MathMacro(MathMacro const & t)
-       : MathInset(t), tmplate_(t.tmplate_) // don't copy 'expanded_'!
+       : MathNestInset(t), tmplate_(t.tmplate_) // don't copy 'expanded_'!
 {}
 
 
@@ -164,13 +164,13 @@ void MathMacro::writeNormal(std::ostream & os) const
 
 bool MathMacro::idxUp(int & idx, int & pos) const
 {
-       return MathInset::idxLeft(idx, pos);
+       return MathNestInset::idxLeft(idx, pos);
 }
 
 
 bool MathMacro::idxDown(int & idx, int & pos) const
 {
-       return MathInset::idxRight(idx, pos);
+       return MathNestInset::idxRight(idx, pos);
 }
 
 
index 08eacce559efb538ddbe070c282f263a335047dd..6348743e8ac9f28f47a3e97120eabe762a7c6672 100644 (file)
@@ -24,7 +24,7 @@
 #include <vector>
 #include <iosfwd>
 
-#include "math_inset.h"
+#include "math_nestinset.h"
 #include "math_macroarg.h"
 
 class MathMacroTemplate;
@@ -34,7 +34,7 @@ class MathMacroTemplate;
     \author Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
     \version November 1996
  */
-class MathMacro : public MathInset {
+class MathMacro : public MathNestInset {
 public:
        /// A macro can be built from an existing template
        explicit MathMacro(MathMacroTemplate const &);
index 75655868f562d01a06f04f707b5cddfc1ae94212..9756b257418159d6e504dccb04cfdd1e49bced85 100644 (file)
@@ -8,12 +8,12 @@
 
 
 MathMacroTemplate::MathMacroTemplate()
-       : MathInset(1), numargs_(0)
+       : MathNestInset(1), numargs_(0)
 {}
 
 
 MathMacroTemplate::MathMacroTemplate(string const & nm, int numargs)
-       : MathInset(1, nm), numargs_(numargs)
+       : MathNestInset(1, nm), numargs_(numargs)
 {}
 
 
index 042edcadbab86055e92e8ec69aa7364c451ec88d..b7f138b6397f078c817fe57478f0d4be537b64d0 100644 (file)
@@ -2,7 +2,7 @@
 #ifndef MATH_MACROTEMPLATE_H
 #define MATH_MACROTEMPLATE_H
 
-#include "math_inset.h"
+#include "math_nestinset.h"
 
 #ifdef __GNUG__
 #pragma interface
@@ -15,7 +15,7 @@ class MathMacro;
  */
 //class MathMacroTemplate : public MathInset, boost::noncopyable 
 
-class MathMacroTemplate : public MathInset {
+class MathMacroTemplate : public MathNestInset {
 public:
        ///
        MathMacroTemplate();
index e2d6038c2d25d1960c76e6da9f38d19a3f2e18bb..be321b53fcc610c132d9603d9cabcb49faac3118 100644 (file)
@@ -68,9 +68,8 @@ int getCols(short int type)
 // used for "intelligent splitting"
 int firstRelOp(MathArray const & array)
 {
-       for (int pos = 0; pos < array.size(); array.next(pos))
-               if (!array.isInset(pos) &&
-                               MathIsRelOp(array.getChar(pos), array.getCode(pos)))
+       for (int pos = 0; pos < array.size(); ++pos)
+               if (MathIsRelOp(array.getChar(pos), array.getCode(pos)))
                        return pos;
        return array.size();
 }
@@ -228,7 +227,7 @@ void MathMatrixInset::validate(LaTeXFeatures & features) const
        features.boldsymbol = true;
        //features.binom      = true;
 
-       MathInset::validate(features);
+       MathNestInset::validate(features);
 }
 
 
diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C
new file mode 100644 (file)
index 0000000..aed935a
--- /dev/null
@@ -0,0 +1,174 @@
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "math_nestinset.h"
+#include "debug.h"
+
+
+MathNestInset::MathNestInset(int nargs, string const & name)
+       : MathInset(name), cells_(nargs)
+{}
+
+
+int MathNestInset::nargs() const
+{
+       return cells_.size();
+}
+
+
+MathXArray & MathNestInset::xcell(int i)
+{
+       return cells_[i];
+}
+
+
+MathXArray const & MathNestInset::xcell(int i) const
+{
+       return cells_[i];
+}
+
+
+MathArray & MathNestInset::cell(int i)
+{
+       return cells_[i].data_;
+}
+
+
+MathArray const & MathNestInset::cell(int i) const
+{
+       return cells_[i].data_;
+}
+
+
+void MathNestInset::substitute(MathArray & array, MathMacro const & m) const
+{
+       MathNestInset * p = static_cast<MathNestInset *>(clone());
+       for (int i = 0; i < nargs(); ++i)
+               p->cell(i).substitute(m);
+       array.push_back(p);
+}
+
+
+void MathNestInset::metrics(MathStyles st)
+{
+       size_ = st;
+       for (int i = 0; i < nargs(); ++i)
+               xcell(i).metrics(st);
+}
+
+
+void MathNestInset::draw(Painter & pain, int x, int y)
+{
+       xo(x);
+       yo(y);
+       for (int i = 0; i < nargs(); ++i)
+               xcell(i).draw(pain, x + xcell(i).xo(), y + xcell(i).yo());
+}
+
+
+bool MathNestInset::idxNext(int & idx, int & pos) const
+{
+       if (idx + 1 >= nargs())
+               return false;
+       ++idx;
+       pos = 0;
+       return true;
+}
+
+
+bool MathNestInset::idxRight(int & idx, int & pos) const
+{
+       return idxNext(idx, pos);
+}
+
+
+bool MathNestInset::idxPrev(int & idx, int & pos) const
+{
+       if (idx == 0)
+               return false;
+       --idx;
+       pos = cell(idx).size();
+       return true;
+}
+
+
+bool MathNestInset::idxLeft(int & idx, int & pos) const
+{
+       return idxPrev(idx, pos);
+}
+
+
+bool MathNestInset::idxFirst(int & i, int & pos) const
+{
+       if (nargs() == 0)
+               return false;
+       i = 0;
+       pos = 0;
+       return true;
+}
+
+
+bool MathNestInset::idxLast(int & i, int & pos) const
+{
+       if (nargs() == 0)
+               return false;
+       i = nargs() - 1;
+       pos = cell(i).size();
+       return true;
+}
+
+
+bool MathNestInset::idxHome(int & /* idx */, int & pos) const
+{
+       if (pos == 0)
+               return false;
+       pos = 0;
+       return true;
+}
+
+
+bool MathNestInset::idxEnd(int & idx, int & pos) const
+{
+       if (pos == cell(idx).size())
+               return false;
+
+       pos = cell(idx).size();
+       return true;
+}
+
+
+void MathNestInset::dump() const
+{
+       lyxerr << "---------------------------------------------\n";
+       write(lyxerr, false);
+       lyxerr << "\n";
+       for (int i = 0; i < nargs(); ++i)
+               lyxerr << cell(i) << "\n";
+       lyxerr << "---------------------------------------------\n";
+}
+
+
+void MathNestInset::push_back(unsigned char ch, MathTextCodes fcode)
+{
+       if (nargs())
+               cells_.back().data_.push_back(ch, fcode);
+       else
+               lyxerr << "can't push without a cell\n";
+}
+
+
+void MathNestInset::push_back(MathInset * p)
+{
+       if (nargs())
+               cells_.back().data_.push_back(p);
+       else
+               lyxerr << "can't push without a cell\n";
+}
+
+
+void MathNestInset::validate(LaTeXFeatures & features) const
+{
+       for (int i = 0; i < nargs(); ++i)
+               cell(i).validate(features);
+}
diff --git a/src/mathed/math_nestinset.h b/src/mathed/math_nestinset.h
new file mode 100644 (file)
index 0000000..114b799
--- /dev/null
@@ -0,0 +1,79 @@
+#ifndef MATH_NESTINSET_H
+#define MATH_NESTINSET_H
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include "math_inset.h"
+
+/** Abstract base class for all math objects that conatin nested items.
+*/
+
+
+class LaTeXFeatures;
+
+class MathNestInset : public MathInset {
+public: 
+       ///
+       explicit MathNestInset(int na = 0, string const & nm = string());
+
+       /// draw the object, sets xo_ and yo_ cached values 
+       virtual void draw(Painter &, int x, int baseline);
+       /// appends itself with macro arguments substituted
+       virtual void substitute(MathArray & array, MathMacro const & macro) const;
+       /// compute the size of the object, sets ascend_, descend_ and width_
+       virtual void metrics(MathStyles st) = 0;
+
+       /// The left key
+       virtual bool idxLeft(int & idx, int & pos) const;
+       /// The right key
+       virtual bool idxRight(int & idx, int & pos) const;
+
+       /// Move one physical cell up
+       virtual bool idxNext(int & idx, int & pos) const;
+       /// Move one physical cell down
+       virtual bool idxPrev(int & idx, int & pos) const;
+
+       /// Target pos when we enter the inset from the left by pressing "Right"
+       virtual bool idxFirst(int & idx, int & pos) const;
+       /// Target pos when we enter the inset from the right by pressing "Left"
+       virtual bool idxLast(int & idx, int & pos) const;
+
+       /// Where should we go if we press home?
+       virtual bool idxHome(int & idx, int & pos) const;
+       /// Where should we go if we press end?
+       virtual bool idxEnd(int & idx, int & pos) const;
+
+       ///
+       int nargs() const;
+
+       ///
+       MathArray & cell(int);
+       ///
+       MathArray const & cell(int) const;
+       ///
+       MathXArray & xcell(int);
+       ///
+       MathXArray const & xcell(int) const;
+                       
+       ///
+       bool isActive() const { return nargs() > 0; }
+       ///
+       void push_back(MathInset *);
+       ///
+       void push_back(unsigned char ch, MathTextCodes fcode);
+       ///
+       void dump() const;
+
+       ///
+       void validate(LaTeXFeatures & features) const;
+
+protected:
+       ///
+       typedef std::vector<MathXArray> cells_type;
+       /// The nested contents of the inset are contained here.
+       cells_type cells_;
+};
+
+#endif
index 09dfc423c21b57d51679467a768bf19eba198d39..50ed6a79c9617f6c51924b499b2e129941926d3d 100644 (file)
@@ -87,9 +87,8 @@ unsigned char getuchar(std::istream * is)
 {
        char c = 0;
        is->get(c);
-       if (!is->good()) {
+       if (!is->good())
                lyxerr << "The input stream is not well..." << endl;
-       }
        
        return static_cast<unsigned char>(c);
 }
@@ -326,7 +325,7 @@ int yylex()
                                }
                                while (lexcode[c] == LexSpace && yyis->good()) 
                                        c = getuchar(yyis);
-                               if (yyis->good() && lexcode[c] != LexSpace)
+                               if (lexcode[c] != LexSpace)
                                        yyis->putback(c);
                        
                                //lyxerr[Debug::MATHED] << "reading: text '" << yytext << "'\n";
@@ -354,7 +353,7 @@ int yylex()
 
 MathScriptInset * prevScriptInset(MathArray const & array)
 {
-       MathInset * p = array.back_inset();
+       MathInset * p = array.back();
        return (p && p->isScriptInset()) ? static_cast<MathScriptInset *>(p) : 0;
 }
 
@@ -363,7 +362,7 @@ MathInset * lastScriptInset(MathArray & array, bool up, bool down, int limits)
 {
        MathScriptInset * p = prevScriptInset(array);
        if (!p) {
-               MathInset * b = array.back_inset();
+               MathInset * b = array.back();
                if (b && b->isScriptable()) {
                        p = new MathScriptInset(up, down, b->clone());
                        array.pop_back();       
@@ -694,12 +693,12 @@ void mathed_parse_into(MathArray & array, unsigned flags)
                        unsigned char c = getuchar(yyis);
                        if (c == '[') {
                                array.push_back(new MathRootInset);
-                               mathed_parse_into(array.back_inset()->cell(0), FLAG_BRACK_END);
-                               mathed_parse_into(array.back_inset()->cell(1), FLAG_ITEM);
+                               mathed_parse_into(array.back()->cell(0), FLAG_BRACK_END);
+                               mathed_parse_into(array.back()->cell(1), FLAG_ITEM);
                        } else {
                                yyis->putback(c);
                                array.push_back(new MathSqrtInset);
-                               mathed_parse_into(array.back_inset()->cell(0), FLAG_ITEM);
+                               mathed_parse_into(array.back()->cell(0), FLAG_ITEM);
                        }
                        break;
                }
index d67cd851361bff5ba29097baf781d2138f3629cb..1f188a47dfb59156a0475a938614e60c38d59116 100644 (file)
@@ -20,7 +20,7 @@
 #include "Painter.h"
 
 MathRootInset::MathRootInset()
-       : MathInset(2)
+       : MathNestInset(2)
 {}
 
 
@@ -32,7 +32,7 @@ MathInset * MathRootInset::clone() const
 
 void MathRootInset::metrics(MathStyles st)
 {
-       MathInset::metrics(st);
+       MathNestInset::metrics(st);
        size_    = st;
        ascent_  = std::max(xcell(0).ascent()  + 5, xcell(1).ascent())  + 2;
        descent_ = std::max(xcell(1).descent() + 5, xcell(0).descent()) + 2;
index 20a73725eedf39cb45b2eb587a847991591a99f6..b832973948774f2225bbb1343b1c606f12caa1f1 100644 (file)
@@ -15,7 +15,7 @@
 #ifndef MATH_ROOT_H
 #define MATH_ROOT_H
 
-#include "math_inset.h"
+#include "math_nestinset.h"
 #include "symbol_def.h"
 
 #ifdef __GNUG__
@@ -26,7 +26,7 @@
     \author Alejandro Aguilar Sierra
     \version January 1999
  */
-class MathRootInset : public MathInset {
+class MathRootInset : public MathNestInset {
 public:
        ///
        MathRootInset();
index d4835efa97c41721685ba2f5e255f308603fa414..49b0bb89fec80591e3d40f12e6090a57fdb7df9f 100644 (file)
@@ -7,17 +7,17 @@
 
 
 MathScriptInset::MathScriptInset()
-       : MathInset(2), up_(false), down_(false), limits_(0), symbol_(0)
+       : MathNestInset(2), up_(false), down_(false), limits_(0), symbol_(0)
 {}
 
 
 MathScriptInset::MathScriptInset(bool up, bool down, MathInset * symbol)
-       : MathInset(2), up_(up), down_(down), limits_(0), symbol_(symbol)
+       : MathNestInset(2), up_(up), down_(down), limits_(0), symbol_(symbol)
 {}
 
 
 MathScriptInset::MathScriptInset(MathScriptInset const & p)
-       : MathInset(p), up_(p.up_), down_(p.down_),
+       : MathNestInset(p), up_(p.up_), down_(p.down_),
                limits_(p.limits_), symbol_(p.symbol_ ? p.symbol_->clone() : 0)
 {}
 
index 4334f019dbb7ca09619370ee5461bd08b70ccffa..b7a2f646c0342980d5f138f611d87176d08ca1ed 100644 (file)
@@ -2,7 +2,7 @@
 #ifndef MATH_SCRIPTINSET_H
 #define MATH_SCRIPTINSET_H
 
-#include "math_inset.h"
+#include "math_nestinset.h"
 
 #ifdef __GNUG__
 #pragma interface
@@ -13,7 +13,7 @@
  */
 
 
-class MathScriptInset : public MathInset {
+class MathScriptInset : public MathNestInset {
 public:
        ///
        MathScriptInset();
index dc2dae86f6bab60407ca072a4b09f6e89b58f210..e498cfdd28b1cdbdeb76db85f4728c08b3c8c165 100644 (file)
@@ -7,7 +7,7 @@
 
 
 MathSizeInset::MathSizeInset(MathStyles st)
-       : MathInset(1), style_(st)
+       : MathNestInset(1), style_(st)
 {
        name_ = verbose();
 }
index 26a78b3ff2d8d104f68d2f78bb67129216c2de88..283e46da9d903b4714dbaff25f34af07f8820f02 100644 (file)
@@ -2,7 +2,7 @@
 #ifndef MATHSIZEINSET_H
 #define MATHSIZEINSET_H
 
-#include "math_inset.h"
+#include "math_nestinset.h"
 #include "math_defs.h"
 
 #ifdef __GNUG__
@@ -13,7 +13,7 @@
     \author André Poenitz
 */
 
-class MathSizeInset : public MathInset {
+class MathSizeInset : public MathNestInset {
 public:
        ///
        explicit MathSizeInset(MathStyles st);
index d3be4d823de92ab00297be9ad52af2d4d7fc659e..cd0a585683822cb4628fcc2eaf4c9ff8f9c1aa44 100644 (file)
@@ -9,7 +9,7 @@
 
 
 MathSqrtInset::MathSqrtInset()
-       : MathInset(1)
+       : MathNestInset(1)
 {}
 
 
index 19c06e34a2aa63bf9debd5c6df3e8d2e2ff77f59..f3cdf82b2a391c200b6753cdfd2f54988a45770b 100644 (file)
@@ -2,7 +2,7 @@
 #ifndef MATH_SQRTINSET_H
 #define MATH_SQRTINSET_H
 
-#include "math_inset.h"
+#include "math_nestinset.h"
 
 #ifdef __GNUG__
 #pragma interface
@@ -11,7 +11,7 @@
 /** The square root inset.
     \author Alejandro Aguilar Siearra
  */
-class MathSqrtInset : public MathInset {
+class MathSqrtInset : public MathNestInset {
 public:
        ///
        MathSqrtInset();
index 884a03b5adfd2772b791bdbc86b7db96a8ababa6..4ac1584d5c49bd9957b1868713b59105e6e4ca6b 100644 (file)
@@ -31,21 +31,12 @@ void MathXArray::metrics(MathStyles st)
        width_   = 0;
        style_   = st;
 
-       for (int pos = 0; pos < data_.size(); data_.next(pos)) {
-               int asc;
-               int des;
-               int wid;
+       for (int pos = 0; pos < data_.size(); ++pos) {
                MathInset * p = data_.nextInset(pos);
-               if (p) {
-                       p->metrics(st);
-                       asc = p->ascent();
-                       des = p->descent();
-                       wid = p->width();
-               } else {
-                       char cx = data_.getChar(pos); 
-                       MathTextCodes fc = data_.getCode(pos); 
-                       mathed_char_dim(fc, style_, cx, asc, des, wid);
-               }
+               p->metrics(st);
+               int asc = p->ascent();
+               int des = p->descent();
+               int wid = p->width();
                ascent_  = max(ascent_, asc);
                descent_ = max(descent_, des);
                width_   += wid;
@@ -63,19 +54,10 @@ void MathXArray::draw(Painter & pain, int x, int y)
                return;
        }
 
-       for (int pos = 0; pos < data_.size(); data_.next(pos)) {
+       for (int pos = 0; pos < data_.size(); ++pos) {
                MathInset * p = data_.nextInset(pos);
-               if (p) {
-                       p->draw(pain, x, y);
-                       x += p->width();
-               } else {
-                       char cx = data_.getChar(pos);
-                       MathTextCodes fc = data_.getCode(pos);
-                       string s;
-                       s += cx;
-                       drawStr(pain, fc, style_, x, y, s);
-                       x += mathed_char_width(fc, style_, cx);
-               }
+               p->draw(pain, x, y);
+               x += p->width();
        }
 }
 
@@ -84,7 +66,7 @@ int MathXArray::pos2x(int targetpos) const
 {
        int x = 0;
        targetpos = min(targetpos, data_.size());
-       for (int pos = 0; pos < targetpos; data_.next(pos)
+       for (int pos = 0; pos < targetpos; ++pos
                x += width(pos);
        return x;
 }
@@ -95,27 +77,24 @@ int MathXArray::x2pos(int targetx) const
        int pos   = 0;
        int lastx = 0;
        int currx = 0;
-       while (currx < targetx && pos < data_.size()) {
+       for ( ; currx < targetx && pos < data_.size(); ++pos) {
                lastx = currx;
                currx += width(pos);
-               data_.next(pos);
        }
        if (abs(lastx - targetx) < abs(currx - targetx))
                data_.prev(pos);
        return pos;
 }
 
+
 int MathXArray::width(int pos) const
 {
        if (pos >= data_.size())
                return 0;
-
-       if (data_.isInset(pos)) 
-               return data_.nextInset(pos)->width();
-       else 
-               return mathed_char_width(data_.getCode(pos), style_, data_.getChar(pos));
+       return data_.nextInset(pos)->width();
 }
 
+
 std::ostream & operator<<(std::ostream & os, MathXArray const & ar)
 {
        os << ar.data_;