]> git.lyx.org Git - lyx.git/blob - src/insets/InsetIndex.cpp
Index as collapsible, preserving existing feature set
[lyx.git] / src / insets / InsetIndex.cpp
1 /**
2  * \file InsetIndex.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10 #include <config.h>
11
12 #include "InsetIndex.h"
13
14 #include "DispatchResult.h"
15 #include "FuncRequest.h"
16 #include "FuncStatus.h"
17 #include "gettext.h"
18 #include "LaTeXFeatures.h"
19 #include "MetricsInfo.h"
20 #include "sgml.h"
21
22 #include "support/std_ostream.h"
23
24
25 namespace lyx {
26
27 using std::string;
28 using std::ostream;
29
30
31 InsetIndex::InsetIndex(BufferParams const & bp)
32         : InsetCollapsable(bp)
33 {
34         setLayout(bp);
35 }
36
37
38 InsetIndex::InsetIndex(InsetIndex const & in)
39         : InsetCollapsable(in)
40 {}
41
42
43 int InsetIndex::docbook(Buffer const & buf, odocstream & os,
44                         OutputParams const & runparams) const
45 {
46         os << "<indexterm><primary>";
47         int const i = InsetText::docbook(buf, os, runparams);
48         os << "</primary></indexterm>";
49         return i;
50 }
51
52
53 Inset::Code InsetIndex::lyxCode() const
54 {
55         return Inset::INDEX_CODE;
56 }
57
58
59 Inset * InsetIndex::clone() const
60 {
61         return new InsetIndex(*this);
62 }
63
64
65 void InsetIndex::write(Buffer const & buf, std::ostream & os) const
66 {
67         os << to_utf8(name()) << "\n";
68         InsetCollapsable::write(buf, os);
69 }
70
71
72 void InsetIndex::metrics(MetricsInfo & mi, Dimension & dim) const
73 {
74         Font tmpfont = mi.base.font;
75         getDrawFont(mi.base.font);
76         mi.base.font.realize(tmpfont);
77         InsetCollapsable::metrics(mi, dim);
78         mi.base.font = tmpfont;
79 }
80
81
82 void InsetIndex::draw(PainterInfo & pi, int x, int y) const
83 {
84         Font tmpfont = pi.base.font;
85         getDrawFont(pi.base.font);
86         pi.base.font.realize(tmpfont);
87         InsetCollapsable::draw(pi, x, y);
88         pi.base.font = tmpfont;
89 }
90
91
92 void InsetIndex::getDrawFont(Font & font) const
93 {
94         font = Font(Font::ALL_INHERIT);
95         font.realize(layout_.font);
96 }
97
98
99 bool InsetIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
100         FuncStatus & status) const
101 {
102         switch (cmd.action) {
103                 // paragraph breaks not allowed
104                 case LFUN_BREAK_PARAGRAPH:
105                 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
106                 case LFUN_BREAK_PARAGRAPH_SKIP:
107                         status.enabled(false);
108                         return true;
109
110                 default:
111                         return InsetCollapsable::getStatus(cur, cmd, status);
112                 }
113 }
114
115
116
117 InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p)
118         : InsetCommand(p, string())
119 {}
120
121
122 docstring const InsetPrintIndex::getScreenLabel(Buffer const &) const
123 {
124         return _("Index");
125 }
126
127
128 void InsetPrintIndex::validate(LaTeXFeatures & features) const
129 {
130         features.require("makeidx");
131 }
132
133
134 Inset::Code InsetPrintIndex::lyxCode() const
135 {
136         return Inset::INDEX_PRINT_CODE;
137 }
138
139
140 } // namespace lyx