/* * Copyright 2005, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: * Axel Dörfler, axeld@pinc-software.de */ #ifndef EVENT_DISPATCHER_H #define EVENT_DISPATCHER_H #include #include #include class BMessageFilter; class EventStream; class HWInterface; class EventDispatcher : public BLocker { public: EventDispatcher(); ~EventDispatcher(); status_t SetTo(EventStream* stream); status_t InitCheck(); void SetFocus(const BMessenger* messenger); bool AddListener(BMessenger& messenger, int32 token, uint32 events, uint32 options); bool AddTemporaryListener(BMessenger& messenger, int32 token, uint32 events, uint32 options); void RemoveListener(BMessenger& messenger, int32 token); void SetMouseFilter(BMessageFilter* filter); void SetKeyFilter(BMessageFilter* filter); bool HasCursorThread(); void SetHWInterface(HWInterface* interface); private: struct event_target; status_t _Run(); void _Unset(); bool _SendMessage(BMessenger& messenger, BMessage* message, float importance); void _SetTransit(BMessage* message, int32 transit); void _UnsetTransit(BMessage* message); bool _AddTokens(BMessage* message, BList& tokens); void _RemoveTokens(BMessage* message); void _SetToken(BMessage* message, int32 token); event_target* _FindListener(BMessenger& messenger, int32 token, int32* _index = NULL); bool _AddListener(BMessenger& messenger, int32 token, uint32 events, uint32 options, bool temporary); void _RemoveTemporaryListeners(); void _EventLoop(); void _CursorLoop(); static status_t _event_looper(void* dispatcher); static status_t _cursor_looper(void* dispatcher); private: EventStream* fStream; thread_id fThread; thread_id fCursorThread; BMessenger fFocus; BMessenger fLastFocus; bool fHasFocus; bool fHasLastFocus; bool fTransit; BList fLastFocusTokens; BList fFocusTokens; bool fSuspendFocus; BMessageFilter* fMouseFilter; BMessageFilter* fKeyFilter; BObjectList fListeners; BLocker fCursorLock; HWInterface* fHWInterface; }; #endif /* EVENT_DISPATCHER_H */