Exemplo n.º 1
0
        /// <summary>
        /// 设置文档内容的样式
        /// </summary>
        /// <param name="newStyle">新样式</param>
        /// <param name="logUndo">是否记录撤销操作信息</param>
        public virtual void EditorSetContentStyle(DocumentContentStyle newStyle, bool logUndo)
        {
            if (newStyle == null)
            {
                throw new ArgumentNullException("newStyle");
            }
            DomElementList list = new DomElementList();

            list.Add(this);
            this.AppendContent(list, true);
            if (logUndo)
            {
                this.OwnerDocument.BeginLogUndo();
            }
            bool result = DomSelection.SetElementStyle(newStyle, this.OwnerDocument, list);

            if (logUndo)
            {
                this.OwnerDocument.EndLogUndo();
            }
            if (result)
            {
                this.OwnerDocument.EditorCurrentStyle = null;
                this.OwnerDocument.OnSelectionChanged();
                this.OwnerDocument.OnDocumentContentChanged();
            }
        }
Exemplo n.º 2
0
        public DomElementList DeeplyClone( )
        {
            this.CheckEOF(-1);
            DomElementList list = new DomElementList();

            foreach (DomElement element in this)
            {
                list.Add(element.Clone(true));
            }
            return(list);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获得区域包含的元素列表
        /// </summary>
        /// <returns>创建的元素列表</returns>
        public DomElementList GetElements()
        {
            CheckState();
            DomElementList result = new DomElementList();

            for (int iCount = 0; iCount < _Length; iCount++)
            {
                result.Add(this._Elements[_StartIndex + iCount]);
            }
            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 复制对象
        /// </summary>
        /// <returns>复制品</returns>
        public DomElementList Clone()
        {
            DomElementList list = (DomElementList)System.Activator.CreateInstance(this.GetType());

            list.bolCanDeleteEOF   = this.bolCanDeleteEOF;
            list.bolFastRemoveFlag = this.bolFastRemoveFlag;
            list.myEOFElement      = this.myEOFElement;
            list.myOwnerElement    = this.myOwnerElement;
            foreach (DomElement e in this)
            {
                list.Add(e);
            }
            return(list);
        }
 private void GetContentElements(DomContainerElement rootElement, DomElementList result)
 {
     foreach (DomElement element in rootElement.Elements)
     {
         if (element is DomContentElement)
         {
             result.Add(element);
         }
         if (element is DomContainerElement)
         {
             GetContentElements((DomContainerElement)element, result);
         }
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// 添加子元素
 /// </summary>
 /// <param name="element">新添加的元素</param>
 public virtual bool AppendChildElement(DomElement element)
 {
     if (element != null)
     {
         if (_Elements.Contains(element) == false)
         {
             _Elements.Add(element);
         }
         element.Parent        = this;
         element.OwnerDocument = this.OwnerDocument;
         return(true);
     }
     return(false);
 }
Exemplo n.º 7
0
 private void MyAddRange(DomElementList list, DomElementList content)
 {
     foreach (DomElement element in content)
     {
         {
             if (list.Contains(element))
             {
                 // 已经添加过内容了,立即退出函数
                 return;
             }
             list.Add(element);
         }
     }
 }
Exemplo n.º 8
0
//		/// <summary>
//		/// 获得指定元素的前一个元素
//		/// </summary>
//		/// <param name="refElement">指定的元素</param>
//		/// <returns>该元素的前一个元素若没找到则返回空</returns>
//		public XTextElement GetPreElement( XTextElement refElement)
//		{
//			int index = this.IndexOf( refElement );
//			return SafeGet( index - 1 );
//		}
//
//		/// <summary>
//		/// 获得指定元素的后一个元素
//		/// </summary>
//		/// <param name="refElement">指定的元素</param>
//		/// <returns>该元素的前一个元素,若没有找到则返回空</returns>
//		public XTextElement GetNextElement( XTextElement refElement )
//		{
//			int index = this.IndexOf( refElement );
//			if( index >= 0 )
//				return SafeGet( index + 1 );
//			else
//				return null;
//		}


        /// <summary>
        /// 获得子列表
        /// </summary>
        /// <param name="startIndex">开始元素的序号</param>
        /// <param name="length">元素的个数</param>
        /// <returns>获得的子列表</returns>
        public DomElementList GetElements(int startIndex, int length)
        {
            if (startIndex <= 0)
            {
                throw new ArgumentException("startIndex");
            }
            DomElementList list     = new DomElementList();
            int            endIndex = Math.Min(this.Count - 1, startIndex + length - 1);

            for (int iCount = startIndex; iCount <= endIndex; iCount++)
            {
                list.Add(this[iCount]);
            }
            return(list);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 将对象拆分成若干个字符元素对象
        /// </summary>
        /// <returns>拆分所得的字符元素对象列表</returns>
        internal DomElementList SplitChars()
        {
            DomElementList list = new DomElementList();
            string         txt  = myText.ToString();

            foreach (char c in txt)
            {
                DomCharElement NewChar = this.OwnerDocument.CreateChar(c, this.StyleIndex);
                if (NewChar != null)
                {
                    NewChar.StyleIndex = this.StyleIndex;
                    NewChar.Parent     = this.Parent;
                    list.Add(NewChar);
                }
            }
            return(list);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 将对象内容添加到文档内容中
        /// </summary>
        /// <param name="content">文档内容对象</param>
        /// <returns>添加的文档元素个数</returns>
        public virtual int AppendContent(DomElementList content, bool privateMode)
        {
            int result = 0;

            foreach (DomElement element in this.Elements)
            {
                element.Parent = this;
                if (element.Visible)
                {
                    if (element is DomContainerElement)
                    {
                        DomContainerElement c = (DomContainerElement)element;
                        result = result + c.AppendContent(content, privateMode);
                    }
                    else
                    {
                        content.Add(element);
                        result++;
                    }
                }//if
            }            //foreach
            return(result);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 设置多个元素的样式
        /// </summary>
        /// <param name="newStyle">新样式</param>
        /// <param name="document">文档对象</param>
        /// <param name="elements">要设置的元素列表</param>
        /// <returns>操作是否成功</returns>
        internal static bool SetElementStyle(
            DocumentContentStyle newStyle,
            DomDocument document,
            System.Collections.IEnumerable elements)
        {
            if (newStyle == null)
            {
                throw new ArgumentNullException("newStyle");
            }
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            if (elements == null)
            {
                throw new ArgumentNullException("elements");
            }
            if (document.Options.SecurityOptions.EnablePermission)
            {
                // 运行授权控制,向样式信息添加用户信息
                newStyle.DisableDefaultValue = false;
                newStyle.CreatorIndex        = document.UserHistories.CurrentIndex;
                newStyle.DeleterIndex        = -1;
            }
            else
            {
                // 去除授权控制相关信息
                newStyle.DisableDefaultValue = false;
                newStyle.CreatorIndex        = -1;
                newStyle.DeleterIndex        = -1;
            }
            Dictionary <DomElement, int> newStyleIndexs
                = new Dictionary <DomElement, int>();
            DomElementList parents    = new DomElementList();
            DomElement     lastParent = null;

            foreach (DomElement element in elements)
            {
                DomElement parent = element.Parent;
                //if (parent != lastParent)
                {
                    // 记录所有涉及到的父元素
                    lastParent = parent;
                    bool addParent = false;
                    //if (element is XTextFieldBorderElement)
                    //{
                    //    addParent = true;
                    //}
                    //else

                    if (addParent)
                    {
                        if (parents.Contains(element.Parent) == false)
                        {
                            parents.Add(element.Parent);
                        }
                    }
                }//if
                DocumentContentStyle rs = (DocumentContentStyle)element.RuntimeStyle.Clone();
                if (XDependencyObject.MergeValues(newStyle, rs, true) > 0)
                {
                    rs.DefaultValuePropertyNames = newStyle.GetDefaultValuePropertyNames();
                    int styleIndex = document.ContentStyles.GetStyleIndex(rs);
                    if (styleIndex != element.StyleIndex)
                    {
                        newStyleIndexs[element] = styleIndex;
                    }
                    if (element.ShadowElement != null && styleIndex != element.ShadowElement.StyleIndex)
                    {
                        newStyleIndexs[element.ShadowElement] = styleIndex;
                    }
                }
            }//foreach
            if (parents.Count > 0)
            {
                // 对涉及到的父元素设置样式
                foreach (DomElement element in parents)
                {
                    DocumentContentStyle rs = (DocumentContentStyle)element.RuntimeStyle.Clone();
                    if (XDependencyObject.MergeValues(newStyle, rs, true) > 0)
                    {
                        rs.DefaultValuePropertyNames = newStyle.GetDefaultValuePropertyNames();
                        int styleIndex = document.ContentStyles.GetStyleIndex(rs);
                        if (styleIndex != element.StyleIndex)
                        {
                            newStyleIndexs[element] = styleIndex;
                        }
                    }
                }
            }
            if (newStyleIndexs.Count > 0)
            {
                DomElementList result = document.EditorSetElementStyle(newStyleIndexs, true);
                if (result != null && result.Count > 0)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 12
0
        /// <summary>
        /// 更新文内容选择状态
        /// </summary>
        /// <param name="startIndex">选择区域的起始位置</param>
        /// <param name="length">选择区域的包含文档内容元素的个数</param>
        /// <param name="raiseEvent">是否触发文档事件</param>
        /// <returns>成功的改变了选择区域状态</returns>
        internal bool Refresh(int startIndex, int length)
        {
            if (_NativeStartIndex == startIndex &&
                _NativeLength == length &&
                this.DocumentContent.OwnerDocument.ContentVersion == _ContentVersion &&
                this.Content.LineEndFlag == _LineEndFlag)
            {
                return(false);
            }
            if (startIndex == 0 || startIndex + length == 0)
            {
                System.Console.Write("");
            }
            if (startIndex < 0)
            {
                System.Console.WriteLine("");
                throw new ArgumentOutOfRangeException("startIndex=" + startIndex);
            }
            _SelectionVersion++;

            this.Document.EditorCurrentStyle = null;

            //if (startIndex == 872)
            //{
            //    System.Console.WriteLine("");
            //}

            // 备份原先被选择的元素的列表
            DomElementList contentElementsBack = _ContentElements.Clone();

            _ContentElements = new DomElementList();


            _ContentVersion = this.DocumentContent.OwnerDocument.ContentVersion;

            if (startIndex == 0 && length == 0)
            {
                _NativeStartIndex = 0;
                _NativeLength     = 0;
                _StartIndex       = 0;
                _Length           = 0;
                _LineEndFlag      = this.Content.LineEndFlag;
                this._Mode        = ContentRangeMode.Content;
                _ContentElements  = new DomElementList();

                //return true;
            }
            else
            {
                _NativeStartIndex = startIndex;
                _NativeLength     = length;
                _LineEndFlag      = this.Content.LineEndFlag;

                DomContent content = this.Content;

                _Mode = ContentRangeMode.Content;
                // 选择区域经过的单元格列表
                DomElementList spanElements = new DomElementList();

                // 所经过的单元格个数
                int cellCount = 0;
                //XTextElementList spanCells = new XTextElementList();
                // 是否有不包含在表格单元格中的文档内容元素
                bool hasContentElement = false;

                int absStartIndex = length > 0 ? startIndex : startIndex + length;
                int absLength     = Math.Abs(length);



                int lengthFix = 1;
                if (content.LineEndFlag && length < 0)
                {
                    lengthFix = 0;
                }
                // 遍历所有的文档元素,查找所经过的单元格
                for (int iCount = 0; iCount < absLength + lengthFix; iCount++)
                {
                    if (absStartIndex + iCount >= content.Count)
                    {
                        break;
                        //System.Console.Write("");
                    }
                    DomElement element = content[absStartIndex + iCount];
                    if (element.Parent == this.DocumentContent)
                    {
                        spanElements.Add(element);
                        hasContentElement = true;
                    }
                    else
                    {
                        spanElements.Add(element);
                        hasContentElement = true;
                    }
                }//for

                // 首先判断内容模式
                _Mode = ContentRangeMode.Content;

                // 选择纯文档内容
                _ContentElements = content.GetRange(absStartIndex, absLength);
                _StartIndex      = startIndex;
                _Length          = length;

                if (length == 0 || _ContentElements.Count == 0)
                {
                    _StartIndex = startIndex;
                    _Length     = length;
                }
                else
                {
                    if (length > 0)
                    {
                        _StartIndex         = _ContentElements[0].ViewIndex;
                        _Length             = _ContentElements.Count;
                        content.LineEndFlag = false;
                    }
                    else
                    {
                        _StartIndex = _ContentElements.LastElement.ViewIndex + 1;
                        _Length     = 0 - _ContentElements.Count;

                        {
                            System.Console.Write("");
                        }
                    }
                    _LineEndFlag = content.LineEndFlag;
                }
            }//if

            if (this.Mode == ContentRangeMode.Content || this.Mode == ContentRangeMode.Mixed)
            {
                // 让选择状态发生改变的文档内容元素用户界面无效,需要重新绘制
                if (contentElementsBack != null && contentElementsBack.Count > 0)
                {
                    foreach (DomElement element in contentElementsBack)
                    {
                        if (_ContentElements.Contains(element) == false)
                        {
                            element.InvalidateView();
                        }
                    }
                }
                if (_ContentElements.Count > 0)
                {
                    foreach (DomElement element in _ContentElements)
                    {
                        if (contentElementsBack == null ||
                            contentElementsBack.Contains(element) == false)
                        {
                            element.InvalidateView();
                        }
                    }
                }
            }
            if (this.StartIndex == -1)
            {
                System.Console.WriteLine("");
            }
            return(true);
        }