aboutsummaryrefslogtreecommitdiff
path: root/src/FocusableTheme.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/FocusableTheme.hh')
-rw-r--r--src/FocusableTheme.hh71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/FocusableTheme.hh b/src/FocusableTheme.hh
new file mode 100644
index 0000000..d0f5d9e
--- /dev/null
+++ b/src/FocusableTheme.hh
@@ -0,0 +1,71 @@
1// FocusableTheme.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 FOCUSABLETHEME_HH
23#define FOCUSABLETHEME_HH
24
25#include "Focusable.hh"
26#include "FbTk/Observer.hh"
27#include "FbTk/Theme.hh"
28
29template <typename BaseTheme>
30class FocusableTheme: public FbTk::ThemeProxy<BaseTheme>,
31 private FbTk::Observer {
32public:
33 FocusableTheme(Focusable &win, FbTk::ThemeProxy<BaseTheme> &focused,
34 FbTk::ThemeProxy<BaseTheme> &unfocused):
35 m_win(win), m_focused_theme(focused), m_unfocused_theme(unfocused) {
36 m_win.focusSig().attach(this);
37 m_win.attentionSig().attach(this);
38 m_focused_theme.reconfigSig().attach(this);
39 m_unfocused_theme.reconfigSig().attach(this);
40 }
41
42 Focusable &win() { return m_win; }
43 const Focusable &win() const { return m_win; }
44
45 FbTk::ThemeProxy<BaseTheme> &focusedTheme() { return m_focused_theme; }
46 const FbTk::ThemeProxy<BaseTheme> &focusedTheme() const { return m_focused_theme; }
47
48 FbTk::ThemeProxy<BaseTheme> &unfocusedTheme() { return m_unfocused_theme; }
49 const FbTk::ThemeProxy<BaseTheme> &unfocusedTheme() const { return m_unfocused_theme; }
50
51 FbTk::Subject &reconfigSig() { return m_reconfig_sig; }
52 const FbTk::Subject &reconfigSig() const { return m_reconfig_sig; }
53
54 virtual BaseTheme &operator *() {
55 return (m_win.isFocused() || m_win.getAttentionState()) ?
56 *m_focused_theme : *m_unfocused_theme;
57 }
58 virtual const BaseTheme &operator *() const {
59 return (m_win.isFocused() || m_win.getAttentionState()) ?
60 *m_focused_theme : *m_unfocused_theme;
61 }
62
63private:
64 void update(FbTk::Subject *subj) { m_reconfig_sig.notify(); }
65
66 Focusable &m_win;
67 FbTk::ThemeProxy<BaseTheme> &m_focused_theme, &m_unfocused_theme;
68 FbTk::Subject m_reconfig_sig;
69};
70
71#endif // FOCUSABLETHEME_HH