mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-27 03:36:39 +00:00
iterators for MathArray; cosmetics;
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2459 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
ad6a378c33
commit
20effa2eb1
@ -25,24 +25,21 @@ MathArray::~MathArray()
|
|||||||
MathArray::MathArray(MathArray const & array)
|
MathArray::MathArray(MathArray const & array)
|
||||||
: bf_(array.bf_)
|
: bf_(array.bf_)
|
||||||
{
|
{
|
||||||
deep_copy(0, size());
|
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(0, size());
|
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) {
|
for (iterator it = from; it != to; ++it)
|
||||||
MathInset * p = bf_[pos]->clone();
|
*it = (*it)->clone();
|
||||||
//lyxerr << "cloning: '" << bf_[pos] << " to " << p << "'\n";
|
|
||||||
bf_[pos] = p;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -55,8 +52,8 @@ int MathArray::last() const
|
|||||||
void MathArray::substitute(MathMacro const & m)
|
void MathArray::substitute(MathMacro const & m)
|
||||||
{
|
{
|
||||||
MathArray tmp;
|
MathArray tmp;
|
||||||
for (int pos = 0; pos < size(); ++pos)
|
for (iterator it = begin(); it != end(); ++it)
|
||||||
bf_[pos]->substitute(tmp, m);
|
(*it)->substitute(tmp, m);
|
||||||
swap(tmp);
|
swap(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,40 +78,22 @@ MathInset const * MathArray::nextInset(int pos) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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());
|
bf_.insert(begin() + pos, array.begin(), array.end());
|
||||||
deep_copy(pos, pos + array.size());
|
deep_copy(begin() + pos, begin() + pos + array.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -176,9 +155,9 @@ void MathArray::erase(int pos)
|
|||||||
|
|
||||||
void MathArray::erase(int pos1, int pos2)
|
void MathArray::erase(int pos1, int pos2)
|
||||||
{
|
{
|
||||||
for (int pos = pos1; pos < pos2; ++pos)
|
for (iterator it = begin() + pos1; it != begin() + pos2; ++it)
|
||||||
delete bf_[pos];
|
delete *it;
|
||||||
bf_.erase(bf_.begin() + pos1, bf_.begin() + pos2);
|
bf_.erase(begin() + pos1, begin() + pos2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -190,15 +169,15 @@ MathInset * MathArray::back() const
|
|||||||
|
|
||||||
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 << ' ';
|
os << *it << ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MathArray::dump(ostream & os) const
|
void MathArray::dump(ostream & os) const
|
||||||
{
|
{
|
||||||
for (int pos = 0; pos < size(); ++pos)
|
for (const_iterator it = begin(); it != end(); ++it)
|
||||||
os << "<" << nextInset(pos) << ">";
|
os << "<" << *it << ">";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -211,8 +190,8 @@ std::ostream & operator<<(std::ostream & os, MathArray const & ar)
|
|||||||
|
|
||||||
void MathArray::write(ostream & os, bool fragile) const
|
void MathArray::write(ostream & os, bool fragile) const
|
||||||
{
|
{
|
||||||
for (int pos = 0; pos < size(); ++pos)
|
for (const_iterator it = begin(); it != end(); ++it)
|
||||||
nextInset(pos)->write(os, fragile);
|
(*it)->write(os, fragile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -229,8 +208,8 @@ void MathArray::writeNormal(ostream & os) const
|
|||||||
|
|
||||||
void MathArray::validate(LaTeXFeatures & features) const
|
void MathArray::validate(LaTeXFeatures & features) const
|
||||||
{
|
{
|
||||||
for (int pos = 0; pos < size(); ++pos)
|
for (const_iterator it = begin(); it != end(); ++it)
|
||||||
nextInset(pos)->validate(features);
|
(*it)->validate(features);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -244,3 +223,26 @@ void MathArray::pop_back()
|
|||||||
bf_.pop_back();
|
bf_.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
@ -40,6 +40,14 @@ class LaTeXFeatures;
|
|||||||
\version February 2001
|
\version February 2001
|
||||||
*/
|
*/
|
||||||
class MathArray {
|
class MathArray {
|
||||||
|
public:
|
||||||
|
///
|
||||||
|
typedef std::vector<MathInset *> buffer_type;
|
||||||
|
///
|
||||||
|
typedef buffer_type::const_iterator const_iterator;
|
||||||
|
///
|
||||||
|
typedef buffer_type::iterator iterator;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
MathArray();
|
MathArray();
|
||||||
@ -102,22 +110,22 @@ public:
|
|||||||
///
|
///
|
||||||
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 write(std::ostream &, bool) const;
|
||||||
///
|
///
|
||||||
void writeNormal(std::ostream &) const;
|
void writeNormal(std::ostream &) const;
|
||||||
///
|
///
|
||||||
void validate(LaTeXFeatures &) const;
|
void validate(LaTeXFeatures &) const;
|
||||||
|
///
|
||||||
|
const_iterator begin() const;
|
||||||
|
///
|
||||||
|
const_iterator end() const;
|
||||||
|
///
|
||||||
|
iterator begin();
|
||||||
|
///
|
||||||
|
iterator end();
|
||||||
private:
|
private:
|
||||||
///
|
///
|
||||||
typedef std::vector<MathInset *> buffer_type;
|
void deep_copy(iterator from, iterator to);
|
||||||
///
|
|
||||||
void deep_copy(int pos1, int pos2);
|
|
||||||
/// Buffer
|
/// Buffer
|
||||||
buffer_type bf_;
|
buffer_type bf_;
|
||||||
};
|
};
|
||||||
|
@ -789,11 +789,9 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
|
|||||||
mathcursor->left();
|
mathcursor->left();
|
||||||
}
|
}
|
||||||
mathcursor->clearLastCode();
|
mathcursor->clearLastCode();
|
||||||
// varcode = LM_TC_MIN;
|
|
||||||
} else if (c == '_' && varcode == LM_TC_TEX) {
|
} else if (c == '_' && varcode == LM_TC_TEX) {
|
||||||
mathcursor->insert(c, LM_TC_SPECIAL);
|
mathcursor->insert(c, LM_TC_SPECIAL);
|
||||||
mathcursor->clearLastCode();
|
mathcursor->clearLastCode();
|
||||||
// varcode = LM_TC_MIN;
|
|
||||||
} else if ('0' <= c && c <= '9' && (varcode == LM_TC_TEX||was_macro)) {
|
} else if ('0' <= c && c <= '9' && (varcode == LM_TC_TEX||was_macro)) {
|
||||||
mathcursor->macroModeOpen();
|
mathcursor->macroModeOpen();
|
||||||
mathcursor->clearLastCode();
|
mathcursor->clearLastCode();
|
||||||
|
@ -76,3 +76,9 @@ void MathCharInset::writeNormal(std::ostream & os) const
|
|||||||
{
|
{
|
||||||
os << char_;
|
os << char_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool MathCharInset::isRelOp() const
|
||||||
|
{
|
||||||
|
return char_ == '=' || char_ == '<' || char_ == '>';
|
||||||
|
}
|
||||||
|
@ -36,6 +36,8 @@ public:
|
|||||||
bool isCharInset() const { return true; }
|
bool isCharInset() const { return true; }
|
||||||
///
|
///
|
||||||
char getChar() const { return char_; }
|
char getChar() const { return char_; }
|
||||||
|
///
|
||||||
|
bool isRelOp() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// the character
|
/// the character
|
||||||
|
@ -861,6 +861,12 @@ void MathCursor::drawSelection(Painter & pain) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MathTextCodes MathCursor::nextCode() const
|
||||||
|
{
|
||||||
|
return (pos() == size()) ? LM_TC_MIN : nextInset()->code();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void MathCursor::handleFont(MathTextCodes t)
|
void MathCursor::handleFont(MathTextCodes t)
|
||||||
{
|
{
|
||||||
if (selection_) {
|
if (selection_) {
|
||||||
@ -869,11 +875,13 @@ void MathCursor::handleFont(MathTextCodes t)
|
|||||||
getSelection(i1, i2);
|
getSelection(i1, i2);
|
||||||
if (i1.idx_ == i2.idx_) {
|
if (i1.idx_ == i2.idx_) {
|
||||||
MathArray & ar = i1.cell();
|
MathArray & ar = i1.cell();
|
||||||
for (int pos = i1.pos_; pos != i2.pos_; ++pos)
|
for (int pos = i1.pos_; pos != i2.pos_; ++pos) {
|
||||||
if (isalnum(ar.getChar(pos))) {
|
MathInset * p = ar.nextInset(pos);
|
||||||
MathTextCodes c = ar.getCode(pos) == t ? LM_TC_VAR : t;
|
if (isalnum(p->getChar())) {
|
||||||
ar.setCode(pos, c);
|
MathTextCodes c = (p->code() == t) ? LM_TC_VAR : t;
|
||||||
|
p->code(c);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
|
lastcode_ = (lastcode_ == t) ? LM_TC_VAR : t;
|
||||||
@ -915,18 +923,6 @@ void MathCursor::getPos(int & x, int & y)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MathTextCodes MathCursor::nextCode() const
|
|
||||||
{
|
|
||||||
return array().getCode(pos());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
MathTextCodes MathCursor::prevCode() const
|
|
||||||
{
|
|
||||||
return array().getCode(pos() - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
MathInset * MathCursor::par() const
|
MathInset * MathCursor::par() const
|
||||||
{
|
{
|
||||||
return cursor().par_;
|
return cursor().par_;
|
||||||
|
@ -187,8 +187,6 @@ public:
|
|||||||
///
|
///
|
||||||
MathTextCodes nextCode() const;
|
MathTextCodes nextCode() const;
|
||||||
///
|
///
|
||||||
MathTextCodes prevCode() const;
|
|
||||||
///
|
|
||||||
char valign() const;
|
char valign() const;
|
||||||
///
|
///
|
||||||
char halign() const;
|
char halign() const;
|
||||||
|
@ -179,6 +179,8 @@ public:
|
|||||||
///
|
///
|
||||||
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; }
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -68,9 +68,9 @@ int getCols(short int type)
|
|||||||
// used for "intelligent splitting"
|
// used for "intelligent splitting"
|
||||||
int firstRelOp(MathArray const & array)
|
int firstRelOp(MathArray const & array)
|
||||||
{
|
{
|
||||||
for (int pos = 0; pos < array.size(); ++pos)
|
for (MathArray::const_iterator it = array.begin(); it != array.end(); ++it)
|
||||||
if (MathIsRelOp(array.getChar(pos), array.getCode(pos)))
|
if ((*it)->isRelOp())
|
||||||
return pos;
|
return it - array.begin();
|
||||||
return array.size();
|
return array.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,3 +52,9 @@ void MathSymbolInset::draw(Painter & pain, int x, int y) const
|
|||||||
|
|
||||||
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;
|
||||||
|
}
|
||||||
|
@ -23,6 +23,8 @@ public:
|
|||||||
void metrics(MathStyles st) const;
|
void metrics(MathStyles st) const;
|
||||||
///
|
///
|
||||||
void draw(Painter &, int x, int y) const;
|
void draw(Painter &, int x, int y) const;
|
||||||
|
///
|
||||||
|
bool isRelOp() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
///
|
///
|
||||||
|
@ -16,12 +16,6 @@ using std::endl;
|
|||||||
using std::max;
|
using std::max;
|
||||||
|
|
||||||
|
|
||||||
bool MathIsInset(MathTextCodes x)
|
|
||||||
{
|
|
||||||
return LM_TC_INSET == x;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool MathIsAlphaFont(MathTextCodes x)
|
bool MathIsAlphaFont(MathTextCodes x)
|
||||||
{
|
{
|
||||||
return LM_TC_VAR <= x && x <= LM_TC_TEXTRM;
|
return LM_TC_VAR <= x && x <= LM_TC_TEXTRM;
|
||||||
@ -741,18 +735,6 @@ MathStyles smallerStyleFrac(MathStyles st)
|
|||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
@ -32,10 +32,8 @@ int mathed_string_width(MathTextCodes type, MathStyles size, string const & s);
|
|||||||
int mathed_string_ascent(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);
|
int mathed_string_descent(MathTextCodes type, MathStyles size, string const & s);
|
||||||
|
|
||||||
bool MathIsInset(MathTextCodes x);
|
|
||||||
bool MathIsAlphaFont(MathTextCodes x);
|
bool MathIsAlphaFont(MathTextCodes x);
|
||||||
bool MathIsSymbol(MathTextCodes x);
|
bool MathIsSymbol(MathTextCodes x);
|
||||||
bool MathIsRelOp(unsigned char c, MathTextCodes f);
|
|
||||||
|
|
||||||
void drawStr(Painter & pain, MathTextCodes type, MathStyles siz,
|
void drawStr(Painter & pain, MathTextCodes type, MathStyles siz,
|
||||||
int x, int y, string const & s);
|
int x, int y, string const & s);
|
||||||
|
Loading…
Reference in New Issue
Block a user