using screen based vector for theme lists

This commit is contained in:
fluxgen 2006-01-03 10:02:46 +00:00
parent 56b8d7296c
commit 7be5606abb
2 changed files with 53 additions and 26 deletions

View file

@ -42,6 +42,27 @@ using namespace std;
namespace FbTk { namespace FbTk {
struct LoadThemeHelper {
LoadThemeHelper():m_tm(ThemeManager::instance()) {}
void operator ()(Theme *tm) {
m_tm.loadTheme(*tm);
}
void operator ()(ThemeManager::ThemeList &tmlist) {
for_each(tmlist.begin(), tmlist.end(),
*this);
// send reconfiguration signal to theme and listeners
ThemeManager::ThemeList::iterator it = tmlist.begin();
ThemeManager::ThemeList::iterator it_end = tmlist.end();
for (; it != it_end; ++it) {
(*it)->reconfigTheme();
(*it)->reconfigSig().notify();
}
}
ThemeManager &m_tm;
};
Theme::Theme(int screen_num):m_screen_num(screen_num) { Theme::Theme(int screen_num):m_screen_num(screen_num) {
ThemeManager::instance().registerTheme(*this); ThemeManager::instance().registerTheme(*this);
} }
@ -65,26 +86,33 @@ ThemeManager::ThemeManager():
} }
bool ThemeManager::registerTheme(Theme &tm) { bool ThemeManager::registerTheme(Theme &tm) {
if (m_max_screens < 0) if (m_max_screens < 0) {
m_max_screens = ScreenCount(FbTk::App::instance()->display()); m_max_screens = ScreenCount(FbTk::App::instance()->display());
m_themes.resize(m_max_screens);
}
// valid screen num? // valid screen num?
if (m_max_screens < tm.screenNum() || tm.screenNum() < 0) if (m_max_screens < tm.screenNum() || tm.screenNum() < 0)
return false; return false;
// TODO: use find and return false if it's already there // TODO: use find and return false if it's already there
// instead of unique // instead of unique
m_themelist.push_back(&tm);
m_themelist.unique(); m_themes[tm.screenNum()].push_back(&tm);
m_themes[tm.screenNum()].unique();
return true; return true;
} }
bool ThemeManager::unregisterTheme(Theme &tm) { bool ThemeManager::unregisterTheme(Theme &tm) {
m_themelist.remove(&tm); if (m_max_screens < tm.screenNum() || tm.screenNum() < 0)
return false;
m_themes[tm.screenNum()].remove(&tm);
return true; return true;
} }
bool ThemeManager::load(const std::string &filename, bool ThemeManager::load(const std::string &filename,
const std::string &overlay_filename, int screen_num) { const std::string &overlay_filename, int screen_num) {
std::string location = FbTk::StringUtil::expandFilename(filename); std::string location = FbTk::StringUtil::expandFilename(filename);
std::string prefix = ""; std::string prefix = "";
@ -136,31 +164,24 @@ bool ThemeManager::load(const std::string &filename,
location.append("/pixmaps"); location.append("/pixmaps");
Image::addSearchPath(location); Image::addSearchPath(location);
LoadThemeHelper load_theme_helper;
// get list and go throu all the resources and load them // get list and go throu all the resources and load them
ThemeList::iterator theme_it = m_themelist.begin(); // and then reconfigure them
const ThemeList::iterator theme_it_end = m_themelist.end(); if (screen_num < 0 || screen_num > m_max_screens) {
for (; theme_it != theme_it_end; ++theme_it) { for_each(m_themes.begin(),
if (screen_num < 0) m_themes.end(),
loadTheme(**theme_it); load_theme_helper);
else if (screen_num == (*theme_it)->screenNum()) // specified screen } else {
loadTheme(**theme_it); load_theme_helper(m_themes[screen_num]);
} }
// notify all themes that we reconfigured
theme_it = m_themelist.begin();
for (; theme_it != theme_it_end; ++theme_it) {
// send reconfiguration signal to theme and listeners
if (screen_num < 0 || (*theme_it)->screenNum() == screen_num) {
(*theme_it)->reconfigTheme();
(*theme_it)->reconfigSig().notify();
}
}
return true; return true;
} }
void ThemeManager::loadTheme(Theme &tm) { void ThemeManager::loadTheme(Theme &tm) {
std::list<ThemeItem_base *>::iterator i = tm.itemList().begin(); Theme::ItemList::iterator i = tm.itemList().begin();
std::list<ThemeItem_base *>::iterator i_end = tm.itemList().end(); Theme::ItemList::iterator i_end = tm.itemList().end();
for (; i != i_end; ++i) { for (; i != i_end; ++i) {
ThemeItem_base *resource = *i; ThemeItem_base *resource = *i;
if (!loadItem(*resource)) { if (!loadItem(*resource)) {

View file

@ -30,6 +30,7 @@
#include <string> #include <string>
#include <list> #include <list>
#include <vector>
#include <string> #include <string>
#include "XrmDatabaseHelper.hh" #include "XrmDatabaseHelper.hh"
@ -94,6 +95,8 @@ private:
/// Hold ThemeItems. Use this to create a Theme set /// Hold ThemeItems. Use this to create a Theme set
class Theme { class Theme {
public: public:
typedef std::list<ThemeItem_base *> ItemList;
explicit Theme(int screen_num); // create a theme for a specific screen explicit Theme(int screen_num); // create a theme for a specific screen
virtual ~Theme(); virtual ~Theme();
virtual void reconfigTheme() = 0; virtual void reconfigTheme() = 0;
@ -113,7 +116,7 @@ public:
private: private:
const int m_screen_num; const int m_screen_num;
typedef std::list<ThemeItem_base *> ItemList;
ItemList m_themeitems; ItemList m_themeitems;
FbTk::Subject m_reconfig_sig; FbTk::Subject m_reconfig_sig;
}; };
@ -125,6 +128,9 @@ private:
*/ */
class ThemeManager { class ThemeManager {
public: public:
typedef std::list<FbTk::Theme *> ThemeList;
typedef std::vector<ThemeList> ScreenThemeVector;
static ThemeManager &instance(); static ThemeManager &instance();
/// load style file "filename" to screen /// load style file "filename" to screen
bool load(const std::string &filename, const std::string &overlay_filename, int screen_num = -1); bool load(const std::string &filename, const std::string &overlay_filename, int screen_num = -1);
@ -150,8 +156,8 @@ private:
/// @return false if theme isn't registred in the manager /// @return false if theme isn't registred in the manager
bool unregisterTheme(FbTk::Theme &tm); bool unregisterTheme(FbTk::Theme &tm);
/// map each theme manager to a screen /// map each theme manager to a screen
typedef std::list<FbTk::Theme *> ThemeList;
ThemeList m_themelist; ScreenThemeVector m_themes;
int m_max_screens; int m_max_screens;
XrmDatabaseHelper m_database; XrmDatabaseHelper m_database;
bool m_verbose; bool m_verbose;