// 粘贴插入_后插 private void menuItem_PasteInsert_InsertAfter(object sender, System.EventArgs e) { Debug.Assert(this.SelectedFieldIndices.Count == 1,"在'粘贴插入/后插'时,SelectedFieldIndices必须为1。"); int nIndex = this.FocusedFieldIndex; Debug.Assert(nIndex >=0 && nIndex < this.record.Fields.Count,"在'粘贴插入/后插'时,FocusFieldIndex越界。"); string strFieldsMarc = MarcEditor.ClipboardToText(); int nStartIndex = nIndex + 1; int nNewFieldsCount = 0; this.record.Fields.InsertInternal(nStartIndex, strFieldsMarc, out nNewFieldsCount); // 把焦点设为最后一项上 Debug.Assert(nStartIndex + nNewFieldsCount <= this.record.Fields.Count,"不可能的情况"); // 把新字段中的最后一个字段设为当前字段 this.SetActiveField(nStartIndex + nNewFieldsCount-1,3); InvalidateRect iRect = new InvalidateRect(); iRect.bAll = false; iRect.rect = this.GetItemBounds(nStartIndex, -1, BoundsPortion.FieldAndBottom); this.AfterDocumentChanged(ScrollBarMember.Both, iRect); }
private void Menu_Paste(System.Object sender, System.EventArgs e) { // Determine if there is any text in the Clipboard to paste into the text box. if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Text) == true) { // 把子字段符号换一下 string strText = DigitalPlatform.Marc.MarcEditor.ClipboardToText(); // 去掉回车换行符号 strText = strText.Replace("\r\n", "\r"); strText = strText.Replace("\r", "*"); strText = strText.Replace("\n", "*"); strText = strText.Replace("\t", "*"); Debug.Assert(this.MarcEditor.SelectedFieldIndices.Count == 1, "Menu_Paste(),MarcEditor.SelectedFieldIndices必须为1。"); string strFieldsMarc = strText; // 先找到有几个字段 strFieldsMarc = strFieldsMarc.Replace(Record.SUBFLD, Record.KERNEL_SUBFLD); List<string> fields = Record.GetFields(strFieldsMarc); if (fields == null || fields.Count == 0) return; // 粘贴内容 if (fields.Count == 1) { string strThisText = fields[0]; int nOldSelectionStart = this.SelectionStart; if (this.SelectedText == "") { this.Text = this.Text.Insert(this.SelectionStart, strThisText); } else { string strTempText = this.Text; strTempText = strTempText.Remove(nOldSelectionStart, this.SelectedText.Length); strTempText = strTempText.Insert(nOldSelectionStart, strThisText); this.Text = strTempText; } this.SelectionStart = nOldSelectionStart + strThisText.Length; // 字段名,确保3字符 if (this.MarcEditor.m_nFocusCol == 1) { if (this.Text.Length > 3) this.Text = this.Text.Substring(0, 3); } // 字段指示符,确保2字符 else if (this.MarcEditor.m_nFocusCol == 2) { if (this.Text.Length > 2) this.Text = this.Text.Substring(0, 2); } this.MarcEditor.Flush(); // 促使通知外界 } else if (fields.Count > 1) { List<string> addFields = new List<string>(); // 甩掉第一个 i = 1 for (int i = 0; i < fields.Count; i++) { addFields.Add(fields[i]); } int nIndex = this.MarcEditor.FocusedFieldIndex; Debug.Assert(nIndex >= 0 && nIndex < this.MarcEditor.Record.Fields.Count, "Menu_Paste(),FocusFieldIndex越界。"); int nStartIndex = nIndex + 1; int nNewFieldsCount = addFields.Count; this.MarcEditor.Record.Fields.InsertInternal(nStartIndex, addFields); // 把焦点设为最后一项上 Debug.Assert(nStartIndex + nNewFieldsCount <= this.MarcEditor.Record.Fields.Count, "不可能的情况"); // 把新字段中的最后一个字段设为当前字段 this.MarcEditor.SetActiveField(nStartIndex + nNewFieldsCount - 1, 3); InvalidateRect iRect = new InvalidateRect(); iRect.bAll = false; iRect.rect = this.MarcEditor.GetItemBounds(nIndex, //nStartIndex, -1, BoundsPortion.FieldAndBottom); this.MarcEditor.AfterDocumentChanged(ScrollBarMember.Both, iRect); } } }
// 粘贴插入_末尾 private void menuItem_PasteInsert_AppendChild(object sender, System.EventArgs e) { string strFieldsMarc = MarcEditor.ClipboardToText(); if (this.record.Fields.Count == 0) { string strError = ""; int nRet = this.record.SetMarc(strFieldsMarc, false, out strError); if (nRet == -1) MessageBox.Show(this,strError); return; } int nOldFocusFieldIndex = 0; if (this.SelectedFieldIndices.Count == 1) nOldFocusFieldIndex = this.FocusedFieldIndex; int nIndex = 0; if (this.record.Fields.Count > 0) nIndex = this.record.Fields.Count; int nNewFieldsCount = 0; this.record.Fields.InsertInternal(nIndex, strFieldsMarc, out nNewFieldsCount); if (this.record.Fields.Count > 0) this.SetActiveField(this.record.Fields.Count -1,3); // 失效范围 InvalidateRect iRect = new InvalidateRect(); iRect.bAll = false; iRect.rect = this.GetItemBounds(nOldFocusFieldIndex, -1, BoundsPortion.FieldAndBottom); this.AfterDocumentChanged(ScrollBarMember.Both, iRect); this.EnsureVisible(); // 2009/3/6 }
// 粘贴插入_前插 private void menuItem_PasteInsert_InsertBefore(object sender, System.EventArgs e) { Debug.Assert(this.SelectedFieldIndices.Count == 1,"在'粘贴插入/前插'时,SelectedFieldIndices必须为1。"); int nIndex = this.FocusedFieldIndex; Debug.Assert(nIndex >=0 && nIndex < this.record.Fields.Count,"在'粘贴插入/前插'时,FocusFieldIndex越界。"); string strFieldsMarc = MarcEditor.ClipboardToText(); // 这里要特别注意,把原来的焦点清空,以便在给新字段赋值时,不影响老字段 this.ClearSelectFieldIndices(); int nNewFieldsCount = 0; this.record.Fields.InsertInternal(nIndex, strFieldsMarc, out nNewFieldsCount); // 这里要特别注意,把焦点设上新插入字段的第一个上面 this.SetActiveField(nIndex,this.m_nFocusCol); // 失效范围 InvalidateRect iRect = new InvalidateRect(); iRect.bAll = false; iRect.rect = this.GetItemBounds(nIndex, -1, BoundsPortion.FieldAndBottom); this.AfterDocumentChanged(ScrollBarMember.Both, iRect); }
// 事项高度因素变化后,善后、兑现显示的函数 // nOldHeightParam 事项原来的像素现实高度。如果==-1,表示不用此参数, // 本函数自动把函数调用时刻的事项Height属性表示的高度当作旧高度, // 而把CalcHeight()计算得到的高度当作新高度。 internal void AfterItemHeightChanged(int nField, int nOldHeightParam) { Field field = this.record.Fields[nField]; // 得到旧高度 int nOldHeight = 0; if (nOldHeightParam == -1) { nOldHeight = field.TotalHeight; field.CalculateHeight(null, false); } else { nOldHeight = nOldHeightParam; } // 新高度 int nNewHeight = field.TotalHeight; // 新旧两高度的差距 int nDelta = nNewHeight - nOldHeight; if (nDelta == 0) return; Rectangle rect = new Rectangle(0,0,0,0); if (this.FocusedFieldIndex < this.record.Fields.Count-1) { // 得到本行以下的区域 // 得到从起始行开始的行数的rectangle // parameter: // nStartLine 起始行 // nCount 行数 // BoundsPortion 区域 如为line表示取整行,如为LineAndBottom表示取行与控件底部 // return: // Rectangle对象 // 注意: 本函数包括的Rectangle对象永远不包含控件左上右的空白 // 返回的Recatangle是实际的坐标 rect = GetItemBounds(this.FocusedFieldIndex + 1, this.record.Fields.Count - (this.FocusedFieldIndex + 1), BoundsPortion.FieldAndBottom); // nDelta修正为edit控件尺寸增大以前的下方bounds rect.Y = rect.Y - nDelta; this.Update(); // 不能直接用rect,因为ScrollWindowEx对rect为ref类型参数 RECT rect1 = new RECT(); rect1.left = rect.Left; rect1.top = rect.Top; rect1.right = rect.Right; rect1.bottom = rect.Bottom; API.ScrollWindowEx(this.Handle, 0, nDelta, ref rect1, IntPtr.Zero, // ref RECT lprcClip, 0, // int hrgnUpdate, IntPtr.Zero, // ref RECT lprcUpdate, API.SW_INVALIDATE); if (rect.Width == 0) { Debug.Assert(false,"width不可能为0"); } } InvalidateRect iRect = null; if (this.FocusedFieldIndex == this.record.Fields.Count-1) { iRect = new InvalidateRect(); iRect.bAll = false; iRect.rect = this.GetItemBounds(this.FocusedFieldIndex, 1, BoundsPortion.FieldAndBottom); } else { iRect = new InvalidateRect(); iRect.bAll = false; iRect.rect = this.GetItemBounds(this.FocusedFieldIndex, this.record.Fields.Count - this.FocusedFieldIndex, BoundsPortion.FieldAndBottom); /* iRect = new InvalidateRect(); iRect.bAll = false; // 只失效下方的部分 // 优化版本,利用rect iRect.rect = new Rectangle( rect.X, rect.Y - nNewHeight, rect.Width, nNewHeight); */ } // 相应的文档变化了 AfterDocumentChanged(ScrollBarMember.Vert, iRect); }
// // 摘要: // 引发 System.Windows.Forms.Control.MouseUp 事件。 // // 参数: // e: // 包含事件数据的 System.Windows.Forms.MouseEventArgs。 /// <summary> /// 引发 System.Windows.Forms.Control.MouseUp 事件。 /// </summary> /// <param name="e">包含事件数据的 System.Windows.Forms.MouseEventArgs。</param> protected override void OnMouseUp(MouseEventArgs e) { this.Capture = false; if (nDragCol != -1) { // 消最后残余的一根 DrawTraker(); // 做改变列宽度的事情 int x0 = 0; int delta = 0; // 把拖动的起点位置x折算成屏幕坐标形态 if (nDragCol == 0) { x0 = this.DocumentOrgX + this.LeftBlank + this.record.NameCaptionTotalWidth; } else { } // 计算差额 delta = nLastTrackerX - x0; if (delta != 0) { if (nDragCol == 0) { this.record.NameCaptionPureWidth += delta; if (this.record.NameCaptionTotalWidth >= this.ClientWidth) this.record.NameCaptionPureWidth -= 20; if (this.record.NameCaptionPureWidth < 0) this.record.NameCaptionPureWidth = 0; } // 迫使每个单元重新测算高度 this.record.CalculateFieldsHeight(0,-1,true); } nLastTrackerX = -1; nDragCol = -1; this.DocumentOrgX = this.DocumentOrgX; // 客户区发生变化后,文档与发生变化 InvalidateRect iRect = new InvalidateRect(); iRect.bAll = true; this.AfterDocumentChanged(ScrollBarMember.Both, iRect); } base.OnMouseUp(e); /* if(e.Button == MouseButtons.Right) { PopupMenu(new Point(e.X, e.Y) ); } */ }
// // 摘要: // 引发 System.Windows.Forms.Control.SizeChanged 事件。 // // 参数: // e: // 包含事件数据的 System.EventArgs。 /// <summary> /// 引发 System.Windows.Forms.Control.SizeChanged 事件。 /// </summary> /// <param name="e">包含事件数据的 System.EventArgs。</param> protected override void OnSizeChanged(System.EventArgs e) { base.OnSizeChanged(e); if (this.record != null) { // 把所有字段的高度计算一下 this.record.CalculateFieldsHeight(0,-1,true); // 客户区发生变化后,文档与发生变化 InvalidateRect iRect = new InvalidateRect(); iRect.bAll = true; this.AfterDocumentChanged(ScrollBarMember.Both, iRect); } }
// 当文档尺寸和文档原点改变后, // 更新卷滚条,小edit控件 等设施状态,和使文档某区域失效以便文档可见 // parameters: // scrollBarMember 卷滚条枚举值 // iRect 失效区域 当为null,则不失效,如bAll等于true则全部区域 internal void AfterDocumentChanged(ScrollBarMember scrollBarMember, InvalidateRect iRect) { // 设小edit控件 this.SetEditPos(false); // 2008/11/26 changed 单纯改变文档尺寸,不应变动小edit的focus特性。也就是说,原来如果没有focus,现在也应没有 // 设卷滚条信息 this.SetScrollBars(scrollBarMember); // 失效区域 if (iRect != null) { if (iRect.bAll == true) this.Invalidate(); else this.Invalidate(iRect.rect); } }
// 设Marc数据设到内存对象中 // parameters: // strMarc Marc记录 机内格式 internal int SetMarc(string strMarc, bool bCheckMarcDef, out string strError) { strError = ""; bool bHasFocus = this.marcEditor.Focused; if (strMarc == null) strMarc = ""; if (strMarc.Length < 24) strMarc = strMarc + new string('?',24-strMarc.Length); // 清空原来的内存对象 this.marcEditor.ClearSelectFieldIndices(); this.Fields.Clear(); /* if (bCheckMarcDef == true && this.marcEditor.MarcDefDom == null) { GetConfigFileEventArgs ar = new GetConfigFileEventArgs(); ar.Path = "marcdef"; ar.Stream = null; this.marcEditor.OnGetConfigFile(ar); if (ar.ErrorInfo != "") { strError = "获取marcdef出错,原因:" + ar.ErrorInfo; return -1; } if (ar.Stream != null) { ar.Stream.Seek(0, SeekOrigin.Begin); this.marcEditor.MarcDefDom = new XmlDocument(); try { this.marcEditor.MarcDefDom.Load(ar.Stream); } catch(Exception ex ) { this.marcEditor.MarcDefDom = null; strError = "加载marcdef配置文件到dom时出错:" + ex.Message; return -1; } ar.Stream.Close(); } } * * */ List<string> fields = null; strMarc = strMarc.Replace(Record.SUBFLD, Record.KERNEL_SUBFLD); Record.GetMarcFields(strMarc, out fields); if (fields == null) return 0; // TODO: 在每个子字段符号前插入\x200e符号 for(int i=0;i<fields.Count;i++) { string strText = fields[i]; int nOutputPosition; string strName = ""; string strIndicator = ""; string strValue = ""; if (i == 0) // 取头标区 { strValue = strText; if (strValue.Length != 24) { if (strValue.Length > 24) strValue = strText.Substring(0,24); else strValue = strText + new string(' ',24 - strText.Length); } this.Fields.AddInternal("###", "", strValue, false, //bFireTextChanged false, //bInOrder out nOutputPosition); continue; } if (strText.Length < 3) strText = strText + new string(' ',3-strText.Length); strName = strText.Substring(0,3); if (IsControlFieldName(strName) == true) { strIndicator = ""; strValue = strText.Substring(3); } else { if (strText.Length < 5) strText = strText + new string(' ',5-strText.Length); strIndicator = strText.Substring(3,2); strValue = strText.Substring(5); } // 可以考虑把字段加好了再统计计算显示页面 this.Fields.AddInternal(strName, strIndicator, strValue, false, //bFireTextChanged false, //bInOrder out nOutputPosition); } // 总体触发一次TextChnaged事件 this.marcEditor.FireTextChanged(); this.marcEditor.InitialFonts(); // 设第一个节点为当前活动焦点 if (bHasFocus == true) { if (this.Fields.Count > 0) this.marcEditor.SetActiveField(0, 3, true); } else { /* if (this.Fields.Count > 0) this.marcEditor.SetActiveField(0, 3, false); * */ } InvalidateRect iRect = new InvalidateRect(); iRect.bAll = true; this.marcEditor.AfterDocumentChanged(ScrollBarMember.Both, iRect); return 0; }