Beispiel #1
0
        /// <summary>
        /// Removes an event listener from this object.
        /// </summary>
        /// <param name="eventName">Name of the event</param>
        /// <param name="callback">Callback that fires when the event is triggered.</param>
        /// <param name="options"></param>
        public void removeEventListener(EventName eventName, EventCallback callback, EventListenerOptions options = null)
        {
            bool capture = false;

            if (!ReferenceEquals(options, null))
            {
                capture = options.capture;
            }

            /* 3) If the context object’s event listener list contains an event listener whose type is type, callback is callback, and capture is capture, then remove an event listener with the context object and that event listener. */
            var found = Find_Listener(eventName, callback, capture);

            if (!ReferenceEquals(found, null))
            {
                found.removed = true;
                Listeners.Remove(found);
            }
        }
Beispiel #2
0
        public IEnumerable <EventHandler> this[EventName Name]
        {
            get
            {
                /* Verify the event is accepted by this element */
                var eventTarget = EventCommon.determine_target(Owner, Name);
                if (eventTarget == null)
                {
                    return(null);/* This event is not valid for the owning element */
                }
                if (!Map.TryGetValue(Name, out LinkedList <EventHandler> handlerList))
                {
                    return(Array.Empty <EventHandler>());
                }

                return(handlerList);
            }
        }
Beispiel #3
0
        public bool Add(EventName Name, EventCallback Callback)
        {
            /* Verify the event is accepted by this element */
            var eventTarget = EventCommon.determine_target(Owner, Name);

            if (eventTarget == null)
            {
                return(false);/* This event is not valid for the owning element */
            }
            if (!Map.TryGetValue(Name, out LinkedList <EventHandler> handlerList))
            {/* We have no handlers for this event yet */
                handlerList = new LinkedList <EventHandler>();
                Map.Add(Name, handlerList);
            }

            /* Theres no need for CssUI to do an extra processing step on event handler callbacks now so we will just give the listener the callback */
            var listener = new EventListener(Name, (Event e) => Callback.Invoke(e));
            var handler  = new EventHandler(listener, Callback);

            handlerList.AddLast(handler);
            return(true);
        }
Beispiel #4
0
        public bool Remove(EventName Name, EventCallback Callback)
        {
            /* Verify the event is accepted by this element */
            var eventTarget = EventCommon.determine_target(Owner, Name);

            if (eventTarget == null)
            {
                return(false);/* This event is not valid for the owning element */
            }
            if (!Map.TryGetValue(Name, out LinkedList <EventHandler> handlerList))
            {/* We have no handlers for this event yet */
                return(false);
            }

            bool found = false;
            var  node  = handlerList.First;

            while (node != null)
            {
                var handler = node.Value;
                if (ReferenceEquals(Callback, handler.callback))
                {
                    handlerList.Remove(node);
                    if (handler.listener != null)
                    {
                        handler.listener.removed = true;
                        Owner.Listeners.Remove(handler.listener);
                    }
                    found = true;
                    break;
                }

                node = node.Next;
            }

            return(found);
        }