aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/FbTk/ThemeItems.cc154
-rw-r--r--src/ToolbarTheme.cc16
2 files changed, 120 insertions, 50 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>
44namespace FbTk { 45namespace FbTk {
45 46
46using namespace std; 47using std::string;
48using std::cerr;
49using 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
49template <> 53template <>
50void FbTk::ThemeItem<std::string>::load(const std::string *name, const std::string *altname) { } 54void ThemeItem<string>::load(const string *name, const string *altname) { }
51 55
52template <> 56template <>
53void FbTk::ThemeItem<std::string>::setDefaultValue() { 57void ThemeItem<string>::setDefaultValue() {
54 *(*this) = ""; 58 *(*this) = "";
55} 59}
56 60
57template <> 61template <>
58void FbTk::ThemeItem<std::string>::setFromString(const char *str) { 62void ThemeItem<string>::setFromString(const char *str) {
59 *(*this) = (str ? str : ""); 63 *(*this) = (str ? str : "");
60} 64}
61 65
62template <> 66template <>
63void FbTk::ThemeItem<int>::load(const std::string *name, const std::string *altname) { } 67void ThemeItem<int>::load(const string *name, const string *altname) { }
64 68
65template<> 69template<>
66void FbTk::ThemeItem<int>::setDefaultValue() { 70void ThemeItem<int>::setDefaultValue() {
67 *(*this) = 0; 71 *(*this) = 0;
68} 72}
69 73
70template <> 74template <>
71void FbTk::ThemeItem<int>::setFromString(const char *str) { 75void 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}
84template<>
85void FbTk::ThemeItem<bool>::load(const std::string *name, const std::string *altname) { }
86
87template<>
88void FbTk::ThemeItem<bool>::setDefaultValue() {
89 *(*this) = false;
90}
91
92template<>
93void FbTk::ThemeItem<bool>::setFromString(char const *strval) {
94 if (strcasecmp(strval, "true")==0)
95 *(*this) = true;
96 else
97 *(*this) = false;
98}
80 99
81template <> 100template <>
82void ThemeItem<FbTk::Font>::setDefaultValue() { 101void 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
88template <> 107template <>
89void ThemeItem<FbTk::Font>::setFromString(const char *str) { 108void 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
110template <> 129template <>
111void ThemeItem<FbTk::Font>::load(const std::string *name, const std::string *altname) { 130void ThemeItem<Font>::load(const string *name, const string *altname) {
112} 131}
113 132
114 133
115template <> 134template <>
116void ThemeItem<FbTk::Texture>::load(const std::string *o_name, const std::string *o_altname) { 135void 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
161template <> 180template <>
162void ThemeItem<FbTk::Texture>::setDefaultValue() { 181void 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
167template <> 186template <>
168void ThemeItem<FbTk::Texture>::setFromString(const char *str) { 187void 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
177template <> 196template <>
178void FbTk::ThemeItem<PixmapWithMask>::load(const std::string *name, const std::string *altname) { } 197void ThemeItem<PixmapWithMask>::load(const string *name, const string *altname) { }
179 198
180template <> 199template <>
181void FbTk::ThemeItem<PixmapWithMask>:: 200void ThemeItem<PixmapWithMask>::setDefaultValue() {
182setDefaultValue() {
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
188template <> 206template <>
189void FbTk::ThemeItem<PixmapWithMask>:: 207void ThemeItem<PixmapWithMask>::
190setFromString(const char *str) { 208setFromString(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
210template <> 228template <>
211void ThemeItem<FbTk::Color>::setDefaultValue() { 229void ThemeItem<Color>::setDefaultValue() {
212 m_value.setFromString("white", m_tm.screenNum()); 230 m_value.setFromString("white", m_tm.screenNum());
213} 231}
214 232
215template <> 233template <>
216void ThemeItem<FbTk::Color>::setFromString(const char *str) { 234void 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
225template <> 243template <>
226void ThemeItem<FbTk::Color>::load(const std::string *name, const std::string *altname) { } 244void ThemeItem<Color>::load(const string *name, const string *altname) { }
245
246template<>
247void ThemeItem<GContext::LineStyle>::setDefaultValue() {
248 *(*this) = GContext::LINESOLID;
249}
250
251template<>
252void 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
264template<>
265void ThemeItem<GContext::LineStyle>::load(const string *name, const string *altname) { }
266
267
268template<>
269void ThemeItem<GContext::JoinStyle>::setDefaultValue() {
270 *(*this) = GContext::JOINMITER;
271}
272
273template<>
274void 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
286template<>
287void ThemeItem<GContext::JoinStyle>::load(const string *name, const string *altname) { }
288
289template<>
290void ThemeItem<GContext::CapStyle>::setDefaultValue() {
291 *(*this) = GContext::CAPNOTLAST;
292}
293
294template<>
295void 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
309template<>
310void ThemeItem<GContext::CapStyle>::load(const string *name, const string *altname) { }
311
312
227 313
228} // end namespace FbTk 314} // end namespace FbTk
229 315
diff --git a/src/ToolbarTheme.cc b/src/ToolbarTheme.cc
index 33b8db6..cb92ae9 100644
--- a/src/ToolbarTheme.cc
+++ b/src/ToolbarTheme.cc
@@ -28,22 +28,6 @@
28#include <iostream> 28#include <iostream>
29using namespace std; 29using namespace std;
30 30
31template<>
32void FbTk::ThemeItem<bool>::load(const std::string *name, const std::string *altname) { }
33
34template<>
35void FbTk::ThemeItem<bool>::setDefaultValue() {
36 *(*this) = false;
37}
38
39template<>
40void FbTk::ThemeItem<bool>::setFromString(char const *strval) {
41 if (strcasecmp(strval, "true")==0)
42 *(*this) = true;
43 else
44 *(*this) = false;
45}
46
47ToolbarTheme::ToolbarTheme(int screen_num): 31ToolbarTheme::ToolbarTheme(int screen_num):
48 FbTk::Theme(screen_num), 32 FbTk::Theme(screen_num),
49 m_toolbar(*this, "toolbar", "Toolbar"), 33 m_toolbar(*this, "toolbar", "Toolbar"),