]> git.lyx.org Git - features.git/commitdiff
This is the first of a series of commits that will make InsetLayout a real class.
authorRichard Heck <rgheck@comcast.net>
Fri, 22 Feb 2008 02:32:52 +0000 (02:32 +0000)
committerRichard Heck <rgheck@comcast.net>
Fri, 22 Feb 2008 02:32:52 +0000 (02:32 +0000)
In this commit, we do the minimal amount of work necessary to protect our data.

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

development/scons/scons_manifest.py
src/Makefile.am
src/MenuBackend.cpp
src/Text3.cpp
src/TextClass.cpp
src/insets/InsetCollapsable.cpp
src/insets/InsetCollapsable.h
src/insets/InsetFlex.cpp
src/insets/InsetFoot.cpp
src/insets/InsetLayout.h

index e189b520ad30885773f6a97471dbee71ad0fe2d5..076f226e6fd18614563806427d2453a267fd85e3 100644 (file)
@@ -1052,6 +1052,7 @@ src_insets_files = Split('''
     InsetIndex.cpp
     InsetInfo.cpp
     InsetLabel.cpp
+    InsetLayout.cpp
     InsetLine.cpp
     InsetListings.cpp
     InsetListingsParams.cpp
index 0b4203424d232686c5191b1100fba1e5c29dc98d..2e7e2e0a7a9d35549ca795491d9c7f4b4eb92547 100644 (file)
@@ -515,6 +515,7 @@ SOURCEFILESINSETS = \
        insets/InsetIndex.cpp \
        insets/InsetInfo.cpp \
        insets/InsetLabel.cpp \
+       insets/InsetLayout.cpp \
        insets/InsetLine.cpp \
        insets/InsetListings.cpp \
        insets/InsetListingsParams.cpp \
index ceb071cf8f7443c063444c7b783b1685d5d501b9..9959bd0d4c083a2e3d0cd082bcc54eb00a0d86f1 100644 (file)
@@ -648,7 +648,7 @@ void expandFlexInsert(Menu & tomenu, Buffer const * buf, string s)
        InsetLayouts::const_iterator end = insetlayouts.end();
        for (; cit != end; ++cit) {
                docstring const label = cit->first;
-               if (cit->second.lyxtype == s)
+               if (cit->second.lyxtype() == s)
                        tomenu.addWithStatusCheck(MenuItem(MenuItem::Command, 
                                label, FuncRequest(LFUN_FLEX_INSERT,
                                                label)));
index 5d3246fa52d481aa27cebe274608fb16f9400a82..99ec81105b7b7be07f468a6054971d1e71814dd9 100644 (file)
@@ -1967,10 +1967,10 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                code = FLEX_CODE;
                string s = cmd.getArg(0);
                InsetLayout il =  cur.buffer().params().getTextClass().insetlayout(from_utf8(s));
-               if (il.lyxtype != "charstyle" &&
-                   il.lyxtype != "custom" &&
-                   il.lyxtype != "element" &&
-                   il.lyxtype != "standard")
+               if (il.lyxtype() != "charstyle" &&
+                   il.lyxtype() != "custom" &&
+                   il.lyxtype() != "element" &&
+                   il.lyxtype ()!= "standard")
                        enable = false;
                break;
                }
@@ -2117,7 +2117,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                if (!cmd.argument().empty()) {
                        InsetLayout il = cur.inset().getLayout(cur.buffer().params());
                        enable = cur.inset().lyxCode() == FLEX_CODE
-                                && il.lyxtype == to_utf8(cmd.argument());
+                                && il.lyxtype() == to_utf8(cmd.argument());
                } else {
                        enable = !isMainText(cur.bv().buffer()) 
                                 && cur.inset().nargs() == 1;
index 7f640b85be0f4a65d28d74a596dd867282e5a5c6..2dbd10b6f364d82d679f1fbb29f47afc33c5241a 100644 (file)
@@ -824,27 +824,27 @@ void TextClass::readInsetLayout(Lexer & lexrc, docstring const & name)
        // Here add element to list if getout == true
        if (getout) {
                InsetLayout il;
-               il.name = to_ascii(name);
-               il.lyxtype = lyxtype;
-               il.labelstring = labelstring;
-               il.decoration = decoration;
-               il.latextype = latextype;
-               il.latexname = latexname;
-               il.latexparam = latexparam;
-               il.multipar = multipar;
-               il.passthru = passthru;
-               il.needprotect = needprotect;
-               il.freespacing = freespacing;
-               il.forceltr = forceltr;
-               il.keepempty = keepempty;
-               il.font = font;
+               il.name_ = to_ascii(name);
+               il.lyxtype_ = lyxtype;
+               il.labelstring_ = labelstring;
+               il.decoration_ = decoration;
+               il.latextype_ = latextype;
+               il.latexname_ = latexname;
+               il.latexparam_ = latexparam;
+               il.multipar_ = multipar;
+               il.passthru_ = passthru;
+               il.needprotect_ = needprotect;
+               il.freespacing_ = freespacing;
+               il.forceltr_ = forceltr;
+               il.keepempty_ = keepempty;
+               il.font_ = font;
                // The label font is generally used as-is without
                // any realization against a given context.
                labelfont.realize(sane_font);
-               il.labelfont = labelfont;
-               il.bgcolor = bgcolor;
-               il.preamble = preamble;
-               il.requires = requires;
+               il.labelfont_ = labelfont;
+               il.bgcolor_ = bgcolor;
+               il.preamble_ = preamble;
+               il.requires_ = requires;
                insetlayoutlist_[name] = il;
        }
 
index 0780999c2e7bbe4b15961731428a8705b04c5278..97783d564321769782a461632d091ea17ea33118 100644 (file)
@@ -105,7 +105,7 @@ docstring InsetCollapsable::toolTip(BufferView const & bv, int x, int y) const
 {
        Dimension dim = dimensionCollapsed();
        if (geometry() == NoButton)
-               return layout_->labelstring;
+               return layout_->labelstring();
        else if (x > xo(bv) + dim.wid || y > yo(bv) + dim.des)
                return docstring();
 
@@ -130,7 +130,7 @@ void InsetCollapsable::setLayout(TextClassPtr tc)
        textClass_ = tc;
        if ( tc.get() != 0 ) {
                layout_ = &tc->insetlayout(name());
-               labelstring_ = layout_->labelstring;
+               labelstring_ = layout_->labelstring();
        } else {
                layout_ = &TextClass::emptyInsetLayout();
                labelstring_ = _("UNDEFINED");
@@ -207,7 +207,7 @@ Dimension InsetCollapsable::dimensionCollapsed() const
 {
        BOOST_ASSERT(layout_);
        Dimension dim;
-       theFontMetrics(layout_->labelfont).buttonText(
+       theFontMetrics(layout_->labelfont()).buttonText(
                labelstring_, dim.wid, dim.asc, dim.des);
        return dim;
 }
@@ -220,7 +220,7 @@ void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
        autoOpen_ = mi.base.bv->cursor().isInside(this);
 
        FontInfo tmpfont = mi.base.font;
-       mi.base.font = layout_->font;
+       mi.base.font = layout_->font();
        mi.base.font.realize(tmpfont);
 
        switch (geometry()) {
@@ -235,7 +235,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(layout_->labelfont());
                font.realize(sane_font);
                font.decSize();
                font.decSize();
@@ -288,7 +288,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
        pi.background_color = backgroundColor();
 
        FontInfo tmpfont = pi.base.font;
-       pi.base.font = layout_->font;
+       pi.base.font = layout_->font();
        pi.base.font.realize(tmpfont);
 
        // Draw button first -- top, left or only
@@ -302,7 +302,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, labelstring_, layout_->labelfont,
+               pi.pain.buttonText(x, y, labelstring_, layout_->labelfont(),
                        mouse_hover_);
        } else {
                button_dim.x1 = 0;
@@ -348,26 +348,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());
+                       layout_->labelfont().color());
                if (status_ == Open)
                        pi.pain.line(xx1, y + desc, 
                                xx2, y + desc,
-                               layout_->labelfont.color());
+                               layout_->labelfont().color());
                else {
                        // Make status_ value visible:
                        pi.pain.line(xx1, y + desc,
                                xx1 + 4, y + desc,
-                               layout_->labelfont.color());
+                               layout_->labelfont().color());
                        pi.pain.line(xx2 - 4, y + desc,
                                xx2, y + desc,
-                               layout_->labelfont.color());
+                               layout_->labelfont().color());
                }
                pi.pain.line(x + textdim.wid - 3, y + desc, x + textdim.wid - 3, y + desc - 4,
-                       layout_->labelfont.color());
+                       layout_->labelfont().color());
 
                // the label below the text. Can be toggled.
                if (geometry() == SubLabel) {
-                       FontInfo font(layout_->labelfont);
+                       FontInfo font(layout_->labelfont());
                        font.realize(sane_font);
                        font.decSize();
                        font.decSize();
@@ -386,12 +386,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, layout_->labelfont().color());
+                       pi.pain.line(xx1 + 4, y, xx1, y, layout_->labelfont().color());
                        pi.pain.line(xx2, y + 4, xx2, y,
-                               layout_->labelfont.color());
+                               layout_->labelfont().color());
                        pi.pain.line(xx2 - 4, y, xx2, y,
-                               layout_->labelfont.color());
+                               layout_->labelfont().color());
                }
                break;
        }
@@ -612,7 +612,7 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
        }
 
        default:
-               if (layout_ && layout_->forceltr) {
+               if (layout_ && layout_->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
@@ -630,7 +630,7 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd)
 
 bool InsetCollapsable::allowMultiPar() const
 {
-       return layout_->multipar;
+       return layout_->isMultiPar();
 }
 
 
@@ -638,9 +638,9 @@ void InsetCollapsable::resetParagraphsFont()
 {
        Font font;
        font.fontInfo() = inherit_font;
-       if (layout_->forceltr)
+       if (layout_->isForceLtr())
                font.setLanguage(latex_language);
-       if (layout_->passthru) {
+       if (layout_->isPassThru()) {
                ParagraphList::iterator par = paragraphs().begin();
                ParagraphList::iterator const end = paragraphs().end();
                while (par != end) {
@@ -744,7 +744,7 @@ bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd,
        case LFUN_TABULAR_INSERT:
        case LFUN_TOC_INSERT:
        case LFUN_WRAP_INSERT:
-       if (layout_->passthru) {
+       if (layout_->isPassThru()) {
                flag.enabled(false);
                return true;
        } else
@@ -759,12 +759,12 @@ bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd,
                return true;
 
        case LFUN_LANGUAGE:
-               flag.enabled(!layout_->forceltr);
+               flag.enabled(!layout_->isForceLtr());
                return InsetText::getStatus(cur, cmd, flag);
 
        case LFUN_BREAK_PARAGRAPH:
        case LFUN_BREAK_PARAGRAPH_SKIP:
-               flag.enabled(layout_->multipar);
+               flag.enabled(layout_->isMultiPar());
                return true;
 
        default:
@@ -799,11 +799,11 @@ docstring InsetCollapsable::floatName(string const & type, BufferParams const &
 
 InsetCollapsable::Decoration InsetCollapsable::decoration() const
 {
-       if (!layout_ || layout_->decoration == "classic")
+       if (!layout_ || layout_->decoration() == "classic")
                return Classic;
-       if (layout_->decoration == "minimalistic")
+       if (layout_->decoration() == "minimalistic")
                return Minimalistic;
-       if (layout_->decoration == "conglomerate")
+       if (layout_->decoration() == "conglomerate")
                return Conglomerate;
        if (lyxCode() == FLEX_CODE)
                // FIXME: Is this really necessary?
@@ -821,7 +821,7 @@ bool InsetCollapsable::isMacroScope(Buffer const &) const
 
        // see InsetCollapsable::latex(...) below. In these case
        // an environment is opened there
-       if (!layout_->latexname.empty())
+       if (!layout_->latexname().empty())
                return true;
 
        return false;
@@ -841,32 +841,32 @@ int InsetCollapsable::latex(Buffer const & buf, odocstream & os,
        // 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 == "command") {
+       if (!layout_->latexname().empty()) {
+               if (layout_->latextype() == "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(layout_->latexname());
+                       if (!layout_->latexparam().empty())
+                               os << from_utf8(layout_->latexparam());
                        os << '{';
-               } else if (layout_->latextype == "environment") {
-                       os << "%\n\\begin{" << from_utf8(layout_->latexname) << "}\n";
-                       if (!layout_->latexparam.empty())
-                               os << from_utf8(layout_->latexparam);
+               } else if (layout_->latextype() == "environment") {
+                       os << "%\n\\begin{" << from_utf8(layout_->latexname()) << "}\n";
+                       if (!layout_->latexparam().empty())
+                               os << from_utf8(layout_->latexparam());
                }
        }
        OutputParams rp = runparams;
-       if (layout_->passthru)
+       if (layout_->isPassThru())
                rp.verbatim = true;
-       if (layout_->needprotect)
+       if (layout_->isNeedProtect())
                rp.moving_arg = true;
        int i = InsetText::latex(buf, os, rp);
-       if (!layout_->latexname.empty()) {
-               if (layout_->latextype == "command") {
+       if (!layout_->latexname().empty()) {
+               if (layout_->latextype() == "command") {
                        os << "}";
-               } else if (layout_->latextype == "environment") {
-                       os << "\n\\end{" << from_utf8(layout_->latexname) << "}\n";
+               } else if (layout_->latextype() == "environment") {
+                       os << "\n\\end{" << from_utf8(layout_->latexname()) << "}\n";
                        i += 4;
                }
        }
@@ -880,15 +880,15 @@ void InsetCollapsable::validate(LaTeXFeatures & features) const
                return;
 
        // Force inclusion of preamble snippet in layout file
-       features.require(layout_->name);
+       features.require(layout_->name());
        InsetText::validate(features);
 }
 
 
 bool InsetCollapsable::undefined() const
 {
-       std::string const & n = getLayout().name;
-       return n.empty() || n == TextClass::emptyInsetLayout().name;
+       std::string const & n = getLayout().name();
+       return n.empty() || n == TextClass::emptyInsetLayout().name();
 }
 
 
index 432e52c8cdc026665c6023fc4999fd311d45a466..58666bfe19c8034273a344713b52898b0c508ec7 100644 (file)
@@ -47,15 +47,20 @@ public:
                );
        ///
        InsetCollapsable(InsetCollapsable const & rhs);
-       
+       ///
        InsetCollapsable * asInsetCollapsable() { return this; }
+       ///
        InsetCollapsable const * asInsetCollapsable() const { return this; }
+       ///
        docstring toolTip(BufferView const & bv, int x, int y) const;
+       ///
        docstring name() const { return from_ascii("Collapsable"); }
+       ///
        InsetLayout const & getLayout(BufferParams const &) const
-       { return *layout_; } 
+               { return *layout_; } 
+       ///
        InsetLayout const & getLayout() const
-       { return *layout_; } 
+               { return *layout_; } 
        ///
        void setLayout(BufferParams const &);
        /// (Re-)set the character style parameters from \p tc according
@@ -74,7 +79,8 @@ public:
 
        /// return x,y of given position relative to the inset's baseline
        void cursorPos(BufferView const & bv, CursorSlice const & sl,
-               bool boundary, int & x, int & y) const;
+       ///
+       bool boundary, int & x, int & y) const;
        ///
        bool hitButton(FuncRequest const &) const;
        ///
@@ -144,8 +150,8 @@ public:
        ///
        bool setMouseHover(bool mouse_hover);
        ///
-       virtual ColorCode backgroundColor() const {return layout_->bgcolor; }
-
+       virtual ColorCode backgroundColor() const {return layout_->bgcolor(); }
+       ///
        int latex(Buffer const &, odocstream &,
                  OutputParams const &) const;
        ///
@@ -154,11 +160,11 @@ public:
        virtual InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
 
        /// Allow multiple blanks
-       virtual bool isFreeSpacing() const { return layout_->freespacing; }
+       virtual bool isFreeSpacing() const { return layout_->isFreeSpacing(); }
        /// Don't eliminate empty paragraphs
-       virtual bool allowEmpty() const { return layout_->keepempty; }
+       virtual bool allowEmpty() const { return layout_->isKeepEmpty(); }
        /// Force inset into LTR environment if surroundings are RTL?
-       virtual bool forceLTR() const { return layout_->forceltr; }
+       virtual bool forceLTR() const { return layout_->isForceLtr(); }
        ///
        virtual bool useEmptyLayout() const { return true; }
        /// Is this inset's layout defined in the document's textclass?
index 7a83014013031bb876e50c0b4ffc00b79c9b41f0..279f9940542a2327f2fd1d300e5cf3b1bb4bf3b7 100644 (file)
@@ -45,8 +45,8 @@ InsetFlex::InsetFlex(BufferParams const & bp,
        name_(layoutName)
 {
        setLayout(tc); // again, because now the name is initialized
-       packages_ = getLayout().requires;
-       preamble_ = getLayout().preamble;
+       packages_ = getLayout().requires();
+       preamble_ = getLayout().preamble();
 }
 
 
@@ -111,8 +111,8 @@ int InsetFlex::docbook(Buffer const & buf, odocstream & os,
        ParagraphList::const_iterator end = paragraphs().end();
 
        if (!undefined())
-               sgml::openTag(os, getLayout().latexname,
-                             par->getID(buf, runparams) + getLayout().latexparam);
+               sgml::openTag(os, getLayout().latexname(),
+                             par->getID(buf, runparams) + getLayout().latexparam());
 
        for (; par != end; ++par) {
                par->simpleDocBookOnePar(buf, os, runparams,
@@ -121,7 +121,7 @@ int InsetFlex::docbook(Buffer const & buf, odocstream & os,
        }
 
        if (!undefined())
-               sgml::closeTag(os, getLayout().latexname);
+               sgml::closeTag(os, getLayout().latexname());
 
        return 0;
 }
index 57b404614fa8c6d6f5c8a45363a61d68a3b27f4c..58acf7d562d312a4be4e8b2dde8656a59b8b60d0 100644 (file)
@@ -67,7 +67,7 @@ void InsetFoot::updateLabels(Buffer const & buf, ParIterator const & it)
                cnts.step(foot);
                //FIXME: the counter should format itself.
                setLabel(support::bformat(from_ascii("%1$s %2$s"), 
-                                         getLayout(buf.params()).labelstring, 
+                                         getLayout(buf.params()).labelstring()
                                          cnts.theCounter(foot)));
        
        }
index c5f64c6a9eb807b1b1af1326965d6ecf497fbf48..08cab983d405366a584cae9e78b5850f2192ef9e 100644 (file)
@@ -4,6 +4,9 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
+ * \author Martin Vermeer
+ * \author Richard Heck
+ *
  * Full author contact details are available in file CREDITS.
  */
 
@@ -23,30 +26,85 @@ namespace lyx {
 ///
 class InsetLayout {
 public:
-       InsetLayout() : 
-               name("undefined"),
-               labelstring(from_utf8("UNDEFINED")),
-               font(sane_font), labelfont(sane_font),
-               bgcolor(Color_error)
-               { labelfont.setColor(Color_error); };
-       std::string name;
-       std::string lyxtype;
-       docstring labelstring;
-       std::string decoration;
-       std::string latextype;
-       std::string latexname;
-       std::string latexparam;
-       FontInfo font;
-       FontInfo labelfont;
-       ColorCode bgcolor;
-       std::string preamble;
-       std::set<std::string> requires;
-       bool multipar;
-       bool passthru;
-       bool needprotect;
-       bool freespacing;
-       bool keepempty;
-       bool forceltr;
+       ///
+       InsetLayout();
+       ///
+       std::string name() const { return name_; };
+       ///
+       std::string lyxtype() const { return lyxtype_; };
+       ///
+       docstring labelstring() const { return labelstring_; };
+       ///
+       //FIXME This could be an enum
+       std::string decoration() const { return decoration_; };
+       ///
+       std::string latextype() const { return latextype_; };
+       ///
+       std::string latexname() const { return latexname_; };
+       ///
+       std::string latexparam() const { return latexparam_; };
+       ///
+       FontInfo font() const { return font_; };
+       ///
+       FontInfo labelfont() const { return labelfont_; };
+       ///
+       ColorCode bgcolor() const { return bgcolor_; };
+       ///
+       std::string preamble() const { return preamble_; };
+       ///
+       std::set<std::string> requires() const { return requires_; };
+       ///
+       bool isMultiPar() const { return multipar_; };
+       ///
+       bool isPassThru() const { return passthru_; };
+       ///
+       bool isNeedProtect() const { return needprotect_; };
+       ///
+       bool isFreeSpacing() const { return freespacing_; };
+       ///
+       bool isKeepEmpty() const { return keepempty_; };
+       ///
+       bool isForceLtr() const { return forceltr_; };
+private:
+       ///
+       std::string name_;
+       ///
+       std::string lyxtype_;
+       ///
+       docstring labelstring_;
+       ///
+       std::string decoration_;
+       ///
+       std::string latextype_;
+       ///
+       std::string latexname_;
+       ///
+       std::string latexparam_;
+       ///
+       FontInfo font_;
+       ///
+       FontInfo labelfont_;
+       ///
+       ColorCode bgcolor_;
+       ///
+       std::string preamble_;
+       ///
+       std::set<std::string> requires_;
+       ///
+       bool multipar_;
+       ///
+       bool passthru_;
+       ///
+       bool needprotect_;
+       ///
+       bool freespacing_;
+       ///
+       bool keepempty_;
+       ///
+       bool forceltr_;
+       
+       //FIXME This will be removed.
+       friend class TextClass;
 };
 
 } // namespace lyx