Пример #1
0
 public void Refresh(DomDocumentContentElement element, DomElement startElement, DomElement endElement)
 {
     _Document        = element.OwnerDocument;
     _Elements        = element.Content;
     _StartElement    = startElement;
     _EndElement      = endElement;
     _StateInvalidate = true;
     _ContentVersion++;
     if (_Document != null)
     {
         // 清空用户指定的样式
         //_Document._UserSpecifyStyle = null;
     }
 }
Пример #2
0
        /// <summary>
        /// 设置文本
        /// </summary>
        /// <param name="newText">新文本</param>
        /// <param name="flags">标记</param>
        /// <param name="disablePermissioin">禁止权限控制</param>
        /// <returns>操作是否修改了对象内容</returns>
        public bool SetEditorTextExt(string newText, DomAccessFlags flags, bool disablePermissioin, bool updateContent)
        {
            bool result = false;

            if (this.OwnerDocument != null)
            {
                string oldText = this.Text;
                if (oldText == null || oldText != newText)
                {
                    // 为了提高效率,只有出现不同的文本才进行文本替换操作
                    bool innerLogUndo = this.OwnerDocument.CanLogUndo;
                    if (innerLogUndo == false)
                    {
                        this.OwnerDocument.BeginLogUndo();
                    }
                    if (string.IsNullOrEmpty(newText))
                    {
                        // 直接设置空内容
                        ReplaceElementsArgs args = new ReplaceElementsArgs(
                            this,
                            0,
                            this.Elements.Count,
                            null,
                            true,
                            true,
                            true);
                        args.DisablePermission = disablePermissioin;
                        args.AccessFlags       = flags;
                        args.ChangeSelection   = false;
                        args.UpdateContent     = updateContent;
                        if (args.DisablePermission == false &&
                            this.OwnerDocument.Options.SecurityOptions.EnablePermission)
                        {
                            // 很多时候,本属性是为下拉列表文本输入域调用的,此时输入域前面的文本可能是被
                            // 当前用户输入的,后面的元素已经被逻辑删除了,此时应该应该是执行物理删除,
                            // 在此进行判断,修正删除区间。
                            for (int iCount = 0; iCount < this.Elements.Count; iCount++)
                            {
                                DomElement element = this.Elements[iCount];
                                if (element.Style.DeleterIndex >= 0)
                                {
                                    bool fix = true;
                                    for (int iCount2 = iCount; iCount2 < this.Elements.Count; iCount2++)
                                    {
                                        if (this.Elements[iCount2].Style.DeleterIndex < 0)
                                        {
                                            fix = false;
                                            break;
                                        }
                                    }
                                    if (fix)
                                    {
                                        args.DeleteLength = iCount;
                                    }
                                    break;
                                }
                            }//for
                        }
                        result = this.OwnerDocument.ReplaceElements(args) != 0;
                    }
                    else
                    {
                        // 设置文本内容
                        DomElementList list = this.OwnerDocument.CreateTextElements(newText, null, this.Style);
                        if (list != null && list.Count > 0)
                        {
                            ReplaceElementsArgs args = new ReplaceElementsArgs(
                                this,
                                0,
                                this.Elements.Count,
                                list,
                                true,
                                true,
                                true);
                            args.DisablePermission = disablePermissioin;
                            args.AccessFlags       = flags;
                            args.ChangeSelection   = false;
                            args.UpdateContent     = updateContent;
                            if (args.DisablePermission == false &&
                                this.OwnerDocument.Options.SecurityOptions.EnablePermission)
                            {
                                // 很多时候,本属性是为下拉列表文本输入域调用的,此时输入域前面的文本可能是被
                                // 当前用户输入的,后面的元素已经被逻辑删除了,此时应该应该是执行物理删除,
                                // 在此进行判断,修正删除区间。
                                for (int iCount = 0; iCount < this.Elements.Count; iCount++)
                                {
                                    DomElement element = this.Elements[iCount];
                                    if (element.Style.DeleterIndex >= 0)
                                    {
                                        bool fix = true;
                                        for (int iCount2 = iCount; iCount2 < this.Elements.Count; iCount2++)
                                        {
                                            if (this.Elements[iCount2].Style.DeleterIndex < 0)
                                            {
                                                fix = false;
                                                break;
                                            }
                                        }
                                        if (fix)
                                        {
                                            args.DeleteLength = iCount;
                                        }
                                        break;
                                    }
                                }//for
                            }
                            result = this.OwnerDocument.ReplaceElements(args) != 0;
                        }
                    }
                    if (innerLogUndo == false)
                    {
                        if (result)
                        {
                            this.OwnerDocument.EndLogUndo();
                        }
                        else
                        {
                            this.OwnerDocument.CancelLogUndo();
                        }
                    }
                    if (result)
                    {
                        this.OwnerDocument.OnDocumentContentChanged();
                        this.OwnerDocument.OnSelectionChanged();
                    }
                }
            }
            else
            {
                DomElementList list = this.SetInnerTextFast(newText);
                result = list != null && list.Count > 0;
            }
            return(result);
        }
Пример #3
0
 public DomRange(DomDocumentContentElement element, DomElement startElement, DomElement endElement)
 {
     Refresh(element, startElement, endElement);
 }
Пример #4
0
        /// <summary>
        /// 刷新状态
        /// </summary>
        /// <returns>操作是否成功</returns>
        public bool RefreshState()
        {
            if (this.Count == 0)
            {
                return(false);
            }
            DocumentControler controler = null;

            foreach (DomElement element in this)
            {
                if (element.OwnerDocument != null)
                {
                    controler = element.OwnerDocument.DocumentControler;
                    break;
                }
            }
            //XTextParagraphFlagElement pe = this.LastElement as XTextParagraphFlagElement ;
            //if( pe != null )
            //{
            //    pe.RefreshSize2( this.SafeGet( this.Count - 2 ));
            //}
            DomLineBreakElement lb = this.LastElement as DomLineBreakElement;

            if (lb != null)
            {
                lb.RefreshSize2(this.SafeGet(this.Count - 2));
            }


//			if( this.Count == 1 )
//			{
//				XTextElement element = this[ 0 ];
//				this.intHeight = element.Height + LineHeighFix + this.LineSpacing ;
//				element.Left = this.intMargin ;
//				element.Top = 0 ;
//				return true ;
//			}
            this._ContentHeight = -1;
            float contentWidth = 0;
            float lineHeight   = 10;

            foreach (DomElement element in this)
            {
                contentWidth     = contentWidth + this.Spacing + element.Width;
                element.WidthFix = 0;
                float eh = element.Height;
                //if (element is XTextCharElement)
                //{
                //    XTextCharElement chr = (XTextCharElement)element;
                //    eh = Math.Max(eh, chr._FontHeight);
                //}
                if (eh > lineHeight)
                {
                    lineHeight = eh;
                }
                element.OwnerLine = this;
            }//foreach
            contentWidth -= this.Spacing;

            this.Height = ( float )Math.Ceiling(lineHeight + LineHeighFix);

//			if( EOF != null )
//				EOF.Height = this.intHeight ;


            bool CanFix = true;

            if (this.Count == 1)
            {
                CanFix = false;
            }
            else
            {
                if (this.HasLineEndElement)// this.OwnerDocument.IsNewLine( this.LastElement ) || this.LastElement is XTextEOF )
                {
                    CanFix = false;
                }
                else if (this.OwnerContentElement.PrivateLines.LastLine == this)
                {
                    CanFix = false;
                }
            }
            DocumentContentAlignment align = this.Align;

            // 元素空白平均修正量
            float fix = 0;
            // 总空白量
            float Blank = this.Width - this.PaddingLeft - contentWidth;

            if (Blank < 0)
            {
                return(false);
            }
            if (CanFix)
            {
                // 计算由于元素分组而损失的空白区域个数
                // 文档中连续的英文和数字字符之间没有修正空白,制表符和书签也拒绝修正空白
                // 由于存在拒绝修正空白,导致空白分摊的元素减少,此处就修正这种空白分摊元素
                // 减少而带来的影响
                int GroupFix = 0;
                for (int iCount = 0; iCount < this.Count; iCount++)
                {
                    DomCharElement c = this[iCount] as DomCharElement;
                    if (c != null)
                    {
                        if (c.CharValue == '\t')
                        {
                            GroupFix++;
                        }
                        else if (iCount < this.Count - 1)
                        {
                            if (controler.IsEnglishLetterOrDigit(c.CharValue))
                            {
                                DomCharElement c2 = this[iCount + 1] as DomCharElement;
                                if (c2 != null &&
                                    controler.IsEnglishLetterOrDigit(c2.CharValue))
                                {
                                    GroupFix++;
                                }
                            }
                        }
                    }
                }
                if (GroupFix > this.Count - 2)
                {
                    GroupFix = 0;
                }
                if (this.Count > 1)
                {
                    fix = (int)Math.Ceiling(Blank / (this.Count - 1.0 - GroupFix));
                }
                if (fix < 0)
                {
                    fix = 0;
                }

                align = DocumentContentAlignment.Justify;
            }
            else
            {
                fix = 0;
            }
            float leftCount = 0;

            if (align == DocumentContentAlignment.Left)
            {
                leftCount = this.PaddingLeft;
            }
            else if (align == DocumentContentAlignment.Center)
            {
                leftCount = this.PaddingLeft + (this.Width - this.PaddingLeft - contentWidth) / 2;
            }
            else if (align == DocumentContentAlignment.Right)
            {
                leftCount = this.PaddingLeft + (this.Width - this.PaddingLeft - contentWidth);
            }
            else
            {
                leftCount = this.PaddingLeft;
            }
            //foreach( XTextElement element in this )
            for (int iCount = 0; iCount < this.Count; iCount++)
            {
                DomElement element = this[iCount];
                element.Left = leftCount;
                float ctf = ContentTopFix;
                //if (this.AdditionHeight < 0)
                //{
                //    ctf = ctf + this.AdditionHeight;
                //}
                switch (this.VerticalAlign)
                {
                case VerticalAlignStyle.Top:
                    element.Top = ContentTopFix;
                    break;

                case VerticalAlignStyle.Middle:
                    element.Top = ContentTopFix + (lineHeight - element.Height) / 2.0f;
                    break;

                case  VerticalAlignStyle.Bottom:
                    element.Top = ctf + lineHeight - element.Height;
                    break;

                case VerticalAlignStyle.Justify:
                    element.Top = ContentTopFix + (lineHeight - element.Height) / 2.0f;
                    break;

                default:
                    element.Top = ctf + lineHeight - element.Height;
                    break;
                }//switch

                //bool IsTab = false ;
                bool FixFlag = true;
                // TAB制表符不接收修正空隙
                if (element is DomCharElement)
                {
                    DomCharElement c = ( DomCharElement )element;
                    if (c.CharValue == '\t')
                    {
                        FixFlag = false;
                    }
                    else if (iCount < this.Count - 1)
                    {
                        if (controler.IsEnglishLetterOrDigit(c.CharValue))
                        {
                            DomCharElement c2 = this[iCount + 1] as DomCharElement;
                            if (c2 != null &&
                                controler.IsEnglishLetterOrDigit(c2.CharValue))
                            {
                                FixFlag = false;
                            }
                        }
                    }
                }

//				// 出现拒绝修正情况,重新计算平均修正空隙
//				if( CanFix && FixFlag == false )
//				{
//					if( iCount < this.Count - 2 )
//					{
//						Blank = ( this.intWidth - LeftCount - element.Width ) ;
//						for( int iCount2 = iCount + 1 ; iCount2 < this.Count ; iCount2 ++ )
//						{
//							Blank -= this[ iCount ].Width ;
//						}
//						if( Blank > 0 )
//						{
//							fix = Blank / ( this.Count - iCount - 1.0 );
//						}
//						else
//							fix = 0 ;
//					}
//				}
//				else if( element is XTextNull )
//				{
//					// 若元素是没有实际意义的占位符合则不接收修正空隙
//					FixFlag = false;
//				}
                if (CanFix && FixFlag)
                {
                    if (Blank < fix)
                    {
                        fix = Blank;
                    }
                    element.WidthFix = fix + _Spacing;
                    Blank           -= fix;
                    if (Blank <= 0)
                    {
                        fix   = 0;
                        Blank = 0;
                    }
                }
                else
                {
                    element.WidthFix = _Spacing;
                }
                leftCount = leftCount + element.Width + element.WidthFix;
            }
            //this.Height += this.LineSpacing  ;
            return(true);
        }
Пример #5
0
        //private ParagraphListStyle _L

        //private float _LeftCount = 0 ;
        internal bool AddElement(DomElement element)
        {
            if (this.Count == 0)
            {
                //intLeftCount = 0 ;
                this.List.Add(element);

                {
                    DomParagraphFlagElement p = element.OwnerParagraphEOF;
                    if (p != null)
                    {
                        DocumentContentStyle rs = p.RuntimeStyle;
                        if (element == p.ParagraphFirstContentElement)
                        {
                            if (rs.NumberedList || rs.BulletedList)
                            {
                                this.PaddingLeft = rs.LeftIndent;
                                if (rs.NumberedList)
                                {
                                    this.ParagraphListStyle = ParagraphListStyle.NumberedList;
                                }
                                else if (rs.BulletedList)
                                {
                                    this.ParagraphListStyle = ParagraphListStyle.BulletedList;
                                }
                                this.ParagraphStyleIndex = p.ListIndex;
                            }
                            this.PaddingLeft = rs.LeftIndent + rs.FirstLineIndent;
                        }
                        else
                        {
                            this.PaddingLeft = rs.LeftIndent;
                        }
                    }
                    else
                    {
                        this.PaddingLeft = 0;
                    }
                }
                element.Left = this.PaddingLeft;
                if (this.ParagraphListStyle == Dom.ParagraphListStyle.BulletedList ||
                    this.ParagraphListStyle == Dom.ParagraphListStyle.NumberedList)
                {
                    DomParagraphListItemElement item = new DomParagraphListItemElement();
                    DocumentContentStyle        rs   = element.RuntimeStyle;
                    float size = rs.Font.GetHeight(element.OwnerDocument.DocumentGraphicsUnit);
                    item.Width  = size;
                    item.Height = size;
                    if (this.ParagraphListStyle == Dom.ParagraphListStyle.NumberedList)
                    {
                        item.Width = item.Width * 2;
                    }
                    item.OwnerDocument = element.OwnerDocument;
                    item.StyleIndex    = element.StyleIndex;
                    this.Insert(0, item);
                    // float size = rs.Font.GetHeight(
                }
                //intLeftCount = intLeftCount + element.Width + this.intSpacing ;
                //element.OwnerLine = this ;
                return(true);
            }
            float WidthCount = this.ContentWidth;

            if ((element is DomParagraphFlagElement) == false)
            {
                // 在排版中段落元素不计宽度,可以无条件的添加到文档行中。
                if (WidthCount + element.Width + this._Spacing > this.Width - this.PaddingLeft)
                {
                    return(false);
                }
            }
            DomElement PreElement = ( DomElement )this.List[this.Count - 1];

            element.Left = PreElement.Left + PreElement.Width + this._Spacing;
            this.List.Add(element);
            //intLeftCount = intLeftCount + element.Width + this.intSpacing ;
            //element.OwnerLine = this ;
            return(true);
        }
Пример #6
0
        /// <summary>
        /// 绘制文档元素背景
        /// </summary>
        /// <param name="element">文档元素对象</param>
        /// <param name="args">参数</param>
        /// <param name="bounds">要绘制背景的区域</param>
        public virtual void DrawBackground(
            DomElement element,
            DocumentPaintEventArgs args,
            RectangleF bounds)
        {
            if (bounds.IsEmpty)
            {
                // 不绘制图形
                return;
            }

            DocumentContentStyle rs = null;

            if (element.Parent != null)
            {
                rs = element.Parent.GetContentBackgroundStyle(element);
            }
            if (rs == null)
            {
                rs = element.RuntimeStyle;
            }
            System.Drawing.Color c = rs.BackgroundColor;
            if (c.A != 0)
            {
                System.Drawing.SolidBrush b = GraphicsObjectBuffer.GetSolidBrush(c);
                bounds = System.Drawing.RectangleF.Intersect(bounds, args.ClipRectangleF);
                if (!bounds.IsEmpty)
                {
                    args.Graphics.FillRectangle(b, bounds);
                    return;
                }
            }

            HighlightInfo highlight = null;

            if (args.ActiveMode && args.RenderStyle == DocumentRenderStyle.Paint)
            {
                highlight = this.Document.HighlightManager[element];
            }
            if (highlight != null)
            {
                if (args.RenderStyle == DocumentRenderStyle.Print &&
                    highlight.ActiveStyle != HighlightActiveStyle.AllTime)
                {
                    // 当进行打印时不显示不能打印的高亮度色
                    return;
                }
                // 如果需要高亮度显示
                // 则绘制高亮度背景
                bounds = RectangleF.Intersect(bounds, args.ClipRectangleF);
                if (highlight.BackColor.A != 0)
                {
                    if (!bounds.IsEmpty)
                    {
                        args.Graphics.FillRectangle(
                            GraphicsObjectBuffer.GetSolidBrush(highlight.BackColor),
                            bounds);
                    }
                }
            }
        }
Пример #7
0
        /// <summary>
        /// 执行查找
        /// </summary>
        /// <param name="args">参数</param>
        /// <param name="setSelection">找到后是否设置文档选择状态</param>
        /// <returns>找到的元素在文档中的序号</returns>
        public int Search(SearchReplaceCommandArgs args, bool setSelection, int startIndex)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }
            if (string.IsNullOrEmpty(args.SearchString))
            {
                return(-1);
            }
            DomContent content            = this.Content;
            int        searchStringLength = args.SearchString.Length;
            int        newStartIndex      = -1;

            if (args.Backward)
            {
                // 向后查找
                if (startIndex < 0)
                {
                    startIndex = content.Selection.AbsEndIndex;
                }
                int contentLength = content.Count;
                for (int iCount = startIndex; iCount < contentLength; iCount++)
                {
                    DomElement element = content[iCount];
                    if (element is DomCharElement)
                    {
                        char c = ((DomCharElement)element).CharValue;
                        if (EqualsChar(c, args.SearchString[0], args.IgnoreCase))
                        {
                            if (searchStringLength == 1)
                            {
                                newStartIndex = iCount;
                                break;
                            }
                            else if (contentLength - iCount >= searchStringLength)
                            {
                                for (int iCount2 = 1; iCount2 < searchStringLength; iCount2++)
                                {
                                    DomElement element2 = content[iCount + iCount2];
                                    if (element2 is DomCharElement)
                                    {
                                        if (EqualsChar(
                                                ((DomCharElement)element2).CharValue,
                                                args.SearchString[iCount2],
                                                args.IgnoreCase))
                                        {
                                            if (iCount2 == searchStringLength - 1)
                                            {
                                                newStartIndex = iCount;
                                                goto EndSetNewStartIndex;
                                            }
                                        }
                                        else
                                        {
                                            // 判断失败
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        // 不是字符元素,判断失败
                                        break;
                                    }
                                } //for
                            }     //else if
                        }
                    }             //if
                }                 //for
            }                     //if
            else
            {
                // 向前查找
                if (startIndex < 0)
                {
                    startIndex = content.Selection.AbsStartIndex;
                }
                char lastChar = args.SearchString[args.SearchString.Length - 1];
                for (int iCount = startIndex; iCount >= 0; iCount--)
                {
                    DomElement element = content[iCount];
                    if (element is DomCharElement)
                    {
                        char c = ((DomCharElement)element).CharValue;
                        if (EqualsChar(c, lastChar, args.IgnoreCase))
                        {
                            if (searchStringLength == 1)
                            {
                                newStartIndex = iCount;
                                break;
                            }
                            else if (iCount >= searchStringLength - 1)
                            {
                                for (int iCount2 = searchStringLength - 2; iCount2 >= 0; iCount2--)
                                {
                                    DomElement element2 = content[iCount - searchStringLength + iCount2 + 1];
                                    if (element2 is DomCharElement)
                                    {
                                        if (EqualsChar(
                                                ((DomCharElement)element2).CharValue,
                                                args.SearchString[iCount2],
                                                args.IgnoreCase))
                                        {
                                            if (iCount2 == 0)
                                            {
                                                newStartIndex = iCount - searchStringLength + 1;
                                                goto EndSetNewStartIndex;
                                            }
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }//for
            }
            EndSetNewStartIndex :;
            if (setSelection)
            {
                if (newStartIndex >= 0)
                {
                    content.SetSelection(newStartIndex, args.SearchString.Length);
                }
            }
            return(newStartIndex);
        }
 /// <summary>
 /// 输出一个元素
 /// </summary>
 /// <param name="element">元素对象</param>
 public virtual void WriteElement(DomElement element)
 {
 }
Пример #9
0
        /// <summary>
        /// 复制对象
        /// </summary>
        /// <param name="Deeply">是否深入复制子元素</param>
        /// <returns>复制品</returns>
        public virtual DomElement Clone(bool Deeply)
        {
            DomElement element = ( DomElement )this.MemberwiseClone();

            return(element);
        }
Пример #10
0
 /// <summary>
 /// 初始化对象
 /// </summary>
 /// <param name="doc">文档对象</param>
 /// <param name="e">元素</param>
 /// <param name="link">链接目标</param>
 public LinkClickEventArgs(DomDocument doc, DomElement e, string link)
 {
     myDocument = doc;
     myElement  = e;
     strLink    = link;
 }
Пример #11
0
 public virtual bool IsVisible(DomElement element)
 {
     return(true);
 }
Пример #12
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);
        }
Пример #13
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);
        }
Пример #14
0
 /// <summary>
 /// 判断元素是否包含在区域中
 /// </summary>
 /// <param name="element">元素对象</param>
 /// <returns>是否包含在区域中</returns>
 public bool Contains(DomElement element)
 {
     {
         return(_ContentElements.Contains(element));
     }
 }
 /// <summary>
 /// 元素是否处于选择状态
 /// </summary>
 /// <param name="element">元素对象</param>
 /// <returns>是否选择</returns>
 public virtual bool IsSelected(DomElement element)
 {
     return(_Selection.Contains(element));
 }
Пример #16
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);
        }
        /// <summary>
        /// 更新文内容选择状态
        /// </summary>
        /// <param name="startIndex">选择区域的起始位置</param>
        /// <param name="length">选择区域的包含文档内容元素的个数</param>
        public bool SetSelection(int startIndex, int length)
        {
            int oldSelectionStart  = this.Selection.StartIndex;
            int oldSelectionLength = this.Selection.Length;

            // 修正旧的选择区域
            // 由于执行了某些操作改变了文档内容但没有更新选择区域,因此旧的选择区域可能超出文档范围,
            // 在此进行修正。
            this.Content.FixRange(ref oldSelectionStart, ref oldSelectionLength);

            if (this.Selection.NeedRefresh(startIndex, length))
            {
                // 触发文档对象的OnSelectionChanging事件
                SelectionChangingEventArgs args = new SelectionChangingEventArgs();
                args.Documnent          = this.OwnerDocument;
                args.OldSelectionIndex  = this.Selection.StartIndex;
                args.OldSelectionLength = this.Selection.Length;
                args.NewSelectionIndex  = startIndex;
                args.NewSelectionLength = length;
                this.OwnerDocument.OnSelectionChanging(args);
                if (args.Cancel)
                {
                    // 用户取消操作
                    return(false);
                }
                // 使用用户设置的新的选择区域配置
                startIndex = args.NewSelectionIndex;
                length     = args.NewSelectionLength;

                if (this.Selection.Refresh(startIndex, length))
                {
                    if (this.OwnerDocument.EditorControl != null)
                    {
                        //this.OwnerDocument.EditorControl.Invalidate();
                        this.OwnerDocument.EditorControl.UpdateTextCaret();
                    }
                    DomElement oldCurrentElement = this.Content[oldSelectionStart];
                    RaiseFocusEvent(
                        this.Content.SafeGet(oldSelectionStart),
                        this.Content.SafeGet(this.Selection.StartIndex));

                    //XTextElementList oldParents = WriterUtils.GetParentList(this.Content[oldSelectionStart]);
                    //XTextElementList newParents = WriterUtils.GetParentList(this.Content[this.Selection.StartIndex]);
                    //// 触发旧的容器元素的失去输入焦点事件
                    //foreach (XTextElement oldParent in oldParents)
                    //{
                    //    if (newParents.Contains(oldParent) == false)
                    //    {
                    //        ((XTextContainerElement)oldParent).OnLostFocus(this, EventArgs.Empty);

                    //        //DocumentEventArgs args2 = new DocumentEventArgs(
                    //        //    this.OwnerDocument,
                    //        //    oldParent,
                    //        //    DocumentEventStyles.LostFocus);
                    //        //oldParent.HandleDocumentEvent(args2);
                    //    }
                    //}
                    //// 触发新的容器元素的获得输入焦点事件
                    //foreach (XTextElement newParent in newParents)
                    //{
                    //    if (oldParents.Contains(newParent) == false)
                    //    {
                    //        ((XTextContainerElement)newParent).OnGotFocus(this, EventArgs.Empty);

                    //        //DocumentEventArgs args2 = new DocumentEventArgs(
                    //        //    this.OwnerDocument,
                    //        //    newParent,
                    //        //    DocumentEventStyles.GotFocus);
                    //        //newParent.HandleDocumentEvent(args2);
                    //    }
                    //}
                    // 触发文档对象的选择区域发生改变事件
                    this.OwnerDocument.OnSelectionChanged( );
                    return(true);
                }
            }
            return(false);
        }
Пример #18
0
        /// <summary>
        /// 绘制授权状态标记
        /// </summary>
        /// <param name="element">文档元素对象</param>
        /// <param name="args">参数</param>
        public virtual void DrawPermissionMark(DomElement element, DocumentPaintEventArgs args)
        {
            DocumentContentStyle style = element.Style;

            if (style.DeleterIndex >= 0)
            {
                DomContentLine line   = element.OwnerLine;
                RectangleF     bounds = new RectangleF(
                    element.AbsLeft,
                    line.AbsTop,
                    element.Width + element.WidthFix,
                    line.Height);
                int level = element.DeleterPermissionLevel;
                if (level >= 0)
                {
                    if (level == 0)
                    {
                        args.Graphics.DrawLine(
                            Pens.Blue,
                            bounds.Left,
                            bounds.Top + bounds.Height / 2,
                            bounds.Right,
                            bounds.Top + bounds.Height / 2);
                    }
                    else
                    {
                        float step = bounds.Height / (level + 1);
                        for (int iCount = 1; iCount <= level; iCount++)
                        {
                            args.Graphics.DrawLine(
                                Pens.Red,
                                bounds.Left,
                                bounds.Top + step * iCount,
                                bounds.Right,
                                bounds.Top + step * iCount);
                        }//for
                    }
                }
            }
            else if (style.CreatorIndex >= 0)
            {
                DomContentLine line   = element.OwnerLine;
                RectangleF     bounds = new RectangleF(
                    element.AbsLeft,
                    line.AbsTop,
                    element.Width + element.WidthFix,
                    line.Height);
                int level = element.CreatorPermessionLevel;
                if (level > 0)
                {
                    if (level == 1)
                    {
                        args.Graphics.DrawLine(Pens.Blue, bounds.Left, bounds.Bottom, bounds.Right, bounds.Bottom);
                    }
                    else
                    {
                        args.Graphics.DrawLine(Pens.Blue, bounds.Left, bounds.Bottom, bounds.Right, bounds.Bottom);
                        args.Graphics.DrawLine(Pens.Blue, bounds.Left, bounds.Bottom - 6, bounds.Right, bounds.Bottom - 6);
                    }
                }
            }
        }