using ComPDFKit.Tool.DrawTool; using ComPDFKitViewer.Layer; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; using System.Windows; using ComPDFKit.Viewer.Layer; using System.Windows.Media; using ComPDFKit.Tool.Help; using ComPDFKitViewer; using ComPDFKit.PDFAnnotation; namespace ComPDFKit.Tool { public partial class CPDFViewerTool { internal bool isDrawSelectRect = false; int selectedRectViewTag = -1; private bool isOutSideScaling = false; public event EventHandler SelectedDataChanging; public event EventHandler SelectedDataChanged; private void InsertSelectedRectView() { int selectedRectViewIndex = PDFViewer.GetMaxViewIndex(); CustomizeLayer customizeLayer = new CustomizeLayer(); SelectedRect selectedRect = new SelectedRect(GetDefaultDrawParam(), SelectedType.Annot); selectedRect.SetDrawMoveType(DrawMoveType.kDefault); customizeLayer.Children.Add(selectedRect); selectedRect.DataChanged += SelectedRect_DataChanged; selectedRect.DataChanging += SelectedRect_DataChanging; PDFViewer.InsertView(selectedRectViewIndex, customizeLayer); selectedRectViewTag= customizeLayer.GetResTag(); } /// /// Set whether the border can be moved outside the border /// /// public void SetOutSideScaling(bool IsOutSideScaling) { isOutSideScaling = IsOutSideScaling; } private void SelectedRect_DataChanging(object sender, SelectedAnnotData e) { SelectedDataChanging?.Invoke(this, e); } private void SelectedRect_DataChanged(object sender, SelectedAnnotData e) { SelectedDataChanged?.Invoke(this, e); } /// /// Start to draw the rectangle /// public void DrawStartSelectedRect() { Point point = Mouse.GetPosition(this); BaseLayer baseLayer = PDFViewer.GetViewForTag(selectedRectViewTag); SelectedRect selectedRect = CommonHelper.FindVisualChild(baseLayer as CustomizeLayer); if (selectedRect != null) { selectedRect.Draw(); selectedRect.OnMouseLeftButtonDown(point); isDrawSelectRect = true; } } public Cursor GetMoveSelectedRectCursor() { Point point = Mouse.GetPosition(this); BaseLayer baseLayer = PDFViewer.GetViewForTag(selectedRectViewTag); SelectedRect selectedRect = CommonHelper.FindVisualChild(baseLayer as CustomizeLayer); if (selectedRect != null) { return selectedRect.GetCursor(point, this.Cursor); } return this.Cursor; } /// /// Draw the rectangle when dragging /// public bool DrawMoveSelectedRect() { bool DrawTag = false; Point point = Mouse.GetPosition(this); BaseLayer baseLayer = PDFViewer.GetViewForTag(selectedRectViewTag); SelectedRect selectedRect = CommonHelper.FindVisualChild(baseLayer as CustomizeLayer); if (selectedRect != null) { selectedRect.SetOutSideScaling(isOutSideScaling); selectedRect.OnMouseMove(point, out DrawTag,PDFViewer.ActualWidth,PDFViewer.ActualHeight); selectedRect.Draw(); } return DrawTag; } /// /// End of drawing the rectangle /// public void DrawEndSelectedRect() { Point point = Mouse.GetPosition(this); BaseLayer baseLayer = PDFViewer.GetViewForTag(selectedRectViewTag); SelectedRect selectedRect = CommonHelper.FindVisualChild(baseLayer as CustomizeLayer); if (selectedRect != null) { selectedRect.OnMouseLeftButtonUp(point); selectedRect.Draw(); } } /// /// Clear the rectangle drawing /// public void CleanSelectedRect() { Point point = Mouse.GetPosition(this); BaseLayer baseLayer = PDFViewer.GetViewForTag(selectedRectViewTag); SelectedRect selectedRect = CommonHelper.FindVisualChild(baseLayer as CustomizeLayer); if (selectedRect != null) { selectedRect.ClearDraw(); isDrawSelectRect = false; } } internal void SelectedAnnot() { if (!isHitTestLink&& cacheHitTestAnnot?.CurrentType== C_ANNOTATION_TYPE.C_ANNOTATION_LINK) { return ; } if (isHitTestRedact && cacheHitTestAnnot?.CurrentType!= C_ANNOTATION_TYPE.C_ANNOTATION_REDACT) { return ; } SelectAnnot(cacheHitTestAnnot.GetAnnotData()); } internal void SelectAnnot(AnnotData selectData) { BaseLayer baseLayer = PDFViewer.GetViewForTag(selectedRectViewTag); SelectedRect selectedRect = CommonHelper.FindVisualChild(baseLayer as CustomizeLayer); if (selectedRect != null) { selectedRect.SetAnnotData(selectData,PDFViewer); } } private void SelectedAnnot(AnnotData annotData) { BaseLayer baseLayer = PDFViewer.GetViewForTag(selectedRectViewTag); SelectedRect selectedRect = CommonHelper.FindVisualChild(baseLayer as CustomizeLayer); if (selectedRect != null) { if (annotData==null) { selectedRect.ClearDraw(); } else { selectedRect.SetAnnotData(annotData, PDFViewer); } } } /// /// Refresh the drawing /// internal void DrawSelectedLayer() { BaseLayer baseLayer = PDFViewer.GetViewForTag(selectedRectViewTag); SelectedRect selectedRect = CommonHelper.FindVisualChild(baseLayer as CustomizeLayer); if (selectedRect != null) { selectedRect.Draw(); } } /// /// Identify whether the mouse is on the rectangle /// /// internal bool DrawSelectRectDownEvent() { BaseLayer baseLayer = PDFViewer.GetViewForTag(selectedRectViewTag); SelectedRect selectedRect = CommonHelper.FindVisualChild(baseLayer as CustomizeLayer); if (selectedRect != null) { if (selectedRect.GetHitControlIndex(Mouse.GetPosition(this)) != PointControlType.None) { return true; } } return false; } } }