Foundation classes for a basic GUI implementing simple widgets and events
Dependents: TouchScreenGUIDemo
Diff: Events/EventDispatcher.cpp
- Revision:
- 12:63db16fea709
- Parent:
- 0:0a590815d51c
- Child:
- 15:e69fd74d42e4
--- a/Events/EventDispatcher.cpp Fri Apr 22 16:12:42 2016 +0000 +++ b/Events/EventDispatcher.cpp Sun May 08 14:42:08 2016 +0000 @@ -3,63 +3,20 @@ EventDispatcher::EventDispatcher() { } - - void EventDispatcher::attachListener(EventListener* l) { - if(_listeners == NULL) { - _listeners = new EventListenerWrapper(l); - } else { - EventListenerWrapper* w = new EventListenerWrapper(l); - EventListenerWrapper* p = _listeners; - while(p->next != NULL) { - p = p->next; - } - p->next = w; - w->prev = p; - } + _listeners.append(l); } void EventDispatcher::detachListener(EventListener* l) { - - EventListenerWrapper *p = _listeners; - - if(p == NULL) { - return; - } - - while(p->listener != l) { - if(p->next == NULL) { - return; - } - p = p->next; - } - - // Found the listener - // Is there only one in the list? - if(p->prev == NULL && p->next == NULL) { - _listeners = NULL; - } else if(p->prev == NULL) { - // First in the list. Move everything down - _listeners = p->next; - _listeners->prev = NULL; - } else if(p->next == NULL) { - p->prev->next = NULL; - } else { - // Middle of the list - p->prev->next = p->next; - p->next->prev = p->prev; - } - - delete p; + _listeners.remove(l); } void EventDispatcher::dispatchEvent(Event e) { - EventListenerWrapper* p = _listeners; - while(p != NULL) { - if(p->listener->isEventTarget(e)) { - p->listener->handleEvent(e); + EventListener* l; + _listeners.reset(); + while((l=_listeners.next()) != NULL) { + if(l->isEventTarget(e)) { + l->handleEvent(e); } - - p = p->next; } } \ No newline at end of file