]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_nestinset.C
small up/down tweaking
[lyx.git] / src / mathed / math_nestinset.C
index 11a3ba9e830e11495a25d07fe1b3b5ad0bbeb479..053ac12356e4b5a8931a56c7cf7006cb90d46e29 100644 (file)
@@ -5,14 +5,11 @@
 #include "math_nestinset.h"
 #include "math_cursor.h"
 #include "math_mathmlstream.h"
-#include "formulabase.h"
-#include "BufferView.h"
+#include "math_parser.h"
+#include "funcrequest.h"
 #include "debug.h"
+#include "BufferView.h"
 #include "frontends/Painter.h"
-#include "graphics/PreviewLoader.h"
-#include "graphics/Previews.h"
-
-using std::vector;
 
 
 MathNestInset::MathNestInset(idx_type nargs)
@@ -26,33 +23,21 @@ MathInset::idx_type MathNestInset::nargs() const
 }
 
 
-MathXArray & MathNestInset::xcell(idx_type i)
-{
-       return cells_[i];
-}
-
-
-MathXArray const & MathNestInset::xcell(idx_type i) const
-{
-       return cells_[i];
-}
-
-
 MathArray & MathNestInset::cell(idx_type i)
 {
-       return cells_[i].data();
+       return cells_[i];
 }
 
 
 MathArray const & MathNestInset::cell(idx_type i) const
 {
-       return cells_[i].data();
+       return cells_[i];
 }
 
 
 void MathNestInset::getPos(idx_type idx, pos_type pos, int & x, int & y) const
 {
-       MathXArray const & ar = xcell(idx);
+       MathArray const & ar = cell(idx);
        x = ar.xo() + ar.pos2x(pos);
        y = ar.yo();
        // move cursor visually into empty cells ("blue rectangles");
@@ -60,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)
@@ -71,7 +57,7 @@ void MathNestInset::metrics(MathMetricsInfo const & mi) const
 {
        MathMetricsInfo m = mi;
        for (idx_type i = 0; i < nargs(); ++i)
-               xcell(i).metrics(m);
+               cell(i).metrics(m);
 }
 
 
@@ -188,21 +174,22 @@ void MathNestInset::drawSelection(MathPainterInfo & pi,
                idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const
 {
        if (idx1 == idx2) {
-               MathXArray const & c = xcell(idx1);
+               MathArray const & c = cell(idx1);
                int x1 = c.xo() + c.pos2x(pos1);
                int y1 = c.yo() - c.ascent();
                int x2 = c.xo() + c.pos2x(pos2);
                int y2 = c.yo() + c.descent();
                pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
        } else {
-               vector<MathInset::idx_type> indices = idxBetween(idx1, idx2);
-               for (unsigned i = 0; i < indices.size(); ++i) {
-                       MathXArray const & c = xcell(indices[i]);
-                       int x1 = c.xo();
-                       int y1 = c.yo() - c.ascent();
-                       int x2 = c.xo() + c.width();
-                       int y2 = c.yo() + c.descent();
-                       pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
+               for (idx_type i = 0; i < nargs(); ++i) {
+                       if (idxBetween(i, idx1, idx2)) {
+                               MathArray const & c = cell(i);
+                               int x1 = c.xo();
+                               int y1 = c.yo() - c.ascent();
+                               int x2 = c.xo() + c.width();
+                               int y2 = c.yo() + c.descent();
+                               pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
+                       }
                }
        }
 }
@@ -242,12 +229,12 @@ void MathNestInset::validate(LaTeXFeatures & features) const
 }
 
 
-bool MathNestInset::match(MathInset * 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;
 }
@@ -260,7 +247,7 @@ void MathNestInset::replace(ReplaceData & rep)
 }
 
 
-bool MathNestInset::contains(MathArray const & ar)
+bool MathNestInset::contains(MathArray const & ar) const
 {
        for (idx_type i = 0; i < nargs(); ++i)
                if (cell(i).contains(ar))
@@ -307,8 +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.pendingSpace(true);
+       if (lock_ && !os.latex()) {
+               os << "\\lyxlock";
+               os.pendingSpace(true);
+       }
 }
 
 
@@ -321,24 +312,39 @@ void MathNestInset::normalize(NormalStream & os) const
 }
 
 
-void MathNestInset::notifyCursorLeaves()
+void MathNestInset::notifyCursorLeaves(idx_type idx)
 {
-       // Generate a preview only if previews are active and we are leaving
-       // the InsetFormula itself
-       if (!grfx::Previews::activated() ||
-           !mathcursor || mathcursor->depth() != 1)
-               return;
+       cell(idx).notifyCursorLeaves();
+}
 
-       InsetFormulaBase * inset = mathcursor->formula();
-       BufferView * bufferview = inset->view();
 
-       // Paranoia check
-       if (!bufferview || !bufferview->buffer())
-               return;
+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);
 
-       grfx::Previews & previews = grfx::Previews::get();
-       grfx::PreviewLoader & loader = previews.loader(bufferview->buffer());
+               case LFUN_MOUSE_PRESS:
+                       if (cmd.button() == mouse_button::button2)
+                               return dispatch(FuncRequest(bv, LFUN_PASTESELECTION), idx, pos);
+                       return UNDISPATCHED;
 
-       inset->generatePreview(loader);
-       loader.startLoading();
+               default:
+                       return MathInset::dispatch(cmd, idx, pos);
+       }
+       return UNDISPATCHED;
 }