Beispiel #1
0
        /// <summary>
        /// 计算该文本行在文档中的绝对行号
        /// </summary>
        public int CalcuteRealIndex()
        {
            int             intCount  = Index;
            ZYTextContainer myElement = Container;

            while (myElement != null && myElement.OwnerLine != null)
            {
                intCount += (myElement.OwnerLine.Index + myElement.LineSpan - 1);
                myElement = myElement.Parent;
            }
            return(intCount);
        }
Beispiel #2
0
        /// <summary>
        /// 重载此方法,主要是为了做padding位置的调整.
        /// 其它的东西和Contontainer中的一致
        /// </summary>
        public override void UpdateBounds()
        {
            int iLineTop = this.paddingTop; //上间距

            System.Drawing.Rectangle NewBounds = System.Drawing.Rectangle.Empty;

            foreach (ZYTextLine myLine in myLines)
            {
                myLine.Top      = iLineTop;
                myLine.RealTop  = this.RealTop + iLineTop;
                myLine.RealLeft = this.RealLeft + this.paddingLeft; //左间距
                if (myLine.LastElement != null && myLine.LastElement.isNewParagraph())
                {
                    myLine.LineSpacing = myOwnerDocument.Info.ParagraphSpacing;
                }
                else
                {
                    myLine.LineSpacing = myOwnerDocument.Info.LineSpacing;
                }

                iLineTop += myLine.FullHeight;

                foreach (ZYTextElement myElement in myLine.Elements)
                {
                    NewBounds = new System.Drawing.Rectangle
                                    (myElement.RealLeft,
                                    myElement.RealTop,
                                    myElement.Width + myElement.WidthFix,
                                    myElement.Height);

                    if (NewBounds.Equals(myElement.Bounds) == false)
                    {
                        if (myOwnerDocument.OwnerControl != null && !(myElement is ZYTextContainer))
                        {
                            if (myElement.Bounds.IsEmpty == false)
                            {
                                myOwnerDocument.OwnerControl.AddInvalidateRect(myElement.Bounds);
                            }
                            myOwnerDocument.OwnerControl.AddInvalidateRect(NewBounds);
                        }
                        myElement.myBounds = NewBounds;
                    }
                    if (myElement is ZYTextContainer)
                    {
                        ZYTextContainer c = (ZYTextContainer)myElement;
                        c.UpdateBounds();
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// 已重载:执行撤销操作
        /// </summary>
        /// <returns></returns>
        public override bool Undo()
        {
            ZYTextElement NewStart           = null;
            int           NewIndex           = -1;
            bool          bolRefreshElements = false;

            if (myUndoSteps.Count > 0)
            {
                for (int iCount = myUndoSteps.Count - 1; iCount >= 0; iCount--)
                {
                    UndoStep myStep = (UndoStep)myUndoSteps[iCount];

                    switch (myStep.Style)
                    {
                    case 0:
                        Container          = myStep.Element.Parent;
                        bolRefreshElements = true;
                        NewIndex           = myStep.Element.Index;
                        Container.ChildElements.Remove(myStep.Element);
                        break;

                    case 1:
                        bolRefreshElements = true;
                        foreach (ZYTextElement e in myStep.Elements)
                        {
                            Container = e.Parent;
                            NewIndex  = e.Index;
                            Container.ChildElements.Remove(e);
                        }
                        break;

                    case 2:
                        Container          = myStep.Element.Parent;
                        bolRefreshElements = true;
                        NewIndex           = myStep.Element.Index;
                        Container.ChildElements.Remove(myStep.Element);
                        break;

                    case 3:
                        Container          = myStep.Element.Parent;
                        bolRefreshElements = true;
                        //先从此处控制,索引小于0的不进行操作edit by ywk 2013年3月11日17:31:02
                        if (myStep.index >= 0)
                        {
                            Container.ChildElements.Insert(myStep.index, myStep.Element);
                            NewStart = myStep.Element;
                        }
                        //Container.ChildElements.Insert(myStep.index, myStep.Element);
                        //NewStart = myStep.Element;
                        break;

                    case 4:

                        myStep.Attribute.SetValue(myStep.OldValue);
                        myStep.Element.UpdateAttrubute();
                        myStep.Element.RefreshSize();
                        NewStart = myStep.Element;
                        break;

                    case 5:

                        bolRefreshElements = true;
                        foreach (ZYTextElement e in myStep.Elements)
                        {
                            Container = e.Parent;
                            NewIndex  = e.Index;
                            Container.ChildElements.Remove(e);
                        }
                        break;

                    case 6:
                        Container          = (myStep.Elements[0] as ZYTextElement).Parent;
                        bolRefreshElements = true;
                        //索引需大于等于0才进入  add by ywk 2013年4月2日16:16:48
                        if (myStep.index >= 0)
                        {
                            Container.ChildElements.InsertRange(myStep.index, myStep.Elements);
                            NewIndex = myStep.index;
                        }
                        break;
                    }
                }
                if (bolRefreshElements)
                {
                    myOwnerDocument.RefreshElements();
                }
                myOwnerDocument.RefreshLine();
                myOwnerDocument.UpdateView();

                #region  以前是被注释的,现在放出来
                myOwnerDocument.Content.SelectLength = 0;
                if (NewStart != null)
                {
                    myOwnerDocument.Content.CurrentElement = NewStart;
                }
                else if (NewIndex >= 0)
                {
                    myOwnerDocument.Content.MoveSelectStart(NewIndex);
                }
                #endregion



                return(true);
            }
            return(false);
        }
Beispiel #4
0
        /// <summary>
        /// 已重载:执行重复操作
        /// </summary>
        /// <returns></returns>
        public override bool Redo()
        {
            bool          bolRefreshElements = false;
            int           NewIndex           = -1;
            ZYTextElement NewStart           = null;

            if (myUndoSteps.Count > 0)
            {
                foreach (UndoStep myStep in myUndoSteps)
                {
                    switch (myStep.Style)
                    {
                    case 0:
                        Container = myStep.Element.Parent;

                        bolRefreshElements = true;
                        Container.ChildElements.Insert(myStep.index, myStep.Element);
                        myStep.Element.OwnerDocument = Container.OwnerDocument;
                        myStep.Element.Parent        = Container;
                        NewStart = myStep.Element;
                        break;

                    case 1:
                        Container          = (myStep.Elements[0] as ZYTextElement).Parent;
                        bolRefreshElements = true;
                        Container.ChildElements.InsertRange(myStep.index, myStep.Elements);
                        if (myStep.Elements.Count > 0)
                        {
                            NewStart = (ZYTextElement)myStep.Elements[0];
                        }
                        break;

                    case 5:
                        Container          = (myStep.Elements[0] as ZYTextElement).Parent;
                        bolRefreshElements = true;
                        Container.ChildElements.AddRange(myStep.Elements);
                        if (myStep.Elements.Count > 0)
                        {
                            NewStart = (ZYTextElement)myStep.Elements[0];
                        }
                        break;

                    case 6:
                        Container          = (myStep.Elements[0] as ZYTextElement).Parent;
                        bolRefreshElements = true;
                        NewIndex           = myStep.index;
                        Container.ChildElements.RemoveRange(myStep.index, myStep.Elements.Count);
                        break;

                    case 2:
                        Container          = myStep.Element.Parent;
                        bolRefreshElements = true;
                        Container.ChildElements.Add(myStep.Element);
                        NewStart = myStep.Element;
                        break;

                    case 3:
                        Container          = myStep.Element.Parent;
                        bolRefreshElements = true;
                        NewIndex           = myStep.index;
                        Container.ChildElements.Remove(myStep.Element);
                        break;

                    case 4:

                        myStep.Attribute.SetValue(myStep.NewValue);
                        myStep.Element.RefreshSize();
                        NewStart = myStep.Element;
                        myStep.Element.UpdateAttrubute();
                        break;
                    }
                }
                if (bolRefreshElements)
                {
                    OwnerDocument.RefreshElements();
                }
                OwnerDocument.RefreshLine();
                OwnerDocument.UpdateView();

                //这句以前是被注释掉的,现在也放出来
                myOwnerDocument.Content.SelectLength = 0;


                if (NewStart != null)
                {
                    myOwnerDocument.Content.CurrentElement = NewStart;
                }
                else if (NewIndex >= 0)
                {
                    myOwnerDocument.Content.MoveSelectStart(NewIndex);
                }
                return(true);
            }
            return(false);
        }