123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- using ComPDFKit.Tool.DrawTool;
- using ComPDFKit.Tool.Help;
- using ComPDFKit.Viewer.Layer;
- using ComPDFKitViewer.Layer;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Input;
- namespace ComPDFKit.Tool
- {
- public class MultiSelectedData
- {
- public int PageIndex { get; set; }
- public List<int> MultiObjectIndex { get; set; }
- /// <summary>
- /// Current multi-select type
- /// </summary>
- public SelectedType ObjectType { get; set; }
- /// <summary>
- /// Move offset value of the whole
- /// </summary>
- public Point MoveOffset { get; set; }
- public float ZoomX { get; set; }
- public float ZoomY { get; set; }
- }
- public partial class CPDFViewerTool
- {
- int multiSelectedRectViewTag = -1;
- List<int> editAreaMultiIndex = new List<int>();
- int multiPage = -1;
- public event EventHandler<MultiSelectedData> MultiDataChanging;
- public event EventHandler<MultiSelectedData> MultiDataChanged;
- private void InsertMultiSelectedRectView()
- {
- int selectedRectViewIndex = PDFViewer.GetMaxViewIndex();
- CustomizeLayer customizeLayer = new CustomizeLayer();
- MultiSelectedRect multiSelectedRect = new MultiSelectedRect(GetDefaultDrawParam(), SelectedType.None);
- multiSelectedRect.SetDrawMoveType(DrawMoveType.kReferenceLine);
- customizeLayer.Children.Add(multiSelectedRect);
- multiSelectedRect.DataChanged += MultiSelectedRect_DataChanged;
- multiSelectedRect.DataChanging += MultiSelectedRect_DataChanging;
- PDFViewer.InsertView(selectedRectViewIndex, customizeLayer);
- multiSelectedRectViewTag = customizeLayer.GetResTag();
- //multiSelectedRect.Children.Add(multiSelectedRect);
- }
- private void MultiSelectedRect_DataChanging(object sender, Point e)
- {
- MultiSelectedData multiSelectedAnnotData = new MultiSelectedData();
- MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(multiSelectedRectViewTag));
- if (isOpen && multiSelectedRect != null)
- {
- multiSelectedAnnotData.ZoomX = multiSelectedRect.GetZoomX();
- multiSelectedAnnotData.ZoomY = multiSelectedRect.GetZoomY();
- multiSelectedAnnotData.MoveOffset = e;
- multiSelectedAnnotData.ObjectType = multiSelectedRect.GetSelectedType();
- multiSelectedAnnotData.MultiObjectIndex = new List<int>();
- multiSelectedAnnotData.MultiObjectIndex.AddRange(editAreaMultiIndex);
- multiSelectedAnnotData.PageIndex = multiPage;
- MultiDataChanging?.Invoke(this, multiSelectedAnnotData);
- }
- }
- private void MultiSelectedRect_DataChanged(object sender, Point e)
- {
- MultiSelectedData multiSelectedAnnotData = new MultiSelectedData();
- MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(multiSelectedRectViewTag));
- if (isOpen && multiSelectedRect != null)
- {
- multiSelectedAnnotData.ZoomX = multiSelectedRect.GetZoomX();
- multiSelectedAnnotData.ZoomY = multiSelectedRect.GetZoomY();
- multiSelectedAnnotData.MoveOffset = e;
- multiSelectedAnnotData.ObjectType = multiSelectedRect.GetSelectedType();
- multiSelectedAnnotData.MultiObjectIndex = new List<int>();
- multiSelectedAnnotData.MultiObjectIndex.AddRange(editAreaMultiIndex);
- multiSelectedAnnotData.PageIndex = multiPage;
- MultiDataChanged?.Invoke(this, multiSelectedAnnotData);
- }
- }
- bool isOpen = false;
- public void OpenSelectedMulti(bool open)
- {
- if (!open)
- {
- CleanSelectedMultiRect();
- }
- isOpen = open;
- }
- public bool HitTestMultiSelectedRect()
- {
- MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(multiSelectedRectViewTag));
- if (isOpen && multiSelectedRect != null)
- {
- if (multiSelectedRect.GetHitControlIndex(Mouse.GetPosition(this)) != PointControlType.None)
- {
- return true;
- }
- }
- return false;
- }
- public void SelectedMultiRect(Rect selectedRects, Rect MaxRect, SelectedType type)
- {
- MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(multiSelectedRectViewTag));
- if (isOpen && multiSelectedRect != null)
- {
- GetSelectedEditAreaForIndex(out int pageIndex, out int editAreaIndex);
- if (multiPage != pageIndex && editAreaMultiIndex.Count > 0)
- {
- foreach (int item in editAreaMultiIndex)
- {
- SelectedRect OldRect = GetEditAreaForIndex(multiPage, item);
- if (OldRect != null)
- {
- OldRect.Draw();
- }
- }
- editAreaMultiIndex.Clear();
- multiSelectedRect.ClearDraw();
- multiSelectedRect.CleanMulitSelectedRect();
- multiPage = pageIndex;
- }
- multiPage = pageIndex;
- editAreaMultiIndex.Add(editAreaIndex);
- multiSelectedRect.SetSelectedType(type);
- SelectedRect selectedRect = new SelectedRect(GetDefaultDrawParam(), type);
- selectedRect.SetDrawMoveType(DrawMoveType.kReferenceLine);
- selectedRect.SetRect(selectedRects,currentZoom);
- selectedRect.SetMaxRect(MaxRect);
- multiSelectedRect.Children.Add(selectedRect);
- multiSelectedRect.SetMulitSelectedRect(selectedRect);
- multiSelectedRect.SetRect(selectedRects);
- multiSelectedRect.SetMaxRect(MaxRect);
- multiSelectedRect.Draw();
- }
- }
- public void HideDrawSelectedMultiRect()
- {
- foreach (int item in editAreaMultiIndex)
- {
- SelectedRect OldRect = GetEditAreaForIndex(multiPage, item);
- if (OldRect != null)
- {
- OldRect.HideDraw();
- }
- }
- }
- public void CleanSelectedMultiRect()
- {
- MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(multiSelectedRectViewTag));
- if (multiSelectedRect != null)
- {
- multiSelectedRect.Children.Clear();
- multiSelectedRect.CleanMulitSelectedRect();
- editAreaMultiIndex.Clear();
- }
- }
- public void DrawStartSelectedMultiRect()
- {
- MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(multiSelectedRectViewTag));
- if (multiSelectedRect != null)
- {
- Point point = Mouse.GetPosition(this);
- multiSelectedRect.Draw();
- multiSelectedRect.OnMouseLeftButtonDown(point);
- }
- }
- public void DrawMoveSelectedMultiRect()
- {
- MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(multiSelectedRectViewTag));
- if (multiSelectedRect != null)
- {
- Point point = Mouse.GetPosition(this);
- multiSelectedRect.OnMouseMove(point, out bool Tag, PDFViewer.ActualWidth, PDFViewer.ActualHeight);
- }
- }
- public void DrawEndSelectedMultiRect()
- {
- MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(multiSelectedRectViewTag));
- if (multiSelectedRect != null)
- {
- Point point = Mouse.GetPosition(this);
- multiSelectedRect.OnMouseLeftButtonUp(point);
- }
- }
- public void ReDrawSelectedMultiRect()
- {
- MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(multiSelectedRectViewTag));
- if (multiSelectedRect != null)
- {
- multiSelectedRect.ClearDraw();
- multiSelectedRect.CleanMulitSelectedRect();
- Point point = Mouse.GetPosition(this);
- switch (multiSelectedRect.GetSelectedType())
- {
- case SelectedType.Annot:
- SelectAnnot();
- break;
- case SelectedType.PDFEdit:
- SelectPDFEdit(multiSelectedRect);
- break;
- default:
- break;
- }
- multiSelectedRect.Draw();
- }
- }
- private void SelectAnnot()
- {
- CleanSelectedRect();
- }
- private void SelectPDFEdit(MultiSelectedRect multiSelectedRect)
- {
- foreach (int item in editAreaMultiIndex)
- {
- SelectedRect OldRect = GetEditAreaForIndex(multiPage, item);
- if (OldRect != null)
- {
- multiSelectedRect.SetSelectedType(SelectedType.PDFEdit);
- SelectedRect selectedRect = new SelectedRect(GetDefaultDrawParam(), SelectedType.PDFEdit);
- selectedRect.SetDrawMoveType(DrawMoveType.kReferenceLine);
- selectedRect.SetRect(OldRect.GetRect(),currentZoom);
- selectedRect.SetMaxRect(OldRect.GetMaxRect());
- multiSelectedRect.Children.Add(selectedRect);
- multiSelectedRect.SetMulitSelectedRect(selectedRect);
- multiSelectedRect.SetRect(OldRect.GetRect());
- multiSelectedRect.SetMaxRect(OldRect.GetMaxRect());
- OldRect.HideDraw();
- }
- }
- }
- }
- }
|