]> git.lyx.org Git - features.git/commitdiff
Prepare for inset configurability
authorMartin Vermeer <martin.vermeer@hut.fi>
Mon, 13 Aug 2007 12:13:17 +0000 (12:13 +0000)
committerMartin Vermeer <martin.vermeer@hut.fi>
Mon, 13 Aug 2007 12:13:17 +0000 (12:13 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19498 a592a061-630c-0410-9148-cb99ea01b6c8

14 files changed:
lib/layouts/scrclass.inc
lib/layouts/stdclass.inc
lib/layouts/stdinsets.inc [new file with mode: 0644]
src/TextClass.cpp
src/TextClass.h
src/insets/Inset.cpp
src/insets/Inset.h
src/insets/InsetCollapsable.cpp
src/insets/InsetCollapsable.h
src/insets/InsetFoot.cpp
src/insets/InsetFootlike.cpp
src/insets/InsetMarginal.cpp
src/insets/InsetNote.cpp
src/insets/InsetNote.h

index 34b54f09952b163454a3bdbc550bcb1129710b64..b8dd1d5835314c8573be26d057b163a6e6f0ce01 100644 (file)
@@ -19,6 +19,7 @@ Style Standard
        AlignPossible         Block, Left, Right, Center
 End
 
+Input stdinsets.inc
 Input stdlists.inc
 Input stdcounters.inc
 Input stdfloats.inc
index 4e375a813d0cf394cdf8cecbff7e153bc4487a30..80e1ad0a2ee31bb1e9da446c1ccc941dc1f502b2 100644 (file)
@@ -37,6 +37,7 @@ Style Standard
 End
 
 
+Input stdinsets.inc
 Input stdlists.inc
 Input stdsections.inc
 Input stdstarsections.inc
diff --git a/lib/layouts/stdinsets.inc b/lib/layouts/stdinsets.inc
new file mode 100644 (file)
index 0000000..178d67e
--- /dev/null
@@ -0,0 +1,78 @@
+# Textclass definition file for LaTeX.
+# Author : Martin vermeer <amrtin.vermeer@hut.fi>
+# Inset layouts definition
+
+Format 2
+
+InsetLayout Marginal
+       LabelString           margin
+       LatexType             command
+       LatexName             marginpar
+       LabelFont
+         Color               Red
+         Size                Small
+       EndFont
+End
+
+InsetLayout Foot
+       LabelString           foot
+       LatexType             command
+       LatexName             footnote
+       LabelFont
+         Color               Green
+         Size                Small
+       EndFont
+End
+
+InsetLayout Note:Comment
+       LabelString           comment
+       LatexType             environment
+       LatexName             comment
+       LabelFont
+         Color               Magenta
+         Size                Small
+       EndFont
+End
+
+
+InsetLayout Note:Note
+       LabelString           note
+       LatexType             command
+       LatexName             note
+       LabelFont
+         Color               Blue
+         Size                Small
+       EndFont
+End
+
+InsetLayout Note:Greyedout
+       LabelString           greyedout
+       LatexType             command
+       LatexName             greyedout
+       LabelFont
+         Color               Red
+         Size                Small
+       EndFont
+End
+
+InsetLayout Note:Framed
+       LabelString           framed
+       LatexType             command
+       LatexName             framed
+       LabelFont
+         Color               Red
+         Size                Small
+       EndFont
+End
+
+InsetLayout Note:Shaded
+       LabelString           shaded
+       LatexType             command
+       LatexName             shaded
+       LabelFont
+         Color               Red
+         Size                Small
+       EndFont
+End
+
+
index ffbb600a01e676ace5c8ca849bb59f65233ffaa9..9d589ac6780d512463bc9cab71d2c18c2ae70e0e 100644 (file)
@@ -150,6 +150,7 @@ enum TextClassTags {
        TC_STYLE,
        TC_DEFAULTSTYLE,
        TC_CHARSTYLE,
+       TC_INSETLAYOUT,
        TC_ENVIRONMENT,
        TC_NOSTYLE,
        TC_COLUMNS,
@@ -192,6 +193,7 @@ bool TextClass::read(FileName const & filename, bool merge)
                { "float",           TC_FLOAT },
                { "format",          TC_FORMAT },
                { "input",           TC_INPUT },
+               { "insetlayout",     TC_INSETLAYOUT },
                { "leftmargin",      TC_LEFTMARGIN },
                { "nofloat",         TC_NOFLOAT },
                { "nostyle",         TC_NOSTYLE },
@@ -411,6 +413,12 @@ bool TextClass::read(FileName const & filename, bool merge)
                                readCharStyle(lexrc, name);
                        }
                        break;
+               case TC_INSETLAYOUT:
+                       if (lexrc.next()) {
+                               docstring const name = subst(lexrc.getDocString(), '_', ' ');
+                               readInsetLayout(lexrc, name);
+                       }
+                       break;
                case TC_FLOAT:
                        readFloat(lexrc);
                        break;
@@ -606,6 +614,19 @@ enum CharStyleTags {
 };
 
 
+enum InsetLayoutTags {
+       IL_FONT = 1,
+       IL_LABELFONT,
+       IL_LABELSTRING,
+       IL_LATEXTYPE,
+       IL_LATEXNAME,
+       IL_LATEXPARAM,
+       IL_PREAMBLE,
+       IL_END
+};
+
+
+
 void TextClass::readCharStyle(Lexer & lexrc, string const & name)
 {
        keyword_item elementTags[] = {
@@ -683,6 +704,92 @@ void TextClass::readCharStyle(Lexer & lexrc, string const & name)
 }
 
 
+void TextClass::readInsetLayout(Lexer & lexrc, docstring const & name)
+{
+       keyword_item elementTags[] = {
+               { "end", IL_END },
+               { "font", IL_FONT },
+               { "labelfont", IL_LABELFONT },
+               { "labelstring", IL_LABELSTRING },
+               { "latexname", IL_LATEXNAME },
+               { "latexparam", IL_LATEXPARAM },
+               { "latextype", IL_LATEXTYPE },
+               { "preamble", IL_PREAMBLE}
+       };
+
+       lexrc.pushTable(elementTags, IL_END);
+
+       docstring labelstring;
+       string latextype;
+       string latexname;
+       string latexparam;
+       Font font(Font::ALL_INHERIT);
+       Font labelfont(Font::ALL_INHERIT);
+       string preamble;
+
+       bool getout = false;
+       while (!getout && lexrc.isOK()) {
+               int le = lexrc.lex();
+               switch (le) {
+               case Lexer::LEX_UNDEF:
+                       lexrc.printError("Unknown ClassOption tag `$$Token'");
+                       continue;
+               default: break;
+               }
+               switch (static_cast<InsetLayoutTags>(le)) {
+               case IL_LATEXTYPE:
+                       lexrc.next();
+                       latextype = lexrc.getString();
+                       break;
+               case IL_LABELSTRING:
+                       lexrc.next();
+                       labelstring = lexrc.getDocString();
+                       break;
+               case IL_LATEXNAME:
+                       lexrc.next();
+                       latexname = lexrc.getString();
+                       break;
+               case IL_LATEXPARAM:
+                       lexrc.next();
+                       latexparam = subst(lexrc.getString(), "&quot;", "\"");
+                       break;
+               case IL_LABELFONT:
+                       labelfont.lyxRead(lexrc);
+                       labelfont.realize(defaultfont());
+                       break;
+               case IL_FONT:
+                       font.lyxRead(lexrc);
+                       font.realize(defaultfont());
+                       labelfont = font;
+                       break;
+               case IL_PREAMBLE:
+                       preamble = lexrc.getLongString("EndPreamble");
+                       break;
+               case IL_END:
+                       getout = true;
+                       break;
+               }
+       }
+
+       //
+       // Here add element to list if getout == true
+       if (getout) {
+               InsetLayout il;
+               il.labelstring = labelstring;
+               il.latextype = latextype;
+               il.latexname = latexname;
+               il.latexparam = latexparam;
+               il.font = font;
+               il.labelfont = labelfont;
+               il.preamble = from_utf8(preamble);
+               insetlayoutlist_[name] = il;
+       }
+
+       lexrc.popTable();
+}
+
+
+
 enum FloatTags {
        FT_TYPE = 1,
        FT_NAME,
@@ -955,6 +1062,11 @@ Counters & TextClass::counters() const
        return *ctrs_.get();
 }
 
+InsetLayout const & TextClass::insetlayout(docstring const & name) const 
+{
+       return insetlayoutlist_[name]; 
+}
+
 
 CharStyles::iterator TextClass::charstyle(string const & s) const
 {
index b5ea3a38b571f19da53ddb269dc37b805eafc6f2..8f0c8cf1cb7932ff24121ad55c8051c09dd5acf9 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <vector>
 #include <set>
+#include <map>
 
 namespace lyx {
 
@@ -40,9 +41,23 @@ public:
 };
 
 
+class InsetLayout {
+public:
+       docstring labelstring;
+       std::string latextype;
+       std::string latexname;
+       std::string latexparam;
+       Font font;
+       Font labelfont;
+       docstring preamble;
+};
+
+
 /// List of semantically defined character style insets
 typedef std::vector<CharStyle> CharStyles;
 
+/// List of inset layouts
+typedef std::map<docstring, InsetLayout> InsetLayouts;
 
 /// Stores the layout specification of a LyX document class.
 class TextClass {
@@ -79,6 +94,8 @@ public:
        ///
        void readCharStyle(Lexer &, std::string const &);
        ///
+       void readInsetLayout(Lexer &, docstring const &);
+       ///
        void readFloat(Lexer &);
        ///
        void readCounter(Lexer &);
@@ -101,6 +118,8 @@ public:
        Counters & counters() const;
        /// CharStyles of this doc class
        CharStyles & charstyles() const { return charstylelist_; };
+       ///  Inset layouts of this doc class
+       InsetLayout const & insetlayout(docstring const & name) const;
        /// Retrieve element of name s:
        CharStyles::iterator charstyle(std::string const & s) const;
        ///
@@ -110,6 +129,8 @@ public:
        ///
        std::string const & name() const;
        ///
+       docstring const & labelstring() const;
+       ///
        std::string const & latexname() const;
        ///
        std::string const & description() const;
@@ -229,6 +250,9 @@ private:
        /// CharStyles available to this layout
        mutable CharStyles charstylelist_;
 
+       /// Input layouts available to this layout
+       mutable InsetLayouts insetlayoutlist_;
+
        /// available types of float, eg. figure, algorithm.
        boost::shared_ptr<FloatList> floatlist_;
 
index 8664c5f8d9b410aed637c6b828da879b393d0802..472c00daa2c615bcb64761832a7ae74d4bfe876d 100644 (file)
@@ -17,6 +17,7 @@
 #include "Inset.h"
 
 #include "Buffer.h"
+#include "BufferParams.h"
 #include "BufferView.h"
 #include "Color.h"
 #include "CoordCache.h"
@@ -29,6 +30,7 @@
 #include "FuncStatus.h"
 #include "gettext.h"
 #include "Text.h"
+#include "TextClass.h"
 #include "MetricsInfo.h"
 #include "MetricsInfo.h"
 
@@ -344,6 +346,12 @@ bool Inset::covers(BufferView const & bv, int x, int y) const
 }
 
 
+InsetLayout const & Inset::getLayout(BufferParams const & bp) const
+{
+       return bp.getTextClass().insetlayout(name());  
+}
+
+
 void Inset::dump() const
 {
        Buffer buf("foo", 1);
index 982d1306dba93a44ffa157ff8217777698d79729..614342084d455bdfabdafc4ba5f8dd81c9378292 100644 (file)
@@ -33,6 +33,7 @@ class ParConstIterator;
 class CursorSlice;
 class FuncRequest;
 class FuncStatus;
+class InsetLayout;
 class InsetMath;
 class InsetText;
 class LaTeXFeatures;
@@ -379,6 +380,8 @@ public:
 
        ///
        virtual docstring name() const { return from_ascii("unknown"); }
+       ///
+       virtual InsetLayout const & getLayout(BufferParams const & bp) const;
        /// used to toggle insets
        /// is the inset open?
        /// should this inset be handled like a normal charater
index bc1b8df9c6ba8733e7e54196543b2193034442e2..6e421d31c073dc3a42f8d27666635c0ce6ce1cdc 100644 (file)
@@ -63,7 +63,7 @@ InsetCollapsable::InsetCollapsable
 
 InsetCollapsable::InsetCollapsable(InsetCollapsable const & rhs)
        : InsetText(rhs),
-               labelfont_(rhs.labelfont_),
+               layout_(rhs.layout_),
                button_dim(rhs.button_dim),
                topx(rhs.topx),
                topbaseline(rhs.topbaseline),
@@ -78,6 +78,13 @@ InsetCollapsable::InsetCollapsable(InsetCollapsable const & rhs)
 }
 
 
+void  InsetCollapsable::setLayout(BufferParams const & bp)
+{
+       setLabelFont(getLayout(bp).labelfont);
+       setLabel(getLayout(bp).labelstring);
+}
+
+
 void InsetCollapsable::write(Buffer const & buf, ostream & os) const
 {
        os << "status ";
@@ -141,7 +148,7 @@ void InsetCollapsable::read(Buffer const & buf, Lexer & lex)
 Dimension InsetCollapsable::dimensionCollapsed() const
 {
        Dimension dim;
-       theFontMetrics(labelfont_).buttonText(
+       theFontMetrics(layout_.labelfont).buttonText(
                label, dim.wid, dim.asc, dim.des);
        return dim;
 }
@@ -206,7 +213,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
                button_dim.y1 = top;
                button_dim.y2 = top + dimc.height();
 
-               pi.pain.buttonText(xx, top + dimc.asc, label, labelfont_, mouse_hover_);
+               pi.pain.buttonText(xx, top + dimc.asc, label, layout_.labelfont, mouse_hover_);
 
                if (status() == Open) {
                        int textx, texty;
@@ -448,9 +455,9 @@ void InsetCollapsable::setStatus(Cursor & cur, CollapseStatus status)
 }
 
 
-void InsetCollapsable::setLabelFont(Font & font)
+void InsetCollapsable::setLabelFont(Font const & font)
 {
-       labelfont_ = font;
+       layout_.labelfont = font;
 }
 
 docstring InsetCollapsable::floatName(string const & type, BufferParams const & bp) const
index 1ffd52a325c6ad1abd311124a28ba6ad73ea503a..2a31b1453fe4828a8bd404f1d54344046fb38471 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "Inset.h"
 #include "InsetText.h"
+#include "TextClass.h"
 
 #include "Box.h"
 #include "Font.h"
@@ -27,6 +28,7 @@ namespace lyx {
 class Text;
 class Paragraph;
 class CursorSlice;
+class InsetLayout;
 
 namespace frontend { class Painter; }
 
@@ -46,6 +48,8 @@ public:
        ///
        docstring name() const { return from_ascii("Collapsable"); }
        ///
+       void setLayout(BufferParams const &);
+       ///
        void read(Buffer const &, Lexer &);
        ///
        void write(Buffer const &, std::ostream &) const;
@@ -71,7 +75,7 @@ public:
        ///
        virtual void setButtonLabel() {}
        ///
-       void setLabelFont(Font & f);
+       void setLabelFont(Font const & f);
        ///
        bool isOpen() const { return status_ == Open || status_ == Inlined; }
        ///
@@ -104,8 +108,6 @@ protected:
        docstring floatName(std::string const & type, BufferParams const &) const;
 
 protected:
-       ///
-       Font labelfont_;
        ///
        mutable Box button_dim;
        ///
@@ -114,6 +116,8 @@ protected:
        mutable int topbaseline;
        ///
        mutable docstring label;
+       ///
+       mutable InsetLayout layout_;
 private:
        ///
        mutable CollapseStatus status_;
index c9c091ddeb490bb12776e0bcc4675c0e016f1f71..5bd2a9d044b9b3646b90028dce776f41d46418f5 100644 (file)
@@ -32,15 +32,13 @@ using std::ostream;
 InsetFoot::InsetFoot(BufferParams const & bp)
        : InsetFootlike(bp)
 {
-       setLabel(_("foot"));
+       setLayout(bp);
 }
 
 
 InsetFoot::InsetFoot(InsetFoot const & in)
        : InsetFootlike(in)
-{
-       setLabel(_("foot"));
-}
+{}
 
 
 auto_ptr<Inset> InsetFoot::doClone() const
index 2f6b8f5b6d6556b51bb7366d019f163cfec24582..fff8555d900f725dc27ad7e65dce5175089e6e08 100644 (file)
 #include "BufferParams.h"
 #include "MetricsInfo.h"
 
-
 namespace lyx {
 
 InsetFootlike::InsetFootlike(BufferParams const & bp)
        : InsetCollapsable(bp)
-{
-       Font font(Font::ALL_SANE);
-       font.decSize();
-       font.decSize();
-       font.setColor(Color::collapsable);
-       setLabelFont(font);
-}
+{}
 
 
 InsetFootlike::InsetFootlike(InsetFootlike const & in)
        : InsetCollapsable(in)
-{
-       Font font(Font::ALL_SANE);
-       font.decSize();
-       font.decSize();
-       font.setColor(Color::collapsable);
-       setLabelFont(font);
-}
+{}
 
 
 bool InsetFootlike::metrics(MetricsInfo & mi, Dimension & dim) const
index be61f468eab1363a20d6d4bdf129e928166c8044..27e9a0a1a06c48cc85d31d35402786320255ab47 100644 (file)
@@ -30,15 +30,13 @@ using std::ostream;
 InsetMarginal::InsetMarginal(BufferParams const & bp)
        : InsetFootlike(bp)
 {
-       setLabel(_("margin"));
+       setLayout(bp);
 }
 
 
 InsetMarginal::InsetMarginal(InsetMarginal const & in)
        : InsetFootlike(in)
-{
-       setLabel(_("margin"));
-}
+{}
 
 
 auto_ptr<Inset> InsetMarginal::doClone() const
index 9324af15e504b198aca4314d51fef3f46306a272..28c804818493b91ab069cdcd72c6692bcb013a86 100644 (file)
 #include "Buffer.h"
 #include "BufferParams.h"
 #include "BufferView.h"
+<<<<<<< .mine
+#include "BufferParams.h"
+=======
 #include "Counters.h"
+>>>>>>> .r19497
 #include "Cursor.h"
 #include "debug.h"
 #include "DispatchResult.h"
@@ -111,24 +115,19 @@ void InsetNoteParams::read(Lexer & lex)
 }
 
 
-void InsetNote::init()
-{
-       setButtonLabel();
-}
-
-
 InsetNote::InsetNote(BufferParams const & bp, string const & label)
        : InsetCollapsable(bp)
 {
        params_.type = notetranslator().find(label);
-       init();
+       setLayout(bp);
+       setButtonLabel();
 }
 
 
 InsetNote::InsetNote(InsetNote const & in)
        : InsetCollapsable(in), params_(in.params_)
 {
-       init();
+       setButtonLabel();
 }
 
 
@@ -150,6 +149,12 @@ docstring const InsetNote::editMessage() const
 }
 
 
+docstring InsetNote::name() const 
+{
+       return from_ascii(string("Note") + string(":") + string(notetranslator().find(params_.type)));
+}
+
+
 Inset::DisplayType InsetNote::display() const
 {
        switch (params_.type) {
@@ -173,6 +178,7 @@ void InsetNote::read(Buffer const & buf, Lexer & lex)
 {
        params_.read(lex);
        InsetCollapsable::read(buf, lex);
+       setLayout(buf.params());
        setButtonLabel();
 }
 
@@ -181,31 +187,7 @@ void InsetNote::setButtonLabel()
 {
        docstring const label = notetranslator_loc().find(params_.type);
        setLabel(label);
-
-       Font font(Font::ALL_SANE);
-       font.decSize();
-       font.decSize();
-
-       Color_color c;
-       switch (params_.type) {
-       case InsetNoteParams::Note:
-               c = Color::note;
-               break;
-       case InsetNoteParams::Comment:
-               c = Color::comment;
-               break;
-       case InsetNoteParams::Greyedout:
-               c = Color::greyedout;
-               break;
-       case InsetNoteParams::Framed:
-               c = Color::greyedout;
-               break;
-       case InsetNoteParams::Shaded:
-               c = Color::greyedout;
-               break;
-       }
-       font.setColor(c);
-       setLabelFont(font);
+       setLabelFont(layout_.labelfont);
 }
 
 
@@ -246,6 +228,8 @@ void InsetNote::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_INSET_MODIFY:
                InsetNoteMailer::string2params(to_utf8(cmd.argument()), params_);
+               // get a bp from cur:
+               setLayout(cur.buffer().params());
                setButtonLabel();
                break;
 
index 91d5771ca2069633d13d023c8e43058547ae4305..ddddeb652e8c812832578a3b54441dfca417ee46 100644 (file)
@@ -52,7 +52,7 @@ public:
        ///
        Inset::Code lyxCode() const { return Inset::NOTE_CODE; }
        ///
-       docstring name() const { return from_ascii("Note"); }
+       docstring name() const;
        /// framed and shaded notes are displayed
        virtual DisplayType display() const;
        ///