public void RemoveEventListener(string strType, EventCallback1 callback) { if (_dic == null) { return; } EventBridge bridge = null; if (_dic.TryGetValue(strType, out bridge)) { bridge.Remove(callback); } }
internal EventBridge GetEventBridge(string strType) { if (_dic == null) { _dic = new Dictionary <string, EventBridge>(); } EventBridge bridge = null; if (!_dic.TryGetValue(strType, out bridge)) { bridge = new EventBridge(this); _dic[strType] = bridge; } return(bridge); }
static void GetChildEventBridges(string strType, Container container, List <EventBridge> bridges) { EventBridge bridge = container.TryGetEventBridge(strType); if (bridge != null) { bridges.Add(bridge); } if (container.gOwner != null) { bridge = container.gOwner.TryGetEventBridge(strType); if (bridge != null && !bridge.isEmpty) { bridges.Add(bridge); } } int count = container.numChildren; for (int i = 0; i < count; ++i) { DisplayObject obj = container.GetChildAt(i); if (obj is Container) { GetChildEventBridges(strType, (Container)obj, bridges); } else { bridge = obj.TryGetEventBridge(strType); if (bridge != null && !bridge.isEmpty) { bridges.Add(bridge); } if (obj.gOwner != null) { bridge = obj.gOwner.TryGetEventBridge(strType); if (bridge != null && !bridge.isEmpty) { bridges.Add(bridge); } } } } }
internal bool InternalDispatchEvent(string strType, EventBridge bridge, object data) { EventBridge gBridge = null; if ((this is DisplayObject) && ((DisplayObject)this).gOwner != null) { gBridge = ((DisplayObject)this).gOwner.TryGetEventBridge(strType); } bool b1 = bridge != null && !bridge.isEmpty; bool b2 = gBridge != null && !gBridge.isEmpty; if (b1 || b2) { EventContext context = EventContext.Get(); context.initiator = this; context._stopsPropagation = false; context._defaultPrevented = false; context.type = strType; context.data = data; if (b1) { bridge.CallCaptureInternal(context); bridge.CallInternal(context); } if (b2) { gBridge.CallCaptureInternal(context); gBridge.CallInternal(context); } EventContext.Return(context); context.initiator = null; context.sender = null; context.data = null; return(context._defaultPrevented); } else { return(false); } }
public void AddEventListener(string strType, EventCallback1 callback) { if (strType == null) { throw new Exception("event type cant be null"); } if (_dic == null) { _dic = new Dictionary <string, EventBridge>(); } EventBridge bridge = null; if (!_dic.TryGetValue(strType, out bridge)) { bridge = new EventBridge(this); _dic[strType] = bridge; } bridge.Add(callback); }
public bool BubbleEvent(string strType, object data) { EventContext context = EventContext.Get(); context.initiator = this; context._stopsPropagation = false; context._defaultPrevented = false; context.type = strType; context.data = data; List <EventBridge> bubbleChain = context.callChain; EventBridge bridge = TryGetEventBridge(strType); if (bridge != null && !bridge.isEmpty) { bubbleChain.Add(bridge); } if ((this is DisplayObject) && ((DisplayObject)this).gOwner != null) { bridge = ((DisplayObject)this).gOwner.TryGetEventBridge(strType); if (bridge != null && !bridge.isEmpty) { bubbleChain.Add(bridge); } } if (this is DisplayObject) { DisplayObject element = (DisplayObject)this; while ((element = element.parent) != null) { bridge = element.TryGetEventBridge(strType); if (bridge != null && !bridge.isEmpty) { bubbleChain.Add(bridge); } if (element.gOwner != null) { bridge = element.gOwner.TryGetEventBridge(strType); if (bridge != null && !bridge.isEmpty) { bubbleChain.Add(bridge); } } } } else if (this is GObject) { GObject element = (GObject)this; while ((element = element.parent) != null) { bridge = element.TryGetEventBridge(strType); if (bridge != null && !bridge.isEmpty) { bubbleChain.Add(bridge); } } } int length = bubbleChain.Count; for (int i = length - 1; i >= 0; i--) { bubbleChain[i].CallCaptureInternal(context); } for (int i = 0; i < length; ++i) { bubbleChain[i].CallInternal(context); if (context._stopsPropagation) { break; } } bubbleChain.Clear(); EventContext.Return(context); context.initiator = null; context.sender = null; context.data = null; return(context._defaultPrevented); }