]> git.lyx.org Git - lyx.git/blobdiff - src/text3.C
compilation fix
[lyx.git] / src / text3.C
index bc341780e3201e93567f173ea76ddc6e12a774fa..9ddee5cf60f2574b5ce4fd8a2e52492ee0aa6687 100644 (file)
@@ -32,6 +32,7 @@
 #include "gettext.h"
 #include "intl.h"
 #include "language.h"
+#include "LyXAction.h"
 #include "lyxfunc.h"
 #include "lyxlex.h"
 #include "lyxrc.h"
@@ -54,7 +55,7 @@
 
 #include "support/lstrings.h"
 #include "support/lyxlib.h"
-#include "support/tostr.h"
+#include "support/convert.h"
 
 #include "mathed/math_hullinset.h"
 #include "mathed/math_macrotemplate.h"
@@ -70,8 +71,6 @@ using lyx::cap::pasteSelection;
 using lyx::cap::replaceSelection;
 
 using lyx::support::isStrUnsignedInt;
-using lyx::support::strToUnsignedInt;
-using lyx::support::atoi;
 using lyx::support::token;
 
 using std::endl;
@@ -253,7 +252,7 @@ void LyXText::gotoInset(LCursor & cur, InsetBase_code code, bool same_content)
 }
 
 
-void LyXText::cursorPrevious(LCursor & cur)
+bool LyXText::cursorPrevious(LCursor & cur)
 {
        pos_type cpos = cur.pos();
        lyx::pit_type cpar = cur.pit();
@@ -261,36 +260,38 @@ void LyXText::cursorPrevious(LCursor & cur)
        int x = cur.x_target();
 
        setCursorFromCoordinates(cur, x, 0);
-       cursorUp(cur);
+       bool updated = cursorUp(cur);
 
        if (cpar == cur.pit() && cpos == cur.pos()) {
                // we have a row which is taller than the workarea. The
                // simplest solution is to move to the previous row instead.
-               cursorUp(cur);
+               updated |= cursorUp(cur);
        }
 
        cur.bv().updateScrollbar();
        finishUndo();
+       return updated;
 }
 
 
-void LyXText::cursorNext(LCursor & cur)
+bool LyXText::cursorNext(LCursor & cur)
 {
        pos_type cpos = cur.pos();
        lyx::pit_type cpar = cur.pit();
 
        int x = cur.x_target();
        setCursorFromCoordinates(cur, x, cur.bv().workHeight() - 1);
-       cursorDown(cur);
+       bool updated = cursorDown(cur);
 
        if (cpar == cur.pit() && cpos == cur.pos()) {
                // we have a row which is taller than the workarea. The
                // simplest solution is to move to the next row instead.
-               cursorDown(cur);
+               updated |= cursorDown(cur);
        }
 
        cur.bv().updateScrollbar();
        finishUndo();
+       return updated;
 }
 
 
@@ -355,13 +356,13 @@ bool LyXText::isRTL(Paragraph const & par) const
 void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
 {
        lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
-       //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
+       lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
 
        BOOST_ASSERT(cur.text() == this);
        BufferView * bv = &cur.bv();
-       CursorSlice sl = cur.top();
+       CursorSlice oldTopSlice = cur.top();
        bool sel = cur.selection();
-       bool moving = false;
+       bool needsUpdate = !lyxaction.funcHasFlag(cmd.action, LyXAction::NoUpdate);
 
        switch (cmd.action) {
 
@@ -405,29 +406,27 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                break;
 
        case LFUN_WORDRIGHT:
-               moving = true;
                if (!cur.mark())
                        cur.clearSelection();
                if (isRTL(cur.paragraph()))
-                       cursorLeftOneWord(cur);
+                       needsUpdate = cursorLeftOneWord(cur);
                else
-                       cursorRightOneWord(cur);
+                       needsUpdate = cursorRightOneWord(cur);
                finishChange(cur, false);
                break;
 
        case LFUN_WORDLEFT:
-               moving = true;
                if (!cur.mark())
                        cur.clearSelection();
                if (isRTL(cur.paragraph()))
-                       cursorRightOneWord(cur);
+                       needsUpdate = cursorRightOneWord(cur);
                else
-                       cursorLeftOneWord(cur);
+                       needsUpdate = cursorLeftOneWord(cur);
                finishChange(cur, false);
                break;
 
        case LFUN_BEGINNINGBUF:
-               if (cur.size() == 1) {
+               if (cur.depth() == 1) {
                        if (!cur.mark())
                                cur.clearSelection();
                        cursorTop(cur);
@@ -438,7 +437,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                break;
 
        case LFUN_BEGINNINGBUFSEL:
-               if (cur.size() == 1) {
+               if (cur.depth() == 1) {
                        if (!cur.selection())
                                cur.resetAnchor();
                        cursorTop(cur);
@@ -449,7 +448,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                break;
 
        case LFUN_ENDBUF:
-               if (cur.size() == 1) {
+               if (cur.depth() == 1) {
                        if (!cur.mark())
                                cur.clearSelection();
                        cursorBottom(cur);
@@ -458,9 +457,9 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                        cur.undispatched();
                }
                break;
-               
+
        case LFUN_ENDBUFSEL:
-               if (cur.size() == 1) {
+               if (cur.depth() == 1) {
                        if (!cur.selection())
                                cur.resetAnchor();
                        cursorBottom(cur);
@@ -471,61 +470,65 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                break;
 
        case LFUN_RIGHT:
-               moving = true;
        case LFUN_RIGHTSEL:
-               //lyxerr << "handle LFUN_RIGHT[SEL]:\n" << cur << endl;
+               lyxerr << BOOST_CURRENT_FUNCTION
+                      << " LFUN_RIGHT[SEL]:\n" << cur << endl;
                cur.selHandle(cmd.action == LFUN_RIGHTSEL);
                if (isRTL(cur.paragraph()))
-                       cursorLeft(cur);
+                       needsUpdate = cursorLeft(cur);
                else
-                       cursorRight(cur);
-               if (sl == cur.top()) {
+                       needsUpdate = cursorRight(cur);
+               if (!needsUpdate && oldTopSlice == cur.top()) {
                        cur.undispatched();
                        cmd = FuncRequest(LFUN_FINISHED_RIGHT);
                }
                break;
 
        case LFUN_LEFT:
-               moving = true;
        case LFUN_LEFTSEL:
                //lyxerr << "handle LFUN_LEFT[SEL]:\n" << cur << endl;
                cur.selHandle(cmd.action == LFUN_LEFTSEL);
                if (isRTL(cur.paragraph()))
-                       cursorRight(cur);
+                       needsUpdate = cursorRight(cur);
                else
-                       cursorLeft(cur);
-               if (sl == cur.top()) {
+                       needsUpdate = cursorLeft(cur);
+               if (oldTopSlice == cur.top()) {
                        cur.undispatched();
                        cmd = FuncRequest(LFUN_FINISHED_LEFT);
                }
                break;
 
        case LFUN_UP:
-               moving = true;
        case LFUN_UPSEL:
                update(cur);
                //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
                cur.selHandle(cmd.action == LFUN_UPSEL);
-               cursorUp(cur);
-               if (sl == cur.top()) {
+               needsUpdate = cursorUp(cur);
+               if (oldTopSlice == cur.top()) {
                        cur.undispatched();
                        cmd = FuncRequest(LFUN_FINISHED_UP);
                }
                break;
 
        case LFUN_DOWN:
-               moving = true;
        case LFUN_DOWNSEL:
                update(cur);
                //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
                cur.selHandle(cmd.action == LFUN_DOWNSEL);
-               cursorDown(cur);
-               if (sl == cur.top()) {
+               needsUpdate = cursorDown(cur);
+               if (oldTopSlice == cur.top()) {
                        cur.undispatched();
                        cmd = FuncRequest(LFUN_FINISHED_DOWN);
                }
                break;
 
+       case LFUN_UP_PARAGRAPH:
+               if (!cur.mark())
+                       cur.clearSelection();
+               needsUpdate = cursorUpParagraph(cur);
+               finishChange(cur, false);
+               break;
+
        case LFUN_UP_PARAGRAPHSEL:
                if (!cur.selection())
                        cur.resetAnchor();
@@ -533,6 +536,13 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                finishChange(cur, true);
                break;
 
+       case LFUN_DOWN_PARAGRAPH:
+               if (!cur.mark())
+                       cur.clearSelection();
+               needsUpdate = cursorDownParagraph(cur);
+               finishChange(cur, false);
+               break;
+
        case LFUN_DOWN_PARAGRAPHSEL:
                if (!cur.selection())
                        cur.resetAnchor();
@@ -598,25 +608,8 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                break;
        }
 
-       case LFUN_UP_PARAGRAPH:
-               moving = true;
-               if (!cur.mark())
-                       cur.clearSelection();
-               cursorUpParagraph(cur);
-               finishChange(cur, false);
-               break;
-
-       case LFUN_DOWN_PARAGRAPH:
-               moving = true;
-               if (!cur.mark())
-                       cur.clearSelection();
-               cursorDownParagraph(cur);
-               finishChange(cur, false);
-               break;
-
        case LFUN_PRIOR:
                update(cur);
-               moving = true;
                if (!cur.mark())
                        cur.clearSelection();
                finishChange(cur, false);
@@ -624,13 +617,12 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                        cur.undispatched();
                        cmd = FuncRequest(LFUN_FINISHED_UP);
                } else {
-                       cursorPrevious(cur);
+                       needsUpdate = cursorPrevious(cur);
                }
                break;
 
        case LFUN_NEXT:
                update(cur);
-               moving = true;
                if (!cur.mark())
                        cur.clearSelection();
                finishChange(cur, false);
@@ -639,7 +631,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                        cur.undispatched();
                        cmd = FuncRequest(LFUN_FINISHED_DOWN);
                } else {
-                       cursorNext(cur);
+                       needsUpdate = cursorNext(cur);
                }
                break;
 
@@ -753,15 +745,15 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
        case LFUN_PARAGRAPH_SPACING: {
                Paragraph & par = cur.paragraph();
                Spacing::Space cur_spacing = par.params().spacing().getSpace();
-               float cur_value = 1.0;
+               string cur_value = "1.0";
                if (cur_spacing == Spacing::Other)
-                       cur_value = par.params().spacing().getValue();
+                       cur_value = par.params().spacing().getValueAsString();
 
                istringstream is(cmd.argument);
                string tmp;
                is >> tmp;
                Spacing::Space new_spacing = cur_spacing;
-               float new_value = cur_value;
+               string new_value = cur_value;
                if (tmp.empty()) {
                        lyxerr << "Missing argument to `paragraph-spacing'"
                               << endl;
@@ -773,10 +765,10 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                        new_spacing = Spacing::Double;
                } else if (tmp == "other") {
                        new_spacing = Spacing::Other;
-                       float tmpval = 0.0;
+                       string tmpval = "0.0";
                        is >> tmpval;
                        lyxerr << "new_value = " << tmpval << endl;
-                       if (tmpval != 0.0)
+                       if (tmpval != "0.0")
                                new_value = tmpval;
                } else if (tmp == "default") {
                        new_spacing = Spacing::Default;
@@ -784,7 +776,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                        lyxerr << _("Unknown spacing argument: ")
                               << cmd.argument << endl;
                }
-               if (cur_spacing != new_spacing || cur_value != new_value) 
+               if (cur_spacing != new_spacing || cur_value != new_value)
                        par.params().spacing(Spacing(new_spacing, new_value));
                break;
        }
@@ -886,7 +878,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
 #warning FIXME Check if the arg is in the domain of available selections.
 #endif
                if (isStrUnsignedInt(cmd.argument))
-                       pasteSelection(cur, strToUnsignedInt(cmd.argument));
+                       pasteSelection(cur, convert<unsigned int>(cmd.argument));
                else
                        pasteSelection(cur, 0);
                cur.clearSelection(); // bug 393
@@ -905,8 +897,8 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                break;
 
        case LFUN_GETXY:
-               cur.message(tostr(cursorX(cur.top())) + ' '
-                         + tostr(cursorY(cur.top())));
+               cur.message(convert<string>(cursorX(cur.top())) + ' '
+                         + convert<string>(cursorY(cur.top())));
                break;
 
        case LFUN_SETXY: {
@@ -1153,7 +1145,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
 
                        int const wh = bv->workHeight();
                        int const y = std::max(0, std::min(wh - 1, cmd.y));
-                                         
+
                        setCursorFromCoordinates(cur, cmd.x, y);
                        cur.x_target() = cmd.x;
                        if (cmd.y >= wh)
@@ -1176,7 +1168,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                                bvcur.selection() = true;
                                lyxerr << "MOTION: " << bv->cursor() << endl;
                        }
-                       
+
                } else
                        cur.undispatched();
                break;
@@ -1318,7 +1310,11 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
 
        case LFUN_MATH_IMPORT_SELECTION:
        case LFUN_MATH_MODE:
-               mathDispatch(cur, cmd, false);
+               if (cmd.argument == "on")
+                       // don't pass "on" as argument
+                       mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
+               else
+                       mathDispatch(cur, cmd, false);
                break;
 
        case LFUN_MATH_MACRO:
@@ -1327,7 +1323,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                else {
                        string s = cmd.argument;
                        string const s1 = token(s, ' ', 1);
-                       int const nargs = s1.empty() ? 0 : atoi(s1);
+                       int const nargs = s1.empty() ? 0 : convert<int>(s1);
                        string const s2 = token(s, ' ', 2);
                        string const type = s2.empty() ? "newcommand" : s2;
                        cur.insert(new MathMacroTemplate(token(s, ' ', 0), nargs, s2));
@@ -1335,6 +1331,14 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                }
                break;
 
+       // passthrough hat and underscore outside mathed:
+       case LFUN_SUBSCRIPT:
+               mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "_"), false);
+               break;
+       case LFUN_SUPERSCRIPT:
+               mathDispatch(cur, FuncRequest(LFUN_SELFINSERT, "^"), false);
+               break;
+
        case LFUN_INSERT_MATH:
        case LFUN_INSERT_MATRIX:
        case LFUN_MATH_DELIM: {
@@ -1474,7 +1478,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                InsetBase & inset = cur.inset();
                bool const accept = !inset.forceDefaultParagraphs(&inset);
 
-               data = "update " + tostr(accept) + '\n' + data;
+               data = "update " + convert<string>(accept) + '\n' + data;
                bv->owner()->getDialogs().update("paragraph", data);
                break;
        }
@@ -1588,17 +1592,20 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                break;
 
        default:
+               lyxerr << BOOST_CURRENT_FUNCTION
+                      << " Not DISPATCHED by LyXText" << endl;
                cur.undispatched();
                break;
        }
 
-       // avoid to update when navigating
-       if (moving
-           && &sl.inset() == &cur.inset()
-           && sl.idx() == cur.idx()
-           && sel == false
-           && cur.selection() == false)
+       if (!needsUpdate
+           && &oldTopSlice.inset() == &cur.inset()
+           && oldTopSlice.idx() == cur.idx()
+           && !sel
+           && !cur.selection())
                cur.noUpdate();
+       else
+               cur.needsUpdate();
 }
 
 
@@ -1904,6 +1911,8 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
        case LFUN_INSERT_MATH:
        case LFUN_INSERT_MATRIX:
        case LFUN_MATH_DELIM:
+       case LFUN_SUBSCRIPT:
+       case LFUN_SUPERSCRIPT:
        case LFUN_DEFAULT:
        case LFUN_UNDERLINE:
        case LFUN_FONT_SIZE: