First shot at 'everything is an inset'. Look at what went out of (x)array.C. And that's not really cleaned up yet... Andre' -- André Pönitz ............................................. [EMAIL PROTECTED]
? todo ? memory.diff ? math_charinset.h ? todo.backup ? math_charinset.C ? parser.diff Index: BUGS =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/BUGS,v retrieving revision 1.2 diff -u -p -r1.2 BUGS --- BUGS 2001/08/03 09:54:47 1.2 +++ BUGS 2001/08/03 15:39:36 @@ -157,6 +157,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 ([EMAIL PROTECTED]) Index: Makefile.am =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/Makefile.am,v retrieving revision 1.30 diff -u -p -r1.30 Makefile.am --- Makefile.am 2001/07/27 10:08:04 1.30 +++ Makefile.am 2001/08/03 15:39:36 @@ -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 \ Index: array.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/array.C,v retrieving revision 1.42 diff -u -p -r1.42 array.C --- array.C 2001/08/01 09:18:21 1.42 +++ array.C 2001/08/03 15:39:36 @@ -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 & a 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,11 +89,7 @@ MathArray & MathArray::operator=(MathArr 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]; } @@ -121,10 +103,11 @@ MathInset * MathArray::prevInset(int pos 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 +122,30 @@ string MathArray::getString(int & pos) c 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,28 +207,19 @@ 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 { return prevInset(size()); @@ -267,12 +236,8 @@ void MathArray::dump2(ostream & os) cons 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 +250,8 @@ std::ostream & operator<<(std::ostream & 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 +268,8 @@ void MathArray::writeNormal(ostream & os 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: array.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/array.h,v retrieving revision 1.37 diff -u -p -r1.37 array.h --- array.h 2001/08/01 09:18:21 1.37 +++ array.h 2001/08/03 15:39:36 @@ -116,21 +116,14 @@ public: /// void setCode(int pos, MathTextCodes t); /// - bool isInset(int pos) const; - /// void write(std::ostream &, bool) const; /// void writeNormal(std::ostream &) const; /// 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: math_cursor.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_cursor.C,v retrieving revision 1.88 diff -u -p -r1.88 math_cursor.C --- math_cursor.C 2001/08/03 09:54:47 1.88 +++ math_cursor.C 2001/08/03 15:39:36 @@ -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(MathTextCode 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: math_cursor.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_cursor.h,v retrieving revision 1.40 diff -u -p -r1.40 math_cursor.h --- math_cursor.h 2001/08/01 16:48:06 1.40 +++ math_cursor.h 2001/08/03 15:39:36 @@ -99,7 +99,7 @@ public: /// bool plainLeft(); /// - bool plainRight(); + void plainRight(); /// void plainErase(); /// Index: math_inset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_inset.h,v retrieving revision 1.45 diff -u -p -r1.45 math_inset.h --- math_inset.h 2001/08/03 09:54:48 1.45 +++ math_inset.h 2001/08/03 15:39:36 @@ -175,10 +175,12 @@ 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 *); Index: math_matrixinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_matrixinset.C,v retrieving revision 1.38 diff -u -p -r1.38 math_matrixinset.C --- math_matrixinset.C 2001/08/02 09:59:09 1.38 +++ math_matrixinset.C 2001/08/03 15:39:36 @@ -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(); } Index: math_parser.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_parser.C,v retrieving revision 1.84 diff -u -p -r1.84 math_parser.C --- math_parser.C 2001/08/03 09:54:48 1.84 +++ math_parser.C 2001/08/03 15:39:36 @@ -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"; Index: xarray.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/xarray.C,v retrieving revision 1.11 diff -u -p -r1.11 xarray.C --- xarray.C 2001/08/01 09:18:21 1.11 +++ xarray.C 2001/08/03 15:39:36 @@ -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, in 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) con { 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,26 +77,23 @@ 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) {