]> git.lyx.org Git - features.git/blob - src/insets/InsetIndex.cpp
some index fixes:
[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 "Buffer.h"
15 #include "DispatchResult.h"
16 #include "FuncRequest.h"
17 #include "FuncStatus.h"
18 #include "LaTeXFeatures.h"
19 #include "MetricsInfo.h"
20 #include "sgml.h"
21 #include "TocBackend.h"
22
23 #include "support/gettext.h"
24
25 #include <ostream>
26
27 using namespace std;
28
29 namespace lyx {
30
31 /////////////////////////////////////////////////////////////////////
32 //
33 // InsetIndex
34 //
35 ///////////////////////////////////////////////////////////////////////
36
37
38 InsetIndex::InsetIndex(Buffer const & buf)
39         : InsetCollapsable(buf)
40 {}
41
42
43 int InsetIndex::latex(odocstream & os,
44                           OutputParams const & runparams) const
45 {
46         os << "\\index";
47         os << '{';
48         if (hasFontChanges()) {
49                 InsetText::plaintext(os, runparams);
50                 os << '@';
51         }
52         int i = InsetText::latex(os, runparams);
53         os << '}';
54         return i;
55 }
56
57
58 int InsetIndex::docbook(odocstream & os, OutputParams const & runparams) const
59 {
60         os << "<indexterm><primary>";
61         int const i = InsetText::docbook(os, runparams);
62         os << "</primary></indexterm>";
63         return i;
64 }
65
66
67 void InsetIndex::write(ostream & os) const
68 {
69         os << to_utf8(name()) << "\n";
70         InsetCollapsable::write(os);
71 }
72
73
74 void InsetIndex::addToToc(ParConstIterator const & cpit) const
75 {
76         ParConstIterator pit = cpit;
77         pit.push_back(*this);
78
79         Toc & toc = buffer().tocBackend().toc("index");
80         docstring str;
81         str = getNewLabel(str);
82         toc.push_back(TocItem(pit, 0, str));
83 }
84
85
86 bool InsetIndex::hasFontChanges() const
87 {
88         // we only have one par
89         Paragraph par = paragraphs().back();
90         FontSpan const font_span = par.fontSpan(0);
91         Font firstfont = par.getFirstFontSettings(buffer().params());
92         return (firstfont.fontInfo() != inherit_font || par.size() > font_span.last + 1);
93 }
94
95
96 /////////////////////////////////////////////////////////////////////
97 //
98 // InsetPrintIndex
99 //
100 ///////////////////////////////////////////////////////////////////////
101
102 InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p)
103         : InsetCommand(p, string())
104 {}
105
106
107 ParamInfo const & InsetPrintIndex::findInfo(string const & /* cmdName */)
108 {
109         static ParamInfo param_info_;
110         if (param_info_.empty())
111                 param_info_.add("name", ParamInfo::LATEX_REQUIRED);
112         return param_info_;
113 }
114
115
116 docstring InsetPrintIndex::screenLabel() const
117 {
118         return _("Index");
119 }
120
121
122 void InsetPrintIndex::validate(LaTeXFeatures & features) const
123 {
124         features.require("makeidx");
125 }
126
127
128 InsetCode InsetPrintIndex::lyxCode() const
129 {
130         return INDEX_PRINT_CODE;
131 }
132
133 } // namespace lyx