From 2bd998c29eab19692e976a086b02174cc924b376 Mon Sep 17 00:00:00 2001 From: Martin Vermeer Date: Mon, 13 Aug 2007 12:13:17 +0000 Subject: [PATCH] Prepare for inset configurability git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19498 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/layouts/scrclass.inc | 1 + lib/layouts/stdclass.inc | 1 + lib/layouts/stdinsets.inc | 78 ++++++++++++++++++++++ src/TextClass.cpp | 112 ++++++++++++++++++++++++++++++++ src/TextClass.h | 24 +++++++ src/insets/Inset.cpp | 8 +++ src/insets/Inset.h | 3 + src/insets/InsetCollapsable.cpp | 17 +++-- src/insets/InsetCollapsable.h | 10 ++- src/insets/InsetFoot.cpp | 6 +- src/insets/InsetFootlike.cpp | 17 +---- src/insets/InsetMarginal.cpp | 6 +- src/insets/InsetNote.cpp | 50 +++++--------- src/insets/InsetNote.h | 2 +- 14 files changed, 270 insertions(+), 65 deletions(-) create mode 100644 lib/layouts/stdinsets.inc diff --git a/lib/layouts/scrclass.inc b/lib/layouts/scrclass.inc index 34b54f0995..b8dd1d5835 100644 --- a/lib/layouts/scrclass.inc +++ b/lib/layouts/scrclass.inc @@ -19,6 +19,7 @@ Style Standard AlignPossible Block, Left, Right, Center End +Input stdinsets.inc Input stdlists.inc Input stdcounters.inc Input stdfloats.inc diff --git a/lib/layouts/stdclass.inc b/lib/layouts/stdclass.inc index 4e375a813d..80e1ad0a2e 100644 --- a/lib/layouts/stdclass.inc +++ b/lib/layouts/stdclass.inc @@ -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 index 0000000000..178d67e498 --- /dev/null +++ b/lib/layouts/stdinsets.inc @@ -0,0 +1,78 @@ +# Textclass definition file for LaTeX. +# Author : Martin vermeer +# 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 + + diff --git a/src/TextClass.cpp b/src/TextClass.cpp index ffbb600a01..9d589ac678 100644 --- a/src/TextClass.cpp +++ b/src/TextClass.cpp @@ -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(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(), """, "\""); + 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 { diff --git a/src/TextClass.h b/src/TextClass.h index b5ea3a38b5..8f0c8cf1cb 100644 --- a/src/TextClass.h +++ b/src/TextClass.h @@ -17,6 +17,7 @@ #include #include +#include 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 CharStyles; +/// List of inset layouts +typedef std::map 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_; diff --git a/src/insets/Inset.cpp b/src/insets/Inset.cpp index 8664c5f8d9..472c00daa2 100644 --- a/src/insets/Inset.cpp +++ b/src/insets/Inset.cpp @@ -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); diff --git a/src/insets/Inset.h b/src/insets/Inset.h index 982d1306db..614342084d 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -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 diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp index bc1b8df9c6..6e421d31c0 100644 --- a/src/insets/InsetCollapsable.cpp +++ b/src/insets/InsetCollapsable.cpp @@ -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 diff --git a/src/insets/InsetCollapsable.h b/src/insets/InsetCollapsable.h index 1ffd52a325..2a31b1453f 100644 --- a/src/insets/InsetCollapsable.h +++ b/src/insets/InsetCollapsable.h @@ -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_; diff --git a/src/insets/InsetFoot.cpp b/src/insets/InsetFoot.cpp index c9c091ddeb..5bd2a9d044 100644 --- a/src/insets/InsetFoot.cpp +++ b/src/insets/InsetFoot.cpp @@ -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 InsetFoot::doClone() const diff --git a/src/insets/InsetFootlike.cpp b/src/insets/InsetFootlike.cpp index 2f6b8f5b6d..fff8555d90 100644 --- a/src/insets/InsetFootlike.cpp +++ b/src/insets/InsetFootlike.cpp @@ -17,29 +17,16 @@ #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 diff --git a/src/insets/InsetMarginal.cpp b/src/insets/InsetMarginal.cpp index be61f468ea..27e9a0a1a0 100644 --- a/src/insets/InsetMarginal.cpp +++ b/src/insets/InsetMarginal.cpp @@ -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 InsetMarginal::doClone() const diff --git a/src/insets/InsetNote.cpp b/src/insets/InsetNote.cpp index 9324af15e5..28c8048184 100644 --- a/src/insets/InsetNote.cpp +++ b/src/insets/InsetNote.cpp @@ -17,7 +17,11 @@ #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; diff --git a/src/insets/InsetNote.h b/src/insets/InsetNote.h index 91d5771ca2..ddddeb652e 100644 --- a/src/insets/InsetNote.h +++ b/src/insets/InsetNote.h @@ -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; /// -- 2.39.2