/// <summary> /// 获得当前元素所在的单元格(当前正在操作的cell) /// </summary> /// <returns></returns> internal TPTextCell GetCurrentCell() { //获取当前元素 ZYTextElement currentEle = OwnerDocument.Content.CurrentElement; TPTextCell cell = OwnerDocument.Content.GetParentByElement(currentEle, ZYTextConst.c_Cell) as TPTextCell; if (cell != null) { return(cell); } return(null); }
public static void KeyBackspace() { //如果上一次是在维文中间回车换行 if (WeiWenProcess.boolEnter) { ZYTextElement CurrentElement = WeiWenProcess.document.Content.CurrentElement; if (WeiWenProcess.document.Content.GetPreElement(CurrentElement) is ZYTextEOF && isWeiwen(WeiWenProcess.document.Content.GetPreChar(2).Char)) { ZYTextChar PreChar = WeiWenProcess.document.Content.GetPreChar(2); (CurrentElement as ZYTextChar).Char = (char)myChars[0]; (CurrentElement as ZYTextChar).RefreshSize(); PreChar.Char = (char)myChars[1]; PreChar.RefreshSize(); boolEnter = false; return; } } ZYTextChar myChar = WeiWenProcess.document.Content.GetPreChar(1); if (isWeiwen(myChar.Char))//当前要删除的是维文 { switch (weiwenType(myChar.Char)) { //0-单独 1-接尾 2-中间 3-起始 //单独(原型) 左 false 右 false 左右不用改变任何 //左右都不是维文,那么左右两个相接不是维文相接,跟当前字符删不删除是一样 // 中间形式 左 true 右 true 左右不用改变 //左右都是维文,那么左右两个相接依然是维文相接,跟当前字符删不删除是一样 case 1: //接尾形式 左 false 右 true 左不用改变 右要改变(中间 -> 接尾 或 起始 -> 单独) ZYTextChar RightChar = WeiWenProcess.document.Content.GetPreChar(2); RightChar.Char = UnicodeToString(ChangeFromweiwen(RightChar.Char, true)).ToCharArray()[0]; RightChar.RefreshSize(); break; case 3: //起始形式 左 true 右 false 左用改变 右不用改变 ZYTextChar LeftChar = WeiWenProcess.document.Content.GetFontChar(0); LeftChar.Char = UnicodeToString(ChangeFromweiwen(LeftChar.Char, false)).ToCharArray()[0]; LeftChar.RefreshSize(); break; default: break; } } }
/// <summary> /// Gets the owner div. /// </summary> /// <param name="myElement">My element.</param> /// <returns></returns> public static ZYTextDiv GetOwnerDiv(ZYTextElement myElement) { ZYTextDiv myDiv = null; while (myElement != null) { myDiv = myElement as ZYTextDiv; if (myDiv == null) { myElement = myElement.Parent; } else { return(myDiv); } } return(myDiv); }
public static bool FixElementsForParent(System.Collections.ArrayList myList) { if (myList != null && myList.Count > 0) { for (int iCount = myList.Count - 1; iCount >= 0; iCount--) { if (iCount >= myList.Count) { iCount = myList.Count - 1; } ZYTextElement myElement = (ZYTextElement)myList[iCount]; if (myList.Contains(myElement.Parent)) { myList.Remove(myElement); } }//for return(true); } return(false); }//public static bool FixElementsForParent(System.Collections.ArrayList myList )
public PropertyBase(object o) { e = o as ZYTextElement; }
//双击弹出窗口 public override bool HandleDblClick(int x, int y, MouseButtons Button) { this.Clicked = true; //当前字符,用于判断是否在[]{}中 ZYTextElement curChar = this.OwnerDocument.GetElementByPos(x, y); //Debug.WriteLine("block handledbclick 当前元素 " + curChar); //选项的字符串 StringBuilder str = new StringBuilder(); this.GetFinalText(str); int m = this.ChildElements.IndexOf(curChar); int tmpindex = -1; //方括号[]的配对索引 List <int> start = new List <int>(); List <int> end = new List <int>(); for (int i = 0; i < str.Length; i++) { if (str[i] == '[') { start.Add(i); } if (str[i] == ']') { end.Add(i); } } //花括号{}的配对索引 List <int> startm = new List <int>(); List <int> endm = new List <int>(); for (int i = 0; i < str.Length; i++) { if (str[i] == '{') { startm.Add(i); } if (str[i] == '}') { endm.Add(i); } } foreach (ZYTextElement ele in this.ChildElements) { if (ele.Bounds.Contains(x, y)) { this.Clicked = true; if (this is ZYSelectableElement) { //如果当前字是选项模板中的一个,则替换模板 //替换子模板 //并把原有选项中内容展开,把[xxx]转换成真正的模板元素 ArrayList al = new ArrayList(); if (ele == curChar) { #region bwy //循环[]匹配的组 for (int i = 0; i < start.Count; i++) { if (start[i] < m && m < end[i]) { //弹出将要展开模板的警告 if (MessageBox.Show("确定要将选项展开为模板吗?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) { return(true); } else { this.OwnerDocument.BeginUpdate(); this.OwnerDocument.BeginContentChangeLog(); tmpindex = i; //展开 this.OwnerDocument._Delete(); string f = "[]"; bool isintmp = false; string tmpname = ""; foreach (char c in str.ToString()) { if (f.IndexOf(c) == 0) { isintmp = true; tmpname = ""; continue; } if (f.IndexOf(c) == 1) { isintmp = false; //插入名为tmpname的模板 ZYTemplate tmp = new ZYTemplate(); tmp.Name = tmpname; tmp.Parent = this.Parent; tmp.OwnerDocument = this.OwnerDocument; this.OwnerDocument._InsertBlock(tmp); al.Add(tmp); continue; } if (isintmp) { tmpname += c; } else { this.OwnerDocument.Content.InsertString(c.ToString()); } } ZYTemplate tmp2 = al[tmpindex] as ZYTemplate; this.OwnerDocument.Content.CurrentElement = tmp2.FirstElement; tmp2.HandleDblClick(tmp2.FirstElement.RealLeft, tmp2.FirstElement.RealTop, Button); this.OwnerDocument.Content.SelectLength = 0; this.OwnerDocument.EndContentChangeLog(); this.OwnerDocument.EndUpdate(); Debug.WriteLine("应该展开模板 " + (al[tmpindex] as ZYTemplate).Name); return(true); } } } #endregion bwy #region bwy 循环{}匹配的每一组 for (int j = 0; j < startm.Count; j++) { //如果当前元素在某个提示中间 if (startm[j] < m && m < endm[j]) { //弹出录入提示 string tmpname = str.ToString().Substring(startm[j] + 1, endm[j] - startm[j] - 1); //弹出名为tmpname的录入提示 ZYPromptText p = new ZYPromptText(); p.Name = tmpname; p.Parent = this.Parent; p.OwnerDocument = this.OwnerDocument; FormatFrm HelpWinx = new FormatFrm(p, this as ZYSelectableElement, startm[j], endm[j]); HelpWinx.Show(); return(true); } } #endregion bwy } ImplementFrm HelpWin = new ImplementFrm((ZYSelectableElement)this); HelpWin.Show(); //Debug.WriteLine("显示弹出窗口OK"); return(true); } if (this is ZYFormatDatetime || this is ZYFormatNumber || this is ZYFormatString || this is ZYPromptText) { FormatFrm HelpWin = new FormatFrm(this); HelpWin.Show(); return(true); } if (this is ZYTemplate) { this.OwnerDocument.ReplaceTemplate(this.Type, this.Name); return(true); } if (this is ZYReplace) { TextBoxFrm TextWin = new TextBoxFrm(this); TextWin.ShowDialog(); return(true); } if (this is ZYLookupEditor) { LookupEditorForm TextWin = new LookupEditorForm(this); if (TextWin.NormalWordBook == null || TextWin.NormalWordBook == "") { return(false); } TextWin.ShowDialog(); return(true); } } } return(base.HandleDblClick(x, y, Button)); }
public override void DrawBackGround(ZYTextElement myElement) { if (myElement.Parent is ZYFixedText && this.OwnerDocument.Info.DocumentModel == DocumentModel.Edit) { return; } Rectangle rect = myElement.Bounds; if (myElement.Parent is ZYTextBlock) { if (myElement.Parent.LastElement == myElement && !WeiWenProcess.weiwen) { rect.Width -= 10; } } //打印状态不绘制背景,其它状态绘制背景,但可能背景是透明的 if (this.OwnerDocument.Info.Printing || this.OwnerDocument.OwnerControl.bolLockingUI) { } else { switch (ZYEditorControl.ElementStyle) { case "下划线": pen.Color = ZYEditorControl.ElementBackColor; pen.Width = 1; //DrectSoft.Library.EmrEditor.Src.Gui.GraphicsUnitConvert.Convert(2, GraphicsUnit.Pixel,GraphicsUnit.Document ); this.OwnerDocument.View.DrawLine(pen, rect.Left, rect.Bottom, rect.Right, rect.Bottom); if (myElement.Parent is ZYTextBlock) { if (myElement.Parent.LastElement == myElement) { this.OwnerDocument.View.DrawLine(pen, rect.Right, rect.Bottom - 5, rect.Right, rect.Bottom + 5); } } break; case "背景色": this.OwnerDocument.View.FillRectangle(ZYEditorControl.ElementBackColor, rect); break; } //base.DrawBackGround(myElement); } //即使是只读状态,但如果它在激活区域中,视同编辑状态 if (this.OwnerDocument.OwnerControl.ActiveEditArea != null) { if (this.OwnerDocument.OwnerControl.ActiveEditArea.Top <= myElement.RealTop && myElement.RealTop + this.Height <= this.OwnerDocument.OwnerControl.ActiveEditArea.End) { switch (ZYEditorControl.ElementStyle) { case "下划线": pen.Color = ZYEditorControl.ElementBackColor; pen.Width = 2; this.OwnerDocument.View.DrawLine(pen, rect.Left, rect.Bottom, rect.Right, rect.Bottom); break; case "背景色": this.OwnerDocument.View.FillRectangle(ZYEditorControl.ElementBackColor, rect); break; } } } }
public override bool HandleMouseMove(int x, int y, MouseButtons Button) { //鼠标移动时的坐标位置,随着鼠标的移动不断的变化 Point p = new Point(x, y); //如果鼠标还在表格中 if (this.GetContentBounds().Contains(p)) { //如果是划选 if (myOwnerDocument.OwnerControl.CaptureMouse && currentCell != null) { //获取当前鼠标点击处单元格的位置和大小 Rectangle currentRec = currentCell.GetContentBounds(); #region 获得一个选择的橡皮筋矩形区域 SelectRect Rectangle SelectRect = Rectangle.Empty; if (p.X > LastMousePosition.X) { SelectRect.X = LastMousePosition.X; SelectRect.Width = p.X - LastMousePosition.X; } else { SelectRect.X = p.X; SelectRect.Width = LastMousePosition.X - p.X; } if (p.Y > LastMousePosition.Y) { SelectRect.Y = LastMousePosition.Y; SelectRect.Height = p.Y - LastMousePosition.Y; } else { SelectRect.Y = p.Y; SelectRect.Height = LastMousePosition.Y - p.Y; } #endregion if (currentRec.Contains(p)) { myOwnerDocument.Content.AutoClearSelection = false; myOwnerDocument.Content.MoveTo(x, y); ZYTextElement myElement = myOwnerDocument.Content.CurrentElement; myOwnerDocument.OwnerControl.MoveCaretWithScroll = false; myOwnerDocument.OwnerControl.UpdateTextCaret(); myOwnerDocument.OwnerControl.MoveCaretWithScroll = true; return(true); } else { for (int i = 0; i < this.allRows.Count; i++) { for (int k = 0; k < this.allRows[i].Cells.Count; k++) { //取得选择的区域和单元格的交集,用来确定那些单元格被选中了. bool flag = SelectRect.IntersectsWith(this.allRows[i][k].GetContentBounds()); if (this.allRows[i][k].Selected != flag) { this.allRows[i][k].Selected = flag; this.allRows[i][k].CanAccess = flag; //将此单元格添加到无效区域 myOwnerDocument.OwnerControl.AddInvalidateRect(this.allRows[i][k].GetContentBounds()); //马上更新无效区域 myOwnerDocument.OwnerControl.UpdateInvalidateRect(); } } } //此处加入测试几个单元格被选中的代码 return(true); } } else if (myOwnerDocument.OwnerControl.CaptureMouse && currentCell == null && OwnerDocument.OwnerControl.Cursor == Cursors.VSplit) { //TODO: 此时是调整表格列宽的时候,应该让纵穿整个页面的虚线随着鼠标移动 ResizeToRectangle(); return(true); } else if (myOwnerDocument.OwnerControl.CaptureMouse == false) { //设置光标状态 Modified By wwj 2012-02-16 SetCursorStatus(p.X, p.Y); } } return(false); }