]> git.lyx.org Git - features.git/blob - src/insets/InsetIndex.cpp
Move the findInfo() and defaultCommand() routines out of InsetCommand and into its...
[features.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 CommandInfo const * InsetIndex::findInfo(std::string const & /* cmdName */)
44 {
45         static const char * const paramnames[] = {"name", ""};
46         static const bool isoptional[] = {false};
47         static const CommandInfo info = {1, paramnames, isoptional};
48         return &info;
49 }
50
51
52 int InsetIndex::docbook(Buffer const & buf, odocstream & os,
53                         OutputParams const & runparams) const
54 {
55         os << "<indexterm><primary>";
56         int const i = InsetText::docbook(buf, os, runparams);
57         os << "</primary></indexterm>";
58         return i;
59 }
60
61
62 Inset * InsetIndex::clone() const
63 {
64         return new InsetIndex(*this);
65 }
66
67
68 void InsetIndex::write(Buffer const & buf, std::ostream & os) const
69 {
70         os << to_utf8(name()) << "\n";
71         InsetCollapsable::write(buf, os);
72 }
73
74
75 void InsetIndex::metrics(MetricsInfo & mi, Dimension & dim) const
76 {
77         Font tmpfont = mi.base.font;
78         getDrawFont(mi.base.font);
79         mi.base.font.realize(tmpfont);
80         InsetCollapsable::metrics(mi, dim);
81         mi.base.font = tmpfont;
82 }
83
84
85 void InsetIndex::draw(PainterInfo & pi, int x, int y) const
86 {
87         Font tmpfont = pi.base.font;
88         getDrawFont(pi.base.font);
89         pi.base.font.realize(tmpfont);
90         InsetCollapsable::draw(pi, x, y);
91         pi.base.font = tmpfont;
92 }
93
94
95 void InsetIndex::getDrawFont(Font & font) const
96 {
97         font = Font(Font::ALL_INHERIT);
98         font.realize(layout_.font);
99 }
100
101
102 bool InsetIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
103         FuncStatus & status) const
104 {
105         switch (cmd.action) {
106                 // paragraph breaks not allowed
107                 case LFUN_BREAK_PARAGRAPH:
108                 case LFUN_BREAK_PARAGRAPH_SKIP:
109                         status.enabled(false);
110                         return true;
111
112                 default:
113                         return InsetCollapsable::getStatus(cur, cmd, status);
114                 }
115 }
116
117
118
119 InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p)
120         : InsetCommand(p, string())
121 {}
122
123
124 CommandInfo const * InsetPrintIndex::findInfo(std::string const & /* cmdName */)
125 {
126         static const char * const paramnames[] = {"name", ""};
127         static const bool isoptional[] = {false};
128         static const CommandInfo info = {1, paramnames, isoptional};
129         return &info;
130 }
131
132
133 docstring const InsetPrintIndex::getScreenLabel(Buffer const &) const
134 {
135         return _("Index");
136 }
137
138
139 void InsetPrintIndex::validate(LaTeXFeatures & features) const
140 {
141         features.require("makeidx");
142 }
143
144
145 InsetCode InsetPrintIndex::lyxCode() const
146 {
147         return INDEX_PRINT_CODE;
148 }
149
150
151 } // namespace lyx