]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_nestinset.C
small up/down tweaking
[lyx.git] / src / mathed / math_nestinset.C
index fc3ea5d7a5f4a406e195820021cea7096a77bf08..053ac12356e4b5a8931a56c7cf7006cb90d46e29 100644 (file)
@@ -5,12 +5,12 @@
 #include "math_nestinset.h"
 #include "math_cursor.h"
 #include "math_mathmlstream.h"
-#include "formulabase.h"
+#include "math_parser.h"
+#include "funcrequest.h"
 #include "debug.h"
+#include "BufferView.h"
 #include "frontends/Painter.h"
 
-using std::vector;
-
 
 MathNestInset::MathNestInset(idx_type nargs)
        : MathDimInset(), cells_(nargs), lock_(false)
@@ -45,6 +45,7 @@ void MathNestInset::getPos(idx_type idx, pos_type pos, int & x, int & y) const
                x += 2;
 }
 
+
 void MathNestInset::substitute(MathMacro const & m)
 {
        for (idx_type i = 0; i < nargs(); ++i)
@@ -228,12 +229,12 @@ void MathNestInset::validate(LaTeXFeatures & features) const
 }
 
 
-bool MathNestInset::match(MathInset const * p) const
+bool MathNestInset::match(MathAtom const & at) const
 {
-       if (nargs() != p->nargs())
+       if (nargs() != at->nargs())
                return false;
        for (idx_type i = 0; i < nargs(); ++i)
-               if (!cell(i).match(p->cell(i)))
+               if (!cell(i).match(at->cell(i)))
                        return false;
        return true;
 }
@@ -293,10 +294,12 @@ void MathNestInset::write(WriteStream & os) const
        os << '\\' << name().c_str();
        for (unsigned i = 0; i < nargs(); ++i)
                os << '{' << cell(i) << '}';
-       if (lock_ && !os.latex())
-               os << "\\lyxlock ";
        if (nargs() == 0)
-               os << ' ';
+               os.pendingSpace(true);
+       if (lock_ && !os.latex()) {
+               os << "\\lyxlock";
+               os.pendingSpace(true);
+       }
 }
 
 
@@ -309,5 +312,39 @@ void MathNestInset::normalize(NormalStream & os) const
 }
 
 
-void MathNestInset::notifyCursorLeaves()
-{}
+void MathNestInset::notifyCursorLeaves(idx_type idx)
+{
+       cell(idx).notifyCursorLeaves();
+}
+
+
+MathInset::result_type MathNestInset::dispatch
+       (FuncRequest const & cmd, idx_type & idx, pos_type & pos)
+{
+       BufferView * bv = cmd.view();
+
+       switch (cmd.action) {
+
+               case LFUN_PASTE: {
+                       MathArray ar;
+                       mathed_parse_cell(ar, cmd.argument);
+                       cell(idx).insert(pos, ar);
+                       pos += ar.size();
+                       return DISPATCHED;
+               }
+
+               case LFUN_PASTESELECTION:
+                       return
+                               dispatch(
+                                       FuncRequest(bv, LFUN_PASTE, bv->getClipboard()), idx, pos);
+
+               case LFUN_MOUSE_PRESS:
+                       if (cmd.button() == mouse_button::button2)
+                               return dispatch(FuncRequest(bv, LFUN_PASTESELECTION), idx, pos);
+                       return UNDISPATCHED;
+
+               default:
+                       return MathInset::dispatch(cmd, idx, pos);
+       }
+       return UNDISPATCHED;
+}