]> git.lyx.org Git - lyx.git/blob - src/insets/InsetIndex.cpp
adjust
[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 * InsetIndex::clone() const
54 {
55         return new InsetIndex(*this);
56 }
57
58
59 void InsetIndex::write(Buffer const & buf, std::ostream & os) const
60 {
61         os << to_utf8(name()) << "\n";
62         InsetCollapsable::write(buf, os);
63 }
64
65
66 void InsetIndex::metrics(MetricsInfo & mi, Dimension & dim) const
67 {
68         Font tmpfont = mi.base.font;
69         getDrawFont(mi.base.font);
70         mi.base.font.realize(tmpfont);
71         InsetCollapsable::metrics(mi, dim);
72         mi.base.font = tmpfont;
73 }
74
75
76 void InsetIndex::draw(PainterInfo & pi, int x, int y) const
77 {
78         Font tmpfont = pi.base.font;
79         getDrawFont(pi.base.font);
80         pi.base.font.realize(tmpfont);
81         InsetCollapsable::draw(pi, x, y);
82         pi.base.font = tmpfont;
83 }
84
85
86 void InsetIndex::getDrawFont(Font & font) const
87 {
88         font = Font(Font::ALL_INHERIT);
89         font.realize(layout_.font);
90 }
91
92
93 bool InsetIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
94         FuncStatus & status) const
95 {
96         switch (cmd.action) {
97                 // paragraph breaks not allowed
98                 case LFUN_BREAK_PARAGRAPH:
99                 case LFUN_BREAK_PARAGRAPH_SKIP:
100                         status.enabled(false);
101                         return true;
102
103                 default:
104                         return InsetCollapsable::getStatus(cur, cmd, status);
105                 }
106 }
107
108
109
110 InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p)
111         : InsetCommand(p, string())
112 {}
113
114
115 docstring const InsetPrintIndex::getScreenLabel(Buffer const &) const
116 {
117         return _("Index");
118 }
119
120
121 void InsetPrintIndex::validate(LaTeXFeatures & features) const
122 {
123         features.require("makeidx");
124 }
125
126
127 InsetCode InsetPrintIndex::lyxCode() const
128 {
129         return INDEX_PRINT_CODE;
130 }
131
132
133 } // namespace lyx