aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorakir <akir>2004-10-21 16:44:06 (GMT)
committerakir <akir>2004-10-21 16:44:06 (GMT)
commita63a27886d7861d59352e0c4fe96f7d61c9925b4 (patch)
tree10dce66e4db697a93d5cd19bbfa62ddab36fe3c4 /src
parent4649df40843318f347691fddfcca7c2c88ea4bc7 (diff)
downloadfluxbox-a63a27886d7861d59352e0c4fe96f7d61c9925b4.zip
fluxbox-a63a27886d7861d59352e0c4fe96f7d61c9925b4.tar.bz2
moved ThemeItems.hh to ThemeItems.cc, solves some linkissues
Diffstat (limited to 'src')
-rw-r--r--src/FbTk/Makefile.am2
-rw-r--r--src/FbTk/ThemeItems.cc230
2 files changed, 231 insertions, 1 deletions
diff --git a/src/FbTk/Makefile.am b/src/FbTk/Makefile.am
index 478a8eb..49217bc 100644
--- a/src/FbTk/Makefile.am
+++ b/src/FbTk/Makefile.am
@@ -25,7 +25,7 @@ libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \
25 RefCount.hh SimpleCommand.hh SignalHandler.cc SignalHandler.hh \ 25 RefCount.hh SimpleCommand.hh SignalHandler.cc SignalHandler.hh \
26 Text.hh Text.cc \ 26 Text.hh Text.cc \
27 Texture.cc Texture.hh TextureRender.hh TextureRender.cc \ 27 Texture.cc Texture.hh TextureRender.hh TextureRender.cc \
28 Theme.hh Theme.cc ThemeItems.hh Timer.hh Timer.cc \ 28 Theme.hh Theme.cc ThemeItems.cc Timer.hh Timer.cc \
29 XFontImp.cc XFontImp.hh \ 29 XFontImp.cc XFontImp.hh \
30 Button.hh Button.cc \ 30 Button.hh Button.cc \
31 TextButton.hh TextButton.cc \ 31 TextButton.hh TextButton.cc \
diff --git a/src/FbTk/ThemeItems.cc b/src/FbTk/ThemeItems.cc
new file mode 100644
index 0000000..6f792cc
--- /dev/null
+++ b/src/FbTk/ThemeItems.cc
@@ -0,0 +1,230 @@
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.cc,v 1.1 2004/10/21 16:44:06 akir 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#include "StringUtil.hh"
36
37#include <string>
38#ifdef HAVE_CSTDIO
39 #include <cstdio>
40#else
41 #include <stdio.h>
42#endif
43#include <iostream>
44namespace FbTk {
45
46using namespace std;
47
48// create default handlers for Color, Font, Texture, int and string
49template <>
50void FbTk::ThemeItem<std::string>::load(const std::string *name, const std::string *altname) { }
51
52template <>
53void FbTk::ThemeItem<std::string>::setDefaultValue() {
54 *(*this) = "";
55}
56
57template <>
58void FbTk::ThemeItem<std::string>::setFromString(const char *str) {
59 *(*this) = (str ? str : "");
60}
61
62template <>
63void FbTk::ThemeItem<int>::load(const std::string *name, const std::string *altname) { }
64
65template<>
66void FbTk::ThemeItem<int>::setDefaultValue() {
67 *(*this) = 0;
68}
69
70template <>
71void FbTk::ThemeItem<int>::setFromString(const char *str) {
72 if (str == 0) {
73 setDefaultValue();
74 return;
75 }
76
77 if (sscanf(str, "%d", &m_value) < 1)
78 setDefaultValue();
79}
80
81template <>
82void ThemeItem<FbTk::Font>::setDefaultValue() {
83 if (!m_value.load("fixed")) {
84 cerr<<"FbTk::ThemeItem<FbTk::Font>: Warning! Failed to load default value 'fixed'"<<endl;
85 }
86}
87
88template <>
89void ThemeItem<FbTk::Font>::setFromString(const char *str) {
90
91 if (str == 0 || m_value.load(str) == false) {
92 if (FbTk::ThemeManager::instance().verbose()) {
93 cerr<<"FbTk::Theme: Error loading font "<<
94 ((m_value.isAntialias() || m_value.utf8()) ? "(" : "")<<
95
96 (m_value.isAntialias() ? "antialias" : "")<<
97 (m_value.utf8() ? " utf8" : "")<<
98
99 ((m_value.isAntialias() || m_value.utf8()) ? ") " : "")<<
100 "for \""<<name()<<"\" or \""<<altName()<<"\": "<<str<<endl;
101
102 cerr<<"FbTk::Theme: Setting default value"<<endl;
103 }
104 setDefaultValue();
105 }
106
107}
108
109// do nothing
110template <>
111void ThemeItem<FbTk::Font>::load(const std::string *name, const std::string *altname) {
112}
113
114
115template <>
116void ThemeItem<FbTk::Texture>::load(const std::string *o_name, const std::string *o_altname) {
117 const std::string &m_name = (o_name==0)?name():*o_name;
118 const std::string &m_altname = (o_altname==0)?altName():*o_altname;
119
120 string color_name(ThemeManager::instance().
121 resourceValue(m_name+".color", m_altname+".Color"));
122 string colorto_name(ThemeManager::instance().
123 resourceValue(m_name+".colorTo", m_altname+".ColorTo"));
124 string pixmap_name(ThemeManager::instance().
125 resourceValue(m_name+".pixmap", m_altname+".Pixmap"));
126
127
128 // set default value if we failed to load color
129 if (!m_value.color().setFromString(color_name.c_str(),
130 m_tm.screenNum()))
131 m_value.color().setFromString("darkgray", m_tm.screenNum());
132
133 if (!m_value.colorTo().setFromString(colorto_name.c_str(),
134 m_tm.screenNum()))
135 m_value.colorTo().setFromString("white", m_tm.screenNum());
136
137
138 if ((m_value.type() & FbTk::Texture::SOLID) != 0 && (m_value.type() & FbTk::Texture::FLAT) == 0)
139 m_value.calcHiLoColors(m_tm.screenNum());
140
141 StringUtil::removeFirstWhitespace(pixmap_name);
142 StringUtil::removeTrailingWhitespace(pixmap_name);
143 if (pixmap_name.empty()) {
144 m_value.pixmap() = 0;
145 return;
146 }
147
148 std::auto_ptr<FbTk::PixmapWithMask> pm(FbTk::Image::load(pixmap_name,
149 m_tm.screenNum()));
150 if (pm.get() == 0) {
151 if (FbTk::ThemeManager::instance().verbose()) {
152 cerr<<"Resource("<<m_name+".pixmap"
153 <<"): Failed to load image: "<<pixmap_name<<endl;
154 }
155 m_value.pixmap() = 0;
156 } else
157 m_value.pixmap() = pm->pixmap().release();
158
159}
160
161template <>
162void ThemeItem<FbTk::Texture>::setDefaultValue() {
163 m_value.setType(FbTk::Texture::FLAT | FbTk::Texture::SOLID);
164 load(); // one might forget to add line something: so we try to load something.*: too
165}
166
167template <>
168void ThemeItem<FbTk::Texture>::setFromString(const char *str) {
169 m_value.setFromString(str);
170 if (m_value.type() == 0) // failed to set value
171 setDefaultValue();
172}
173
174
175
176// not used
177template <>
178void FbTk::ThemeItem<PixmapWithMask>::load(const std::string *name, const std::string *altname) { }
179
180template <>
181void FbTk::ThemeItem<PixmapWithMask>::
182setDefaultValue() {
183 // create empty pixmap
184 (*this)->pixmap() = 0;
185 (*this)->mask() = 0;
186}
187
188template <>
189void FbTk::ThemeItem<PixmapWithMask>::
190setFromString(const char *str) {
191 if (str == 0)
192 setDefaultValue();
193 else {
194 std::string filename(str);
195
196 StringUtil::removeFirstWhitespace(filename);
197 StringUtil::removeTrailingWhitespace(filename);
198
199 std::auto_ptr<FbTk::PixmapWithMask> pm(Image::load(filename, m_tm.screenNum()));
200 if (pm.get() == 0)
201 setDefaultValue();
202 else {
203 (*this)->pixmap() = pm->pixmap().release();
204 (*this)->mask() = pm->mask().release();
205 }
206 }
207}
208
209
210template <>
211void ThemeItem<FbTk::Color>::setDefaultValue() {
212 m_value.setFromString("white", m_tm.screenNum());
213}
214
215template <>
216void ThemeItem<FbTk::Color>::setFromString(const char *str) {
217 if (!m_value.setFromString(str, m_tm.screenNum())) {
218 if (FbTk::ThemeManager::instance().verbose())
219 cerr<<"FbTk::Theme: Error loading color value for \""<<name()<<"\" or \""<<altName()<<"\"."<<endl;
220 setDefaultValue();
221 }
222}
223
224// does nothing
225template <>
226void ThemeItem<FbTk::Color>::load(const std::string *name, const std::string *altname) { }
227
228} // end namespace FbTk
229
230#endif // THEMEITEMS_HH