diff options
author | fluxgen <fluxgen> | 2006-01-03 10:02:46 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2006-01-03 10:02:46 (GMT) |
commit | 7be5606abb88b44ea09613af5155b5f0cc8a3052 (patch) | |
tree | 7ae20c6a5b9fb7749593067672e2277848ab79d7 /src | |
parent | 56b8d7296c03b4a849d3e73df274e31a9bab825f (diff) | |
download | fluxbox_paul-7be5606abb88b44ea09613af5155b5f0cc8a3052.zip fluxbox_paul-7be5606abb88b44ea09613af5155b5f0cc8a3052.tar.bz2 |
using screen based vector for theme lists
Diffstat (limited to 'src')
-rw-r--r-- | src/FbTk/Theme.cc | 67 | ||||
-rw-r--r-- | 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; | |||
42 | 42 | ||
43 | namespace FbTk { | 43 | namespace FbTk { |
44 | 44 | ||
45 | struct 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 | |||
45 | Theme::Theme(int screen_num):m_screen_num(screen_num) { | 66 | Theme::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 | ||
67 | bool ThemeManager::registerTheme(Theme &tm) { | 88 | bool 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 | ||
81 | bool ThemeManager::unregisterTheme(Theme &tm) { | 105 | bool 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 | ||
86 | bool ThemeManager::load(const std::string &filename, | 114 | bool 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 | ||
161 | void ThemeManager::loadTheme(Theme &tm) { | 182 | void 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)) { |
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 @@ | |||
30 | 30 | ||
31 | #include <string> | 31 | #include <string> |
32 | #include <list> | 32 | #include <list> |
33 | #include <vector> | ||
33 | #include <string> | 34 | #include <string> |
34 | 35 | ||
35 | #include "XrmDatabaseHelper.hh" | 36 | #include "XrmDatabaseHelper.hh" |
@@ -94,6 +95,8 @@ private: | |||
94 | /// Hold ThemeItems. Use this to create a Theme set | 95 | /// Hold ThemeItems. Use this to create a Theme set |
95 | class Theme { | 96 | class Theme { |
96 | public: | 97 | public: |
98 | typedef std::list<ThemeItem_base *> ItemList; | ||
99 | |||
97 | explicit Theme(int screen_num); // create a theme for a specific screen | 100 | explicit Theme(int screen_num); // create a theme for a specific screen |
98 | virtual ~Theme(); | 101 | virtual ~Theme(); |
99 | virtual void reconfigTheme() = 0; | 102 | virtual void reconfigTheme() = 0; |
@@ -113,7 +116,7 @@ public: | |||
113 | 116 | ||
114 | private: | 117 | private: |
115 | const int m_screen_num; | 118 | const int m_screen_num; |
116 | typedef std::list<ThemeItem_base *> ItemList; | 119 | |
117 | ItemList m_themeitems; | 120 | ItemList m_themeitems; |
118 | FbTk::Subject m_reconfig_sig; | 121 | FbTk::Subject m_reconfig_sig; |
119 | }; | 122 | }; |
@@ -125,6 +128,9 @@ private: | |||
125 | */ | 128 | */ |
126 | class ThemeManager { | 129 | class ThemeManager { |
127 | public: | 130 | public: |
131 | typedef std::list<FbTk::Theme *> ThemeList; | ||
132 | typedef std::vector<ThemeList> ScreenThemeVector; | ||
133 | |||
128 | static ThemeManager &instance(); | 134 | static ThemeManager &instance(); |
129 | /// load style file "filename" to screen | 135 | /// load style file "filename" to screen |
130 | bool load(const std::string &filename, const std::string &overlay_filename, int screen_num = -1); | 136 | bool load(const std::string &filename, const std::string &overlay_filename, int screen_num = -1); |
@@ -150,8 +156,8 @@ private: | |||
150 | /// @return false if theme isn't registred in the manager | 156 | /// @return false if theme isn't registred in the manager |
151 | bool unregisterTheme(FbTk::Theme &tm); | 157 | bool unregisterTheme(FbTk::Theme &tm); |
152 | /// map each theme manager to a screen | 158 | /// map each theme manager to a screen |
153 | typedef std::list<FbTk::Theme *> ThemeList; | 159 | |
154 | ThemeList m_themelist; | 160 | ScreenThemeVector m_themes; |
155 | int m_max_screens; | 161 | int m_max_screens; |
156 | XrmDatabaseHelper m_database; | 162 | XrmDatabaseHelper m_database; |
157 | bool m_verbose; | 163 | bool m_verbose; |