fixed load item

This commit is contained in:
fluxgen 2003-08-19 21:25:26 +00:00
parent ce77642a0e
commit 46ea237c38
2 changed files with 27 additions and 12 deletions

View file

@ -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.11 2003/08/13 09:24:02 fluxgen Exp $
// $Id: Theme.cc,v 1.12 2003/08/19 21:25:26 fluxgen Exp $
#include "Theme.hh"
@ -245,24 +245,35 @@ void ThemeManager::loadTheme(Theme &tm) {
std::list<ThemeItem_base *>::iterator i_end = tm.itemList().end();
for (; i != i_end; ++i) {
ThemeItem_base *resource = *i;
loadItem(*resource);
if (!loadItem(*resource)) {
// try fallback resource in theme
if (!tm.fallback(*resource)) {
cerr<<"Failed to read theme item: "<<resource->name()<<endl;
cerr<<"Setting default value"<<endl;
resource->setDefaultValue();
}
}
}
// send reconfiguration signal to theme and listeners
}
void ThemeManager::loadItem(ThemeItem_base &resource) {
bool ThemeManager::loadItem(ThemeItem_base &resource) {
return loadItem(resource, resource.name(), resource.altName());
}
/// handles resource item loading with specific name/altname
bool ThemeManager::loadItem(ThemeItem_base &resource, const std::string &name, const std::string &alt_name) {
XrmValue value;
char *value_type;
if (XrmGetResource(*m_database, resource.name().c_str(),
resource.altName().c_str(), &value_type, &value)) {
if (XrmGetResource(*m_database, name.c_str(),
alt_name.c_str(), &value_type, &value)) {
resource.setFromString(value.addr);
resource.load(); // load additional stuff by the ThemeItem
} else {
cerr<<"Failed to read theme item: "<<resource.name()<<endl;
cerr<<"Setting default value"<<endl;
resource.setDefaultValue();
}
} else
return false;
return true;
}
std::string ThemeManager::resourceValue(const std::string &name, const std::string &altname) {

View file

@ -19,7 +19,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// $Id: Theme.hh,v 1.6 2003/08/13 09:24:33 fluxgen Exp $
// $Id: Theme.hh,v 1.7 2003/08/19 21:25:26 fluxgen Exp $
/**
@file holds ThemeItem<T>, Theme and ThemeManager which is the base for any theme
@ -80,6 +80,8 @@ public:
inline T *operator->() { return &m_value; }
inline const T *operator->() const { return &m_value; }
/**@}*/
FbTk::Theme &theme() { return m_tm; }
private:
T m_value;
@ -102,6 +104,7 @@ public:
/// remove ThemeItem
template <typename T>
void remove(ThemeItem<T> &item);
virtual bool fallback(ThemeItem_base &base) { return false; }
FbTk::Subject &reconfigSig() { return m_reconfig_sig; }
private:
const int m_screen_num;
@ -121,7 +124,8 @@ public:
bool load(const std::string &filename);
std::string resourceValue(const std::string &name, const std::string &altname);
void loadTheme(Theme &tm);
void loadItem(ThemeItem_base &resource);
bool loadItem(ThemeItem_base &resource);
bool loadItem(ThemeItem_base &resource, const std::string &name, const std::string &altname);
private:
ThemeManager();
~ThemeManager() { }