aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/Theme.cc159
1 files changed, 2 insertions, 157 deletions
diff --git a/src/FbTk/Theme.cc b/src/FbTk/Theme.cc
index 0c13a9c..c554545 100644
--- a/src/FbTk/Theme.cc
+++ b/src/FbTk/Theme.cc
@@ -19,18 +19,14 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22// $Id: Theme.cc,v 1.19 2003/09/14 11:17:21 fluxgen Exp $ 22// $Id: Theme.cc,v 1.20 2003/10/13 22:57:14 fluxgen Exp $
23 23
24#include "Theme.hh" 24#include "Theme.hh"
25 25
26#include "XrmDatabaseHelper.hh" 26#include "XrmDatabaseHelper.hh"
27#include "Font.hh"
28#include "Color.hh"
29#include "Texture.hh"
30#include "App.hh" 27#include "App.hh"
31#include "Image.hh"
32#include "PixmapWithMask.hh"
33#include "StringUtil.hh" 28#include "StringUtil.hh"
29#include "ThemeItems.hh"
34 30
35#include <cstdio> 31#include <cstdio>
36#include <memory> 32#include <memory>
@@ -39,157 +35,6 @@ using namespace std;
39 35
40namespace FbTk { 36namespace FbTk {
41 37
42// create default handlers for Color, Font, Texture, int and string
43template <>
44void FbTk::ThemeItem<std::string>::load() { }
45
46template <>
47void FbTk::ThemeItem<std::string>::setDefaultValue() {
48 *(*this) = "";
49}
50
51template <>
52void FbTk::ThemeItem<std::string>::setFromString(const char *str) {
53 *(*this) = (str ? str : "");
54}
55
56template <>
57void FbTk::ThemeItem<int>::load() { }
58
59template <>
60void FbTk::ThemeItem<int>::setDefaultValue() {
61 *(*this) = 0;
62}
63
64template <>
65void FbTk::ThemeItem<int>::setFromString(const char *str) {
66 if (str == 0)
67 return;
68 sscanf(str, "%d", &m_value);
69}
70
71template <>
72void ThemeItem<FbTk::Font>::setDefaultValue() {
73 if (!m_value.load("fixed")) {
74 cerr<<"FbTk::ThemeItem<FbTk::Font>: Warning! Failed to load default value 'fixed'"<<endl;
75 }
76}
77
78template <>
79void ThemeItem<FbTk::Font>::setFromString(const char *str) {
80 if (m_value.load(str) == false) {
81 if (FbTk::ThemeManager::instance().verbose()) {
82 cerr<<"FbTk::Theme: Error loading font "<<
83 ((m_value.isAntialias() || m_value.utf8()) ? "(" : "")<<
84
85 (m_value.isAntialias() ? "antialias" : "")<<
86 (m_value.utf8() ? " utf8" : "")<<
87
88 ((m_value.isAntialias() || m_value.utf8()) ? ") " : "")<<
89 "for \""<<name()<<"\" or \""<<altName()<<"\": "<<str<<endl;
90
91 cerr<<"FbTk::Theme: Setting default value"<<endl;
92 }
93 setDefaultValue();
94 }
95
96}
97
98// do nothing
99template <>
100void ThemeItem<FbTk::Font>::load() {
101}
102
103
104template <>
105void ThemeItem<FbTk::Texture>::load() {
106 string color_name(ThemeManager::instance().
107 resourceValue(name()+".color", altName()+".Color"));
108 string colorto_name(ThemeManager::instance().
109 resourceValue(name()+".colorTo", altName()+".ColorTo"));
110 string pixmap_name(ThemeManager::instance().
111 resourceValue(name()+".pixmap", altName()+".Pixmap"));
112
113
114 // set default value if we failed to load color
115 if (!m_value.color().setFromString(color_name.c_str(), m_tm.screenNum()))
116 m_value.color().setFromString("darkgray", m_tm.screenNum());
117
118 if (!m_value.colorTo().setFromString(colorto_name.c_str(), m_tm.screenNum()))
119 m_value.colorTo().setFromString("white", m_tm.screenNum());
120
121
122 std::auto_ptr<PixmapWithMask> pm(Image::load(pixmap_name, m_tm.screenNum()));
123 if (pm.get() == 0) {
124 if (FbTk::ThemeManager::instance().verbose())
125 cerr<<"Resource("<<name()+".pixmap"<<"): Failed to load image: "<<pixmap_name<<endl;
126 m_value.pixmap() = 0;
127 } else
128 m_value.pixmap() = pm->pixmap().release();
129}
130
131template <>
132void ThemeItem<FbTk::Texture>::setDefaultValue() {
133 m_value.setType(FbTk::Texture::FLAT | FbTk::Texture::SOLID);
134 load(); // one might forget to add line something: so we try to load something.*: too
135}
136
137template <>
138void ThemeItem<FbTk::Texture>::setFromString(const char *str) {
139 m_value.setFromString(str);
140 if (m_value.type() == 0) // failed to set value
141 setDefaultValue();
142}
143
144
145
146// not used
147template <>
148void FbTk::ThemeItem<PixmapWithMask>::
149load() { }
150
151template <>
152void FbTk::ThemeItem<PixmapWithMask>::
153setDefaultValue() {
154 // create empty pixmap
155 (*this)->pixmap() = 0;
156 (*this)->mask() = 0;
157}
158
159template <>
160void FbTk::ThemeItem<PixmapWithMask>::
161setFromString(const char *str) {
162 if (str == 0)
163 setDefaultValue();
164 else {
165 std::auto_ptr<FbTk::PixmapWithMask> pm(Image::load(str, m_tm.screenNum()));
166 if (pm.get() == 0)
167 setDefaultValue();
168 else {
169 (*this)->pixmap() = pm->pixmap().release();
170 (*this)->mask() = pm->mask().release();
171 }
172 }
173}
174
175template <>
176void ThemeItem<FbTk::Color>::setDefaultValue() {
177 m_value.setFromString("white", m_tm.screenNum());
178}
179
180template <>
181void ThemeItem<FbTk::Color>::setFromString(const char *str) {
182 if (!m_value.setFromString(str, m_tm.screenNum())) {
183 if (FbTk::ThemeManager::instance().verbose())
184 cerr<<"FbTk::Theme: Error loading color value for \""<<name()<<"\" or \""<<altName()<<"\"."<<endl;
185 setDefaultValue();
186 }
187}
188
189// does nothing
190template <>
191void ThemeItem<FbTk::Color>::load() { }
192
193Theme::Theme(int screen_num):m_screen_num(screen_num) { 38Theme::Theme(int screen_num):m_screen_num(screen_num) {
194 ThemeManager::instance().registerTheme(*this); 39 ThemeManager::instance().registerTheme(*this);
195} 40}