From ae68b7f7cd47c91e776fadee7aecb93d5b3ee3df Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Wed, 4 May 2011 18:26:15 +0200 Subject: Convert Focusable::orderSig,addSig,removeSig,resetSig to FbTk::Signal --- src/FocusableList.cc | 63 ++++++++++++++++++++++++++-------------------------- src/FocusableList.hh | 33 +++++++++------------------ src/IconbarTool.cc | 47 +++++++++++++++++++++------------------ src/IconbarTool.hh | 8 ++++--- 4 files changed, 72 insertions(+), 79 deletions(-) diff --git a/src/FocusableList.cc b/src/FocusableList.cc index a130ec0..73d865e 100644 --- a/src/FocusableList.cc +++ b/src/FocusableList.cc @@ -125,40 +125,41 @@ void FocusableList::update(FbTk::Subject *subj) { checkUpdate(**it); } } - if (typeid(*subj) == typeid(FocusableListSubject)) { - FocusableListSubject *fsubj = - static_cast(subj); - if (subj == &m_parent->addSig()) { - attachSignals(*fsubj->win()); - if (m_pat->match(*fsubj->win())) { - insertFromParent(*fsubj->win()); - m_addsig.notify(fsubj->win()); - } - } else if (subj == &m_parent->removeSig()) - remove(*fsubj->win()); - else if (subj == &m_parent->resetSig()) - reset(); - else if (subj == &m_parent->orderSig()) { - Focusable *win = fsubj->win(); - if (!win || !contains(*win)) - return; - if (insertFromParent(*win)) - m_ordersig.notify(win); +} + +void FocusableList::parentOrderChanged(Focusable *win) { + if(!m_screen.isShuttingdown() && contains(*win)) { + if(insertFromParent(*win)) + m_ordersig.emit(win); + } +} + +void FocusableList::parentWindowAdded(Focusable *win) { + if(!m_screen.isShuttingdown()) { + attachSignals(*win); + if (m_pat->match(*win)) { + insertFromParent(*win); + m_addsig.emit(win); } } } +void FocusableList::parentWindowRemoved(Focusable *win) { + if(!m_screen.isShuttingdown()) + remove(*win); +} + void FocusableList::checkUpdate(Focusable &win) { if (contains(win)) { if (!m_pat->match(win)) { m_list.remove(&win); m_pat->removeMatch(); - m_removesig.notify(&win); + m_removesig.emit(&win); } } else if (m_pat->match(win)) { insertFromParent(win); m_pat->addMatch(); - m_addsig.notify(&win); + m_addsig.emit(&win); } } @@ -203,13 +204,13 @@ void FocusableList::addMatching() { void FocusableList::pushFront(Focusable &win) { m_list.push_front(&win); attachSignals(win); - m_addsig.notify(&win); + m_addsig.emit(&win); } void FocusableList::pushBack(Focusable &win) { m_list.push_back(&win); attachSignals(win); - m_addsig.notify(&win); + m_addsig.emit(&win); } void FocusableList::moveToFront(Focusable &win) { @@ -219,7 +220,7 @@ void FocusableList::moveToFront(Focusable &win) { m_list.remove(&win); m_list.push_front(&win); - m_ordersig.notify(&win); + m_ordersig.emit(&win); } void FocusableList::moveToBack(Focusable &win) { @@ -229,7 +230,7 @@ void FocusableList::moveToBack(Focusable &win) { m_list.remove(&win); m_list.push_back(&win); - m_ordersig.notify(&win); + m_ordersig.emit(&win); } void FocusableList::remove(Focusable &win) { @@ -241,7 +242,7 @@ void FocusableList::remove(Focusable &win) { return; } m_list.remove(&win); - m_removesig.notify(&win); + m_removesig.emit(&win); } void FocusableList::updateTitle(Focusable& win) { @@ -292,7 +293,7 @@ void FocusableList::reset() { m_pat->resetMatches(); if (m_parent) addMatching(); - m_resetsig.notify(0); + m_resetsig.emit(); } bool FocusableList::contains(const Focusable &win) const { @@ -311,10 +312,10 @@ Focusable *FocusableList::find(const ClientPattern &pat) const { } void FocusableList::attachChild(FocusableList &child) const { - m_addsig.attach(&child); - m_removesig.attach(&child); - m_resetsig.attach(&child); - m_ordersig.attach(&child); + m_addsig.connect(FbTk::MemFun(child, &FocusableList::parentWindowAdded)); + m_ordersig.connect(FbTk::MemFun(child, &FocusableList::parentOrderChanged)); + m_removesig.connect(FbTk::MemFun(child, &FocusableList::parentWindowRemoved)); + m_resetsig.connect(FbTk::MemFun(child, &FocusableList::reset)); } void FocusableList::workspaceChanged(BScreen &screen) { diff --git a/src/FocusableList.hh b/src/FocusableList.hh index 6e46db9..29d536f 100644 --- a/src/FocusableList.hh +++ b/src/FocusableList.hh @@ -82,30 +82,12 @@ public: @name signals @{ */ - FbTk::Subject &orderSig() { return m_ordersig; } - const FbTk::Subject &orderSig() const { return m_ordersig; } - FbTk::Subject &addSig() { return m_addsig; } - const FbTk::Subject &addSig() const { return m_addsig; } - FbTk::Subject &removeSig() { return m_removesig; } - const FbTk::Subject &removeSig() const { return m_removesig; } - FbTk::Subject &resetSig() { return m_resetsig; } - const FbTk::Subject &resetSig() const { return m_resetsig; } + FbTk::Signal &orderSig() { return m_ordersig; } + FbTk::Signal &addSig() { return m_addsig; } + FbTk::Signal &removeSig() { return m_removesig; } + FbTk::Signal<> &resetSig() { return m_resetsig; } /** @} */ // end group signals - /** - * Signaling object to attatch observers to. - */ - class FocusableListSubject: public FbTk::Subject { - public: - explicit FocusableListSubject(): m_win(0) { } - void notify(Focusable *win) { m_win = win; FbTk::Subject::notify(); } - /// @return context for this signal - Focusable *win() { return m_win; } - - private: - Focusable *m_win; - }; - private: void init(); void addMatching(); @@ -120,13 +102,18 @@ private: /// Title has changed for a window /// @param win The window that title changed for. void updateTitle(Focusable& win); + void parentOrderChanged(Focusable* win); + void parentWindowAdded(Focusable* win); + void parentWindowRemoved(Focusable* win); + std::auto_ptr m_pat; const FocusableList *m_parent; BScreen &m_screen; std::list m_list; - mutable FocusableListSubject m_ordersig, m_addsig, m_removesig, m_resetsig; + mutable FbTk::Signal m_ordersig, m_addsig, m_removesig; + mutable FbTk::Signal<> m_resetsig; typedef std::map > SignalMap; SignalMap m_signal_map; }; diff --git a/src/IconbarTool.cc b/src/IconbarTool.cc index 42817c5..45e3a45 100644 --- a/src/IconbarTool.cc +++ b/src/IconbarTool.cc @@ -331,7 +331,7 @@ void IconbarTool::hide() { void IconbarTool::setAlignment(FbTk::Container::Alignment align) { *m_rc_alignment = align; - update(0); + update(ALIGN, NULL); m_menu.reconfigure(); } @@ -344,22 +344,24 @@ void IconbarTool::setMode(string mode) { // lock graphics update m_icon_container.setUpdateLock(true); - if (m_winlist.get()) { - m_winlist->addSig().detach(this); - m_winlist->removeSig().detach(this); - m_winlist->orderSig().detach(this); - m_winlist->resetSig().detach(this); - } if (mode == "none") m_winlist.reset(new FocusableList(m_screen)); else m_winlist.reset(new FocusableList(m_screen, mode + " (iconhidden=no)")); if (m_winlist.get()) { - m_winlist->addSig().attach(this); - m_winlist->removeSig().attach(this); - m_winlist->orderSig().attach(this); - m_winlist->resetSig().attach(this); + m_winlist->addSig().connect( + std::bind1st(FbTk::MemFun(*this, &IconbarTool::update), LIST_ADD) + ); + m_winlist->removeSig().connect( + std::bind1st(FbTk::MemFun(*this, &IconbarTool::update), LIST_REMOVE) + ); + m_winlist->addSig().connect( + std::bind1st(FbTk::MemFun(*this, &IconbarTool::update), LIST_ORDER) + ); + m_winlist->resetSig().connect(FbTk::MemFunBind( + *this, &IconbarTool::update, LIST_RESET, static_cast(0) + )); } reset(); @@ -389,7 +391,7 @@ void IconbarTool::themeReconfigured() { setMode(*m_rc_mode); } -void IconbarTool::update(FbTk::Subject *subj) { +void IconbarTool::update(UpdateReason reason, Focusable *win) { // ignore updates if we're shutting down if (m_screen.isShuttingdown()) { if (!m_icons.empty()) @@ -405,17 +407,18 @@ void IconbarTool::update(FbTk::Subject *subj) { // lock graphic update m_icon_container.setUpdateLock(true); - if (subj && typeid(*subj) == typeid(FocusableList::FocusableListSubject)) { - FocusableList::FocusableListSubject *fsubj = - static_cast(subj); - if (subj == &m_winlist->addSig()) - insertWindow(*fsubj->win()); - else if (subj == &m_winlist->removeSig()) - removeWindow(*fsubj->win()); - else if (subj == &m_winlist->resetSig()) + switch(reason) { + case LIST_ADD: case LIST_ORDER: + insertWindow(*win); + break; + case LIST_REMOVE: + removeWindow(*win); + break; + case LIST_RESET: reset(); - else if (subj == &m_winlist->orderSig()) - insertWindow(*fsubj->win()); + break; + case ALIGN: + break; } // unlock container and update graphics diff --git a/src/IconbarTool.hh b/src/IconbarTool.hh index 92fbe63..118eacf 100644 --- a/src/IconbarTool.hh +++ b/src/IconbarTool.hh @@ -28,7 +28,6 @@ #include "FbTk/Container.hh" #include "FbTk/CachedPixmap.hh" -#include "FbTk/Observer.hh" #include "FbTk/Resource.hh" #include @@ -39,7 +38,7 @@ class IconButton; class Focusable; class FocusableList; -class IconbarTool: public ToolbarItem, public FbTk::Observer { +class IconbarTool: public ToolbarItem { public: typedef std::map IconMap; @@ -54,7 +53,6 @@ public: void moveResize(int x, int y, unsigned int width, unsigned int height); - void update(FbTk::Subject *subj); void show(); void hide(); void setAlignment(FbTk::Container::Alignment a); @@ -72,6 +70,7 @@ public: const BScreen &screen() const { return m_screen; } private: + enum UpdateReason { LIST_ORDER, LIST_ADD, LIST_REMOVE, LIST_RESET, ALIGN }; void updateSizing(); @@ -95,6 +94,9 @@ private: /// add icons to the list void updateList(); + /// called when the list emits a signal + void update(UpdateReason reason, Focusable *win); + void themeReconfigured(); BScreen &m_screen; -- cgit v0.11.2