]> git.lyx.org Git - lyx.git/blob - src/insets/insetfloatlist.C
Move #includes out of header files.
[lyx.git] / src / insets / insetfloatlist.C
1 /**
2  * \file insetfloatlist.C
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
11 #include <config.h>
12
13 #include "insetfloatlist.h"
14
15 #include "buffer.h"
16 #include "BufferView.h"
17 #include "debug.h"
18 #include "Floating.h"
19 #include "FloatList.h"
20 #include "funcrequest.h"
21 #include "gettext.h"
22 #include "LaTeXFeatures.h"
23 #include "lyxlex.h"
24 #include "metricsinfo.h"
25 #include "toc.h"
26 #include "Lsstream.h"
27
28 #include "support/lstrings.h"
29
30 using namespace lyx::support;
31
32 using std::ostream;
33 using std::endl;
34
35
36 InsetFloatList::InsetFloatList()
37         : InsetCommand(InsetCommandParams())
38 {}
39
40
41 InsetFloatList::InsetFloatList(string const & type)
42         : InsetCommand(InsetCommandParams())
43 {
44         setCmdName(type);
45 }
46
47
48 InsetFloatList::~InsetFloatList()
49 {
50         InsetCommandMailer mailer("toc", *this);
51         mailer.hideDialog();
52 }
53
54
55 string const InsetFloatList::getScreenLabel(Buffer const & buf) const
56 {
57         FloatList const & floats = buf.params.getLyXTextClass().floats();
58         FloatList::const_iterator it = floats[getCmdName()];
59         if (it != floats.end())
60                 return _(it->second.listName());
61         else
62                 return _("ERROR: Nonexistent float type!");
63 }
64
65
66 InsetOld::Code InsetFloatList::lyxCode() const
67 {
68         return InsetOld::FLOAT_LIST_CODE;
69 }
70
71
72 void InsetFloatList::write(Buffer const &, ostream & os) const
73 {
74         os << "FloatList " << getCmdName() << "\n";
75 }
76
77
78 void InsetFloatList::read(Buffer const & buf, LyXLex & lex)
79 {
80         FloatList const & floats = buf.params.getLyXTextClass().floats();
81         string token;
82
83         if (lex.eatLine()) {
84                 setCmdName(lex.getString());
85                 lyxerr[Debug::INSETS] << "FloatList::float_type: " << getCmdName() << endl;
86                 if (!floats.typeExist(getCmdName()))
87                         lex.printError("InsetFloatList: Unknown float type: `$$Token'");
88         } else
89                 lex.printError("InsetFloatList: Parse error: `$$Token'");
90         while (lex.isOK()) {
91                 lex.nextToken();
92                 token = lex.getString();
93                 if (token == "\\end_inset")
94                         break;
95         }
96         if (token != "\\end_inset") {
97                 lex.printError("Missing \\end_inset at this point. "
98                                "Read: `$$Token'");
99         }
100 }
101
102
103 void InsetFloatList::metrics(MetricsInfo & mi, Dimension & dim) const
104 {
105         InsetCommand::metrics(mi, dim);
106         center_indent_ = (mi.base.textwidth - dim.wid) / 2;
107         dim.wid = mi.base.textwidth;
108         dim_ = dim;
109 }
110
111
112 void InsetFloatList::draw(PainterInfo & pi, int x, int y) const
113 {
114         InsetCommand::draw(pi, x + center_indent_, y);
115 }
116
117
118 dispatch_result InsetFloatList::localDispatch(FuncRequest const & cmd)
119 {
120         switch (cmd.action) {
121                 case LFUN_INSET_EDIT:
122                         InsetCommandMailer("toc", *this).showDialog(cmd.view());
123                         return DISPATCHED;
124                 default:
125                         return InsetCommand::localDispatch(cmd);
126         }
127 }
128
129
130 int InsetFloatList::latex(Buffer const & buf, ostream & os,
131                           LatexRunParams const &) const
132 {
133         FloatList const & floats = buf.params.getLyXTextClass().floats();
134         FloatList::const_iterator cit = floats[getCmdName()];
135
136         if (cit != floats.end()) {
137                 if (cit->second.builtin()) {
138                         // Only two different types allowed here:
139                         string const type = cit->second.type();
140                         if (type == "table") {
141                                 os << "\\listoftables\n";
142                         } else if (type == "figure") {
143                                 os << "\\listoffigures\n";
144                         } else {
145                                 os << "%% unknown builtin float\n";
146                         }
147                 } else {
148                         os << "\\listof{" << getCmdName() << "}{"
149                            << cit->second.listName() << "}\n";
150                 }
151         } else {
152                 os << "%%\\listof{" << getCmdName() << "}{"
153                    << bformat(_("List of %1$s"), cit->second.name())
154                    << "}\n";
155         }
156         return 1;
157 }
158
159
160 int InsetFloatList::ascii(Buffer const & buffer, ostream & os, int) const
161 {
162         os << getScreenLabel(buffer) << "\n\n";
163
164         lyx::toc::asciiTocList(getCmdName(), buffer, os);
165
166         os << "\n";
167         return 0;
168 }
169
170
171 void InsetFloatList::validate(LaTeXFeatures & features) const
172 {
173         features.useFloat(getCmdName());
174 }