diff options
author | Mathias Gumz <akira at fluxbox dot org> | 2010-09-15 00:07:09 (GMT) |
---|---|---|
committer | Mathias Gumz <akira at fluxbox dot org> | 2010-09-15 00:07:09 (GMT) |
commit | 12e1ef78265a621dc51f7b9af245d81431835dcc (patch) | |
tree | b1e7c9ec99f24c89989a34cb994119319184abb7 /src/FbTk | |
parent | ba316aa18a8813958cedea1cc4d54452e40c4b59 (diff) | |
download | fluxbox_paul-12e1ef78265a621dc51f7b9af245d81431835dcc.zip fluxbox_paul-12e1ef78265a621dc51f7b9af245d81431835dcc.tar.bz2 |
code deduplication by using <algorithm> and FbTk/STLUtil.hh
Diffstat (limited to 'src/FbTk')
-rw-r--r-- | src/FbTk/Container.cc | 70 | ||||
-rw-r--r-- | src/FbTk/STLUtil.hh | 27 | ||||
-rw-r--r-- | src/FbTk/Theme.cc | 9 |
3 files changed, 53 insertions, 53 deletions
diff --git a/src/FbTk/Container.cc b/src/FbTk/Container.cc index ce143ef..e1d2e07 100644 --- a/src/FbTk/Container.cc +++ b/src/FbTk/Container.cc | |||
@@ -26,6 +26,7 @@ | |||
26 | #include "TextUtils.hh" | 26 | #include "TextUtils.hh" |
27 | #include "EventManager.hh" | 27 | #include "EventManager.hh" |
28 | #include "CompareEqual.hh" | 28 | #include "CompareEqual.hh" |
29 | #include "STLUtil.hh" | ||
29 | 30 | ||
30 | #include <algorithm> | 31 | #include <algorithm> |
31 | 32 | ||
@@ -78,7 +79,7 @@ void Container::insertItem(Item item, int pos) { | |||
78 | } else if (pos == 0) { | 79 | } else if (pos == 0) { |
79 | m_item_list.push_front(item); | 80 | m_item_list.push_front(item); |
80 | } else { | 81 | } else { |
81 | ItemList::iterator it = m_item_list.begin(); | 82 | ItemList::iterator it = begin(); |
82 | for (; pos != 0; ++it, --pos) | 83 | for (; pos != 0; ++it, --pos) |
83 | continue; | 84 | continue; |
84 | 85 | ||
@@ -104,12 +105,10 @@ void Container::moveItem(Item item, int movement) { | |||
104 | if (newindex < 0) // neg wrap | 105 | if (newindex < 0) // neg wrap |
105 | newindex += size; | 106 | newindex += size; |
106 | 107 | ||
107 | ItemList::iterator it = std::find(m_item_list.begin(), | 108 | ItemList::iterator it = std::find(begin(), end(), item); |
108 | m_item_list.end(), | ||
109 | item); | ||
110 | m_item_list.erase(it); | 109 | m_item_list.erase(it); |
111 | 110 | ||
112 | for (it = m_item_list.begin(); newindex >= 0; ++it, --newindex) { | 111 | for (it = begin(); newindex >= 0; ++it, --newindex) { |
113 | if (newindex == 0) { | 112 | if (newindex == 0) { |
114 | break; | 113 | break; |
115 | } | 114 | } |
@@ -143,12 +142,11 @@ bool Container::moveItemTo(Item item, int x, int y) { | |||
143 | &itemwin)) | 142 | &itemwin)) |
144 | return false; | 143 | return false; |
145 | 144 | ||
146 | ItemList::iterator it = find_if(m_item_list.begin(), | 145 | ItemList::iterator it = find_if(begin(), end(), |
147 | m_item_list.end(), | ||
148 | CompareWindow(&FbWindow::window, | 146 | CompareWindow(&FbWindow::window, |
149 | itemwin)); | 147 | itemwin)); |
150 | // not found :( | 148 | // not found :( |
151 | if (it == m_item_list.end()) | 149 | if (it == end()) |
152 | return false; | 150 | return false; |
153 | 151 | ||
154 | Window child_return = 0; | 152 | Window child_return = 0; |
@@ -162,8 +160,8 @@ bool Container::moveItemTo(Item item, int x, int y) { | |||
162 | } | 160 | } |
163 | 161 | ||
164 | bool Container::removeItem(Item item) { | 162 | bool Container::removeItem(Item item) { |
165 | ItemList::iterator it = m_item_list.begin(); | 163 | ItemList::iterator it = begin(); |
166 | ItemList::iterator it_end = m_item_list.end(); | 164 | ItemList::iterator it_end = end(); |
167 | for (; it != it_end && (*it) != item; ++it); | 165 | for (; it != it_end && (*it) != item; ++it); |
168 | 166 | ||
169 | if (it == it_end) | 167 | if (it == it_end) |
@@ -178,7 +176,7 @@ bool Container::removeItem(int index) { | |||
178 | if (index < 0 || index > size()) | 176 | if (index < 0 || index > size()) |
179 | return false; | 177 | return false; |
180 | 178 | ||
181 | ItemList::iterator it = m_item_list.begin(); | 179 | ItemList::iterator it = begin(); |
182 | for (; index != 0; ++it, --index) | 180 | for (; index != 0; ++it, --index) |
183 | continue; | 181 | continue; |
184 | 182 | ||
@@ -247,12 +245,11 @@ bool Container::tryExposeEvent(XExposeEvent &event) { | |||
247 | return true; | 245 | return true; |
248 | } | 246 | } |
249 | 247 | ||
250 | ItemList::iterator it = find_if(m_item_list.begin(), | 248 | ItemList::iterator it = find_if(begin(), end(), |
251 | m_item_list.end(), | ||
252 | CompareWindow(&FbWindow::window, | 249 | CompareWindow(&FbWindow::window, |
253 | event.window)); | 250 | event.window)); |
254 | // not found :( | 251 | // not found :( |
255 | if (it == m_item_list.end()) | 252 | if (it == end()) |
256 | return false; | 253 | return false; |
257 | 254 | ||
258 | (*it)->exposeEvent(event); | 255 | (*it)->exposeEvent(event); |
@@ -265,12 +262,11 @@ bool Container::tryButtonPressEvent(XButtonEvent &event) { | |||
265 | return true; | 262 | return true; |
266 | } | 263 | } |
267 | 264 | ||
268 | ItemList::iterator it = find_if(m_item_list.begin(), | 265 | ItemList::iterator it = find_if(begin(), end(), |
269 | m_item_list.end(), | ||
270 | CompareWindow(&FbWindow::window, | 266 | CompareWindow(&FbWindow::window, |
271 | event.window)); | 267 | event.window)); |
272 | // not found :( | 268 | // not found :( |
273 | if (it == m_item_list.end()) | 269 | if (it == end()) |
274 | return false; | 270 | return false; |
275 | 271 | ||
276 | (*it)->buttonPressEvent(event); | 272 | (*it)->buttonPressEvent(event); |
@@ -283,12 +279,11 @@ bool Container::tryButtonReleaseEvent(XButtonEvent &event) { | |||
283 | return true; | 279 | return true; |
284 | } | 280 | } |
285 | 281 | ||
286 | ItemList::iterator it = find_if(m_item_list.begin(), | 282 | ItemList::iterator it = find_if(begin(), end(), |
287 | m_item_list.end(), | ||
288 | CompareWindow(&FbWindow::window, | 283 | CompareWindow(&FbWindow::window, |
289 | event.window)); | 284 | event.window)); |
290 | // not found :( | 285 | // not found :( |
291 | if (it == m_item_list.end()) | 286 | if (it == end()) |
292 | return false; | 287 | return false; |
293 | 288 | ||
294 | (*it)->buttonReleaseEvent(event); | 289 | (*it)->buttonReleaseEvent(event); |
@@ -360,8 +355,8 @@ void Container::repositionItems() { | |||
360 | } | 355 | } |
361 | 356 | ||
362 | 357 | ||
363 | ItemList::iterator it = m_item_list.begin(); | 358 | ItemList::iterator it = begin(); |
364 | const ItemList::iterator it_end = m_item_list.end(); | 359 | const ItemList::iterator it_end = end(); |
365 | 360 | ||
366 | int rounding_error = 0; | 361 | int rounding_error = 0; |
367 | 362 | ||
@@ -442,41 +437,26 @@ unsigned int Container::maxWidthPerClient() const { | |||
442 | } | 437 | } |
443 | 438 | ||
444 | void Container::for_each(std::mem_fun_t<void, FbWindow> function) { | 439 | void Container::for_each(std::mem_fun_t<void, FbWindow> function) { |
445 | std::for_each(m_item_list.begin(), | 440 | std::for_each(begin(), end(), function); |
446 | m_item_list.end(), | ||
447 | function); | ||
448 | } | 441 | } |
449 | 442 | ||
450 | void Container::setAlpha(unsigned char alpha) { | 443 | void Container::setAlpha(unsigned char alpha) { |
451 | FbWindow::setAlpha(alpha); | 444 | FbWindow::setAlpha(alpha); |
452 | ItemList::iterator it = m_item_list.begin(); | 445 | STLUtil::forAll(m_item_list, std::bind2nd(std::mem_fun(&Button::setAlpha), alpha)); |
453 | ItemList::iterator it_end = m_item_list.end(); | ||
454 | for (; it != it_end; ++it) | ||
455 | (*it)->setAlpha(alpha); | ||
456 | } | 446 | } |
457 | 447 | ||
458 | void Container::parentMoved() { | 448 | void Container::parentMoved() { |
459 | FbWindow::parentMoved(); | 449 | FbWindow::parentMoved(); |
460 | ItemList::iterator it = m_item_list.begin(); | 450 | STLUtil::forAll(m_item_list, std::mem_fun(&Button::parentMoved)); |
461 | ItemList::iterator it_end = m_item_list.end(); | ||
462 | for (; it != it_end; ++it) | ||
463 | (*it)->parentMoved(); | ||
464 | } | 451 | } |
465 | 452 | ||
466 | void Container::invalidateBackground() { | 453 | void Container::invalidateBackground() { |
467 | FbWindow::invalidateBackground(); | 454 | FbWindow::invalidateBackground(); |
468 | ItemList::iterator it = m_item_list.begin(); | 455 | STLUtil::forAll(m_item_list, std::mem_fun(&Button::invalidateBackground)); |
469 | ItemList::iterator it_end = m_item_list.end(); | ||
470 | for (; it != it_end; ++it) | ||
471 | (*it)->invalidateBackground(); | ||
472 | } | 456 | } |
473 | 457 | ||
474 | void Container::clear() { | 458 | void Container::clear() { |
475 | ItemList::iterator it = m_item_list.begin(); | 459 | STLUtil::forAll(m_item_list, std::mem_fun(&Button::clear)); |
476 | ItemList::iterator it_end = m_item_list.end(); | ||
477 | for (; it != it_end; ++it) | ||
478 | (*it)->clear(); | ||
479 | |||
480 | } | 460 | } |
481 | 461 | ||
482 | void Container::setOrientation(Orientation orient) { | 462 | void Container::setOrientation(Orientation orient) { |
@@ -484,11 +464,7 @@ void Container::setOrientation(Orientation orient) { | |||
484 | return; | 464 | return; |
485 | 465 | ||
486 | FbWindow::invalidateBackground(); | 466 | FbWindow::invalidateBackground(); |
487 | 467 | STLUtil::forAll(m_item_list, std::bind2nd(std::mem_fun(&Button::setOrientation), orient)); | |
488 | ItemList::iterator it = m_item_list.begin(); | ||
489 | ItemList::iterator it_end = m_item_list.end(); | ||
490 | for (; it != it_end; ++it) | ||
491 | (*it)->setOrientation(orient); | ||
492 | 468 | ||
493 | if (((m_orientation == ROT0 || m_orientation == ROT180) && | 469 | if (((m_orientation == ROT0 || m_orientation == ROT180) && |
494 | (orient == ROT90 || orient == ROT270)) || | 470 | (orient == ROT90 || orient == ROT270)) || |
diff --git a/src/FbTk/STLUtil.hh b/src/FbTk/STLUtil.hh index e08036a..b1007f7 100644 --- a/src/FbTk/STLUtil.hh +++ b/src/FbTk/STLUtil.hh | |||
@@ -68,6 +68,33 @@ void destroyAndClearSecond(A &a) { | |||
68 | a.clear(); | 68 | a.clear(); |
69 | } | 69 | } |
70 | 70 | ||
71 | |||
72 | template <typename C, typename F> | ||
73 | F forAll(C& c, F f) { | ||
74 | typedef typename C::iterator iterator; | ||
75 | iterator i = c.begin(); | ||
76 | iterator e = c.end(); | ||
77 | for (; i != e; i++) { | ||
78 | f(*i); | ||
79 | } | ||
80 | return f; | ||
81 | } | ||
82 | |||
83 | template <typename C, typename I, typename F> | ||
84 | F forAllIf(C& c, I i, F f) { | ||
85 | typedef typename C::iterator iterator; | ||
86 | iterator it = c.begin(); | ||
87 | iterator end = c.end(); | ||
88 | for (; it != end; it++) { | ||
89 | if (i(*it)) | ||
90 | f(*it); | ||
91 | } | ||
92 | return f; | ||
93 | } | ||
94 | |||
95 | |||
96 | |||
97 | |||
71 | } // end namespace STLUtil | 98 | } // end namespace STLUtil |
72 | } // end namespace FbTk | 99 | } // end namespace FbTk |
73 | 100 | ||
diff --git a/src/FbTk/Theme.cc b/src/FbTk/Theme.cc index cd478fc..c92e563 100644 --- a/src/FbTk/Theme.cc +++ b/src/FbTk/Theme.cc | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "FileUtil.hh" | 27 | #include "FileUtil.hh" |
28 | #include "I18n.hh" | 28 | #include "I18n.hh" |
29 | #include "Image.hh" | 29 | #include "Image.hh" |
30 | #include "STLUtil.hh" | ||
30 | 31 | ||
31 | #ifdef HAVE_CSTDIO | 32 | #ifdef HAVE_CSTDIO |
32 | #include <cstdio> | 33 | #include <cstdio> |
@@ -50,13 +51,11 @@ struct LoadThemeHelper { | |||
50 | } | 51 | } |
51 | void operator ()(ThemeManager::ThemeList &tmlist) { | 52 | void operator ()(ThemeManager::ThemeList &tmlist) { |
52 | 53 | ||
53 | for_each(tmlist.begin(), tmlist.end(), | 54 | STLUtil::forAll(tmlist, *this); |
54 | *this); | ||
55 | // send reconfiguration signal to theme and listeners | 55 | // send reconfiguration signal to theme and listeners |
56 | ThemeManager::ThemeList::iterator it = tmlist.begin(); | 56 | ThemeManager::ThemeList::iterator it = tmlist.begin(); |
57 | ThemeManager::ThemeList::iterator it_end = tmlist.end(); | 57 | ThemeManager::ThemeList::iterator it_end = tmlist.end(); |
58 | for (; it != it_end; ++it) { | 58 | for (; it != it_end; ++it) { |
59 | (*it)->reconfigTheme(); | ||
60 | (*it)->reconfigSig().notify(); | 59 | (*it)->reconfigSig().notify(); |
61 | } | 60 | } |
62 | } | 61 | } |
@@ -174,9 +173,7 @@ bool ThemeManager::load(const string &filename, | |||
174 | // get list and go throu all the resources and load them | 173 | // get list and go throu all the resources and load them |
175 | // and then reconfigure them | 174 | // and then reconfigure them |
176 | if (screen_num < 0 || screen_num > m_max_screens) { | 175 | if (screen_num < 0 || screen_num > m_max_screens) { |
177 | for_each(m_themes.begin(), | 176 | STLUtil::forAll(m_themes, load_theme_helper); |
178 | m_themes.end(), | ||
179 | load_theme_helper); | ||
180 | } else { | 177 | } else { |
181 | load_theme_helper(m_themes[screen_num]); | 178 | load_theme_helper(m_themes[screen_num]); |
182 | } | 179 | } |