aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/AttentionNoticeHandler.cc1
-rw-r--r--src/FbTk/Makefile.am3
-rw-r--r--src/FbTk/Observer.cc31
-rw-r--r--src/FbTk/Observer.hh37
-rw-r--r--src/FbTk/RelaySignal.hh62
-rw-r--r--src/FbTk/SimpleObserver.hh70
-rw-r--r--src/FbTk/Subject.cc85
-rw-r--r--src/FbTk/Subject.hh57
-rw-r--r--src/FocusableList.hh2
-rw-r--r--src/FocusableTheme.hh2
-rw-r--r--src/Screen.hh2
-rw-r--r--src/SendToMenu.cc1
-rw-r--r--src/SendToMenu.hh4
-rw-r--r--src/WinButton.hh1
-rw-r--r--src/Window.hh3
15 files changed, 2 insertions, 359 deletions
diff --git a/src/AttentionNoticeHandler.cc b/src/AttentionNoticeHandler.cc
index 7edd8e2..0aaf266 100644
--- a/src/AttentionNoticeHandler.cc
+++ b/src/AttentionNoticeHandler.cc
@@ -25,7 +25,6 @@
25#include "Screen.hh" 25#include "Screen.hh"
26 26
27#include "FbTk/STLUtil.hh" 27#include "FbTk/STLUtil.hh"
28#include "FbTk/Subject.hh"
29#include "FbTk/Timer.hh" 28#include "FbTk/Timer.hh"
30#include "FbTk/Resource.hh" 29#include "FbTk/Resource.hh"
31#include "FbTk/MemFun.hh" 30#include "FbTk/MemFun.hh"
diff --git a/src/FbTk/Makefile.am b/src/FbTk/Makefile.am
index 8619cc1..4c38f84 100644
--- a/src/FbTk/Makefile.am
+++ b/src/FbTk/Makefile.am
@@ -46,7 +46,6 @@ libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \
46 StringUtil.hh StringUtil.cc Parser.hh Parser.cc \ 46 StringUtil.hh StringUtil.cc Parser.hh Parser.cc \
47 RegExp.hh RegExp.cc \ 47 RegExp.hh RegExp.cc \
48 FbString.hh FbString.cc \ 48 FbString.hh FbString.cc \
49 Subject.hh Subject.cc Observer.hh Observer.cc SimpleObserver.hh \
50 AutoReloadHelper.hh AutoReloadHelper.cc \ 49 AutoReloadHelper.hh AutoReloadHelper.cc \
51 Transparent.hh Transparent.cc \ 50 Transparent.hh Transparent.cc \
52 FbPixmap.hh FbPixmap.cc \ 51 FbPixmap.hh FbPixmap.cc \
@@ -63,7 +62,7 @@ libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \
63 TypeAhead.hh SearchResult.hh SearchResult.cc ITypeAheadable.hh \ 62 TypeAhead.hh SearchResult.hh SearchResult.cc ITypeAheadable.hh \
64 Select2nd.hh STLUtil.hh \ 63 Select2nd.hh STLUtil.hh \
65 CachedPixmap.hh CachedPixmap.cc \ 64 CachedPixmap.hh CachedPixmap.cc \
66 Slot.hh Signal.hh MemFun.hh RelaySignal.hh SelectArg.hh \ 65 Slot.hh Signal.hh MemFun.hh SelectArg.hh \
67 Util.hh \ 66 Util.hh \
68 ${xpm_SOURCE} \ 67 ${xpm_SOURCE} \
69 ${xft_SOURCE} \ 68 ${xft_SOURCE} \
diff --git a/src/FbTk/Observer.cc b/src/FbTk/Observer.cc
deleted file mode 100644
index dcd115f..0000000
--- a/src/FbTk/Observer.cc
+++ /dev/null
@@ -1,31 +0,0 @@
1// Observer.cc for FbTk
2// Copyright (c) 2002 - 2006 Henrik Kinnunen (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#include "Observer.hh"
23#include "Subject.hh"
24
25namespace FbTk {
26
27Observer::~Observer() {
28 Subject::removeObserver(this); // make sure no subject has this observer attached
29}
30
31}
diff --git a/src/FbTk/Observer.hh b/src/FbTk/Observer.hh
deleted file mode 100644
index 3f1a8c3..0000000
--- a/src/FbTk/Observer.hh
+++ /dev/null
@@ -1,37 +0,0 @@
1// Observer.hh for FbTk
2// Copyright (c) 2002 Henrik Kinnunen (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 FBTK_OBSERVER_HH
23#define FBTK_OBSERVER_HH
24
25namespace FbTk {
26
27class Subject;
28
29class Observer {
30public:
31 virtual ~Observer();
32 virtual void update(Subject *changedSubj) = 0;
33};
34
35} // end namespace FBTK
36
37#endif // FBTK_OBSERVER_HH
diff --git a/src/FbTk/RelaySignal.hh b/src/FbTk/RelaySignal.hh
deleted file mode 100644
index e9b7281..0000000
--- a/src/FbTk/RelaySignal.hh
+++ /dev/null
@@ -1,62 +0,0 @@
1// RelaySignal.hh
2// Copyright (c) 2010 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 FBTK_RELAY_SIGNAL_HH
23#define FBTK_RELAY_SIGNAL_HH
24
25#include "Signal.hh"
26#include "MemFun.hh"
27#include "Subject.hh"
28
29namespace FbTk {
30
31/**
32 * Relays a new signal type to the old subject type signal. When the new signal
33 * emits the subject notify() will be called.
34 * This function is temporary and just a helper during transition between old
35 * and new signal system.
36 *
37 * @param from The original source of the signal.
38 * @param to_subject The destination Subject.
39 */
40template < typename Signal >
41void relaySignal(Signal& from, FbTk::Subject& to_subject) {
42 from.connect(MemFunIgnoreArgs(to_subject, &FbTk::Subject::notify));
43}
44
45/**
46 * Relays a new signal type to the old subject type signal. When the new signal
47 * emits the subject notify() will be called.
48 * This function is temporary and just a helper during transition between old
49 * and new signal system.
50 *
51 * @param tracker Keeps track of signals
52 * @param from The original source of the signal.
53 * @param to_subject The destination Subject
54 */
55template < typename Signal >
56void relaySignal(SignalTracker& tracker, Signal& from, FbTk::Subject& to_subject) {
57 tracker.join(from, MemFunIgnoreArgs(to_subject, &FbTk::Subject::notify));
58}
59
60} // end namespace FbTk
61
62#endif // FBTK_RELAY_SIGNAL_HH
diff --git a/src/FbTk/SimpleObserver.hh b/src/FbTk/SimpleObserver.hh
deleted file mode 100644
index aafdf59..0000000
--- a/src/FbTk/SimpleObserver.hh
+++ /dev/null
@@ -1,70 +0,0 @@
1// SimpleObserver.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#include "Observer.hh"
23#include "SimpleCommand.hh"
24
25namespace FbTk {
26
27/** Functor for observers, instead of using this directly use makeObserver.
28 * Usage:
29 * @code
30 * class SomeClass {
31 * public:
32 * void doAction();
33 * };
34 *
35 * SomeClass some;
36 *
37 * Observer* obs = makeProxyObserver(some, &SomeClass::doAction);
38 * SomeSubject subj;
39 * subj.attach(obs);
40 * @endcode
41 */
42template <typename Receiver>
43class SimpleObserver: public Observer {
44public:
45 typedef void (Receiver::* Action)();
46 SimpleObserver(Receiver &r, Action a):
47 m_receiver(r), m_action(a) {
48
49 }
50 void update(Subject *changedSubj) {
51 (m_receiver.*m_action)();
52 }
53private:
54 Receiver &m_receiver;
55 Action m_action;
56};
57
58// Helpers
59/** Creates an observer that takes no arguments.
60 * @param receiver The receiving instance.
61 * @param action A function in the receiving class.
62 * @return allocated simple observer. @see SimpleObserver
63 */
64template <typename Receiver, typename Action>
65Observer *makeObserver(Receiver &receiver, Action action) {
66 return new SimpleObserver<Receiver>( receiver, action );
67}
68
69}
70
diff --git a/src/FbTk/Subject.cc b/src/FbTk/Subject.cc
deleted file mode 100644
index 594eb23..0000000
--- a/src/FbTk/Subject.cc
+++ /dev/null
@@ -1,85 +0,0 @@
1// Subject.cc for FbTk
2// Copyright (c) 2002 - 2006 Henrik Kinnunen (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#include "Subject.hh"
23#include "Observer.hh"
24
25#include <algorithm>
26#include <functional>
27
28namespace FbTk {
29
30Subject::SubjectList Subject::s_subjectlist;
31
32Subject::Subject():m_notify_mode(false) {
33 s_subjectlist.push_back(this);
34}
35
36Subject::~Subject() {
37 s_subjectlist.erase(std::remove(s_subjectlist.begin(),
38 s_subjectlist.end(), this));
39}
40
41void Subject::attach(Observer *obj) {
42 m_observerlist.push_back(obj);
43 // no need to have more than one instance of an observer
44 m_observerlist.erase(std::unique(m_observerlist.begin(), m_observerlist.end()),
45 m_observerlist.end());
46}
47
48void Subject::detach(Observer *obj) {
49 if (m_notify_mode)
50 m_dead_observers.push_back(obj);
51 else {
52 m_observerlist.erase(std::remove(m_observerlist.begin(),
53 m_observerlist.end(), obj),
54 m_observerlist.end());
55 }
56}
57
58void Subject::notify() {
59 ObserverList::iterator it = m_observerlist.begin(),
60 it_end = m_observerlist.end();
61 for (; it != it_end; ++it) {
62 m_notify_mode = true;
63 (*it)->update(this);
64 ObserverList::iterator d_it = m_dead_observers.begin(),
65 d_it_end = m_dead_observers.end();
66 m_notify_mode = false;
67
68 // there might be dead observers later in the list, so we must remove
69 // them now
70 for (; d_it != d_it_end; ++d_it) {
71 if (*d_it == *it)
72 --it; // don't invalidate our iterator
73 detach(*d_it);
74 }
75 m_dead_observers.clear();
76 }
77}
78
79void Subject::removeObserver(Observer *obj) {
80 std::for_each(s_subjectlist.begin(), s_subjectlist.end(),
81 std::bind2nd(std::mem_fun(&Subject::detach), obj));
82
83}
84
85} // end namespace FbTk
diff --git a/src/FbTk/Subject.hh b/src/FbTk/Subject.hh
deleted file mode 100644
index f2cde41..0000000
--- a/src/FbTk/Subject.hh
+++ /dev/null
@@ -1,57 +0,0 @@
1// Subject.hh for FbTk
2// Copyright (c) 2002-2003 Henrik Kinnunen (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 FBTK_SUBJECT_HH
23#define FBTK_SUBJECT_HH
24
25#include "NotCopyable.hh"
26
27#include <list>
28
29namespace FbTk {
30
31class Observer;
32
33class Subject:private FbTk::NotCopyable {
34public:
35 Subject();
36 virtual ~Subject();
37 /// attach an observer
38 void attach(Observer *obs);
39 /// detach an observer
40 void detach(Observer *obs);
41 /// notify all attached observers
42 void notify();
43 static void removeObserver(Observer *obs);
44private:
45 bool m_notify_mode;
46
47 typedef std::list<Observer *> ObserverList;
48 ObserverList m_observerlist;
49 ObserverList m_dead_observers;
50
51 typedef std::list<Subject *> SubjectList;
52 static SubjectList s_subjectlist;
53};
54
55} // end namespace FbTk
56
57#endif // FBTK_SUBJECT_HH
diff --git a/src/FocusableList.hh b/src/FocusableList.hh
index aea7909..48881d0 100644
--- a/src/FocusableList.hh
+++ b/src/FocusableList.hh
@@ -23,9 +23,7 @@
23#define FOCUSABLELIST_HH 23#define FOCUSABLELIST_HH
24 24
25#include "FbTk/NotCopyable.hh" 25#include "FbTk/NotCopyable.hh"
26#include "FbTk/Observer.hh"
27#include "FbTk/RefCount.hh" 26#include "FbTk/RefCount.hh"
28#include "FbTk/Subject.hh"
29#include "FbTk/Signal.hh" 27#include "FbTk/Signal.hh"
30 28
31#include "ClientPattern.hh" 29#include "ClientPattern.hh"
diff --git a/src/FocusableTheme.hh b/src/FocusableTheme.hh
index df73881..49d7945 100644
--- a/src/FocusableTheme.hh
+++ b/src/FocusableTheme.hh
@@ -23,8 +23,8 @@
23#define FOCUSABLETHEME_HH 23#define FOCUSABLETHEME_HH
24 24
25#include "Focusable.hh" 25#include "Focusable.hh"
26#include "FbTk/MemFun.hh"
26#include "FbTk/Theme.hh" 27#include "FbTk/Theme.hh"
27#include "FbTk/RelaySignal.hh"
28 28
29template <typename BaseTheme> 29template <typename BaseTheme>
30class FocusableTheme: public FbTk::ThemeProxy<BaseTheme> { 30class FocusableTheme: public FbTk::ThemeProxy<BaseTheme> {
diff --git a/src/Screen.hh b/src/Screen.hh
index a237b36..de3a5a1 100644
--- a/src/Screen.hh
+++ b/src/Screen.hh
@@ -35,10 +35,8 @@
35#include "FbTk/MenuTheme.hh" 35#include "FbTk/MenuTheme.hh"
36#include "FbTk/EventHandler.hh" 36#include "FbTk/EventHandler.hh"
37#include "FbTk/Resource.hh" 37#include "FbTk/Resource.hh"
38#include "FbTk/Subject.hh"
39#include "FbTk/MultLayers.hh" 38#include "FbTk/MultLayers.hh"
40#include "FbTk/NotCopyable.hh" 39#include "FbTk/NotCopyable.hh"
41#include "FbTk/Observer.hh"
42#include "FbTk/Signal.hh" 40#include "FbTk/Signal.hh"
43 41
44#include "FocusControl.hh" 42#include "FocusControl.hh"
diff --git a/src/SendToMenu.cc b/src/SendToMenu.cc
index b148a30..afdc854 100644
--- a/src/SendToMenu.cc
+++ b/src/SendToMenu.cc
@@ -30,7 +30,6 @@
30 30
31#include "FbTk/MultiButtonMenuItem.hh" 31#include "FbTk/MultiButtonMenuItem.hh"
32#include "FbTk/Command.hh" 32#include "FbTk/Command.hh"
33#include "FbTk/SimpleObserver.hh"
34#include "FbTk/MemFun.hh" 33#include "FbTk/MemFun.hh"
35 34
36class SendToCmd: public FbTk::Command<void> { 35class SendToCmd: public FbTk::Command<void> {
diff --git a/src/SendToMenu.hh b/src/SendToMenu.hh
index 37f45fc..0509360 100644
--- a/src/SendToMenu.hh
+++ b/src/SendToMenu.hh
@@ -27,10 +27,6 @@
27 27
28#include "FbTk/Signal.hh" 28#include "FbTk/Signal.hh"
29 29
30namespace FbTk {
31class Observer;
32}
33
34class BScreen; 30class BScreen;
35 31
36/** 32/**
diff --git a/src/WinButton.hh b/src/WinButton.hh
index 35befa8..80fc4b1 100644
--- a/src/WinButton.hh
+++ b/src/WinButton.hh
@@ -23,7 +23,6 @@
23#define WINBUTTON_HH 23#define WINBUTTON_HH
24 24
25#include "FbTk/Button.hh" 25#include "FbTk/Button.hh"
26#include "FbTk/Observer.hh"
27#include "FbTk/FbPixmap.hh" 26#include "FbTk/FbPixmap.hh"
28#include "FbTk/Signal.hh" 27#include "FbTk/Signal.hh"
29 28
diff --git a/src/Window.hh b/src/Window.hh
index 4ecfe05..a5bcb66 100644
--- a/src/Window.hh
+++ b/src/Window.hh
@@ -317,9 +317,6 @@ public:
317 void leaveNotifyEvent(XCrossingEvent &ev); 317 void leaveNotifyEvent(XCrossingEvent &ev);
318 //@} 318 //@}
319 319
320 /// handle Subject notifications
321 void update(FbTk::Subject *subj);
322
323 void applyDecorations(); 320 void applyDecorations();
324 void toggleDecoration(); 321 void toggleDecoration();
325 322