1
// ThemeItems.cc for FbTk - Fluxbox ToolKit
2
// Copyright (c) 2002 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org)
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:
11
// The above copyright notice and this permission notice shall be included in
12
// all copies or substantial portions of the Software.
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.
22
// $Id: ThemeItems.cc 4107 2005-09-14 19:22:59Z fluxgen $
24
/// @file implements common theme items
31
#endif // HAVE_CONFIG_H
37
#include "GContext.hh"
38
#include "PixmapWithMask.hh"
40
#include "StringUtil.hh"
59
// create default handlers for Color, Font, Texture, int and string
61
void ThemeItem<string>::load(const string *name, const string *altname) { }
64
void ThemeItem<string>::setDefaultValue() {
69
void ThemeItem<string>::setFromString(const char *str) {
70
*(*this) = (str ? str : "");
74
void ThemeItem<int>::load(const string *name, const string *altname) { }
77
void ThemeItem<int>::setDefaultValue() {
82
void ThemeItem<int>::setFromString(const char *str) {
88
if (sscanf(str, "%d", &m_value) < 1)
92
void FbTk::ThemeItem<bool>::load(const std::string *name, const std::string *altname) { }
95
void FbTk::ThemeItem<bool>::setDefaultValue() {
100
void FbTk::ThemeItem<bool>::setFromString(char const *strval) {
101
if (strcasecmp(strval, "true")==0)
108
void ThemeItem<unsigned int>::setDefaultValue() {
113
void ThemeItem<unsigned int>::setFromString(const char *str) {
114
sscanf(str, "%d", &m_value);
118
void ThemeItem<unsigned int>::load(const std::string *name, const std::string *altname) {
122
void ThemeItem<Font>::setDefaultValue() {
123
if (!m_value.load("fixed")) {
124
cerr<<"ThemeItem<Font>: Warning! Failed to load default value 'fixed'"<<endl;
126
string effect(ThemeManager::instance().resourceValue(name()+".effect", altName()+".Effect"));
127
if (effect == "halo") {
128
m_value.setHalo(true);
129
FbTk::Color halo_color(ThemeManager::instance().resourceValue(name()+".halo.color", altName()+".Halo.Color").c_str(),
130
theme().screenNum());
131
m_value.setHaloColor(halo_color);
133
} else if (effect == "shadow" ) {
134
FbTk::Color shadow_color(ThemeManager::instance().resourceValue(name()+".shadow.color", altName()+".Shadow.Color").c_str(),
135
theme().screenNum());
137
m_value.setShadow(true);
138
m_value.setShadowColor(shadow_color);
139
m_value.setShadowOffX(atoi(ThemeManager::instance().resourceValue(name()+".shadow.x", altName()+".Shadow.X").c_str()));
140
m_value.setShadowOffY(atoi(ThemeManager::instance().resourceValue(name()+".shadow.y", altName()+".Shadow.Y").c_str()));
146
void ThemeItem<Font>::setFromString(const char *str) {
148
if (str == 0 || m_value.load(str) == false) {
149
if (ThemeManager::instance().verbose()) {
150
cerr<<"Theme: Error loading font "<<
151
((m_value.utf8()) ? "(utf8)" : "")<<
152
"for \""<<name()<<"\" or \""<<altName()<<"\": "<<str<<endl;
154
cerr<<"Theme: Setting default value"<<endl;
158
string effect(ThemeManager::instance().resourceValue(name()+".effect", altName()+".Effect"));
159
if (effect == "halo") {
160
m_value.setHalo(true);
161
FbTk::Color halo_color(ThemeManager::instance().resourceValue(name()+".halo.color", altName()+".Halo.Color").c_str(),
162
theme().screenNum());
163
m_value.setHaloColor(halo_color);
165
} else if (effect == "shadow" ) {
166
FbTk::Color shadow_color(ThemeManager::instance().resourceValue(name()+".shadow.color", altName()+".Shadow.Color").c_str(),
167
theme().screenNum());
169
m_value.setShadow(true);
170
m_value.setShadowColor(shadow_color);
172
int offset_x = atoi(ThemeManager::instance().resourceValue(name()+".shadow.x", altName()+".Shadow.X").c_str());
173
int offset_y = atoi(ThemeManager::instance().resourceValue(name()+".shadow.y", altName()+".Shadow.Y").c_str());
175
m_value.setShadowOffX(offset_x);
177
m_value.setShadowOffY(offset_y);
184
void ThemeItem<Font>::load(const string *name, const string *altname) {
189
void ThemeItem<Texture>::load(const string *o_name, const string *o_altname) {
190
const string &m_name = (o_name==0)?name():*o_name;
191
const string &m_altname = (o_altname==0)?altName():*o_altname;
193
string color_name(ThemeManager::instance().
194
resourceValue(m_name+".color", m_altname+".Color"));
195
string colorto_name(ThemeManager::instance().
196
resourceValue(m_name+".colorTo", m_altname+".ColorTo"));
197
string pixmap_name(ThemeManager::instance().
198
resourceValue(m_name+".pixmap", m_altname+".Pixmap"));
201
// set default value if we failed to load color
202
if (!m_value.color().setFromString(color_name.c_str(),
204
m_value.color().setFromString("darkgray", m_tm.screenNum());
206
if (!m_value.colorTo().setFromString(colorto_name.c_str(),
208
m_value.colorTo().setFromString("white", m_tm.screenNum());
211
if ((m_value.type() & Texture::SOLID) != 0 && (m_value.type() & Texture::FLAT) == 0)
212
m_value.calcHiLoColors(m_tm.screenNum());
214
StringUtil::removeFirstWhitespace(pixmap_name);
215
StringUtil::removeTrailingWhitespace(pixmap_name);
216
if (pixmap_name.empty()) {
217
m_value.pixmap() = 0;
221
std::auto_ptr<PixmapWithMask> pm(Image::load(pixmap_name,
224
if (ThemeManager::instance().verbose()) {
225
cerr<<"Resource("<<m_name+".pixmap"
226
<<"): Failed to load image: "<<pixmap_name<<endl;
228
m_value.pixmap() = 0;
230
m_value.pixmap() = pm->pixmap().release();
235
void ThemeItem<Texture>::setDefaultValue() {
236
m_value.setType(Texture::FLAT | Texture::SOLID);
237
load(); // one might forget to add line something: so we try to load something.*: too
241
void ThemeItem<Texture>::setFromString(const char *str) {
242
m_value.setFromString(str);
243
if (m_value.type() == 0) // failed to set value
251
void ThemeItem<PixmapWithMask>::load(const string *name, const string *altname) { }
254
void ThemeItem<PixmapWithMask>::setDefaultValue() {
255
// create empty pixmap
256
(*this)->pixmap() = 0;
261
void ThemeItem<PixmapWithMask>::
262
setFromString(const char *str) {
266
string filename(str);
268
StringUtil::removeFirstWhitespace(filename);
269
StringUtil::removeTrailingWhitespace(filename);
271
std::auto_ptr<PixmapWithMask> pm(Image::load(filename, m_tm.screenNum()));
275
(*this)->pixmap() = pm->pixmap().release();
276
(*this)->mask() = pm->mask().release();
283
void ThemeItem<Color>::setDefaultValue() {
284
m_value.setFromString("white", m_tm.screenNum());
288
void ThemeItem<Color>::setFromString(const char *str) {
289
if (!m_value.setFromString(str, m_tm.screenNum())) {
290
if (ThemeManager::instance().verbose())
291
cerr<<"Theme: Error loading color value for \""<<name()<<"\" or \""<<altName()<<"\"."<<endl;
298
void ThemeItem<Color>::load(const string *name, const string *altname) { }
301
void ThemeItem<GContext::LineStyle>::setDefaultValue() {
302
*(*this) = GContext::LINESOLID;
306
void ThemeItem<GContext::LineStyle>::setFromString(char const *strval) {
308
if (strcasecmp(strval, "LineSolid") == 0 )
309
m_value = GContext::LINESOLID;
310
else if (strcasecmp(strval, "LineOnOffDash") == 0 )
311
m_value = GContext::LINEONOFFDASH;
312
else if (strcasecmp(strval, "LineDoubleDash") == 0)
313
m_value = GContext::LINEDOUBLEDASH;
319
void ThemeItem<GContext::LineStyle>::load(const string *name, const string *altname) { }
323
void ThemeItem<GContext::JoinStyle>::setDefaultValue() {
324
*(*this) = GContext::JOINMITER;
328
void ThemeItem<GContext::JoinStyle>::setFromString(char const *strval) {
330
if (strcasecmp(strval, "JoinRound") == 0 )
331
m_value = GContext::JOINROUND;
332
else if (strcasecmp(strval, "JoinMiter") == 0 )
333
m_value = GContext::JOINMITER;
334
else if (strcasecmp(strval, "JoinBevel") == 0)
335
m_value = GContext::JOINBEVEL;
341
void ThemeItem<GContext::JoinStyle>::load(const string *name, const string *altname) { }
344
void ThemeItem<GContext::CapStyle>::setDefaultValue() {
345
*(*this) = GContext::CAPNOTLAST;
349
void ThemeItem<GContext::CapStyle>::setFromString(char const *strval) {
351
if (strcasecmp(strval, "CapNotLast") == 0 )
352
m_value = GContext::CAPNOTLAST;
353
else if (strcasecmp(strval, "CapProjecting") == 0 )
354
m_value = GContext::CAPPROJECTING;
355
else if (strcasecmp(strval, "CapRound") == 0)
356
m_value = GContext::CAPROUND;
357
else if (strcasecmp(strval, "CapButt" ) == 0)
358
m_value = GContext::CAPBUTT;
364
void ThemeItem<GContext::CapStyle>::load(const string *name, const string *altname) { }
368
} // end namespace FbTk
370
#endif // THEMEITEMS_HH