using screen based vector for theme lists
fluxgen fluxgen
2 files changed,
53 insertions(+),
26 deletions(-)
M
src/FbTk/Theme.cc
→
src/FbTk/Theme.cc
@@ -42,6 +42,27 @@ using namespace std;
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) { ThemeManager::instance().registerTheme(*this); }@@ -65,26 +86,33 @@
} bool ThemeManager::registerTheme(Theme &tm) { - if (m_max_screens < 0) + if (m_max_screens < 0) { m_max_screens = ScreenCount(FbTk::App::instance()->display()); + m_themes.resize(m_max_screens); + } // valid screen num? if (m_max_screens < tm.screenNum() || tm.screenNum() < 0) return false; // TODO: use find and return false if it's already there // 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; } 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; } 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 prefix = "";@@ -136,31 +164,24 @@ Image::addSearchPath(location);
location.append("/pixmaps"); Image::addSearchPath(location); + LoadThemeHelper load_theme_helper; + // get list and go throu all the resources and load them - ThemeList::iterator theme_it = m_themelist.begin(); - const ThemeList::iterator theme_it_end = m_themelist.end(); - for (; theme_it != theme_it_end; ++theme_it) { - if (screen_num < 0) - loadTheme(**theme_it); - else if (screen_num == (*theme_it)->screenNum()) // specified screen - loadTheme(**theme_it); + // and then reconfigure them + if (screen_num < 0 || screen_num > m_max_screens) { + for_each(m_themes.begin(), + m_themes.end(), + load_theme_helper); + } else { + 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; } void ThemeManager::loadTheme(Theme &tm) { - std::list<ThemeItem_base *>::iterator i = tm.itemList().begin(); - std::list<ThemeItem_base *>::iterator i_end = tm.itemList().end(); + Theme::ItemList::iterator i = tm.itemList().begin(); + Theme::ItemList::iterator i_end = tm.itemList().end(); for (; i != i_end; ++i) { ThemeItem_base *resource = *i; if (!loadItem(*resource)) {
M
src/FbTk/Theme.hh
→
src/FbTk/Theme.hh
@@ -30,6 +30,7 @@ #define FBTK_THEME_HH
#include <string> #include <list> +#include <vector> #include <string> #include "XrmDatabaseHelper.hh"@@ -94,6 +95,8 @@
/// Hold ThemeItems. Use this to create a Theme set class Theme { public: + typedef std::list<ThemeItem_base *> ItemList; + explicit Theme(int screen_num); // create a theme for a specific screen virtual ~Theme(); virtual void reconfigTheme() = 0;@@ -113,7 +116,7 @@
private: const int m_screen_num; - typedef std::list<ThemeItem_base *> ItemList; + ItemList m_themeitems; FbTk::Subject m_reconfig_sig; };@@ -125,6 +128,9 @@ Use this to load all the registred themes
*/ class ThemeManager { public: + typedef std::list<FbTk::Theme *> ThemeList; + typedef std::vector<ThemeList> ScreenThemeVector; + static ThemeManager &instance(); /// load style file "filename" to screen bool load(const std::string &filename, const std::string &overlay_filename, int screen_num = -1);@@ -150,8 +156,8 @@ bool registerTheme(FbTk::Theme &tm);
/// @return false if theme isn't registred in the manager bool unregisterTheme(FbTk::Theme &tm); /// map each theme manager to a screen - typedef std::list<FbTk::Theme *> ThemeList; - ThemeList m_themelist; + + ScreenThemeVector m_themes; int m_max_screens; XrmDatabaseHelper m_database; bool m_verbose;