aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-08-13 09:24:02 (GMT)
committerfluxgen <fluxgen>2003-08-13 09:24:02 (GMT)
commit34a392c138236186707e27d9bc8e6227006f1be0 (patch)
treeb6621f103252986a6a81d0d6836a6be91f7922c3
parent72b654992d5c38b4bc5d19cfe0e580b2bdbc5eca (diff)
downloadfluxbox-34a392c138236186707e27d9bc8e6227006f1be0.zip
fluxbox-34a392c138236186707e27d9bc8e6227006f1be0.tar.bz2
default values for texture items and added loadItem function
-rw-r--r--src/FbTk/Theme.cc51
1 files changed, 31 insertions, 20 deletions
diff --git a/src/FbTk/Theme.cc b/src/FbTk/Theme.cc
index b1f45fb..0121eb5 100644
--- a/src/FbTk/Theme.cc
+++ b/src/FbTk/Theme.cc
@@ -19,7 +19,7 @@
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.10 2003/08/11 14:54:18 fluxgen Exp $ 22// $Id: Theme.cc,v 1.11 2003/08/13 09:24:02 fluxgen Exp $
23 23
24#include "Theme.hh" 24#include "Theme.hh"
25 25
@@ -103,16 +103,18 @@ template <>
103void ThemeItem<FbTk::Font>::load() { 103void ThemeItem<FbTk::Font>::load() {
104} 104}
105 105
106template <>
107void ThemeItem<FbTk::Texture>::setDefaultValue() {
108 m_value.setType(FbTk::Texture::FLAT | FbTk::Texture::SOLID);
109}
106 110
107template <> 111template <>
108void ThemeItem<FbTk::Texture>::setFromString(const char *str) { 112void ThemeItem<FbTk::Texture>::setFromString(const char *str) {
109 m_value.setFromString(str); 113 m_value.setFromString(str);
114 if (m_value.type() == 0) // failed to set value
115 setDefaultValue();
110} 116}
111 117
112template <>
113void ThemeItem<FbTk::Texture>::setDefaultValue() {
114 m_value.setType(0);
115}
116 118
117template <> 119template <>
118void ThemeItem<FbTk::Texture>::load() { 120void ThemeItem<FbTk::Texture>::load() {
@@ -123,8 +125,14 @@ void ThemeItem<FbTk::Texture>::load() {
123 string pixmap_name(ThemeManager::instance(). 125 string pixmap_name(ThemeManager::instance().
124 resourceValue(name()+".pixmap", altName()+".Pixmap")); 126 resourceValue(name()+".pixmap", altName()+".Pixmap"));
125 127
126 m_value.color().setFromString(color_name.c_str(), m_tm.screenNum()); 128
127 m_value.colorTo().setFromString(colorto_name.c_str(), m_tm.screenNum()); 129 // set default value if we failed to load color
130 if (!m_value.color().setFromString(color_name.c_str(), m_tm.screenNum()))
131 m_value.color().setFromString("darkgray", m_tm.screenNum());
132
133 if (!m_value.colorTo().setFromString(colorto_name.c_str(), m_tm.screenNum()))
134 m_value.colorTo().setFromString("white", m_tm.screenNum());
135
128 136
129#ifdef HAVE_XPM 137#ifdef HAVE_XPM
130 XpmAttributes xpm_attr; 138 XpmAttributes xpm_attr;
@@ -233,27 +241,30 @@ bool ThemeManager::load(const std::string &filename) {
233} 241}
234 242
235void ThemeManager::loadTheme(Theme &tm) { 243void ThemeManager::loadTheme(Theme &tm) {
236
237 XrmValue value;
238 char *value_type;
239
240 std::list<ThemeItem_base *>::iterator i = tm.itemList().begin(); 244 std::list<ThemeItem_base *>::iterator i = tm.itemList().begin();
241 std::list<ThemeItem_base *>::iterator i_end = tm.itemList().end(); 245 std::list<ThemeItem_base *>::iterator i_end = tm.itemList().end();
242 for (; i != i_end; ++i) { 246 for (; i != i_end; ++i) {
243 ThemeItem_base *resource = *i; 247 ThemeItem_base *resource = *i;
244 if (XrmGetResource(*m_database, resource->name().c_str(), 248 loadItem(*resource);
245 resource->altName().c_str(), &value_type, &value)) {
246 resource->setFromString(value.addr);
247 resource->load(); // load additional stuff by the ThemeItem
248 } else {
249 cerr<<"Failed to read theme item: "<<resource->name()<<endl;
250 cerr<<"Setting default value"<<endl;
251 resource->setDefaultValue();
252 }
253 } 249 }
254 // send reconfiguration signal to theme and listeners 250 // send reconfiguration signal to theme and listeners
255} 251}
256 252
253void ThemeManager::loadItem(ThemeItem_base &resource) {
254 XrmValue value;
255 char *value_type;
256
257 if (XrmGetResource(*m_database, resource.name().c_str(),
258 resource.altName().c_str(), &value_type, &value)) {
259 resource.setFromString(value.addr);
260 resource.load(); // load additional stuff by the ThemeItem
261 } else {
262 cerr<<"Failed to read theme item: "<<resource.name()<<endl;
263 cerr<<"Setting default value"<<endl;
264 resource.setDefaultValue();
265 }
266}
267
257std::string ThemeManager::resourceValue(const std::string &name, const std::string &altname) { 268std::string ThemeManager::resourceValue(const std::string &name, const std::string &altname) {
258 XrmValue value; 269 XrmValue value;
259 char *value_type; 270 char *value_type;