]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathNest.C
make it compile again (hopefully)
[lyx.git] / src / mathed / InsetMathNest.C
index 25569afe88ff7ac0e355be99afbd0af93b05f92b..2ca97cde51311f60c3e99cd6a0769f6ad1b3ff71 100644 (file)
 
 #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;
@@ -95,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
@@ -107,7 +112,7 @@ 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();
-       CoordCache & coord_cache = sl.text()->bv()->coordCache();
+       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.
@@ -204,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());
 }
 
 
@@ -344,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);
@@ -671,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;
                }
@@ -698,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();
                }
@@ -909,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"
@@ -929,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;
                }
@@ -1111,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);
@@ -1158,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;
@@ -1181,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;
                }
 
@@ -1202,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;
@@ -1223,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)) {
@@ -1245,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;
        }
 
@@ -1318,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;
        }
 
@@ -1334,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
@@ -1366,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;
        }