]> git.lyx.org Git - lyx.git/blob - src/insets/InsetMarginal.cpp
748ae3eca511b6e451a72f978971d997f502b6ca
[lyx.git] / src / insets / InsetMarginal.cpp
1 /**
2  * \file InsetMarginal.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Jürgen Vigna
7  * \author Lars Gullik Bjønnes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "InsetMarginal.h"
15
16 #include "Buffer.h"
17 #include "BufferParams.h"
18 #include "OutputParams.h"
19 #include "TocBackend.h"
20
21 #include "support/docstream.h"
22 #include "support/gettext.h"
23
24 #include <ostream>
25
26
27 namespace lyx {
28
29
30 InsetMarginal::InsetMarginal(Buffer const & buf)
31         : InsetFootlike(buf)
32 {}
33
34
35 docstring InsetMarginal::editMessage() const
36 {
37         return _("Opened Marginal Note Inset");
38 }
39
40
41 docstring InsetMarginal::toolTip(BufferView const & bv, int x, int y) const
42 {
43         docstring default_tip = InsetCollapsable::toolTip(bv, x, y);
44         OutputParams rp(&buffer().params().encoding());
45         odocstringstream ods;
46         InsetText::plaintext(ods, rp);
47         docstring margin_tip = ods.str();
48         // shorten it if necessary
49         if (margin_tip.size() > 200)
50                 margin_tip = margin_tip.substr(0, 200) + "...";
51         if (!isOpen() && !margin_tip.empty())
52                 return margin_tip + '\n' + default_tip;
53         return default_tip;
54 }
55
56
57 int InsetMarginal::latex(odocstream & os, OutputParams const & runparams) const
58 {
59         os << "%\n\\marginpar{";
60         int const i = InsetText::latex(os, runparams);
61         os << "%\n}";
62         return i + 2;
63 }
64
65
66 int InsetMarginal::plaintext(odocstream & os,
67                              OutputParams const & runparams) const
68 {
69         os << '[' << buffer().B_("margin") << ":\n";
70         InsetText::plaintext(os, runparams);
71         os << "\n]";
72
73         return PLAINTEXT_NEWLINE + 1; // one char on a separate line
74 }
75
76
77 int InsetMarginal::docbook(odocstream & os,
78                            OutputParams const & runparams) const
79 {
80         os << "<note role=\"margin\">";
81         int const i = InsetText::docbook(os, runparams);
82         os << "</note>";
83
84         return i;
85 }
86
87
88 void InsetMarginal::addToToc(ParConstIterator const & cpit) const
89 {
90         ParConstIterator pit = cpit;
91         pit.push_back(*this);
92
93         Toc & toc = buffer().tocBackend().toc("marginalnote");
94         docstring str;
95         str = getNewLabel(str);
96         toc.push_back(TocItem(pit, 0, str));
97 }
98
99 } // namespace lyx