diff --git a/src/insets/inset.C b/src/insets/inset.C index f708b80bd9..c5cc6ad5d3 100644 --- a/src/insets/inset.C +++ b/src/insets/inset.C @@ -20,6 +20,7 @@ #include "lyxfont.h" #include "lyxtext.h" #include "dimension.h" +#include "metricsinfo.h" #include "frontends/Painter.h" #include "frontends/mouse_state.h" @@ -146,7 +147,10 @@ int Inset::latexTextWidth(BufferView * bv) const int Inset::ascent(BufferView * bv, LyXFont const & font) const { Dimension dim; - dimension(bv, font, dim); + MetricsInfo mi; + mi.base.bv = bv; + mi.base.font = font; + metrics(mi, dim); return dim.ascent(); } @@ -154,7 +158,10 @@ int Inset::ascent(BufferView * bv, LyXFont const & font) const int Inset::descent(BufferView * bv, LyXFont const & font) const { Dimension dim; - dimension(bv, font, dim); + MetricsInfo mi; + mi.base.bv = bv; + mi.base.font = font; + metrics(mi, dim); return dim.descent(); } @@ -162,6 +169,9 @@ int Inset::descent(BufferView * bv, LyXFont const & font) const int Inset::width(BufferView * bv, LyXFont const & font) const { Dimension dim; - dimension(bv, font, dim); + MetricsInfo mi; + mi.base.bv = bv; + mi.base.font = font; + metrics(mi, dim); return dim.width(); } diff --git a/src/insets/inset.h b/src/insets/inset.h index b4f82328bb..844d9377ab 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -160,8 +160,6 @@ public: /// Inset(Inset const & in); /// - virtual void dimension(BufferView *, LyXFont const &, Dimension &) const = 0; - /// int ascent(BufferView *, LyXFont const &) const; /// int descent(BufferView *, LyXFont const &) const; diff --git a/src/insets/insetbase.h b/src/insets/insetbase.h index 52b5ec824b..ef87a2f966 100644 --- a/src/insets/insetbase.h +++ b/src/insets/insetbase.h @@ -17,6 +17,7 @@ class BufferView; class FuncRequest; class MetricsInfo; +class Dimension; class PainterInfo; /** Dispatch result codes @@ -49,14 +50,18 @@ enum dispatch_result { /// Common base class to all insets class InsetBase { public: + /// + typedef int difference_type; + /// short of anything else reasonable + typedef size_t size_type; /// type for cell indices - typedef size_t idx_type; + typedef size_t idx_type; /// type for cursor positions - typedef size_t pos_type; + typedef size_t pos_type; /// type for row numbers - typedef size_t row_type; + typedef size_t row_type; /// type for column numbers - typedef size_t col_type; + typedef size_t col_type; // the real dispatcher virtual dispatch_result dispatch @@ -64,7 +69,9 @@ public: /// small wrapper for the time being virtual dispatch_result localDispatch(FuncRequest const & cmd); - /// + /// compute the size of the object returned in dim + virtual void metrics(MetricsInfo & mi, Dimension & dim) const = 0; + /// draw inset and update (xo, yo)-cache virtual void draw(PainterInfo & pi, int x, int y) const = 0; /// diff --git a/src/insets/insetbibtex.C b/src/insets/insetbibtex.C index dc35dcc236..f0f536f23c 100644 --- a/src/insets/insetbibtex.C +++ b/src/insets/insetbibtex.C @@ -7,8 +7,8 @@ * * Full author contact details are available in file CREDITS */ -#include +#include #include "insetbibtex.h" #include "buffer.h" @@ -40,15 +40,9 @@ InsetBibtex::InsetBibtex(InsetCommandParams const & p) {} -// InsetBibtex::InsetBibtex(InsetCommandParams const & p, bool) -// : InsetCommand(p, false) -// {} - - InsetBibtex::~InsetBibtex() { - InsetCommandMailer mailer("bibtex", *this); - mailer.hideDialog(); + InsetCommandMailer("bibtex", *this).hideDialog(); } diff --git a/src/insets/insetbutton.C b/src/insets/insetbutton.C index 5310940d6c..796d46d9a8 100644 --- a/src/insets/insetbutton.C +++ b/src/insets/insetbutton.C @@ -28,15 +28,14 @@ using std::ostream; using std::endl; -void InsetButton::dimension(BufferView * bv, LyXFont const &, - Dimension & dim) const +void InsetButton::metrics(MetricsInfo & mi, Dimension & dim) const { - lyx::Assert(bv); + lyx::Assert(mi.base.bv); LyXFont font(LyXFont::ALL_SANE); font.decSize(); - string const s = getScreenLabel(bv->buffer()); + string const s = getScreenLabel(mi.base.bv->buffer()); if (editable()) font_metrics::buttonText(s, font, dim.wid, dim.asc, dim.des); diff --git a/src/insets/insetbutton.h b/src/insets/insetbutton.h index beb127761c..04b5cd1df8 100644 --- a/src/insets/insetbutton.h +++ b/src/insets/insetbutton.h @@ -23,7 +23,7 @@ class InsetButton: public Inset { public: /// - void dimension(BufferView *, LyXFont const &, Dimension &) const; + void metrics(MetricsInfo &, Dimension &) const; /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/insets/insetcaption.C b/src/insets/insetcaption.C index 0da530552d..93a579f8c9 100644 --- a/src/insets/insetcaption.C +++ b/src/insets/insetcaption.C @@ -29,6 +29,7 @@ using std::ostream; using std::endl; + InsetCaption::InsetCaption(BufferParams const & bp) : InsetText(bp) { @@ -45,7 +46,6 @@ void InsetCaption::write(Buffer const * buf, ostream & os) const } - void InsetCaption::read(Buffer const * buf, LyXLex & lex) { #if 0 diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index b6cae4d6e2..facf2f5f36 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -124,16 +124,15 @@ int InsetCollapsable::height_collapsed() const } -void InsetCollapsable::dimension(BufferView * bv, LyXFont const & font, - Dimension & dim) const +void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const { dimension_collapsed(dim); if (collapsed_) return; Dimension insetdim; - inset.dimension(bv, font, insetdim); + inset.metrics(mi, insetdim); dim.des += insetdim.height() + TEXT_TO_BOTTOM_OFFSET; - dim.wid = max(dim.wid, insetdim.width()); + dim.wid = max(dim.wid, insetdim.wid); } diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index e7dc0cbaa7..f6b8c70cd3 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -45,7 +45,7 @@ public: /// void write(Buffer const *, std::ostream &) const; /// - void dimension(BufferView *, LyXFont const &, Dimension &) const; + void metrics(MetricsInfo &, Dimension &) const; /// void draw(PainterInfo & pi, int x, int y) const; /// draw, either inlined (no button) or collapsed/open diff --git a/src/insets/inseterror.C b/src/insets/inseterror.C index 8bc8a7e5bb..ae0d0b125c 100644 --- a/src/insets/inseterror.C +++ b/src/insets/inseterror.C @@ -61,14 +61,14 @@ dispatch_result InsetError::localDispatch(FuncRequest const & cmd) } -void InsetError::dimension(BufferView *, LyXFont const & font, - Dimension & dim) const +void InsetError::metrics(MetricsInfo & mi, Dimension & dim) const { LyXFont efont; - efont.setSize(font.size()).decSize(); - dim.asc = font_metrics::maxAscent(efont) + 1; - dim.des = font_metrics::maxDescent(efont) + 1; - dim.wid = 6 + font_metrics::width(_("Error"), efont); + efont.setSize(mi.base.font.size()).decSize(); + dim_.asc = font_metrics::maxAscent(efont) + 1; + dim_.des = font_metrics::maxDescent(efont) + 1; + dim_.wid = 6 + font_metrics::width(_("Error"), efont); + dim = dim_; } @@ -84,7 +84,11 @@ void InsetError::draw(PainterInfo & pi, int x, int y) const // Draw as "Error" in a framed box x += 1; Dimension dim; - dimension(pi.base.bv, pi.base.font, dim); + MetricsInfo mi; + mi.base.bv = pi.base.bv; + mi.base.font = pi.base.font; + metrics(mi, dim); + dim_ = dim; pi.pain.fillRectangle(x, y - dim.asc + 1, dim.wid - 2, dim.asc + dim.des - 2, LColor::insetbg); pi.pain.rectangle(x, y - dim.asc + 1, diff --git a/src/insets/inseterror.h b/src/insets/inseterror.h index 919f6b0cd6..d5d951c4e3 100644 --- a/src/insets/inseterror.h +++ b/src/insets/inseterror.h @@ -14,6 +14,7 @@ #include "inset.h" #include "LString.h" +#include "dimension.h" /** Used for error messages from LaTeX runs. @@ -30,7 +31,7 @@ public: /// virtual dispatch_result localDispatch(FuncRequest const & cmd); /// - void dimension(BufferView *, LyXFont const &, Dimension &) const; + void metrics(MetricsInfo &, Dimension &) const; /// void draw(PainterInfo & pi, int x, int y) const; /// @@ -65,5 +66,7 @@ public: private: /// string contents; + /// + mutable Dimension dim_; }; #endif diff --git a/src/insets/insetert.C b/src/insets/insetert.C index c4141894f0..a2c2d0478a 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -552,13 +552,12 @@ bool InsetERT::checkInsertChar(LyXFont & /* font */) } -void InsetERT::dimension(BufferView * bv, LyXFont const & font, - Dimension & dim) const +void InsetERT::metrics(MetricsInfo & mi, Dimension & dim) const { if (inlined()) - inset.dimension(bv, font, dim); + inset.metrics(mi, dim); else - InsetCollapsable::dimension(bv, font, dim); + InsetCollapsable::metrics(mi, dim); } diff --git a/src/insets/insetert.h b/src/insets/insetert.h index 3483cbd2e0..377d0ffc4f 100644 --- a/src/insets/insetert.h +++ b/src/insets/insetert.h @@ -99,7 +99,7 @@ public: WordLangTuple const selectNextWordToSpellcheck(BufferView *, float &) const; /// - void dimension(BufferView *, LyXFont const &, Dimension &) const; + void metrics(MetricsInfo &, Dimension &) const; /// void draw(PainterInfo & pi, int x, int y) const; /// set the status of the inset diff --git a/src/insets/insetfootlike.C b/src/insets/insetfootlike.C index 7922e022a6..ecf1dc1bd4 100644 --- a/src/insets/insetfootlike.C +++ b/src/insets/insetfootlike.C @@ -10,7 +10,6 @@ #include - #include "insetfootlike.h" #include "lyxfont.h" #include "buffer.h" diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index c92b5b12ff..86df4442a0 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -285,8 +285,7 @@ bool InsetGraphics::imageIsDrawable() const } -void InsetGraphics::dimension(BufferView *, LyXFont const & font, - Dimension & dim) const +void InsetGraphics::metrics(MetricsInfo & mi, Dimension & dim) const { cache_->old_ascent = 50; if (imageIsDrawable()) @@ -298,7 +297,7 @@ void InsetGraphics::dimension(BufferView *, LyXFont const & font, else { int font_width = 0; - LyXFont msgFont(font); + LyXFont msgFont(mi.base.font); msgFont.setFamily(LyXFont::SANS_FAMILY); string const justname = OnlyFilename(params().filename); @@ -315,6 +314,7 @@ void InsetGraphics::dimension(BufferView *, LyXFont const & font, dim.wid = std::max(50, font_width + 15); } + dim_ = dim; } @@ -343,7 +343,11 @@ void InsetGraphics::draw(PainterInfo & pi, int x, int y) const int oasc = cache_->old_ascent; Dimension dim; - dimension(bv, pi.base.font, dim); + MetricsInfo mi; + mi.base.bv = pi.base.bv; + mi.base.font = pi.base.font; + metrics(mi, dim); + dim_ = dim; // we may have changed while someone other was drawing us so better // to not draw anything as we surely call to redraw ourself soon. @@ -367,14 +371,14 @@ void InsetGraphics::draw(PainterInfo & pi, int x, int y) const // we draw just a rectangle. if (imageIsDrawable()) { - pi.pain.image(x + TEXT_TO_INSET_OFFSET, y - dim.asc, - dim.wid - 2 * TEXT_TO_INSET_OFFSET, dim.asc + dim.des, + pi.pain.image(x + TEXT_TO_INSET_OFFSET, y - dim_.asc, + dim_.wid - 2 * TEXT_TO_INSET_OFFSET, dim_.asc + dim_.des, *cache_->loader.image()); } else { - pi.pain.rectangle(x + TEXT_TO_INSET_OFFSET, y - dim.asc, - dim.wid - 2 * TEXT_TO_INSET_OFFSET, dim.asc + dim.des); + pi.pain.rectangle(x + TEXT_TO_INSET_OFFSET, y - dim_.asc, + dim_.wid - 2 * TEXT_TO_INSET_OFFSET, dim_.asc + dim_.des); // Print the file name. LyXFont msgFont = pi.base.font; diff --git a/src/insets/insetgraphics.h b/src/insets/insetgraphics.h index 958dbc64b0..db6a01a29f 100644 --- a/src/insets/insetgraphics.h +++ b/src/insets/insetgraphics.h @@ -13,8 +13,9 @@ #ifndef INSET_GRAPHICS_H #define INSET_GRAPHICS_H -#include "insets/inset.h" -#include "insets/insetgraphicsParams.h" +#include "inset.h" +#include "insetgraphicsParams.h" +#include "dimension.h" #include #include @@ -34,7 +35,7 @@ public: /// virtual dispatch_result localDispatch(FuncRequest const & cmd); /// - void dimension(BufferView *, LyXFont const &, Dimension &) const; + void metrics(MetricsInfo &, Dimension &) const; /// void draw(PainterInfo & pi, int x, int y) const; /// @@ -113,6 +114,8 @@ private: friend class Cache; /// The pointer never changes although *cache_'s contents may. boost::scoped_ptr const cache_; + /// dimension cache + mutable Dimension dim_; }; diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 5f492c0745..6863c93f11 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -512,24 +512,16 @@ void InsetInclude::fillWithBibKeys(vector > & keys) const } -int InsetInclude::ascent(BufferView * bv, LyXFont const & font) const +void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const { - return preview_->previewReady() ? - preview_->pimage()->ascent() : InsetButton::ascent(bv, font); -} - - -int InsetInclude::descent(BufferView * bv, LyXFont const & font) const -{ - return preview_->previewReady() ? - preview_->pimage()->descent() : InsetButton::descent(bv, font); -} - - -int InsetInclude::width(BufferView * bv, LyXFont const & font) const -{ - return preview_->previewReady() ? - preview_->pimage()->width() : InsetButton::width(bv, font); + if (preview_->previewReady()) { + dim.asc = preview_->pimage()->ascent(); + dim.des = preview_->pimage()->descent(); + dim.wid = preview_->pimage()->width(); + } else { + InsetButton::metrics(mi, dim); + } + dim_ = dim; } @@ -545,7 +537,11 @@ void InsetInclude::draw(PainterInfo & pi, int x, int y) const preview_->startMonitoring(); Dimension dim; - dimension(pi.base.bv, pi.base.font, dim); + MetricsInfo mi; + mi.base.bv = pi.base.bv; + mi.base.font = pi.base.font; + metrics(mi, dim); + dim_ = dim; pi.pain.image(x, y - dim.asc, dim.wid, dim.height(), *(preview_->pimage()->image())); diff --git a/src/insets/insetinclude.h b/src/insets/insetinclude.h index b81e9df26c..a81b77f447 100644 --- a/src/insets/insetinclude.h +++ b/src/insets/insetinclude.h @@ -13,6 +13,7 @@ #define INSET_INCLUDE_H #include "insetcommand.h" +#include "dimension.h" #include @@ -60,11 +61,7 @@ public: virtual dispatch_result localDispatch(FuncRequest const & cmd); /// Override these InsetButton methods if Previewing - int ascent(BufferView *, LyXFont const &) const; - /// - int descent(BufferView *, LyXFont const &) const; - /// - int width(BufferView *, LyXFont const &) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; @@ -131,6 +128,9 @@ private: friend class PreviewImpl; /// The pointer never changes although *preview_'s contents may. boost::scoped_ptr const preview_; + + /// cache + mutable Dimension dim_; }; diff --git a/src/insets/insetlatexaccent.C b/src/insets/insetlatexaccent.C index 791269e73e..3fd62aa645 100644 --- a/src/insets/insetlatexaccent.C +++ b/src/insets/insetlatexaccent.C @@ -13,7 +13,6 @@ #include "insetlatexaccent.h" #include "debug.h" -#include "dimension.h" #include "lyxrc.h" #include "support/lstrings.h" #include "BufferView.h" @@ -264,9 +263,9 @@ void InsetLatexAccent::checkContents() } -void InsetLatexAccent::dimension(BufferView *, LyXFont const & font, - Dimension & dim) const +void InsetLatexAccent::metrics(MetricsInfo & mi, Dimension & dim) const { + LyXFont & font = mi.base.font; // This function is a bit too simplistic and is just a // "try to make a fit for all accents" approach, to // make it better we need to know what kind of accent is @@ -292,6 +291,7 @@ void InsetLatexAccent::dimension(BufferView *, LyXFont const & font, dim.des = font_metrics::maxDescent(font) + 4; dim.wid = font_metrics::width(contents, font) + 4; } + dim_ = dim; } @@ -363,7 +363,11 @@ void InsetLatexAccent::draw(PainterInfo & pi, int x, int baseline) const font.setLanguage(english_language); Dimension dim; - dimension(bv, font, dim); + MetricsInfo mi; + mi.base.bv = pi.base.bv; + mi.base.font = pi.base.font; + metrics(mi, dim); + dim_ = dim; if (candisp) { float x2 = x + (rbearing(font) - lbearing(font)) / 2.0; @@ -372,13 +376,13 @@ void InsetLatexAccent::draw(PainterInfo & pi, int x, int baseline) const if (plusasc) { // mark at the top hg = font_metrics::maxDescent(font); - y = baseline - dim.asc; + y = baseline - dim_.asc; if (font.shape() == LyXFont::ITALIC_SHAPE) x2 += (4.0 * hg) / 5.0; // italic } else { // at the bottom - hg = dim.des; + hg = dim_.des; y = baseline; } @@ -395,7 +399,7 @@ void InsetLatexAccent::draw(PainterInfo & pi, int x, int baseline) const tmpx += int(0.8 * hg); // italic lyxerr[Debug::KEY] << "Removing dot." << endl; // remove the dot first - pi.pain.fillRectangle(x + tmpx, tmpvar, dim.wid, + pi.pain.fillRectangle(x + tmpx, tmpvar, dim_.wid, font_metrics::ascent('i', pi.base.font) - font_metrics::ascent('x', pi.base.font) - 1, backgroundColor()); @@ -506,17 +510,17 @@ void InsetLatexAccent::draw(PainterInfo & pi, int x, int baseline) const case SPECIAL_CARON: // special caron { switch (ic) { - case 'L': dim.wid = int(4.0 * dim.wid / 5.0); break; + case 'L': dim_.wid = int(4.0 * dim_.wid / 5.0); break; case 't': y -= int(hg35 / 2.0); break; } int xp[3], yp[3]; - xp[0] = int(x + dim.wid); + xp[0] = int(x + dim_.wid); yp[0] = int(y + hg35 + hg); - xp[1] = int(x + dim.wid + (hg35 / 2.0)); + xp[1] = int(x + dim_.wid + (hg35 / 2.0)); yp[1] = int(y + hg + (hg35 / 2.0)); - xp[2] = int(x + dim.wid + (hg35 / 2.0)); + xp[2] = int(x + dim_.wid + (hg35 / 2.0)); yp[2] = y + int(hg); pi.pain.lines(xp, yp, 3); @@ -577,7 +581,7 @@ void InsetLatexAccent::draw(PainterInfo & pi, int x, int baseline) const xp[0] = int(x); yp[0] = y + int(3.0 * hg); - xp[1] = int(x + float(dim.wid) * 0.75); + xp[1] = int(x + float(dim_.wid) * 0.75); yp[1] = y + int(hg); pi.pain.lines(xp, yp, 2); @@ -592,10 +596,10 @@ void InsetLatexAccent::draw(PainterInfo & pi, int x, int baseline) const } } else { pi.pain.fillRectangle(x + 1, - baseline - dim.asc + 1, dim.wid - 2, - dim.asc + dim.des - 2, backgroundColor()); - pi.pain.rectangle(x + 1, baseline - dim.asc + 1, - dim.wid - 2, dim.asc + dim.des - 2); + baseline - dim_.asc + 1, dim_.wid - 2, + dim_.asc + dim_.des - 2, backgroundColor()); + pi.pain.rectangle(x + 1, baseline - dim_.asc + 1, + dim_.wid - 2, dim_.asc + dim_.des - 2); pi.pain.text(x + 2, baseline, contents, font); } } diff --git a/src/insets/insetlatexaccent.h b/src/insets/insetlatexaccent.h index 414369a5a9..c0b3dee272 100644 --- a/src/insets/insetlatexaccent.h +++ b/src/insets/insetlatexaccent.h @@ -12,11 +12,9 @@ #ifndef INSET_LATEX_ACCENT_H #define INSET_LATEX_ACCENT_H - #include "inset.h" #include "LString.h" - -class LyXLex; +#include "dimension.h" /** Insertion of accents @@ -34,7 +32,7 @@ public: explicit InsetLatexAccent(string const & string); /// - void dimension(BufferView *, LyXFont const &, Dimension &) const; + void metrics(MetricsInfo &, Dimension &) const; /// void draw(PainterInfo & pi, int x, int y) const; /// @@ -131,6 +129,8 @@ private: bool plusdesc; /// international char mutable char ic; + /// + mutable Dimension dim_; }; diff --git a/src/insets/insetminipage.C b/src/insets/insetminipage.C index 6a6f3f16d9..70440b4e5b 100644 --- a/src/insets/insetminipage.C +++ b/src/insets/insetminipage.C @@ -218,14 +218,13 @@ void InsetMinipage::read(Buffer const * buf, LyXLex & lex) } -void InsetMinipage::dimension(BufferView * bv, LyXFont const & font, - Dimension & dim) const +void InsetMinipage::metrics(MetricsInfo & mi, Dimension & dim) const { if (collapsed_) dimension_collapsed(dim); else { Dimension d; - InsetCollapsable::dimension(bv, font, d); + InsetCollapsable::metrics(mi, d); switch (params_.pos) { case top: dim.asc = d.asc; diff --git a/src/insets/insetminipage.h b/src/insets/insetminipage.h index 2db509f111..4d72d04777 100644 --- a/src/insets/insetminipage.h +++ b/src/insets/insetminipage.h @@ -68,7 +68,7 @@ public: /// Inset * clone(Buffer const &) const; /// - void dimension(BufferView *, LyXFont const &, Dimension &) const; + void metrics(MetricsInfo &, Dimension &) const; /// Inset::Code lyxCode() const { return Inset::MINIPAGE_CODE; } /// diff --git a/src/insets/insetnewline.C b/src/insets/insetnewline.C index 0ac4e9a442..c7a3adeee9 100644 --- a/src/insets/insetnewline.C +++ b/src/insets/insetnewline.C @@ -38,9 +38,9 @@ void InsetNewline::write(Buffer const *, ostream & os) const } -void InsetNewline::dimension(BufferView *, LyXFont const & font, - Dimension & dim) const +void InsetNewline::metrics(MetricsInfo & mi, Dimension & dim) const { + LyXFont & font = mi.base.font; dim.asc = font_metrics::maxAscent(font); dim.des = font_metrics::maxDescent(font); dim.wid = font_metrics::width('n', font); diff --git a/src/insets/insetnewline.h b/src/insets/insetnewline.h index 7b4188f402..b2d7b13798 100644 --- a/src/insets/insetnewline.h +++ b/src/insets/insetnewline.h @@ -26,7 +26,7 @@ public: Inset::Code lyxCode() const { return Inset::NEWLINE_CODE; } - void dimension(BufferView *, LyXFont const &, Dimension &) const; + void metrics(MetricsInfo &, Dimension &) const; virtual void draw(PainterInfo & pi, int x, int y) const; diff --git a/src/insets/insetquotes.C b/src/insets/insetquotes.C index 24f44ff444..91cf57cbaa 100644 --- a/src/insets/insetquotes.C +++ b/src/insets/insetquotes.C @@ -171,9 +171,9 @@ string const InsetQuotes::dispString(Language const * loclang) const } -void InsetQuotes::dimension(BufferView *, LyXFont const & font, - Dimension & dim) const +void InsetQuotes::metrics(MetricsInfo & mi, Dimension & dim) const { + LyXFont & font = mi.base.font; dim.asc = font_metrics::maxAscent(font); dim.des = font_metrics::maxDescent(font); dim.wid = 0; diff --git a/src/insets/insetquotes.h b/src/insets/insetquotes.h index 5816a1e86c..8771546f65 100644 --- a/src/insets/insetquotes.h +++ b/src/insets/insetquotes.h @@ -69,8 +69,9 @@ public: InsetQuotes(char c, BufferParams const & params); /// Inset * clone(Buffer const &) const; + /// - void dimension(BufferView *, LyXFont const &, Dimension &) const; + void metrics(MetricsInfo &, Dimension &) const; /// void draw(PainterInfo & pi, int x, int y) const; #if 0 diff --git a/src/insets/insetspace.C b/src/insets/insetspace.C index 05f6beca52..ec1192d4d3 100644 --- a/src/insets/insetspace.C +++ b/src/insets/insetspace.C @@ -45,9 +45,9 @@ InsetSpace::Kind InsetSpace::kind() const } -void InsetSpace::dimension(BufferView *, LyXFont const & font, - Dimension & dim) const +void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const { + LyXFont & font = mi.base.font; dim.asc = font_metrics::maxAscent(font); dim.des = font_metrics::maxDescent(font); diff --git a/src/insets/insetspace.h b/src/insets/insetspace.h index a124a670f2..f616ab7dad 100644 --- a/src/insets/insetspace.h +++ b/src/insets/insetspace.h @@ -54,7 +54,7 @@ public: /// Kind kind() const; /// - void dimension(BufferView *, LyXFont const &, Dimension &) const; + void metrics(MetricsInfo &, Dimension &) const; /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/insets/insetspecialchar.C b/src/insets/insetspecialchar.C index 8a67a62141..76e4023ef8 100644 --- a/src/insets/insetspecialchar.C +++ b/src/insets/insetspecialchar.C @@ -39,9 +39,9 @@ InsetSpecialChar::Kind InsetSpecialChar::kind() const } -void InsetSpecialChar::dimension(BufferView *, LyXFont const & font, - Dimension & dim) const +void InsetSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const { + LyXFont & font = mi.base.font; dim.asc = font_metrics::maxAscent(font); dim.des = font_metrics::maxDescent(font); diff --git a/src/insets/insetspecialchar.h b/src/insets/insetspecialchar.h index 69264a4e82..e34505cbf8 100644 --- a/src/insets/insetspecialchar.h +++ b/src/insets/insetspecialchar.h @@ -46,7 +46,7 @@ public: /// Kind kind() const; /// - void dimension(BufferView *, LyXFont const &, Dimension &) const; + void metrics(MetricsInfo &, Dimension &) const; /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index cf36af15f0..c3067d9c44 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -243,7 +243,7 @@ void InsetTabular::read(Buffer const * buf, LyXLex & lex) } -void InsetTabular::dimension(BufferView *, LyXFont const &, +void InsetTabular::metrics(MetricsInfo &, Dimension & dim) const { dim.asc = tabular->GetAscentOfRow(0); diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index 93a9ef6f5c..5c64dd11a0 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -86,7 +86,7 @@ public: /// void write(Buffer const *, std::ostream &) const; /// - void dimension(BufferView *, LyXFont const &, Dimension &) const; + void metrics(MetricsInfo &, Dimension &) const; /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/insets/insettext.C b/src/insets/insettext.C index c7c3b74f28..bdbf361b74 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -293,15 +293,14 @@ void InsetText::read(Buffer const * buf, LyXLex & lex) } -void InsetText::dimension(BufferView * bv, LyXFont const &, - Dimension & dim) const +void InsetText::metrics(MetricsInfo & mi, Dimension & dim) const { + BufferView * bv = mi.base.bv; LyXText * text = getLyXText(bv); dim.asc = text->rows().begin()->ascent_of_text() + TEXT_TO_INSET_OFFSET; dim.des = text->height - dim.asc + TEXT_TO_INSET_OFFSET; dim.wid = max(textWidth(bv), int(text->width)) + 2 * TEXT_TO_INSET_OFFSET; dim.wid = max(dim.wid, 10); - // cache it dim_ = dim; } @@ -336,9 +335,6 @@ void InsetText::draw(PainterInfo & pi, int x, int baseline) const BufferView * bv = pi.base.bv; Painter & pain = pi.pain; - // call this method so that dim_ has the right value - dimension(bv, pi.base.font, dim_); - // repaint the background if needed if (backgroundColor() != LColor::background) clearInset(bv, start_x + TEXT_TO_INSET_OFFSET, baseline); diff --git a/src/insets/insettext.h b/src/insets/insettext.h index e1ad8a8788..f32be50b43 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -87,7 +87,7 @@ public: /// void write(Buffer const *, std::ostream &) const; /// - void dimension(BufferView *, LyXFont const &, Dimension &) const; + void metrics(MetricsInfo &, Dimension &) const; /// int textWidth(BufferView *, bool fordraw = false) const; /// diff --git a/src/mathed/button_inset.C b/src/mathed/button_inset.C index 0784850ac1..8a8e59d85a 100644 --- a/src/mathed/button_inset.C +++ b/src/mathed/button_inset.C @@ -16,7 +16,7 @@ ButtonInset::ButtonInset() {} -Dimension ButtonInset::metrics(MetricsInfo & mi) const +void ButtonInset::metrics(MetricsInfo & mi, Dimension & dim) const { FontSetChanger dummy(mi.base, "textnormal"); if (editing()) { @@ -28,7 +28,7 @@ Dimension ButtonInset::metrics(MetricsInfo & mi) const mathed_string_dim(mi.base.font, screenLabel(), dim_); dim_.wid += 10; } - return dim_; + dim = dim_; } diff --git a/src/mathed/button_inset.h b/src/mathed/button_inset.h index 31e534450a..8174f3cc35 100644 --- a/src/mathed/button_inset.h +++ b/src/mathed/button_inset.h @@ -23,7 +23,7 @@ public: /// ButtonInset(); /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 6ebf101eac..b388923e7c 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -89,11 +89,11 @@ InsetFormula::InsetFormula(InsetFormula const & other) {} -InsetFormula::InsetFormula(BufferView * bv) +InsetFormula::InsetFormula(BufferView *) : par_(MathAtom(new MathHullInset)), preview_(new PreviewImpl(*this)) { - view_ = bv->owner()->view(); + //view_ = bv->owner()->view(); } @@ -152,7 +152,7 @@ int InsetFormula::ascii(Buffer const *, ostream & os, int) const par()->drawT(tpain, 0, dim.ascent()); tpain.show(os, 3); // reset metrics cache to "real" values - metrics(); + //metrics(); return tpain.textheight(); } else { WriteStream wi(os, false, true); @@ -201,7 +201,7 @@ void InsetFormula::read(Buffer const *, LyXLex & lex) } } } - metrics(); + //metrics(); } @@ -220,7 +220,11 @@ void InsetFormula::draw(PainterInfo & pi, int x, int y) const bool const use_preview = preview_->previewReady(); Dimension dim; - dimension(pi.base.bv, pi.base.font, dim); + MetricsInfo mi; + mi.base.bv = pi.base.bv; + mi.base.font = pi.base.font; + metrics(mi, dim); + dim_ = dim; int const w = dim.wid; int const d = dim.des; int const a = dim.asc; @@ -282,23 +286,25 @@ bool InsetFormula::insetAllowed(Inset::Code code) const } -void InsetFormula::dimension(BufferView * bv, LyXFont const & font, - Dimension & dim) const +void InsetFormula::metrics(MetricsInfo & m, Dimension & dim) const { - metrics(bv, font, dim); + view_ = m.base.bv; if (preview_->previewReady()) { - dim.asc = preview_->pimage()->ascent(); - int const descent = preview_->pimage()->descent(); - dim.des = display() ? descent + 12 : descent; + dim_.asc = preview_->pimage()->ascent(); + dim_.des = preview_->pimage()->descent(); // insert a one pixel gap in front of the formula - dim.wid = 1 + preview_->pimage()->width(); + dim_.wid = 1 + preview_->pimage()->width(); + if (display()) + dim_.des += 12; } else { - MetricsInfo mi; - mi.base.bv = bv; - dim = par()->metrics(mi); - dim.asc += 1; - dim.des += 1; + MetricsInfo mi = m; + mi.base.style = LM_ST_TEXT; + mi.base.font.setColor(LColor::math); + par()->metrics(mi, dim_); + dim_.asc += 1; + dim_.des += 1; } + dim = dim_; } diff --git a/src/mathed/formula.h b/src/mathed/formula.h index 201b71027a..ec6cc3871c 100644 --- a/src/mathed/formula.h +++ b/src/mathed/formula.h @@ -15,12 +15,12 @@ #ifndef INSET_FORMULA_H #define INSET_FORMULA_H - #include "formulabase.h" #include "math_atom.h" #include + /// The main LyX math inset class InsetFormula : public InsetFormulaBase { public: @@ -35,7 +35,7 @@ public: /// ~InsetFormula(); /// - void dimension(BufferView *, LyXFont const &, Dimension &) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index be5b8d97db..7691765360 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -27,11 +27,11 @@ #include "debug.h" #include "math_support.h" #include "metricsinfo.h" +#include "math_data.h" #include "support/lstrings.h" #include "frontends/LyXView.h" #include "frontends/font_metrics.h" #include "frontends/mouse_state.h" -#include "Lsstream.h" #include "math_arrayinset.h" #include "math_charinset.h" #include "math_deliminset.h" @@ -83,7 +83,7 @@ bool openNewInset(BufferView * bv, UpdatableInset * new_inset) InsetFormulaBase::InsetFormulaBase() - : font_(), xo_(0), yo_(0) + : xo_(0), yo_(0) { // This is needed as long the math parser is not re-entrant initMath(); @@ -133,7 +133,7 @@ void InsetFormulaBase::handleFont BufferView * InsetFormulaBase::view() const { - return view_.lock().get(); + return view_; } @@ -141,27 +141,6 @@ void InsetFormulaBase::validate(LaTeXFeatures &) const {} -void InsetFormulaBase::metrics(BufferView * bv, LyXFont const & f, - Dimension & /*dim*/) const -{ - font_ = f; - metrics(bv); -} - - -void InsetFormulaBase::metrics(BufferView * bv) const -{ - if (bv) - view_ = bv->owner()->view(); - MetricsInfo mi; - mi.base.bv = bv; - mi.base.style = LM_ST_TEXT; - mi.base.font = font_; - mi.base.font.setColor(LColor::math); - par()->metrics(mi); -} - - string const InsetFormulaBase::editMessage() const { return _("Math editor mode"); @@ -211,7 +190,9 @@ void InsetFormulaBase::fitInsetCursor(BufferView * bv) const if (!mathcursor) return; int x, y, asc, des; - math_font_max_dim(font_, asc, des); + asc = 10; + des = 2; + //math_font_max_dim(font_, asc, des); getCursorPos(bv, x, y); //y += yo_; //lyxerr << "fitInsetCursor: x: " << x << " y: " << y << " yo: " << yo_ << endl; @@ -252,9 +233,11 @@ dispatch_result InsetFormulaBase::lfunMouseRelease(FuncRequest const & cmd) } if (cmd.button() == mouse_button::button2) { + MathArray ar; + asArray(bv->getClipboard(), ar); mathcursor->selClear(); mathcursor->setPos(cmd.x + xo_, cmd.y + yo_); - mathcursor->insert(asArray(bv->getClipboard())); + mathcursor->insert(ar); bv->updateInset(this); return DISPATCHED; } @@ -284,7 +267,7 @@ dispatch_result InsetFormulaBase::lfunMousePress(FuncRequest const & cmd) lyxerr[Debug::MATHED] << "re-create cursor" << endl; releaseMathCursor(bv); mathcursor = new MathCursor(this, cmd.x == 0); - metrics(bv); + //metrics(bv); mathcursor->setPos(cmd.x + xo_, cmd.y + yo_); } @@ -356,10 +339,10 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd) releaseMathCursor(bv); if (!cmd.argument.empty()) { mathcursor = new MathCursor(this, cmd.argument == "left"); - metrics(bv); + //metrics(bv); } else { mathcursor = new MathCursor(this, true); - metrics(bv); + //metrics(bv); mathcursor->setPos(cmd.x + xo_, cmd.y + yo_); } // if that is removed, we won't get the magenta box when entering an @@ -681,8 +664,8 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd) bv->lockedInsetStoreUndo(Undo::EDIT); if (argument.size() == 1) result = mathcursor->interpret(argument[0]) ? DISPATCHED : FINISHED_RIGHT; - else - mathcursor->insert(asArray(argument)); + else + mathcursor->insert(argument); } break; @@ -811,13 +794,13 @@ Inset::Code InsetFormulaBase::lyxCode() const int InsetFormulaBase::ylow() const { - return yo_ - ascent(view(), font_); + return yo_ - dim_.asc; } int InsetFormulaBase::yhigh() const { - return yo_ + descent(view(), font_); + return yo_ + dim_.des; } @@ -829,7 +812,7 @@ int InsetFormulaBase::xlow() const int InsetFormulaBase::xhigh() const { - return xo_ + width(view(), font_); + return xo_ + dim_.wid; } @@ -868,7 +851,7 @@ bool InsetFormulaBase::searchForward(BufferView * bv, string const & str, } delete mathcursor; mathcursor = new MathCursor(this, true); - metrics(bv); + //metrics(bv); mathcursor->setSelection(it, ar.size()); current = it; it.jump(ar.size()); diff --git a/src/mathed/formulabase.h b/src/mathed/formulabase.h index 691b8205f7..afa498d3a9 100644 --- a/src/mathed/formulabase.h +++ b/src/mathed/formulabase.h @@ -14,7 +14,7 @@ #define INSET_FORMULABASE_H #include "insets/updatableinset.h" -#include "lyxfont.h" +#include "dimension.h" #include #include @@ -108,15 +108,10 @@ private: protected: /// - mutable boost::weak_ptr view_; - /// - mutable LyXFont font_; + //mutable boost::weak_ptr view_; + mutable BufferView * view_; protected: - /// - void metrics(BufferView * bv, LyXFont const & font, Dimension & dim) const; - /// - void metrics(BufferView * bv = 0) const; /// void handleFont(BufferView * bv, string const & arg, string const & font); @@ -124,6 +119,8 @@ protected: mutable int xo_; /// mutable int yo_; + /// + mutable Dimension dim_; }; // We don't really mess want around with mathed stuff outside mathed. diff --git a/src/mathed/formulamacro.C b/src/mathed/formulamacro.C index 6eeb17968f..42f8f19755 100644 --- a/src/mathed/formulamacro.C +++ b/src/mathed/formulamacro.C @@ -29,16 +29,13 @@ #include "frontends/Painter.h" #include "frontends/font_metrics.h" #include "support/lyxlib.h" +#include "support/lstrings.h" #include "support/LOstream.h" #include "debug.h" #include "lyxlex.h" #include "lyxtext.h" -#include "lyxfont.h" - #include "Lsstream.h" -#include "support/BoostFormat.h" - using std::ostream; extern MathCursor * mathcursor; @@ -125,31 +122,24 @@ void InsetFormulaMacro::read(std::istream & is) MathMacroTemplate * p = new MathMacroTemplate(is); setInsetName(p->name()); MathMacroTable::create(MathAtom(p)); - metrics(); + //metrics(); } string InsetFormulaMacro::prefix() const { -#if USE_BOOST_FORMAT - return STRCONV(boost::io::str(boost::format(_(" Macro: %s: ")) % - STRCONV(getInsetName()))); -#else - return _(" Macro: ") + getInsetName() + ": "; -#endif + return bformat(_(" Macro: %s: "), getInsetName()); } -void InsetFormulaMacro::dimension(BufferView * bv, LyXFont const & font, - Dimension & dim) const +void InsetFormulaMacro::metrics(MetricsInfo & m, Dimension & dim) const { - MetricsInfo mi; - mi.base.bv = bv; - mi.base.font = font; - dim = par()->metrics(mi); - dim.asc += 5; - dim.des += 5; - dim.wid += 10 + font_metrics::width(prefix(), font); + MetricsInfo mi = m; + par()->metrics(mi, dim_); + dim_.asc += 5; + dim_.des += 5; + dim_.wid += 10 + font_metrics::width(prefix(), mi.base.font); + dim = dim_; } @@ -182,7 +172,11 @@ void InsetFormulaMacro::draw(PainterInfo & p, int x, int y) const pi.base.font = font; Dimension dim; - dimension(pi.base.bv, font, dim); + MetricsInfo mi; + mi.base.bv = pi.base.bv; + mi.base.font = pi.base.font; + metrics(mi, dim); + dim_ = dim; int const a = y - dim.asc + 1; int const w = dim.wid - 2; int const h = dim.height() - 2; diff --git a/src/mathed/formulamacro.h b/src/mathed/formulamacro.h index 27f56c5920..a28efe39ea 100644 --- a/src/mathed/formulamacro.h +++ b/src/mathed/formulamacro.h @@ -33,7 +33,7 @@ public: /// constructs a mocro from its LaTeX definition explicit InsetFormulaMacro(string const & s); /// - void dimension(BufferView *, LyXFont const &, Dimension &) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; diff --git a/src/mathed/math_amsarrayinset.C b/src/mathed/math_amsarrayinset.C index bfb6f2032c..ea64089128 100644 --- a/src/mathed/math_amsarrayinset.C +++ b/src/mathed/math_amsarrayinset.C @@ -3,7 +3,6 @@ #include "math_amsarrayinset.h" #include "math_mathmlstream.h" #include "metricsinfo.h" -#include "math_support.h" #include "math_streamstr.h" #include "math_support.h" #include "Lsstream.h" @@ -57,14 +56,14 @@ char const * MathAMSArrayInset::name_right() const } -Dimension MathAMSArrayInset::metrics(MetricsInfo & mi) const +void MathAMSArrayInset::metrics(MetricsInfo & mi, Dimension & dim) const { MetricsInfo m = mi; if (m.base.style == LM_ST_DISPLAY) m.base.style = LM_ST_TEXT; MathGridInset::metrics(m); dim_.wid += 12; - return dim_; + dim = dim_; } diff --git a/src/mathed/math_amsarrayinset.h b/src/mathed/math_amsarrayinset.h index 47332517e6..c7896421e4 100644 --- a/src/mathed/math_amsarrayinset.h +++ b/src/mathed/math_amsarrayinset.h @@ -22,7 +22,7 @@ public: /// MathInset * clone() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pain, int x, int y) const; /// diff --git a/src/mathed/math_arrayinset.C b/src/mathed/math_arrayinset.C index 9ccd154006..ec78e036a3 100644 --- a/src/mathed/math_arrayinset.C +++ b/src/mathed/math_arrayinset.C @@ -63,12 +63,12 @@ MathInset * MathArrayInset::clone() const } -Dimension MathArrayInset::metrics(MetricsInfo & mi) const +void MathArrayInset::metrics(MetricsInfo & mi, Dimension & dim) const { ArrayChanger dummy(mi.base); MathGridInset::metrics(mi); metricsMarkers2(); - return dim_; + dim = dim_; } diff --git a/src/mathed/math_arrayinset.h b/src/mathed/math_arrayinset.h index 05e77e9139..ee3f7545fb 100644 --- a/src/mathed/math_arrayinset.h +++ b/src/mathed/math_arrayinset.h @@ -27,7 +27,7 @@ public: /// MathInset * clone() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/mathed/math_biginset.C b/src/mathed/math_biginset.C index 0824bfbb66..bc56b011d4 100644 --- a/src/mathed/math_biginset.C +++ b/src/mathed/math_biginset.C @@ -35,14 +35,14 @@ double MathBigInset::increase() const } -Dimension MathBigInset::metrics(MetricsInfo & mi) const +void MathBigInset::metrics(MetricsInfo & mi, Dimension & dim) const { double const h = mathed_char_ascent(mi.base.font, 'I'); double const f = increase(); dim_.wid = 6; dim_.asc = int(h + f * h); dim_.des = int(f * h); - return dim_; + dim = dim_; } diff --git a/src/mathed/math_biginset.h b/src/mathed/math_biginset.h index fb5e99bcb8..e88b518c06 100644 --- a/src/mathed/math_biginset.h +++ b/src/mathed/math_biginset.h @@ -26,7 +26,7 @@ public: /// MathInset * clone() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/mathed/math_binaryopinset.C b/src/mathed/math_binaryopinset.C index e09edf5731..dd801913d0 100644 --- a/src/mathed/math_binaryopinset.C +++ b/src/mathed/math_binaryopinset.C @@ -28,7 +28,7 @@ int MathBinaryOpInset::opwidth() const } -Dimension MathBinaryOpInset::metrics(MetricsInfo & mi) const +void MathBinaryOpInset::metrics(MetricsInfo & mi, Dimension & dim) const { mi_ = mi; cell(0).metrics(mi); diff --git a/src/mathed/math_binominset.C b/src/mathed/math_binominset.C index a240adb6c6..fd7aa7ad73 100644 --- a/src/mathed/math_binominset.C +++ b/src/mathed/math_binominset.C @@ -31,7 +31,7 @@ int MathBinomInset::dw() const } -Dimension MathBinomInset::metrics(MetricsInfo & mi) const +void MathBinomInset::metrics(MetricsInfo & mi, Dimension & dim) const { ScriptChanger dummy(mi.base); cell(0).metrics(mi); @@ -39,7 +39,7 @@ Dimension MathBinomInset::metrics(MetricsInfo & mi) const dim_.asc = cell(0).height() + 4 + 5; dim_.des = cell(1).height() + 4 - 5; dim_.wid = max(cell(0).width(), cell(1).width()) + 2 * dw() + 4; - return dim_; + dim = dim_; } diff --git a/src/mathed/math_binominset.h b/src/mathed/math_binominset.h index 58f1534c36..3b72255614 100644 --- a/src/mathed/math_binominset.h +++ b/src/mathed/math_binominset.h @@ -19,7 +19,7 @@ public: /// void normalize(NormalStream &) const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo &, int x, int y) const; private: diff --git a/src/mathed/math_boxinset.C b/src/mathed/math_boxinset.C index e57a151e54..1729cd4ba8 100644 --- a/src/mathed/math_boxinset.C +++ b/src/mathed/math_boxinset.C @@ -32,12 +32,12 @@ void MathBoxInset::normalize(NormalStream & os) const } -Dimension MathBoxInset::metrics(MetricsInfo & mi) const +void MathBoxInset::metrics(MetricsInfo & mi, Dimension & dim) const { FontSetChanger dummy(mi.base, "textnormal"); cell(0).metrics(mi, dim_); metricsMarkers(); - return dim_; + dim = dim_; } diff --git a/src/mathed/math_boxinset.h b/src/mathed/math_boxinset.h index 754d9fd7d2..8358b99b65 100644 --- a/src/mathed/math_boxinset.h +++ b/src/mathed/math_boxinset.h @@ -19,7 +19,7 @@ public: /// mode_type currentMode() const { return TEXT_MODE; } /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/mathed/math_braceinset.C b/src/mathed/math_braceinset.C index 524fe4e673..b3fe857610 100644 --- a/src/mathed/math_braceinset.C +++ b/src/mathed/math_braceinset.C @@ -27,7 +27,7 @@ MathInset * MathBraceInset::clone() const } -Dimension MathBraceInset::metrics(MetricsInfo & mi) const +void MathBraceInset::metrics(MetricsInfo & mi, Dimension & dim) const { cell(0).metrics(mi); Dimension t; @@ -36,7 +36,7 @@ Dimension MathBraceInset::metrics(MetricsInfo & mi) const dim_.asc = max(cell(0).ascent(), t.asc); dim_.des = max(cell(0).descent(), t.des); dim_.wid = cell(0).width() + 2 * wid_; - return dim_; + dim = dim_; } diff --git a/src/mathed/math_braceinset.h b/src/mathed/math_braceinset.h index abc67b1f5b..2fc685ba75 100644 --- a/src/mathed/math_braceinset.h +++ b/src/mathed/math_braceinset.h @@ -22,7 +22,7 @@ public: /// we write extra braces in any case... bool extraBraces() const { return true; } /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo &, int x, int y) const; /// diff --git a/src/mathed/math_casesinset.C b/src/mathed/math_casesinset.C index ae04d38444..1c093bd738 100644 --- a/src/mathed/math_casesinset.C +++ b/src/mathed/math_casesinset.C @@ -20,11 +20,11 @@ MathInset * MathCasesInset::clone() const } -Dimension MathCasesInset::metrics(MetricsInfo & mi) const +void MathCasesInset::metrics(MetricsInfo & mi, Dimension & dim) const { MathGridInset::metrics(mi); dim_.wid += 8; - return dim_; + dim = dim_; } diff --git a/src/mathed/math_casesinset.h b/src/mathed/math_casesinset.h index 6349656fea..6864325c1e 100644 --- a/src/mathed/math_casesinset.h +++ b/src/mathed/math_casesinset.h @@ -14,7 +14,7 @@ public: /// MathInset * clone() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pain, int x, int y) const; diff --git a/src/mathed/math_charinset.C b/src/mathed/math_charinset.C index 827aa7f7ad..9884a2efe2 100644 --- a/src/mathed/math_charinset.C +++ b/src/mathed/math_charinset.C @@ -2,6 +2,7 @@ #include "math_charinset.h" #include "LColor.h" +#include "dimension.h" #include "frontends/Painter.h" #include "frontends/font_metrics.h" #include "support/LOstream.h" @@ -54,9 +55,8 @@ MathInset * MathCharInset::clone() const } -Dimension MathCharInset::metrics(MetricsInfo & mi) const +void MathCharInset::metrics(MetricsInfo & mi, Dimension & dim) const { - Dimension dim; #if 1 if (char_ == '=' && has_math_fonts) { FontSetChanger dummy(mi.base, "cmr"); @@ -82,7 +82,6 @@ Dimension MathCharInset::metrics(MetricsInfo & mi) const width_ += 2 * font_metrics::width(' ', font_); lyxerr << "MathCharInset::metrics: " << dim << "\n"; #endif - return dim; } diff --git a/src/mathed/math_charinset.h b/src/mathed/math_charinset.h index a98044cff2..4e49f34038 100644 --- a/src/mathed/math_charinset.h +++ b/src/mathed/math_charinset.h @@ -18,7 +18,7 @@ public: /// MathInset * clone() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/mathed/math_commentinset.C b/src/mathed/math_commentinset.C index 7c7400e3a1..11e5e6f3af 100644 --- a/src/mathed/math_commentinset.C +++ b/src/mathed/math_commentinset.C @@ -1,14 +1,14 @@ #include - #include "math_commentinset.h" +#include "math_data.h" +#include "math_support.h" #include "math_mathmlstream.h" #include "LaTeXFeatures.h" #include "support/LOstream.h" #include "textpainter.h" - MathCommentInset::MathCommentInset() : MathNestInset(1) {} @@ -17,7 +17,7 @@ MathCommentInset::MathCommentInset() MathCommentInset::MathCommentInset(string const & str) : MathNestInset(1) { - cell(0) = asArray(str); + asArray(str, cell(0)); } @@ -27,11 +27,11 @@ MathInset * MathCommentInset::clone() const } -Dimension MathCommentInset::metrics(MetricsInfo & mi) const +void MathCommentInset::metrics(MetricsInfo & mi, Dimension & dim) const { cell(0).metrics(mi); metricsMarkers(); - return dim_; + dim = dim_; } diff --git a/src/mathed/math_commentinset.h b/src/mathed/math_commentinset.h index 04b117ea95..c324482b6b 100644 --- a/src/mathed/math_commentinset.h +++ b/src/mathed/math_commentinset.h @@ -22,7 +22,7 @@ public: /// MathInset * clone() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index ac95f75b97..3e146f460a 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -346,6 +346,14 @@ void MathCursor::plainInsert(MathAtom const & t) } +void MathCursor::insert2(string const & str) +{ + MathArray ar; + asArray(str, ar); + insert(ar); +} + + void MathCursor::insert(string const & str) { //lyxerr << "inserting '" << str << "'\n"; @@ -373,7 +381,8 @@ void MathCursor::insert(MathAtom const & t) void MathCursor::niceInsert(string const & t) { - MathArray ar = asArray(t); + MathArray ar; + asArray(t, ar); if (ar.size() == 1) niceInsert(ar[0]); else @@ -624,7 +633,7 @@ void MathCursor::drawSelection(PainterInfo & pi) const void MathCursor::handleNest(MathAtom const & a) { MathAtom at = a; - at.nucleus()->cell(0) = asArray(grabAndEraseSelection()); + asArray(grabAndEraseSelection(), at.nucleus()->cell(0)); insert(at); pushRight(prevAtom()); } diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index 91ab25e470..7d30ae57e1 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -63,6 +63,8 @@ public: /// void insert(MathArray const &); /// + void insert2(string const &); + /// void paste(string const & data); /// return false for empty math insets bool erase(); diff --git a/src/mathed/math_data.C b/src/mathed/math_data.C index de0588783a..124097c15d 100644 --- a/src/mathed/math_data.C +++ b/src/mathed/math_data.C @@ -12,6 +12,7 @@ #include "debug.h" #include "support/LAssert.h" #include "metricsinfo.h" +#include "math_data.h" #include "frontends/Painter.h" #include "textpainter.h" @@ -220,8 +221,9 @@ void MathArray::metrics(MetricsInfo & mi) const if (!empty()) { dim_.wid = 0; + Dimension d; for (const_iterator it = begin(), et = end(); it != et; ++it) { - Dimension d = (*it)->metrics(mi); + (*it)->metrics(mi, d); dim_ += d; it->width_ = d.wid; } diff --git a/src/mathed/math_decorationinset.C b/src/mathed/math_decorationinset.C index f685706e34..5f37628eb5 100644 --- a/src/mathed/math_decorationinset.C +++ b/src/mathed/math_decorationinset.C @@ -72,7 +72,7 @@ bool MathDecorationInset::wide() const } -Dimension MathDecorationInset::metrics(MetricsInfo & mi) const +void MathDecorationInset::metrics(MetricsInfo & mi, Dimension & dim) const { cell(0).metrics(mi); dim_ = cell(0).dim(); @@ -89,7 +89,7 @@ Dimension MathDecorationInset::metrics(MetricsInfo & mi) const } metricsMarkers(); - return dim_; + dim = dim_; } diff --git a/src/mathed/math_decorationinset.h b/src/mathed/math_decorationinset.h index d6783e7c56..e84488b1bc 100644 --- a/src/mathed/math_decorationinset.h +++ b/src/mathed/math_decorationinset.h @@ -25,7 +25,7 @@ public: /// void write(WriteStream & os) const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void normalize(NormalStream & os) const; /// diff --git a/src/mathed/math_deliminset.C b/src/mathed/math_deliminset.C index 53f10ff11b..6fd65e3da4 100644 --- a/src/mathed/math_deliminset.C +++ b/src/mathed/math_deliminset.C @@ -72,7 +72,7 @@ void MathDelimInset::normalize(NormalStream & os) const } -Dimension MathDelimInset::metrics(MetricsInfo & mi) const +void MathDelimInset::metrics(MetricsInfo & mi, Dimension & dim) const { cell(0).metrics(mi); Dimension t; @@ -88,7 +88,7 @@ Dimension MathDelimInset::metrics(MetricsInfo & mi) const dim_.wid = cell(0).width() + 2 * dw_ + 8; dim_.asc = max(a0, d0) + h0; dim_.des = max(a0, d0) - h0; - return dim_; + dim = dim_; } diff --git a/src/mathed/math_deliminset.h b/src/mathed/math_deliminset.h index 09731c8df8..bedd04f55b 100644 --- a/src/mathed/math_deliminset.h +++ b/src/mathed/math_deliminset.h @@ -31,7 +31,7 @@ public: /// is it |...|? bool isAbs() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo &, int x, int y) const; diff --git a/src/mathed/math_diffinset.C b/src/mathed/math_diffinset.C index d6f739aacd..5f0f202db4 100644 --- a/src/mathed/math_diffinset.C +++ b/src/mathed/math_diffinset.C @@ -32,10 +32,9 @@ void MathDiffInset::normalize(NormalStream & os) const } -Dimension MathDiffInset::metrics(MetricsInfo &) const +void MathDiffInset::metrics(MetricsInfo &, Dimension &) const { lyxerr << "should not happen\n"; - return Dimension(); } diff --git a/src/mathed/math_diffinset.h b/src/mathed/math_diffinset.h index ceb00f853f..17436c8da5 100644 --- a/src/mathed/math_diffinset.h +++ b/src/mathed/math_diffinset.h @@ -17,7 +17,7 @@ public: /// void addDer(MathArray const & der); /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; diff --git a/src/mathed/math_dotsinset.C b/src/mathed/math_dotsinset.C index a1ba4d2133..51bd28a74d 100644 --- a/src/mathed/math_dotsinset.C +++ b/src/mathed/math_dotsinset.C @@ -18,7 +18,7 @@ MathInset * MathDotsInset::clone() const } -Dimension MathDotsInset::metrics(MetricsInfo & mi) const +void MathDotsInset::metrics(MetricsInfo & mi, Dimension & dim) const { mathed_char_dim(mi.base.font, 'M', dim_); dh_ = 0; @@ -33,7 +33,7 @@ Dimension MathDotsInset::metrics(MetricsInfo & mi) const } else if (key_->name == "ddots") dh_ = dim_.asc; - return dim_; + dim = dim_; } diff --git a/src/mathed/math_dotsinset.h b/src/mathed/math_dotsinset.h index b1b28a3294..22d87e076a 100644 --- a/src/mathed/math_dotsinset.h +++ b/src/mathed/math_dotsinset.h @@ -15,7 +15,7 @@ public: /// MathInset * clone() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/mathed/math_envinset.C b/src/mathed/math_envinset.C index 04e7433dff..a7da4500ff 100644 --- a/src/mathed/math_envinset.C +++ b/src/mathed/math_envinset.C @@ -1,6 +1,5 @@ #include - #include "math_envinset.h" #include "math_mathmlstream.h" #include "math_streamstr.h" @@ -18,11 +17,11 @@ MathInset * MathEnvInset::clone() const } -Dimension MathEnvInset::metrics(MetricsInfo & mi) const +void MathEnvInset::metrics(MetricsInfo & mi, Dimension & dim) const { cell(0).metrics(mi, dim_); metricsMarkers(); - return dim_; + dim = dim_; } diff --git a/src/mathed/math_envinset.h b/src/mathed/math_envinset.h index 270d6a70a1..c13a17c099 100644 --- a/src/mathed/math_envinset.h +++ b/src/mathed/math_envinset.h @@ -25,7 +25,7 @@ public: /// write normalized content void normalize(NormalStream & ns) const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void infoize(std::ostream & os) const; diff --git a/src/mathed/math_ertinset.C b/src/mathed/math_ertinset.C index 10f5f595c5..64dfbeca74 100644 --- a/src/mathed/math_ertinset.C +++ b/src/mathed/math_ertinset.C @@ -12,13 +12,13 @@ MathInset * MathErtInset::clone() const } -Dimension MathErtInset::metrics(MetricsInfo & mi) const +void MathErtInset::metrics(MetricsInfo & mi, Dimension & dim) const { FontSetChanger dummy(mi.base, "lyxert"); - MathTextInset::metrics(mi); + MathTextInset::metrics(mi, dim_); cache_.colinfo_[0].align_ = 'l'; metricsMarkers(); - return dim_; + dim = dim_; } diff --git a/src/mathed/math_ertinset.h b/src/mathed/math_ertinset.h index 37c35fdcda..d72b58d907 100644 --- a/src/mathed/math_ertinset.h +++ b/src/mathed/math_ertinset.h @@ -15,7 +15,7 @@ public: /// mode_type currentMode() const { return TEXT_MODE; } /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/mathed/math_exfuncinset.C b/src/mathed/math_exfuncinset.C index 9c693b3b6b..7912da47a1 100644 --- a/src/mathed/math_exfuncinset.C +++ b/src/mathed/math_exfuncinset.C @@ -25,7 +25,7 @@ MathInset * MathExFuncInset::clone() const } -Dimension MathExFuncInset::metrics(MetricsInfo & mi) const +void MathExFuncInset::metrics(MetricsInfo & mi, Dimension & dim) const { mathed_string_dim(mi.base.font, name_, dim_); } diff --git a/src/mathed/math_exfuncinset.h b/src/mathed/math_exfuncinset.h index 5417754779..98b08b192e 100644 --- a/src/mathed/math_exfuncinset.h +++ b/src/mathed/math_exfuncinset.h @@ -17,7 +17,7 @@ public: /// MathInset * clone() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/mathed/math_exintinset.C b/src/mathed/math_exintinset.C index 096c996471..b4b1204365 100644 --- a/src/mathed/math_exintinset.C +++ b/src/mathed/math_exintinset.C @@ -48,10 +48,9 @@ void MathExIntInset::normalize(NormalStream & os) const } -Dimension MathExIntInset::metrics(MetricsInfo &) const +void MathExIntInset::metrics(MetricsInfo &, Dimension &) const { lyxerr << "should not happen\n"; - return Dimension(); } diff --git a/src/mathed/math_exintinset.h b/src/mathed/math_exintinset.h index 4623bd0247..05e209c36a 100644 --- a/src/mathed/math_exintinset.h +++ b/src/mathed/math_exintinset.h @@ -18,7 +18,7 @@ public: /// void symbol(string const &); /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo &, int x, int y) const; diff --git a/src/mathed/math_factory.C b/src/mathed/math_factory.C index f2fa0b4396..c9e8312a6d 100644 --- a/src/mathed/math_factory.C +++ b/src/mathed/math_factory.C @@ -41,6 +41,7 @@ #include "ref_inset.h" #include "metricsinfo.h" +#include "math_data.h" #include "debug.h" #include "math_support.h" #include "Lsstream.h" diff --git a/src/mathed/math_fboxinset.C b/src/mathed/math_fboxinset.C index afef0c6837..3383a3f97c 100644 --- a/src/mathed/math_fboxinset.C +++ b/src/mathed/math_fboxinset.C @@ -28,7 +28,7 @@ MathInset::mode_type MathFboxInset::currentMode() const } -Dimension MathFboxInset::metrics(MetricsInfo & mi) const +void MathFboxInset::metrics(MetricsInfo & mi, Dimension & dim) const { if (key_->name == "fbox") { FontSetChanger dummy(mi.base, "textnormal"); @@ -37,7 +37,7 @@ Dimension MathFboxInset::metrics(MetricsInfo & mi) const cell(0).metrics(mi, dim_); } metricsMarkers(5); // 5 pixels margin - return dim_; + dim = dim_; } diff --git a/src/mathed/math_fboxinset.h b/src/mathed/math_fboxinset.h index b9b54e1e54..c0e9fc85c7 100644 --- a/src/mathed/math_fboxinset.h +++ b/src/mathed/math_fboxinset.h @@ -23,7 +23,7 @@ public: /// mode_type currentMode() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/mathed/math_fontinset.C b/src/mathed/math_fontinset.C index a1c2e3824d..1873c831a6 100644 --- a/src/mathed/math_fontinset.C +++ b/src/mathed/math_fontinset.C @@ -32,12 +32,12 @@ MathInset::mode_type MathFontInset::currentMode() const } -Dimension MathFontInset::metrics(MetricsInfo & mi) const +void MathFontInset::metrics(MetricsInfo & mi, Dimension & dim) const { FontSetChanger dummy(mi.base, key_->name.c_str()); cell(0).metrics(mi, dim_); metricsMarkers(1); - return dim_; + dim = dim_; } diff --git a/src/mathed/math_fontinset.h b/src/mathed/math_fontinset.h index d0b8f33e72..69ae8bbc21 100644 --- a/src/mathed/math_fontinset.h +++ b/src/mathed/math_fontinset.h @@ -28,7 +28,7 @@ public: /// string name() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/mathed/math_fontoldinset.C b/src/mathed/math_fontoldinset.C index 86661d0159..c6b3c2b299 100644 --- a/src/mathed/math_fontoldinset.C +++ b/src/mathed/math_fontoldinset.C @@ -25,12 +25,12 @@ MathInset * MathFontOldInset::clone() const } -Dimension MathFontOldInset::metrics(MetricsInfo & mi) const +void MathFontOldInset::metrics(MetricsInfo & mi, Dimension & dim) const { FontSetChanger dummy(mi.base, key_->name.c_str()); cell(0).metrics(mi, dim_); metricsMarkers(1); - return dim_; + dim = dim_; } diff --git a/src/mathed/math_fontoldinset.h b/src/mathed/math_fontoldinset.h index 62621ac08c..dc168e50a9 100644 --- a/src/mathed/math_fontoldinset.h +++ b/src/mathed/math_fontoldinset.h @@ -24,7 +24,7 @@ public: /// we write extra braces in any case... bool extraBraces() const { return true; } /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/mathed/math_fracinset.C b/src/mathed/math_fracinset.C index 776265656c..be4b75d496 100644 --- a/src/mathed/math_fracinset.C +++ b/src/mathed/math_fracinset.C @@ -32,7 +32,7 @@ MathFracInset const * MathFracInset::asFracInset() const } -Dimension MathFracInset::metrics(MetricsInfo & mi) const +void MathFracInset::metrics(MetricsInfo & mi, Dimension & dim) const { FracChanger dummy(mi.base); cell(0).metrics(mi); @@ -40,7 +40,7 @@ Dimension MathFracInset::metrics(MetricsInfo & mi) const dim_.wid = max(cell(0).width(), cell(1).width()) + 2; dim_.asc = cell(0).height() + 2 + 5; dim_.des = cell(1).height() + 2 - 5; - return dim_; + dim = dim_; } @@ -62,7 +62,7 @@ void MathFracInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const dim.wid = max(cell(0).width(), cell(1).width()); dim.asc = cell(0).height() + 1; dim.des = cell(1).height(); - //return dim_; + //dim = dim_; } diff --git a/src/mathed/math_fracinset.h b/src/mathed/math_fracinset.h index 14ca4d4c40..61d4dcbeb2 100644 --- a/src/mathed/math_fracinset.h +++ b/src/mathed/math_fracinset.h @@ -17,7 +17,7 @@ public: /// MathInset * clone() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo &, int x, int y) const; /// diff --git a/src/mathed/math_frameboxinset.C b/src/mathed/math_frameboxinset.C index 4e51af0c41..26b42aff95 100644 --- a/src/mathed/math_frameboxinset.C +++ b/src/mathed/math_frameboxinset.C @@ -18,7 +18,7 @@ MathInset * MathFrameboxInset::clone() const } -Dimension MathFrameboxInset::metrics(MetricsInfo & mi) const +void MathFrameboxInset::metrics(MetricsInfo & mi, Dimension & dim) const { FontSetChanger dummy(mi.base, "textnormal"); w_ = mathed_char_width(mi.base.font, '['); @@ -27,7 +27,7 @@ Dimension MathFrameboxInset::metrics(MetricsInfo & mi) const dim_ += cell(1).dim(); dim_ += cell(2).dim(); metricsMarkers(); - return dim_; + dim = dim_; } diff --git a/src/mathed/math_frameboxinset.h b/src/mathed/math_frameboxinset.h index 7dd13ba711..11b3b8ea8a 100644 --- a/src/mathed/math_frameboxinset.h +++ b/src/mathed/math_frameboxinset.h @@ -18,7 +18,7 @@ public: /// MathInset * clone() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index d42d4927aa..4201aef6e5 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -298,7 +298,7 @@ LyXLength MathGridInset::vcrskip(row_type row) const } -Dimension MathGridInset::metrics(MetricsInfo & mi) const +void MathGridInset::metrics(MetricsInfo & mi) const { // let the cells adjust themselves MathNestInset::metrics(mi); @@ -434,7 +434,13 @@ Dimension MathGridInset::metrics(MetricsInfo & mi) const cxrow->setBaseline(cxrow->getBaseline() - ascent); } */ - return dim_; +} + + +void MathGridInset::metrics(MetricsInfo & mi, Dimension & dim) const +{ + metrics(mi); + dim = dim_; } @@ -1020,17 +1026,14 @@ dispatch_result MathGridInset::dispatch case LFUN_MOUSE_RELEASE: //if (cmd.button() == mouse_button::button3) { - // GridInsetMailer mailer(*this); - // mailer.showDialog(); + // GridInsetMailer(*this).showDialog(); // return DISPATCHED; //} - break; + return UNDISPATCHED; - case LFUN_INSET_DIALOG_UPDATE: { - GridInsetMailer mailer(*this); - mailer.updateDialog(cmd.view()); - break; - } + case LFUN_INSET_DIALOG_UPDATE: + GridInsetMailer(*this).updateDialog(cmd.view()); + return UNDISPATCHED; // insert file functions case LFUN_DELETE_LINE_FORWARD: @@ -1164,5 +1167,4 @@ dispatch_result MathGridInset::dispatch default: return MathNestInset::dispatch(cmd, idx, pos); } - return UNDISPATCHED; } diff --git a/src/mathed/math_gridinset.h b/src/mathed/math_gridinset.h index 5d5af40d86..6177c9be82 100644 --- a/src/mathed/math_gridinset.h +++ b/src/mathed/math_gridinset.h @@ -92,7 +92,9 @@ public: /// MathInset * clone() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi) const; + /// + void metrics(MetricsInfo & mi, Dimension &) const; /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index 78f3549e58..a0309b100f 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -165,7 +165,7 @@ char const * MathHullInset::standardFont() const } -Dimension MathHullInset::metrics(MetricsInfo & mi) const +void MathHullInset::metrics(MetricsInfo & mi, Dimension & dim) const { FontSetChanger dummy1(mi.base, standardFont()); StyleChanger dummy2(mi.base, display() ? LM_ST_DISPLAY : LM_ST_TEXT); @@ -197,7 +197,7 @@ Dimension MathHullInset::metrics(MetricsInfo & mi) const // for markers metricsMarkers2(); - return dim_; + dim = dim_; } @@ -697,7 +697,7 @@ void MathHullInset::doExtern size_type pos = cell(idx).find_last(eq); MathArray ar; if (mathcursor && mathcursor->selection()) { - ar = asArray(mathcursor->grabAndEraseSelection()); + asArray(mathcursor->grabAndEraseSelection(), ar); } else if (pos == cell(idx).size()) { ar = cell(idx); lyxerr << "use whole cell: " << ar << "\n"; diff --git a/src/mathed/math_hullinset.h b/src/mathed/math_hullinset.h index 0ef8679a6c..c0a1c6ca54 100644 --- a/src/mathed/math_hullinset.h +++ b/src/mathed/math_hullinset.h @@ -24,7 +24,7 @@ public: /// mode_type currentMode() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo &, int x, int y) const; /// diff --git a/src/mathed/math_inferinset.C b/src/mathed/math_inferinset.C index 0cc5246a69..7a6da9a3c9 100644 --- a/src/mathed/math_inferinset.C +++ b/src/mathed/math_inferinset.C @@ -17,9 +17,8 @@ MathInset * MathInferInset::clone() const } -Dimension MathInferInset::metrics(MetricsInfo &) const +void MathInferInset::metrics(MetricsInfo &, Dimension &) const { - return Dimension(); } diff --git a/src/mathed/math_inferinset.h b/src/mathed/math_inferinset.h index 4385b7a232..582a85a17d 100644 --- a/src/mathed/math_inferinset.h +++ b/src/mathed/math_inferinset.h @@ -17,7 +17,7 @@ public: /// MathInset * clone() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index d5d6af8653..675126d418 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -18,11 +18,9 @@ #include #include "math_inset.h" -#include "Lsstream.h" #include "math_scriptinset.h" #include "math_mathmlstream.h" #include "math_cursor.h" -#include "math_parser.h" #include "debug.h" #include "frontends/LyXView.h" @@ -35,9 +33,7 @@ using std::ostream; BufferView * MathInset::view() const { - if (!mathcursor) - return 0; - return mathcursor->formula()->view(); + return mathcursor ? mathcursor->formula()->view() : 0; } @@ -158,12 +154,6 @@ bool MathInset::idxBetween(idx_type idx, idx_type from, idx_type to) const } -void MathInset::draw(PainterInfo &, int, int) const -{ - lyxerr << "MathInset::draw() called directly!\n"; -} - - void MathInset::drawSelection(PainterInfo &, idx_type, pos_type, idx_type, pos_type) const { @@ -267,23 +257,6 @@ string MathInset::name() const } -string asString(MathArray const & ar) -{ - std::ostringstream os; - WriteStream ws(os); - ws << ar; - return STRCONV(os.str()); -} - - -MathArray asArray(string const & str) -{ - MathArray ar; - mathed_parse_cell(ar, str); - return ar; -} - - ostream & operator<<(ostream & os, MathAtom const & at) { WriteStream wi(os, false, false); diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index d3cb73333a..02b9420b0e 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -16,9 +16,6 @@ * the GNU General Public Licence version 2 or later. */ -// Note: These math insets are internal to Math and are not derived -// from lyx inset. - #ifndef MATH_INSET_H #define MATH_INSET_H @@ -26,7 +23,6 @@ #include "LString.h" #include "insets/insetbase.h" -#include "math_data.h" /** @@ -36,8 +32,8 @@ the math objects. Math insets do not know there parents, a cursor position or things like that. The are dumb object that are contained in other math insets -(mathNestInsets, in fact) thus forming a tree. The root of this tree is -always a mathHullInset, which provides an interface to the Outer World by +(MathNestInsets, in fact) thus forming a tree. The root of this tree is +always a MathHullInset, which provides an interface to the Outer World by inclusion in the "real LyX insets" FormulaInset and FormulaMacroInset. */ @@ -47,9 +43,9 @@ class MathArrayInset; class MathAMSArrayInset; class MathCharInset; class MathDelimInset; -class MathGridInset; class MathFracInset; class MathFontInset; +class MathGridInset; class MathHullInset; class MathMatrixInset; class MathNestInset; @@ -62,6 +58,9 @@ class MathUnknownInset; class RefInset; +class MathArray; +class MathAtom; + class NormalStream; class OctaveStream; class MapleStream; @@ -70,32 +69,22 @@ class MathematicaStream; class MathMLStream; class WriteStream; class InfoStream; -class MathArray; class LaTeXFeatures; class BufferView; class UpdatableInset; class MathMacroTemplate; +class MathMacro; class MathPosFinder; class Dimension; class FuncRequest; +class TextPainter; +class TextMetricsInfo; +class ReplaceData; class MathInset : public InsetBase { public: - /// short of anything else reasonable - typedef MathArray::size_type size_type; - /// type for cursor positions differences within a cell - typedef MathArray::difference_type difference_type; - /// type for cursor positions within a cell - typedef MathArray::size_type pos_type; - /// type for cell indices - typedef size_type idx_type; - /// type for row numbers - typedef size_type row_type; - /// type for column numbers - typedef size_type col_type; - /// our members behave nicely... MathInset() {} @@ -103,11 +92,6 @@ public: virtual MathInset * clone() const = 0; /// substitutes macro arguments if necessary virtual void substitute(MathMacro const & macro); - /// compute the size of the object returned in dim - virtual Dimension metrics(MetricsInfo & mi) const = 0; - /// draw the object - // updates the (xo,yo)-caches of all contained cells - virtual void draw(PainterInfo & pi, int x, int y) const; /// draw selection between two positions virtual void drawSelection(PainterInfo & pi, idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const; @@ -295,11 +279,6 @@ protected: std::ostream & operator<<(std::ostream &, MathAtom const &); -// converts single cell to string -string asString(MathArray const & ar); -// converts string to single cell -MathArray asArray(string const & str); - // initialize math void initMath(); diff --git a/src/mathed/math_kerninset.C b/src/mathed/math_kerninset.C index cf7cb75611..735df272c3 100644 --- a/src/mathed/math_kerninset.C +++ b/src/mathed/math_kerninset.C @@ -28,13 +28,11 @@ MathInset * MathKernInset::clone() const } -Dimension MathKernInset::metrics(MetricsInfo & mi) const +void MathKernInset::metrics(MetricsInfo & mi, Dimension & dim) const { - Dimension dim; dim.wid = wid_.inPixels(0, mathed_char_width(mi.base.font, 'M')); dim.asc = 0; dim.des = 0; - return dim; } diff --git a/src/mathed/math_kerninset.h b/src/mathed/math_kerninset.h index 53a03b9656..956a5415e4 100644 --- a/src/mathed/math_kerninset.h +++ b/src/mathed/math_kerninset.h @@ -22,7 +22,7 @@ public: /// MathInset * clone() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/mathed/math_lefteqninset.C b/src/mathed/math_lefteqninset.C index d560e1237a..af20371875 100644 --- a/src/mathed/math_lefteqninset.C +++ b/src/mathed/math_lefteqninset.C @@ -15,14 +15,14 @@ MathInset * MathLefteqnInset::clone() const } -Dimension MathLefteqnInset::metrics(MetricsInfo & mi) const +void MathLefteqnInset::metrics(MetricsInfo & mi, Dimension & dim) const { cell(0).metrics(mi); dim_.asc = cell(0).ascent() + 2; dim_.des = cell(0).descent() + 2; dim_.wid = 4; metricsMarkers(); - return dim_; + dim = dim_; } diff --git a/src/mathed/math_lefteqninset.h b/src/mathed/math_lefteqninset.h index 7a7f74df90..fea4ee5381 100644 --- a/src/mathed/math_lefteqninset.h +++ b/src/mathed/math_lefteqninset.h @@ -16,7 +16,7 @@ public: /// string name() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/mathed/math_liminset.C b/src/mathed/math_liminset.C index 3dd05b6997..0b854fa9a8 100644 --- a/src/mathed/math_liminset.C +++ b/src/mathed/math_liminset.C @@ -28,10 +28,9 @@ void MathLimInset::normalize(NormalStream & os) const } -Dimension MathLimInset::metrics(MetricsInfo &) const +void MathLimInset::metrics(MetricsInfo &, Dimension &) const { lyxerr << "should not happen\n"; - return Dimension(); } diff --git a/src/mathed/math_liminset.h b/src/mathed/math_liminset.h index 71a97e6ac1..18817748f0 100644 --- a/src/mathed/math_liminset.h +++ b/src/mathed/math_liminset.h @@ -15,7 +15,7 @@ public: /// MathInset * clone() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; diff --git a/src/mathed/math_macro.C b/src/mathed/math_macro.C index 0291e37c15..8d07cf8e79 100644 --- a/src/mathed/math_macro.C +++ b/src/mathed/math_macro.C @@ -69,7 +69,7 @@ void MathMacro::expand() const } -Dimension MathMacro::metrics(MetricsInfo & mi) const +void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const { augmentFont(font_, "lyxtex"); mi_ = mi; @@ -104,13 +104,13 @@ Dimension MathMacro::metrics(MetricsInfo & mi) const } - return dim_; + dim = dim_; } void MathMacro::draw(PainterInfo & pi, int x, int y) const { - metrics(mi_); + metrics(mi_, dim_); LyXFont texfont; augmentFont(texfont, "lyxtex"); diff --git a/src/mathed/math_macro.h b/src/mathed/math_macro.h index d233b6a773..ec22720880 100644 --- a/src/mathed/math_macro.h +++ b/src/mathed/math_macro.h @@ -41,7 +41,7 @@ public: /// void draw(PainterInfo & pi, int x, int y) const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// MathInset * clone() const; /// diff --git a/src/mathed/math_macroarg.C b/src/mathed/math_macroarg.C index ce318085a2..0e3ea48aad 100644 --- a/src/mathed/math_macroarg.C +++ b/src/mathed/math_macroarg.C @@ -33,13 +33,13 @@ void MathMacroArgument::write(WriteStream & os) const } -Dimension MathMacroArgument::metrics(MetricsInfo & mi) const +void MathMacroArgument::metrics(MetricsInfo & mi, Dimension & dim) const { if (expanded_) cell(0).metrics(mi, dim_); else mathed_string_dim(mi.base.font, str_, dim_); - return dim_; + dim = dim_; } diff --git a/src/mathed/math_macroarg.h b/src/mathed/math_macroarg.h index 22a42f7542..c8f4469592 100644 --- a/src/mathed/math_macroarg.h +++ b/src/mathed/math_macroarg.h @@ -19,7 +19,7 @@ public: /// bool isActive() const { return false; } /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo &, int x, int y) const; /// diff --git a/src/mathed/math_macrotemplate.C b/src/mathed/math_macrotemplate.C index ce4481526b..f5ff5995ad 100644 --- a/src/mathed/math_macrotemplate.C +++ b/src/mathed/math_macrotemplate.C @@ -62,14 +62,14 @@ string MathMacroTemplate::name() const } -Dimension MathMacroTemplate::metrics(MetricsInfo & mi) const +void MathMacroTemplate::metrics(MetricsInfo & mi, Dimension & dim) const { cell(0).metrics(mi); cell(1).metrics(mi); dim_.wid = cell(0).width() + cell(1).width() + 10; dim_.asc = std::max(cell(0).ascent(), cell(1).ascent()) + 2; dim_.des = std::max(cell(0).descent(), cell(1).descent()) + 2; - return dim_; + dim = dim_; } diff --git a/src/mathed/math_macrotemplate.h b/src/mathed/math_macrotemplate.h index d0b10c075e..4e0677a478 100644 --- a/src/mathed/math_macrotemplate.h +++ b/src/mathed/math_macrotemplate.h @@ -37,7 +37,7 @@ public: /// void draw(PainterInfo &, int x, int y) const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// identifies macro templates MathMacroTemplate * asMacroTemplate() { return this; } /// identifies macro templates diff --git a/src/mathed/math_makeboxinset.C b/src/mathed/math_makeboxinset.C index f2d5ea80cb..9e57932be7 100644 --- a/src/mathed/math_makeboxinset.C +++ b/src/mathed/math_makeboxinset.C @@ -23,7 +23,7 @@ MathInset * MathMakeboxInset::clone() const } -Dimension MathMakeboxInset::metrics(MetricsInfo & mi) const +void MathMakeboxInset::metrics(MetricsInfo & mi, Dimension & dim) const { FontSetChanger dummy(mi.base, "textnormal"); w_ = mathed_char_width(mi.base.font, '['); @@ -33,7 +33,7 @@ Dimension MathMakeboxInset::metrics(MetricsInfo & mi) const dim_ += cell(2).dim(); dim_.wid += 4 * w_ + 4; metricsMarkers(); - return dim_; + dim = dim_; } diff --git a/src/mathed/math_makeboxinset.h b/src/mathed/math_makeboxinset.h index 95e8db12d0..805bdd4960 100644 --- a/src/mathed/math_makeboxinset.h +++ b/src/mathed/math_makeboxinset.h @@ -23,7 +23,7 @@ public: /// MathInset * clone() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/mathed/math_mathmlstream.C b/src/mathed/math_mathmlstream.C index 8a226ac17f..a395288680 100644 --- a/src/mathed/math_mathmlstream.C +++ b/src/mathed/math_mathmlstream.C @@ -3,6 +3,7 @@ #include "math_mathmlstream.h" #include "math_inset.h" +#include "math_data.h" #include "math_extern.h" #include "debug.h" #include "support/lyxalgo.h" diff --git a/src/mathed/math_nestinset.h b/src/mathed/math_nestinset.h index 401e3091e8..2d87fbdc1e 100644 --- a/src/mathed/math_nestinset.h +++ b/src/mathed/math_nestinset.h @@ -2,6 +2,7 @@ #define MATH_NESTINSET_H #include "math_diminset.h" +#include "math_data.h" /** Abstract base class for all math objects that contain nested items. This is basically everything that is not a single character or a diff --git a/src/mathed/math_numberinset.C b/src/mathed/math_numberinset.C index d53409630d..669a84bf4e 100644 --- a/src/mathed/math_numberinset.C +++ b/src/mathed/math_numberinset.C @@ -19,11 +19,9 @@ MathInset * MathNumberInset::clone() const } -Dimension MathNumberInset::metrics(MetricsInfo & mi) const +void MathNumberInset::metrics(MetricsInfo & mi, Dimension & dim) const { - Dimension dim; mathed_string_dim(mi.base.font, str_, dim); - return dim; } diff --git a/src/mathed/math_numberinset.h b/src/mathed/math_numberinset.h index 30ca051734..68a4cd5b4b 100644 --- a/src/mathed/math_numberinset.h +++ b/src/mathed/math_numberinset.h @@ -19,7 +19,7 @@ public: /// MathInset * clone() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo &, int x, int y) const; /// diff --git a/src/mathed/math_parboxinset.C b/src/mathed/math_parboxinset.C index d40efc594f..5f41f1fa8b 100644 --- a/src/mathed/math_parboxinset.C +++ b/src/mathed/math_parboxinset.C @@ -33,13 +33,13 @@ void MathParboxInset::setWidth(string const & w) } -Dimension MathParboxInset::metrics(MetricsInfo & mi) const +void MathParboxInset::metrics(MetricsInfo & mi, Dimension & dim) const { FontSetChanger dummy1(mi.base, "textnormal"); WidthChanger dummy2(mi.base, lyx_width_); - MathTextInset::metrics(mi); + MathTextInset::metrics(mi, dim_); metricsMarkers(); - return dim_; + dim = dim_; } diff --git a/src/mathed/math_parboxinset.h b/src/mathed/math_parboxinset.h index 9aae3c1450..dc8e0d4d8a 100644 --- a/src/mathed/math_parboxinset.h +++ b/src/mathed/math_parboxinset.h @@ -17,7 +17,7 @@ public: /// mode_type currentMode() const { return TEXT_MODE; } /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo &, int x, int y) const; /// diff --git a/src/mathed/math_parinset.C b/src/mathed/math_parinset.C index 9d50bfdca7..4910404687 100644 --- a/src/mathed/math_parinset.C +++ b/src/mathed/math_parinset.C @@ -12,11 +12,11 @@ MathParInset::MathParInset(MathArray const & ar) } -Dimension MathParInset::metrics(MetricsInfo & mi) const +void MathParInset::metrics(MetricsInfo & mi, Dimension & dim) const { FontSetChanger dummy1(mi.base, "textnormal"); MathGridInset::metrics(mi); - return dim_; + dim = dim_; } diff --git a/src/mathed/math_parinset.h b/src/mathed/math_parinset.h index 1465d0739d..f27230e949 100644 --- a/src/mathed/math_parinset.h +++ b/src/mathed/math_parinset.h @@ -13,7 +13,7 @@ public: /// mode_type currentMode() const { return TEXT_MODE; } /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo &, int x, int y) const; /// diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 54bc695110..06713ed70f 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -1109,11 +1109,13 @@ void Parser::parse1(MathGridInset & grid, unsigned flags, else if (t.cs() == "label") { string label = parse_verbatim_item(); + MathArray ar; + asArray(label, ar); if (grid.asHullInset()) { grid.asHullInset()->label(cellrow, label); } else { cell->push_back(createMathInset(t.cs())); - cell->push_back(MathAtom(new MathBraceInset(asArray(label)))); + cell->push_back(MathAtom(new MathBraceInset(ar))); } } diff --git a/src/mathed/math_rootinset.C b/src/mathed/math_rootinset.C index 48fc1375f8..18aafd84f0 100644 --- a/src/mathed/math_rootinset.C +++ b/src/mathed/math_rootinset.C @@ -31,14 +31,14 @@ MathInset * MathRootInset::clone() const } -Dimension MathRootInset::metrics(MetricsInfo & mi) const +void MathRootInset::metrics(MetricsInfo & mi, Dimension & dim) const { MathNestInset::metrics(mi); dim_.asc = max(cell(0).ascent() + 5, cell(1).ascent()) + 2; dim_.des = max(cell(1).descent() + 5, cell(0).descent()) + 2; dim_.wid = cell(0).width() + cell(1).width() + 10; metricsMarkers(1); - return dim_; + dim = dim_; } diff --git a/src/mathed/math_rootinset.h b/src/mathed/math_rootinset.h index e1293e287b..d72db051c3 100644 --- a/src/mathed/math_rootinset.h +++ b/src/mathed/math_rootinset.h @@ -33,7 +33,7 @@ public: /// bool idxUpDown(idx_type & idx, pos_type & pos, bool up, int targetx) const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; diff --git a/src/mathed/math_scriptinset.C b/src/mathed/math_scriptinset.C index c59bf351e4..67de499710 100644 --- a/src/mathed/math_scriptinset.C +++ b/src/mathed/math_scriptinset.C @@ -180,7 +180,7 @@ int MathScriptInset::ndes() const } -Dimension MathScriptInset::metrics(MetricsInfo & mi) const +void MathScriptInset::metrics(MetricsInfo & mi, Dimension & dim) const { cell(2).metrics(mi); ScriptChanger dummy(mi.base); @@ -203,7 +203,7 @@ Dimension MathScriptInset::metrics(MetricsInfo & mi) const dim_.asc = dy1() + (hasUp() ? up().ascent() : 0); dim_.des = dy0() + (hasDown() ? down().descent() : 0); metricsMarkers(); - return dim_; + dim = dim_; } diff --git a/src/mathed/math_scriptinset.h b/src/mathed/math_scriptinset.h index 50a409b799..5a411e71e1 100644 --- a/src/mathed/math_scriptinset.h +++ b/src/mathed/math_scriptinset.h @@ -22,7 +22,7 @@ public: /// MathInset * clone() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/mathed/math_sizeinset.C b/src/mathed/math_sizeinset.C index 409993b270..4d77161c46 100644 --- a/src/mathed/math_sizeinset.C +++ b/src/mathed/math_sizeinset.C @@ -21,12 +21,12 @@ MathInset * MathSizeInset::clone() const } -Dimension MathSizeInset::metrics(MetricsInfo & mi) const +void MathSizeInset::metrics(MetricsInfo & mi, Dimension & dim) const { StyleChanger dummy(mi.base, style_); cell(0).metrics(mi, dim_); metricsMarkers(); - return dim_; + dim = dim_; } diff --git a/src/mathed/math_sizeinset.h b/src/mathed/math_sizeinset.h index 1b14135d01..05bc74d236 100644 --- a/src/mathed/math_sizeinset.h +++ b/src/mathed/math_sizeinset.h @@ -23,7 +23,7 @@ public: /// we write extra braces in any case... bool extraBraces() const { return true; } /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo &, int x, int y) const; diff --git a/src/mathed/math_spaceinset.C b/src/mathed/math_spaceinset.C index c346e45a25..0d2ee4e7cc 100644 --- a/src/mathed/math_spaceinset.C +++ b/src/mathed/math_spaceinset.C @@ -1,5 +1,6 @@ #include "math_spaceinset.h" +#include "math_data.h" #include "math_support.h" #include "LColor.h" #include "frontends/Painter.h" @@ -31,16 +32,14 @@ MathSpaceInset::MathSpaceInset(string const & name) } - MathInset * MathSpaceInset::clone() const { return new MathSpaceInset(*this); } -Dimension MathSpaceInset::metrics(MetricsInfo &) const +void MathSpaceInset::metrics(MetricsInfo &, Dimension & dim) const { - Dimension dim; switch (space_) { case 0: dim.wid = 6; break; case 1: dim.wid = 8; break; @@ -56,7 +55,6 @@ Dimension MathSpaceInset::metrics(MetricsInfo &) const } dim.asc = 4; dim.des = 0; - return dim; } diff --git a/src/mathed/math_spaceinset.h b/src/mathed/math_spaceinset.h index e3e14900fb..75c8fbe8bd 100644 --- a/src/mathed/math_spaceinset.h +++ b/src/mathed/math_spaceinset.h @@ -21,7 +21,7 @@ public: /// void incSpace(); /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; diff --git a/src/mathed/math_sqrtinset.C b/src/mathed/math_sqrtinset.C index 2969c6b21d..b1bcb84d8f 100644 --- a/src/mathed/math_sqrtinset.C +++ b/src/mathed/math_sqrtinset.C @@ -17,14 +17,14 @@ MathInset * MathSqrtInset::clone() const } -Dimension MathSqrtInset::metrics(MetricsInfo & mi) const +void MathSqrtInset::metrics(MetricsInfo & mi, Dimension & dim) const { cell(0).metrics(mi, dim_); dim_.asc += 4; dim_.des += 2; dim_.wid += 12; metricsMarkers(1); - return dim_; + dim = dim_; } diff --git a/src/mathed/math_sqrtinset.h b/src/mathed/math_sqrtinset.h index 68c490925b..40aa6e8b35 100644 --- a/src/mathed/math_sqrtinset.h +++ b/src/mathed/math_sqrtinset.h @@ -19,7 +19,7 @@ public: /// void draw(PainterInfo &, int x, int y) const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void drawT(TextPainter &, int x, int y) const; /// diff --git a/src/mathed/math_stackrelinset.C b/src/mathed/math_stackrelinset.C index 621f07fd0e..4e03e7258b 100644 --- a/src/mathed/math_stackrelinset.C +++ b/src/mathed/math_stackrelinset.C @@ -17,7 +17,7 @@ MathInset * MathStackrelInset::clone() const } -Dimension MathStackrelInset::metrics(MetricsInfo & mi) const +void MathStackrelInset::metrics(MetricsInfo & mi, Dimension & dim) const { cell(1).metrics(mi); FracChanger dummy(mi.base); @@ -26,7 +26,7 @@ Dimension MathStackrelInset::metrics(MetricsInfo & mi) const dim_.asc = cell(1).ascent() + cell(0).height() + 4; dim_.des = cell(1).descent(); metricsMarkers(); - return dim_; + dim = dim_; } diff --git a/src/mathed/math_stackrelinset.h b/src/mathed/math_stackrelinset.h index 0050a224ab..2474c4929c 100644 --- a/src/mathed/math_stackrelinset.h +++ b/src/mathed/math_stackrelinset.h @@ -17,7 +17,7 @@ public: /// MathInset * clone() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; diff --git a/src/mathed/math_stringinset.C b/src/mathed/math_stringinset.C index 0dc71e7bb6..915c7d3b1a 100644 --- a/src/mathed/math_stringinset.C +++ b/src/mathed/math_stringinset.C @@ -19,11 +19,9 @@ MathInset * MathStringInset::clone() const } -Dimension MathStringInset::metrics(MetricsInfo & mi) const +void MathStringInset::metrics(MetricsInfo & mi, Dimension & dim) const { - Dimension dim; mathed_string_dim(mi.base.font, str_, dim); - return dim; } diff --git a/src/mathed/math_stringinset.h b/src/mathed/math_stringinset.h index 1345a5acde..a449a99fde 100644 --- a/src/mathed/math_stringinset.h +++ b/src/mathed/math_stringinset.h @@ -19,7 +19,7 @@ public: /// MathInset * clone() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/mathed/math_substackinset.C b/src/mathed/math_substackinset.C index bd4cf9eaf2..5da53cb4bf 100644 --- a/src/mathed/math_substackinset.C +++ b/src/mathed/math_substackinset.C @@ -17,7 +17,7 @@ MathInset * MathSubstackInset::clone() const } -Dimension MathSubstackInset::metrics(MetricsInfo & mi) const +void MathSubstackInset::metrics(MetricsInfo & mi, Dimension & dim) const { if (mi.base.style == LM_ST_DISPLAY) { StyleChanger dummy(mi.base, LM_ST_TEXT); @@ -26,7 +26,7 @@ Dimension MathSubstackInset::metrics(MetricsInfo & mi) const MathGridInset::metrics(mi); } metricsMarkers(); - return dim_; + dim = dim_; } diff --git a/src/mathed/math_substackinset.h b/src/mathed/math_substackinset.h index 1e152c1567..4d7b8fabf6 100644 --- a/src/mathed/math_substackinset.h +++ b/src/mathed/math_substackinset.h @@ -14,7 +14,7 @@ public: /// MathInset * clone() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/mathed/math_support.C b/src/mathed/math_support.C index 804e38b554..b4798318ee 100644 --- a/src/mathed/math_support.C +++ b/src/mathed/math_support.C @@ -6,12 +6,15 @@ #include "math_inset.h" #include "math_parser.h" #include "metricsinfo.h" +#include "math_data.h" #include "frontends/Painter.h" #include "frontends/font_metrics.h" #include "frontends/lyx_gui.h" #include "debug.h" #include "lfuns.h" #include "dimension.h" +#include "Lsstream.h" +#include "math_mathmlstream.h" #include @@ -676,3 +679,20 @@ void augmentFont(LyXFont & font, string const & name) if (info->color_ != LColor::none) font.setColor(info->color_); } + + +string asString(MathArray const & ar) +{ + std::ostringstream os; + WriteStream ws(os); + ws << ar; + return STRCONV(os.str()); +} + + +void asArray(string const & str, MathArray & ar) +{ + mathed_parse_cell(ar, str); +} + + diff --git a/src/mathed/math_support.h b/src/mathed/math_support.h index b6a275dcb9..9ecf7d8d05 100644 --- a/src/mathed/math_support.h +++ b/src/mathed/math_support.h @@ -3,12 +3,12 @@ #ifndef MATH_SUPPORT_H #define MATH_SUPPORT_H - #include "LString.h" class PainterInfo; class LyXFont; class Dimension; +class MathArray; void mathed_char_dim(LyXFont const &, unsigned char c, Dimension & dim); int mathed_char_width(LyXFont const &, unsigned char c); @@ -33,4 +33,9 @@ void augmentFont(LyXFont & f, string const & cmd); bool isFontName(string const & name); +// converts single cell to string +string asString(MathArray const & ar); +// converts string to single cell +void asArray(string const & str, MathArray & ar); + #endif diff --git a/src/mathed/math_symbolinset.C b/src/mathed/math_symbolinset.C index 99b823ad49..de090d83ab 100644 --- a/src/mathed/math_symbolinset.C +++ b/src/mathed/math_symbolinset.C @@ -2,10 +2,12 @@ #include #include "math_symbolinset.h" +#include "dimension.h" #include "math_mathmlstream.h" #include "math_streamstr.h" #include "math_support.h" #include "math_parser.h" +#include "math_atom.h" #include "LaTeXFeatures.h" #include "debug.h" @@ -38,14 +40,13 @@ string MathSymbolInset::name() const } -Dimension MathSymbolInset::metrics(MetricsInfo & mi) const +void MathSymbolInset::metrics(MetricsInfo & mi, Dimension & dim) const { //lyxerr << "metrics: symbol: '" << sym_->name // << "' in font: '" << sym_->inset // << "' drawn as: '" << sym_->draw // << "'\n"; - Dimension dim; int const em = mathed_char_width(mi.base.font, 'M'); FontSetChanger dummy(mi.base, sym_->inset.c_str()); mathed_string_dim(mi.base.font, sym_->draw, dim); @@ -65,8 +66,6 @@ Dimension MathSymbolInset::metrics(MetricsInfo & mi) const if (mi.base.style == LM_ST_DISPLAY) if (sym_->inset == "cmex" || sym_->extra == "funclim") scriptable_ = true; - - return dim; } diff --git a/src/mathed/math_symbolinset.h b/src/mathed/math_symbolinset.h index 4fbe359f86..f33def2b1c 100644 --- a/src/mathed/math_symbolinset.h +++ b/src/mathed/math_symbolinset.h @@ -21,7 +21,7 @@ public: /// MathInset * clone() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo &, int x, int y) const; /// diff --git a/src/mathed/math_tabularinset.C b/src/mathed/math_tabularinset.C index 95be73efcb..7f506bc040 100644 --- a/src/mathed/math_tabularinset.C +++ b/src/mathed/math_tabularinset.C @@ -39,7 +39,7 @@ MathInset * MathTabularInset::clone() const } -Dimension MathTabularInset::metrics(MetricsInfo & mi) const +void MathTabularInset::metrics(MetricsInfo & mi, Dimension & dim) const { FontSetChanger dummy(mi.base, "textnormal"); return MathGridInset::metrics(mi); diff --git a/src/mathed/math_tabularinset.h b/src/mathed/math_tabularinset.h index 35426e2dc7..62fa37fbaf 100644 --- a/src/mathed/math_tabularinset.h +++ b/src/mathed/math_tabularinset.h @@ -25,7 +25,7 @@ public: /// MathInset * clone() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/mathed/math_textinset.C b/src/mathed/math_textinset.C index 965cdb087a..bc7c9a74f5 100644 --- a/src/mathed/math_textinset.C +++ b/src/mathed/math_textinset.C @@ -57,7 +57,7 @@ bool MathTextInset::idxUpDown2(idx_type &, pos_type & pos, bool up, } -Dimension MathTextInset::metrics(MetricsInfo & mi) const +void MathTextInset::metrics(MetricsInfo & mi, Dimension & dim) const { cell(0).metrics(mi); @@ -151,14 +151,14 @@ Dimension MathTextInset::metrics(MetricsInfo & mi) const //lyxerr << "last line: " << ar.data() << "\n"; // what to report? - dim_ = cache_.metrics(mi); + cache_.metrics(mi, dim_); //lyxerr << "outer dim: " << dim_ << endl; // reset position cache for (idx_type i = 0; i < cache_.nargs(); ++i) cache_.cell(i).setXY(old_xo, old_yo); - return dim_; + dim = dim_; } diff --git a/src/mathed/math_textinset.h b/src/mathed/math_textinset.h index d44144d402..d276d16f70 100644 --- a/src/mathed/math_textinset.h +++ b/src/mathed/math_textinset.h @@ -1,9 +1,9 @@ #ifndef MATH_TEXTINSET_H #define MATH_TEXTINSET_H - #include "math_gridinset.h" + // not yet a substitute for the real text inset... class MathTextInset : public MathNestInset { @@ -15,7 +15,7 @@ public: /// get cursor position void getPos(idx_type idx, pos_type pos, int & x, int & y) const; /// this stores metrics information in cache_ - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// draw according to cached metrics void draw(PainterInfo &, int x, int y) const; /// draw selection background diff --git a/src/mathed/math_undersetinset.C b/src/mathed/math_undersetinset.C index f04e2dfeec..93335d3e16 100644 --- a/src/mathed/math_undersetinset.C +++ b/src/mathed/math_undersetinset.C @@ -17,7 +17,7 @@ MathInset * MathUndersetInset::clone() const } -Dimension MathUndersetInset::metrics(MetricsInfo & mi) const +void MathUndersetInset::metrics(MetricsInfo & mi, Dimension & dim) const { cell(1).metrics(mi); FracChanger dummy(mi.base); @@ -25,7 +25,7 @@ Dimension MathUndersetInset::metrics(MetricsInfo & mi) const dim_.wid = max(cell(0).width(), cell(1).width()) + 4; dim_.asc = cell(1).ascent(); dim_.des = cell(1).descent() + cell(0).height() + 4; - return dim_; + dim = dim_; } diff --git a/src/mathed/math_undersetinset.h b/src/mathed/math_undersetinset.h index 95b68921a2..c4004af554 100644 --- a/src/mathed/math_undersetinset.h +++ b/src/mathed/math_undersetinset.h @@ -20,7 +20,7 @@ public: /// MathInset * clone() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; diff --git a/src/mathed/math_unknowninset.C b/src/mathed/math_unknowninset.C index 6d5e446a13..bda6e8d7bf 100644 --- a/src/mathed/math_unknowninset.C +++ b/src/mathed/math_unknowninset.C @@ -2,6 +2,7 @@ #include "math_unknowninset.h" #include "math_support.h" +#include "math_atom.h" #include "math_mathmlstream.h" #include "math_streamstr.h" @@ -42,11 +43,9 @@ void MathUnknownInset::normalize(NormalStream & os) const } -Dimension MathUnknownInset::metrics(MetricsInfo & mi) const +void MathUnknownInset::metrics(MetricsInfo & mi, Dimension & dim) const { - Dimension dim; mathed_string_dim(mi.base.font, name_, dim); - return dim; } diff --git a/src/mathed/math_unknowninset.h b/src/mathed/math_unknowninset.h index eff59df80f..6270cdcaeb 100644 --- a/src/mathed/math_unknowninset.h +++ b/src/mathed/math_unknowninset.h @@ -15,7 +15,7 @@ public: /// MathInset * clone() const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void draw(PainterInfo & pi, int x, int y) const; /// diff --git a/src/mathed/math_xarrowinset.C b/src/mathed/math_xarrowinset.C index 8bbf0497e2..7add8d2715 100644 --- a/src/mathed/math_xarrowinset.C +++ b/src/mathed/math_xarrowinset.C @@ -18,7 +18,7 @@ MathInset * MathXArrowInset::clone() const } -Dimension MathXArrowInset::metrics(MetricsInfo & mi) const +void MathXArrowInset::metrics(MetricsInfo & mi, Dimension & dim) const { ScriptChanger dummy(mi.base); cell(0).metrics(mi); @@ -26,7 +26,7 @@ Dimension MathXArrowInset::metrics(MetricsInfo & mi) const dim_.wid = std::max(cell(0).width(), cell(1).width()) + 10; dim_.asc = cell(0).height() + 10; dim_.des = cell(1).height(); - return dim_; + dim = dim_; } diff --git a/src/mathed/math_xarrowinset.h b/src/mathed/math_xarrowinset.h index 302ba78cfe..21d1fcece1 100644 --- a/src/mathed/math_xarrowinset.h +++ b/src/mathed/math_xarrowinset.h @@ -23,7 +23,7 @@ public: /// void write(WriteStream & os) const; /// - Dimension metrics(MetricsInfo & mi) const; + void metrics(MetricsInfo & mi, Dimension & dim) const; /// void normalize(NormalStream & os) const; diff --git a/src/mathed/ref_inset.C b/src/mathed/ref_inset.C index 33e8000d91..b0f2c204e6 100644 --- a/src/mathed/ref_inset.C +++ b/src/mathed/ref_inset.C @@ -7,6 +7,7 @@ #include "BufferView.h" #include "debug.h" #include "funcrequest.h" +#include "math_support.h" #include "gettext.h" #include "LaTeXFeatures.h"