/// <summary> /// The form 1_ load. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void Form1Load(object sender, EventArgs e) { var myDoc = Document.CreateDummyDocument; this.myCompany = new Company(myDoc) { Name = "Data Communication", Code = "ABC", Id = 123 }; this.myDocumentController = new DocumentControler(); this.dataGridView1.DataSource = this.myCompany.GetSetDocuments; }
/// <summary> /// The enter button_ click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void EnterButtonClick(object sender, EventArgs e) { if (!string.IsNullOrEmpty(this.nameTextBox.Text)) { lastId++; var doc = DocumentControler.CreateNewDocument(this.nameTextBox.Text, lastId); doc.MyCompany = this.myCompany; this.dataGridView1.DataSource = this.myDocumentController.AddNewDocumentToList(this.myCompany.GetSetDocuments, doc); this.nameTextBox.Visible = false; this.enterButton.Visible = false; this.nameTextBox.Text = string.Empty; } else { MessageBox.Show(Resources.Form1_enterButton_Click_Give_a_valid_name); } }
/// <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); }
/// <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); }