]> git.lyx.org Git - lyx.git/blob - src/insets/insetfloatlist.C
dont use pragma impementation and interface anymore
[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 #include <config.h>
11
12
13 #include "insetfloatlist.h"
14 #include "FloatList.h"
15 #include "LaTeXFeatures.h"
16 #include "lyxlex.h"
17 #include "frontends/Dialogs.h"
18 #include "frontends/LyXView.h"
19 #include "BufferView.h"
20 #include "buffer.h"
21 #include "toc.h"
22 #include "gettext.h"
23 #include "debug.h"
24
25 #include "BoostFormat.h"
26
27 using std::ostream;
28 using std::endl;
29
30
31 InsetFloatList::InsetFloatList()
32         : InsetCommand(InsetCommandParams())
33 {
34 }
35
36
37 InsetFloatList::InsetFloatList(string const & type)
38         : InsetCommand(InsetCommandParams())
39 {
40         setCmdName(type);
41 }
42
43
44 string const InsetFloatList::getScreenLabel(Buffer const * buf) const
45 {
46         FloatList const & floats = buf->params.getLyXTextClass().floats();
47         FloatList::const_iterator it = floats[getCmdName()];
48         if (it != floats.end())
49                 return _(it->second.listName());
50         else
51                 return _("ERROR: Nonexistent float type!");
52 }
53
54
55 Inset::Code InsetFloatList::lyxCode() const
56 {
57         return Inset::FLOAT_LIST_CODE;
58 }
59
60
61 void InsetFloatList::write(Buffer const *, ostream & os) const
62 {
63         os << "FloatList " << getCmdName() << "\n";
64 }
65
66
67 void InsetFloatList::read(Buffer const * buf, LyXLex & lex)
68 {
69         FloatList const & floats = buf->params.getLyXTextClass().floats();
70         string token;
71
72         if (lex.eatLine()) {
73                 setCmdName(lex.getString());
74                 lyxerr[Debug::INSETS] << "FloatList::float_type: " << getCmdName() << endl;
75                 if (!floats.typeExist(getCmdName()))
76                         lex.printError("InsetFloatList: Unknown float type: `$$Token'");
77         } else
78                 lex.printError("InsetFloatList: Parse error: `$$Token'");
79         while (lex.isOK()) {
80                 lex.nextToken();
81                 token = lex.getString();
82                 if (token == "\\end_inset")
83                         break;
84         }
85         if (token != "\\end_inset") {
86                 lex.printError("Missing \\end_inset at this point. "
87                                "Read: `$$Token'");
88         }
89 }
90
91
92 void InsetFloatList::edit(BufferView * bv, int, int, mouse_button::state)
93 {
94         bv->owner()->getDialogs().showTOC(this);
95 }
96
97
98 void InsetFloatList::edit(BufferView * bv, bool)
99 {
100         edit(bv, 0, 0, mouse_button::none);
101 }
102
103
104 int InsetFloatList::latex(Buffer const * buf, ostream & os, bool, bool) const
105 {
106         FloatList const & floats = buf->params.getLyXTextClass().floats();
107         FloatList::const_iterator cit = floats[getCmdName()];
108
109         if (cit != floats.end()) {
110                 if (cit->second.builtin()) {
111                         // Only two different types allowed here:
112                         string const type = cit->second.type();
113                         if (type == "table") {
114                                 os << "\\listoftables\n";
115                         } else if (type == "figure") {
116                                 os << "\\listoffigures\n";
117                         } else {
118                                 os << "%% unknown builtin float\n";
119                         }
120                 } else {
121                         os << "\\listof{" << getCmdName() << "}{"
122                            << cit->second.listName() << "}\n";
123                 }
124         } else {
125 #if USE_BOOST_FORMAT
126                 os << "%%\\listof{"
127                    << getCmdName()
128                    << "}{"
129                    << boost::format(_("List of %1$s")) % cit->second.name()
130                    << "}\n";
131 #else
132                 os << "%%\\listof{"
133                    << getCmdName()
134                    << "}{"
135                    << _("List of ") << cit->second.name()
136                    << "}\n";
137 #endif
138         }
139         return 1;
140 }
141
142
143 int InsetFloatList::ascii(Buffer const * buffer, ostream & os, int) const
144 {
145         os << getScreenLabel(buffer) << "\n\n";
146
147         toc::asciiTocList(getCmdName(), buffer, os);
148
149         os << "\n";
150         return 0;
151 }
152
153
154 void InsetFloatList::validate(LaTeXFeatures & features) const
155 {
156         features.useFloat(getCmdName());
157 }