13 files changed:
MathArray::MathArray(MathArray const & array)
: bf_(array.bf_)
{
MathArray::MathArray(MathArray const & array)
: bf_(array.bf_)
{
+ deep_copy(begin(), end());
}
MathArray::MathArray(MathArray const & array, int from, int to)
}
MathArray::MathArray(MathArray const & array, int from, int to)
- : bf_(array.bf_.begin() + from, array.bf_.begin() + to)
+ : bf_(array.begin() + from, array.begin() + to)
+ deep_copy(begin(), end());
-void MathArray::deep_copy(int pos1, int pos2)
+void MathArray::deep_copy(iterator from, iterator to)
- for (int pos = pos1; pos < pos2; ++pos) {
- MathInset * p = bf_[pos]->clone();
- //lyxerr << "cloning: '" << bf_[pos] << " to " << p << "'\n";
- bf_[pos] = p;
- }
+ for (iterator it = from; it != to; ++it)
+ *it = (*it)->clone();
void MathArray::substitute(MathMacro const & m)
{
MathArray tmp;
void MathArray::substitute(MathMacro const & m)
{
MathArray tmp;
- for (int pos = 0; pos < size(); ++pos)
- bf_[pos]->substitute(tmp, m);
+ for (iterator it = begin(); it != end(); ++it)
+ (*it)->substitute(tmp, m);
-unsigned char MathArray::getChar(int pos) const
-{
- return (pos == size()) ? 0 : (bf_[pos]->getChar());
-}
-
-
-MathTextCodes MathArray::getCode(int pos) const
-{
- return pos < size() ? (bf_[pos]->code()) : LM_TC_MIN;
-}
-
-
-void MathArray::setCode(int pos, MathTextCodes t)
-{
- bf_[pos]->code(t);
-}
-
-
void MathArray::insert(int pos, MathInset * p)
{
void MathArray::insert(int pos, MathInset * p)
{
- bf_.insert(bf_.begin() + pos, p);
+ bf_.insert(begin() + pos, p);
}
void MathArray::insert(int pos, unsigned char b, MathTextCodes t)
{
}
void MathArray::insert(int pos, unsigned char b, MathTextCodes t)
{
- bf_.insert(bf_.begin() + pos, new MathCharInset(b, t));
+ bf_.insert(begin() + pos, new MathCharInset(b, t));
}
void MathArray::insert(int pos, MathArray const & array)
{
}
void MathArray::insert(int pos, MathArray const & array)
{
- bf_.insert(bf_.begin() + pos, array.bf_.begin(), array.bf_.end());
- deep_copy(pos, pos + array.size());
+ bf_.insert(begin() + pos, array.begin(), array.end());
+ deep_copy(begin() + pos, begin() + pos + array.size());
void MathArray::erase(int pos1, int pos2)
{
void MathArray::erase(int pos1, int pos2)
{
- for (int pos = pos1; pos < pos2; ++pos)
- delete bf_[pos];
- bf_.erase(bf_.begin() + pos1, bf_.begin() + pos2);
+ for (iterator it = begin() + pos1; it != begin() + pos2; ++it)
+ delete *it;
+ bf_.erase(begin() + pos1, begin() + pos2);
void MathArray::dump2(ostream & os) const
{
void MathArray::dump2(ostream & os) const
{
- for (buffer_type::const_iterator it = bf_.begin(); it != bf_.end(); ++it)
+ for (const_iterator it = begin(); it != end(); ++it)
os << *it << ' ';
}
void MathArray::dump(ostream & os) const
{
os << *it << ' ';
}
void MathArray::dump(ostream & os) const
{
- for (int pos = 0; pos < size(); ++pos)
- os << "<" << nextInset(pos) << ">";
+ for (const_iterator it = begin(); it != end(); ++it)
+ os << "<" << *it << ">";
void MathArray::write(ostream & os, bool fragile) const
{
void MathArray::write(ostream & os, bool fragile) const
{
- for (int pos = 0; pos < size(); ++pos)
- nextInset(pos)->write(os, fragile);
+ for (const_iterator it = begin(); it != end(); ++it)
+ (*it)->write(os, fragile);
void MathArray::validate(LaTeXFeatures & features) const
{
void MathArray::validate(LaTeXFeatures & features) const
{
- for (int pos = 0; pos < size(); ++pos)
- nextInset(pos)->validate(features);
+ for (const_iterator it = begin(); it != end(); ++it)
+ (*it)->validate(features);
+
+MathArray::const_iterator MathArray::begin() const
+{
+ return bf_.begin();
+}
+
+
+MathArray::const_iterator MathArray::end() const
+{
+ return bf_.end();
+}
+
+
+MathArray::iterator MathArray::begin()
+{
+ return bf_.begin();
+}
+
+
+MathArray::iterator MathArray::end()
+{
+ return bf_.end();
+}
\version February 2001
*/
class MathArray {
\version February 2001
*/
class MathArray {
+public:
+ ///
+ typedef std::vector<MathInset *> buffer_type;
+ ///
+ typedef buffer_type::const_iterator const_iterator;
+ ///
+ typedef buffer_type::iterator iterator;
+
///
MathInset const * nextInset(int pos) const;
///
///
MathInset const * nextInset(int pos) const;
///
- unsigned char getChar(int pos) const;
- ///
- MathTextCodes getCode(int pos) const;
- ///
- void setCode(int pos, MathTextCodes t);
- ///
void write(std::ostream &, bool) const;
///
void writeNormal(std::ostream &) const;
///
void validate(LaTeXFeatures &) const;
void write(std::ostream &, bool) const;
///
void writeNormal(std::ostream &) const;
///
void validate(LaTeXFeatures &) const;
- typedef std::vector<MathInset *> buffer_type;
+ const_iterator begin() const;
+ ///
+ const_iterator end() const;
+ ///
+ iterator begin();
+ ///
+ iterator end();
+private:
- void deep_copy(int pos1, int pos2);
+ void deep_copy(iterator from, iterator to);
/// Buffer
buffer_type bf_;
};
/// Buffer
buffer_type bf_;
};
mathcursor->left();
}
mathcursor->clearLastCode();
mathcursor->left();
}
mathcursor->clearLastCode();
- // varcode = LM_TC_MIN;
} else if (c == '_' && varcode == LM_TC_TEX) {
mathcursor->insert(c, LM_TC_SPECIAL);
mathcursor->clearLastCode();
} else if (c == '_' && varcode == LM_TC_TEX) {
mathcursor->insert(c, LM_TC_SPECIAL);
mathcursor->clearLastCode();
- // varcode = LM_TC_MIN;
} else if ('0' <= c && c <= '9' && (varcode == LM_TC_TEX||was_macro)) {
mathcursor->macroModeOpen();
mathcursor->clearLastCode();
} else if ('0' <= c && c <= '9' && (varcode == LM_TC_TEX||was_macro)) {
mathcursor->macroModeOpen();
mathcursor->clearLastCode();
+
+
+bool MathCharInset::isRelOp() const
+{
+ return char_ == '=' || char_ == '<' || char_ == '>';
+}
bool isCharInset() const { return true; }
///
char getChar() const { return char_; }
bool isCharInset() const { return true; }
///
char getChar() const { return char_; }
+ ///
+ bool isRelOp() const;
private:
/// the character
private:
/// the character
+MathTextCodes MathCursor::nextCode() const
+{
+ return (pos() == size()) ? LM_TC_MIN : nextInset()->code();
+}
+
+
void MathCursor::handleFont(MathTextCodes t)
{
if (selection_) {
void MathCursor::handleFont(MathTextCodes t)
{
if (selection_) {
getSelection(i1, i2);
if (i1.idx_ == i2.idx_) {
MathArray & ar = i1.cell();
getSelection(i1, i2);
if (i1.idx_ == i2.idx_) {
MathArray & ar = i1.cell();
- 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);
+ for (int pos = i1.pos_; pos != i2.pos_; ++pos) {
+ MathInset * p = ar.nextInset(pos);
+ if (isalnum(p->getChar())) {
+ MathTextCodes c = (p->code() == t) ? LM_TC_VAR : t;
+ p->code(c);
}
} else
lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
}
} else
lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
-MathTextCodes MathCursor::nextCode() const
-{
- return array().getCode(pos());
-}
-
-
-MathTextCodes MathCursor::prevCode() const
-{
- return array().getCode(pos() - 1);
-}
-
-
MathInset * MathCursor::par() const
{
return cursor().par_;
MathInset * MathCursor::par() const
{
return cursor().par_;
///
MathTextCodes nextCode() const;
///
///
MathTextCodes nextCode() const;
///
- MathTextCodes prevCode() const;
- ///
char valign() const;
///
char halign() const;
char valign() const;
///
char halign() const;
///
virtual bool isActive() const { return nargs() > 0; }
///
///
virtual bool isActive() const { return nargs() > 0; }
///
+ virtual bool isRelOp() const { return false; }
+ ///
virtual char getChar() const { return 0; }
///
virtual char getChar() const { return 0; }
///
// used for "intelligent splitting"
int firstRelOp(MathArray const & array)
{
// used for "intelligent splitting"
int firstRelOp(MathArray const & array)
{
- for (int pos = 0; pos < array.size(); ++pos)
- if (MathIsRelOp(array.getChar(pos), array.getCode(pos)))
- return pos;
+ for (MathArray::const_iterator it = array.begin(); it != array.end(); ++it)
+ if ((*it)->isRelOp())
+ return it - array.begin();
drawStr(pain, code_, size_, x, y, ssym_);
}
drawStr(pain, code_, size_, x, y, ssym_);
}
+
+
+bool MathSymbolInset::isRelOp() const
+{
+ return sym_->id == LM_leq || sym_->id == LM_geq;
+}
void metrics(MathStyles st) const;
///
void draw(Painter &, int x, int y) const;
void metrics(MathStyles st) const;
///
void draw(Painter &, int x, int y) const;
+ ///
+ bool isRelOp() const;
-bool MathIsInset(MathTextCodes x)
-{
- return LM_TC_INSET == x;
-}
-
-
bool MathIsAlphaFont(MathTextCodes x)
{
return LM_TC_VAR <= x && x <= LM_TC_TEXTRM;
bool MathIsAlphaFont(MathTextCodes x)
{
return LM_TC_VAR <= x && x <= LM_TC_TEXTRM;
-bool MathIsRelOp(unsigned char c, MathTextCodes f)
-{
- if (f == LM_TC_BOP && (c == '=' || c == '<' || c == '>'))
- return true;
-#ifndef WITH_WARNINGS
-#warning implement me properly
-#endif
- if (f == LM_TC_SYMB && (c == LM_leq || c == LM_geq))
- return true;
- return false;
-}
-
void math_font_max_dim(MathTextCodes code, MathStyles siz, int & asc, int & des)
{
void math_font_max_dim(MathTextCodes code, MathStyles siz, int & asc, int & des)
{
int mathed_string_ascent(MathTextCodes type, MathStyles size, string const & s);
int mathed_string_descent(MathTextCodes type, MathStyles size, string const & s);
int mathed_string_ascent(MathTextCodes type, MathStyles size, string const & s);
int mathed_string_descent(MathTextCodes type, MathStyles size, string const & s);
-bool MathIsInset(MathTextCodes x);
bool MathIsAlphaFont(MathTextCodes x);
bool MathIsSymbol(MathTextCodes x);
bool MathIsAlphaFont(MathTextCodes x);
bool MathIsSymbol(MathTextCodes x);
-bool MathIsRelOp(unsigned char c, MathTextCodes f);
void drawStr(Painter & pain, MathTextCodes type, MathStyles siz,
int x, int y, string const & s);
void drawStr(Painter & pain, MathTextCodes type, MathStyles siz,
int x, int y, string const & s);