diff options
author | mathias <mathias> | 2005-01-14 09:43:31 (GMT) |
---|---|---|
committer | mathias <mathias> | 2005-01-14 09:43:31 (GMT) |
commit | a07d61e63dfc129660cc9bab344c9e040a7f991f (patch) | |
tree | 054793ac4730a39a4ebc0499e747d71e02fad4f8 /src/FbTk | |
parent | 4f9370cafa693862cdd901ce8d237380900a95de (diff) | |
download | fluxbox_paul-a07d61e63dfc129660cc9bab344c9e040a7f991f.zip fluxbox_paul-a07d61e63dfc129660cc9bab344c9e040a7f991f.tar.bz2 |
moved ThemeItem<bool> - implementation to FbTk/ThemeItems.cc
Diffstat (limited to 'src/FbTk')
-rw-r--r-- | src/FbTk/ThemeItems.cc | 154 |
1 files changed, 120 insertions, 34 deletions
diff --git a/src/FbTk/ThemeItems.cc b/src/FbTk/ThemeItems.cc index a588328..f55c162 100644 --- a/src/FbTk/ThemeItems.cc +++ b/src/FbTk/ThemeItems.cc | |||
@@ -30,6 +30,7 @@ | |||
30 | #include "Color.hh" | 30 | #include "Color.hh" |
31 | #include "Texture.hh" | 31 | #include "Texture.hh" |
32 | #include "Font.hh" | 32 | #include "Font.hh" |
33 | #include "GContext.hh" | ||
33 | #include "PixmapWithMask.hh" | 34 | #include "PixmapWithMask.hh" |
34 | #include "Image.hh" | 35 | #include "Image.hh" |
35 | #include "StringUtil.hh" | 36 | #include "StringUtil.hh" |
@@ -43,32 +44,35 @@ | |||
43 | #include <iostream> | 44 | #include <iostream> |
44 | namespace FbTk { | 45 | namespace FbTk { |
45 | 46 | ||
46 | using namespace std; | 47 | using std::string; |
48 | using std::cerr; | ||
49 | using std::endl; | ||
50 | |||
47 | 51 | ||
48 | // create default handlers for Color, Font, Texture, int and string | 52 | // create default handlers for Color, Font, Texture, int and string |
49 | template <> | 53 | template <> |
50 | void FbTk::ThemeItem<std::string>::load(const std::string *name, const std::string *altname) { } | 54 | void ThemeItem<string>::load(const string *name, const string *altname) { } |
51 | 55 | ||
52 | template <> | 56 | template <> |
53 | void FbTk::ThemeItem<std::string>::setDefaultValue() { | 57 | void ThemeItem<string>::setDefaultValue() { |
54 | *(*this) = ""; | 58 | *(*this) = ""; |
55 | } | 59 | } |
56 | 60 | ||
57 | template <> | 61 | template <> |
58 | void FbTk::ThemeItem<std::string>::setFromString(const char *str) { | 62 | void ThemeItem<string>::setFromString(const char *str) { |
59 | *(*this) = (str ? str : ""); | 63 | *(*this) = (str ? str : ""); |
60 | } | 64 | } |
61 | 65 | ||
62 | template <> | 66 | template <> |
63 | void FbTk::ThemeItem<int>::load(const std::string *name, const std::string *altname) { } | 67 | void ThemeItem<int>::load(const string *name, const string *altname) { } |
64 | 68 | ||
65 | template<> | 69 | template<> |
66 | void FbTk::ThemeItem<int>::setDefaultValue() { | 70 | void ThemeItem<int>::setDefaultValue() { |
67 | *(*this) = 0; | 71 | *(*this) = 0; |
68 | } | 72 | } |
69 | 73 | ||
70 | template <> | 74 | template <> |
71 | void FbTk::ThemeItem<int>::setFromString(const char *str) { | 75 | void ThemeItem<int>::setFromString(const char *str) { |
72 | if (str == 0) { | 76 | if (str == 0) { |
73 | setDefaultValue(); | 77 | setDefaultValue(); |
74 | return; | 78 | return; |
@@ -77,20 +81,35 @@ void FbTk::ThemeItem<int>::setFromString(const char *str) { | |||
77 | if (sscanf(str, "%d", &m_value) < 1) | 81 | if (sscanf(str, "%d", &m_value) < 1) |
78 | setDefaultValue(); | 82 | setDefaultValue(); |
79 | } | 83 | } |
84 | template<> | ||
85 | void FbTk::ThemeItem<bool>::load(const std::string *name, const std::string *altname) { } | ||
86 | |||
87 | template<> | ||
88 | void FbTk::ThemeItem<bool>::setDefaultValue() { | ||
89 | *(*this) = false; | ||
90 | } | ||
91 | |||
92 | template<> | ||
93 | void FbTk::ThemeItem<bool>::setFromString(char const *strval) { | ||
94 | if (strcasecmp(strval, "true")==0) | ||
95 | *(*this) = true; | ||
96 | else | ||
97 | *(*this) = false; | ||
98 | } | ||
80 | 99 | ||
81 | template <> | 100 | template <> |
82 | void ThemeItem<FbTk::Font>::setDefaultValue() { | 101 | void ThemeItem<Font>::setDefaultValue() { |
83 | if (!m_value.load("fixed")) { | 102 | if (!m_value.load("fixed")) { |
84 | cerr<<"FbTk::ThemeItem<FbTk::Font>: Warning! Failed to load default value 'fixed'"<<endl; | 103 | cerr<<"ThemeItem<Font>: Warning! Failed to load default value 'fixed'"<<endl; |
85 | } | 104 | } |
86 | } | 105 | } |
87 | 106 | ||
88 | template <> | 107 | template <> |
89 | void ThemeItem<FbTk::Font>::setFromString(const char *str) { | 108 | void ThemeItem<Font>::setFromString(const char *str) { |
90 | 109 | ||
91 | if (str == 0 || m_value.load(str) == false) { | 110 | if (str == 0 || m_value.load(str) == false) { |
92 | if (FbTk::ThemeManager::instance().verbose()) { | 111 | if (ThemeManager::instance().verbose()) { |
93 | cerr<<"FbTk::Theme: Error loading font "<< | 112 | cerr<<"Theme: Error loading font "<< |
94 | ((m_value.isAntialias() || m_value.utf8()) ? "(" : "")<< | 113 | ((m_value.isAntialias() || m_value.utf8()) ? "(" : "")<< |
95 | 114 | ||
96 | (m_value.isAntialias() ? "antialias" : "")<< | 115 | (m_value.isAntialias() ? "antialias" : "")<< |
@@ -99,7 +118,7 @@ void ThemeItem<FbTk::Font>::setFromString(const char *str) { | |||
99 | ((m_value.isAntialias() || m_value.utf8()) ? ") " : "")<< | 118 | ((m_value.isAntialias() || m_value.utf8()) ? ") " : "")<< |
100 | "for \""<<name()<<"\" or \""<<altName()<<"\": "<<str<<endl; | 119 | "for \""<<name()<<"\" or \""<<altName()<<"\": "<<str<<endl; |
101 | 120 | ||
102 | cerr<<"FbTk::Theme: Setting default value"<<endl; | 121 | cerr<<"Theme: Setting default value"<<endl; |
103 | } | 122 | } |
104 | setDefaultValue(); | 123 | setDefaultValue(); |
105 | } | 124 | } |
@@ -108,14 +127,14 @@ void ThemeItem<FbTk::Font>::setFromString(const char *str) { | |||
108 | 127 | ||
109 | // do nothing | 128 | // do nothing |
110 | template <> | 129 | template <> |
111 | void ThemeItem<FbTk::Font>::load(const std::string *name, const std::string *altname) { | 130 | void ThemeItem<Font>::load(const string *name, const string *altname) { |
112 | } | 131 | } |
113 | 132 | ||
114 | 133 | ||
115 | template <> | 134 | template <> |
116 | void ThemeItem<FbTk::Texture>::load(const std::string *o_name, const std::string *o_altname) { | 135 | void ThemeItem<Texture>::load(const string *o_name, const string *o_altname) { |
117 | const std::string &m_name = (o_name==0)?name():*o_name; | 136 | const string &m_name = (o_name==0)?name():*o_name; |
118 | const std::string &m_altname = (o_altname==0)?altName():*o_altname; | 137 | const string &m_altname = (o_altname==0)?altName():*o_altname; |
119 | 138 | ||
120 | string color_name(ThemeManager::instance(). | 139 | string color_name(ThemeManager::instance(). |
121 | resourceValue(m_name+".color", m_altname+".Color")); | 140 | resourceValue(m_name+".color", m_altname+".Color")); |
@@ -135,7 +154,7 @@ void ThemeItem<FbTk::Texture>::load(const std::string *o_name, const std::string | |||
135 | m_value.colorTo().setFromString("white", m_tm.screenNum()); | 154 | m_value.colorTo().setFromString("white", m_tm.screenNum()); |
136 | 155 | ||
137 | 156 | ||
138 | if ((m_value.type() & FbTk::Texture::SOLID) != 0 && (m_value.type() & FbTk::Texture::FLAT) == 0) | 157 | if ((m_value.type() & Texture::SOLID) != 0 && (m_value.type() & Texture::FLAT) == 0) |
139 | m_value.calcHiLoColors(m_tm.screenNum()); | 158 | m_value.calcHiLoColors(m_tm.screenNum()); |
140 | 159 | ||
141 | StringUtil::removeFirstWhitespace(pixmap_name); | 160 | StringUtil::removeFirstWhitespace(pixmap_name); |
@@ -145,10 +164,10 @@ void ThemeItem<FbTk::Texture>::load(const std::string *o_name, const std::string | |||
145 | return; | 164 | return; |
146 | } | 165 | } |
147 | 166 | ||
148 | std::auto_ptr<FbTk::PixmapWithMask> pm(FbTk::Image::load(pixmap_name, | 167 | std::auto_ptr<PixmapWithMask> pm(Image::load(pixmap_name, |
149 | m_tm.screenNum())); | 168 | m_tm.screenNum())); |
150 | if (pm.get() == 0) { | 169 | if (pm.get() == 0) { |
151 | if (FbTk::ThemeManager::instance().verbose()) { | 170 | if (ThemeManager::instance().verbose()) { |
152 | cerr<<"Resource("<<m_name+".pixmap" | 171 | cerr<<"Resource("<<m_name+".pixmap" |
153 | <<"): Failed to load image: "<<pixmap_name<<endl; | 172 | <<"): Failed to load image: "<<pixmap_name<<endl; |
154 | } | 173 | } |
@@ -159,13 +178,13 @@ void ThemeItem<FbTk::Texture>::load(const std::string *o_name, const std::string | |||
159 | } | 178 | } |
160 | 179 | ||
161 | template <> | 180 | template <> |
162 | void ThemeItem<FbTk::Texture>::setDefaultValue() { | 181 | void ThemeItem<Texture>::setDefaultValue() { |
163 | m_value.setType(FbTk::Texture::FLAT | FbTk::Texture::SOLID); | 182 | m_value.setType(Texture::FLAT | Texture::SOLID); |
164 | load(); // one might forget to add line something: so we try to load something.*: too | 183 | load(); // one might forget to add line something: so we try to load something.*: too |
165 | } | 184 | } |
166 | 185 | ||
167 | template <> | 186 | template <> |
168 | void ThemeItem<FbTk::Texture>::setFromString(const char *str) { | 187 | void ThemeItem<Texture>::setFromString(const char *str) { |
169 | m_value.setFromString(str); | 188 | m_value.setFromString(str); |
170 | if (m_value.type() == 0) // failed to set value | 189 | if (m_value.type() == 0) // failed to set value |
171 | setDefaultValue(); | 190 | setDefaultValue(); |
@@ -175,28 +194,27 @@ void ThemeItem<FbTk::Texture>::setFromString(const char *str) { | |||
175 | 194 | ||
176 | // not used | 195 | // not used |
177 | template <> | 196 | template <> |
178 | void FbTk::ThemeItem<PixmapWithMask>::load(const std::string *name, const std::string *altname) { } | 197 | void ThemeItem<PixmapWithMask>::load(const string *name, const string *altname) { } |
179 | 198 | ||
180 | template <> | 199 | template <> |
181 | void FbTk::ThemeItem<PixmapWithMask>:: | 200 | void ThemeItem<PixmapWithMask>::setDefaultValue() { |
182 | setDefaultValue() { | ||
183 | // create empty pixmap | 201 | // create empty pixmap |
184 | (*this)->pixmap() = 0; | 202 | (*this)->pixmap() = 0; |
185 | (*this)->mask() = 0; | 203 | (*this)->mask() = 0; |
186 | } | 204 | } |
187 | 205 | ||
188 | template <> | 206 | template <> |
189 | void FbTk::ThemeItem<PixmapWithMask>:: | 207 | void ThemeItem<PixmapWithMask>:: |
190 | setFromString(const char *str) { | 208 | setFromString(const char *str) { |
191 | if (str == 0) | 209 | if (str == 0) |
192 | setDefaultValue(); | 210 | setDefaultValue(); |
193 | else { | 211 | else { |
194 | std::string filename(str); | 212 | string filename(str); |
195 | 213 | ||
196 | StringUtil::removeFirstWhitespace(filename); | 214 | StringUtil::removeFirstWhitespace(filename); |
197 | StringUtil::removeTrailingWhitespace(filename); | 215 | StringUtil::removeTrailingWhitespace(filename); |
198 | 216 | ||
199 | std::auto_ptr<FbTk::PixmapWithMask> pm(Image::load(filename, m_tm.screenNum())); | 217 | std::auto_ptr<PixmapWithMask> pm(Image::load(filename, m_tm.screenNum())); |
200 | if (pm.get() == 0) | 218 | if (pm.get() == 0) |
201 | setDefaultValue(); | 219 | setDefaultValue(); |
202 | else { | 220 | else { |
@@ -208,22 +226,90 @@ setFromString(const char *str) { | |||
208 | 226 | ||
209 | 227 | ||
210 | template <> | 228 | template <> |
211 | void ThemeItem<FbTk::Color>::setDefaultValue() { | 229 | void ThemeItem<Color>::setDefaultValue() { |
212 | m_value.setFromString("white", m_tm.screenNum()); | 230 | m_value.setFromString("white", m_tm.screenNum()); |
213 | } | 231 | } |
214 | 232 | ||
215 | template <> | 233 | template <> |
216 | void ThemeItem<FbTk::Color>::setFromString(const char *str) { | 234 | void ThemeItem<Color>::setFromString(const char *str) { |
217 | if (!m_value.setFromString(str, m_tm.screenNum())) { | 235 | if (!m_value.setFromString(str, m_tm.screenNum())) { |
218 | if (FbTk::ThemeManager::instance().verbose()) | 236 | if (ThemeManager::instance().verbose()) |
219 | cerr<<"FbTk::Theme: Error loading color value for \""<<name()<<"\" or \""<<altName()<<"\"."<<endl; | 237 | cerr<<"Theme: Error loading color value for \""<<name()<<"\" or \""<<altName()<<"\"."<<endl; |
220 | setDefaultValue(); | 238 | setDefaultValue(); |
221 | } | 239 | } |
222 | } | 240 | } |
223 | 241 | ||
224 | // does nothing | 242 | // does nothing |
225 | template <> | 243 | template <> |
226 | void ThemeItem<FbTk::Color>::load(const std::string *name, const std::string *altname) { } | 244 | void ThemeItem<Color>::load(const string *name, const string *altname) { } |
245 | |||
246 | template<> | ||
247 | void ThemeItem<GContext::LineStyle>::setDefaultValue() { | ||
248 | *(*this) = GContext::LINESOLID; | ||
249 | } | ||
250 | |||
251 | template<> | ||
252 | void ThemeItem<GContext::LineStyle>::setFromString(char const *strval) { | ||
253 | |||
254 | if (strcasecmp(strval, "LineSolid") == 0 ) | ||
255 | m_value = GContext::LINESOLID; | ||
256 | else if (strcasecmp(strval, "LineOnOffDash") == 0 ) | ||
257 | m_value = GContext::LINEONOFFDASH; | ||
258 | else if (strcasecmp(strval, "LineDoubleDash") == 0) | ||
259 | m_value = GContext::LINEDOUBLEDASH; | ||
260 | else | ||
261 | setDefaultValue(); | ||
262 | } | ||
263 | |||
264 | template<> | ||
265 | void ThemeItem<GContext::LineStyle>::load(const string *name, const string *altname) { } | ||
266 | |||
267 | |||
268 | template<> | ||
269 | void ThemeItem<GContext::JoinStyle>::setDefaultValue() { | ||
270 | *(*this) = GContext::JOINMITER; | ||
271 | } | ||
272 | |||
273 | template<> | ||
274 | void ThemeItem<GContext::JoinStyle>::setFromString(char const *strval) { | ||
275 | |||
276 | if (strcasecmp(strval, "JoinRound") == 0 ) | ||
277 | m_value = GContext::JOINROUND; | ||
278 | else if (strcasecmp(strval, "JoinMiter") == 0 ) | ||
279 | m_value = GContext::JOINMITER; | ||
280 | else if (strcasecmp(strval, "JoinBevel") == 0) | ||
281 | m_value = GContext::JOINBEVEL; | ||
282 | else | ||
283 | setDefaultValue(); | ||
284 | } | ||
285 | |||
286 | template<> | ||
287 | void ThemeItem<GContext::JoinStyle>::load(const string *name, const string *altname) { } | ||
288 | |||
289 | template<> | ||
290 | void ThemeItem<GContext::CapStyle>::setDefaultValue() { | ||
291 | *(*this) = GContext::CAPNOTLAST; | ||
292 | } | ||
293 | |||
294 | template<> | ||
295 | void ThemeItem<GContext::CapStyle>::setFromString(char const *strval) { | ||
296 | |||
297 | if (strcasecmp(strval, "CapNotLast") == 0 ) | ||
298 | m_value = GContext::CAPNOTLAST; | ||
299 | else if (strcasecmp(strval, "CapProjecting") == 0 ) | ||
300 | m_value = GContext::CAPPROJECTING; | ||
301 | else if (strcasecmp(strval, "CapRound") == 0) | ||
302 | m_value = GContext::CAPROUND; | ||
303 | else if (strcasecmp(strval, "CapButt" ) == 0) | ||
304 | m_value = GContext::CAPBUTT; | ||
305 | else | ||
306 | setDefaultValue(); | ||
307 | } | ||
308 | |||
309 | template<> | ||
310 | void ThemeItem<GContext::CapStyle>::load(const string *name, const string *altname) { } | ||
311 | |||
312 | |||
227 | 313 | ||
228 | } // end namespace FbTk | 314 | } // end namespace FbTk |
229 | 315 | ||