Ejemplo n.º 1
0
        ///// <summary>
        ///// 设置容器元素的可见性
        ///// </summary>
        ///// <param name="visible">新的可见性</param>
        ///// <returns>操作是否成功</returns>
        //public bool EditorSetVisible(bool visible)
        //{
        //    bool result = false;
        //    bool oldVisible = this.Visible;
        //    if( oldVisible != visible )
        //    {
        //        this.Visible = visible;
        //        bool visible2 = this.Visible;
        //        if (visible2 == visible)
        //        {
        //            // 成功的修改了元素的可见性
        //            if (visible)
        //            {
        //                this.OwnerDocument.HighlightManager.InvalidateHighlightInfo(this);
        //            }
        //            else
        //            {
        //                this.OwnerDocument.HighlightManager.Remove(this);
        //            }
        //            result = true;
        //            XTextElement fc = this.FirstContentElement;
        //            XTextElement lc = this.LastContentElement;
        //            XTextContentElement content = this.ContentElement;
        //            int startIndex = 0;
        //            if (oldVisible)
        //            {
        //                startIndex = content.PrivateContent.IndexOf(fc);
        //            }
        //            this.UpdateContentVersion();
        //            content.UpdateContentElements(true);
        //            if (oldVisible == false)
        //            {
        //                startIndex = content.PrivateContent.IndexOf(fc);
        //            }
        //            content.RefreshPrivateContent(startIndex, -1, false);
        //        }
        //    }
        //    return result;
        //}

        /// <summary>
        /// 声明容器元素内容无效,需要重新排版
        /// </summary>
        public void EditorInvalidateContent()
        {
            DomContentElement ce = this.ContentElement;

            DomElement currentElementBack = this.DocumentContentElement.CurrentElement;
            //XTextElementList contentElements = new XTextElementList();
            //this.AppendContent(contentElements , true );

            DomElement firstElement = ce.PrivateContent.GetPreElement(this.FirstContentElement);

            if (firstElement == null)
            {
                firstElement = this.FirstContentElement;
            }
            DomElement lastElement = ce.PrivateContent.GetNextElement(this.LastContentElement);

            if (lastElement == null)
            {
                lastElement = ce.PrivateContent.LastElement;
            }
            // 声明所经过的文本行无效
            int endIndex = ce.PrivateContent.IndexOf(lastElement);

            for (int iCount = ce.PrivateContent.IndexOf(firstElement); iCount <= endIndex; iCount++)
            {
                if (ce.PrivateContent[iCount].OwnerLine != null)
                {
                    ce.PrivateContent[iCount].OwnerLine.InvalidateState = true;
                }
            }
            this.UpdateContentVersion();
            ce.UpdateContentElements(true);
            ce.RefreshPrivateContent(
                ce.PrivateContent.IndexOf(firstElement),
                ce.PrivateContent.IndexOf(lastElement),
                false);
            // 确认新的插入点的位置
            DomDocumentContentElement dce = this.DocumentContentElement;

            dce.RefreshGlobalLines();
            if (currentElementBack != null)
            {
                dce.Content.AutoClearSelection = true;
                dce.Content.LineEndFlag        = false;

                int newSelectionPosition = currentElementBack.ViewIndex;
                dce.Content.MoveSelectStart(newSelectionPosition);
            }
        }
Ejemplo n.º 2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (this.SourceEventArgs != null && this.SourceEventArgs.Element is DomImageElement)
            {
                DomDocument     document = this.SourceEventArgs.Document;
                DomImageElement element  = (DomImageElement)this.SourceEventArgs.Element;
                element.OwnerDocument = document;
                bool   logUndo  = this.SourceEventArgs.LogUndo && document.CanLogUndo;
                bool   modified = false;
                string txt      = txtID.Text.Trim();
                if (txt.Length == 0)
                {
                    txt = null;
                }
                if (txt != element.ID)
                {
                    if (logUndo)
                    {
                        document.UndoList.AddProperty("ID", element.ID, txt, element);
                    }
                    element.ID = txt;
                    modified   = true;
                }

                txt = txtTitle.Text.Trim();
                if (txt.Length == 0)
                {
                    txt = null;
                }
                if (txt != element.Title)
                {
                    if (logUndo)
                    {
                        document.UndoList.AddProperty("Title", element.Title, txt, element);
                    }
                    element.Title = txt;
                    modified      = true;
                }

                txt = txtAlt.Text.Trim();
                if (txt.Length == 0)
                {
                    txt = null;
                }
                if (txt != element.Alt)
                {
                    if (logUndo)
                    {
                        document.UndoList.AddProperty("Alt", element.Alt, txt, element);
                    }
                    element.Alt = txt;
                    modified    = true;
                }

                txt = txtSource.Text.Trim();
                if (txt.Length == 0)
                {
                    txt = null;
                }
                if (txt != element.Source)
                {
                    if (logUndo)
                    {
                        document.UndoList.AddProperty("Source", element.Source, txt, element);
                    }
                    element.Source = txt;
                    modified       = true;
                    element.UpdateImageContent();
                }

                if (chkKeepWidthHeightRate.Checked != element.KeepWidthHeightRate)
                {
                    if (logUndo)
                    {
                        document.UndoList.AddProperty(
                            "KeepWidthHeightRate",
                            element.KeepWidthHeightRate,
                            chkKeepWidthHeightRate.Checked,
                            element);
                    }
                    element.KeepWidthHeightRate = chkKeepWidthHeightRate.Checked;
                    modified = true;
                }

                if (chkSaveContentInFile.Checked != element.SaveContentInFile)
                {
                    if (logUndo)
                    {
                        document.UndoList.AddProperty(
                            "SaveContentInFile",
                            element.SaveContentInFile,
                            chkSaveContentInFile.Checked,
                            element);
                    }
                    element.SaveContentInFile = chkSaveContentInFile.Checked;
                    modified = true;
                }

                if (picImage.Tag != element.Image)
                {
                    XImageValue img = (XImageValue)picImage.Tag;
                    if (img == null)
                    {
                        img = new XImageValue();
                    }
                    if (img.HasContent)
                    {
                        if (logUndo)
                        {
                            document.UndoList.AddProperty(
                                "Image",
                                element.Image,
                                img,
                                element);
                        }
                        element.Image = img;
                        modified      = true;
                    }
                }
                if (modified)
                {
                    SizeF oldSize = new SizeF(element.Width, element.Height);
                    element.UpdateSize();
                    SizeF newSize = new SizeF(element.Width, element.Height);
                    if (logUndo)
                    {
                        document.UndoList.AddProperty("Width", oldSize.Width, element.Width, element);
                        document.UndoList.AddProperty("Height", oldSize.Height, element.Height, element);
                    }
                }
                if (this.SourceEventArgs.Method == ElementEditMethod.Edit)
                {
                    if (modified)
                    {
                        element.UpdateContentVersion();
                        DomContentElement ce = element.ContentElement;
                        ce.SetLinesInvalidateState(
                            element.OwnerLine,
                            element.OwnerLine);
                        ce.UpdateContentElements(true);
                        element.SizeInvalid = true;
                        ce.RefreshPrivateContent(element.ViewIndex);
                        ContentChangedEventArgs args = new ContentChangedEventArgs();
                        args.Document        = element.OwnerDocument;
                        args.Element         = element;
                        args.LoadingDocument = false;
                        element.Parent.RaiseBubbleOnContentChanged(args);
                    }
                }
                else
                {
                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                }
                this.Close();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 设置容器元素的可见性
        /// </summary>
        /// <param name="visible">新的可见性</param>
        /// <param name="fastMode">是否启用快速模式,当使用快速模式时,
        /// 只更新DOM结构,不更新用户界面视图</param>
        /// <returns>操作是否成功</returns>
        public virtual bool EditorSetVisible(bool visible, bool fastMode)
        {
            bool result     = false;
            bool oldVisible = this.Visible;

            if (oldVisible != visible)
            {
                this.Visible = visible;
                bool visible2 = this.Visible;
                if (visible2 == visible)
                {
                    this.InvalidateView();
                    // 成功的修改了元素的可见性
                    if (visible)
                    {
                        this.OwnerDocument.HighlightManager.InvalidateHighlightInfo(this);
                    }
                    else
                    {
                        this.OwnerDocument.HighlightManager.Remove(this);
                    }
                    result = true;
                    DomElement        fc      = this.FirstContentElement;
                    DomElement        lc      = this.LastContentElement;
                    DomContentElement content = this.ContentElement;
                    int        startIndex     = 0;
                    DomElement preElement     = content.PrivateContent.GetPreElement(fc);
                    if (oldVisible)
                    {
                        startIndex = content.PrivateContent.IndexOf(fc);
                    }
                    this.UpdateContentVersion();
                    DomDocumentContentElement dce = this.DocumentContentElement;
                    DomElement currentElementBack = dce.CurrentElement;
                    content.UpdateContentElements(true);
                    if (oldVisible == false)
                    {
                        startIndex = content.PrivateContent.IndexOf(fc);
                    }
                    else
                    {
                        if (preElement != null && content.PrivateContent.Contains(preElement))
                        {
                            startIndex = content.PrivateContent.IndexOf(preElement);
                        }
                    }
                    content.RefreshPrivateContent(startIndex, -1, fastMode);
                    if (fastMode == false)
                    {
                        if (currentElementBack != null)
                        {
                            int index = dce.Content.IndexOf(currentElementBack);
                            if (index >= 0)
                            {
                            }
                        }
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 重复操作
 /// </summary>
 public override void Redo(DCSoft.CSharpWriter.Undo.XUndoEventArgs args)
 {
     if (myContainer != null)
     {
         DomContentElement ce = myContainer.ContentElement;
         //args.Parameters["ContentElement"] = ce;
         if (_OldElements != null && _NewElements == null)
         {
             // 光删除,重复操作就是重复删除数据
             int index = ce.PrivateContent.IndexOf(_OldElements.FirstContentElement);
             foreach (DomElement element in _OldElements)
             {
                 DomElement e2 = GetContentElement(element);
                 if (e2 != null)
                 {
                     if (e2.OwnerLine != null)
                     {
                         e2.OwnerLine.InvalidateState = true;
                     }
                 }
                 element.OwnerLine = null;
                 myContainer.Elements.Remove(element);
                 myContainer.OwnerDocument.HighlightManager.Remove(element);
             }
             myContainer.UpdateContentVersion();
             this.OwnerList.AddContentRefreshInfo(ce, index);
         }
         else if (_OldElements == null && _NewElements != null)
         {
             // 光插入,重复操作就是重复插入数据
             myContainer.Elements.InsertRange(intIndex, _NewElements);
             foreach (DomElement element in _NewElements)
             {
                 DomElement e2 = GetContentElement(element);
                 if (e2 != null && e2.OwnerLine != null)
                 {
                     e2.OwnerLine.InvalidateState = true;
                 }
                 element.OwnerLine = null;
             }//foreach
             myContainer.UpdateContentVersion();
             AddRefreshElements(
                 _NewElements.FirstContentElement,
                 _NewElements.LastContentElement);
         }
         else if (_OldElements != null && _NewElements != null)
         {
             // 替换,撤销操作就是删除旧数据并插入新数据
             int index = ce.PrivateContent.IndexOf(_OldElements.FirstContentElement);
             foreach (DomElement element in _OldElements)
             {
                 DomElement e2 = GetContentElement(element);
                 if (e2 != null && e2.OwnerLine != null)
                 {
                     e2.OwnerLine.InvalidateState = true;
                 }
                 element.OwnerLine = null;
                 myContainer.Elements.Remove(element);
                 myContainer.OwnerDocument.HighlightManager.Remove(element);
             }
             this.OwnerList.AddContentRefreshInfo(ce, index);
             myContainer.Elements.InsertRange(intIndex, _NewElements);
             foreach (DomElement element in _NewElements)
             {
                 if (element.OwnerLine != null)
                 {
                     element.OwnerLine.InvalidateState = true;
                     element.OwnerLine = null;
                 }
             }
             myContainer.UpdateContentVersion();
             ce.UpdateContentElements(true);
             AddRefreshElements(
                 _NewElements.FirstContentElement,
                 _NewElements.LastContentElement);
         }
         if (this.OwnerList.ContentChangedContainer.Contains(myContainer) == false)
         {
             this.OwnerList.ContentChangedContainer.Add(myContainer);
         }
     }
 }
Ejemplo n.º 5
0
        private void Execute(XUndoEventArgs args, bool undo)
        {
            myDocument.UndoList.RefreshElements.Clear();
            myDocument.UndoList._ContentRefreshInfos.Clear();
            myDocument.UndoList.ContentChangedContainer.Clear();
            myDocument.UndoList.NeedRefreshDocument = false;
            if (undo)
            {
                base.Undo(args);
            }
            else
            {
                base.Redo(args);
            }
            if (myDocument.UndoList.NeedRefreshDocument)
            {
                // 需要刷新整个文档。
                if (this.Document.EditorControl != null)
                {
                    this.Document.EditorControl.RefreshDocument();
                    return;
                }
            }

            // 指定了要刷新的元素
            DomElementList RedrawElements = new DomElementList();

            Dictionary <DomContentElement, int> startIndexs
                = new Dictionary <DomContentElement, int>();

            if (this.Document.UndoList._ContentRefreshInfos.Count > 0)
            {
                // 直接获得要刷新排版的位置信息
                DomDocumentContentElement dce2 = null;
                foreach (DomContentElement ce in this.Document.UndoList._ContentRefreshInfos.Keys)
                {
                    dce2 = ce.DocumentContentElement;
                    ce.UpdateContentElements(false);
                    startIndexs[ce] = this.Document.UndoList._ContentRefreshInfos[ce];
                }
                dce2.UpdateContentElements(false);
            }//if

            if (this.Document.UndoList.RefreshElements.Count > 0)
            {
                // 获得要刷新排版的位置信息
                foreach (DomElement element in this.Document.UndoList.RefreshElements)
                {
                    DomContentElement ce = element.ContentElement;
                    if (startIndexs.ContainsKey(ce))
                    {
                        int index = ce.PrivateContent.IndexOf(element);
                        if (index >= 0 && index < startIndexs[ce])
                        {
                            for (int iCount = startIndexs[ce]; iCount >= index; iCount--)
                            {
                                DomElement element2 = ce.PrivateContent[iCount];
                                if (element2.OwnerLine != null)
                                {
                                    // 声明文本行无效
                                    element2.OwnerLine.InvalidateState = true;
                                }
                            }
                            startIndexs[ce] = index;
                        }
                    }
                    else
                    {
                        ce.UpdateContentElements(true);
                        int index = ce.PrivateContent.IndexOf(element.FirstContentElement);
                        if (index >= 0)
                        {
                            startIndexs[ce] = index;
                        }
                    }
                }//foreach

                using (System.Drawing.Graphics g = this.Document.CreateGraphics())
                {
                    foreach (DomElement element in this.Document.UndoList.RefreshElements)
                    {
                        DomContentElement ce = element.ContentElement;
                        int index2           = ce.PrivateContent.IndexOf(element.FirstContentElement);
                        if (index2 >= 0)
                        {
                            //element.SizeInvalid = true;
                            if (element.SizeInvalid || element.ViewInvalid)
                            {
                                RedrawElements.Add(element);
                            }
                            if (element.SizeInvalid)
                            {
                                this.Document.Render.RefreshSize(element, g);
                            }
                            //if (StartIndex == int.MinValue || StartIndex > index2)
                            //{
                            //    StartIndex = index2;
                            //}
                            //if (EndIndex == -1 || EndIndex < index2)
                            //{
                            //    EndIndex = index2;
                            //}
                        } //if
                    }     //foreach
                }         //using
            }             //if

            DomDocumentContentElement dce = this.Document.Body;

            foreach (DomContentElement ce in startIndexs.Keys)
            {
                dce = ce.DocumentContentElement;
                //ce.UpdateContentElements();
                int index = startIndexs[ce];
                if (index > 0)
                {
                    //index--;
                }
                ce.RefreshPrivateContent(index, -1, true);
            }//foreach
            if (this.Document.PageRefreshed == false)
            {
                this.Document.RefreshPages();
                if (this.Document.EditorControl != null)
                {
                    this.Document.EditorControl.UpdatePages();
                    this.Document.EditorControl.Invalidate();
                }
            }
            dce.Content.AutoClearSelection = true;
            dce.Content.LineEndFlag        = false;
            if (undo)
            {
                dce.SetSelection(intOldSelectionStart, 0);
            }
            else
            {
                dce.SetSelection(intNewSelectionStart, 0);
            }
            //myDocument.Content.MoveSelectStart( intOldSelectionStart );
            foreach (DomElement element in RedrawElements)
            {
                element.ViewInvalid = true;
                element.InvalidateView();
            }
            if (this.Document.UndoList.ContentChangedContainer.Count > 0)
            {
                // 触发文档内容修改事件
                foreach (DomContainerElement container in this.Document.UndoList.ContentChangedContainer)
                {
                    // 触发文档事件
                    ContentChangedEventArgs args2 = new ContentChangedEventArgs();
                    args2.UndoRedoCause = true;
                    args2.Document      = this.Document;
                    args2.Element       = container;
                    container.RaiseBubbleOnContentChanged(args2);
                }
                this.Document.HighlightManager.UpdateHighlightInfos();
                this.Document.OnDocumentContentChanged();
            }
            if (this.Document.EditorControl != null)
            {
                this.Document.EditorControl.UpdateTextCaret();
                this.Document.EditorControl.Update();
            }
        }