Convert Focusable::orderSig,addSig,removeSig,resetSig to FbTk::Signal

This commit is contained in:
Pavel Labath 2011-05-04 18:26:15 +02:00
parent 19ac8e40d8
commit ae68b7f7cd
4 changed files with 72 additions and 79 deletions

View file

@ -125,40 +125,41 @@ void FocusableList::update(FbTk::Subject *subj) {
checkUpdate(**it); checkUpdate(**it);
} }
} }
if (typeid(*subj) == typeid(FocusableListSubject)) { }
FocusableListSubject *fsubj =
static_cast<FocusableListSubject *>(subj); void FocusableList::parentOrderChanged(Focusable *win) {
if (subj == &m_parent->addSig()) { if(!m_screen.isShuttingdown() && contains(*win)) {
attachSignals(*fsubj->win()); if(insertFromParent(*win))
if (m_pat->match(*fsubj->win())) { m_ordersig.emit(win);
insertFromParent(*fsubj->win()); }
m_addsig.notify(fsubj->win()); }
}
} else if (subj == &m_parent->removeSig()) void FocusableList::parentWindowAdded(Focusable *win) {
remove(*fsubj->win()); if(!m_screen.isShuttingdown()) {
else if (subj == &m_parent->resetSig()) attachSignals(*win);
reset(); if (m_pat->match(*win)) {
else if (subj == &m_parent->orderSig()) { insertFromParent(*win);
Focusable *win = fsubj->win(); m_addsig.emit(win);
if (!win || !contains(*win))
return;
if (insertFromParent(*win))
m_ordersig.notify(win);
} }
} }
} }
void FocusableList::parentWindowRemoved(Focusable *win) {
if(!m_screen.isShuttingdown())
remove(*win);
}
void FocusableList::checkUpdate(Focusable &win) { void FocusableList::checkUpdate(Focusable &win) {
if (contains(win)) { if (contains(win)) {
if (!m_pat->match(win)) { if (!m_pat->match(win)) {
m_list.remove(&win); m_list.remove(&win);
m_pat->removeMatch(); m_pat->removeMatch();
m_removesig.notify(&win); m_removesig.emit(&win);
} }
} else if (m_pat->match(win)) { } else if (m_pat->match(win)) {
insertFromParent(win); insertFromParent(win);
m_pat->addMatch(); m_pat->addMatch();
m_addsig.notify(&win); m_addsig.emit(&win);
} }
} }
@ -203,13 +204,13 @@ void FocusableList::addMatching() {
void FocusableList::pushFront(Focusable &win) { void FocusableList::pushFront(Focusable &win) {
m_list.push_front(&win); m_list.push_front(&win);
attachSignals(win); attachSignals(win);
m_addsig.notify(&win); m_addsig.emit(&win);
} }
void FocusableList::pushBack(Focusable &win) { void FocusableList::pushBack(Focusable &win) {
m_list.push_back(&win); m_list.push_back(&win);
attachSignals(win); attachSignals(win);
m_addsig.notify(&win); m_addsig.emit(&win);
} }
void FocusableList::moveToFront(Focusable &win) { void FocusableList::moveToFront(Focusable &win) {
@ -219,7 +220,7 @@ void FocusableList::moveToFront(Focusable &win) {
m_list.remove(&win); m_list.remove(&win);
m_list.push_front(&win); m_list.push_front(&win);
m_ordersig.notify(&win); m_ordersig.emit(&win);
} }
void FocusableList::moveToBack(Focusable &win) { void FocusableList::moveToBack(Focusable &win) {
@ -229,7 +230,7 @@ void FocusableList::moveToBack(Focusable &win) {
m_list.remove(&win); m_list.remove(&win);
m_list.push_back(&win); m_list.push_back(&win);
m_ordersig.notify(&win); m_ordersig.emit(&win);
} }
void FocusableList::remove(Focusable &win) { void FocusableList::remove(Focusable &win) {
@ -241,7 +242,7 @@ void FocusableList::remove(Focusable &win) {
return; return;
} }
m_list.remove(&win); m_list.remove(&win);
m_removesig.notify(&win); m_removesig.emit(&win);
} }
void FocusableList::updateTitle(Focusable& win) { void FocusableList::updateTitle(Focusable& win) {
@ -292,7 +293,7 @@ void FocusableList::reset() {
m_pat->resetMatches(); m_pat->resetMatches();
if (m_parent) if (m_parent)
addMatching(); addMatching();
m_resetsig.notify(0); m_resetsig.emit();
} }
bool FocusableList::contains(const Focusable &win) const { bool FocusableList::contains(const Focusable &win) const {
@ -311,10 +312,10 @@ Focusable *FocusableList::find(const ClientPattern &pat) const {
} }
void FocusableList::attachChild(FocusableList &child) const { void FocusableList::attachChild(FocusableList &child) const {
m_addsig.attach(&child); m_addsig.connect(FbTk::MemFun(child, &FocusableList::parentWindowAdded));
m_removesig.attach(&child); m_ordersig.connect(FbTk::MemFun(child, &FocusableList::parentOrderChanged));
m_resetsig.attach(&child); m_removesig.connect(FbTk::MemFun(child, &FocusableList::parentWindowRemoved));
m_ordersig.attach(&child); m_resetsig.connect(FbTk::MemFun(child, &FocusableList::reset));
} }
void FocusableList::workspaceChanged(BScreen &screen) { void FocusableList::workspaceChanged(BScreen &screen) {

View file

@ -82,30 +82,12 @@ public:
@name signals @name signals
@{ @{
*/ */
FbTk::Subject &orderSig() { return m_ordersig; } FbTk::Signal<Focusable *> &orderSig() { return m_ordersig; }
const FbTk::Subject &orderSig() const { return m_ordersig; } FbTk::Signal<Focusable *> &addSig() { return m_addsig; }
FbTk::Subject &addSig() { return m_addsig; } FbTk::Signal<Focusable *> &removeSig() { return m_removesig; }
const FbTk::Subject &addSig() const { return m_addsig; } FbTk::Signal<> &resetSig() { return m_resetsig; }
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; }
/** @} */ // end group signals /** @} */ // 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: private:
void init(); void init();
void addMatching(); void addMatching();
@ -120,13 +102,18 @@ private:
/// Title has changed for a window /// Title has changed for a window
/// @param win The window that title changed for. /// @param win The window that title changed for.
void updateTitle(Focusable& win); void updateTitle(Focusable& win);
void parentOrderChanged(Focusable* win);
void parentWindowAdded(Focusable* win);
void parentWindowRemoved(Focusable* win);
std::auto_ptr<ClientPattern> m_pat; std::auto_ptr<ClientPattern> m_pat;
const FocusableList *m_parent; const FocusableList *m_parent;
BScreen &m_screen; BScreen &m_screen;
std::list<Focusable *> m_list; std::list<Focusable *> m_list;
mutable FocusableListSubject m_ordersig, m_addsig, m_removesig, m_resetsig; mutable FbTk::Signal<Focusable *> m_ordersig, m_addsig, m_removesig;
mutable FbTk::Signal<> m_resetsig;
typedef std::map<Focusable*, FbTk::RefCount<FbTk::SignalTracker> > SignalMap; typedef std::map<Focusable*, FbTk::RefCount<FbTk::SignalTracker> > SignalMap;
SignalMap m_signal_map; SignalMap m_signal_map;
}; };

View file

@ -331,7 +331,7 @@ void IconbarTool::hide() {
void IconbarTool::setAlignment(FbTk::Container::Alignment align) { void IconbarTool::setAlignment(FbTk::Container::Alignment align) {
*m_rc_alignment = align; *m_rc_alignment = align;
update(0); update(ALIGN, NULL);
m_menu.reconfigure(); m_menu.reconfigure();
} }
@ -344,22 +344,24 @@ void IconbarTool::setMode(string mode) {
// lock graphics update // lock graphics update
m_icon_container.setUpdateLock(true); 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") if (mode == "none")
m_winlist.reset(new FocusableList(m_screen)); m_winlist.reset(new FocusableList(m_screen));
else else
m_winlist.reset(new FocusableList(m_screen, m_winlist.reset(new FocusableList(m_screen,
mode + " (iconhidden=no)")); mode + " (iconhidden=no)"));
if (m_winlist.get()) { if (m_winlist.get()) {
m_winlist->addSig().attach(this); m_winlist->addSig().connect(
m_winlist->removeSig().attach(this); std::bind1st(FbTk::MemFun(*this, &IconbarTool::update), LIST_ADD)
m_winlist->orderSig().attach(this); );
m_winlist->resetSig().attach(this); 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<Focusable *>(0)
));
} }
reset(); reset();
@ -389,7 +391,7 @@ void IconbarTool::themeReconfigured() {
setMode(*m_rc_mode); setMode(*m_rc_mode);
} }
void IconbarTool::update(FbTk::Subject *subj) { void IconbarTool::update(UpdateReason reason, Focusable *win) {
// ignore updates if we're shutting down // ignore updates if we're shutting down
if (m_screen.isShuttingdown()) { if (m_screen.isShuttingdown()) {
if (!m_icons.empty()) if (!m_icons.empty())
@ -405,17 +407,18 @@ void IconbarTool::update(FbTk::Subject *subj) {
// lock graphic update // lock graphic update
m_icon_container.setUpdateLock(true); m_icon_container.setUpdateLock(true);
if (subj && typeid(*subj) == typeid(FocusableList::FocusableListSubject)) { switch(reason) {
FocusableList::FocusableListSubject *fsubj = case LIST_ADD: case LIST_ORDER:
static_cast<FocusableList::FocusableListSubject *>(subj); insertWindow(*win);
if (subj == &m_winlist->addSig()) break;
insertWindow(*fsubj->win()); case LIST_REMOVE:
else if (subj == &m_winlist->removeSig()) removeWindow(*win);
removeWindow(*fsubj->win()); break;
else if (subj == &m_winlist->resetSig()) case LIST_RESET:
reset(); reset();
else if (subj == &m_winlist->orderSig()) break;
insertWindow(*fsubj->win()); case ALIGN:
break;
} }
// unlock container and update graphics // unlock container and update graphics

View file

@ -28,7 +28,6 @@
#include "FbTk/Container.hh" #include "FbTk/Container.hh"
#include "FbTk/CachedPixmap.hh" #include "FbTk/CachedPixmap.hh"
#include "FbTk/Observer.hh"
#include "FbTk/Resource.hh" #include "FbTk/Resource.hh"
#include <map> #include <map>
@ -39,7 +38,7 @@ class IconButton;
class Focusable; class Focusable;
class FocusableList; class FocusableList;
class IconbarTool: public ToolbarItem, public FbTk::Observer { class IconbarTool: public ToolbarItem {
public: public:
typedef std::map<Focusable *, IconButton *> IconMap; typedef std::map<Focusable *, IconButton *> IconMap;
@ -54,7 +53,6 @@ public:
void moveResize(int x, int y, void moveResize(int x, int y,
unsigned int width, unsigned int height); unsigned int width, unsigned int height);
void update(FbTk::Subject *subj);
void show(); void show();
void hide(); void hide();
void setAlignment(FbTk::Container::Alignment a); void setAlignment(FbTk::Container::Alignment a);
@ -72,6 +70,7 @@ public:
const BScreen &screen() const { return m_screen; } const BScreen &screen() const { return m_screen; }
private: private:
enum UpdateReason { LIST_ORDER, LIST_ADD, LIST_REMOVE, LIST_RESET, ALIGN };
void updateSizing(); void updateSizing();
@ -95,6 +94,9 @@ private:
/// add icons to the list /// add icons to the list
void updateList(); void updateList();
/// called when the list emits a signal
void update(UpdateReason reason, Focusable *win);
void themeReconfigured(); void themeReconfigured();
BScreen &m_screen; BScreen &m_screen;