]> git.lyx.org Git - features.git/commitdiff
First step of InsetLayout cleanup.
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 13 Jul 2009 00:28:22 +0000 (00:28 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 13 Jul 2009 00:28:22 +0000 (00:28 +0000)
Get rid of Inset::getLayout(BufferParams), since all insets have access to
their own buffer. Inset::getLayout() does the same now.

Get rid of InsetCollapsable::getLayout(BufferParams) too, and remove most references to InsetCollapsable::layout_. For now IC::getLayout() still returns layout_, but the idea is to change this (provided there is no performance problem).

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30530 a592a061-630c-0410-9148-cb99ea01b6c8

src/Text3.cpp
src/insets/Inset.cpp
src/insets/Inset.h
src/insets/InsetCollapsable.cpp
src/insets/InsetCollapsable.h
src/insets/InsetFoot.cpp

index 2e99f936c566630da02dfd708e462f526af0e26e..a29e6913d9e17881e0a74650ecec53859d6113ce 100644 (file)
@@ -1327,7 +1327,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                pos_type pos = cur.pos();
                BufferParams const & bufparams = bv->buffer().params();
                Layout const & style = par.layout();
-               InsetLayout const & ilayout = cur.inset().getLayout(bufparams);
+               InsetLayout const & ilayout = cur.inset().getLayout();
                if (!style.pass_thru && !ilayout.isPassThru()
                    && par.getFontSettings(bufparams, pos).language()->lang() != "hebrew") {
                        // this avoids a double undo
@@ -2443,7 +2443,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
 
        case LFUN_INSET_DISSOLVE:
                if (!cmd.argument().empty()) {
-                       InsetLayout const & il = cur.inset().getLayout(cur.buffer()->params());
+                       InsetLayout const & il = cur.inset().getLayout();
                        InsetLayout::InsetLyXType const type = 
                                        translateLyXType(to_utf8(cmd.argument()));
                        enable = cur.inset().lyxCode() == FLEX_CODE
index 720254a7244a9670816b381eda588d63ab8b4f6e..620e995e66086c3262bcc472668f0e6e81c1cbeb 100644 (file)
@@ -448,9 +448,9 @@ bool Inset::covers(BufferView const & bv, int x, int y) const
 }
 
 
-InsetLayout const & Inset::getLayout(BufferParams const & bp) const
+InsetLayout const & Inset::getLayout() const
 {
-       return bp.documentClass().insetLayout(name());
+       return buffer().params().documentClass().insetLayout(name());
 }
 
 
index f80bff6c9fea70e537c3aca67000a9d5fba41894..f5726bcb39ffe3eb2b6887c198c191dcb86a827c 100644 (file)
@@ -385,7 +385,7 @@ public:
        ///
        virtual docstring name() const;
        ///
-       virtual InsetLayout const & getLayout(BufferParams const & bp) const;
+       virtual InsetLayout const & getLayout() const;
        /// used to toggle insets
        /// is the inset open?
        /// should this inset be handled like a normal charater
index aca37578168cece9de0004095370575322699b48..b4065f9043d6654f4b2cd6ef7147d26228d90fe8 100644 (file)
@@ -134,7 +134,7 @@ docstring InsetCollapsable::toolTip(BufferView const & bv, int x, int y) const
 {
        Dimension dim = dimensionCollapsed(bv);
        if (geometry(bv) == NoButton)
-               return translateIfPossible(layout_->labelstring());
+               return translateIfPossible(getLayout().labelstring());
        if (x > xo(bv) + dim.wid || y > yo(bv) + dim.des || isOpen(bv))
                return docstring();
 
@@ -156,7 +156,7 @@ void InsetCollapsable::setLayout(DocumentClass const * const dc)
 {
        if (dc) {
                layout_ = &(dc->insetLayout(name()));
-               labelstring_ = translateIfPossible(layout_->labelstring());
+               labelstring_ = translateIfPossible(getLayout().labelstring());
        } else {
                layout_ = &DocumentClass::plainInsetLayout();
                labelstring_ = _("UNDEFINED");
@@ -213,7 +213,7 @@ Dimension InsetCollapsable::dimensionCollapsed(BufferView const & bv) const
 {
        LASSERT(layout_, /**/);
        Dimension dim;
-       theFontMetrics(layout_->labelfont()).buttonText(
+       theFontMetrics(getLayout().labelfont()).buttonText(
                buttonLabel(bv), dim.wid, dim.asc, dim.des);
        return dim;
 }
@@ -221,12 +221,10 @@ Dimension InsetCollapsable::dimensionCollapsed(BufferView const & bv) const
 
 void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       LASSERT(layout_, /**/);
-
        auto_open_[mi.base.bv] =  mi.base.bv->cursor().isInside(this);
 
        FontInfo tmpfont = mi.base.font;
-       mi.base.font = layout_->font();
+       mi.base.font = getLayout().font();
        mi.base.font.realize(tmpfont);
 
        BufferView const & bv = *mi.base.bv;
@@ -243,7 +241,7 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
        case SubLabel: {
                InsetText::metrics(mi, dim);
                // consider width of the inset label
-               FontInfo font(layout_->labelfont());
+               FontInfo font(getLayout().labelfont());
                font.realize(sane_font);
                font.decSize();
                font.decSize();
@@ -289,13 +287,12 @@ bool InsetCollapsable::setMouseHover(bool mouse_hover)
 
 void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
 {
-       LASSERT(layout_, /**/);
        BufferView const & bv = *pi.base.bv;
 
        auto_open_[&bv] =  bv.cursor().isInside(this);
 
        FontInfo tmpfont = pi.base.font;
-       pi.base.font = layout_->font();
+       pi.base.font = getLayout().font();
        pi.base.font.realize(tmpfont);
 
        // Draw button first -- top, left or only
@@ -309,7 +306,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
                button_dim.y1 = y - dimc.asc;
                button_dim.y2 = y + dimc.des;
 
-               pi.pain.buttonText(x, y, buttonLabel(bv), layout_->labelfont(),
+               pi.pain.buttonText(x, y, buttonLabel(bv), getLayout().labelfont(),
                        mouse_hover_);
        } else {
                button_dim.x1 = 0;
@@ -355,26 +352,26 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
                const int xx2 = x + textdim.wid - TEXT_TO_INSET_OFFSET + 1;
                pi.pain.line(xx1, y + desc - 4, 
                             xx1, y + desc, 
-                       layout_->labelfont().color());
+                       getLayout().labelfont().color());
                if (status_ == Open)
                        pi.pain.line(xx1, y + desc, 
                                xx2, y + desc,
-                               layout_->labelfont().color());
+                               getLayout().labelfont().color());
                else {
                        // Make status_ value visible:
                        pi.pain.line(xx1, y + desc,
                                xx1 + 4, y + desc,
-                               layout_->labelfont().color());
+                               getLayout().labelfont().color());
                        pi.pain.line(xx2 - 4, y + desc,
                                xx2, y + desc,
-                               layout_->labelfont().color());
+                               getLayout().labelfont().color());
                }
                pi.pain.line(x + textdim.wid - 3, y + desc, x + textdim.wid - 3, 
-                       y + desc - 4, layout_->labelfont().color());
+                       y + desc - 4, getLayout().labelfont().color());
 
                // the label below the text. Can be toggled.
                if (geometry(bv) == SubLabel) {
-                       FontInfo font(layout_->labelfont());
+                       FontInfo font(getLayout().labelfont());
                        font.realize(sane_font);
                        font.decSize();
                        font.decSize();
@@ -393,12 +390,12 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
                if (cur.isInside(this)) {
                        y -= textdim.asc;
                        y += 3;
-                       pi.pain.line(xx1, y + 4, xx1, y, layout_->labelfont().color());
-                       pi.pain.line(xx1 + 4, y, xx1, y, layout_->labelfont().color());
+                       pi.pain.line(xx1, y + 4, xx1, y, getLayout().labelfont().color());
+                       pi.pain.line(xx1 + 4, y, xx1, y, getLayout().labelfont().color());
                        pi.pain.line(xx2, y + 4, xx2, y,
-                               layout_->labelfont().color());
+                               getLayout().labelfont().color());
                        pi.pain.line(xx2 - 4, y, xx2, y,
-                               layout_->labelfont().color());
+                               getLayout().labelfont().color());
                }
                break;
        }
@@ -679,7 +676,7 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
                break;
 
        default:
-               if (layout_ && layout_->isForceLtr()) {
+               if (getLayout().isForceLtr()) {
                        // Force any new text to latex_language
                        // FIXME: This should only be necessary in constructor, but
                        // new paragraphs that are created by pressing enter at the
@@ -697,16 +694,16 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
 
 bool InsetCollapsable::allowMultiPar() const
 {
-       return layout_->isMultiPar();
+       return getLayout().isMultiPar();
 }
 
 
 void InsetCollapsable::resetParagraphsFont()
 {
        Font font(inherit_font, buffer().params().language);
-       if (layout_->isForceLtr())
+       if (getLayout().isForceLtr())
                font.setLanguage(latex_language);
-       if (layout_->isPassThru()) {
+       if (getLayout().isPassThru()) {
                ParagraphList::iterator par = paragraphs().begin();
                ParagraphList::iterator const end = paragraphs().end();
                while (par != end) {
@@ -806,7 +803,7 @@ bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd,
        case LFUN_TEXTSTYLE_UPDATE:
        case LFUN_TOC_INSERT:
        case LFUN_WRAP_INSERT:
-               if (layout_->isPassThru()) {
+               if (getLayout().isPassThru()) {
                        flag.setEnabled(false);
                        return true;
                }
@@ -825,16 +822,16 @@ bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd,
                return true;
 
        case LFUN_LANGUAGE:
-               flag.setEnabled(!layout_->isForceLtr());
+               flag.setEnabled(!getLayout().isForceLtr());
                return InsetText::getStatus(cur, cmd, flag);
 
        case LFUN_BREAK_PARAGRAPH:
-               flag.setEnabled(layout_->isMultiPar());
+               flag.setEnabled(getLayout().isMultiPar());
                return true;
 
        case LFUN_TAB_INSERT:
        case LFUN_TAB_DELETE:
-               if (layout_->isPassThru()) {
+               if (getLayout().isPassThru()) {
                        flag.setEnabled(true);
                        return true;
                }
@@ -875,9 +872,7 @@ docstring InsetCollapsable::floatName(
 
 InsetLayout::InsetDecoration InsetCollapsable::decoration() const
 {
-       if (!layout_)
-               return InsetLayout::CLASSIC;
-       InsetLayout::InsetDecoration const dec = layout_->decoration();
+       InsetLayout::InsetDecoration const dec = getLayout().decoration();
        switch (dec) {
        case InsetLayout::CLASSIC:
        case InsetLayout::MINIMALISTIC:
@@ -895,42 +890,36 @@ InsetLayout::InsetDecoration InsetCollapsable::decoration() const
 int InsetCollapsable::latex(odocstream & os,
                          OutputParams const & runparams) const
 {
-       // FIXME: What should we do layout_ is 0?
-       // 1) assert
-       // 2) throw an error
-       if (!layout_)
-               return 0;
-
        // This implements the standard way of handling the LaTeX output of
        // a collapsable inset, either a command or an environment. Standard 
        // collapsable insets should not redefine this, non-standard ones may
        // call this.
-       if (!layout_->latexname().empty()) {
-               if (layout_->latextype() == InsetLayout::COMMAND) {
+       if (!getLayout().latexname().empty()) {
+               if (getLayout().latextype() == InsetLayout::COMMAND) {
                        // FIXME UNICODE
                        if (runparams.moving_arg)
                                os << "\\protect";
-                       os << '\\' << from_utf8(layout_->latexname());
-                       if (!layout_->latexparam().empty())
-                               os << from_utf8(layout_->latexparam());
+                       os << '\\' << from_utf8(getLayout().latexname());
+                       if (!getLayout().latexparam().empty())
+                               os << from_utf8(getLayout().latexparam());
                        os << '{';
-               } else if (layout_->latextype() == InsetLayout::ENVIRONMENT) {
-                       os << "%\n\\begin{" << from_utf8(layout_->latexname()) << "}\n";
-                       if (!layout_->latexparam().empty())
-                               os << from_utf8(layout_->latexparam());
+               } else if (getLayout().latextype() == InsetLayout::ENVIRONMENT) {
+                       os << "%\n\\begin{" << from_utf8(getLayout().latexname()) << "}\n";
+                       if (!getLayout().latexparam().empty())
+                               os << from_utf8(getLayout().latexparam());
                }
        }
        OutputParams rp = runparams;
-       if (layout_->isPassThru())
+       if (getLayout().isPassThru())
                rp.verbatim = true;
-       if (layout_->isNeedProtect())
+       if (getLayout().isNeedProtect())
                rp.moving_arg = true;
        int i = InsetText::latex(os, rp);
-       if (!layout_->latexname().empty()) {
-               if (layout_->latextype() == InsetLayout::COMMAND) {
+       if (!getLayout().latexname().empty()) {
+               if (getLayout().latextype() == InsetLayout::COMMAND) {
                        os << "}";
-               } else if (layout_->latextype() == InsetLayout::ENVIRONMENT) {
-                       os << "\n\\end{" << from_utf8(layout_->latexname()) << "}\n";
+               } else if (getLayout().latextype() == InsetLayout::ENVIRONMENT) {
+                       os << "\n\\end{" << from_utf8(getLayout().latexname()) << "}\n";
                        i += 4;
                }
        }
index de432aa8fa01447ad1d3ae3d9d82f2307fef6168..3a1591f32f178baba21a095cb1482888bf1eb617 100644 (file)
@@ -45,8 +45,6 @@ public:
        ///
        docstring name() const { return from_ascii("Collapsable"); }
        ///
-       InsetLayout const & getLayout(BufferParams const &) const { return *layout_; }
-       ///
        InsetLayout const & getLayout() const { return *layout_; } 
        ///
        void setLayout(BufferParams const &);
@@ -138,7 +136,7 @@ public:
        ///
        bool setMouseHover(bool mouse_hover);
        ///
-       ColorCode backgroundColor() const { return layout_->bgcolor(); }
+       ColorCode backgroundColor() const { return getLayout().bgcolor(); }
        ///
        int latex(odocstream &, OutputParams const &) const;
        ///
@@ -153,11 +151,11 @@ public:
        InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
 
        /// Allow multiple blanks
-       virtual bool isFreeSpacing() const { return layout_->isFreeSpacing(); }
+       virtual bool isFreeSpacing() const { return getLayout().isFreeSpacing(); }
        /// Don't eliminate empty paragraphs
-       virtual bool allowEmpty() const { return layout_->isKeepEmpty(); }
+       virtual bool allowEmpty() const { return getLayout().isKeepEmpty(); }
        /// Force inset into LTR environment if surroundings are RTL?
-       virtual bool forceLTR() const { return layout_->isForceLtr(); }
+       virtual bool forceLTR() const { return getLayout().isForceLtr(); }
        ///
        virtual bool usePlainLayout() const { return true; }
        /// Is this inset's layout defined in the document's textclass?
index 6c0d9b79245fba635b6ec2e78bf9599496607876..d0d432b5fdbbf7f4af0341d86d80cad3cb091bcd 100644 (file)
@@ -55,7 +55,7 @@ void InsetFoot::updateLabels(ParIterator const & it)
                cnts.step(foot);
                // FIXME: the counter should format itself.
                custom_label_= bformat(from_utf8("%1$s %2$s"),
-                                      translateIfPossible(getLayout(bp).labelstring()),
+                                      translateIfPossible(getLayout().labelstring()),
                                       cnts.theCounter(foot, outer.getParLanguage(bp)->code()));
                setLabel(custom_label_);