public override bool InsertItem(HCCustomItem aItem) { bool Result = base.InsertItem(aItem); if (Result) { Style.UpdateInfoRePaint(); Style.UpdateInfoReCaret(); Style.UpdateInfoReScroll(); } return(Result); }
public HCViewTool() : base() { FToolOffset = -4; FActiveItem = null; FHotToolBar = null; FTableToolBar = new HCTableToolBar(); FTableToolBar.OnUpdateView = DoTableToolBarUpdateView; FImageToolBar = new HCImageToolBar(); FImageToolBar.OnUpdateView = DoImageToolBarUpdateView; FImageToolBar.OnControlPaint = DoImageToolBarControlPaint; }
protected override void DoRemoveItem(HCCustomItem aItem) { if (aItem.StyleNo == HCStyle.Annotate && (aItem as HCAnnotateItem).MarkType == MarkType.cmtBeg) { FAnnotateCount--; if (FOnRemoveAnnotate != null) { FOnRemoveAnnotate(this, aItem as HCAnnotateItem); } } base.DoRemoveItem(aItem); }
public override bool InsertItem(int aIndex, HCCustomItem aItem, bool aOffsetBefor = true) { bool Result = base.InsertItem(aIndex, aItem, aOffsetBefor); if (Result) { Style.UpdateInfoRePaint(); Style.UpdateInfoReCaret(); Style.UpdateInfoReScroll(); } return(Result); }
private void UndoRedoItemProperty(HCCustomUndoAction aAction, bool aIsUndo, ref int aCaretItemNo, ref int aCaretOffset) { HCItemPropertyUndoAction vAction = aAction as HCItemPropertyUndoAction; aCaretItemNo = vAction.ItemNo; aCaretOffset = vAction.Offset; HCCustomItem vItem = Items[vAction.ItemNo]; switch (vAction.ItemProperty) { case ItemProperty.uipStyleNo: { if (aIsUndo) { vItem.StyleNo = (vAction as HCItemStyleUndoAction).OldStyleNo; } else { vItem.StyleNo = (vAction as HCItemStyleUndoAction).NewStyleNo; } } break; case ItemProperty.uipParaNo: { if (aIsUndo) { vItem.ParaNo = (vAction as HCItemParaUndoAction).OldParaNo; } else { vItem.ParaNo = (vAction as HCItemParaUndoAction).NewParaNo; } } break; case ItemProperty.uipParaFirst: { if (aIsUndo) { vItem.ParaFirst = (vAction as HCItemParaFirstUndoAction).OldParaFirst; } else { vItem.ParaFirst = (vAction as HCItemParaFirstUndoAction).NewParaFirst; } } break; } }
/// <summary> 复制前,便于控制是否允许复制 </summary> protected virtual bool DoCopyRequest(int aFormat) { HCCustomItem vTopItem = FData.GetTopLevelItem(); if (vTopItem is HCEditItem) { if ((vTopItem as HCEditItem).SelectTextExists()) { return((aFormat == User.CF_TEXT) || (aFormat == User.CF_UNICODETEXT)); } } return(true); }
// 当前RectItem格式化时所属的Data(为松耦合请传入TCustomRichData类型) public override void FormatToDrawItem(HCCustomData aRichData, int aItemNo) { this.Width = 0; this.Height = aRichData.Style.TextStyles[0].FontHeight; // 默认大小 if (this.MarkType == MarkType.cmtBeg) { if (aItemNo < aRichData.Items.Count - 1) { HCCustomItem vItem = aRichData.Items[aItemNo + 1]; if ((vItem.StyleNo == this.StyleNo) && // 下一个是组标识 ((vItem as HCDomainItem).MarkType == MarkType.cmtEnd)) // 下一个是结束标识 { this.Width = 10; // 增加宽度以便输入时光标可方便点击 } else if (vItem.ParaFirst) // 下一个是段首,我是段尾 { this.Width = 10; // 增加宽度以便输入时光标可方便点击 } else if (vItem.StyleNo > HCStyle.Null) // 后面是文本,跟随后面的高度 { this.Height = aRichData.Style.TextStyles[vItem.StyleNo].FontHeight; } } else { this.Width = 10; } } else // 域结束标识 { HCCustomItem vItem = aRichData.Items[aItemNo - 1]; if ((vItem.StyleNo == this.StyleNo) && ((vItem as HCDomainItem).MarkType == MarkType.cmtBeg)) { this.Width = 10; } else if (this.ParaFirst) // 结束标识是段首,增加宽度 { this.Width = 10; } else if (vItem.StyleNo > HCStyle.Null) // 前面是文本,距离前面的高度 { this.Height = aRichData.Style.TextStyles[vItem.StyleNo].FontHeight; } } }
private void CalcItemFormatHeigh(HCCustomItem AItem) { if (Style.TempStyleNo != AItem.StyleNo) { Style.ApplyTempStyle(AItem.StyleNo); FLastFormatParaNo = AItem.ParaNo; FItemFormatHeight = CalculateLineHeight(Style.TextStyles[AItem.StyleNo], Style.ParaStyles[AItem.ParaNo]); } else if (FLastFormatParaNo != AItem.ParaNo) { FLastFormatParaNo = AItem.ParaNo; FItemFormatHeight = CalculateLineHeight(Style.TextStyles[AItem.StyleNo], Style.ParaStyles[AItem.ParaNo]); } }
private void CancelActiveToolItem() { if (FActiveItem is HCImageItem) { (FActiveItem as HCImageItem).ShapeManager.DisActive(); FImageToolBar.Visible = false; } else if (FActiveItem is HCTableItem) // 是表格 { FTableToolBar.Visible = false; } FActiveItem = null; }
private void UndoRedoInsertItem(HCCustomUndo aUndo, HCCustomUndoAction aAction, bool aIsUndo, ref int aCaretItemNo, ref int aCaretOffset, ref int aCaretDrawItemNo) { HCItemUndoAction vAction = aAction as HCItemUndoAction; aCaretItemNo = vAction.ItemNo; if (aIsUndo) { Items.RemoveAt(vAction.ItemNo); FItemAddCount--; if (aCaretItemNo > 0) { aCaretItemNo--; if (Items[aCaretItemNo].StyleNo > HCStyle.Null) { aCaretOffset = Items[aCaretItemNo].Length; } else { aCaretOffset = HC.OffsetAfter; } } else { aCaretOffset = 0; } } else // 重做 { HCCustomItem vItem = null; LoadItemFromStreamAlone(vAction.ItemStream, ref vItem); Items.Insert(vAction.ItemNo, vItem); FItemAddCount++; aCaretItemNo = vAction.ItemNo; if (Items[aCaretItemNo].StyleNo > HCStyle.Null) { aCaretOffset = Items[aCaretItemNo].Length; } else { aCaretOffset = HC.OffsetAfter; } aCaretDrawItemNo = (aUndo as HCDataUndo).CaretDrawItemNo + 1; } }
public override HCCustomItem BreakByOffset(int aOffset) { HCCustomItem Result = null; if ((aOffset >= Length) || (aOffset <= 0)) { } else { Result = base.BreakByOffset(aOffset); Result.Text = this.SubString(aOffset + 1, Length - aOffset); FText = FText.Substring(0, aOffset); // 当前Item减去光标后的字符串 } return(Result); }
public override HCCustomItem CreateItemByStyle(int aStyleNo) { HCCustomItem Result = null; if (FOnCreateItemByStyle != null) { Result = FOnCreateItemByStyle(this, aStyleNo); } if (Result == null) { Result = base.CreateItemByStyle(aStyleNo); } return(Result); }
protected override HCCustomItem CreateItemByStyle(int AStyleNo) { HCCustomItem Result = null; if (FOnCreateItemByStyle != null) { Result = FOnCreateItemByStyle(this, AStyleNo); } if (Result == null) { Result = base.CreateItemByStyle(AStyleNo); } return(Result); }
private void UndoRedoItemMirror(HCCustomUndoAction aAction, bool aIsUndo, ref int aCaretItemNo, ref int aCaretOffset) { HCItemUndoAction vAction = aAction as HCItemUndoAction; aCaretItemNo = vAction.ItemNo; aCaretOffset = vAction.Offset; HCCustomItem vItem = Items[aCaretItemNo]; if (aIsUndo) { LoadItemFromStreamAlone(vAction.ItemStream, ref vItem); } else { LoadItemFromStreamAlone(vAction.ItemStream, ref vItem); } }
public override void Assign(HCCustomItem Source) { base.Assign(Source); FItems.Clear(); HCComboboxItem vCombobox = Source as HCComboboxItem; for (int i = 0; i < vCombobox.Items.Count; i++) { FItems.Add(vCombobox.Items[i]); } FItemValues.Clear(); for (int i = 0; i < vCombobox.ItemValues.Count; i++) { FItemValues.Add(vCombobox.ItemValues[i]); } }
public void LoadItemFromStreamAlone(Stream aStream, ref HCCustomItem aItem) { string vFileExt = ""; ushort vFileVersion = 0; byte vLan = 0; aStream.Position = 0; HC._LoadFileFormatAndVersion(aStream, ref vFileExt, ref vFileVersion, ref vLan); // 文件格式和版本 if ((vFileExt != HC.HC_EXT) && (vFileExt != "cff.")) { throw new Exception("加载失败,不是" + HC.HC_EXT + "文件!"); } HCStyle vStyle = new HCStyle(); vStyle.LoadFromStream(aStream, vFileVersion); int vStyleNo = HCStyle.Null; byte[] vBuffer = BitConverter.GetBytes(vStyleNo); aStream.Read(vBuffer, 0, vBuffer.Length); vStyleNo = BitConverter.ToInt32(vBuffer, 0); if (vStyleNo > HCStyle.Null) { HCTextStyle vTextStyle = vStyle.TextStyles[vStyleNo]; vStyleNo = Style.GetStyleNo(vTextStyle, true); } if (aItem == null) { aItem = CreateItemByStyle(vStyleNo); } aItem.LoadFromStream(aStream, vStyle, vFileVersion); aItem.StyleNo = vStyleNo; int vParaNo = aItem.ParaNo; HCParaStyle vParaStyle = vStyle.ParaStyles[vParaNo]; vParaNo = Style.GetParaNo(vParaStyle, true); aItem.ParaNo = vParaNo; }
protected override void DoSectionRemoveItem(object sender, HCCustomData aData, HCCustomItem aItem) { base.DoSectionRemoveItem(sender, aData, aItem); if (aItem == FActiveItem) { if (FActiveItem is HCImageItem) { (FActiveItem as HCImageItem).ShapeManager.DisActive(); FImageToolBar.Visible = false; } else if (FActiveItem is HCTableItem) // 是表格 { FTableToolBar.Visible = false; } FActiveItem = null; } }
// 当前RectItem格式化时所属的Data(为松耦合请传入TCustomRichData类型) public override void FormatToDrawItem(HCCustomData ARichData, int AItemNo) { this.Width = 0; this.Height = 5; // 默认大小 if (this.MarkType == MarkType.cmtBeg) { if (AItemNo < ARichData.Items.Count - 1) { HCCustomItem vItem = ARichData.Items[AItemNo + 1]; if ((vItem.StyleNo == this.StyleNo) && // 下一个是组标识) ((vItem as HCDomainItem).MarkType == MarkType.cmtEnd)) // 下一个是结束标识 { this.Width = 10; // 增加宽度以便输入时光标可方便点击 } else if (vItem.StyleNo > HCStyle.Null) { ARichData.Style.TextStyles[vItem.StyleNo].ApplyStyle(ARichData.Style.DefCanvas); this.Height = ARichData.Style.DefCanvas.TextHeight("H"); } } else { this.Width = 10; } } else // 域结束标识 { HCCustomItem vItem = ARichData.Items[AItemNo - 1]; if ((vItem.StyleNo == this.StyleNo) && ((vItem as HCDomainItem).MarkType == MarkType.cmtBeg)) { this.Width = 10; } else if (vItem.StyleNo > HCStyle.Null) { ARichData.Style.TextStyles[vItem.StyleNo].ApplyStyle(ARichData.Style.DefCanvas); this.Height = ARichData.Style.DefCanvas.TextHeight("H"); } } }
protected override void OnMouseDown(MouseEventArgs e) { FCaptureToolBar = null; if (!this.ReadOnly) { if (FUseTableTool && FTableToolBar.Visible && TableMouseDown(e)) { FCaptureToolBar = FTableToolBar; return; } if (FUseImageTool && FImageToolBar.Visible && ImageMouseDown(e)) { FCaptureToolBar = FImageToolBar; return; } } base.OnMouseDown(e); FTopData = this.ActiveSectionTopLevelData(); HCCustomItem vTopItem = FTopData.GetActiveItem(); SetActiveToolItem(vTopItem); HCCustomData vData = null; while (FActiveItem == null) { vData = FTopData.GetRootData(); if (vData == FTopData) { break; } FTopData = vData; vTopItem = FTopData.GetActiveItem(); SetActiveToolItem(vTopItem); } }
public override void FormatToDrawItem(HCCustomData aRichData, int aItemNo) { this.Width = 0; this.Height = aRichData.Style.TextStyles[0].FontHeight - aRichData.Style.LineSpaceMin; if (this.MarkType == MarkType.cmtBeg) { if (aItemNo < aRichData.Items.Count - 1) { HCCustomItem vItem = aRichData.Items[aItemNo + 1]; if (vItem.StyleNo == this.StyleNo && (vItem as HCAnnotateItem).MarkType == MarkType.cmtEnd) { this.Width = 10; } else if (vItem.ParaFirst) { this.Width = 10; } } else { this.Width = 10; } } else { HCCustomItem vItem = aRichData.Items[aItemNo - 1]; if (vItem.StyleNo == this.StyleNo && (vItem as HCAnnotateItem).MarkType == MarkType.cmtBeg) { this.Width = 10; } else if (this.ParaFirst) { this.Width = 10; } } }
protected override void OnMouseDown(MouseEventArgs e) { if (!this.ReadOnly) { if (FTableToolBar.Visible && TableMouseDown(e)) { return; } if (FImageToolBar.Visible && ImageMouseDown(e)) { return; } } base.OnMouseDown(e); FTopData = this.ActiveSectionTopLevelData(); HCCustomItem vTopItem = this.GetTopLevelItem(); SetActiveItem(vTopItem); }
private void _FormatBreakTextDrawItem(int aItemNo, int aFmtLeft, int aFmtRight, ref int aDrawItemNo, ref POINT aPos, ref RECT vRect, ref int vRemainderWidth, ref bool vParaFirst) { HCCanvas vCanvas = HCStyle.CreateStyleCanvas(); try { HCCustomDrawItem vDrawItem = DrawItems[aDrawItemNo]; HCCustomItem vItemBK = Items[vDrawItem.ItemNo]; int vLen = vItemBK.Text.Length; CalcItemFormatHeigh(vItemBK); int vWidth = Style.TempCanvas.TextWidth(vItemBK.Text[vLen - 1]); // 分裂前 vDrawItem.CharLen = vDrawItem.CharLen - 1; vDrawItem.Rect.Right = vDrawItem.Rect.Right - vWidth; vRemainderWidth = aFmtRight - vDrawItem.Rect.Right; FinishLine(aItemNo, aDrawItemNo, vRemainderWidth); // 分裂后 aPos.X = aFmtLeft; aPos.Y = vDrawItem.Rect.Bottom; vRect.Left = aPos.X; vRect.Top = aPos.Y; vRect.Right = vRect.Left + vWidth; vRect.Bottom = vRect.Top + FItemFormatHeight; NewDrawItem(vDrawItem.ItemNo, vLen - 1, 1, vRect, false, true, ref aDrawItemNo); vParaFirst = false; aPos.X = vRect.Right; vRemainderWidth = aFmtRight - vRect.Right; // 放入最多后的剩余量 } finally { HCStyle.DestroyStyleCanvas(vCanvas); } }
public override void Assign(HCCustomItem source) { base.Assign(source); FFormat = (source as HCDateTimePicker).Format; FDateTime = (source as HCDateTimePicker).DateTime; }
private void UndoRedoItemProperty(HCCustomUndoAction aAction, bool aIsUndo, ref int aCaretItemNo, ref int aCaretOffset) { HCItemPropertyUndoAction vAction = aAction as HCItemPropertyUndoAction; aCaretItemNo = vAction.ItemNo; aCaretOffset = vAction.Offset; HCCustomItem vItem = Items[vAction.ItemNo]; switch (vAction.ItemProperty) { case ItemProperty.uipStyleNo: { if (aIsUndo) { vItem.StyleNo = (vAction as HCItemStyleUndoAction).OldStyleNo; } else { vItem.StyleNo = (vAction as HCItemStyleUndoAction).NewStyleNo; } } break; case ItemProperty.uipParaNo: { int vParaLastItemNo = GetParaLastItemNo(vAction.ItemNo); if (aIsUndo) { for (int i = vAction.ItemNo; i <= vParaLastItemNo; i++) { Items[i].ParaNo = (vAction as HCItemParaUndoAction).OldParaNo; } } else { for (int i = vAction.ItemNo; i <= vParaLastItemNo; i++) { Items[i].ParaNo = (vAction as HCItemParaUndoAction).NewParaNo; } } } break; case ItemProperty.uipParaFirst: { if (aIsUndo) { vItem.ParaFirst = (vAction as HCItemParaFirstUndoAction).OldParaFirst; } else { vItem.ParaFirst = (vAction as HCItemParaFirstUndoAction).NewParaFirst; } } break; case ItemProperty.uipPageBreak: { FForceClearExtra = true; if (aIsUndo) { vItem.PageBreak = (vAction as HCItemPageBreakUndoAction).OldPageBreak; } else { vItem.PageBreak = (vAction as HCItemPageBreakUndoAction).NewPageBreak; } } break; } }
private void UndoRedoInsertItem(HCCustomUndo aUndo, HCCustomUndoAction aAction, bool aIsUndo, ref int aCaretItemNo, ref int aCaretOffset, ref int aCaretDrawItemNo) { HCItemUndoAction vAction = aAction as HCItemUndoAction; aCaretItemNo = vAction.ItemNo; if (aIsUndo) { if (aCaretItemNo < Items.Count - 1) // 不是最后一个 { if (Items[aCaretItemNo].ParaFirst) // 段首删除了,光标为下一个开始 { aCaretOffset = 0; aCaretDrawItemNo = Items[aCaretItemNo + 1].FirstDItemNo; } else // 删除的不是段首 //if (Items[aCaretItemNo + 1].ParaFirst) // 下一个是段首,光标保持在同段最后 { aCaretItemNo--; if (Items[aCaretItemNo].StyleNo > HCStyle.Null) { aCaretOffset = Items[aCaretItemNo].Length; } else { aCaretOffset = HC.OffsetAfter; } aCaretDrawItemNo = (aUndo as HCDataUndo).CaretDrawItemNo;// - 1; } } else if (aCaretItemNo > 0) // 不是第一个 { aCaretItemNo--; if (Items[aCaretItemNo].StyleNo > HCStyle.Null) { aCaretOffset = Items[aCaretItemNo].Length; } else { aCaretOffset = HC.OffsetAfter; } aCaretDrawItemNo = (aUndo as HCDataUndo).CaretDrawItemNo - 1; } else { aCaretOffset = 0; } Items.RemoveAt(vAction.ItemNo); FItemAddCount--; } else // 重做 { HCCustomItem vItem = null; LoadItemFromStreamAlone(vAction.ItemStream, ref vItem); Items.Insert(vAction.ItemNo, vItem); FItemAddCount++; aCaretItemNo = vAction.ItemNo; if (Items[aCaretItemNo].StyleNo > HCStyle.Null) { aCaretOffset = Items[aCaretItemNo].Length; } else { aCaretOffset = HC.OffsetAfter; } aCaretDrawItemNo = (aUndo as HCDataUndo).CaretDrawItemNo + 1; } }
public void SaveItemToStreamAlone(Stream aStream, HCCustomItem aItem) { HC._SaveFileFormatAndVersion(aStream); Style.SaveToStream(aStream); aItem.SaveToStream(aStream); }
private void SetActiveToolItem(HCCustomItem aItem) { // MouseDown里会触发重绘,此时ToolBar并未确定显示,处理ToolBar的Visible属性 // 会重新触发重绘,重绘是通过DoImageToolBarUpdateView(Rect),需要先计算区域参数 // 然后触发UpdateView,所以需要提前计算ToolBar的坐标vPt位置 if (FActiveItem != aItem) { if (FUseTableTool && (FActiveItem is HCTableItem)) { FTableToolBar.Visible = false; } else if (FUseImageTool && (FActiveItem is HCImageItem)) { FImageToolBar.Visible = false; } if ((aItem != null) && (aItem.Active)) { POINT vPt = this.GetTopLevelRectDrawItemViewCoord(); if (FUseTableTool && (aItem is HCTableItem) && (FTableToolBar.Controls.Count > 0)) { FActiveItem = aItem; FTableToolBar.Left = vPt.X - FTableToolBar.Width + FToolOffset; FTableToolBar.Top = vPt.Y;// - FTableToolBar.Height + FToolOffset; FTableToolBar.Visible = true; } else if (FUseImageTool && (aItem is HCImageItem) && (FImageToolBar.Controls.Count > 0)) { FActiveItem = aItem; (FActiveItem as HCImageItem).ShapeManager.OnStructOver = DoImageShapeStructOver; FImageToolBar.Left = vPt.X; FImageToolBar.Top = vPt.Y - FImageToolBar.Height + FToolOffset; FImageToolBar.Visible = true; } else { FActiveItem = null; } } else { FActiveItem = null; } } else if ((FActiveItem != null) && (!FActiveItem.Active)) { if (FUseTableTool && (FActiveItem is HCTableItem)) { FTableToolBar.Visible = false; } else if (FUseImageTool && (FActiveItem is HCImageItem)) { FImageToolBar.Visible = false; } FActiveItem = null; } }
public override void Assign(HCCustomItem source) { base.Assign(source); FText = (source as HCTextItem).Text; }
protected override void DoSectionRemoveItem(object sender, HCCustomData aData, HCCustomItem aItem) { base.DoSectionRemoveItem(sender, aData, aItem); if (aItem == FActiveItem) { FState = HCToolState.hcsRemoveItem; try { CancelActiveToolItem(); } finally { FState = HCToolState.hcsNone; } } }
public override void Assign(HCCustomItem source) { base.Assign(source); FImage = new Bitmap((source as HCImageItem).Image); }