From 34a392c138236186707e27d9bc8e6227006f1be0 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Wed, 13 Aug 2003 09:24:02 +0000 Subject: default values for texture items and added loadItem function --- src/FbTk/Theme.cc | 51 +++++++++++++++++++++++++++++++-------------------- 1 file 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 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Theme.cc,v 1.10 2003/08/11 14:54:18 fluxgen Exp $ +// $Id: Theme.cc,v 1.11 2003/08/13 09:24:02 fluxgen Exp $ #include "Theme.hh" @@ -103,16 +103,18 @@ template <> void ThemeItem::load() { } +template <> +void ThemeItem::setDefaultValue() { + m_value.setType(FbTk::Texture::FLAT | FbTk::Texture::SOLID); +} template <> void ThemeItem::setFromString(const char *str) { m_value.setFromString(str); + if (m_value.type() == 0) // failed to set value + setDefaultValue(); } -template <> -void ThemeItem::setDefaultValue() { - m_value.setType(0); -} template <> void ThemeItem::load() { @@ -123,8 +125,14 @@ void ThemeItem::load() { string pixmap_name(ThemeManager::instance(). resourceValue(name()+".pixmap", altName()+".Pixmap")); - m_value.color().setFromString(color_name.c_str(), m_tm.screenNum()); - m_value.colorTo().setFromString(colorto_name.c_str(), m_tm.screenNum()); + + // set default value if we failed to load color + if (!m_value.color().setFromString(color_name.c_str(), m_tm.screenNum())) + m_value.color().setFromString("darkgray", m_tm.screenNum()); + + if (!m_value.colorTo().setFromString(colorto_name.c_str(), m_tm.screenNum())) + m_value.colorTo().setFromString("white", m_tm.screenNum()); + #ifdef HAVE_XPM XpmAttributes xpm_attr; @@ -233,27 +241,30 @@ bool ThemeManager::load(const std::string &filename) { } void ThemeManager::loadTheme(Theme &tm) { - - XrmValue value; - char *value_type; - std::list::iterator i = tm.itemList().begin(); std::list::iterator i_end = tm.itemList().end(); for (; i != i_end; ++i) { ThemeItem_base *resource = *i; - if (XrmGetResource(*m_database, resource->name().c_str(), - resource->altName().c_str(), &value_type, &value)) { - resource->setFromString(value.addr); - resource->load(); // load additional stuff by the ThemeItem - } else { - cerr<<"Failed to read theme item: "<name()<setDefaultValue(); - } + loadItem(*resource); } // send reconfiguration signal to theme and listeners } +void ThemeManager::loadItem(ThemeItem_base &resource) { + XrmValue value; + char *value_type; + + if (XrmGetResource(*m_database, resource.name().c_str(), + resource.altName().c_str(), &value_type, &value)) { + resource.setFromString(value.addr); + resource.load(); // load additional stuff by the ThemeItem + } else { + cerr<<"Failed to read theme item: "<