aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/ThemeItems.hh196
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>
39namespace FbTk {
40
41using namespace std;
42
43// create default handlers for Color, Font, Texture, int and string
44template <>
45void FbTk::ThemeItem<std::string>::load() { }
46
47template <>
48void FbTk::ThemeItem<std::string>::setDefaultValue() {
49 *(*this) = "";
50}
51
52template <>
53void FbTk::ThemeItem<std::string>::setFromString(const char *str) {
54 *(*this) = (str ? str : "");
55}
56
57template <>
58void FbTk::ThemeItem<int>::load() { }
59
60template <>
61void FbTk::ThemeItem<int>::setDefaultValue() {
62 *(*this) = 0;
63}
64
65template <>
66void FbTk::ThemeItem<int>::setFromString(const char *str) {
67 if (str == 0)
68 return;
69 sscanf(str, "%d", &m_value);
70}
71
72template <>
73void 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
79template <>
80void 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
100template <>
101void ThemeItem<FbTk::Font>::load() {
102}
103
104
105template <>
106void 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
132template <>
133void 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
138template <>
139void 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
148template <>
149void FbTk::ThemeItem<PixmapWithMask>::
150load() { }
151
152template <>
153void FbTk::ThemeItem<PixmapWithMask>::
154setDefaultValue() {
155 // create empty pixmap
156 (*this)->pixmap() = 0;
157 (*this)->mask() = 0;
158}
159
160template <>
161void FbTk::ThemeItem<PixmapWithMask>::
162setFromString(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
176template <>
177void ThemeItem<FbTk::Color>::setDefaultValue() {
178 m_value.setFromString("white", m_tm.screenNum());
179}
180
181template <>
182void 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
191template <>
192void ThemeItem<FbTk::Color>::load() { }
193
194};
195
196#endif // THEMEITEMS_HH