123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- 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
- {
- bool isDrawSelectRect = false;
- int selectedRectViewTag = -1;
- private bool isOutSideScaling = false;
- public event EventHandler<SelectedAnnotData> SelectedDataChanging;
- public event EventHandler<SelectedAnnotData> 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();
- }
- /// <summary>
- /// Set whether the border can be moved outside the border
- /// </summary>
- /// <param name="IsOutSideScaling"></param>
- 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);
- }
- /// <summary>
- /// Start to draw the rectangle
- /// </summary>
- public void DrawStartSelectedRect()
- {
- Point point = Mouse.GetPosition(this);
- BaseLayer baseLayer = PDFViewer.GetViewForTag(selectedRectViewTag);
- SelectedRect selectedRect = CommonHelper.FindVisualChild<SelectedRect>(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<SelectedRect>(baseLayer as CustomizeLayer);
- if (selectedRect != null)
- {
- return selectedRect.GetCursor(point, this.Cursor);
- }
- return this.Cursor;
- }
- /// <summary>
- /// Draw the rectangle when dragging
- /// </summary>
- public bool DrawMoveSelectedRect()
- {
- bool DrawTag = false;
- Point point = Mouse.GetPosition(this);
- BaseLayer baseLayer = PDFViewer.GetViewForTag(selectedRectViewTag);
- SelectedRect selectedRect = CommonHelper.FindVisualChild<SelectedRect>(baseLayer as CustomizeLayer);
- if (selectedRect != null)
- {
- selectedRect.SetOutSideScaling(isOutSideScaling);
- selectedRect.OnMouseMove(point, out DrawTag,PDFViewer.ActualWidth,PDFViewer.ActualHeight);
- selectedRect.Draw();
- }
- return DrawTag;
- }
- /// <summary>
- /// End of drawing the rectangle
- /// </summary>
- public void DrawEndSelectedRect()
- {
- Point point = Mouse.GetPosition(this);
- BaseLayer baseLayer = PDFViewer.GetViewForTag(selectedRectViewTag);
- SelectedRect selectedRect = CommonHelper.FindVisualChild<SelectedRect>(baseLayer as CustomizeLayer);
- if (selectedRect != null)
- {
- selectedRect.OnMouseLeftButtonUp(point);
- selectedRect.Draw();
- }
- }
- /// <summary>
- /// Clear the rectangle drawing
- /// </summary>
- public void CleanSelectedRect()
- {
- Point point = Mouse.GetPosition(this);
- BaseLayer baseLayer = PDFViewer.GetViewForTag(selectedRectViewTag);
- SelectedRect selectedRect = CommonHelper.FindVisualChild<SelectedRect>(baseLayer as CustomizeLayer);
- if (selectedRect != null)
- {
- selectedRect.ClearDraw();
- isDrawSelectRect = false;
- }
- }
- private void SelectedAnnot()
- {
- if (!isHitTestLink&& cacheHitTestAnnot?.CurrentType== C_ANNOTATION_TYPE.C_ANNOTATION_LINK)
- {
- return ;
- }
- if (isHitTestRedact && cacheHitTestAnnot?.CurrentType!= C_ANNOTATION_TYPE.C_ANNOTATION_REDACT)
- {
- return ;
- }
- BaseLayer baseLayer = PDFViewer.GetViewForTag(selectedRectViewTag);
- SelectedRect selectedRect = CommonHelper.FindVisualChild<SelectedRect>(baseLayer as CustomizeLayer);
- if (selectedRect != null)
- {
- selectedRect.SetAnnotData(cacheHitTestAnnot.GetAnnotData(), PDFViewer);
- }
- }
- private void SelectedAnnot(AnnotData annotData)
- {
- BaseLayer baseLayer = PDFViewer.GetViewForTag(selectedRectViewTag);
- SelectedRect selectedRect = CommonHelper.FindVisualChild<SelectedRect>(baseLayer as CustomizeLayer);
- if (selectedRect != null)
- {
- if (annotData==null)
- {
- selectedRect.ClearDraw();
- }
- else
- {
- selectedRect.SetAnnotData(annotData, PDFViewer);
- }
- }
- }
- /// <summary>
- /// Refresh the drawing
- /// </summary>
- private void DrawSelectedLayer()
- {
- BaseLayer baseLayer = PDFViewer.GetViewForTag(selectedRectViewTag);
- SelectedRect selectedRect = CommonHelper.FindVisualChild<SelectedRect>(baseLayer as CustomizeLayer);
- if (selectedRect != null)
- {
- selectedRect.Draw();
- }
- }
-
- /// <summary>
- /// Identify whether the mouse is on the rectangle
- /// </summary>
- /// <returns></returns>
- private bool DrawSelectRectDownEvent()
- {
- BaseLayer baseLayer = PDFViewer.GetViewForTag(selectedRectViewTag);
- SelectedRect selectedRect = CommonHelper.FindVisualChild<SelectedRect>(baseLayer as CustomizeLayer);
- if (selectedRect != null)
- {
- if (selectedRect.GetHitControlIndex(Mouse.GetPosition(this)) != PointControlType.None)
- {
- return true;
- }
- }
- return false;
- }
- }
- }
|