CPDFDisplaySettingsControl.xaml.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using ComPDFKit.Controls.PDFControlUI;
  2. using ComPDFKitViewer;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. namespace ComPDFKit.Controls.PDFControl
  9. {
  10. public partial class CPDFDisplaySettingsControl : UserControl
  11. {
  12. /// <summary>
  13. /// PDFViewer
  14. /// </summary>
  15. private PDFViewControl ViewControl;
  16. public event EventHandler<CPDFViewModeUI.SplitMode> SplitModeChanged;
  17. public CPDFDisplaySettingsControl()
  18. {
  19. InitializeComponent();
  20. Loaded += CPDFDisplaySettingsControl_Loaded;
  21. }
  22. private void CPDFDisplaySettingsControl_Loaded(object sender, RoutedEventArgs e)
  23. {
  24. }
  25. private void ViewModeUI_SplitModeChanged(object sender, CPDFViewModeUI.SplitMode e)
  26. {
  27. SplitModeChanged?.Invoke(this, e);
  28. }
  29. private void ViewModeUI_CropModeChanged(object sender, bool e)
  30. {
  31. if (ViewControl != null && ViewControl.PDFViewTool != null)
  32. {
  33. ViewControl?.SetCropMode(e);
  34. }
  35. }
  36. private void DrawModeUI_DrawModeChanged(object sender, DrawModeData e)
  37. {
  38. if(ViewControl!=null && ViewControl.PDFViewTool!=null)
  39. {
  40. ViewControl.SetDrawModes(e);
  41. }
  42. }
  43. private void ViewModeUI_ViewModeChanged(object sender, ViewMode e)
  44. {
  45. if (ViewControl != null && ViewControl.PDFViewTool != null)
  46. {
  47. CPDFViewer pdfViewer = ViewControl.FocusPDFViewTool.GetCPDFViewer();
  48. if (pdfViewer != null)
  49. {
  50. pdfViewer?.SetViewMode(e);
  51. }
  52. }
  53. }
  54. public void InitWithPDFViewer(PDFViewControl viewControl)
  55. {
  56. ViewControl = viewControl;
  57. ViewControl.FocusPDFViewToolChanged -= PDFViewControl_FocusPDFViewToolChanged;
  58. ViewControl.FocusPDFViewToolChanged += PDFViewControl_FocusPDFViewToolChanged;
  59. if(ViewControl != null && ViewControl.PDFViewTool!=null)
  60. {
  61. CPDFViewer pdfViewer= viewControl.PDFViewTool.GetCPDFViewer();
  62. if(pdfViewer != null)
  63. {
  64. ViewModeUI.SetViewModeUI(pdfViewer.GetViewMode());
  65. }
  66. }
  67. ViewModeUI.ViewModeChanged -= ViewModeUI_ViewModeChanged;
  68. ViewModeUI.SplitModeChanged -= ViewModeUI_SplitModeChanged;
  69. ViewModeUI.CropModeChanged -= ViewModeUI_CropModeChanged;
  70. DrawModeUI.DrawModeChanged -= DrawModeUI_DrawModeChanged;
  71. ViewModeUI.ViewModeChanged += ViewModeUI_ViewModeChanged;
  72. ViewModeUI.SplitModeChanged += ViewModeUI_SplitModeChanged;
  73. ViewModeUI.CropModeChanged += ViewModeUI_CropModeChanged;
  74. DrawModeUI.DrawModeChanged += DrawModeUI_DrawModeChanged;
  75. }
  76. private void PDFViewControl_FocusPDFViewToolChanged(object sender,EventArgs e)
  77. {
  78. if (ViewControl != null && ViewControl.PDFViewTool != null)
  79. {
  80. CPDFViewer pdfViewer = ViewControl.FocusPDFViewTool.GetCPDFViewer();
  81. if (pdfViewer != null)
  82. {
  83. ViewModeUI.SetViewModeUI(pdfViewer.GetViewMode());
  84. }
  85. }
  86. }
  87. public void SetVisibilityWhenContentEdit(Visibility visible)
  88. {
  89. ViewModeUI?.SetSplitContainerVisibility(visible);
  90. ViewModeUI?.SetCropContainerVisibility(visible);
  91. }
  92. }
  93. }