]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathHull.cpp
* BufferView::buffer() returns a reference instead of a pointer.
[lyx.git] / src / mathed / InsetMathHull.cpp
index 1f6972fa99f869cddcd2590998378ed00af03792..a4ff0eaada2f61b1ca13e307a891c1b9df2edcc1 100644 (file)
@@ -13,7 +13,7 @@
 #include "InsetMathArray.h"
 #include "InsetMathChar.h"
 #include "InsetMathColor.h"
-#include "MathArray.h"
+#include "MathData.h"
 #include "InsetMathDelim.h"
 #include "MathExtern.h"
 #include "MathFactory.h"
 #include "InsetMathRef.h"
 
 #include "bufferview_funcs.h"
-#include "LyXText.h"
+#include "Text.h"
 
 #include "Buffer.h"
 #include "BufferParams.h"
 #include "BufferView.h"
 #include "CutAndPaste.h"
 #include "FuncStatus.h"
-#include "LColor.h"
+#include "Color.h"
 #include "LaTeXFeatures.h"
-#include "LCursor.h"
+#include "Cursor.h"
 #include "debug.h"
 #include "DispatchResult.h"
 #include "FuncRequest.h"
@@ -52,6 +52,8 @@
 #include "graphics/PreviewImage.h"
 #include "graphics/PreviewLoader.h"
 
+#include "frontends/Painter.h"
+
 #include "support/lyxlib.h"
 #include "support/lstrings.h"
 
@@ -98,9 +100,9 @@ namespace {
 
        // returns position of first relation operator in the array
        // used for "intelligent splitting"
-       size_t firstRelOp(MathArray const & ar)
+       size_t firstRelOp(MathData const & ar)
        {
-               for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
+               for (MathData::const_iterator it = ar.begin(); it != ar.end(); ++it)
                        if ((*it)->isRelOp())
                                return it - ar.begin();
                return ar.size();
@@ -162,7 +164,7 @@ InsetMathHull::InsetMathHull()
        //lyxerr << "sizeof InsetMath: " << sizeof(InsetMath) << endl;
        //lyxerr << "sizeof MetricsInfo: " << sizeof(MetricsInfo) << endl;
        //lyxerr << "sizeof InsetMathChar: " << sizeof(InsetMathChar) << endl;
-       //lyxerr << "sizeof LyXFont: " << sizeof(LyXFont) << endl;
+       //lyxerr << "sizeof Font: " << sizeof(Font) << endl;
        initMath();
        setDefaults();
 }
@@ -180,7 +182,7 @@ InsetMathHull::InsetMathHull(HullType type)
 InsetMathHull::InsetMathHull(InsetMathHull const & other)
        : InsetMathGrid(other),
          type_(other.type_), nonum_(other.nonum_), label_(other.label_),
-         preview_(new RenderPreview(this))
+         preview_(new RenderPreview(*other.preview_, this))
 {}
 
 
@@ -188,9 +190,9 @@ InsetMathHull::~InsetMathHull()
 {}
 
 
-auto_ptr<InsetBase> InsetMathHull::doClone() const
+auto_ptr<Inset> InsetMathHull::doClone() const
 {
-       return auto_ptr<InsetBase>(new InsetMathHull(*this));
+       return auto_ptr<Inset>(new InsetMathHull(*this));
 }
 
 
@@ -208,7 +210,7 @@ InsetMathHull & InsetMathHull::operator=(InsetMathHull const & other)
 }
 
 
-InsetBase * InsetMathHull::editXY(LCursor & cur, int x, int y)
+Inset * InsetMathHull::editXY(Cursor & cur, int x, int y)
 {
        if (use_preview_) {
                edit(cur, true);
@@ -227,7 +229,7 @@ InsetMath::mode_type InsetMathHull::currentMode() const
 }
 
 
-bool InsetMathHull::idxFirst(LCursor & cur) const
+bool InsetMathHull::idxFirst(Cursor & cur) const
 {
        cur.idx() = 0;
        cur.pos() = 0;
@@ -235,7 +237,7 @@ bool InsetMathHull::idxFirst(LCursor & cur) const
 }
 
 
-bool InsetMathHull::idxLast(LCursor & cur) const
+bool InsetMathHull::idxLast(Cursor & cur) const
 {
        cur.idx() = nargs() - 1;
        cur.pos() = cur.lastpos();
@@ -275,7 +277,7 @@ bool InsetMathHull::previewState(BufferView * bv) const
 {
        if (!editing(bv) && RenderPreview::status() == LyXRC::PREVIEW_ON) {
                graphics::PreviewImage const * pimage =
-                       preview_->getPreviewImage(*bv->buffer());
+                       preview_->getPreviewImage(bv->buffer());
                return pimage && pimage->image();
        }
        return false;
@@ -335,6 +337,12 @@ void InsetMathHull::draw(PainterInfo & pi, int x, int y) const
 {
        use_preview_ = previewState(pi.base.bv);
 
+       // background of mathed under focus is not painted because
+       // selection at the top level of nested inset is difficult to handle.
+       if (!editing(pi.base.bv))
+               pi.pain.fillRectangle(x + 1, y - ascent() + 1, width() - 2,
+                               ascent() + descent() - 1, Color::mathbg);
+
        if (use_preview_) {
                // one pixel gap in front
                preview_->draw(pi, x + 1, y);
@@ -409,7 +417,7 @@ void InsetMathHull::addPreview(graphics::PreviewLoader & ploader) const
 }
 
 
-bool InsetMathHull::notifyCursorLeaves(LCursor & cur)
+bool InsetMathHull::notifyCursorLeaves(Cursor & cur)
 {
        if (RenderPreview::status() == LyXRC::PREVIEW_ON) {
                Buffer const & buffer = cur.buffer();
@@ -463,9 +471,9 @@ bool InsetMathHull::ams() const
 }
 
 
-bool InsetMathHull::display() const
+Inset::DisplayType InsetMathHull::display() const
 {
-       return type_ != hullSimple && type_ != hullNone;
+       return (type_ != hullSimple && type_ != hullNone) ? AlignCenter : Inline;
 }
 
 
@@ -680,7 +688,7 @@ docstring InsetMathHull::nicelabel(row_type row) const
 
 void InsetMathHull::glueall()
 {
-       MathArray ar;
+       MathData ar;
        for (idx_type i = 0; i < nargs(); ++i)
                ar.append(cell(i));
        *this = InsetMathHull(hullSimple);
@@ -696,7 +704,7 @@ void InsetMathHull::splitTo2Cols()
        for (row_type row = 0; row < nrows(); ++row) {
                idx_type const i = 2 * row;
                pos_type pos = firstRelOp(cell(i));
-               cell(i + 1) = MathArray(cell(i).begin() + pos, cell(i).end());
+               cell(i + 1) = MathData(cell(i).begin() + pos, cell(i).end());
                cell(i).erase(pos, cell(i).size());
        }
 }
@@ -711,7 +719,7 @@ void InsetMathHull::splitTo3Cols()
        for (row_type row = 0; row < nrows(); ++row) {
                idx_type const i = 3 * row + 1;
                if (cell(i).size()) {
-                       cell(i + 1) = MathArray(cell(i).begin() + 1, cell(i).end());
+                       cell(i + 1) = MathData(cell(i).begin() + 1, cell(i).end());
                        cell(i).erase(1, cell(i).size());
                }
        }
@@ -954,7 +962,7 @@ void InsetMathHull::check() const
 }
 
 
-void InsetMathHull::doExtern(LCursor & cur, FuncRequest & func)
+void InsetMathHull::doExtern(Cursor & cur, FuncRequest & func)
 {
        docstring dlang;
        docstring extra;
@@ -964,18 +972,16 @@ void InsetMathHull::doExtern(LCursor & cur, FuncRequest & func)
                extra = from_ascii("noextra");
        std::string const lang = to_ascii(dlang);
 
-#ifdef WITH_WARNINGS
-#warning temporarily disabled
+       // FIXME: temporarily disabled
        //if (cur.selection()) {
-       //      MathArray ar;
+       //      MathData ar;
        //      selGet(cur.ar);
        //      lyxerr << "use selection: " << ar << endl;
        //      insert(pipeThroughExtern(lang, extra, ar));
        //      return;
        //}
-#endif
 
-       MathArray eq;
+       MathData eq;
        eq.push_back(MathAtom(new InsetMathChar('=')));
 
        // go to first item in line
@@ -984,14 +990,14 @@ void InsetMathHull::doExtern(LCursor & cur, FuncRequest & func)
 
        if (getType() == hullSimple) {
                size_type pos = cur.cell().find_last(eq);
-               MathArray ar;
+               MathData ar;
                if (cur.inMathed() && cur.selection()) {
                        asArray(grabAndEraseSelection(cur), ar);
                } else if (pos == cur.cell().size()) {
                        ar = cur.cell();
                        lyxerr << "use whole cell: " << ar << endl;
                } else {
-                       ar = MathArray(cur.cell().begin() + pos + 1, cur.cell().end());
+                       ar = MathData(cur.cell().begin() + pos + 1, cur.cell().end());
                        lyxerr << "use partial cell form pos: " << pos << endl;
                }
                cur.cell().append(eq);
@@ -1003,7 +1009,7 @@ void InsetMathHull::doExtern(LCursor & cur, FuncRequest & func)
        if (getType() == hullEquation) {
                lyxerr << "use equation inset" << endl;
                mutate(hullEqnArray);
-               MathArray & ar = cur.cell();
+               MathData & ar = cur.cell();
                lyxerr << "use cell: " << ar << endl;
                ++cur.idx();
                cur.cell() = eq;
@@ -1018,11 +1024,9 @@ void InsetMathHull::doExtern(LCursor & cur, FuncRequest & func)
                lyxerr << "use eqnarray" << endl;
                cur.idx() += 2 - cur.idx() % ncols();
                cur.pos() = 0;
-               MathArray ar = cur.cell();
+               MathData ar = cur.cell();
                lyxerr << "use cell: " << ar << endl;
-#ifdef WITH_WARNINGS
-#warning temporarily disabled
-#endif
+               // FIXME: temporarily disabled
                addRow(cur.row());
                ++cur.idx();
                ++cur.idx();
@@ -1034,15 +1038,13 @@ void InsetMathHull::doExtern(LCursor & cur, FuncRequest & func)
 }
 
 
-void InsetMathHull::doDispatch(LCursor & cur, FuncRequest & cmd)
+void InsetMathHull::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
        //lyxerr << "action: " << cmd.action << endl;
        switch (cmd.action) {
 
        case LFUN_FINISHED_LEFT:
        case LFUN_FINISHED_RIGHT:
-       case LFUN_FINISHED_UP:
-       case LFUN_FINISHED_DOWN:
                //lyxerr << "action: " << cmd.action << endl;
                InsetMathGrid::doDispatch(cur, cmd);
                notifyCursorLeaves(cur);
@@ -1058,7 +1060,7 @@ void InsetMathHull::doDispatch(LCursor & cur, FuncRequest & cmd)
                if (type_ == hullSimple || type_ == hullEquation) {
                        recordUndoInset(cur);
                        bool const align =
-                               cur.bv().buffer()->params().use_amsmath == BufferParams::package_on;
+                               cur.bv().buffer().params().use_amsmath == BufferParams::package_on;
                        mutate(align ? hullAlign : hullEqnArray);
                        cur.idx() = 0;
                        cur.pos() = cur.lastpos();
@@ -1127,8 +1129,8 @@ void InsetMathHull::doDispatch(LCursor & cur, FuncRequest & cmd)
                                numbered(r, true);
                        docstring old = label(r);
                        if (str != old) {
-                               cur.bv().buffer()->changeRefsIfUnique(old, str,
-                                                       InsetBase::REF_CODE);
+                               cur.bv().buffer().changeRefsIfUnique(old, str,
+                                                       Inset::REF_CODE);
                                label(r, str);
                        }
                        break;
@@ -1174,14 +1176,14 @@ void InsetMathHull::doDispatch(LCursor & cur, FuncRequest & cmd)
 }
 
 
-bool InsetMathHull::getStatus(LCursor & cur, FuncRequest const & cmd,
+bool InsetMathHull::getStatus(Cursor & cur, FuncRequest const & cmd,
                FuncStatus & status) const
 {
        switch (cmd.action) {
        case LFUN_FINISHED_LEFT:
        case LFUN_FINISHED_RIGHT:
-       case LFUN_FINISHED_UP:
-       case LFUN_FINISHED_DOWN:
+       case LFUN_UP:
+       case LFUN_DOWN:
                status.enabled(true);
                return true;
        case LFUN_BREAK_LINE:
@@ -1274,7 +1276,7 @@ void InsetMathHull::mutateToText()
        string str = os.str();
 
        // insert this text
-       LyXText * lt = view_->cursor().innerText();
+       Text * lt = view_->cursor().innerText();
        string::const_iterator cit = str.begin();
        string::const_iterator end = str.end();
        for (; cit != end; ++cit)
@@ -1286,7 +1288,7 @@ void InsetMathHull::mutateToText()
 }
 
 
-void InsetMathHull::handleFont(LCursor & cur, docstring const & arg,
+void InsetMathHull::handleFont(Cursor & cur, docstring const & arg,
        docstring const & font)
 {
        // this whole function is a hack and won't work for incremental font
@@ -1301,26 +1303,26 @@ void InsetMathHull::handleFont(LCursor & cur, docstring const & arg,
 }
 
 
-void InsetMathHull::handleFont2(LCursor & cur, docstring const & arg)
+void InsetMathHull::handleFont2(Cursor & cur, docstring const & arg)
 {
        recordUndo(cur);
-       LyXFont font;
+       Font font;
        bool b;
        bv_funcs::string2font(to_utf8(arg), font, b);
-       if (font.color() != LColor::inherit) {
+       if (font.color() != Color::inherit) {
                MathAtom at = MathAtom(new InsetMathColor(true, font.color()));
                cur.handleNest(at, 0);
        }
 }
 
 
-void InsetMathHull::edit(LCursor & cur, bool left)
+void InsetMathHull::edit(Cursor & cur, bool left)
 {
        cur.push(*this);
        left ? idxFirst(cur) : idxLast(cur);
        // The inset formula dimension is not necessarily the same as the
        // one of the instant preview image, so we have to indicate to the
-       // BufferView that a metrics update is needed. 
+       // BufferView that a metrics update is needed.
        cur.updateFlags(Update::Force);
 }
 
@@ -1331,7 +1333,7 @@ docstring const InsetMathHull::editMessage() const
 }
 
 
-void InsetMathHull::revealCodes(LCursor & cur) const
+void InsetMathHull::revealCodes(Cursor & cur) const
 {
        if (!cur.inMathed())
                return;
@@ -1367,7 +1369,7 @@ void InsetMathHull::revealCodes(LCursor & cur) const
 }
 
 
-InsetBase::Code InsetMathHull::lyxCode() const
+Inset::Code InsetMathHull::lyxCode() const
 {
        return MATH_CODE;
 }
@@ -1380,12 +1382,10 @@ InsetBase::Code InsetMathHull::lyxCode() const
 bool InsetMathHull::searchForward(BufferView * bv, string const & str,
                                     bool, bool)
 {
-#ifdef WITH_WARNINGS
-#warning completely broken
-#endif
+       // FIXME: completely broken
        static InsetMathHull * lastformula = 0;
        static CursorBase current = DocIterator(ibegin(nucleus()));
-       static MathArray ar;
+       static MathData ar;
        static string laststr;
 
        if (lastformula != this || laststr != str) {
@@ -1402,7 +1402,7 @@ bool InsetMathHull::searchForward(BufferView * bv, string const & str,
 
        for (DocIterator it = current; it != iend(nucleus()); increment(it)) {
                CursorSlice & top = it.back();
-               MathArray const & a = top.asInsetMath()->cell(top.idx_);
+               MathData const & a = top.asInsetMath()->cell(top.idx_);
                if (a.matchpart(ar, top.pos_)) {
                        bv->cursor().setSelection(it, ar.size());
                        current = it;
@@ -1429,7 +1429,7 @@ void InsetMathHull::write(Buffer const &, std::ostream & os) const
 }
 
 
-void InsetMathHull::read(Buffer const &, LyXLex & lex)
+void InsetMathHull::read(Buffer const &, Lexer & lex)
 {
        MathAtom at;
        mathed_parse_normal(at, lex);
@@ -1438,7 +1438,7 @@ void InsetMathHull::read(Buffer const &, LyXLex & lex)
 
 
 int InsetMathHull::plaintext(Buffer const &, odocstream & os,
-                             OutputParams const &) const
+                            OutputParams const &) const
 {
        if (0 && display()) {
                Dimension dim;
@@ -1463,7 +1463,7 @@ int InsetMathHull::plaintext(Buffer const &, odocstream & os,
 
 
 int InsetMathHull::docbook(Buffer const & buf, odocstream & os,
-                           OutputParams const & runparams) const
+                          OutputParams const & runparams) const
 {
        MathStream ms(os);
        int res = 0;