diff options
Diffstat (limited to 'src/WindowMenuAccessor.hh')
-rw-r--r-- | src/WindowMenuAccessor.hh | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/WindowMenuAccessor.hh b/src/WindowMenuAccessor.hh new file mode 100644 index 0000000..91994b9 --- /dev/null +++ b/src/WindowMenuAccessor.hh | |||
@@ -0,0 +1,74 @@ | |||
1 | // WindowMenuAccessor.hh | ||
2 | // Copyright (c) 2008 Fluxbox Team (fluxgen at fluxbox dot org) | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | #ifndef WINDOW_MENU_ACCESSOR_HH | ||
23 | #define WINDOW_MENU_ACCESSOR_HH | ||
24 | |||
25 | #include "FbTk/Accessor.hh" | ||
26 | |||
27 | #include "FbMenu.hh" | ||
28 | |||
29 | /// accesses values in current window | ||
30 | template <typename Ret, typename Def=Ret> | ||
31 | class WindowMenuAccessor: public FbTk::Accessor<Ret> { | ||
32 | public: | ||
33 | typedef Ret (FluxboxWindow:: *Getter)() const; | ||
34 | typedef void (FluxboxWindow:: *Setter)(Ret); | ||
35 | WindowMenuAccessor(Getter g, Setter s, Def def): | ||
36 | m_getter(g), m_setter(s), m_def(def) { } | ||
37 | |||
38 | operator Ret() const { | ||
39 | FluxboxWindow *fbwin = FbMenu::window(); | ||
40 | return fbwin ? (fbwin->*m_getter)() : m_def; | ||
41 | } | ||
42 | FbTk::Accessor<Ret> &operator =(const Ret &val) { | ||
43 | FluxboxWindow *fbwin = FbMenu::window(); | ||
44 | if (fbwin) | ||
45 | (fbwin->*m_setter)(val); | ||
46 | return *this; | ||
47 | } | ||
48 | |||
49 | private: | ||
50 | Getter m_getter; | ||
51 | Setter m_setter; | ||
52 | Def m_def; | ||
53 | }; | ||
54 | |||
55 | /// same as above but only reads | ||
56 | template <typename Ret, typename Def=Ret> | ||
57 | class ConstWindowMenuAccessor: public FbTk::Accessor<Ret> { | ||
58 | public: | ||
59 | typedef Ret (FluxboxWindow:: *Getter)() const; | ||
60 | ConstWindowMenuAccessor(Getter g, Def def): | ||
61 | m_getter(g), m_def(def) { } | ||
62 | |||
63 | operator Ret() const { | ||
64 | FluxboxWindow *fbwin = FbMenu::window(); | ||
65 | return fbwin ? (fbwin->*m_getter)() : m_def; | ||
66 | } | ||
67 | FbTk::Accessor<Ret> &operator =(const Ret &val) { return *this; } | ||
68 | |||
69 | private: | ||
70 | Getter m_getter; | ||
71 | Def m_def; | ||
72 | }; | ||
73 | |||
74 | #endif // WINDOW_MENU_ACCESSOR_HH | ||