Example #1
0
        /// <summary>
        /// 复制对象
        /// </summary>
        /// <param name="Deeply">是否复制子孙节点</param>
        /// <returns>复制品</returns>
        public override DomElement Clone(bool Deeply)
        {
            DomContainerElement c = (DomContainerElement)base.Clone(Deeply);

            if (this._Attributes != null)
            {
                c._Attributes = this._Attributes.Clone();
            }
            //if (this._Expressions != null)
            //{
            //    c._Expressions = this._Expressions.Clear
            //}
            c._Elements             = new DomElementList();
            c._ElementsForSerialize = null;
            if (Deeply)
            {
                if (_Elements != null)
                {
                    c._Elements = new DomElementList();
                    foreach (DomElement element in _Elements)
                    {
                        DomElement newElement = element.Clone(Deeply);
                        c._Elements.Add(newElement);
                        newElement.Parent = c;
                    } //foreach
                }     //if
            }
            return(c);
        }
Example #2
0
        /// <summary>
        /// 在编辑器中删除整个对象
        /// </summary>
        /// <param name="logUndo">是否记录撤销操作信息</param>
        public bool EditorDelete(bool logUndo)
        {
            if (this is DomDocumentContentElement)
            {
                return(false);
            }

            DomContainerElement container = this.Parent;
            int         index             = container.Elements.IndexOf(this);
            DomDocument document          = this.OwnerDocument;

            if (logUndo)
            {
                document.BeginLogUndo();
            }
            int result = document.ReplaceElements(new ReplaceElementsArgs(
                                                      container,
                                                      index,
                                                      1,
                                                      null,
                                                      logUndo,
                                                      true,
                                                      true));

            if (logUndo)
            {
                document.EndLogUndo();
            }
            return(result != 0);
        }
 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);
         }
     }
 }
Example #4
0
        /// <summary>
        /// 以冒泡方式出发文档容器元素的OnContentChanged事件
        /// </summary>
        /// <param name="args">事件参数</param>
        public void RaiseBubbleOnContentChanged(ContentChangedEventArgs args)
        {
            DomContainerElement parent = this;

            while (parent != null)
            {
                parent.OnContentChanged(args);
                if (args.CancelBubble)
                {
                    break;
                }
                parent = parent.Parent;
            }
        }
Example #5
0
 /// <summary>
 /// 初始化对象
 /// </summary>
 /// <param name="container">要替换子元素的容器元素对象</param>
 /// <param name="startIndex">替换区域的开始序号</param>
 /// <param name="deleteLength">要删除的子元素的个数</param>
 /// <param name="newElements">要插入的新元素列表</param>
 /// <param name="logUndo">是否记录撤销操作信息</param>
 /// <param name="updateContent">是否更新文档视图</param>
 /// <param name="raiseEvent">是否触发事件</param>
 public ReplaceElementsArgs(
     DomContainerElement container,
     int startIndex,
     int deleteLength,
     DomElementList newElements,
     bool logUndo,
     bool updateContent,
     bool raiseEvent)
 {
     _Container     = container;
     _StartIndex    = startIndex;
     _DeleteLength  = deleteLength;
     _NewElements   = newElements;
     _LogUndo       = logUndo;
     _UpdateContent = updateContent;
     _RaiseEvent    = raiseEvent;
 }
Example #6
0
        /// <summary>
        /// 根据内容创建一个新的文档对象,而且不包含已经被逻辑删除的内容.
        /// </summary>
        /// <returns>创建的文档对象</returns>
        public DomDocument CreateDocument()
        {
            DomDocument         document       = ( DomDocument )this.Document.Clone(false);
            DomDocument         sourceDocument = this.Document;
            DomContainerElement body           = document.Body;
            // 寻找所有内容共同的文档容器元素
            DomElementList parents1 = WriterUtils.GetParentList(this.ContentElements.FirstElement);
            DomElementList parents2 = WriterUtils.GetParentList(this.ContentElements.LastElement);

            foreach (DomContainerElement parent in parents1)
            {
                if (parents2.Contains(parent))
                {
                    DomContentElement ce = parent.ContentElement;
                    CloneElements(parent, ref body);
                    break;
                }
            }

            //CloneElements(this.DocumentContent, ref body );

            // 删除用户操作历史记录信息
            foreach (DocumentContentStyle style in document.ContentStyles.Styles)
            {
                style.CreatorIndex = -1;
                style.DeleterIndex = -1;
            }
            document.UserHistories.Clear();

            // 删除没有引用的样式
            document.DeleteUselessStyle();
            document.EditorControl      = null;
            document.DocumentControler  = null;
            document.HighlightManager   = null;
            document.EditorCurrentStyle = null;
            document.HoverElement       = null;
            if (document.UndoList != null)
            {
                document.EndLogUndo();
                document.UndoList.Clear();
            }
            document.FixDomState();
            return(document);
        }
Example #7
0
        /// <summary>
        /// 获得高亮度显示信息对象
        /// </summary>
        /// <param name="element"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        private HighlightInfo GetHighlightInfo(DomElement element)
        {
            if (_HighlightBuffer == null)
            {
                _HighlightBuffer = new HighlightInfoList();
            }
            else
            {
                // 在缓存区中逆向搜索
                // 由于绘制文档内容都是按照顺序绘制文档内容
                for (int iCount = _HighlightBuffer.Count - 1; iCount >= 0; iCount--)
                {
                    if (_HighlightBuffer[iCount].Contains(element))
                    {
                        return(_HighlightBuffer[iCount]);
                    }
                }
            }

            DomContainerElement parent = element.Parent;

            while (parent != null)
            {
                HighlightInfoList infos = parent.GetHighlightInfos();
                if (infos != null && infos.Count > 0)
                {
                    foreach (HighlightInfo info in infos)
                    {
                        if (info.Contains(element))
                        {
                            // 保存在缓存区中
                            _HighlightBuffer.Add(info);
                            return(info);
                        }
                    }
                }
                parent = parent.Parent;
            }
            return(null);
        }
Example #8
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);
        }
Example #9
0
        /// <summary>
        /// 全局替换
        /// </summary>
        /// <param name="args">参数</param>
        /// <returns>替换的次数</returns>
        public int ReplaceAll(SearchReplaceCommandArgs args)
        {
            int        result = 0;
            List <int> indexs = new List <int>();
            SearchReplaceCommandArgs args2 = args.Clone();

            args2.Backward = false;
            int currentIndex = this.Content.Count - 1;

            this.Document.BeginLogUndo();
            DocumentControler controler = this.Document.DocumentControler;
            Dictionary <DomContentElement, int> startIndexs = new Dictionary <DomContentElement, int>();

            while (true)
            {
                int index = Search(args2, false, currentIndex);
                if (index >= 0)
                {
                    DomSelection mySelection = new DomSelection(this.Document.CurrentContentElement);
                    mySelection.Refresh(index, args.SearchString.Length);
                    DomContainerElement container = null;
                    int elementIndex = 0;
                    this.Content.GetPositonInfo(index, out container, out elementIndex, false);
                    DomContentElement contentElement = container.ContentElement;
                    int pi = contentElement.PrivateContent.IndexOf(this.Content[index]);
                    if (startIndexs.ContainsKey(contentElement))
                    {
                        startIndexs[contentElement] = Math.Min(startIndexs[contentElement], pi);
                    }
                    else
                    {
                        startIndexs[contentElement] = pi;
                    }
                    indexs.Add(index);
                    if (string.IsNullOrEmpty(args.ReplaceString))
                    {
                        this.Content.DeleteSelection(true, false, true, mySelection);
                    }
                    else
                    {
                        DomElementList newElements = this.Document.CreateTextElements(
                            args.ReplaceString,
                            (DocumentContentStyle)this.Document.CurrentParagraphStyle,
                            (DocumentContentStyle)this.Document.EditorCurrentStyle.Clone());
                        ReplaceElementsArgs args3 = new ReplaceElementsArgs(
                            container,
                            index,
                            0,
                            newElements,
                            true,
                            false,
                            true);
                        int repResult = this.Document.ReplaceElements(args3);
                    }
                    result++;
                }
                else
                {
                    break;
                }
                currentIndex = index + args2.SearchString.Length;
            }//while
            this.Document.EndLogUndo();
            if (startIndexs.Count > 0)
            {
                bool refreshPage = false;
                foreach (DomContentElement ce in startIndexs.Keys)
                {
                    ce.UpdateContentElements(true);
                    ce.UpdateContentVersion();
                    ce._NeedRefreshPage = false;
                    ce.RefreshPrivateContent(startIndexs[ce]);
                    if (ce._NeedRefreshPage)
                    {
                        refreshPage = true;
                    }
                }
                if (refreshPage)
                {
                    this.Document.RefreshPages();
                    if (this.Document.EditorControl != null)
                    {
                        this.Document.EditorControl.UpdatePages();
                        this.Document.EditorControl.UpdateTextCaret();
                        this.Document.EditorControl.Invalidate();
                    }
                }
            }
            return(startIndexs.Count);
        }
Example #10
0
        private int CloneElements(
            DomContainerElement sourceContainer,
            ref DomContainerElement descContainer)
        {
            int result = 0;

            foreach (DomElement element in sourceContainer.Elements)
            {
                if (element.Style.DeleterIndex >= 0)
                {
                    // 元素被逻辑删除了,无法复制
                    continue;
                }

                else if (element is DomContainerElement)
                {
                    DomContainerElement c    = ( DomContainerElement )element;
                    DomContainerElement newC = null;
                    int result2 = CloneElements(c, ref newC);
                    if (result2 == 0)
                    {
                        if (element is DomContainerElement)
                        {
                            DomContainerElement container = ( DomContainerElement )element;
                            if (c.Elements.Count == 0)
                            {
                                // 有些特殊的容器元素没有标准意义上的子元素,例如设置了背景文本的没有实际
                                // 内容的输入域等,此时需要判断文档内容元素
                                DomElementList ces = new DomElementList();
                                container.AppendContent(ces, true);
                                foreach (DomElement ce in ces)
                                {
                                    if (this.ContentElements.Contains(ce))
                                    {
                                        if (newC == null)
                                        {
                                            // 发现有内容在包含区域中,则创建新的容器元素对象
                                            newC           = ( DomContainerElement )c.Clone(false);
                                            newC.OwnerLine = null;
                                            break;
                                        }
                                    }
                                } //foreach
                            }     //if
                        }         //if
                    }             //if
                    if (newC != null)
                    {
                        if (descContainer == null)
                        {
                            result++;
                            descContainer           = (DomContainerElement)sourceContainer.Clone(false);
                            descContainer.OwnerLine = null;
                        }
                        descContainer.AppendChildElement(newC);
                    }
                }
            }//foreach

            return(result);
        }