123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- using ComPDFKit.Tool.DrawTool;
- using ComPDFKit.Tool.Help;
- using ComPDFKit.Viewer.Layer;
- using ComPDFKitViewer.Layer;
- using System;
- using System.Windows;
- using System.Windows.Input;
- namespace ComPDFKit.Tool
- {
- public partial class CPDFViewerTool
- {
- bool IsDrawEditAnnot = false;
- int annotEditViewTag = -1;
- public event EventHandler<SelectedAnnotData> AnnotEditDataChanging;
- public event EventHandler<SelectedAnnotData> AnnotEditDataChanged;
- public event EventHandler<object> AnnotChanged;
- private void InsertAnnotEditView()
- {
- int selectedRectViewIndex = PDFViewer.GetMaxViewIndex();
- CustomizeLayer customizeLayer = new CustomizeLayer();
- AnnotEdit annotEdit = new AnnotEdit(GetDefaultDrawParam());
- annotEdit.DataChanged += AnnotEdit_DataChanged;
- annotEdit.DataChanging += AnnotEdit_DataChanging;
- customizeLayer.Children.Add(annotEdit);
- PDFViewer.InsertView(selectedRectViewIndex, customizeLayer);
- annotEditViewTag = customizeLayer.GetResTag();
- }
- private void AnnotEdit_DataChanging(object sender, SelectedAnnotData e)
- {
- AnnotEditDataChanging?.Invoke(this, e);
- }
- private void AnnotEdit_DataChanged(object sender, SelectedAnnotData e)
- {
- AnnotEditDataChanged?.Invoke(this, e);
- }
- public void StartDrawEditAnnot()
- {
- Point point = Mouse.GetPosition(this);
- BaseLayer baseLayer = PDFViewer.GetViewForTag(annotEditViewTag);
- AnnotEdit annotEdit = CommonHelper.FindVisualChild<AnnotEdit>(baseLayer as CustomizeLayer);
- if (annotEdit != null)
- {
- annotEdit.Draw();
- annotEdit.OnMouseLeftButtonDown(point);
- IsDrawEditAnnot = true;
- }
- }
- public bool DrawMoveEditAnnot()
- {
- bool DrawTag = false;
- Point point = Mouse.GetPosition(this);
- BaseLayer baseLayer = PDFViewer.GetViewForTag(annotEditViewTag);
- AnnotEdit annotEdit = CommonHelper.FindVisualChild<AnnotEdit>(baseLayer as CustomizeLayer);
- if (annotEdit != null)
- {
- annotEdit.OnMouseMove(point, out DrawTag);
- if (DrawTag)
- {
- annotEdit.Draw();
- }
- }
- return DrawTag;
- }
- public void DrawEndEditAnnot()
- {
- Point point = Mouse.GetPosition(this);
- BaseLayer baseLayer = PDFViewer.GetViewForTag(annotEditViewTag);
- AnnotEdit annotEdit = CommonHelper.FindVisualChild<AnnotEdit>(baseLayer as CustomizeLayer);
- if (annotEdit != null)
- {
- annotEdit.Draw();
- annotEdit.OnMouseLeftButtonUp(point);
- }
- }
- public void CleanEditAnnot()
- {
- Point point = Mouse.GetPosition(this);
- BaseLayer baseLayer = PDFViewer.GetViewForTag(annotEditViewTag);
- AnnotEdit annotEdit = CommonHelper.FindVisualChild<AnnotEdit>(baseLayer as CustomizeLayer);
- if (annotEdit != null)
- {
- annotEdit.ClearDraw();
- IsDrawEditAnnot = false;
- }
- }
- private void DrawEditAnnotLayer()
- {
- BaseLayer baseLayer = PDFViewer.GetViewForTag(annotEditViewTag);
- AnnotEdit annotEdit = CommonHelper.FindVisualChild<AnnotEdit>(baseLayer as CustomizeLayer);
- if (annotEdit != null)
- {
- annotEdit.Draw();
- }
- }
- /// <summary>
- /// Press the mouse on the selected rectangle
- /// </summary>
- /// <returns></returns>
- private bool DrawEditAnnotDownEvent()
- {
- BaseLayer baseLayer = PDFViewer.GetViewForTag(annotEditViewTag);
- AnnotEdit selectedRect = CommonHelper.FindVisualChild<AnnotEdit>(baseLayer as CustomizeLayer);
- if (selectedRect != null)
- {
- if (selectedRect.GetHitIndex(Mouse.GetPosition(this)) != -1)
- {
- return true;
- }
- }
- return false;
- }
- private void SetEditAnnotObject()
- {
- if (cacheHitTestAnnot == null)
- {
- return;
- }
- Point point = Mouse.GetPosition(this);
- BaseLayer baseLayer = PDFViewer.GetViewForTag(annotEditViewTag);
- AnnotEdit annotEdit = CommonHelper.FindVisualChild<AnnotEdit>(baseLayer as CustomizeLayer);
- if (annotEdit != null)
- {
- annotEdit.SetAnnotObject(cacheHitTestAnnot.GetAnnotData());
- }
- }
- }
- }
|