Esempio n. 1
0
        /// <summary>
        /// Gets the frame that creates cells associated to a property in a state.
        /// This overload uses selectors to choose the correct frame.
        /// </summary>
        /// <param name="state">The state.</param>
        /// <param name="propertyName">The property name.</param>
        /// <param name="selectorStack">A list of selectors to choose the correct frame.</param>
        public virtual IFocusFrame PropertyToFrame(IFocusNodeState state, string propertyName, IList <IFocusFrameSelectorList> selectorStack)
        {
            Type OwnerType              = state.Node.GetType();
            Type InterfaceType          = NodeTreeHelper.NodeTypeToInterfaceType(OwnerType);
            IFocusNodeTemplate Template = (IFocusNodeTemplate)NodeTypeToTemplate(InterfaceType);
            IFocusFrame        Frame    = Template.PropertyToFrame(propertyName, selectorStack);

            return(Frame);
        }
        private protected override IFrameFrame GetAssociatedFrame(IFrameInner <IFrameBrowsingChildIndex> inner)
        {
            IFocusNodeState                Owner         = ((IFocusInner <IFocusBrowsingChildIndex>)inner).Owner;
            IFocusNodeStateView            StateView     = (IFocusNodeStateView)StateViewTable[Owner];
            IList <FocusFrameSelectorList> SelectorStack = StateView.GetSelectorStack();

            IFocusFrame AssociatedFrame = TemplateSet.InnerToFrame((IFocusInner <IFocusBrowsingChildIndex>)inner, SelectorStack) as IFocusFrame;

            return(AssociatedFrame);
        }
Esempio n. 3
0
        /// <summary></summary>
        protected virtual bool FrameSelectorForPropertySingle(IFocusFrame root, string propertyName, out IFocusFrameWithSelector frame)
        {
            frame = null;
            bool Found = false;

            if (root is IFocusSelectorPropertyFrame AsSelectorPropertyFrame)
            {
                Found = AsSelectorPropertyFrame.FrameSelectorForProperty(propertyName, out frame);
            }

            return(Found);
        }
Esempio n. 4
0
        /// <summary>
        /// Get the location in the source code corresponding to this focus.
        /// </summary>
        /// <param name="node">The node in the source code upon return.</param>
        /// <param name="frame">The frame in the template associated to <paramref name="node"/> that indicates where in the node is the focus upon return.</param>
        public virtual void GetLocationInSourceCode(out Node node, out IFocusFrame frame)
        {
            node  = null;
            frame = null;

            // We might be reading the focus of a node that has just been unassigned, so don't assert that IsAssigned == true.
            IFocusOptionalNodeState AsOptionalNodeState = CellView.StateView.State as IFocusOptionalNodeState;

            if (AsOptionalNodeState == null || AsOptionalNodeState.ParentInner.IsAssigned)
            {
                node  = CellView.StateView.State.Node;
                frame = CellView.Frame;
            }
        }
        private protected override void Refresh(IFrameNodeState state)
        {
            Node        FocusedNode  = null;
            IFocusFrame FocusedFrame = null;

            if (Focus != null)
            {
                Focus.GetLocationInSourceCode(out FocusedNode, out FocusedFrame);
            }

            base.Refresh(state);

            UpdateFocusChain((IFocusNodeState)state, FocusedNode, FocusedFrame);
        }
        private bool GetFirstNamedFramePanel(IFocusPanelFrame root, string propertyName, IList <FocusFrameSelectorList> selectorStack, bool reverseSearch, ref int valueFrameIndex, out IFocusNamedFrame frame)
        {
            frame = null;

            int Count = root.Items.Count;

            for (int i = 0; i < Count; i++)
            {
                IFocusFrame Item = (IFocusFrame)root.Items[reverseSearch ? Count - 1 - i : i];

                if (GetFirstNamedFrame(Item, propertyName, selectorStack, reverseSearch, ref valueFrameIndex, out frame))
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 7
0
            public LayoutRootFrame()
            {
                UpdateParent(null, null);
                int CommentFrameCount = 0;

                Debug.Assert(ParentTemplate == null);
                Debug.Assert(ParentFrame == null);
                Debug.Assert(!IsValid(null, null, ref CommentFrameCount));

                IFrameFrame AsFrameFrame = this;

                Debug.Assert(AsFrameFrame.ParentTemplate == null);
                Debug.Assert(AsFrameFrame.ParentFrame == null);

                IFocusFrame AsFocusFrame = this;

                Debug.Assert(AsFocusFrame.ParentTemplate == null);
                Debug.Assert(AsFocusFrame.ParentFrame == null);
            }
Esempio n. 8
0
        /// <summary>
        /// Checks if a new item can be inserted at the focus.
        /// </summary>
        /// <param name="inner">Inner to use to insert the new item upon return.</param>
        /// <param name="index">Index of the new item to insert upon return.</param>
        /// <returns>True if a new item can be inserted at the focus.</returns>
        public virtual bool IsNewItemInsertable(out IFocusCollectionInner inner, out IFocusInsertionCollectionNodeIndex index)
        {
            inner = null;
            index = null;

            bool Result = false;

            IFocusNodeState State = Focus.CellView.StateView.State;
            IFocusFrame     Frame = Focus.CellView.Frame;

            if (Frame is IFocusInsertFrame AsInsertFrame)
            {
                Result = IsNewItemInsertableAtInsertFrame(State, AsInsertFrame, out inner, out index);
            }
            else if (Focus.CellView is IFocusStringContentFocusableCellView AsStringContentFocusableCellView)
            {
                Result = IsNewItemInsertableAtStringContentCellView(State, AsStringContentFocusableCellView, out inner, out index);
            }

            return(Result);
        }
Esempio n. 9
0
        /// <summary>
        /// Gets the frame that creates cells associated to states in the inner.
        /// This overload uses selectors to choose the correct frame.
        /// </summary>
        /// <param name="inner">The inner.</param>
        /// <param name="selectorStack">A list of selectors to choose the correct frame.</param>
        public virtual IFocusFrame InnerToFrame(IFocusInner <IFocusBrowsingChildIndex> inner, IList <IFocusFrameSelectorList> selectorStack)
        {
            IFocusNodeState    Owner         = inner.Owner;
            Type               OwnerType     = Owner.Node.GetType();
            Type               InterfaceType = NodeTreeHelper.NodeTypeToInterfaceType(OwnerType);
            IFocusNodeTemplate Template      = (IFocusNodeTemplate)NodeTypeToTemplate(InterfaceType);
            IFocusFrame        Frame         = Template.PropertyToFrame(inner.PropertyName, selectorStack);

            if (Frame is IFocusBlockListFrame AsBlockListFrame)
            {
                IFocusBlockListInner <IFocusBrowsingBlockNodeIndex> BlockListInner = inner as IFocusBlockListInner <IFocusBrowsingBlockNodeIndex>;
                Debug.Assert(BlockListInner != null);

                Type BlockType = NodeTreeHelperBlockList.BlockListBlockType(Owner.Node, BlockListInner.PropertyName);
                IFocusBlockTemplate BlockTemplate = (IFocusBlockTemplate)BlockTypeToTemplate(BlockType);

                Frame = (IFocusFrame)BlockTemplate.GetPlaceholderFrame();
            }

            return(Frame);
        }
        private protected virtual bool IsSameChangeCommentOperationFocus(FocusChangeCommentOperation operation)
        {
            Node Node = null;

            if (operation.State.ParentIndex is IFocusNodeIndex AsNodeIndex)
            {
                Node = AsNodeIndex.Node;
            }
            else if (operation.State is IFocusOptionalNodeState AsOptionalNodeState && AsOptionalNodeState.ParentInner.IsAssigned)
            {
                Node = AsOptionalNodeState.Node;
            }

            Debug.Assert(Node != null);

            Node        FocusedNode  = null;
            IFocusFrame FocusedFrame = null;

            Focus.GetLocationInSourceCode(out FocusedNode, out FocusedFrame);

            return(FocusedNode == Node && FocusedFrame is IFocusCommentFrame);
        }
        private protected bool GetFirstNamedFrame(IFocusFrame root, string propertyName, IList <FocusFrameSelectorList> selectorStack, bool reverseSearch, ref int valueFrameIndex, out IFocusNamedFrame frame)
        {
            frame = null;
            bool Found = false;

            switch (root)
            {
            case IFocusNamedFrame AsNamedFrame:
                Found = GetFirstNamedFrameNamed(AsNamedFrame, propertyName, ref valueFrameIndex, out frame);
                break;

            case IFocusPanelFrame AsPanelFrame:
                Found = GetFirstNamedFramePanel(AsPanelFrame, propertyName, selectorStack, reverseSearch, ref valueFrameIndex, out frame);
                break;

            case IFocusSelectionFrame AsSelectionFrame:
                Found = GetFirstNamedFrameSelection(AsSelectionFrame, propertyName, selectorStack, reverseSearch, ref valueFrameIndex, out frame);
                break;
            }

            return(Found);
        }
        private protected virtual void RecoverFocus(IFocusNodeState state, FocusFocusList newFocusChain)
        {
            IFocusNodeState            CurrentState           = state;
            List <IFocusNodeStateView> StateViewList          = new List <IFocusNodeStateView>();
            IFocusNodeStateView        MainStateView          = null;
            List <IFocusFocus>         SameStateFocusableList = new List <IFocusFocus>();

            // Get the state that should have the focus and all its children.
            while (CurrentState != null && !GetFocusedStateAndChildren(newFocusChain, CurrentState, out MainStateView, out StateViewList, out SameStateFocusableList))
            {
                CurrentState = CurrentState.ParentState;
            }

            Debug.Assert(SameStateFocusableList.Count > 0);

            // Now that we have found candidates, try to select the original frame.
            bool IsFrameChanged = true;

            IFocusFrame Frame = Focus.CellView.Frame;

            foreach (IFocusFocus CellFocus in SameStateFocusableList)
            {
                if (CellFocus.CellView.Frame == Frame)
                {
                    IsFrameChanged = false;
                    Focus          = CellFocus;
                    break;
                }
            }

            // If the frame has changed, use a preferred frame.
            if (IsFrameChanged)
            {
                FindPreferredFrame(MainStateView, SameStateFocusableList);
            }

            ResetCaretPosition(0, true);
        }
        private protected virtual bool GetFirstCommentFrame(IFocusFrame root, IList <FocusFrameSelectorList> selectorStack, out IFocusCommentFrame frame)
        {
            bool Found = false;

            frame = null;

            switch (root)
            {
            case IFocusCommentFrame AsCommentFrame:
                Found = GetFirstCommentFrameComment(AsCommentFrame, out frame);
                break;

            case IFocusPanelFrame AsPanelFrame:
                Found = GetFirstCommentFramePanel(AsPanelFrame, selectorStack, out frame);
                break;

            case IFocusSelectionFrame AsSelectionFrame:
                Found = GetFirstCommentFrameSelection(AsSelectionFrame, selectorStack, out frame);
                break;
            }

            return(Found);
        }
Esempio n. 14
0
 bool ICollection <IFocusFrame> .Remove(IFocusFrame item)
 {
     return(Remove((ILayoutFrame)item));
 }
        private protected virtual void UpdateFocusChain(IFocusNodeState state, Node focusedNode, IFocusFrame focusedFrame)
        {
            FocusFocusList      NewFocusChain = CreateFocusChain();
            IFocusNodeState     RootState     = Controller.RootState;
            IFocusNodeStateView RootStateView = (IFocusNodeStateView)StateViewTable[RootState];

            IFocusFocus MatchingFocus = null;

            RootStateView.UpdateFocusChain(NewFocusChain, focusedNode, focusedFrame, ref MatchingFocus);

            // Ensured by all templates having at least one preferred (hence focusable) frame.
            Debug.Assert(NewFocusChain.Count > 0);

            // First run, initialize the focus to the first focusable cell.
            if (Focus == null)
            {
                Debug.Assert(FocusChain == null);
                Focus = NewFocusChain[0];
                ResetCaretPosition(0, true);
            }
            else if (MatchingFocus != null)
            {
                Focus = MatchingFocus;
                UpdateMaxCaretPosition(); // The focus didn't change, but the content may have.
            }
            else
            {
                RecoverFocus(state, NewFocusChain); // The focus has forcibly changed.
            }
            FocusChain = NewFocusChain;
            DebugObjects.AddReference(NewFocusChain);

            Debug.Assert(Focus != null);
            Debug.Assert(FocusChain.Contains(Focus));

            SelectionAnchor    = Focus.CellView.StateView;
            SelectionExtension = 0;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="FocusCommentCellView"/> class.
 /// </summary>
 /// <param name="stateView">The state view containing the tree with this cell.</param>
 /// <param name="parentCellView">The collection of cell views containing this view. Null for the root of the cell tree.</param>
 /// <param name="frame">The frame that created this cell view.</param>
 /// <param name="documentation">The comment this cell is displaying.</param>
 public FocusCommentCellView(IFocusNodeStateView stateView, IFocusCellViewCollection parentCellView, IFocusFrame frame, IDocument documentation)
     : base(stateView, parentCellView, frame, documentation)
 {
 }
Esempio n. 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FocusContentFocusableCellView"/> class.
 /// </summary>
 /// <param name="stateView">The state view containing the tree with this cell.</param>
 /// <param name="parentCellView">The collection of cell views containing this view. Null for the root of the cell tree.</param>
 /// <param name="frame">The frame that created this cell view.</param>
 /// <param name="propertyName">Property corresponding to the component of the node.</param>
 public FocusContentFocusableCellView(IFocusNodeStateView stateView, IFocusCellViewCollection parentCellView, IFocusFrame frame, string propertyName)
     : base(stateView, parentCellView, frame, propertyName)
 {
 }
Esempio n. 18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FocusFocusableCellView"/> class.
 /// </summary>
 /// <param name="stateView">The state view containing the tree with this cell.</param>
 /// <param name="parentCellView">The collection of cell views containing this view. Null for the root of the cell tree.</param>
 /// <param name="frame">The frame that created this cell view.</param>
 public FocusFocusableCellView(IFocusNodeStateView stateView, IFocusCellViewCollection parentCellView, IFocusFrame frame)
     : base(stateView, parentCellView, frame)
 {
 }
Esempio n. 19
0
 void ICollection <IFocusFrame> .Add(IFocusFrame item)
 {
     Add((ILayoutFrame)item);
 }
Esempio n. 20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FocusColumn"/> class.
 /// </summary>
 /// <param name="stateView">The state view containing the tree with this cell.</param>
 /// <param name="parentCellView">The collection of cell views containing this view. Null for the root of the cell tree.</param>
 /// <param name="cellViewList">The list of child cell views.</param>
 /// <param name="frame">The frame that was used to create this cell. Can be null.</param>
 public FocusColumn(IFocusNodeStateView stateView, IFocusCellViewCollection parentCellView, IFocusCellViewList cellViewList, IFocusFrame frame)
     : base(stateView, parentCellView, cellViewList, frame)
 {
 }
Esempio n. 21
0
        private protected virtual bool GetFirstCommentFrame(IFocusFrame root, IList <IFocusFrameSelectorList> selectorStack, out IFocusCommentFrame frame)
        {
            bool Found = false;

            frame = null;

            if (root is IFocusCommentFrame AsCommentFrame)
            {
                frame = AsCommentFrame;
                Found = true;
            }

            if (!Found && root is IFocusPanelFrame AsPanelFrame)
            {
                foreach (IFocusFrame Item in AsPanelFrame.Items)
                {
                    if (GetFirstCommentFrame(Item, selectorStack, out frame))
                    {
                        Found = true;
                        break;
                    }
                }
            }

            else if (root is IFocusSelectionFrame AsSelectionFrame)
            {
                IFocusSelectableFrame SelectedFrame = null;

                foreach (IFocusSelectableFrame Item in AsSelectionFrame.Items)
                {
                    foreach (IFocusFrameSelectorList SelectorList in selectorStack)
                    {
                        foreach (IFocusFrameSelector Selector in SelectorList)
                        {
                            if (Selector.SelectorType == NodeType)
                            {
                                if (Selector.SelectorName == Item.Name)
                                {
                                    SelectedFrame = Item;
                                    break;
                                }
                            }
                        }
                        if (SelectedFrame != null)
                        {
                            break;
                        }
                    }
                    if (SelectedFrame != null)
                    {
                        break;
                    }
                }

                if (SelectedFrame != null)
                {
                    if (GetFirstCommentFrame(SelectedFrame.Content, selectorStack, out frame))
                    {
                        Found = true;
                    }
                }
            }

            return(Found);
        }
Esempio n. 22
0
 bool ICollection <IFocusFrame> .Contains(IFocusFrame value)
 {
     return(Contains((ILayoutFrame)value));
 }
        /// <summary>
        /// Updates the focus chain with cells in the tree.
        /// </summary>
        /// <param name="focusChain">The list of focusable cell views found in the tree.</param>
        /// <param name="focusedNode">The currently focused node.</param>
        /// <param name="focusedFrame">The currently focused frame in the template associated to <paramref name="focusedNode"/>.</param>
        /// <param name="matchingFocus">The focus in <paramref name="focusChain"/> that match <paramref name="focusedNode"/> and <paramref name="focusedFrame"/> upon return.</param>
        public virtual void UpdateFocusChain(FocusFocusList focusChain, Node focusedNode, IFocusFrame focusedFrame, ref IFocusFocus matchingFocus)
        {
            Debug.Assert(RootCellView != null);

            RootCellView.UpdateFocusChain(focusChain, focusedNode, focusedFrame, ref matchingFocus);
        }
Esempio n. 24
0
 int IList <IFocusFrame> .IndexOf(IFocusFrame value)
 {
     return(IndexOf((ILayoutFrame)value));
 }
Esempio n. 25
0
        private protected bool GetFirstNamedFrame(IFocusFrame root, string propertyName, IList <IFocusFrameSelectorList> selectorStack, bool reverseSearch, ref int valueFrameIndex, out IFocusNamedFrame frame)
        {
            frame = null;
            bool Found = false;

            if (root is IFocusNamedFrame AsNamedFrame)
            {
                valueFrameIndex++;

                if (AsNamedFrame.PropertyName == propertyName)
                {
                    frame = AsNamedFrame;
                    Found = true;
                }
            }

            if (root is IFocusPanelFrame AsPanelFrame)
            {
                int Count = AsPanelFrame.Items.Count;
                for (int i = 0; i < Count; i++)
                {
                    IFocusFrame Item = AsPanelFrame.Items[reverseSearch ? Count - 1 - i : i];

                    if (GetFirstNamedFrame(Item, propertyName, selectorStack, reverseSearch, ref valueFrameIndex, out frame))
                    {
                        Found = true;
                        break;
                    }
                }
            }

            else if (root is IFocusSelectionFrame AsSelectionFrame)
            {
                IFocusSelectableFrame SelectedFrame = null;

                foreach (IFocusSelectableFrame Item in AsSelectionFrame.Items)
                {
                    foreach (IFocusFrameSelectorList SelectorList in selectorStack)
                    {
                        foreach (IFocusFrameSelector Selector in SelectorList)
                        {
                            if (Selector.SelectorType == NodeType)
                            {
                                if (Selector.SelectorName == Item.Name)
                                {
                                    SelectedFrame = Item;
                                    break;
                                }
                            }
                        }
                        if (SelectedFrame != null)
                        {
                            break;
                        }
                    }
                    if (SelectedFrame != null)
                    {
                        break;
                    }
                }

                if (SelectedFrame != null)
                {
                    if (GetFirstNamedFrame(SelectedFrame.Content, propertyName, selectorStack, reverseSearch, ref valueFrameIndex, out frame))
                    {
                        Found = true;
                    }
                }
            }

            return(Found);
        }
Esempio n. 26
0
 void IList <IFocusFrame> .Insert(int index, IFocusFrame item)
 {
     Insert(index, (ILayoutFrame)item);
 }
 /// <summary>
 /// Updates the focus chain with cells in the tree.
 /// </summary>
 /// <param name="focusChain">The list of focusable cell views found in the tree.</param>
 /// <param name="focusedNode">The currently focused node.</param>
 /// <param name="focusedFrame">The currently focused frame in the template associated to <paramref name="focusedNode"/>.</param>
 /// <param name="matchingFocus">The focus in <paramref name="focusChain"/> that match <paramref name="focusedNode"/> and <paramref name="focusedFrame"/> upon return.</param>
 public abstract void UpdateFocusChain(FocusFocusList focusChain, Node focusedNode, IFocusFrame focusedFrame, ref IFocusFocus matchingFocus);
Esempio n. 28
0
        /// <summary>
        /// Updates the focus chain with cells in the tree.
        /// </summary>
        /// <param name="focusChain">The list of focusable cell views found in the tree.</param>
        /// <param name="focusedNode">The currently focused node.</param>
        /// <param name="focusedFrame">The currently focused frame in the template associated to <paramref name="focusedNode"/>.</param>
        /// <param name="matchingFocus">The focus in <paramref name="focusChain"/> that match <paramref name="focusedNode"/> and <paramref name="focusedFrame"/> upon return.</param>
        public virtual void UpdateFocusChain(IFocusFocusList focusChain, INode focusedNode, IFocusFrame focusedFrame, ref IFocusFocus matchingFocus)
        {
            IFocusDiscreteContentFocus NewFocus = CreateFocus();

            focusChain.Add(NewFocus);

            if (focusedFrame == Frame)
            {
                IFocusOptionalNodeState AsOptionalNodeState = StateView.State as IFocusOptionalNodeState;
                Debug.Assert(AsOptionalNodeState == null || AsOptionalNodeState.ParentInner.IsAssigned);

                if (focusedNode == StateView.State.Node)
                {
                    Debug.Assert(matchingFocus == null);
                    matchingFocus = NewFocus;
                }
            }
        }
Esempio n. 29
0
 /// <summary>
 /// Updates the focus chain with cells in the tree.
 /// </summary>
 /// <param name="focusChain">The list of focusable cell views found in the tree.</param>
 /// <param name="focusedNode">The currently focused node.</param>
 /// <param name="focusedFrame">The currently focused frame in the template associated to <paramref name="focusedNode"/>.</param>
 /// <param name="matchingFocus">The focus in <paramref name="focusChain"/> that match <paramref name="focusedNode"/> and <paramref name="focusedFrame"/> upon return.</param>
 public virtual void UpdateFocusChain(IFocusFocusList focusChain, INode focusedNode, IFocusFrame focusedFrame, ref IFocusFocus matchingFocus)
 {
     foreach (IFocusCellView Item in CellViewList)
     {
         Item.UpdateFocusChain(focusChain, focusedNode, focusedFrame, ref matchingFocus);
     }
 }
Esempio n. 30
0
 /// <summary>
 /// Updates the focus chain with cells in the tree.
 /// </summary>
 /// <param name="focusChain">The list of focusable cell views found in the tree.</param>
 /// <param name="focusedNode">The currently focused node.</param>
 /// <param name="focusedFrame">The currently focused frame in the template associated to <paramref name="focusedNode"/>.</param>
 /// <param name="matchingFocus">The focus in <paramref name="focusChain"/> that match <paramref name="focusedNode"/> and <paramref name="focusedFrame"/> upon return.</param>
 public virtual void UpdateFocusChain(IFocusFocusList focusChain, INode focusedNode, IFocusFrame focusedFrame, ref IFocusFocus matchingFocus)
 {
     ChildStateView.UpdateFocusChain(focusChain, focusedNode, focusedFrame, ref matchingFocus);
 }