void EventDispatcher::RemoveTemporaryListener(EventTarget& target, int32 token) { BAutolock _(this); ETRACE(("events: remove temporary listener token %ld\n", token)); if (target.RemoveTemporaryListener(token) && target.IsEmpty()) fTargets.RemoveItem(&target); }
/*! \brief Adds the specified listener or updates its event mask and options if already added. It follows the BView semantics in that specifiying an event mask of zero leaves the event mask untouched and just updates the options. */ bool EventDispatcher::_AddListener(EventTarget& target, int32 token, uint32 eventMask, uint32 options, bool temporary) { BAutolock _(this); if (temporary && fLastButtons == 0) { // only allow to add temporary listeners in case a buttons is pressed return false; } if (!fTargets.HasItem(&target)) fTargets.AddItem(&target); event_listener* listener = target.FindListener(token); if (listener != NULL) { // we already have this target, update its event mask if (temporary) { if (eventMask != 0) listener->temporary_event_mask = eventMask; listener->temporary_options = options; } else { if (eventMask != 0) listener->event_mask = eventMask; listener->options = options; } return true; } if (eventMask == 0) return false; ETRACE(("events: add listener: token %ld, eventMask = %ld, options = %ld, %s\n", token, eventMask, options, temporary ? "temporary" : "permanent")); // we need a new target bool success = target.AddListener(token, eventMask, options, temporary); if (!success) { if (target.IsEmpty()) fTargets.RemoveItem(&target); } else { if (options & B_SUSPEND_VIEW_FOCUS) fSuspendFocus = true; } return success; }