From 7be5606abb88b44ea09613af5155b5f0cc8a3052 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Tue, 3 Jan 2006 10:02:46 +0000 Subject: using screen based vector for theme lists --- src/FbTk/Theme.cc | 67 ++++++++++++++++++++++++++++++++++++------------------- src/FbTk/Theme.hh | 12 +++++++--- 2 files changed, 53 insertions(+), 26 deletions(-) diff --git a/src/FbTk/Theme.cc b/src/FbTk/Theme.cc index 8978e11..be8192d 100644 --- a/src/FbTk/Theme.cc +++ b/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 @@ ThemeManager::ThemeManager(): } 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 @@ bool ThemeManager::load(const std::string &filename, 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::iterator i = tm.itemList().begin(); - std::list::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)) { diff --git a/src/FbTk/Theme.hh b/src/FbTk/Theme.hh index c5d8e36..aeef4f1 100644 --- a/src/FbTk/Theme.hh +++ b/src/FbTk/Theme.hh @@ -30,6 +30,7 @@ #include #include +#include #include #include "XrmDatabaseHelper.hh" @@ -94,6 +95,8 @@ private: /// Hold ThemeItems. Use this to create a Theme set class Theme { public: + typedef std::list ItemList; + explicit Theme(int screen_num); // create a theme for a specific screen virtual ~Theme(); virtual void reconfigTheme() = 0; @@ -113,7 +116,7 @@ public: private: const int m_screen_num; - typedef std::list ItemList; + ItemList m_themeitems; FbTk::Subject m_reconfig_sig; }; @@ -125,6 +128,9 @@ private: */ class ThemeManager { public: + typedef std::list ThemeList; + typedef std::vector 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 @@ private: /// @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 ThemeList; - ThemeList m_themelist; + + ScreenThemeVector m_themes; int m_max_screens; XrmDatabaseHelper m_database; bool m_verbose; -- cgit v0.11.2