]> git.lyx.org Git - lyx.git/blobdiff - src/Text3.cpp
EmbeddedObjects.lyx: add hint how to force a rotation direction for rotated floats
[lyx.git] / src / Text3.cpp
index 3ebb1db41b7a0631dc0b3cfca19dac0010be4867..63e523a898046346dcb076bf93e289f127190dea 100644 (file)
@@ -99,7 +99,6 @@ namespace {
        Font freefont(Font::ALL_IGNORE);
        bool toggleall = false;
 
-
        void toggleAndShow(Cursor & cur, Text * text,
                Font const & font, bool toggleall = true)
        {
@@ -108,13 +107,10 @@ namespace {
                if (font.language() != ignore_language ||
                                font.number() != Font::IGNORE) {
                        Paragraph & par = cur.paragraph();
-                       text->bidi.computeTables(par, cur.buffer(), cur.textRow());
-                       if (cur.boundary() !=
-                                       text->bidi.isBoundary(cur.buffer(), par,
-                                                       cur.pos(),
-                                                       text->real_current_font))
+                       if (cur.boundary() != text->isRTLBoundary(cur.buffer(), par,
+                                               cur.pos(), text->real_current_font))
                                text->setCursor(cur, cur.pit(), cur.pos(),
-                                               false, !cur.boundary());
+                                               false, !cur.boundary());
                }
        }
 
@@ -124,7 +120,6 @@ namespace {
                if (selecting || cur.mark())
                        cur.setSelection();
                saveSelection(cur);
-               cur.bv().switchKeyMap();
        }
 
 
@@ -299,6 +294,56 @@ bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const
 }
 
 
+bool Text::isRTL(Buffer const & buffer, CursorSlice const & sl, bool boundary) const
+{
+       if (!lyxrc.rtl_support && !sl.text())
+               return false;
+
+       int correction = 0;
+       if (boundary && sl.pos() > 0)
+               correction = -1;
+               
+       Paragraph const & par = getPar(sl.pit());
+       return getFont(buffer, par, sl.pos() + correction).isVisibleRightToLeft();
+}
+
+
+bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
+                         pos_type pos) const
+{
+       if (!lyxrc.rtl_support)
+               return false;
+
+       // no RTL boundary at line start
+       if (pos == 0)
+               return false;
+
+       bool left = getFont(buffer, par, pos - 1).isVisibleRightToLeft();
+       bool right;
+       if (pos == par.size())
+               right = par.isRightToLeftPar(buffer.params());
+       else
+               right = getFont(buffer, par, pos).isVisibleRightToLeft();
+       return left != right;
+}
+
+
+bool Text::isRTLBoundary(Buffer const & buffer, Paragraph const & par,
+                         pos_type pos, Font const & font) const
+{
+       if (!lyxrc.rtl_support)
+               return false;
+
+       bool left = font.isVisibleRightToLeft();
+       bool right;
+       if (pos == par.size())
+               right = par.isRightToLeftPar(buffer.params());
+       else
+               right = getFont(buffer, par, pos).isVisibleRightToLeft();
+       return left != right;
+}
+
+
 void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 {
        LYXERR(Debug::ACTION) << "Text::dispatch: cmd: " << cmd << endl;
@@ -443,8 +488,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                                && cur.boundary() == oldBoundary) {
                        cur.undispatched();
                        cmd = FuncRequest(LFUN_FINISHED_RIGHT);
-               }
-               if (cur.selection())
+               } else if (cur.selection())
                        saveSelection(cur);
                break;
 
@@ -466,37 +510,33 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        saveSelection(cur);
                break;
 
-       case LFUN_UP:
        case LFUN_UP_SELECT:
-               //lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
-               needsUpdate |= cur.selHandle(cmd.action == LFUN_UP_SELECT);
-
-               needsUpdate |= cursorUp(cur);
-
-               if (!needsUpdate && oldTopSlice == cur.top()
-                         && cur.boundary() == oldBoundary) {
-                       cur.undispatched();
-                       cmd = FuncRequest(LFUN_FINISHED_UP);
-               }
-               if (cur.selection())
-                       saveSelection(cur);
-               break;
-
-       case LFUN_DOWN:
        case LFUN_DOWN_SELECT:
-               //lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
-               needsUpdate |= cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
-               needsUpdate |= cursorDown(cur);
-
-               if (!needsUpdate && oldTopSlice == cur.top() &&
-                   cur.boundary() == oldBoundary)
-               {
+       case LFUN_UP:
+       case LFUN_DOWN: {
+               // stop/start the selection
+               bool select = cmd.action == LFUN_DOWN_SELECT ||
+                       cmd.action == LFUN_UP_SELECT;
+               cur.selHandle(select);
+               
+               // move cursor up/down
+               bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP;
+               bool const successful = cur.upDownInText(up, needsUpdate);
+               if (successful) {
+                       // notify insets which were left and get their update flags 
+                       notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
+                       cur.fixIfBroken();
+                       
+                       // redraw if you leave mathed (for the decorations)
+                       needsUpdate |= cur.beforeDispatchCursor().inMathed();
+               } else
                        cur.undispatched();
-                       cmd = FuncRequest(LFUN_FINISHED_DOWN);
-               }
+               
+               // save new selection
                if (cur.selection())
                        saveSelection(cur);
                break;
+       }
 
        case LFUN_PARAGRAPH_UP:
        case LFUN_PARAGRAPH_UP_SELECT:
@@ -517,10 +557,9 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_SCREEN_UP:
        case LFUN_SCREEN_UP_SELECT:
                needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_UP_SELECT);
-               if (cur.pit() == 0 && cur.textRow().pos() == 0) {
+               if (cur.pit() == 0 && cur.textRow().pos() == 0)
                        cur.undispatched();
-                       cmd = FuncRequest(LFUN_FINISHED_UP);
-               } else {
+               else {
                        cursorPrevious(cur);
                }
                if (cur.selection())
@@ -531,10 +570,9 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_SCREEN_DOWN_SELECT:
                needsUpdate |= cur.selHandle(cmd.action == LFUN_SCREEN_DOWN_SELECT);
                if (cur.pit() == cur.lastpit()
-                         && cur.textRow().endpos() == cur.lastpos()) {
+                         && cur.textRow().endpos() == cur.lastpos())
                        cur.undispatched();
-                       cmd = FuncRequest(LFUN_FINISHED_DOWN);
-               } else {
+               else {
                        cursorNext(cur);
                }
                if (cur.selection())
@@ -644,7 +682,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        cutSelection(cur, true, false);
                        singleParUpdate = false;
                }
-               bv->switchKeyMap();
                break;
 
        case LFUN_DELETE_BACKWARD_SKIP:
@@ -665,14 +702,12 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                cap::replaceSelection(cur);
                breakParagraph(cur, 0);
                cur.resetAnchor();
-               bv->switchKeyMap();
                break;
 
        case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
                cap::replaceSelection(cur);
                breakParagraph(cur, 1);
                cur.resetAnchor();
-               bv->switchKeyMap();
                break;
 
        case LFUN_BREAK_PARAGRAPH_SKIP: {
@@ -684,7 +719,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                else
                        breakParagraph(cur, 0);
                cur.resetAnchor();
-               bv->switchKeyMap();
                break;
        }
 
@@ -827,7 +861,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                }
                bv->buffer()->errors("Paste");
                cur.clearSelection(); // bug 393
-               bv->switchKeyMap();
                finishUndo();
                break;
 
@@ -918,7 +951,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        setLayout(cur, layout);
                        // inform the GUI that the layout has changed.
                        bv->layoutChanged(layout);
-                       bv->switchKeyMap();
                }
                break;
        }
@@ -1032,9 +1064,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        paste_internally = true;
                }
 
-               // we have to update after dePM triggered
-               bool update = bv->mouseSetCursor(cur);
-
                // Insert primary selection with middle mouse
                // if there is a local selection in the current buffer,
                // insert this
@@ -1043,12 +1072,17 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                                cap::pasteSelection(cur, bv->buffer()->errorList("Paste"));
                                bv->buffer()->errors("Paste");
                                cur.clearSelection(); // bug 393
-                               bv->switchKeyMap();
+                               bv->buffer()->markDirty();
                                finishUndo();
-                       } else
+                       } else {
+                               bv->mouseSetCursor(cur);
                                lyx::dispatch(FuncRequest(LFUN_PRIMARY_SELECTION_PASTE, "paragraph"));
+                       }
                }
 
+               // we have to update after dePM triggered
+               bool update = bv->mouseSetCursor(cur);
+
                if (!update && cmd.button() == mouse_button::button1) {
                        needsUpdate = false;
                        cur.noUpdate();
@@ -1071,7 +1105,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        int const y = std::max(0, std::min(wh - 1, cmd.y));
 
                        setCursorFromCoordinates(cur, cmd.x, y);
-                       cur.x_target() = cmd.x;
+                       cur.setTargetX(cmd.x);
                        if (cmd.y >= wh)
                                lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
                        else if (cmd.y < 0)
@@ -1118,7 +1152,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        cur.noUpdate();
                }
 
-               bv->switchKeyMap();
                break;
        }
 
@@ -1142,8 +1175,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                docstring::const_iterator cit = cmd.argument().begin();
                docstring::const_iterator end = cmd.argument().end();
                for (; cit != end; ++cit)
-                       bv->getIntl().getTransManager().
-                               translateAndInsert(*cit, this, cur);
+                       bv->translateAndInsert(*cit, this, cur);
 
                cur.resetAnchor();
                moveCursor(cur, false);
@@ -1336,7 +1368,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_MATH_DELIM:
        case LFUN_MATH_BIGDELIM: {
                cur.insert(new InsetMathHull(hullSimple));
-               cur.dispatch(FuncRequest(LFUN_CHAR_FORWARD));
+               checkAndActivateInset(cur, true);
                BOOST_ASSERT(cur.inMathed());
                cur.dispatch(cmd);
                break;
@@ -1411,7 +1443,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                Font font(Font::ALL_IGNORE);
                font.setLanguage(lang);
                toggleAndShow(cur, this, font);
-               bv->switchKeyMap();
                break;
        }
 
@@ -1446,16 +1477,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        ++cur.pos();
                break;
 
-       case LFUN_FINISHED_UP:
-               LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_UP:\n" << cur << endl;
-               cursorUp(cur);
-               break;
-
-       case LFUN_FINISHED_DOWN:
-               LYXERR(Debug::DEBUG) << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
-               cursorDown(cur);
-               break;
-
        case LFUN_LAYOUT_PARAGRAPH: {
                string data;
                params2string(cur.paragraph(), data);
@@ -1496,8 +1517,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                theLyXFunc().handleKeyFunc(cmd.action);
                if (!cmd.argument().empty())
                        // FIXME: Are all these characters encoded in one byte in utf8?
-                       bv->getIntl().getTransManager()
-                               .translateAndInsert(cmd.argument()[0], this, cur);
+                       bv->translateAndInsert(cmd.argument()[0], this, cur);
                break;
 
        case LFUN_FLOAT_LIST: {