|
@@ -37,9 +37,6 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
{
|
|
|
public AnnotAttribEvent AnnotAttribEvent { get; set; }
|
|
|
|
|
|
- private AnnotPropertyPanel PropertyPanel;
|
|
|
- private AnnotArgsType annotType;
|
|
|
-
|
|
|
private LinkAnnotArgs linkAnnotArgs;
|
|
|
|
|
|
public LinkAnnotArgs LinkAnnotArgs
|
|
@@ -64,6 +61,8 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private AnnotArgsType annotType;
|
|
|
+
|
|
|
public AnnotArgsType AnnotType
|
|
|
{
|
|
|
get { return annotType; }
|
|
@@ -415,7 +414,8 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
|
|
|
private bool isLoaded = false;
|
|
|
private bool isMail = false;
|
|
|
- private bool isTextChanged = false;
|
|
|
+ private bool isSelected = false;
|
|
|
+
|
|
|
private string historyBtnGOorBackTag = string.Empty;
|
|
|
private int totalPage = 0;
|
|
|
private int backPageIndex = 0;
|
|
@@ -425,6 +425,11 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
private CPDFDocument document;
|
|
|
private Button btnGOorBack = null;
|
|
|
private LinkAnnotProperty linkAnnot;
|
|
|
+ private AnnotPropertyPanel propertyPanel;
|
|
|
+ private ViewContentViewModel viewContentViewModel;
|
|
|
+
|
|
|
+ #region 命令
|
|
|
+
|
|
|
public DelegateCommand<object> LoadedCommand { get; set; }
|
|
|
public DelegateCommand<object> PageNumTextLostFocusCommand { get; set; }
|
|
|
|
|
@@ -434,6 +439,8 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
|
|
|
public DelegateCommand<object> ToggleButtonTabCommand { get; set; }
|
|
|
|
|
|
+ #endregion 命令
|
|
|
+
|
|
|
public LinkAnnotPropertyViewModel()
|
|
|
{
|
|
|
LoadedCommand = new DelegateCommand<object>(Loaded);
|
|
@@ -445,6 +452,10 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
isLoaded = true;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 页码文本框 Enter键
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="obj"></param>
|
|
|
private void PageNumTextKeyDown(object obj)
|
|
|
{
|
|
|
if (obj is KeyEventArgs keyEventArgs)
|
|
@@ -456,29 +467,45 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 页码文本框失去焦点
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="obj"></param>
|
|
|
private void PageNumTextLostFocus(object obj)
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(PageNumTextContent))
|
|
|
{
|
|
|
if (CheckPageNumVaild(out int pageNum, PageNumTextContent))
|
|
|
{
|
|
|
+ //isSelected = true;
|
|
|
+
|
|
|
AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkType, LINK_TYPE.GOTO);
|
|
|
AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkDestIndx, pageNum - 1);
|
|
|
AnnotAttribEvent?.UpdateAnnot();
|
|
|
|
|
|
- LinkAnnotArgs?.InvokeLinkSaveCalled(this, EventArgs.Empty);
|
|
|
//isTextChanged = false;
|
|
|
SetImagePreview(LinkAnnotArgs.DestIndex);
|
|
|
+ //ImagePreviewVisibility = Visibility.Collapsed;
|
|
|
+ //BtnGOorBackVisibility= Visibility.Collapsed;
|
|
|
BtnLocationIsEnabled = false;
|
|
|
+
|
|
|
+ LinkAnnotArgs?.InvokeLinkSaveCalled(this, EventArgs.Empty);
|
|
|
+
|
|
|
+ SelectAnnotation();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ImagePreviewVisibility = Visibility.Collapsed;
|
|
|
BtnGOorBackVisibility = Visibility.Collapsed;
|
|
|
+ isSelected = false;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 模块选择
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="obj"></param>
|
|
|
private void ToggleButtonTabSelected(object obj)
|
|
|
{
|
|
|
if (obj is RadioButton radioButton)
|
|
@@ -506,65 +533,69 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
break;
|
|
|
|
|
|
case "Web":
|
|
|
- LinkAnnotArgs.LinkType = LINK_TYPE.URI;
|
|
|
- LinkAnnotArgs.URI = string.Empty;
|
|
|
- AnnotAttribEvent.Attribs[AnnotAttrib.LinkType] = LINK_TYPE.URI;
|
|
|
- AnnotAttribEvent.Attribs[AnnotAttrib.LinkUri] = string.Empty;
|
|
|
isMail = false;
|
|
|
- if (btnGOorBack != null)
|
|
|
- {
|
|
|
- historyBtnGOorBackTag = btnGOorBack.Tag.ToString();
|
|
|
- ChangeBtnGOorBack("GO", btnGOorBack);
|
|
|
- }
|
|
|
+ SetLinkType_URIState("Web");
|
|
|
|
|
|
- BtnGOorBackVisibility = string.IsNullOrEmpty(PageWebTextContent) ? Visibility.Collapsed : Visibility.Visible;
|
|
|
break;
|
|
|
|
|
|
case "Mail":
|
|
|
- LinkAnnotArgs.LinkType = LINK_TYPE.URI;
|
|
|
- LinkAnnotArgs.URI = string.Empty;
|
|
|
- AnnotAttribEvent.Attribs[AnnotAttrib.LinkType] = LINK_TYPE.URI;
|
|
|
- AnnotAttribEvent.Attribs[AnnotAttrib.LinkUri] = string.Empty;
|
|
|
isMail = true;
|
|
|
- if (btnGOorBack != null)
|
|
|
+ SetLinkType_URIState("Mail");
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 设置BtnGOorBack状态
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="uri"></param>
|
|
|
+ private void SetLinkType_URIState(string uri)
|
|
|
+ {
|
|
|
+ LinkAnnotArgs.LinkType = LINK_TYPE.URI;
|
|
|
+ LinkAnnotArgs.URI = string.Empty;
|
|
|
+ AnnotAttribEvent.Attribs[AnnotAttrib.LinkType] = LINK_TYPE.URI;
|
|
|
+ AnnotAttribEvent.Attribs[AnnotAttrib.LinkUri] = string.Empty;
|
|
|
+
|
|
|
+ if (btnGOorBack != null)
|
|
|
+ {
|
|
|
+ historyBtnGOorBackTag = btnGOorBack.Tag.ToString();
|
|
|
+ //ChangeBtnGOorBack("GO", btnGOorBack);
|
|
|
+ switch (uri)
|
|
|
+ {
|
|
|
+ case "Web":
|
|
|
+ if (!string.IsNullOrEmpty(PageWebTextContent))
|
|
|
{
|
|
|
- historyBtnGOorBackTag = btnGOorBack.Tag.ToString();
|
|
|
ChangeBtnGOorBack("GO", btnGOorBack);
|
|
|
}
|
|
|
- BtnGOorBackVisibility = string.IsNullOrEmpty(PageMailTextContent) ? Visibility.Collapsed : Visibility.Visible;
|
|
|
|
|
|
+ BtnGOorBackVisibility = string.IsNullOrEmpty(PageWebTextContent) ? Visibility.Collapsed : Visibility.Visible;
|
|
|
break;
|
|
|
|
|
|
- default:
|
|
|
- LinkAnnotArgs.LinkType = LINK_TYPE.GOTO;
|
|
|
- AnnotAttribEvent.Attribs[AnnotAttrib.LinkType] = LINK_TYPE.GOTO;
|
|
|
- isMail = false;
|
|
|
- if (btnGOorBack != null)
|
|
|
+ case "Mail":
|
|
|
+ if (!string.IsNullOrEmpty(PageMailTextContent))
|
|
|
{
|
|
|
- if (!string.IsNullOrEmpty(historyBtnGOorBackTag))
|
|
|
- {
|
|
|
- ChangeBtnGOorBack(historyBtnGOorBackTag, btnGOorBack);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- ChangeBtnGOorBack("GO", btnGOorBack);
|
|
|
- }
|
|
|
+ ChangeBtnGOorBack("GO", btnGOorBack);
|
|
|
}
|
|
|
- BtnGOorBackVisibility = string.IsNullOrEmpty(PageNumTextContent) ? Visibility.Collapsed : Visibility.Visible;
|
|
|
+
|
|
|
+ BtnGOorBackVisibility = string.IsNullOrEmpty(PageMailTextContent) ? Visibility.Collapsed : Visibility.Visible;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 定位
|
|
|
+ /// 定位目标范围
|
|
|
/// </summary>
|
|
|
/// <param name="obj"></param>
|
|
|
private void LocationPage(object obj)
|
|
|
{
|
|
|
+ pdfViewer.EnableDrawSelectArea(true);
|
|
|
historyPageIndex = pdfViewer.CurrentIndex;
|
|
|
PageNumTextIsEnabled = false;
|
|
|
- pdfViewer.EnableDrawSelectArea(true);
|
|
|
+ isSelected = false;
|
|
|
+ viewContentViewModel.LinkAnnotTipVisibility=Visibility.Visible;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -600,6 +631,9 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 保存邮件链接
|
|
|
+ /// </summary>
|
|
|
private void LinkMailSave()
|
|
|
{
|
|
|
if (CheckPageMailVaild(PageMailTextContent))
|
|
@@ -614,6 +648,9 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 保存web链接
|
|
|
+ /// </summary>
|
|
|
private void LinkWebSave()
|
|
|
{
|
|
|
if (CheckPageWebVaild(PageWebTextContent))
|
|
@@ -639,6 +676,9 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 页码链接 GoOrBack
|
|
|
+ /// </summary>
|
|
|
private void LinkPageGoOrBack()
|
|
|
{
|
|
|
int pageIndex = Convert.ToInt32(PageNumTextContent) - 1;
|
|
@@ -656,8 +696,28 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- pdfViewer.GoToPage(historyPageIndex);
|
|
|
- ChangeBtnGOorBack("GO", btnGOorBack);
|
|
|
+ if (historyPageIndex != -1)
|
|
|
+ {
|
|
|
+ SelectAnnotation();
|
|
|
+ pdfViewer.GoToPage(historyPageIndex);
|
|
|
+ ChangeBtnGOorBack("GO", btnGOorBack);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 选择注释
|
|
|
+ /// </summary>
|
|
|
+ private void SelectAnnotation()
|
|
|
+ {
|
|
|
+ if (linkAnnotArgs != null && !isSelected && linkAnnotArgs.AnnotIndex >= 0)
|
|
|
+ {
|
|
|
+ pdfViewer.SelectAnnotation(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex);
|
|
|
+ isSelected = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ isSelected = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -685,24 +745,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void PageNumTextChanged(object obj)
|
|
|
- {
|
|
|
- if (obj is TextChangedEventArgs textChangedEventArgs)
|
|
|
- {
|
|
|
- if (textChangedEventArgs.Source is TextBoxWithTip textBox)
|
|
|
- {
|
|
|
- int pageNum = -1;
|
|
|
- //if (CheckPageNumVaild(out pageNum))
|
|
|
- //{
|
|
|
- // if (AnnotArgs != null)
|
|
|
- // {
|
|
|
- // AnnotArgs.DestIndex = pageNum - 1;
|
|
|
- // SetImagePreview();
|
|
|
- // }
|
|
|
- //}
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
/// <summary>
|
|
|
/// 页码格式验证
|
|
@@ -741,6 +784,11 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// web链接格式验证
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="text"></param>
|
|
|
+ /// <returns></returns>
|
|
|
private bool CheckPageWebVaild(string text)
|
|
|
{
|
|
|
BtnGOorBackVisibility = Visibility.Collapsed;
|
|
@@ -771,6 +819,11 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 邮箱链接格式验证
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="text"></param>
|
|
|
+ /// <returns></returns>
|
|
|
private bool CheckPageMailVaild(string text)
|
|
|
{
|
|
|
BtnGOorBackVisibility = Visibility.Collapsed;
|
|
@@ -833,12 +886,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
/// <param name="e"></param>
|
|
|
private void linkAnnotArgs_LinkDrawFinished(object sender, bool e)
|
|
|
{
|
|
|
- //linkAnnot.SetTextBoxEnableOrNot(e, totalPage);
|
|
|
- //AnnotArgs.DestIndex = -1;
|
|
|
- //AnnotAttribEvent.Attribs[AnnotAttrib.LinkDestIndx] =- 1;
|
|
|
SetTextBoxEnableOrNot(e, totalPage);
|
|
|
-
|
|
|
- //AnnotArgs = (LinkAnnotArgs)PropertyPanel.annot;
|
|
|
}
|
|
|
|
|
|
private void Loaded(object obj)
|
|
@@ -864,16 +912,17 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
|
|
|
public void OnNavigatedTo(NavigationContext navigationContext)
|
|
|
{
|
|
|
- navigationContext.Parameters.TryGetValue<AnnotPropertyPanel>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
|
|
|
+ navigationContext.Parameters.TryGetValue<AnnotPropertyPanel>(ParameterNames.PropertyPanelContentViewModel, out propertyPanel);
|
|
|
navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfViewer);
|
|
|
+ navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
|
|
|
|
|
|
- if (PropertyPanel != null && pdfViewer != null)
|
|
|
+ if (propertyPanel != null && pdfViewer != null)
|
|
|
{
|
|
|
pdfViewer.CustomNotifyHandler -= PDFViewer_CustomNotifyHandler;
|
|
|
|
|
|
pdfViewer.CustomNotifyHandler += PDFViewer_CustomNotifyHandler;
|
|
|
- AnnotAttribEvent = PropertyPanel.AnnotEvent;
|
|
|
- AnnotType = PropertyPanel.annot.EventType;
|
|
|
+ AnnotAttribEvent = propertyPanel.AnnotEvent;
|
|
|
+ AnnotType = propertyPanel.annot.EventType;
|
|
|
|
|
|
document = pdfViewer.Document;
|
|
|
totalPage = pdfViewer.Document.PageCount;
|
|
@@ -909,12 +958,17 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
|
|
|
if (LinkAnnotArgs == null)
|
|
|
{
|
|
|
- LinkAnnotArgs = (LinkAnnotArgs)PropertyPanel.annot;
|
|
|
+ LinkAnnotArgs = (LinkAnnotArgs)propertyPanel.annot;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void PDFViewer_CustomNotifyHandler(object sender, CustomNotityData e)
|
|
|
+ /// <summary>
|
|
|
+ /// 定位目标范围完成时,触发
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="sender"></param>
|
|
|
+ /// <param name="e"></param>
|
|
|
+ private async void PDFViewer_CustomNotifyHandler(object sender, CustomNotityData e)
|
|
|
{
|
|
|
if (e.NotifyType == CustomNotifyType.LinkAreaLocate)
|
|
|
{
|
|
@@ -928,22 +982,31 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
linkArgs.DestIndex = areaInfo.PageIndex;
|
|
|
linkArgs.DestinationPos = new System.Windows.Point(areaInfo.Area.X, pageSize.Height - areaInfo.Area.Y);
|
|
|
|
|
|
+ LinkAnnotArgs = linkArgs;
|
|
|
+ LinkAnnotArgs.PageIndex = historyPageIndex;
|
|
|
+
|
|
|
AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkType, LINK_TYPE.GOTO);
|
|
|
AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkDestIndx, areaInfo.PageIndex);
|
|
|
AnnotAttribEvent?.UpdateAnnot();
|
|
|
|
|
|
- linkArgs.InvokeLinkSaveCalled(this, EventArgs.Empty);
|
|
|
+ LinkAnnotArgs.InvokeLinkSaveCalled(this, EventArgs.Empty);
|
|
|
|
|
|
- pdfViewer.GoToPage(historyPageIndex);
|
|
|
- LinkAnnotArgs = linkArgs;
|
|
|
- LinkAnnotArgs.PageIndex = historyPageIndex;
|
|
|
PageNumTextContent = (areaInfo.PageIndex + 1).ToString();
|
|
|
SetImagePreview(areaInfo.PageIndex);
|
|
|
+
|
|
|
+ await System.Threading.Tasks.Task.Delay(2);
|
|
|
+ SelectAnnotation();
|
|
|
+
|
|
|
+ pdfViewer.GoToPage(historyPageIndex);
|
|
|
+ viewContentViewModel.LinkAnnotTipVisibility = Visibility.Collapsed;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 选择链接后,显示参数
|
|
|
+ /// </summary>
|
|
|
private void GetAnnotAttribute()
|
|
|
{
|
|
|
if (AnnotAttribEvent.Attribs.ContainsKey(AnnotAttrib.LinkType))
|
|
@@ -1061,6 +1124,11 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 设置文本框和按钮的属性
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="enable"></param>
|
|
|
+ /// <param name="totalPage"></param>
|
|
|
private void SetTextBoxEnableOrNot(bool enable, int totalPage)
|
|
|
{
|
|
|
this.totalPage = totalPage;
|
|
@@ -1086,6 +1154,16 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
BtnLocationIsEnabled = enable;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 将PDF的页面转换成数据流
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="document"></param>
|
|
|
+ /// <param name="pageIndex"></param>
|
|
|
+ /// <param name="renderRect"></param>
|
|
|
+ /// <param name="currentZoom"></param>
|
|
|
+ /// <param name="renderAnnot"></param>
|
|
|
+ /// <param name="renderForm"></param>
|
|
|
+ /// <returns></returns>
|
|
|
public byte[] RenderPDFPageToArray(CPDFDocument document, int pageIndex, Rect renderRect, double currentZoom, bool renderAnnot = false, bool renderForm = false)
|
|
|
{
|
|
|
if (renderRect.Width <= 0 || renderRect.Height <= 0 || document == null)
|
|
@@ -1115,6 +1193,13 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 获取页面的矩形
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="document"></param>
|
|
|
+ /// <param name="pageIndex"></param>
|
|
|
+ /// <param name="displayBox"></param>
|
|
|
+ /// <returns></returns>
|
|
|
private Rect GetPageRect(CPDFDocument document, int pageIndex, CPDFDisplayBox displayBox)
|
|
|
{
|
|
|
CPDFPage currentPage = document.PageAtIndex(pageIndex);
|
|
@@ -1126,6 +1211,12 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
return boundRect;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 获取页面的尺寸
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="document"></param>
|
|
|
+ /// <param name="pageIndex"></param>
|
|
|
+ /// <returns></returns>
|
|
|
private System.Windows.Size GetPageSize(CPDFDocument document, int pageIndex)
|
|
|
{
|
|
|
System.Windows.Size pageSize = document.GetPageSize(pageIndex);
|