diff options
author | fluxgen <fluxgen> | 2003-10-13 22:57:14 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2003-10-13 22:57:14 (GMT) |
commit | 481202b91d7b77d8d8bac4d47b59fc4634dd656f (patch) | |
tree | 44ca06a21e984eb867df54a9afa7b95cbeeb43b7 /src/FbTk/Theme.cc | |
parent | 75c98b0c8d60804a2b34b2294b4f40a7bd32ca4e (diff) | |
download | fluxbox-481202b91d7b77d8d8bac4d47b59fc4634dd656f.zip fluxbox-481202b91d7b77d8d8bac4d47b59fc4634dd656f.tar.bz2 |
cleaning, moved theme items to ThemeItems.hh
Diffstat (limited to 'src/FbTk/Theme.cc')
-rw-r--r-- | src/FbTk/Theme.cc | 159 |
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 | ||
40 | namespace FbTk { | 36 | namespace FbTk { |
41 | 37 | ||
42 | // create default handlers for Color, Font, Texture, int and string | ||
43 | template <> | ||
44 | void FbTk::ThemeItem<std::string>::load() { } | ||
45 | |||
46 | template <> | ||
47 | void FbTk::ThemeItem<std::string>::setDefaultValue() { | ||
48 | *(*this) = ""; | ||
49 | } | ||
50 | |||
51 | template <> | ||
52 | void FbTk::ThemeItem<std::string>::setFromString(const char *str) { | ||
53 | *(*this) = (str ? str : ""); | ||
54 | } | ||
55 | |||
56 | template <> | ||
57 | void FbTk::ThemeItem<int>::load() { } | ||
58 | |||
59 | template <> | ||
60 | void FbTk::ThemeItem<int>::setDefaultValue() { | ||
61 | *(*this) = 0; | ||
62 | } | ||
63 | |||
64 | template <> | ||
65 | void FbTk::ThemeItem<int>::setFromString(const char *str) { | ||
66 | if (str == 0) | ||
67 | return; | ||
68 | sscanf(str, "%d", &m_value); | ||
69 | } | ||
70 | |||
71 | template <> | ||
72 | void 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 | |||
78 | template <> | ||
79 | void 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 | ||
99 | template <> | ||
100 | void ThemeItem<FbTk::Font>::load() { | ||
101 | } | ||
102 | |||
103 | |||
104 | template <> | ||
105 | void 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 | |||
131 | template <> | ||
132 | void 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 | |||
137 | template <> | ||
138 | void 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 | ||
147 | template <> | ||
148 | void FbTk::ThemeItem<PixmapWithMask>:: | ||
149 | load() { } | ||
150 | |||
151 | template <> | ||
152 | void FbTk::ThemeItem<PixmapWithMask>:: | ||
153 | setDefaultValue() { | ||
154 | // create empty pixmap | ||
155 | (*this)->pixmap() = 0; | ||
156 | (*this)->mask() = 0; | ||
157 | } | ||
158 | |||
159 | template <> | ||
160 | void FbTk::ThemeItem<PixmapWithMask>:: | ||
161 | setFromString(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 | |||
175 | template <> | ||
176 | void ThemeItem<FbTk::Color>::setDefaultValue() { | ||
177 | m_value.setFromString("white", m_tm.screenNum()); | ||
178 | } | ||
179 | |||
180 | template <> | ||
181 | void 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 | ||
190 | template <> | ||
191 | void ThemeItem<FbTk::Color>::load() { } | ||
192 | |||
193 | Theme::Theme(int screen_num):m_screen_num(screen_num) { | 38 | Theme::Theme(int screen_num):m_screen_num(screen_num) { |
194 | ThemeManager::instance().registerTheme(*this); | 39 | ThemeManager::instance().registerTheme(*this); |
195 | } | 40 | } |