Esempio n. 1
0
        /// <summary>Returns a new stroke that has a deep copy.</summary>
        /// <remarks>Deep copied data includes points, point description, drawing attributes, and transform</remarks>
        /// <returns>Deep copy of current stroke</returns>
        public virtual Stroke Clone()
        {
            //
            // use MemberwiseClone, which will instance the most derived type
            // We use this instead of Activator.CreateInstance because it does not
            // require ReflectionPermission.  One thing to note, all references
            // are shared, including event delegates, so we need to set those to null
            //
            Stroke clone = (Stroke)this.MemberwiseClone();

            //
            // null the delegates in the cloned strokes
            //
            clone.DrawingAttributesChanged  = null;
            clone.DrawingAttributesReplaced = null;
            clone.StylusPointsReplaced      = null;
            clone.StylusPointsChanged       = null;
            clone.PropertyDataChanged       = null;
            clone.Invalidated      = null;
            clone._propertyChanged = null;

            //Clone is also called from Stroke.Copy internally for point
            //erase.  In that case, we don't want to clone the StylusPoints
            //because they will be replaced after we call
            if (_cloneStylusPoints)
            {
                clone._stylusPoints = _stylusPoints.Clone();
            }
            clone._drawingAttributes = _drawingAttributes.Clone();
            if (_extendedProperties != null)
            {
                clone._extendedProperties = _extendedProperties.Clone();
            }
            //set up listeners
            clone.Initialize();

            //
            // copy state
            //
            Debug.Assert(_cachedGeometry == null || _cachedGeometry.IsFrozen);
            //we don't need to cache if this is frozen
            //if (null != _cachedGeometry)
            //{
            //    clone._cachedGeometry = _cachedGeometry.Clone();
            //}
            //don't need to clone these, they are value types
            //and are copied by MemberwiseClone
            //_isSelected
            //_drawAsHollow
            //_cachedBounds

            //this need to be reset
            clone._cloneStylusPoints = true;

            return(clone);
        }