From a07d61e63dfc129660cc9bab344c9e040a7f991f Mon Sep 17 00:00:00 2001 From: mathias Date: Fri, 14 Jan 2005 09:43:31 +0000 Subject: moved ThemeItem - implementation to FbTk/ThemeItems.cc --- src/FbTk/ThemeItems.cc | 154 ++++++++++++++++++++++++++++++++++++++----------- src/ToolbarTheme.cc | 16 ----- 2 files changed, 120 insertions(+), 50 deletions(-) diff --git a/src/FbTk/ThemeItems.cc b/src/FbTk/ThemeItems.cc index a588328..f55c162 100644 --- a/src/FbTk/ThemeItems.cc +++ b/src/FbTk/ThemeItems.cc @@ -30,6 +30,7 @@ #include "Color.hh" #include "Texture.hh" #include "Font.hh" +#include "GContext.hh" #include "PixmapWithMask.hh" #include "Image.hh" #include "StringUtil.hh" @@ -43,32 +44,35 @@ #include namespace FbTk { -using namespace std; +using std::string; +using std::cerr; +using std::endl; + // create default handlers for Color, Font, Texture, int and string template <> -void FbTk::ThemeItem::load(const std::string *name, const std::string *altname) { } +void ThemeItem::load(const string *name, const string *altname) { } template <> -void FbTk::ThemeItem::setDefaultValue() { +void ThemeItem::setDefaultValue() { *(*this) = ""; } template <> -void FbTk::ThemeItem::setFromString(const char *str) { +void ThemeItem::setFromString(const char *str) { *(*this) = (str ? str : ""); } template <> -void FbTk::ThemeItem::load(const std::string *name, const std::string *altname) { } +void ThemeItem::load(const string *name, const string *altname) { } template<> -void FbTk::ThemeItem::setDefaultValue() { +void ThemeItem::setDefaultValue() { *(*this) = 0; } template <> -void FbTk::ThemeItem::setFromString(const char *str) { +void ThemeItem::setFromString(const char *str) { if (str == 0) { setDefaultValue(); return; @@ -77,20 +81,35 @@ void FbTk::ThemeItem::setFromString(const char *str) { if (sscanf(str, "%d", &m_value) < 1) setDefaultValue(); } +template<> +void FbTk::ThemeItem::load(const std::string *name, const std::string *altname) { } + +template<> +void FbTk::ThemeItem::setDefaultValue() { + *(*this) = false; +} + +template<> +void FbTk::ThemeItem::setFromString(char const *strval) { + if (strcasecmp(strval, "true")==0) + *(*this) = true; + else + *(*this) = false; +} template <> -void ThemeItem::setDefaultValue() { +void ThemeItem::setDefaultValue() { if (!m_value.load("fixed")) { - cerr<<"FbTk::ThemeItem: Warning! Failed to load default value 'fixed'"<: Warning! Failed to load default value 'fixed'"< -void ThemeItem::setFromString(const char *str) { +void ThemeItem::setFromString(const char *str) { if (str == 0 || m_value.load(str) == false) { - if (FbTk::ThemeManager::instance().verbose()) { - cerr<<"FbTk::Theme: Error loading font "<< + if (ThemeManager::instance().verbose()) { + cerr<<"Theme: Error loading font "<< ((m_value.isAntialias() || m_value.utf8()) ? "(" : "")<< (m_value.isAntialias() ? "antialias" : "")<< @@ -99,7 +118,7 @@ void ThemeItem::setFromString(const char *str) { ((m_value.isAntialias() || m_value.utf8()) ? ") " : "")<< "for \""<::setFromString(const char *str) { // do nothing template <> -void ThemeItem::load(const std::string *name, const std::string *altname) { +void ThemeItem::load(const string *name, const string *altname) { } template <> -void ThemeItem::load(const std::string *o_name, const std::string *o_altname) { - const std::string &m_name = (o_name==0)?name():*o_name; - const std::string &m_altname = (o_altname==0)?altName():*o_altname; +void ThemeItem::load(const string *o_name, const string *o_altname) { + const string &m_name = (o_name==0)?name():*o_name; + const string &m_altname = (o_altname==0)?altName():*o_altname; string color_name(ThemeManager::instance(). resourceValue(m_name+".color", m_altname+".Color")); @@ -135,7 +154,7 @@ void ThemeItem::load(const std::string *o_name, const std::string m_value.colorTo().setFromString("white", m_tm.screenNum()); - if ((m_value.type() & FbTk::Texture::SOLID) != 0 && (m_value.type() & FbTk::Texture::FLAT) == 0) + if ((m_value.type() & Texture::SOLID) != 0 && (m_value.type() & Texture::FLAT) == 0) m_value.calcHiLoColors(m_tm.screenNum()); StringUtil::removeFirstWhitespace(pixmap_name); @@ -145,10 +164,10 @@ void ThemeItem::load(const std::string *o_name, const std::string return; } - std::auto_ptr pm(FbTk::Image::load(pixmap_name, + std::auto_ptr pm(Image::load(pixmap_name, m_tm.screenNum())); if (pm.get() == 0) { - if (FbTk::ThemeManager::instance().verbose()) { + if (ThemeManager::instance().verbose()) { cerr<<"Resource("<::load(const std::string *o_name, const std::string } template <> -void ThemeItem::setDefaultValue() { - m_value.setType(FbTk::Texture::FLAT | FbTk::Texture::SOLID); +void ThemeItem::setDefaultValue() { + m_value.setType(Texture::FLAT | Texture::SOLID); load(); // one might forget to add line something: so we try to load something.*: too } template <> -void ThemeItem::setFromString(const char *str) { +void ThemeItem::setFromString(const char *str) { m_value.setFromString(str); if (m_value.type() == 0) // failed to set value setDefaultValue(); @@ -175,28 +194,27 @@ void ThemeItem::setFromString(const char *str) { // not used template <> -void FbTk::ThemeItem::load(const std::string *name, const std::string *altname) { } +void ThemeItem::load(const string *name, const string *altname) { } template <> -void FbTk::ThemeItem:: -setDefaultValue() { +void ThemeItem::setDefaultValue() { // create empty pixmap (*this)->pixmap() = 0; (*this)->mask() = 0; } template <> -void FbTk::ThemeItem:: +void ThemeItem:: setFromString(const char *str) { if (str == 0) setDefaultValue(); else { - std::string filename(str); + string filename(str); StringUtil::removeFirstWhitespace(filename); StringUtil::removeTrailingWhitespace(filename); - std::auto_ptr pm(Image::load(filename, m_tm.screenNum())); + std::auto_ptr pm(Image::load(filename, m_tm.screenNum())); if (pm.get() == 0) setDefaultValue(); else { @@ -208,22 +226,90 @@ setFromString(const char *str) { template <> -void ThemeItem::setDefaultValue() { +void ThemeItem::setDefaultValue() { m_value.setFromString("white", m_tm.screenNum()); } template <> -void ThemeItem::setFromString(const char *str) { +void ThemeItem::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 \""< -void ThemeItem::load(const std::string *name, const std::string *altname) { } +void ThemeItem::load(const string *name, const string *altname) { } + +template<> +void ThemeItem::setDefaultValue() { + *(*this) = GContext::LINESOLID; +} + +template<> +void ThemeItem::setFromString(char const *strval) { + + if (strcasecmp(strval, "LineSolid") == 0 ) + m_value = GContext::LINESOLID; + else if (strcasecmp(strval, "LineOnOffDash") == 0 ) + m_value = GContext::LINEONOFFDASH; + else if (strcasecmp(strval, "LineDoubleDash") == 0) + m_value = GContext::LINEDOUBLEDASH; + else + setDefaultValue(); +} + +template<> +void ThemeItem::load(const string *name, const string *altname) { } + + +template<> +void ThemeItem::setDefaultValue() { + *(*this) = GContext::JOINMITER; +} + +template<> +void ThemeItem::setFromString(char const *strval) { + + if (strcasecmp(strval, "JoinRound") == 0 ) + m_value = GContext::JOINROUND; + else if (strcasecmp(strval, "JoinMiter") == 0 ) + m_value = GContext::JOINMITER; + else if (strcasecmp(strval, "JoinBevel") == 0) + m_value = GContext::JOINBEVEL; + else + setDefaultValue(); +} + +template<> +void ThemeItem::load(const string *name, const string *altname) { } + +template<> +void ThemeItem::setDefaultValue() { + *(*this) = GContext::CAPNOTLAST; +} + +template<> +void ThemeItem::setFromString(char const *strval) { + + if (strcasecmp(strval, "CapNotLast") == 0 ) + m_value = GContext::CAPNOTLAST; + else if (strcasecmp(strval, "CapProjecting") == 0 ) + m_value = GContext::CAPPROJECTING; + else if (strcasecmp(strval, "CapRound") == 0) + m_value = GContext::CAPROUND; + else if (strcasecmp(strval, "CapButt" ) == 0) + m_value = GContext::CAPBUTT; + else + setDefaultValue(); +} + +template<> +void ThemeItem::load(const string *name, const string *altname) { } + + } // end namespace FbTk diff --git a/src/ToolbarTheme.cc b/src/ToolbarTheme.cc index 33b8db6..cb92ae9 100644 --- a/src/ToolbarTheme.cc +++ b/src/ToolbarTheme.cc @@ -28,22 +28,6 @@ #include using namespace std; -template<> -void FbTk::ThemeItem::load(const std::string *name, const std::string *altname) { } - -template<> -void FbTk::ThemeItem::setDefaultValue() { - *(*this) = false; -} - -template<> -void FbTk::ThemeItem::setFromString(char const *strval) { - if (strcasecmp(strval, "true")==0) - *(*this) = true; - else - *(*this) = false; -} - ToolbarTheme::ToolbarTheme(int screen_num): FbTk::Theme(screen_num), m_toolbar(*this, "toolbar", "Toolbar"), -- cgit v0.11.2