]> git.lyx.org Git - features.git/blobdiff - src/mathed/math_cursor.C
Replace LString.h with support/std_string.h,
[features.git] / src / mathed / math_cursor.C
index 450d16614f6cbe7e9f3cee0d6463b72f36bdcf43..96fdc1c7d9c7bd956f292ff63797cb143159b7d3 100644 (file)
@@ -1,41 +1,30 @@
-/*
- *  File:        math_cursor.C
- *  Purpose:     Interaction for mathed
- *  Author:      Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
- *  Created:     January 1996
- *  Description: Math interaction for a WYSIWYG math editor.
+/**
+ * \file math_cursor.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *  Dependencies: Xlib, XForms
+ * \author Alejandro Aguilar Sierra
+ * \author André Pönitz
  *
- *  Copyright: 1996, Alejandro Aguilar Sierra
- *
- *   Version: 0.8beta, Math & Lyx project.
- *
- *   You are free to use and modify this code under the terms of
- *   the GNU General Public Licence version 2 or later.
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
+
 #include <lyxrc.h>
 
-#include "support/lstrings.h"
 #include "support/LAssert.h"
 #include "support/limited_stack.h"
 #include "debug.h"
-#include "Lsstream.h"
-#include "frontends/Painter.h"
+#include "support/std_sstream.h"
 #include "math_cursor.h"
 #include "formulabase.h"
 #include "funcrequest.h"
-#include "math_autocorrect.h"
 #include "math_braceinset.h"
 #include "math_commentinset.h"
 #include "math_charinset.h"
-#include "math_extern.h"
 #include "math_factory.h"
-#include "math_fontinset.h"
 #include "math_gridinset.h"
-#include "math_iterator.h"
 #include "math_macroarg.h"
 #include "math_macrotemplate.h"
 #include "math_mathmlstream.h"
 #include "math_support.h"
 #include "math_unknowninset.h"
 
-#include <algorithm>
-#include <cctype>
 
 //#define FILEDEBUG 1
 
+using namespace lyx::support;
+
 using std::endl;
 using std::min;
 using std::max;
@@ -86,7 +75,7 @@ void MathCursor::push(MathAtom & t)
 
 void MathCursor::pushLeft(MathAtom & t)
 {
-       //lyxerr << "Entering atom " << t << " left\n";
+       //lyxerr << "Entering atom " << t << " left" << endl;
        push(t);
        t->idxFirst(idx(), pos());
 }
@@ -94,7 +83,7 @@ void MathCursor::pushLeft(MathAtom & t)
 
 void MathCursor::pushRight(MathAtom & t)
 {
-       //lyxerr << "Entering atom " << t << " right\n";
+       //lyxerr << "Entering atom " << t << " right" << endl;
        posLeft();
        push(t);
        t->idxLast(idx(), pos());
@@ -103,7 +92,7 @@ void MathCursor::pushRight(MathAtom & t)
 
 bool MathCursor::popLeft()
 {
-       //lyxerr << "Leaving atom to the left\n";
+       //lyxerr << "Leaving atom to the left" << endl;
        if (depth() <= 1) {
                if (depth() == 1)
                        inset()->notifyCursorLeaves(idx());
@@ -117,7 +106,7 @@ bool MathCursor::popLeft()
 
 bool MathCursor::popRight()
 {
-       //lyxerr << "Leaving atom "; inset()->write(cerr, false); cerr << " right\n";
+       //lyxerr << "Leaving atom "; inset()->write(cerr, false); cerr << " right" << endl;
        if (depth() <= 1) {
                if (depth() == 1)
                        inset()->notifyCursorLeaves(idx());
@@ -326,14 +315,14 @@ void MathCursor::plainErase()
 
 void MathCursor::markInsert()
 {
-       //lyxerr << "inserting mark\n";
+       //lyxerr << "inserting mark" << endl;
        array().insert(pos(), MathAtom(new MathCharInset(0)));
 }
 
 
 void MathCursor::markErase()
 {
-       //lyxerr << "deleting mark\n";
+       //lyxerr << "deleting mark" << endl;
        array().erase(pos());
 }
 
@@ -356,7 +345,7 @@ void MathCursor::insert2(string const & str)
 
 void MathCursor::insert(string const & str)
 {
-       //lyxerr << "inserting '" << str << "'\n";
+       //lyxerr << "inserting '" << str << "'" << endl;
        selClearOrDel();
        for (string::const_iterator it = str.begin(); it != str.end(); ++it)
                plainInsert(MathAtom(new MathCharInset(*it)));
@@ -365,7 +354,7 @@ void MathCursor::insert(string const & str)
 
 void MathCursor::insert(char c)
 {
-       //lyxerr << "inserting '" << c << "'\n";
+       //lyxerr << "inserting '" << c << "'" << endl;
        selClearOrDel();
        plainInsert(MathAtom(new MathCharInset(c)));
 }
@@ -526,12 +515,12 @@ void MathCursor::macroModeClose()
        if (s == "\\")
                return;
 
-       string name = s.substr(1);
+       string const name = s.substr(1);
 
        // prevent entering of recursive macros
-       if (formula()->lyxCode() == Inset::MATHMACRO_CODE
+       if (formula()->lyxCode() == InsetOld::MATHMACRO_CODE
                        && formula()->getInsetName() == name)
-               lyxerr << "can't enter recursive macro\n";
+               lyxerr << "can't enter recursive macro" << endl;
 
        niceInsert(createMathInset(name));
 }
@@ -579,7 +568,7 @@ void MathCursor::selDel()
 }
 
 
-void MathCursor::selPaste(int n)
+void MathCursor::selPaste(size_t n)
 {
        dump("selPaste");
        selClearOrDel();
@@ -836,28 +825,28 @@ bool MathCursor::hasNextAtom() const
 
 MathAtom const & MathCursor::prevAtom() const
 {
-       lyx::Assert(pos() > 0);
+       Assert(pos() > 0);
        return array()[pos() - 1];
 }
 
 
 MathAtom & MathCursor::prevAtom()
 {
-       lyx::Assert(pos() > 0);
+       Assert(pos() > 0);
        return array()[pos() - 1];
 }
 
 
 MathAtom const & MathCursor::nextAtom() const
 {
-       lyx::Assert(pos() < size());
+       Assert(pos() < size());
        return array()[pos()];
 }
 
 
 MathAtom & MathCursor::nextAtom()
 {
-       lyx::Assert(pos() < size());
+       Assert(pos() < size());
        return array()[pos()];
 }
 
@@ -867,12 +856,12 @@ MathArray & MathCursor::array() const
        static MathArray dummy;
 
        if (idx() >= inset()->nargs()) {
-               lyxerr << "############  idx_ " << idx() << " not valid\n";
+               lyxerr << "############  idx_ " << idx() << " not valid" << endl;
                return dummy;
        }
 
        if (depth() == 0) {
-               lyxerr << "############  depth() == 0 not valid\n";
+               lyxerr << "############  depth() == 0 not valid" << endl;
                return dummy;
        }
 
@@ -923,14 +912,14 @@ void MathCursor::getSelection(CursorPos & i1, CursorPos & i2) const
 
 CursorPos & MathCursor::cursor()
 {
-       lyx::Assert(depth());
+       Assert(depth());
        return Cursor_.back();
 }
 
 
 CursorPos const & MathCursor::cursor() const
 {
-       lyx::Assert(depth());
+       Assert(depth());
        return Cursor_.back();
 }
 
@@ -959,7 +948,7 @@ bool MathCursor::goUpDown(bool up)
                        push(nextAtom());
                        idx() = up; // the superscript has index 1
                        pos() = size();
-                       ///lyxerr << "updown: handled by scriptinset to the left\n";
+                       ///lyxerr << "updown: handled by scriptinset to the left" << endl;
                        return true;
                }
        }
@@ -971,7 +960,7 @@ bool MathCursor::goUpDown(bool up)
                        push(nextAtom());
                        idx() = up;
                        pos() = 0;
-                       ///lyxerr << "updown: handled by scriptinset to the right\n";
+                       ///lyxerr << "updown: handled by scriptinset to the right" << endl;
                        return true;
                }
        }
@@ -986,13 +975,13 @@ bool MathCursor::goUpDown(bool up)
        //else
        //      ylow = yo + 4;
        //if (bruteFind(xo, yo, xlow, xhigh, ylow, yhigh)) {
-       //      lyxerr << "updown: handled by brute find in the same cell\n";
+       //      lyxerr << "updown: handled by brute find in the same cell" << endl;
        //      return true;
        //}
 
        // try to find an inset that knows better then we
        while (1) {
-               ///lyxerr << "updown: We are in " << *inset() << " idx: " << idx() << '\n';
+               ///lyxerr << "updown: We are in " << *inset() << " idx: " << idx() << endl;
                // ask inset first
                if (inset()->idxUpDown(idx(), pos(), up, targetx_)) {
                        // try to find best position within this inset
@@ -1002,7 +991,7 @@ bool MathCursor::goUpDown(bool up)
                }
 
                // no such inset found, just take something "above"
-               ///lyxerr << "updown: handled by strange case\n";
+               ///lyxerr << "updown: handled by strange case" << endl;
                if (!popLeft())
                        return
                                bruteFind(xo, yo,
@@ -1147,7 +1136,7 @@ bool MathCursor::script(bool up)
 
 bool MathCursor::interpret(char c)
 {
-       //lyxerr << "interpret 2: '" << c << "'\n";
+       //lyxerr << "interpret 2: '" << c << "'" << endl;
        targetx_ = -1; // "no target"
        if (inMacroArgMode()) {
                --pos();
@@ -1166,7 +1155,7 @@ bool MathCursor::interpret(char c)
        // handle macroMode
        if (inMacroMode()) {
                string name = macroName();
-               //lyxerr << "interpret name: '" << name << "'\n";
+               //lyxerr << "interpret name: '" << name << "'" << endl;
 
                if (isalpha(c)) {
                        activeMacro()->setName(activeMacro()->name() + c);
@@ -1219,7 +1208,7 @@ bool MathCursor::interpret(char c)
        selClearOrDel();
 
        if (c == '\\') {
-               //lyxerr << "starting with macro\n";
+               //lyxerr << "starting with macro" << endl;
                insert(MathAtom(new MathUnknownInset("\\", false)));
                return true;
        }
@@ -1403,7 +1392,7 @@ CursorPos MathCursor::normalAnchor() const
 {
        if (Anchor_.size() < depth()) {
                Anchor_ = Cursor_;
-               lyxerr << "unusual Anchor size\n";
+               lyxerr << "unusual Anchor size" << endl;
        }
        //lyx::Assert(Anchor_.size() >= cursor.depth());
        // use Anchor on the same level as Cursor