- int i, imax;
- MathedXIter * item;
-
- MathStackXIter(int n = MAX_STACK_ITEMS): imax(n) {
- item = new MathedXIter[imax];
- i = 0;
- }
-
- MathStackXIter(MathStackXIter & stk);
-
- ~MathStackXIter() {
- delete[] item;
- }
-
- void push(MathedXIter ** a) {
- *a = &item[i++];
- }
-
- MathedXIter * pop() {
- --i;
- return &item[i - 1];
- }
-
- MathedXIter * Item(int idx) {
- return (idx + 1 <= i) ? &item[i - idx - 1] : 0;
- }
-
- void Reset() {
- i = 0;
- }
-
- bool Full() {
- return i >= MAX_STACK_ITEMS;
- }
-
- bool Empty() {
- return i <= 1;
- }
-
- int Level() { return i; }
-
-} mathstk, *selstk = 0;
-
-
-MathStackXIter::MathStackXIter(MathStackXIter & stk)
+public:
+ enum type {MATHSTK, SELSTK};
+
+private:
+ std::vector<MathedXIter> item;
+ int pos_;
+ type id_;
+
+
+public:
+
+ MathStackXIter(type id)
+ : item(MAX_STACK_ITEMS), pos_(-1), id_(id) {
+ }
+
+ MathedXIter * push() {
+ //dump();
+ ++pos_;
+ return &item[pos_];
+ }
+
+ MathedXIter * pop() {
+ //dump();
+ item[pos_] = MathedXIter();
+ --pos_;
+ return &item[pos_];
+ }
+
+ MathedXIter * Item(int idx) {
+ if (idx > pos_)
+ lyxerr << "Wrong index: " << idx << " pos_: " << pos_ << endl;
+ return &item[pos_ - idx];
+ }
+
+ void Reset() {
+ pos_ = -1;
+ }
+
+ bool Full() {
+ return pos_ >= MAX_STACK_ITEMS - 2;
+ }
+
+ bool empty() {
+ return pos_ <= 0;
+ }
+
+ MathParInset * outer() {
+ return empty() ? 0 : item[0].getPar();
+ }
+
+ int Level() {
+ return pos_;
+ }
+
+ MathParInset * parInset(int i) {
+ return pos_ < 0 ? 0 : item[i].getPar();
+ }
+
+
+ void dump() {
+ lyxerr << "\n------------- MathStack ------------\n";
+ for (int i = 0; i < pos_ + 3; ++i) {
+ lyxerr << "pos: " << i << " par: "
+ << item[i].getPar() << " data: '"
+ << *item[i].GetData() << "'" << endl;
+ }
+ lyxerr << "------------- MathStack ------------\n";
+ }
+
+};
+
+MathStackXIter mathstk = MathStackXIter(MathStackXIter::MATHSTK);
+MathStackXIter selstk = MathStackXIter(MathStackXIter::SELSTK);
+
+} // namespace anon
+
+
+extern MathedCursor * mathcursor;
+
+bool is_mathcursor_inside(MathParInset * p)