Exemple #1
0
        /// <summary>
        /// Implements copy functionalty for GetAsFrozenCore and GetCurrentValueAsFrozenCore
        /// Timeline does not need to override CloneCore and CloneCurrentValueCore.
        /// </summary>
        /// <param name="sourceTimeline"></param>
        private void CopyCommon(Timeline sourceTimeline)
        {
            // When creating a frozen copy of a Timeline we want to copy the
            // event handlers. This is for two reasons
            //
            //   1.) Internally when creating a clock tree we use
            //       a frozen copy of the timing tree.  If that frozen
            //       copy does not preserve the event handlers then
            //       any callbacks registered on the Timelines will be lost.
            //
            //   2.) GetAsFrozen and GetCurrentValueAsFrozen don't always clone.
            //       If any object in the tree is frozen it'll simply return it.
            //       If we did not copy the event handlers GetAsFrozen
            //       would return different results depending on whether a
            //       Timeline was frozen before the call.
            //
            //
            // The other two clone methods make unfrozen clones, so it's consisent
            // to not copy the event handlers for those methods.  Cloning an object
            // is basically the only way to get a 'fresh' copy without event handlers
            // attached.  If someone wants a frozen clone they probably want an exact
            // copy of the original.

            EventHandlersStore sourceStore = EventHandlersStoreField.GetValue(sourceTimeline);

            if (sourceStore != null)
            {
                Debug.Assert(sourceStore.Count > 0);
                EventHandlersStoreField.SetValue(this, new EventHandlersStore(sourceStore));
            }
        }
Exemple #2
0
        private static void EnsureClassHandlers()
        {
            // since we can't rely on the order of static constructors,
            // we will do this the first time an element is created.
            // we have a single dispatcher, so we don't have to worry about
            // race conditions here..

            if (_classEventHandlersStore == null)
            {
                _classEventHandlersStore = new EventHandlersStore();

                EventHandlersStore handlers = _classEventHandlersStore;

                // buttons
                handlers.AddRoutedEventHandler(Buttons.PreviewButtonDownEvent, new ButtonEventHandler(UIElement.OnPreviewButtonDownThunk), true);
                handlers.AddRoutedEventHandler(Buttons.ButtonDownEvent, new ButtonEventHandler(UIElement.OnButtonDownThunk), true);
                handlers.AddRoutedEventHandler(Buttons.PreviewButtonUpEvent, new ButtonEventHandler(UIElement.OnPreviewButtonUpThunk), true);
                handlers.AddRoutedEventHandler(Buttons.ButtonUpEvent, new ButtonEventHandler(UIElement.OnButtonUpThunk), true);

                // focus
                handlers.AddRoutedEventHandler(Buttons.GotFocusEvent, new FocusChangedEventHandler(UIElement.OnGotFocusThunk), true);
                handlers.AddRoutedEventHandler(Buttons.LostFocusEvent, new FocusChangedEventHandler(UIElement.OnLostFocusThunk), true);

                handlers.AddRoutedEventHandler(TouchEvents.TouchDownEvent, new TouchEventHandler(UIElement.OnTouchDownThunk), true);
                handlers.AddRoutedEventHandler(TouchEvents.TouchUpEvent, new TouchEventHandler(UIElement.OnTouchUpThunk), true);
                handlers.AddRoutedEventHandler(TouchEvents.TouchMoveEvent, new TouchEventHandler(UIElement.OnTouchMoveThunk), true);

                handlers.AddRoutedEventHandler(GenericEvents.GenericStandardEvent, new GenericEventHandler(UIElement.OnGenericEventThunk), true);

            }
        }
Exemple #3
0
        /// <summary>
        /// Adds a delegate to the list of event handlers on this object.
        /// </summary>
        /// <param name="key">
        /// A unique identifier for the event handler.
        /// </param>
        /// <param name="handler">The delegate to add.</param>
        private void AddEventHandler(EventPrivateKey key, Delegate handler)
        {
            WritePreamble();

            EventHandlersStore store = EventHandlersStoreField.GetValue(this);

            if (store == null)
            {
                store = new EventHandlersStore();
                EventHandlersStoreField.SetValue(this, store);
            }

            store.Add(key, handler);
            WritePostscript();
        }
        /// <summary>
        /// Removes a delegate from the list of event handlers on this object.
        /// </summary>
        /// <param name="key">
        /// A unique identifier for the event handler.
        /// </param>
        /// <param name="handler">The delegate to remove.</param>
        private void RemoveEventHandler(EventPrivateKey key, Delegate handler)
        {
            WritePreamble();

            EventHandlersStore store = EventHandlersStoreField.GetValue(this);
            if (store != null)
            {
                store.Remove(key, handler);
                if (store.Count == 0)
                {
                    // last event handler was removed -- throw away underlying EventHandlersStore
                    EventHandlersStoreField.ClearValue(this);
                }

                WritePostscript();
            }
        }
 public EventHandlersStore(EventHandlersStore source)
 {
     this.entries = source.entries;
 }
 private static EventHandlersStore EnsureEventHandlersStore(DependencyObject element)
 {
     EventHandlersStore store = element.GetValue(EventHandlersStoreProperty) as EventHandlersStore;
     if (store == null)
     {
         store = new EventHandlersStore();
         element.SetValue(EventHandlersStoreProperty, store);
     }
     return store;
 }