]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathNest.C
make it compile again (hopefully)
[lyx.git] / src / mathed / InsetMathNest.C
index b23dc673d7ab2cb402690711501588e44b1b8eb9..2ca97cde51311f60c3e99cd6a0769f6ad1b3ff71 100644 (file)
@@ -44,6 +44,7 @@
 #include "dispatchresult.h"
 #include "funcrequest.h"
 #include "gettext.h"
+#include "lyxtext.h"
 #include "outputparams.h"
 #include "undo.h"
 
 
 #include <sstream>
 
+using lyx::CoordCache;
+using lyx::docstring;
+using lyx::odocstream;
+using lyx::Point;
+
 using lyx::cap::copySelection;
 using lyx::cap::grabAndEraseSelection;
 using lyx::cap::cutSelection;
@@ -93,8 +99,9 @@ MathArray const & InsetMathNest::cell(idx_type i) const
 }
 
 
-void InsetMathNest::cursorPos(CursorSlice const & sl, bool /*boundary*/,
-       int & x, int & y) const
+void InsetMathNest::cursorPos(BufferView const & bv,
+               CursorSlice const & sl, bool /*boundary*/,
+               int & x, int & y) const
 {
 // FIXME: This is a hack. Ideally, the coord cache should not store
 // absolute positions, but relative ones. This would mean to call
@@ -105,7 +112,8 @@ void InsetMathNest::cursorPos(CursorSlice const & sl, bool /*boundary*/,
 // absolute again when actually drawing the cursor. What a mess.
        BOOST_ASSERT(ptr_cmp(&sl.inset(), this));
        MathArray const & ar = sl.cell();
-       if (!theCoords.getArrays().has(&ar)) {
+       CoordCache const & coord_cache = bv.coordCache();
+       if (!coord_cache.getArrays().has(&ar)) {
                // this can (semi-)legally happen if we just created this cell
                // and it never has been drawn before. So don't ASSERT.
                //lyxerr << "no cached data for array " << &ar << endl;
@@ -113,15 +121,15 @@ void InsetMathNest::cursorPos(CursorSlice const & sl, bool /*boundary*/,
                y = 0;
                return;
        }
-       Point const pt = theCoords.getArrays().xy(&ar);
-       if (!theCoords.getInsets().has(this)) {
+       Point const pt = coord_cache.getArrays().xy(&ar);
+       if (!coord_cache.getInsets().has(this)) {
                // same as above
                //lyxerr << "no cached data for inset " << this << endl;
                x = 0;
                y = 0;
                return;
        }
-       Point const pt2 = theCoords.getInsets().xy(this);
+       Point const pt2 = coord_cache.getInsets().xy(this);
        //lyxerr << "retrieving position cache for MathArray "
        //      << pt.x_ << ' ' << pt.y_ << std::endl;
        x = pt.x_ - pt2.x_ + ar.pos2x(sl.pos());
@@ -201,13 +209,15 @@ bool InsetMathNest::idxLast(LCursor & cur) const
 
 void InsetMathNest::dump() const
 {
-       WriteStream os(lyxerr);
+       lyx::odocstringstream oss;
+       WriteStream os(oss);
        os << "---------------------------------------------\n";
        write(os);
        os << "\n";
        for (idx_type i = 0, n = nargs(); i != n; ++i)
                os << cell(i) << "\n";
        os << "---------------------------------------------\n";
+       lyxerr << lyx::to_utf8(oss.str());
 }
 
 
@@ -224,8 +234,9 @@ void InsetMathNest::draw(PainterInfo & pi, int x, int y) const
 
 void InsetMathNest::drawSelection(PainterInfo & pi, int x, int y) const
 {
+       BufferView & bv = *pi.base.bv;
        // this should use the x/y values given, not the cached values
-       LCursor & cur = pi.base.bv->cursor();
+       LCursor & cur = bv.cursor();
        if (!cur.selection())
                return;
        if (!ptr_cmp(&cur.inset(), this))
@@ -239,14 +250,15 @@ void InsetMathNest::drawSelection(PainterInfo & pi, int x, int y) const
 
        CursorSlice s1 = cur.selBegin();
        CursorSlice s2 = cur.selEnd();
+
        //lyxerr << "InsetMathNest::drawing selection: "
        //      << " s1: " << s1 << " s2: " << s2 << endl;
        if (s1.idx() == s2.idx()) {
                MathArray const & c = cell(s1.idx());
-               int x1 = c.xo() + c.pos2x(s1.pos());
-               int y1 = c.yo() - c.ascent();
-               int x2 = c.xo() + c.pos2x(s2.pos());
-               int y2 = c.yo() + c.descent();
+               int x1 = c.xo(bv) + c.pos2x(s1.pos());
+               int y1 = c.yo(bv) - c.ascent();
+               int x2 = c.xo(bv) + c.pos2x(s2.pos());
+               int y2 = c.yo(bv) + c.descent();
                pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
        //lyxerr << "InsetMathNest::drawing selection 3: "
        //      << " x1: " << x1 << " x2: " << x2
@@ -255,10 +267,10 @@ void InsetMathNest::drawSelection(PainterInfo & pi, int x, int y) const
                for (idx_type i = 0; i < nargs(); ++i) {
                        if (idxBetween(i, s1.idx(), s2.idx())) {
                                MathArray const & c = cell(i);
-                               int x1 = c.xo();
-                               int y1 = c.yo() - c.ascent();
-                               int x2 = c.xo() + c.width();
-                               int y2 = c.yo() + c.descent();
+                               int x1 = c.xo(bv);
+                               int y1 = c.yo(bv) - c.ascent();
+                               int x2 = c.xo(bv) + c.width();
+                               int y2 = c.yo(bv) + c.descent();
                                pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
                        }
                }
@@ -339,7 +351,7 @@ void InsetMathNest::normalize(NormalStream & os) const
 }
 
 
-int InsetMathNest::latex(Buffer const &, std::ostream & os,
+int InsetMathNest::latex(Buffer const &, odocstream & os,
                        OutputParams const & runparams) const
 {
        WriteStream wi(os, runparams.moving_arg, true);
@@ -424,8 +436,9 @@ void InsetMathNest::doDispatch(LCursor & cur, FuncRequest & cmd)
                size_t n = 0;
                istringstream is(lyx::to_utf8(cmd.argument()));
                is >> n;
-               string const selection = lyx::cap::getSelection(cur.buffer(), n);
-               cur.niceInsert(selection);
+               docstring const selection = lyx::cap::getSelection(cur.buffer(), n);
+               // FIXME UNICODE
+               cur.niceInsert(lyx::to_utf8(selection));
                cur.clearSelection(); // bug 393
                cur.bv().switchKeyMap();
                finishUndo();
@@ -665,7 +678,7 @@ void InsetMathNest::doDispatch(LCursor & cur, FuncRequest & cmd)
                if (cmd.argument().size() != 1) {
                        recordUndo(cur);
                        string const arg = lyx::to_utf8(cmd.argument());
-                       if (!interpret(cur, arg))
+                       if (!interpretString(cur, arg))
                                cur.insert(arg);
                        break;
                }
@@ -692,10 +705,7 @@ void InsetMathNest::doDispatch(LCursor & cur, FuncRequest & cmd)
                                cur.posLeft();
                                cur.pushLeft(*cur.nextInset());
                        }
-               // FIXME: Change to
-               // } else if (!interpret(cur, cmd.argument()[0])) {
-               // when interpret accepts UCS4 characters
-               } else if (!interpret(cur, lyx::to_utf8(cmd.argument()))) {
+               } else if (!interpretChar(cur, cmd.argument()[0])) {
                        cmd = FuncRequest(LFUN_FINISHED_RIGHT);
                        cur.undispatched();
                }
@@ -903,19 +913,19 @@ void InsetMathNest::doDispatch(LCursor & cur, FuncRequest & cmd)
        case LFUN_ERT_INSERT:
                // interpret this as if a backslash was typed
                recordUndo(cur, Undo::ATOMIC);
-               interpret(cur, '\\');
+               interpretChar(cur, '\\');
                break;
 
        case LFUN_MATH_SUBSCRIPT:
                // interpret this as if a _ was typed
                recordUndo(cur, Undo::ATOMIC);
-               interpret(cur, '_');
+               interpretChar(cur, '_');
                break;
 
        case LFUN_MATH_SUPERSCRIPT:
                // interpret this as if a ^ was typed
                recordUndo(cur, Undo::ATOMIC);
-               interpret(cur, '^');
+               interpretChar(cur, '^');
                break;
 
 // FIXME: We probably should swap parts of "math-insert" and "self-insert"
@@ -923,9 +933,9 @@ void InsetMathNest::doDispatch(LCursor & cur, FuncRequest & cmd)
 // math-insert only handles special math things like "matrix".
        case LFUN_MATH_INSERT: {
                recordUndo(cur, Undo::ATOMIC);
-               if (cmd.argument() == "^" || cmd.argument() == "_")
-                       interpret(cur, cmd.argument()[0]);
-               else
+               if (cmd.argument() == "^" || cmd.argument() == "_") {
+                       interpretChar(cur, cmd.argument()[0]);
+               else
                        cur.niceInsert(lyx::to_utf8(cmd.argument()));
                break;
                }
@@ -1073,7 +1083,7 @@ InsetBase * InsetMathNest::editXY(LCursor & cur, int x, int y)
        int idx_min = 0;
        int dist_min = 1000000;
        for (idx_type i = 0, n = nargs(); i != n; ++i) {
-               int const d = cell(i).dist(x, y);
+               int const d = cell(i).dist(cur.bv(), x, y);
                if (d < dist_min) {
                        dist_min = d;
                        idx_min = i;
@@ -1082,12 +1092,13 @@ InsetBase * InsetMathNest::editXY(LCursor & cur, int x, int y)
        MathArray & ar = cell(idx_min);
        cur.push(*this);
        cur.idx() = idx_min;
-       cur.pos() = ar.x2pos(x - ar.xo());
+       cur.pos() = ar.x2pos(x - ar.xo(cur.bv()));
+
        //lyxerr << "found cell : " << idx_min << " pos: " << cur.pos() << endl;
        if (dist_min == 0) {
                // hit inside cell
                for (pos_type i = 0, n = ar.size(); i < n; ++i)
-                       if (ar[i]->covers(x, y))
+                       if (ar[i]->covers(cur.bv(), x, y))
                                return ar[i].nucleus()->editXY(cur, x, y);
        }
        return this;
@@ -1104,9 +1115,9 @@ void InsetMathNest::lfunMousePress(LCursor & cur, FuncRequest & cmd)
        } else if (cmd.button() == mouse_button::button2) {
                MathArray ar;
                if (cur.selection())
-                       asArray(lyx::to_utf8(bv.cursor().selectionAsString(false)), ar);
+                       asArray(bv.cursor().selectionAsString(false), ar);
                else
-                       asArray(lyx::to_utf8(theSelection().get()), ar);
+                       asArray(theSelection().get(), ar);
 
                cur.insert(ar);
                bv.mouseSetCursor(cur);
@@ -1151,7 +1162,7 @@ void InsetMathNest::lfunMouseRelease(LCursor & cur, FuncRequest & cmd)
 }
 
 
-bool InsetMathNest::interpret(LCursor & cur, char c)
+bool InsetMathNest::interpretChar(LCursor & cur, lyx::char_type c)
 {
        //lyxerr << "interpret 2: '" << c << "'" << endl;
        string save_selection;
@@ -1174,7 +1185,7 @@ bool InsetMathNest::interpret(LCursor & cur, char c)
                }
 
                if (isalpha(c)) {
-                       cur.activeMacro()->setName(name + c);
+                       cur.activeMacro()->setName(name + lyx::to_ascii(docstring(1, c)));
                        return true;
                }
 
@@ -1195,16 +1206,16 @@ bool InsetMathNest::interpret(LCursor & cur, char c)
                                cur.niceInsert(MathAtom(new InsetMathComment));
                        } else if (c == '#') {
                                BOOST_ASSERT(cur.activeMacro());
-                               cur.activeMacro()->setName(name + c);
+                               cur.activeMacro()->setName(name + lyx::to_ascii(docstring(1, c)));
                        } else {
                                cur.backspace();
-                               cur.niceInsert(createInsetMath(string(1, c)));
+                               cur.niceInsert(createInsetMath(lyx::to_ascii(docstring(1, c))));
                        }
                        return true;
                }
 
                // One character big delimiters. The others are handled in
-               // the other interpret() method.
+               // interpretString().
                latexkeys const * l = in_word_set(name.substr(1));
                if (name[0] == '\\' && l && l->inset == "big") {
                        string delim;
@@ -1216,7 +1227,7 @@ bool InsetMathNest::interpret(LCursor & cur, char c)
                                delim = "\\}";
                                break;
                        default:
-                               delim = string(1, c);
+                               delim = lyx::to_ascii(docstring(1, c));
                                break;
                        }
                        if (InsetMathBig::isBigInsetDelim(delim)) {
@@ -1238,7 +1249,7 @@ bool InsetMathNest::interpret(LCursor & cur, char c)
                if (c == '{')
                        cur.niceInsert(MathAtom(new InsetMathBrace));
                else if (c != ' ')
-                       interpret(cur, c);
+                       interpretChar(cur, c);
                return true;
        }
 
@@ -1311,7 +1322,7 @@ bool InsetMathNest::interpret(LCursor & cur, char c)
 
        if (c == '{' || c == '}' || c == '&' || c == '$' || c == '#' ||
            c == '%' || c == '_' || c == '^') {
-               cur.niceInsert(createInsetMath(string(1, c)));
+               cur.niceInsert(createInsetMath(lyx::to_ascii(docstring(1, c))));
                return true;
        }
 
@@ -1327,7 +1338,7 @@ bool InsetMathNest::interpret(LCursor & cur, char c)
 }
 
 
-bool InsetMathNest::interpret(LCursor & cur, string const & str)
+bool InsetMathNest::interpretString(LCursor & cur, string const & str)
 {
        // Create a InsetMathBig from cur.cell()[cur.pos() - 1] and t if
        // possible
@@ -1359,7 +1370,7 @@ bool InsetMathNest::script(LCursor & cur, bool up, string const &
                if (up)
                        cur.niceInsert(createInsetMath("mathcircumflex"));
                else
-                       interpret(cur, '_');
+                       interpretChar(cur, '_');
                return true;
        }