]> git.lyx.org Git - features.git/blob - src/Floating.cpp
458dfb910384d61e381bcd65026db2c15ee23844
[features.git] / src / Floating.cpp
1 /**
2  * \file Floating.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  * \author Jean-Marc Lasgouttes
8  * \author Angus Leeming
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "Floating.h"
16
17 #include "support/docstring.h"
18 #include "support/lstrings.h"
19 #include "support/Messages.h"
20
21 using namespace std;
22
23
24 namespace lyx {
25
26
27 Floating::Floating()
28 {}
29
30
31 Floating::Floating(string const & type, string const & placement,
32                    string const & ext, string const & within,
33                    string const & style, string const & name,
34                    string const & listName, string const & htmlTag,
35                    string const & htmlAttrib, string const & htmlStyle,
36                    bool needsfloat)
37         : floattype_(type), placement_(placement), ext_(ext), within_(within),
38           style_(style), name_(name), listname_(listName), needsfloatpkg_(needsfloat),
39     html_tag_(htmlTag), html_attrib_(htmlAttrib), html_style_(htmlStyle)
40 {}
41
42
43 docstring const & Floating::listCommand(string const & lang) const
44 {
45         if (listcommand_.empty()) {
46                 if (needsFloatPkg())    
47                         listcommand_ = from_ascii("\\listof{" + floattype_ + "}{")
48                            + getMessages(lang).get(listName()) + "}";
49                 else {
50                         if (floattype_ == "table")
51                                 listcommand_ = from_ascii("\\listoftables");
52                         else if (floattype_ == "figure")
53                                 listcommand_ = from_ascii("\\listoffigures");
54                         else
55                                 // FIXME We really need a special tag for this.
56                                 listcommand_ = from_ascii("\\listof" + floattype_ + "s");
57                 }
58         }
59         return listcommand_;
60 }
61
62
63 string const & Floating::htmlAttrib() const
64 {
65         if (html_attrib_.empty())
66                 html_attrib_ = "class='float " + defaultCSSClass() + "'";
67         return html_attrib_;
68 }
69
70
71 string const & Floating::htmlTag() const
72 {
73         if (html_tag_.empty())
74                 html_tag_ = "div";
75         return html_tag_;
76 }
77
78
79 string Floating::defaultCSSClass() const
80
81         if (!defaultcssclass_.empty())
82                 return defaultcssclass_;
83         string d;
84         string n = floattype_;
85         string::const_iterator it = n.begin();
86         string::const_iterator en = n.end();
87         for (; it != en; ++it) {
88                 if (!isalpha(*it))
89                         d += "_";
90                 else if (islower(*it))
91                         d += *it;
92                 else
93                         d += support::lowercase(*it);
94         }
95         // are there other characters we need to remove?
96         defaultcssclass_ = "float-" + d;
97         return defaultcssclass_;
98 }
99
100
101 } // namespace lyx