]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathNest.cpp
* src/frontends/controllers/Dialog.{cpp,h}:
[lyx.git] / src / mathed / InsetMathNest.cpp
index 517c045c31160a837161fcb5a796f715349e451f..d2c98e901a9a019e6be973307986c584daa7ba63 100644 (file)
 #include "InsetMathBrace.h"
 #include "InsetMathColor.h"
 #include "InsetMathComment.h"
-#include "MathData.h"
 #include "InsetMathDelim.h"
-#include "MathFactory.h"
 #include "InsetMathHull.h"
-#include "MathStream.h"
-#include "MathMacroArgument.h"
 //#include "InsetMathMBox.h"
-#include "MathParser.h"
+#include "InsetMathRef.h"
 #include "InsetMathScript.h"
 #include "InsetMathSpace.h"
 #include "InsetMathSymbol.h"
-#include "MathSupport.h"
 #include "InsetMathUnknown.h"
-#include "InsetMathRef.h"
+#include "MathData.h"
+#include "MathFactory.h"
+#include "MathMacroArgument.h"
+#include "MathParser.h"
+#include "MathStream.h"
+#include "MathSupport.h"
 
+#include "bufferview_funcs.h"
 #include "BufferView.h"
-#include "CutAndPaste.h"
-#include "FuncStatus.h"
 #include "Color.h"
-#include "bufferview_funcs.h"
 #include "CoordCache.h"
 #include "Cursor.h"
+#include "CutAndPaste.h"
 #include "debug.h"
 #include "DispatchResult.h"
 #include "FuncRequest.h"
+#include "FuncStatus.h"
 #include "gettext.h"
-#include "LyXText.h"
+#include "Text.h"
 #include "OutputParams.h"
 #include "Undo.h"
 
@@ -56,8 +56,6 @@
 #include "frontends/Selection.h"
 
 #include "FuncRequest.h"
-#include "LyXServer.h"
-#include "LyXServerSocket.h"
 
 #include <sstream>
 
@@ -76,10 +74,26 @@ using std::istringstream;
 
 
 InsetMathNest::InsetMathNest(idx_type nargs)
-       : cells_(nargs), lock_(false)
+       : cells_(nargs), lock_(false), mouse_hover_(false)
+{}
+
+
+InsetMathNest::InsetMathNest(InsetMathNest const & inset)
+       : InsetMath(inset), cells_(inset.cells_), lock_(inset.lock_),
+         mouse_hover_(false)
 {}
 
 
+InsetMathNest & InsetMathNest::operator=(InsetMathNest const & inset)
+{
+       cells_ = inset.cells_;
+       lock_ = inset.lock_;
+       mouse_hover_ = false;
+       InsetMath::operator=(inset);
+       return *this;
+}
+
+
 InsetMath::idx_type InsetMathNest::nargs() const
 {
        return cells_.size();
@@ -346,6 +360,13 @@ int InsetMathNest::latex(Buffer const &, odocstream & os,
 }
 
 
+bool InsetMathNest::setMouseHover(bool mouse_hover)
+{
+       mouse_hover_ = mouse_hover;
+       return true;
+}
+
+
 bool InsetMathNest::notifyCursorLeaves(Cursor & /*cur*/)
 {
 #ifdef WITH_WARNINGS
@@ -406,7 +427,7 @@ void InsetMathNest::handleFont
 void InsetMathNest::handleFont2(Cursor & cur, docstring const & arg)
 {
        recordUndo(cur, Undo::ATOMIC);
-       LyXFont font;
+       Font font;
        bool b;
        bv_funcs::string2font(to_utf8(arg), font, b);
        if (font.color() != Color::inherit) {
@@ -438,7 +459,6 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
                }
                cur.niceInsert(topaste);
                cur.clearSelection(); // bug 393
-               cur.bv().switchKeyMap();
                finishUndo();
                break;
        }
@@ -478,15 +498,6 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
                cur.bv().cursor() = cur;
                break;
 
-       case LFUN_FINISHED_UP:
-               cur.bv().cursor() = cur;
-               break;
-
-       case LFUN_FINISHED_DOWN:
-               ++cur.pos();
-               cur.bv().cursor() = cur;
-               break;
-
        case LFUN_CHAR_FORWARD:
                cur.updateFlags(Update::Decoration | Update::FitCursor);
        case LFUN_CHAR_FORWARD_SELECT:
@@ -494,6 +505,10 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
                cur.autocorrect() = false;
                cur.clearTargetX();
                cur.macroModeClose();
+               if (reverseDirectionNeeded(cur))
+                       goto goto_char_backwards;
+
+goto_char_forwards:
                if (cur.pos() != cur.lastpos() && cur.openable(cur.nextAtom())) {
                        cur.pushLeft(*cur.nextAtom().nucleus());
                        cur.inset().idxFirst(cur);
@@ -513,6 +528,10 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
                cur.autocorrect() = false;
                cur.clearTargetX();
                cur.macroModeClose();
+               if (reverseDirectionNeeded(cur))
+                       goto goto_char_forwards;
+
+goto_char_backwards:
                if (cur.pos() != 0 && cur.openable(cur.prevAtom())) {
                        cur.posLeft();
                        cur.push(*cur.nextAtom().nucleus());
@@ -526,39 +545,33 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
                }
                break;
 
-       case LFUN_UP:
-               cur.updateFlags(Update::Decoration | Update::FitCursor);
-       case LFUN_UP_SELECT:
-               // FIXME Tried to use clearTargetX and macroModeClose, crashed on cur.up()
-               if (cur.inMacroMode()) {
-                       // Make Helge happy
-                       cur.macroModeClose();
-                       break;
-               }
-               cur.selHandle(cmd.action == LFUN_UP_SELECT);
-               if (!cur.up()) {
-                       cmd = FuncRequest(LFUN_FINISHED_UP);
-                       cur.undispatched();
-               }
-               // fixes bug 1598. Please check!
-               cur.normalize();
-               break;
-
        case LFUN_DOWN:
+       case LFUN_UP:
                cur.updateFlags(Update::Decoration | Update::FitCursor);
-       case LFUN_DOWN_SELECT:
+       case LFUN_DOWN_SELECT: 
+       case LFUN_UP_SELECT: {
+               // close active macro
                if (cur.inMacroMode()) {
                        cur.macroModeClose();
                        break;
                }
-               cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
-               if (!cur.down()) {
-                       cmd = FuncRequest(LFUN_FINISHED_DOWN);
+               
+               // stop/start the selection
+               bool select = cmd.action == LFUN_DOWN_SELECT ||
+                       cmd.action == LFUN_UP_SELECT;
+               cur.selHandle(select);
+               
+               // go up/down
+               bool up = cmd.action == LFUN_UP || cmd.action == LFUN_UP_SELECT;
+               bool successful = cur.upDownInMath(up);
+               if (successful) {
+                       // notify left insets and give them chance to set update flags
+                       lyx::notifyCursorLeaves(cur.beforeDispatchCursor(), cur);
+                       cur.fixIfBroken();
+               }       else
                        cur.undispatched();
-               }
-               // fixes bug 1598. Please check!
-               cur.normalize();
                break;
+       }
 
        case LFUN_MOUSE_DOUBLE:
        case LFUN_MOUSE_TRIPLE:
@@ -716,7 +729,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
                    && cur.inMacroMode() && cur.macroName() != "\\"
                    && cur.macroModeClose()) {
                        MathAtom const atom = cur.prevAtom();
-                       if (atom->asNestInset() && atom->nargs() > 0) {
+                       if (atom->asNestInset() && atom->isActive()) {
                                cur.posLeft();
                                cur.pushLeft(*cur.nextInset());
                        }
@@ -831,7 +844,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_MATH_MODE: {
 #if 1
                // ignore math-mode on when already in math mode
-               if (currentMode() == InsetBase::MATH_MODE && cmd.argument() == "on")
+               if (currentMode() == Inset::MATH_MODE && cmd.argument() == "on")
                        break;
                cur.macroModeClose();
                docstring const save_selection = grabAndEraseSelection(cur);
@@ -842,7 +855,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
                cur.pushLeft(*cur.nextInset());
                cur.niceInsert(save_selection);
 #else
-               if (currentMode() == InsetBase::TEXT_MODE) {
+               if (currentMode() == Inset::TEXT_MODE) {
                        cur.niceInsert(MathAtom(new InsetMathHull("simple")));
                        cur.message(_("create new math text environment ($...$)"));
                } else {
@@ -917,7 +930,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
                                                                rdelim)));
                }
                // Don't call cur.undispatched() if we did nothing, this would
-               // lead to infinite recursion via LyXText::dispatch().
+               // lead to infinite recursion via Text::dispatch().
                break;
        }
 
@@ -985,7 +998,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
        }
 
        default:
-               InsetMathDim::doDispatch(cur, cmd);
+               InsetMath::doDispatch(cur, cmd);
                break;
        }
 }
@@ -1083,6 +1096,15 @@ bool InsetMathNest::getStatus(Cursor & cur, FuncRequest const & cmd,
                flag.enabled(cur.selBegin().idx() == cur.selEnd().idx());
                break;
 
+       case LFUN_HYPHENATION_POINT_INSERT:
+       case LFUN_LIGATURE_BREAK_INSERT:
+       case LFUN_MENU_SEPARATOR_INSERT:
+       case LFUN_DOTS_INSERT:
+       case LFUN_END_OF_SENTENCE_PERIOD_INSERT:
+               // FIXME: These would probably make sense in math-text mode
+               flag.enabled(false);
+               break;
+
        default:
                ret = false;
                break;
@@ -1101,7 +1123,7 @@ void InsetMathNest::edit(Cursor & cur, bool left)
 }
 
 
-InsetBase * InsetMathNest::editXY(Cursor & cur, int x, int y)
+Inset * InsetMathNest::editXY(Cursor & cur, int x, int y)
 {
        int idx_min = 0;
        int dist_min = 1000000;
@@ -1146,7 +1168,7 @@ void InsetMathNest::lfunMousePress(Cursor & cur, FuncRequest & cmd)
        } else if (cmd.button() == mouse_button::button2) {
                MathData ar;
                if (cap::selection()) {
-                       // See comment in LyXText::dispatch why we do this
+                       // See comment in Text::dispatch why we do this
                        cap::copySelectionToStack();
                        cmd = FuncRequest(LFUN_PASTE, "0");
                        doDispatch(cur, cmd);
@@ -1412,7 +1434,7 @@ bool InsetMathNest::interpretString(Cursor & cur, docstring const & str)
 }
 
 
-bool InsetMathNest::script(Cursor & cur, bool up, 
+bool InsetMathNest::script(Cursor & cur, bool up,
                docstring const & save_selection)
 {
        // Hack to get \^ and \_ working