Пример #1
0
        /// <summary>
        /// Visit the control at the specified index.
        /// </summary>
        /// <param name="index"></param>
        /// <param name="visitor"></param>
        /// <returns>true if the visit was successful</returns>
        private bool VisitControl(int index, ControlVisitor visitor)
        {
            object obj = _controls[index];

            if (obj is Control)
            {
                return(visitor.VisitControl((Control)obj));
            }
            else if (obj is LightweightControl)
            {
                return(visitor.VisitLightweightControl((LightweightControl)obj));
            }
            else
            {
                Debug.Fail("Unsupported control type detected: " + obj.GetType().Name);
                return(false);
            }
        }
 //..
 public void Accept(ControlVisitor visitor)
 {
     visitor.Visit(this);
 }
Пример #3
0
        /// <summary>
        /// Visit all controls in the specified forward/backward direction.
        /// </summary>
        /// <param name="from"></param>
        /// <param name="forward"></param>
        /// <param name="wrap"></param>
        /// <param name="stopResult">the value expected from the visitor to stop the visit loop</param>
        /// <param name="visitor"></param>
        /// <returns></returns>
        private bool VisitControlsUntilStopValue(int from, bool forward, bool wrap, bool stopResult, ControlVisitor visitor)
        {
            int currIndex = from;

            while (true)
            {
                int nextIndex = -1;
                if (currIndex < 0)
                {
                    if (_controls.Count > 0)
                    {
                        nextIndex = forward ? 0 : _controls.Count - 1;
                    }
                }
                else
                {
                    nextIndex = GetNextControlIndex(currIndex, forward, wrap);
                }

                if (nextIndex != -1)
                {
                    if (VisitControl(nextIndex, visitor) == stopResult)
                    {
                        return(stopResult);
                    }
                }
                else
                {
                    return(!stopResult);
                }
                currIndex = nextIndex;
            }
        }
        /// <summary>
        /// Visit all controls in the specified forward/backward direction.
        /// </summary>
        /// <param name="from"></param>
        /// <param name="forward"></param>
        /// <param name="wrap"></param>
        /// <param name="stopResult">the value expected from the visitor to stop the visit loop</param>
        /// <param name="visitor"></param>
        /// <returns></returns>
        private bool VisitControlsUntilStopValue(int from, bool forward, bool wrap, bool stopResult, ControlVisitor visitor)
        {
            int currIndex = from;
            while (true)
            {
                int nextIndex = -1;
                if (currIndex < 0)
                {
                    if (_controls.Count > 0)
                        nextIndex = forward ? 0 : _controls.Count - 1;
                }
                else
                    nextIndex = GetNextControlIndex(currIndex, forward, wrap);

                if (nextIndex != -1)
                {
                    if (VisitControl(nextIndex, visitor) == stopResult)
                        return stopResult;
                }
                else
                {
                    return !stopResult;
                }
                currIndex = nextIndex;
            }
        }
 /// <summary>
 /// Visit the control at the specified index.
 /// </summary>
 /// <param name="index"></param>
 /// <param name="visitor"></param>
 /// <returns>true if the visit was successful</returns>
 private bool VisitControl(int index, ControlVisitor visitor)
 {
     object obj = _controls[index];
     if (obj is Control)
         return visitor.VisitControl((Control)obj);
     else if (obj is LightweightControl)
         return visitor.VisitLightweightControl((LightweightControl)obj);
     else
     {
         Debug.Fail("Unsupported control type detected: " + obj.GetType().Name);
         return false;
     }
 }