]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathHull.cpp
* the old cursor is stored before dispatch and then used after moving
[lyx.git] / src / mathed / InsetMathHull.cpp
index 1b963ac068762cc23022f0c2948ff93453a6eb1f..38f0226bc77fd97799cf8bef6f9f7be1239f6e1d 100644 (file)
 #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 "Cursor.h"
 #include "debug.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"
 
@@ -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();
 }
@@ -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(Cursor & cur, int x, int y)
+Inset * InsetMathHull::editXY(Cursor & cur, int x, int y)
 {
        if (use_preview_) {
                edit(cur, true);
@@ -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);
@@ -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;
 }
 
 
@@ -1041,8 +1049,6 @@ void InsetMathHull::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        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);
@@ -1128,7 +1134,7 @@ void InsetMathHull::doDispatch(Cursor & cur, FuncRequest & cmd)
                        docstring old = label(r);
                        if (str != old) {
                                cur.bv().buffer()->changeRefsIfUnique(old, str,
-                                                       InsetBase::REF_CODE);
+                                                       Inset::REF_CODE);
                                label(r, str);
                        }
                        break;
@@ -1180,8 +1186,8 @@ bool InsetMathHull::getStatus(Cursor & cur, FuncRequest const & cmd,
        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 +1280,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)
@@ -1304,10 +1310,10 @@ void InsetMathHull::handleFont(Cursor & 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);
        }
@@ -1320,7 +1326,7 @@ void InsetMathHull::edit(Cursor & cur, bool left)
        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);
 }
 
@@ -1367,7 +1373,7 @@ void InsetMathHull::revealCodes(Cursor & cur) const
 }
 
 
-InsetBase::Code InsetMathHull::lyxCode() const
+Inset::Code InsetMathHull::lyxCode() const
 {
        return MATH_CODE;
 }
@@ -1438,7 +1444,7 @@ void InsetMathHull::read(Buffer const &, Lexer & lex)
 
 
 int InsetMathHull::plaintext(Buffer const &, odocstream & os,
-                             OutputParams const &) const
+                            OutputParams const &) const
 {
        if (0 && display()) {
                Dimension dim;
@@ -1463,7 +1469,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;