The attached patch... as nobody came up with a better name, InsetFlex it will be.
Also fixed the handling of inset-specific preamble snippets, and further minor removal of dead code. - Martin
Index: TextClass.cpp =================================================================== --- TextClass.cpp (revision 20022) +++ TextClass.cpp (working copy) @@ -694,6 +694,7 @@ case IL_FONT: font.lyxRead(lexrc); font.realize(defaultfont()); + // So: define font before labelfont labelfont = font; break; case IL_BGCOLOR: { Index: insets/InsetFlex.cpp =================================================================== --- insets/InsetFlex.cpp (revision 20022) +++ insets/InsetFlex.cpp (working copy) @@ -1,5 +1,5 @@ /** - * \file InsetCharStyle.cpp + * \file InsetFlex.cpp * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * @@ -12,7 +12,7 @@ #include <config.h> -#include "InsetCharStyle.h" +#include "InsetFlex.h" #include "Buffer.h" #include "BufferParams.h" @@ -44,14 +44,7 @@ using std::ostream; -InsetCharStyle::InsetCharStyle(BufferParams const & bp, string const s) - : InsetCollapsable(bp, Collapsed) -{ - params_.name = s; -} - - -InsetCharStyle::InsetCharStyle(BufferParams const & bp, +InsetFlex::InsetFlex(BufferParams const & bp, InsetLayout il) : InsetCollapsable(bp, Collapsed) { @@ -60,50 +53,50 @@ } -InsetCharStyle::InsetCharStyle(InsetCharStyle const & in) +InsetFlex::InsetFlex(InsetFlex const & in) : InsetCollapsable(in), params_(in.params_) {} -Inset * InsetCharStyle::clone() const +Inset * InsetFlex::clone() const { - return new InsetCharStyle(*this); + return new InsetFlex(*this); } -bool InsetCharStyle::undefined() const +bool InsetFlex::undefined() const { return layout_.labelstring == from_utf8("UNDEFINED"); } -void InsetCharStyle::setLayout(InsetLayout il) +void InsetFlex::setLayout(InsetLayout il) { layout_ = il; } -docstring const InsetCharStyle::editMessage() const +docstring const InsetFlex::editMessage() const { return _("Opened CharStyle Inset"); } -void InsetCharStyle::write(Buffer const & buf, ostream & os) const +void InsetFlex::write(Buffer const & buf, ostream & os) const { params_.write(os); InsetCollapsable::write(buf, os); } -void InsetCharStyle::read(Buffer const & buf, Lexer & lex) +void InsetFlex::read(Buffer const & buf, Lexer & lex) { params_.read(lex); InsetCollapsable::read(buf, lex); } -bool InsetCharStyle::metrics(MetricsInfo & mi, Dimension & dim) const +bool InsetFlex::metrics(MetricsInfo & mi, Dimension & dim) const { Font tmpfont = mi.base.font; getDrawFont(mi.base.font); @@ -115,7 +108,7 @@ } -void InsetCharStyle::draw(PainterInfo & pi, int x, int y) const +void InsetFlex::draw(PainterInfo & pi, int x, int y) const { setPosCache(pi, x, y); @@ -128,19 +121,19 @@ } -void InsetCharStyle::getDrawFont(Font & font) const +void InsetFlex::getDrawFont(Font & font) const { font = layout_.font; } -void InsetCharStyle::doDispatch(Cursor & cur, FuncRequest & cmd) +void InsetFlex::doDispatch(Cursor & cur, FuncRequest & cmd) { InsetCollapsable::doDispatch(cur, cmd); } -bool InsetCharStyle::getStatus(Cursor & cur, FuncRequest const & cmd, +bool InsetFlex::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & status) const { switch (cmd.action) { @@ -157,14 +150,14 @@ } -int InsetCharStyle::plaintext(Buffer const & buf, odocstream & os, +int InsetFlex::plaintext(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { return InsetText::plaintext(buf, os, runparams); } -int InsetCharStyle::docbook(Buffer const & buf, odocstream & os, +int InsetFlex::docbook(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { ParagraphList::const_iterator beg = paragraphs().begin(); @@ -189,19 +182,19 @@ } -void InsetCharStyle::textString(Buffer const & buf, odocstream & os) const +void InsetFlex::textString(Buffer const & buf, odocstream & os) const { os << paragraphs().begin()->asString(buf, true); } -void InsetCharStyleParams::write(ostream & os) const +void InsetFlexParams::write(ostream & os) const { os << "CharStyle " << name << "\n"; } -void InsetCharStyleParams::read(Lexer & lex) +void InsetFlexParams::read(Lexer & lex) { while (lex.isOK()) { lex.next(); Index: insets/Inset.cpp =================================================================== --- insets/Inset.cpp (revision 20022) +++ insets/Inset.cpp (working copy) @@ -98,7 +98,7 @@ InsetName("line", Inset::LINE_CODE), InsetName("branch", Inset::BRANCH_CODE), InsetName("box", Inset::BOX_CODE), - InsetName("charstyle", Inset::CHARSTYLE_CODE), + InsetName("flex", Inset::FLEX_CODE), InsetName("vspace", Inset::VSPACE_CODE), InsetName("mathmacroarg", Inset::MATHMACROARG_CODE), InsetName("listings", Inset::LISTINGS_CODE), Index: insets/InsetCharStyle.h =================================================================== --- insets/InsetCharStyle.h (revision 20022) +++ insets/InsetCharStyle.h (working copy) @@ -1,100 +0,0 @@ -// -*- C++ -*- -/** - * \file InsetCharStyle.h - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Angus Leeming - * \author Martin Vermeer - * - * Full author contact details are available in file CREDITS. - */ - -#ifndef INSETCHARSTYLE_H -#define INSETCHARSTYLE_H - -#include "InsetCollapsable.h" -#include "TextClass.h" - - -namespace lyx { - - -class InsetCharStyleParams { -public: - /// - void write(std::ostream & os) const; - /// - void read(Lexer & lex); - /// - std::string name; -}; - - -/** The CharStyle inset, also XML short element - -*/ -class InsetCharStyle : public InsetCollapsable { -public: - /// Construct an undefined character style - InsetCharStyle(BufferParams const &, std::string const); - /// - InsetCharStyle(BufferParams const &, InsetLayout); - /// - docstring name() const { return from_ascii("CharStyle"); } - /// Is this character style defined in the document's textclass? - /// May be wrong after textclass change or paste from another document - bool undefined() const; - /// (Re-)set the character style parameters from \p il - void setLayout(InsetLayout il); - /// - virtual docstring const editMessage() const; - /// - Inset::Code lyxCode() const { return Inset::CHARSTYLE_CODE; } - /// - void write(Buffer const &, std::ostream &) const; - /// - void read(Buffer const & buf, Lexer & lex); - /// - bool metrics(MetricsInfo &, Dimension &) const; - /// - void draw(PainterInfo &, int, int) const; - /// - void getDrawFont(Font &) const; - /// - bool forceDefaultParagraphs(idx_type) const { return true; } - - /// - int plaintext(Buffer const &, odocstream &, - OutputParams const &) const; - /// - int docbook(Buffer const &, odocstream &, - OutputParams const &) const; - /// the string that is passed to the TOC - virtual void textString(Buffer const &, odocstream &) const; - - /// - InsetCharStyleParams const & params() const { return params_; } - - /// should paragraph indendation be ommitted in any case? - bool neverIndent(Buffer const &) const { return true; } - -protected: - InsetCharStyle(InsetCharStyle const &); - virtual void doDispatch(Cursor & cur, FuncRequest & cmd); - /// - bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const; - -private: - friend class InsetCharStyleParams; - - virtual Inset * clone() const; - - /// - InsetCharStyleParams params_; -}; - - -} // namespace lyx - -#endif Index: insets/Inset.h =================================================================== --- insets/Inset.h (revision 20022) +++ insets/Inset.h (working copy) @@ -352,7 +352,7 @@ /// BOX_CODE, /// - CHARSTYLE_CODE, + FLEX_CODE, /// VSPACE_CODE, /// Index: insets/InsetCharStyle.cpp =================================================================== --- insets/InsetCharStyle.cpp (revision 20022) +++ insets/InsetCharStyle.cpp (working copy) @@ -1,224 +0,0 @@ -/** - * \file InsetCharStyle.cpp - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Angus Leeming - * \author Martin Vermeer - * \author Jürgen Spitzmüller - * - * Full author contact details are available in file CREDITS. - */ - -#include <config.h> - -#include "InsetCharStyle.h" - -#include "Buffer.h" -#include "BufferParams.h" -#include "BufferView.h" -#include "DispatchResult.h" -#include "FuncRequest.h" -#include "FuncStatus.h" -#include "Cursor.h" -#include "gettext.h" -#include "Color.h" -#include "Lexer.h" -#include "Text.h" -#include "MetricsInfo.h" -#include "Paragraph.h" -#include "paragraph_funcs.h" -#include "sgml.h" - -#include "frontends/FontMetrics.h" -#include "frontends/Painter.h" - -#include "support/convert.h" - -#include <sstream> - - -namespace lyx { - -using std::string; -using std::ostream; - - -InsetCharStyle::InsetCharStyle(BufferParams const & bp, string const s) - : InsetCollapsable(bp, Collapsed) -{ - params_.name = s; -} - - -InsetCharStyle::InsetCharStyle(BufferParams const & bp, - InsetLayout il) - : InsetCollapsable(bp, Collapsed) -{ - params_.name = il.name; - setLayout(il); -} - - -InsetCharStyle::InsetCharStyle(InsetCharStyle const & in) - : InsetCollapsable(in), params_(in.params_) -{} - - -Inset * InsetCharStyle::clone() const -{ - return new InsetCharStyle(*this); -} - - -bool InsetCharStyle::undefined() const -{ - return layout_.labelstring == from_utf8("UNDEFINED"); -} - - -void InsetCharStyle::setLayout(InsetLayout il) -{ - layout_ = il; -} - - -docstring const InsetCharStyle::editMessage() const -{ - return _("Opened CharStyle Inset"); -} - - -void InsetCharStyle::write(Buffer const & buf, ostream & os) const -{ - params_.write(os); - InsetCollapsable::write(buf, os); -} - - -void InsetCharStyle::read(Buffer const & buf, Lexer & lex) -{ - params_.read(lex); - InsetCollapsable::read(buf, lex); -} - - -bool InsetCharStyle::metrics(MetricsInfo & mi, Dimension & dim) const -{ - Font tmpfont = mi.base.font; - getDrawFont(mi.base.font); - mi.base.font.reduce(Font(Font::ALL_SANE)); - mi.base.font.realize(tmpfont); - bool changed = InsetCollapsable::metrics(mi, dim); - mi.base.font = tmpfont; - return changed; -} - - -void InsetCharStyle::draw(PainterInfo & pi, int x, int y) const -{ - setPosCache(pi, x, y); - - Font tmpfont = pi.base.font; - getDrawFont(pi.base.font); - // I don't understand why the above .reduce and .realize aren't - //needed, or even wanted, here. It just works. -- MV 10.04.2005 - InsetCollapsable::draw(pi, x, y); - pi.base.font = tmpfont; -} - - -void InsetCharStyle::getDrawFont(Font & font) const -{ - font = layout_.font; -} - - -void InsetCharStyle::doDispatch(Cursor & cur, FuncRequest & cmd) -{ - InsetCollapsable::doDispatch(cur, cmd); -} - - -bool InsetCharStyle::getStatus(Cursor & cur, FuncRequest const & cmd, - FuncStatus & status) const -{ - switch (cmd.action) { - // paragraph breaks not allowed in charstyle insets - case LFUN_BREAK_PARAGRAPH: - case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT: - case LFUN_BREAK_PARAGRAPH_SKIP: - status.enabled(false); - return true; - - default: - return InsetCollapsable::getStatus(cur, cmd, status); - } -} - - -int InsetCharStyle::plaintext(Buffer const & buf, odocstream & os, - OutputParams const & runparams) const -{ - return InsetText::plaintext(buf, os, runparams); -} - - -int InsetCharStyle::docbook(Buffer const & buf, odocstream & os, - OutputParams const & runparams) const -{ - ParagraphList::const_iterator beg = paragraphs().begin(); - ParagraphList::const_iterator par = paragraphs().begin(); - ParagraphList::const_iterator end = paragraphs().end(); - - if (!undefined()) - // FIXME UNICODE - sgml::openTag(os, layout_.latexname, - par->getID(buf, runparams) + layout_.latexparam); - - for (; par != end; ++par) { - par->simpleDocBookOnePar(buf, os, runparams, - outerFont(std::distance(beg, par), - paragraphs())); - } - - if (!undefined()) - sgml::closeTag(os, layout_.latexname); - - return 0; -} - - -void InsetCharStyle::textString(Buffer const & buf, odocstream & os) const -{ - os << paragraphs().begin()->asString(buf, true); -} - - -void InsetCharStyleParams::write(ostream & os) const -{ - os << "CharStyle " << name << "\n"; -} - - -void InsetCharStyleParams::read(Lexer & lex) -{ - while (lex.isOK()) { - lex.next(); - string token = lex.getString(); - - if (token == "CharStyle") { - lex.next(); - name = lex.getString(); - } - - // This is handled in Collapsable - else if (token == "status") { - lex.pushToken(token); - break; - } - } -} - - -} // namespace lyx Index: insets/InsetCollapsable.cpp =================================================================== --- insets/InsetCollapsable.cpp (revision 20022) +++ insets/InsetCollapsable.cpp (working copy) @@ -635,7 +635,7 @@ return Minimalistic; if (layout_.decoration == "conglomerate") return Conglomerate; - if (name() == from_ascii("CharStyle")) + if (name() == from_ascii("Flex")) return Conglomerate; return Classic; } @@ -676,7 +676,7 @@ void InsetCollapsable::validate(LaTeXFeatures & features) const { // Force inclusion of preamble snippet in layout file - features.addPreambleSnippet(layout_.preamble); + features.require(layout_.name); InsetText::validate(features); } Index: insets/InsetFlex.h =================================================================== --- insets/InsetFlex.h (revision 20022) +++ insets/InsetFlex.h (working copy) @@ -1,6 +1,6 @@ // -*- C++ -*- /** - * \file InsetCharStyle.h + * \file InsetFlex.h * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * @@ -10,8 +10,8 @@ * Full author contact details are available in file CREDITS. */ -#ifndef INSETCHARSTYLE_H -#define INSETCHARSTYLE_H +#ifndef INSETFLEX_H +#define INSETFLEX_H #include "InsetCollapsable.h" #include "TextClass.h" @@ -20,7 +20,7 @@ namespace lyx { -class InsetCharStyleParams { +class InsetFlexParams { public: /// void write(std::ostream & os) const; @@ -31,17 +31,15 @@ }; -/** The CharStyle inset, also XML short element +/** The Flex inset, e.g., CharStyle, Custom inset or XML short element */ -class InsetCharStyle : public InsetCollapsable { +class InsetFlex : public InsetCollapsable { public: - /// Construct an undefined character style - InsetCharStyle(BufferParams const &, std::string const); /// - InsetCharStyle(BufferParams const &, InsetLayout); + InsetFlex(BufferParams const &, InsetLayout); /// - docstring name() const { return from_ascii("CharStyle"); } + docstring name() const { return from_ascii("Flex"); } /// Is this character style defined in the document's textclass? /// May be wrong after textclass change or paste from another document bool undefined() const; @@ -50,7 +48,7 @@ /// virtual docstring const editMessage() const; /// - Inset::Code lyxCode() const { return Inset::CHARSTYLE_CODE; } + Inset::Code lyxCode() const { return Inset::FLEX_CODE; } /// void write(Buffer const &, std::ostream &) const; /// @@ -74,24 +72,24 @@ virtual void textString(Buffer const &, odocstream &) const; /// - InsetCharStyleParams const & params() const { return params_; } + InsetFlexParams const & params() const { return params_; } /// should paragraph indendation be ommitted in any case? bool neverIndent(Buffer const &) const { return true; } protected: - InsetCharStyle(InsetCharStyle const &); + InsetFlex(InsetFlex const &); virtual void doDispatch(Cursor & cur, FuncRequest & cmd); /// bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const; private: - friend class InsetCharStyleParams; + friend class InsetFlexParams; virtual Inset * clone() const; /// - InsetCharStyleParams params_; + InsetFlexParams params_; }; Index: TextClass.h =================================================================== --- TextClass.h (revision 20022) +++ TextClass.h (working copy) @@ -46,9 +46,6 @@ }; -/// List of semantically defined character style insets -typedef std::vector<InsetLayout> CharStyles; - /// List of inset layouts typedef std::map<docstring, InsetLayout> InsetLayouts; @@ -115,8 +112,6 @@ FloatList const & floats() const; /// The Counters present in this document class. Counters & counters() const; - /// CharStyles of this doc class - CharStyles & charstyles() const { return charstylelist_; }; /// Inset layouts of this doc class InsetLayouts & insetlayouts() const { return insetlayoutlist_; }; /// @@ -254,8 +249,6 @@ /// Paragraph styles used in this layout LayoutList layoutlist_; - /// CharStyles available to this layout - mutable CharStyles charstylelist_; /// Input layouts available to this layout mutable InsetLayouts insetlayoutlist_; Index: Makefile.am =================================================================== --- Makefile.am (revision 20022) +++ Makefile.am (working copy) @@ -494,8 +494,8 @@ insets/InsetBranch.h \ insets/InsetCaption.cpp \ insets/InsetCaption.h \ - insets/InsetCharStyle.cpp \ - insets/InsetCharStyle.h \ + insets/InsetFlex.cpp \ + insets/InsetFlex.h \ insets/InsetCitation.cpp \ insets/InsetCitation.h \ insets/InsetCollapsable.cpp \ Index: factory.cpp =================================================================== --- factory.cpp (revision 20022) +++ factory.cpp (working copy) @@ -26,7 +26,7 @@ #include "insets/InsetBibtex.h" #include "insets/InsetCaption.h" #include "insets/InsetCitation.h" -#include "insets/InsetCharStyle.h" +#include "insets/InsetFlex.h" #include "insets/InsetEnvironment.h" #include "insets/InsetERT.h" #include "insets/InsetListings.h" @@ -106,7 +106,7 @@ string s = cmd.getArg(0); TextClass tclass = params.getTextClass(); InsetLayout il = tclass.insetlayout(from_utf8(s)); - return new InsetCharStyle(params, il); + return new InsetFlex(params, il); } case LFUN_NOTE_INSERT: { @@ -474,7 +474,7 @@ lex.next(); string s = lex.getString(); InsetLayout il = tclass.insetlayout(from_utf8(s)); - inset.reset(new InsetCharStyle(buf.params(), il)); + inset.reset(new InsetFlex(buf.params(), il)); } else if (tmptok == "Branch") { inset.reset(new InsetBranch(buf.params(), InsetBranchParams())); Index: CutAndPaste.cpp =================================================================== --- CutAndPaste.cpp (revision 20022) +++ CutAndPaste.cpp (working copy) @@ -38,7 +38,7 @@ #include "ParIterator.h" #include "Undo.h" -#include "insets/InsetCharStyle.h" +#include "insets/InsetFlex.h" #include "insets/InsetTabular.h" #include "mathed/MathData.h" @@ -442,24 +442,24 @@ // character styles InsetIterator const i_end = inset_iterator_end(in); for (InsetIterator it = inset_iterator_begin(in); it != i_end; ++it) { - if (it->lyxCode() == Inset::CHARSTYLE_CODE) { - InsetCharStyle & inset = - static_cast<InsetCharStyle &>(*it); + if (it->lyxCode() == Inset::FLEX_CODE) { + InsetFlex & inset = + static_cast<InsetFlex &>(*it); string const name = inset.params().name; InsetLayout const il = tclass2.insetlayout(from_utf8(name)); inset.setLayout(il); if (il.labelstring == from_utf8("UNDEFINED")) { - // The character style is undefined in tclass2 + // The flex inset is undefined in tclass2 docstring const s = bformat(_( - "Character style %1$s is " + "Flex inset %1$s is " "undefined because of class " "conversion from\n%2$s to %3$s"), from_utf8(name), from_utf8(tclass1.name()), from_utf8(tclass2.name())); // To warn the user that something had to be done. errorlist.push_back(ErrorItem( - _("Undefined character style"), + _("Undefined flex inset"), s, it.paragraph().id(), it.pos(), it.pos() + 1)); } } Index: LaTeXFeatures.cpp =================================================================== --- LaTeXFeatures.cpp (revision 20022) +++ LaTeXFeatures.cpp (working copy) @@ -719,11 +719,13 @@ tcpreamble << tclass[*cit]->preamble(); } - CharStyles::iterator cs = tclass.charstyles().begin(); - CharStyles::iterator csend = tclass.charstyles().end(); - for (; cs != csend; ++cs) { - if (isRequired(cs->name)) - tcpreamble << cs->preamble; + InsetLayouts const & insetlayouts = tclass.insetlayouts(); + InsetLayouts::const_iterator cit2 = insetlayouts.begin(); + InsetLayouts::const_iterator end2 = insetlayouts.end(); + for (; cit2 != end2; ++cit2) { + if (isRequired(to_utf8(cit2->first))) { + tcpreamble << from_utf8(cit2->second.preamble); + } } return tcpreamble.str(); Index: Text3.cpp =================================================================== --- Text3.cpp (revision 20022) +++ Text3.cpp (working copy) @@ -1681,7 +1681,7 @@ code = Inset::NOTE_CODE; break; case LFUN_CHARSTYLE_INSERT: - code = Inset::CHARSTYLE_CODE; + code = Inset::FLEX_CODE; if (cur.buffer().params().getTextClass().insetlayouts().empty()) enable = false; break;