aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Theme.cc
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2006-01-03 10:02:46 (GMT)
committerfluxgen <fluxgen>2006-01-03 10:02:46 (GMT)
commit7be5606abb88b44ea09613af5155b5f0cc8a3052 (patch)
tree7ae20c6a5b9fb7749593067672e2277848ab79d7 /src/FbTk/Theme.cc
parent56b8d7296c03b4a849d3e73df274e31a9bab825f (diff)
downloadfluxbox-7be5606abb88b44ea09613af5155b5f0cc8a3052.zip
fluxbox-7be5606abb88b44ea09613af5155b5f0cc8a3052.tar.bz2
using screen based vector for theme lists
Diffstat (limited to 'src/FbTk/Theme.cc')
-rw-r--r--src/FbTk/Theme.cc67
1 files changed, 44 insertions, 23 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;
42 42
43namespace FbTk { 43namespace FbTk {
44 44
45struct LoadThemeHelper {
46 LoadThemeHelper():m_tm(ThemeManager::instance()) {}
47 void operator ()(Theme *tm) {
48 m_tm.loadTheme(*tm);
49 }
50 void operator ()(ThemeManager::ThemeList &tmlist) {
51
52 for_each(tmlist.begin(), tmlist.end(),
53 *this);
54 // send reconfiguration signal to theme and listeners
55 ThemeManager::ThemeList::iterator it = tmlist.begin();
56 ThemeManager::ThemeList::iterator it_end = tmlist.end();
57 for (; it != it_end; ++it) {
58 (*it)->reconfigTheme();
59 (*it)->reconfigSig().notify();
60 }
61 }
62
63 ThemeManager &m_tm;
64};
65
45Theme::Theme(int screen_num):m_screen_num(screen_num) { 66Theme::Theme(int screen_num):m_screen_num(screen_num) {
46 ThemeManager::instance().registerTheme(*this); 67 ThemeManager::instance().registerTheme(*this);
47} 68}
@@ -65,26 +86,33 @@ ThemeManager::ThemeManager():
65} 86}
66 87
67bool ThemeManager::registerTheme(Theme &tm) { 88bool ThemeManager::registerTheme(Theme &tm) {
68 if (m_max_screens < 0) 89 if (m_max_screens < 0) {
69 m_max_screens = ScreenCount(FbTk::App::instance()->display()); 90 m_max_screens = ScreenCount(FbTk::App::instance()->display());
91 m_themes.resize(m_max_screens);
92 }
70 93
71 // valid screen num? 94 // valid screen num?
72 if (m_max_screens < tm.screenNum() || tm.screenNum() < 0) 95 if (m_max_screens < tm.screenNum() || tm.screenNum() < 0)
73 return false; 96 return false;
74 // TODO: use find and return false if it's already there 97 // TODO: use find and return false if it's already there
75 // instead of unique 98 // instead of unique
76 m_themelist.push_back(&tm); 99
77 m_themelist.unique(); 100 m_themes[tm.screenNum()].push_back(&tm);
101 m_themes[tm.screenNum()].unique();
78 return true; 102 return true;
79} 103}
80 104
81bool ThemeManager::unregisterTheme(Theme &tm) { 105bool ThemeManager::unregisterTheme(Theme &tm) {
82 m_themelist.remove(&tm); 106 if (m_max_screens < tm.screenNum() || tm.screenNum() < 0)
107 return false;
108
109 m_themes[tm.screenNum()].remove(&tm);
110
83 return true; 111 return true;
84} 112}
85 113
86bool ThemeManager::load(const std::string &filename, 114bool ThemeManager::load(const std::string &filename,
87 const std::string &overlay_filename, int screen_num) { 115 const std::string &overlay_filename, int screen_num) {
88 std::string location = FbTk::StringUtil::expandFilename(filename); 116 std::string location = FbTk::StringUtil::expandFilename(filename);
89 std::string prefix = ""; 117 std::string prefix = "";
90 118
@@ -136,31 +164,24 @@ bool ThemeManager::load(const std::string &filename,
136 location.append("/pixmaps"); 164 location.append("/pixmaps");
137 Image::addSearchPath(location); 165 Image::addSearchPath(location);
138 166
167 LoadThemeHelper load_theme_helper;
168
139 // get list and go throu all the resources and load them 169 // get list and go throu all the resources and load them
140 ThemeList::iterator theme_it = m_themelist.begin(); 170 // and then reconfigure them
141 const ThemeList::iterator theme_it_end = m_themelist.end(); 171 if (screen_num < 0 || screen_num > m_max_screens) {
142 for (; theme_it != theme_it_end; ++theme_it) { 172 for_each(m_themes.begin(),
143 if (screen_num < 0) 173 m_themes.end(),
144 loadTheme(**theme_it); 174 load_theme_helper);
145 else if (screen_num == (*theme_it)->screenNum()) // specified screen 175 } else {
146 loadTheme(**theme_it); 176 load_theme_helper(m_themes[screen_num]);
147 } 177 }
148 178
149 // notify all themes that we reconfigured
150 theme_it = m_themelist.begin();
151 for (; theme_it != theme_it_end; ++theme_it) {
152 // send reconfiguration signal to theme and listeners
153 if (screen_num < 0 || (*theme_it)->screenNum() == screen_num) {
154 (*theme_it)->reconfigTheme();
155 (*theme_it)->reconfigSig().notify();
156 }
157 }
158 return true; 179 return true;
159} 180}
160 181
161void ThemeManager::loadTheme(Theme &tm) { 182void ThemeManager::loadTheme(Theme &tm) {
162 std::list<ThemeItem_base *>::iterator i = tm.itemList().begin(); 183 Theme::ItemList::iterator i = tm.itemList().begin();
163 std::list<ThemeItem_base *>::iterator i_end = tm.itemList().end(); 184 Theme::ItemList::iterator i_end = tm.itemList().end();
164 for (; i != i_end; ++i) { 185 for (; i != i_end; ++i) {
165 ThemeItem_base *resource = *i; 186 ThemeItem_base *resource = *i;
166 if (!loadItem(*resource)) { 187 if (!loadItem(*resource)) {