Exemplo n.º 1
0
 protected override IHighlightableElement GetSkipBehavior( IHighlightableElement element )
 {
     switch( element.Skip )
     {
         case SkippingBehavior.Skip:
             return GetNextElement( ActionType.Normal );
         default:
             if( element != null && element.Children.Count > 0 ) return GetNextElement( ActionType.EnterChild );
             return element;
     }
 }
        public ExtensibleHighlightableElementProxy( string name, IHighlightableElement element, bool highlightPrePostChildren = false )
        {
            if( element == null ) throw new ArgumentNullException( "element" );

            _preChildren = new List<IHighlightableElement>();
            _postChildren = new List<IHighlightableElement>();

            _highlightPrePostChildren = highlightPrePostChildren;
            _element = element;
            _name = name;
        }
 public void FocusElement(MenuElement element)
 {
     for (int i = 0; i < menuElements.Count; i++)
     {
         IHighlightableElement content = menuElements[i].content;
         if (menuElements[i].Equals(element))
         {
             content.Focus();
         }
         else
         {
             content.Blur();
         }
     }
 }
 public void FocusElement(int index)
 {
     currentMenuElementIndex = index;
     for (int i = 0; i < menuElements.Count; i++)
     {
         IHighlightableElement content = menuElements[i].content;
         if (i == currentMenuElementIndex)
         {
             content.Focus();
         }
         else
         {
             content.Blur();
         }
     }
 }
Exemplo n.º 5
0
        public VirtualZone( IHighlightableElement element )
        {
            WrappedElement = element;

            List<IHighlightableElement> children = new List<IHighlightableElement>();
            int childPerZone = element.Children.Count / HalfZoneScrollingStrategy.ZoneDivider;

            for( int i = 0; i < HalfZoneScrollingStrategy.ZoneDivider; i++ )
            {
                //On the last iteration, we add the remaining children.
                if( i == HalfZoneScrollingStrategy.ZoneDivider - 1 )
                    children.Add( new VirtualZone( element.Children, childPerZone * i, childPerZone + element.Children.Count % HalfZoneScrollingStrategy.ZoneDivider ) );
                else
                    children.Add( new VirtualZone( element.Children, childPerZone * i, childPerZone ) );
            }

            Children = new CKReadOnlyListOnIList<IHighlightableElement>( children );
            Skip = SkippingBehavior.None;
        }
Exemplo n.º 6
0
 /// <summary>
 /// This function forces the highlight of the given element.
 /// </summary>
 /// <param name="element">The element highlight.</param>
 /// <remarks> 
 /// This function is useful only when there is no alternative to.
 /// </remarks>
 public void HighlightImmediately( IHighlightableElement element )
 {
     _scrollingStrategy.GoToElement( element );
 }
 public ZondeDivderWalker(IHighlightableElement root)
     : base(root)
 {
 }
Exemplo n.º 8
0
 public HighlightEventArgs( IHighlightableElement element )
 {
     Element = element;
 }
 public bool UnregisterElement( ChildPosition positionToRemove, IHighlightableElement element )
 {
     if( positionToRemove == ChildPosition.Pre )
     {
         return _preChildren.Remove( element );
     }
     else if( positionToRemove == ChildPosition.Post )
     {
         return _postChildren.Remove( element );
     }
     return false;
 }
Exemplo n.º 10
0
 public void RegisterTree( IHighlightableElement element )
 {
     if( !_registeredElements.Contains( element ) )
     {
         _registeredElements.Add( element );
         if( !_scrollingStrategy.IsStarted ) _scrollingStrategy.Start();
     }
 }
Exemplo n.º 11
0
        public void UnregisterTree( string targetModuleName, IHighlightableElement element )
        {
            IHighlightableElement foundElement;
            if( _registeredElements.TryGetValue( targetModuleName, out foundElement ) )
            {
                //If the element we're scrolling on is a proxy, we retrieve the actual element behind it.
                var ehep = foundElement as ExtensibleHighlightableElementProxy;
                if( ehep != null && ehep != element ) foundElement = ehep.HighlightableElement;

                if( foundElement == element )
                {
                    //Actually removing the module from the registered elements.
                    _registeredElements.Remove( targetModuleName );

                    BrowseTree( element, e =>
                    {
                        var iheus = e as IHighlightableElementController;
                        if( iheus != null ) iheus.OnUnregisterTree();
                        return false;
                    } );

                    //Warning the strategy that an element has been unregistered
                    _scrollingStrategy.ElementUnregistered( ehep == null ? element : ehep );
                }

                if( ElementRegisteredOrUnregistered != null ) ElementRegisteredOrUnregistered( this, new HighlightElementRegisterEventArgs( element, targetModuleName, false, element.IsHighlightableTreeRoot ) );
            }
        }
Exemplo n.º 12
0
        public void ElementUnregistered( IHighlightableElement unregisteredElement )
        {
            if( _currentElementParents.Contains( unregisteredElement ) )
            {
                //The unregistered element is one of the parents of the current element, so we need to stop iterating on this element and start on the next one.
                if( _currentElement != null ) FireEndHighlight();

                //We flush the parent list. When we call the next element, we'll be on the next registered tree
                _currentElementParents = new Stack<IHighlightableElement>();
                _currentId = 0;
            }
        }
Exemplo n.º 13
0
 void FireEndHighlight()
 {
     if( EndHighlight != null ) EndHighlight( this, new HighlightEventArgs( _currentElement ) );
     _currentElement = null;
 }
Exemplo n.º 14
0
        protected virtual void OnInternalBeat( object sender, EventArgs e )
        {
            //Console.Out.WriteLine( "Internalbeat " + DateTime.Now );
            if( _currentElement != null ) FireEndHighlight();

            // highlight the next element
            _currentElement = GetNextElement( _actionType );
            FireBeginHighlight();
        }
Exemplo n.º 15
0
        protected virtual IHighlightableElement GetUpToParent()
        {
            IHighlightableElement nextElement = null;
            // if there is no parent, go to normal next element
            if( _currentElementParents.Count == 0 ) return GetNextElement( ActionType.Normal );

            IHighlightableElement parent = _currentElementParents.Pop();
            ICKReadOnlyList<IHighlightableElement> parentSibblings = null;
            if( _currentElementParents.Count > 0 ) parentSibblings = _currentElementParents.Peek().Children;
            else parentSibblings = RegisteredElements;

            _currentId = parentSibblings.IndexOf( parent );
            nextElement = parent;

            // if the parent skipping behavior is enter children, we skip it
            if( parent.Skip == SkippingBehavior.EnterChildren )
            {
                _currentElement = nextElement;
                return GetNextElement( ActionType.Normal );
            }

            return nextElement;
        }
Exemplo n.º 16
0
 protected virtual IHighlightableElement GetSkipBehavior( IHighlightableElement element )
 {
     switch( element.Skip )
     {
         case SkippingBehavior.Skip:
             return GetNextElement( ActionType.Normal );
         case SkippingBehavior.EnterChildren:
             return GetNextElement( ActionType.EnterChild );
         default:
             return element;
     }
 }
Exemplo n.º 17
0
        public void UnregisterTree( IHighlightableElement element )
        {
            _registeredElements.Remove( element );

            if( _registeredElements.Count == 0 )
            {
                _scrollingStrategy.Stop();
            }

            _scrollingStrategy.ElementUnregistered( element );
        }
Exemplo n.º 18
0
        public void RegisterTree( string targetModuleName, string targetDisplayName, IHighlightableElement element, bool HighlightDirectly = false )
        {
            if( !_registeredElements.ContainsKey( targetModuleName ) )
            {
                if( _displayNames.ContainsKey( targetModuleName ) )
                    _displayNames[targetModuleName] = targetDisplayName;
                else
                    _displayNames.Add( targetModuleName, targetDisplayName );

                _registeredElements.Add( targetModuleName, element );
                if( !_scrollingStrategy.IsStarted ) _scrollingStrategy.Start();
                if( HighlightDirectly ) _scrollingStrategy.GoToElement( element );

                if( ElementRegisteredOrUnregistered != null ) ElementRegisteredOrUnregistered( this, new HighlightElementRegisterEventArgs( element, targetModuleName, true, element.IsHighlightableTreeRoot ) );
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Enables unregistering a tree node (and its children) that had been registered inside an already registered module (see <see cref="RegisterInRegisteredElementAt"/> )
        /// </summary>
        /// <param name="targetModuleName">The name of the target module</param>
        /// <param name="extensibleElementName">The name of the target node</param>
        /// <param name="position"></param>
        /// <param name="element">The element to unregister</param>
        /// <returns></returns>
        public bool UnregisterInRegisteredElement( string targetModuleName, string extensibleElementName, ChildPosition position, IHighlightableElement element )
        {
            IHighlightableElement registeredElement;
            if( _registeredElements.TryGetValue( targetModuleName, out registeredElement ) )
            {
                _scrollingStrategy.ElementUnregistered( element );

                return BrowseTree( registeredElement, e =>
                {
                    IExtensibleHighlightableElement extensibleElement = e as IExtensibleHighlightableElement;
                    if( extensibleElement != null && extensibleElement.Name == extensibleElementName ) return extensibleElement.UnregisterElement( position, element );
                    else return false;
                } );
            }

            return false;
        }
Exemplo n.º 20
0
 public HighlightElementRegisterEventArgs( IHighlightableElement element, string internalName, bool hasRegistered, bool isRoot )
 {
     Element = element;
     InternalName = internalName;
     HasRegistered = hasRegistered;
     IsRoot = isRoot;
 }
Exemplo n.º 21
0
        /// <summary>
        /// This method calls the function with with "element" as parameter and then calls it on each of its hightlightable children.
        /// At any point, if the function returns false, the browsing stops.
        /// </summary>
        /// <param name="element">The element set as parameter of the function</param>
        /// <param name="doing">The function called on each node</param>
        /// <returns>true fi the browing has been stopped at any point</returns>
        bool BrowseTree( IHighlightableElement element, Func<IHighlightableElement, bool> doing )
        {
            if( doing( element ) ) return true;

            foreach( var child in element.Children )
            {
                if( child.Children != null && child.Children.Count > 0 )
                {
                    if( BrowseTree( child, doing ) ) return true;
                }
                if( doing( child ) ) return true;
            }
            return false;
        }
Exemplo n.º 22
0
 public ActionType PreviewChildAction( IHighlightableElement element, ActionType action )
 {
     ActionType a = action;
     if( _initialLoopCount != 1 && _previousElement != element && _keys[_keys.Count - 1] == element )
     {
         if( _loopCount == 1 )
         {
             _loopCount = _initialLoopCount;
             a = ActionType.UpToParent;
         }
         else
         {
             _loopCount--;
             a = ActionType.MoveToFirst;
         }
     }
     _previousElement = element;
     return a;
 }
        /// <summary>
        /// Adds an element at the beginning or the end of the child list.
        /// An element can be added only once for a given position.
        /// </summary>
        /// <remarks>For ChildPosition.Pre, the element is added to the position 0 of the list, for ChildPosition.Post is added at the end</remarks>
        /// <param name="position"></param>
        /// <param name="child"></param>
        /// <returns>Returns true if the element could be added and did not exist yet. Otherwise false</returns>
        public bool RegisterElementAt( ChildPosition position, IHighlightableElement child )
        {
            if( child == null ) throw new ArgumentNullException( "child" );

            if( position == ChildPosition.Pre )
            {
                if( _preChildren.Contains( child ) ) return false;
                _preChildren.Insert( 0, child );
                return true;
            }
            else if( position == ChildPosition.Post )
            {
                if( _postChildren.Contains( child ) ) return false;
                _postChildren.Add( child );
                return true;
            }
            return false;
        }
 public BeginScrollingInfo( double tickInterval, IHighlightableElement previousElement )
 {
     TickInterval = tickInterval;
     PreviousElement = previousElement;
 }
 public EndScrollingInfo( double tickInterval, IHighlightableElement previouslyHighlightedElement, IHighlightableElement elementToBeHighlighted )
 {
     TickInterval = tickInterval;
     PreviouslyHighlightedElement = previouslyHighlightedElement;
     ElementToBeHighlighted = elementToBeHighlighted;
 }
Exemplo n.º 26
0
        /// <summary>
        /// Update a child reference with a new one
        /// </summary>
        /// <param name="oldChild"></param>
        /// <param name="newChild"></param>
        public void UpdateChild( IHighlightableElement oldChild, IHighlightableElement newChild )
        {
            int idx = Children.IndexOf( oldChild );
            List<IHighlightableElement> list = Children.ToList();
            list[idx] = newChild;

            Children = new CKReadOnlyListOnIList<IHighlightableElement>( list );
        }
 /// <summary>
 /// Calls the EndHighlight method of the current IHighlightableElement
 /// It also sets _lastDirective to the ScrollingDirective object returned by the call to EndHighlight.
 /// </summary>
 protected virtual void FireEndHighlight( IHighlightableElement previousElement, IHighlightableElement element )
 {
     if( previousElement != null )
     {
         LastDirective = previousElement.EndHighlight( new EndScrollingInfo( Timer.Interval.Ticks, previousElement, element ), LastDirective );
         EnsureReactivity();
     }
 }
Exemplo n.º 28
0
 public TreeWalker( IHighlightableElement root )
 {
     Parents = new Stack<IHighlightableElement>();
     Root = root;
 }