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