From a63a27886d7861d59352e0c4fe96f7d61c9925b4 Mon Sep 17 00:00:00 2001 From: akir Date: Thu, 21 Oct 2004 16:44:06 +0000 Subject: moved ThemeItems.hh to ThemeItems.cc, solves some linkissues --- src/FbTk/Makefile.am | 2 +- src/FbTk/ThemeItems.cc | 230 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 231 insertions(+), 1 deletion(-) create mode 100644 src/FbTk/ThemeItems.cc diff --git a/src/FbTk/Makefile.am b/src/FbTk/Makefile.am index 478a8eb..49217bc 100644 --- a/src/FbTk/Makefile.am +++ b/src/FbTk/Makefile.am @@ -25,7 +25,7 @@ libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \ RefCount.hh SimpleCommand.hh SignalHandler.cc SignalHandler.hh \ Text.hh Text.cc \ Texture.cc Texture.hh TextureRender.hh TextureRender.cc \ - Theme.hh Theme.cc ThemeItems.hh Timer.hh Timer.cc \ + Theme.hh Theme.cc ThemeItems.cc Timer.hh Timer.cc \ XFontImp.cc XFontImp.hh \ Button.hh Button.cc \ TextButton.hh TextButton.cc \ diff --git a/src/FbTk/ThemeItems.cc b/src/FbTk/ThemeItems.cc new file mode 100644 index 0000000..6f792cc --- /dev/null +++ b/src/FbTk/ThemeItems.cc @@ -0,0 +1,230 @@ +// ThemeItems.cc for FbTk - Fluxbox ToolKit +// Copyright (c) 2002 - 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +// $Id: ThemeItems.cc,v 1.1 2004/10/21 16:44:06 akir Exp $ + +/// @file implements common theme items + +#ifndef THEMEITEMS_HH +#define THEMEITEMS_HH + +#include "Theme.hh" +#include "Color.hh" +#include "Texture.hh" +#include "Font.hh" +#include "PixmapWithMask.hh" +#include "Image.hh" +#include "StringUtil.hh" + +#include +#ifdef HAVE_CSTDIO + #include +#else + #include +#endif +#include +namespace FbTk { + +using namespace std; + +// create default handlers for Color, Font, Texture, int and string +template <> +void FbTk::ThemeItem::load(const std::string *name, const std::string *altname) { } + +template <> +void FbTk::ThemeItem::setDefaultValue() { + *(*this) = ""; +} + +template <> +void FbTk::ThemeItem::setFromString(const char *str) { + *(*this) = (str ? str : ""); +} + +template <> +void FbTk::ThemeItem::load(const std::string *name, const std::string *altname) { } + +template<> +void FbTk::ThemeItem::setDefaultValue() { + *(*this) = 0; +} + +template <> +void FbTk::ThemeItem::setFromString(const char *str) { + if (str == 0) { + setDefaultValue(); + return; + } + + if (sscanf(str, "%d", &m_value) < 1) + setDefaultValue(); +} + +template <> +void ThemeItem::setDefaultValue() { + if (!m_value.load("fixed")) { + cerr<<"FbTk::ThemeItem: Warning! Failed to load default value 'fixed'"< +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 "<< + ((m_value.isAntialias() || m_value.utf8()) ? "(" : "")<< + + (m_value.isAntialias() ? "antialias" : "")<< + (m_value.utf8() ? " utf8" : "")<< + + ((m_value.isAntialias() || m_value.utf8()) ? ") " : "")<< + "for \""< +void ThemeItem::load(const std::string *name, const std::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; + + string color_name(ThemeManager::instance(). + resourceValue(m_name+".color", m_altname+".Color")); + string colorto_name(ThemeManager::instance(). + resourceValue(m_name+".colorTo", m_altname+".ColorTo")); + string pixmap_name(ThemeManager::instance(). + resourceValue(m_name+".pixmap", m_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()); + + + if ((m_value.type() & FbTk::Texture::SOLID) != 0 && (m_value.type() & FbTk::Texture::FLAT) == 0) + m_value.calcHiLoColors(m_tm.screenNum()); + + StringUtil::removeFirstWhitespace(pixmap_name); + StringUtil::removeTrailingWhitespace(pixmap_name); + if (pixmap_name.empty()) { + m_value.pixmap() = 0; + return; + } + + std::auto_ptr pm(FbTk::Image::load(pixmap_name, + m_tm.screenNum())); + if (pm.get() == 0) { + if (FbTk::ThemeManager::instance().verbose()) { + cerr<<"Resource("<pixmap().release(); + +} + +template <> +void ThemeItem::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::setFromString(const char *str) { + m_value.setFromString(str); + if (m_value.type() == 0) // failed to set value + setDefaultValue(); +} + + + +// not used +template <> +void FbTk::ThemeItem::load(const std::string *name, const std::string *altname) { } + +template <> +void FbTk::ThemeItem:: +setDefaultValue() { + // create empty pixmap + (*this)->pixmap() = 0; + (*this)->mask() = 0; +} + +template <> +void FbTk::ThemeItem:: +setFromString(const char *str) { + if (str == 0) + setDefaultValue(); + else { + std::string filename(str); + + StringUtil::removeFirstWhitespace(filename); + StringUtil::removeTrailingWhitespace(filename); + + std::auto_ptr pm(Image::load(filename, m_tm.screenNum())); + if (pm.get() == 0) + setDefaultValue(); + else { + (*this)->pixmap() = pm->pixmap().release(); + (*this)->mask() = pm->mask().release(); + } + } +} + + +template <> +void ThemeItem::setDefaultValue() { + m_value.setFromString("white", m_tm.screenNum()); +} + +template <> +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) { } + +} // end namespace FbTk + +#endif // THEMEITEMS_HH -- cgit v0.11.2