Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }