]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_scriptinset.C
mathed uglyfication
[lyx.git] / src / mathed / math_scriptinset.C
index 67de4997107fa172c27475da3022218f2cf4c0df..5b6c4a2e7f72f478006edcf370cf0112c33866b8 100644 (file)
@@ -1,14 +1,31 @@
+/**
+ * \file math_scriptinset.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author André Pönitz
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
 
 #include "math_scriptinset.h"
+#include "math_data.h"
+#include "math_mathmlstream.h"
 #include "math_support.h"
 #include "math_symbolinset.h"
-#include "math_mathmlstream.h"
-#include "funcrequest.h"
-#include "support/LAssert.h"
+#include "dispatchresult.h"
 #include "debug.h"
+#include "funcrequest.h"
+
+#include <boost/assert.hpp>
 
 
+using std::string;
 using std::max;
+using std::auto_ptr;
+using std::endl;
 
 
 MathScriptInset::MathScriptInset()
@@ -37,9 +54,9 @@ MathScriptInset::MathScriptInset(MathAtom const & at, bool up)
 
 
 
-MathInset * MathScriptInset::clone() const
+auto_ptr<InsetBase> MathScriptInset::clone() const
 {
-       return new MathScriptInset(*this);
+       return auto_ptr<InsetBase>(new MathScriptInset(*this));
 }
 
 
@@ -55,18 +72,20 @@ MathScriptInset * MathScriptInset::asScriptInset()
 }
 
 
-bool MathScriptInset::idxFirst(idx_type & idx, pos_type & pos) const
+bool MathScriptInset::idxFirst(BufferView & bv) const
 {
-       idx = 2;
-       pos = 0;
+       CursorSlice & cur = cursorTip(bv);
+       cur.idx() = 2;
+       cur.pos() = 0;
        return true;
 }
 
 
-bool MathScriptInset::idxLast(idx_type & idx, pos_type & pos) const
+bool MathScriptInset::idxLast(BufferView & bv) const
 {
-       idx = 2;
-       pos = nuc().size();
+       CursorSlice & cur = cursorTip(bv);
+       cur.idx() = 2;
+       cur.pos() = nuc().size();
        return true;
 }
 
@@ -144,14 +163,14 @@ int MathScriptInset::dy1() const
 
 int MathScriptInset::dx0() const
 {
-       lyx::Assert(hasDown());
+       BOOST_ASSERT(hasDown());
        return hasLimits() ? (dim_.wid - down().width()) / 2 : nwid();
 }
 
 
 int MathScriptInset::dx1() const
 {
-       lyx::Assert(hasUp());
+       BOOST_ASSERT(hasUp());
        return hasLimits() ? (dim_.wid - up().width()) / 2 : nwid();
 }
 
@@ -296,36 +315,36 @@ bool MathScriptInset::hasDown() const
 }
 
 
-bool MathScriptInset::idxRight(idx_type &, pos_type &) const
+bool MathScriptInset::idxRight(BufferView &) const
 {
        return false;
 }
 
 
-bool MathScriptInset::idxLeft(idx_type &, pos_type &) const
+bool MathScriptInset::idxLeft(BufferView &) const
 {
        return false;
 }
 
 
-bool MathScriptInset::idxUpDown(idx_type & idx, pos_type & pos, bool up,
-       int) const
+bool MathScriptInset::idxUpDown(BufferView & bv, bool up, int) const
 {
-       if (idx == 1) {
+       CursorSlice & cur = cursorTip(bv);
+       if (cur.idx() == 1) {
                // if we are 'up' we can't go further up
                if (up)
                        return false;
                // otherwise go to last base position
-               idx = 2;
-               pos = cell(2).size();
+               cur.idx() = 2;
+               cur.pos() = cur.lastpos();
        }
 
-       else if (idx == 0) {
+       else if (cur.idx() == 0) {
                // if we are 'down' we can't go further down
                if (!up)
                        return false;
-               idx = 2;
-               pos = cell(2).size();
+               cur.idx() = 2;
+               cur.pos() = cur.lastpos();
        }
 
        else {
@@ -335,9 +354,9 @@ bool MathScriptInset::idxUpDown(idx_type & idx, pos_type & pos, bool up,
                        return false;
                // go up/down only if in the last position
                // or in the first position of something with displayed limits
-               if (pos == cell(2).size() || (pos == 0 && hasLimits())) {
-                       idx = up;
-                       pos = 0;
+               if (cur.pos() == cur.lastpos() || (cur.pos() == 0 && hasLimits())) {
+                       cur.idx() = up;
+                       cur.pos() = 0;
                        return true;
                }
                return false;
@@ -358,7 +377,8 @@ void MathScriptInset::write(WriteStream & os) const
                //}
        } else {
                if (os.firstitem())
-                       lyxerr[Debug::MATHED] << "suppressing {} when writing\n";
+                       lyxerr[Debug::MATHED] << "suppressing {} when writing"
+                                             << endl;
                else
                        os << "{}";
        }
@@ -494,8 +514,8 @@ void MathScriptInset::notifyCursorLeaves(idx_type idx)
 }
 
 
-dispatch_result MathScriptInset::dispatch
-       (FuncRequest const & cmd, idx_type & idx, pos_type & pos)
+DispatchResult
+MathScriptInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
 {
        if (cmd.action == LFUN_MATH_LIMITS) {
                if (!cmd.argument.empty()) {
@@ -506,11 +526,11 @@ dispatch_result MathScriptInset::dispatch
                        else
                                limits_ = 0;
                } else if (limits_ == 0)
-                       limits_ =  (hasLimits()) ? -1 : 1;
+                       limits_ = hasLimits() ? -1 : 1;
                else
                        limits_ = 0;
-               return DISPATCHED;
+               return DispatchResult(true, true);
        }
 
-       return MathNestInset::dispatch(cmd, idx, pos);
+       return MathNestInset::priv_dispatch(bv, cmd);
 }