diff options
Diffstat (limited to 'src/FbTk')
-rw-r--r-- | src/FbTk/ThemeItems.hh | 196 |
1 files changed, 196 insertions, 0 deletions
diff --git a/src/FbTk/ThemeItems.hh b/src/FbTk/ThemeItems.hh new file mode 100644 index 0000000..1a6a402 --- /dev/null +++ b/src/FbTk/ThemeItems.hh | |||
@@ -0,0 +1,196 @@ | |||
1 | // ThemeItems.cc for FbTk - Fluxbox ToolKit | ||
2 | // Copyright (c) 2002 - 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net) | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | // $Id: ThemeItems.hh,v 1.1 2003/10/13 22:56:28 fluxgen Exp $ | ||
23 | |||
24 | /// @file implements common theme items | ||
25 | |||
26 | #ifndef THEMEITEMS_HH | ||
27 | #define THEMEITEMS_HH | ||
28 | |||
29 | #include "Theme.hh" | ||
30 | #include "Color.hh" | ||
31 | #include "Texture.hh" | ||
32 | #include "Font.hh" | ||
33 | #include "PixmapWithMask.hh" | ||
34 | #include "Image.hh" | ||
35 | |||
36 | #include <string> | ||
37 | #include <cstdio> | ||
38 | #include <iostream> | ||
39 | namespace FbTk { | ||
40 | |||
41 | using namespace std; | ||
42 | |||
43 | // create default handlers for Color, Font, Texture, int and string | ||
44 | template <> | ||
45 | void FbTk::ThemeItem<std::string>::load() { } | ||
46 | |||
47 | template <> | ||
48 | void FbTk::ThemeItem<std::string>::setDefaultValue() { | ||
49 | *(*this) = ""; | ||
50 | } | ||
51 | |||
52 | template <> | ||
53 | void FbTk::ThemeItem<std::string>::setFromString(const char *str) { | ||
54 | *(*this) = (str ? str : ""); | ||
55 | } | ||
56 | |||
57 | template <> | ||
58 | void FbTk::ThemeItem<int>::load() { } | ||
59 | |||
60 | template <> | ||
61 | void FbTk::ThemeItem<int>::setDefaultValue() { | ||
62 | *(*this) = 0; | ||
63 | } | ||
64 | |||
65 | template <> | ||
66 | void FbTk::ThemeItem<int>::setFromString(const char *str) { | ||
67 | if (str == 0) | ||
68 | return; | ||
69 | sscanf(str, "%d", &m_value); | ||
70 | } | ||
71 | |||
72 | template <> | ||
73 | void ThemeItem<FbTk::Font>::setDefaultValue() { | ||
74 | if (!m_value.load("fixed")) { | ||
75 | cerr<<"FbTk::ThemeItem<FbTk::Font>: Warning! Failed to load default value 'fixed'"<<endl; | ||
76 | } | ||
77 | } | ||
78 | |||
79 | template <> | ||
80 | void ThemeItem<FbTk::Font>::setFromString(const char *str) { | ||
81 | if (m_value.load(str) == false) { | ||
82 | if (FbTk::ThemeManager::instance().verbose()) { | ||
83 | cerr<<"FbTk::Theme: Error loading font "<< | ||
84 | ((m_value.isAntialias() || m_value.utf8()) ? "(" : "")<< | ||
85 | |||
86 | (m_value.isAntialias() ? "antialias" : "")<< | ||
87 | (m_value.utf8() ? " utf8" : "")<< | ||
88 | |||
89 | ((m_value.isAntialias() || m_value.utf8()) ? ") " : "")<< | ||
90 | "for \""<<name()<<"\" or \""<<altName()<<"\": "<<str<<endl; | ||
91 | |||
92 | cerr<<"FbTk::Theme: Setting default value"<<endl; | ||
93 | } | ||
94 | setDefaultValue(); | ||
95 | } | ||
96 | |||
97 | } | ||
98 | |||
99 | // do nothing | ||
100 | template <> | ||
101 | void ThemeItem<FbTk::Font>::load() { | ||
102 | } | ||
103 | |||
104 | |||
105 | template <> | ||
106 | void ThemeItem<FbTk::Texture>::load() { | ||
107 | string color_name(ThemeManager::instance(). | ||
108 | resourceValue(name()+".color", altName()+".Color")); | ||
109 | string colorto_name(ThemeManager::instance(). | ||
110 | resourceValue(name()+".colorTo", altName()+".ColorTo")); | ||
111 | string pixmap_name(ThemeManager::instance(). | ||
112 | resourceValue(name()+".pixmap", altName()+".Pixmap")); | ||
113 | |||
114 | |||
115 | // set default value if we failed to load color | ||
116 | if (!m_value.color().setFromString(color_name.c_str(), m_tm.screenNum())) | ||
117 | m_value.color().setFromString("darkgray", m_tm.screenNum()); | ||
118 | |||
119 | if (!m_value.colorTo().setFromString(colorto_name.c_str(), m_tm.screenNum())) | ||
120 | m_value.colorTo().setFromString("white", m_tm.screenNum()); | ||
121 | |||
122 | |||
123 | std::auto_ptr<PixmapWithMask> pm(Image::load(pixmap_name, m_tm.screenNum())); | ||
124 | if (pm.get() == 0) { | ||
125 | if (FbTk::ThemeManager::instance().verbose()) | ||
126 | cerr<<"Resource("<<name()+".pixmap"<<"): Failed to load image: "<<pixmap_name<<endl; | ||
127 | m_value.pixmap() = 0; | ||
128 | } else | ||
129 | m_value.pixmap() = pm->pixmap().release(); | ||
130 | } | ||
131 | |||
132 | template <> | ||
133 | void ThemeItem<FbTk::Texture>::setDefaultValue() { | ||
134 | m_value.setType(FbTk::Texture::FLAT | FbTk::Texture::SOLID); | ||
135 | load(); // one might forget to add line something: so we try to load something.*: too | ||
136 | } | ||
137 | |||
138 | template <> | ||
139 | void ThemeItem<FbTk::Texture>::setFromString(const char *str) { | ||
140 | m_value.setFromString(str); | ||
141 | if (m_value.type() == 0) // failed to set value | ||
142 | setDefaultValue(); | ||
143 | } | ||
144 | |||
145 | |||
146 | |||
147 | // not used | ||
148 | template <> | ||
149 | void FbTk::ThemeItem<PixmapWithMask>:: | ||
150 | load() { } | ||
151 | |||
152 | template <> | ||
153 | void FbTk::ThemeItem<PixmapWithMask>:: | ||
154 | setDefaultValue() { | ||
155 | // create empty pixmap | ||
156 | (*this)->pixmap() = 0; | ||
157 | (*this)->mask() = 0; | ||
158 | } | ||
159 | |||
160 | template <> | ||
161 | void FbTk::ThemeItem<PixmapWithMask>:: | ||
162 | setFromString(const char *str) { | ||
163 | if (str == 0) | ||
164 | setDefaultValue(); | ||
165 | else { | ||
166 | std::auto_ptr<FbTk::PixmapWithMask> pm(Image::load(str, m_tm.screenNum())); | ||
167 | if (pm.get() == 0) | ||
168 | setDefaultValue(); | ||
169 | else { | ||
170 | (*this)->pixmap() = pm->pixmap().release(); | ||
171 | (*this)->mask() = pm->mask().release(); | ||
172 | } | ||
173 | } | ||
174 | } | ||
175 | |||
176 | template <> | ||
177 | void ThemeItem<FbTk::Color>::setDefaultValue() { | ||
178 | m_value.setFromString("white", m_tm.screenNum()); | ||
179 | } | ||
180 | |||
181 | template <> | ||
182 | void ThemeItem<FbTk::Color>::setFromString(const char *str) { | ||
183 | if (!m_value.setFromString(str, m_tm.screenNum())) { | ||
184 | if (FbTk::ThemeManager::instance().verbose()) | ||
185 | cerr<<"FbTk::Theme: Error loading color value for \""<<name()<<"\" or \""<<altName()<<"\"."<<endl; | ||
186 | setDefaultValue(); | ||
187 | } | ||
188 | } | ||
189 | |||
190 | // does nothing | ||
191 | template <> | ||
192 | void ThemeItem<FbTk::Color>::load() { } | ||
193 | |||
194 | }; | ||
195 | |||
196 | #endif // THEMEITEMS_HH | ||