]> git.lyx.org Git - lyx.git/blob - src/insets/insetmarginal.C
546a36c124f93900c37453fa0e4ff792e14974ea
[lyx.git] / src / insets / insetmarginal.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 1998 The LyX Team.
7  *
8  * ======================================================
9  */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "insetmarginal.h"
18 #include "gettext.h"
19 #include "lyxfont.h"
20 #include "BufferView.h"
21 #include "Painter.h"
22 #include "lyxtext.h"
23 #include "support/LOstream.h"
24
25 using std::ostream;
26 using std::endl;
27
28 InsetMarginal::InsetMarginal()
29         : InsetCollapsable()
30 {
31     setLabel(_("margin"));
32     LyXFont font(LyXFont::ALL_SANE);
33     font.decSize();
34     font.decSize();
35     font.setColor(LColor::footnote);
36     setLabelFont(font);
37     setAutoCollapse(false);
38     setInsetName("Marginal");
39 }
40
41
42 void InsetMarginal::Write(Buffer const * buf, ostream & os) const
43 {
44     os << getInsetName() << "\n";
45     InsetCollapsable::Write(buf, os);
46 }
47
48
49 Inset * InsetMarginal::Clone() const
50 {
51     InsetMarginal * result = new InsetMarginal;
52     result->init(this);
53     
54     result->collapsed = collapsed;
55     return result;
56 }
57
58
59 char const * InsetMarginal::EditMessage() const
60 {
61     return _("Opened Marginal Note Inset");
62 }
63
64
65 int InsetMarginal::Latex(Buffer const * buf,
66                          ostream & os, bool fragile, bool fp) const
67 {
68     os << "\\marginpar{%\n";
69     
70     int i = InsetText::Latex(buf, os, fragile, fp);
71     os << "}%\n";
72     
73     return i + 2;
74 }
75
76
77 bool InsetMarginal::InsertInset(BufferView * bv, Inset * inset)
78 {
79     if (!InsertInsetAllowed(inset))
80         return false;
81
82     return InsetText::InsertInset(bv, inset);
83 }
84
85
86 bool InsetMarginal::InsertInsetAllowed(Inset * inset) const
87 {
88     if ((inset->LyxCode() == Inset::FOOT_CODE) ||
89         (inset->LyxCode() == Inset::MARGIN_CODE)) {
90         return false;
91     }
92     return true;
93 }
94
95
96 LyXFont InsetMarginal::GetDrawFont(BufferView * bv,
97                                    LyXParagraph * p, int pos) const
98 {
99     LyXFont fn = getLyXText(bv)->GetFont(bv->buffer(), p, pos);
100     fn.decSize().decSize();
101     return fn;
102 }