mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-11 11:08:41 +00:00
Prepare for inset configurability
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19498 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
77cfe019f2
commit
2bd998c29e
@ -19,6 +19,7 @@ Style Standard
|
||||
AlignPossible Block, Left, Right, Center
|
||||
End
|
||||
|
||||
Input stdinsets.inc
|
||||
Input stdlists.inc
|
||||
Input stdcounters.inc
|
||||
Input stdfloats.inc
|
||||
|
@ -37,6 +37,7 @@ Style Standard
|
||||
End
|
||||
|
||||
|
||||
Input stdinsets.inc
|
||||
Input stdlists.inc
|
||||
Input stdsections.inc
|
||||
Input stdstarsections.inc
|
||||
|
78
lib/layouts/stdinsets.inc
Normal file
78
lib/layouts/stdinsets.inc
Normal file
@ -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
|
||||
|
||||
|
@ -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(), """, "\"");
|
||||
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
|
||||
{
|
||||
|
@ -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_;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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_;
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user