2002-12-02 19:34:54 +00:00
|
|
|
// Theme.hh for FbTk - Fluxbox ToolKit
|
2006-02-16 06:53:05 +00:00
|
|
|
// Copyright (c) 2002 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org)
|
2002-12-02 19:34:54 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2003-04-25 18:13:29 +00:00
|
|
|
/**
|
2006-04-25 02:19:04 +00:00
|
|
|
@file Theme.hh holds ThemeItem<T>, Theme and ThemeManager which is the base for any theme
|
2003-04-25 18:13:29 +00:00
|
|
|
*/
|
2002-12-02 19:34:54 +00:00
|
|
|
|
2002-12-16 11:01:43 +00:00
|
|
|
#ifndef FBTK_THEME_HH
|
|
|
|
#define FBTK_THEME_HH
|
2002-12-02 19:34:54 +00:00
|
|
|
|
2007-12-30 15:32:53 +00:00
|
|
|
#include "XrmDatabaseHelper.hh"
|
|
|
|
#include "Subject.hh"
|
|
|
|
|
2002-12-02 19:34:54 +00:00
|
|
|
#include <string>
|
|
|
|
#include <list>
|
2006-01-03 10:02:46 +00:00
|
|
|
#include <vector>
|
2002-12-02 19:34:54 +00:00
|
|
|
|
|
|
|
namespace FbTk {
|
|
|
|
|
|
|
|
class Theme;
|
2002-12-16 11:01:43 +00:00
|
|
|
|
|
|
|
/// Base class for ThemeItem, holds name and altname
|
2002-12-02 19:34:54 +00:00
|
|
|
/**
|
2002-12-16 11:01:43 +00:00
|
|
|
@see ThemeItem
|
|
|
|
*/
|
2002-12-02 19:34:54 +00:00
|
|
|
class ThemeItem_base {
|
|
|
|
public:
|
|
|
|
ThemeItem_base(const std::string &name, const std::string &altname):
|
|
|
|
m_name(name), m_altname(altname) { }
|
|
|
|
virtual ~ThemeItem_base() { }
|
|
|
|
virtual void setFromString(const char *str) = 0;
|
|
|
|
virtual void setDefaultValue() = 0;
|
2004-04-26 15:04:37 +00:00
|
|
|
virtual void load(const std::string *name = 0, const std::string *altname = 0) = 0; // if it needs to load additional stuff
|
2002-12-02 19:34:54 +00:00
|
|
|
const std::string &name() const { return m_name; }
|
|
|
|
const std::string &altName() const { return m_altname; }
|
|
|
|
private:
|
|
|
|
std::string m_name, m_altname;
|
|
|
|
};
|
|
|
|
|
2002-12-16 11:01:43 +00:00
|
|
|
|
2003-04-25 18:13:29 +00:00
|
|
|
/// template ThemeItem class for basic theme items
|
|
|
|
/// to use this you need to specialize setDefaultValue, setFromString and load
|
2002-12-02 19:34:54 +00:00
|
|
|
template <typename T>
|
|
|
|
class ThemeItem:public ThemeItem_base {
|
|
|
|
public:
|
|
|
|
ThemeItem(FbTk::Theme &tm, const std::string &name, const std::string &altname);
|
|
|
|
virtual ~ThemeItem();
|
|
|
|
/// specialized
|
2007-12-29 21:38:53 +00:00
|
|
|
void setDefaultValue();
|
2002-12-02 19:34:54 +00:00
|
|
|
/// specialized
|
2007-01-14 19:00:18 +00:00
|
|
|
virtual void setFromString(const char *strval);
|
2002-12-02 19:34:54 +00:00
|
|
|
/// specialized
|
2004-04-26 15:04:37 +00:00
|
|
|
// name and altname may be different to the primary ones (e.g. from fallback)
|
|
|
|
// if they are null, then the original name is used
|
2007-01-14 19:00:18 +00:00
|
|
|
virtual void load(const std::string *name = 0, const std::string *altname = 0);
|
2002-12-02 19:34:54 +00:00
|
|
|
/**
|
|
|
|
@name access operators
|
|
|
|
*/
|
|
|
|
/**@{*/
|
2007-12-29 21:38:53 +00:00
|
|
|
T& operator*() { return m_value; }
|
|
|
|
const T& operator*() const { return m_value; }
|
|
|
|
T *operator->() { return &m_value; }
|
|
|
|
const T *operator->() const { return &m_value; }
|
2002-12-02 19:34:54 +00:00
|
|
|
/**@}*/
|
2003-08-19 21:25:26 +00:00
|
|
|
|
|
|
|
FbTk::Theme &theme() { return m_tm; }
|
2002-12-02 19:34:54 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
T m_value;
|
|
|
|
FbTk::Theme &m_tm;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-12-16 11:01:43 +00:00
|
|
|
/// Hold ThemeItems. Use this to create a Theme set
|
2002-12-02 19:34:54 +00:00
|
|
|
class Theme {
|
|
|
|
public:
|
2006-01-03 10:02:46 +00:00
|
|
|
typedef std::list<ThemeItem_base *> ItemList;
|
|
|
|
|
2002-12-02 19:34:54 +00:00
|
|
|
explicit Theme(int screen_num); // create a theme for a specific screen
|
|
|
|
virtual ~Theme();
|
|
|
|
virtual void reconfigTheme() = 0;
|
|
|
|
int screenNum() const { return m_screen_num; }
|
|
|
|
std::list<ThemeItem_base *> &itemList() { return m_themeitems; }
|
|
|
|
const std::list<ThemeItem_base *> &itemList() const { return m_themeitems; }
|
|
|
|
/// add ThemeItem
|
|
|
|
template <typename T>
|
|
|
|
void add(ThemeItem<T> &item);
|
|
|
|
/// remove ThemeItem
|
|
|
|
template <typename T>
|
|
|
|
void remove(ThemeItem<T> &item);
|
2003-12-16 17:06:52 +00:00
|
|
|
virtual bool fallback(ThemeItem_base &) { return false; }
|
2003-08-11 14:55:14 +00:00
|
|
|
FbTk::Subject &reconfigSig() { return m_reconfig_sig; }
|
2003-12-17 00:43:22 +00:00
|
|
|
const FbTk::Subject &reconfigSig() const { return m_reconfig_sig; }
|
2003-08-28 23:06:27 +00:00
|
|
|
|
2007-12-29 21:38:53 +00:00
|
|
|
|
2002-12-02 19:34:54 +00:00
|
|
|
private:
|
|
|
|
const int m_screen_num;
|
2006-01-03 10:02:46 +00:00
|
|
|
|
2002-12-02 19:34:54 +00:00
|
|
|
ItemList m_themeitems;
|
2003-08-11 14:55:14 +00:00
|
|
|
FbTk::Subject m_reconfig_sig;
|
2002-12-02 19:34:54 +00:00
|
|
|
};
|
|
|
|
|
2008-01-04 09:06:38 +00:00
|
|
|
/// Proxy interface for themes, so they can be substituted dynamically
|
|
|
|
template <class BaseTheme>
|
|
|
|
class ThemeProxy {
|
|
|
|
public:
|
|
|
|
virtual ~ThemeProxy() { }
|
|
|
|
|
|
|
|
virtual Subject &reconfigSig() = 0;
|
|
|
|
virtual const Subject &reconfigSig() const = 0;
|
|
|
|
|
2008-01-05 01:39:19 +00:00
|
|
|
virtual BaseTheme &operator *() = 0;
|
|
|
|
virtual const BaseTheme &operator *() const = 0;
|
|
|
|
virtual BaseTheme *operator ->() { return &(**this); }
|
|
|
|
virtual const BaseTheme *operator ->() const { return &(**this); }
|
2008-01-04 09:06:38 +00:00
|
|
|
};
|
2002-12-02 19:34:54 +00:00
|
|
|
|
2002-12-16 11:01:43 +00:00
|
|
|
/// Singleton theme manager
|
2002-12-02 19:34:54 +00:00
|
|
|
/**
|
2002-12-16 11:01:43 +00:00
|
|
|
Use this to load all the registred themes
|
2002-12-02 19:34:54 +00:00
|
|
|
*/
|
|
|
|
class ThemeManager {
|
|
|
|
public:
|
2006-01-03 10:02:46 +00:00
|
|
|
typedef std::list<FbTk::Theme *> ThemeList;
|
|
|
|
typedef std::vector<ThemeList> ScreenThemeVector;
|
|
|
|
|
2002-12-02 19:34:54 +00:00
|
|
|
static ThemeManager &instance();
|
2007-12-29 21:38:53 +00:00
|
|
|
/// load style file "filename" to screen
|
2005-11-16 22:08:05 +00:00
|
|
|
bool load(const std::string &filename, const std::string &overlay_filename, int screen_num = -1);
|
2002-12-02 19:34:54 +00:00
|
|
|
std::string resourceValue(const std::string &name, const std::string &altname);
|
|
|
|
void loadTheme(Theme &tm);
|
2003-08-19 21:25:26 +00:00
|
|
|
bool loadItem(ThemeItem_base &resource);
|
|
|
|
bool loadItem(ThemeItem_base &resource, const std::string &name, const std::string &altname);
|
2003-08-28 23:06:27 +00:00
|
|
|
|
|
|
|
bool verbose() const { return m_verbose; }
|
|
|
|
void setVerbose(bool value) { m_verbose = value; }
|
2004-12-13 14:03:17 +00:00
|
|
|
|
|
|
|
// dump theme out to filename, stdout if no filename is given
|
|
|
|
void dump(Theme& theme, const char* filename = 0) const;
|
2003-09-14 11:17:21 +00:00
|
|
|
// void listItems();
|
2002-12-02 19:34:54 +00:00
|
|
|
private:
|
|
|
|
ThemeManager();
|
|
|
|
~ThemeManager() { }
|
|
|
|
|
|
|
|
friend class FbTk::Theme; // so only theme can register itself in constructor
|
2007-12-29 21:38:53 +00:00
|
|
|
/// @return false if screen_num if out of
|
2002-12-16 11:01:43 +00:00
|
|
|
/// range or theme already registered, else true
|
2007-12-29 21:38:53 +00:00
|
|
|
bool registerTheme(FbTk::Theme &tm);
|
2002-12-02 19:34:54 +00:00
|
|
|
/// @return false if theme isn't registred in the manager
|
|
|
|
bool unregisterTheme(FbTk::Theme &tm);
|
|
|
|
/// map each theme manager to a screen
|
2006-01-03 10:02:46 +00:00
|
|
|
|
|
|
|
ScreenThemeVector m_themes;
|
2004-01-02 22:55:35 +00:00
|
|
|
int m_max_screens;
|
2002-12-02 19:34:54 +00:00
|
|
|
XrmDatabaseHelper m_database;
|
2003-08-28 23:06:27 +00:00
|
|
|
bool m_verbose;
|
2003-11-16 22:33:56 +00:00
|
|
|
|
|
|
|
std::string m_themelocation;
|
2002-12-02 19:34:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
2007-12-29 21:38:53 +00:00
|
|
|
ThemeItem<T>::ThemeItem(FbTk::Theme &tm,
|
2002-12-02 19:34:54 +00:00
|
|
|
const std::string &name, const std::string &altname):
|
|
|
|
ThemeItem_base(name, altname),
|
|
|
|
m_tm(tm) {
|
|
|
|
tm.add(*this);
|
2003-08-28 14:19:27 +00:00
|
|
|
setDefaultValue();
|
2002-12-02 19:34:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
ThemeItem<T>::~ThemeItem() {
|
|
|
|
m_tm.remove(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void Theme::add(ThemeItem<T> &item) {
|
|
|
|
m_themeitems.push_back(&item);
|
|
|
|
m_themeitems.unique();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void Theme::remove(ThemeItem<T> &item) {
|
|
|
|
m_themeitems.remove(&item);
|
|
|
|
}
|
|
|
|
|
2003-12-16 17:06:52 +00:00
|
|
|
} // end namespace FbTk
|
2002-12-02 19:34:54 +00:00
|
|
|
|
2002-12-16 11:01:43 +00:00
|
|
|
#endif // FBTK_THEME_HH
|
2002-12-02 19:34:54 +00:00
|
|
|
|