X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2FInsetMathHull.cpp;h=38f0226bc77fd97799cf8bef6f9f7be1239f6e1d;hb=98fb638d61d38df1443339de4e8ba58c7c81784a;hp=d21174ce447d23673ca42bd6601638cce2923b0b;hpb=6e3a75969b97a5db4c80c46be49d4deb122abfe7;p=lyx.git diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index d21174ce44..38f0226bc7 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -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" @@ -26,25 +26,25 @@ #include "InsetMathRef.h" #include "bufferview_funcs.h" -#include "lyxtext.h" +#include "Text.h" -#include "buffer.h" -#include "bufferparams.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 "Cursor.h" #include "debug.h" -#include "dispatchresult.h" -#include "funcrequest.h" +#include "DispatchResult.h" +#include "FuncRequest.h" #include "gettext.h" -#include "lyxrc.h" -#include "outputparams.h" +#include "LyXRC.h" +#include "OutputParams.h" #include "sgml.h" #include "TextPainter.h" -#include "undo.h" +#include "Undo.h" #include "insets/RenderPreview.h" #include "insets/InsetLabel.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(); } @@ -188,9 +190,9 @@ InsetMathHull::~InsetMathHull() {} -auto_ptr InsetMathHull::doClone() const +auto_ptr InsetMathHull::doClone() const { - return auto_ptr(new InsetMathHull(*this)); + return auto_ptr(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(); @@ -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; @@ -967,7 +975,7 @@ void InsetMathHull::doExtern(LCursor & cur, FuncRequest & func) #ifdef WITH_WARNINGS #warning temporarily disabled //if (cur.selection()) { - // MathArray ar; + // MathData ar; // selGet(cur.ar); // lyxerr << "use selection: " << ar << endl; // insert(pipeThroughExtern(lang, extra, ar)); @@ -975,7 +983,7 @@ void InsetMathHull::doExtern(LCursor & cur, FuncRequest & func) //} #endif - MathArray eq; + MathData eq; eq.push_back(MathAtom(new InsetMathChar('='))); // go to first item in line @@ -984,14 +992,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 +1011,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,7 +1026,7 @@ 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 @@ -1034,15 +1042,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); @@ -1128,7 +1134,7 @@ void InsetMathHull::doDispatch(LCursor & 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; @@ -1174,14 +1180,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 +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) @@ -1286,7 +1292,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 +1307,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 +1337,7 @@ docstring const InsetMathHull::editMessage() const } -void InsetMathHull::revealCodes(LCursor & cur) const +void InsetMathHull::revealCodes(Cursor & cur) const { if (!cur.inMathed()) return; @@ -1367,7 +1373,7 @@ void InsetMathHull::revealCodes(LCursor & cur) const } -InsetBase::Code InsetMathHull::lyxCode() const +Inset::Code InsetMathHull::lyxCode() const { return MATH_CODE; } @@ -1385,7 +1391,7 @@ bool InsetMathHull::searchForward(BufferView * bv, string const & str, #endif 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 +1408,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 +1435,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 +1444,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 +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;