cleaning, moved theme items to ThemeItems.hh
This commit is contained in:
parent
75c98b0c8d
commit
481202b91d
1 changed files with 2 additions and 157 deletions
|
@ -19,18 +19,14 @@
|
|||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// $Id: Theme.cc,v 1.19 2003/09/14 11:17:21 fluxgen Exp $
|
||||
// $Id: Theme.cc,v 1.20 2003/10/13 22:57:14 fluxgen Exp $
|
||||
|
||||
#include "Theme.hh"
|
||||
|
||||
#include "XrmDatabaseHelper.hh"
|
||||
#include "Font.hh"
|
||||
#include "Color.hh"
|
||||
#include "Texture.hh"
|
||||
#include "App.hh"
|
||||
#include "Image.hh"
|
||||
#include "PixmapWithMask.hh"
|
||||
#include "StringUtil.hh"
|
||||
#include "ThemeItems.hh"
|
||||
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
|
@ -39,157 +35,6 @@ using namespace std;
|
|||
|
||||
namespace FbTk {
|
||||
|
||||
// create default handlers for Color, Font, Texture, int and string
|
||||
template <>
|
||||
void FbTk::ThemeItem<std::string>::load() { }
|
||||
|
||||
template <>
|
||||
void FbTk::ThemeItem<std::string>::setDefaultValue() {
|
||||
*(*this) = "";
|
||||
}
|
||||
|
||||
template <>
|
||||
void FbTk::ThemeItem<std::string>::setFromString(const char *str) {
|
||||
*(*this) = (str ? str : "");
|
||||
}
|
||||
|
||||
template <>
|
||||
void FbTk::ThemeItem<int>::load() { }
|
||||
|
||||
template <>
|
||||
void FbTk::ThemeItem<int>::setDefaultValue() {
|
||||
*(*this) = 0;
|
||||
}
|
||||
|
||||
template <>
|
||||
void FbTk::ThemeItem<int>::setFromString(const char *str) {
|
||||
if (str == 0)
|
||||
return;
|
||||
sscanf(str, "%d", &m_value);
|
||||
}
|
||||
|
||||
template <>
|
||||
void ThemeItem<FbTk::Font>::setDefaultValue() {
|
||||
if (!m_value.load("fixed")) {
|
||||
cerr<<"FbTk::ThemeItem<FbTk::Font>: Warning! Failed to load default value 'fixed'"<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
void ThemeItem<FbTk::Font>::setFromString(const char *str) {
|
||||
if (m_value.load(str) == false) {
|
||||
if (FbTk::ThemeManager::instance().verbose()) {
|
||||
cerr<<"FbTk::Theme: Error loading font "<<
|
||||
((m_value.isAntialias() || m_value.utf8()) ? "(" : "")<<
|
||||
|
||||
(m_value.isAntialias() ? "antialias" : "")<<
|
||||
(m_value.utf8() ? " utf8" : "")<<
|
||||
|
||||
((m_value.isAntialias() || m_value.utf8()) ? ") " : "")<<
|
||||
"for \""<<name()<<"\" or \""<<altName()<<"\": "<<str<<endl;
|
||||
|
||||
cerr<<"FbTk::Theme: Setting default value"<<endl;
|
||||
}
|
||||
setDefaultValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// do nothing
|
||||
template <>
|
||||
void ThemeItem<FbTk::Font>::load() {
|
||||
}
|
||||
|
||||
|
||||
template <>
|
||||
void ThemeItem<FbTk::Texture>::load() {
|
||||
string color_name(ThemeManager::instance().
|
||||
resourceValue(name()+".color", altName()+".Color"));
|
||||
string colorto_name(ThemeManager::instance().
|
||||
resourceValue(name()+".colorTo", altName()+".ColorTo"));
|
||||
string pixmap_name(ThemeManager::instance().
|
||||
resourceValue(name()+".pixmap", altName()+".Pixmap"));
|
||||
|
||||
|
||||
// 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());
|
||||
|
||||
|
||||
std::auto_ptr<PixmapWithMask> pm(Image::load(pixmap_name, m_tm.screenNum()));
|
||||
if (pm.get() == 0) {
|
||||
if (FbTk::ThemeManager::instance().verbose())
|
||||
cerr<<"Resource("<<name()+".pixmap"<<"): Failed to load image: "<<pixmap_name<<endl;
|
||||
m_value.pixmap() = 0;
|
||||
} else
|
||||
m_value.pixmap() = pm->pixmap().release();
|
||||
}
|
||||
|
||||
template <>
|
||||
void ThemeItem<FbTk::Texture>::setDefaultValue() {
|
||||
m_value.setType(FbTk::Texture::FLAT | FbTk::Texture::SOLID);
|
||||
load(); // one might forget to add line something: so we try to load something.*: too
|
||||
}
|
||||
|
||||
template <>
|
||||
void ThemeItem<FbTk::Texture>::setFromString(const char *str) {
|
||||
m_value.setFromString(str);
|
||||
if (m_value.type() == 0) // failed to set value
|
||||
setDefaultValue();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// not used
|
||||
template <>
|
||||
void FbTk::ThemeItem<PixmapWithMask>::
|
||||
load() { }
|
||||
|
||||
template <>
|
||||
void FbTk::ThemeItem<PixmapWithMask>::
|
||||
setDefaultValue() {
|
||||
// create empty pixmap
|
||||
(*this)->pixmap() = 0;
|
||||
(*this)->mask() = 0;
|
||||
}
|
||||
|
||||
template <>
|
||||
void FbTk::ThemeItem<PixmapWithMask>::
|
||||
setFromString(const char *str) {
|
||||
if (str == 0)
|
||||
setDefaultValue();
|
||||
else {
|
||||
std::auto_ptr<FbTk::PixmapWithMask> pm(Image::load(str, m_tm.screenNum()));
|
||||
if (pm.get() == 0)
|
||||
setDefaultValue();
|
||||
else {
|
||||
(*this)->pixmap() = pm->pixmap().release();
|
||||
(*this)->mask() = pm->mask().release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
void ThemeItem<FbTk::Color>::setDefaultValue() {
|
||||
m_value.setFromString("white", m_tm.screenNum());
|
||||
}
|
||||
|
||||
template <>
|
||||
void ThemeItem<FbTk::Color>::setFromString(const char *str) {
|
||||
if (!m_value.setFromString(str, m_tm.screenNum())) {
|
||||
if (FbTk::ThemeManager::instance().verbose())
|
||||
cerr<<"FbTk::Theme: Error loading color value for \""<<name()<<"\" or \""<<altName()<<"\"."<<endl;
|
||||
setDefaultValue();
|
||||
}
|
||||
}
|
||||
|
||||
// does nothing
|
||||
template <>
|
||||
void ThemeItem<FbTk::Color>::load() { }
|
||||
|
||||
Theme::Theme(int screen_num):m_screen_num(screen_num) {
|
||||
ThemeManager::instance().registerTheme(*this);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue