CPDFDisplaySettingsControl.xaml.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using Compdfkit_Tools.PDFControlUI;
  2. using ComPDFKitViewer;
  3. using ComPDFKitViewer.PdfViewer;
  4. using System.Collections.Generic;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. namespace Compdfkit_Tools.PDFControl
  8. {
  9. public partial class CPDFDisplaySettingsControl : UserControl
  10. {
  11. /// <summary>
  12. /// PDFViewer
  13. /// </summary>
  14. private CPDFViewer pdfView;
  15. public CPDFDisplaySettingsControl()
  16. {
  17. InitializeComponent();
  18. Loaded += CPDFDisplaySettingsControl_Loaded;
  19. }
  20. private void CPDFDisplaySettingsControl_Loaded(object sender, RoutedEventArgs e)
  21. {
  22. ViewModeUI.ViewModeChanged += ViewModeUI_ViewModeChanged;
  23. ViewModeUI.SplitModeChanged += ViewModeUI_SplitModeChanged;
  24. ViewModeUI.CropModeChanged += ViewModeUI_CropModeChanged;
  25. DrawModeUI.DrawModeChanged += DrawModeUI_DrawModeChanged;
  26. }
  27. private void ViewModeUI_CropModeChanged(object sender, bool e)
  28. {
  29. pdfView?.SetCropMode(e);
  30. }
  31. private void DrawModeUI_DrawModeChanged(object sender, DrawModeData e)
  32. {
  33. if (e.DrawMode != DrawModes.Draw_Mode_Custom)
  34. {
  35. pdfView?.SetDrawMode(e.DrawMode);
  36. pdfView?.ReloadDocument();
  37. }
  38. else
  39. {
  40. pdfView?.SetDrawMode(e.DrawMode,e.CustomColor);
  41. pdfView?.ReloadDocument();
  42. }
  43. }
  44. private void ViewModeUI_SplitModeChanged(object sender, SplitMode e)
  45. {
  46. pdfView?.SetSplitMode(e);
  47. }
  48. private void ViewModeUI_ViewModeChanged(object sender, ViewMode e)
  49. {
  50. pdfView?.ChangeViewMode(e);
  51. }
  52. public void InitWithPDFViewer(CPDFViewer newPDFView)
  53. {
  54. pdfView = newPDFView;
  55. if(pdfView != null)
  56. {
  57. pdfView.InfoChanged -= PdfView_InfoChanged;
  58. pdfView.InfoChanged += PdfView_InfoChanged;
  59. ViewModeUI.SetSplitModeUI(pdfView.Mode);
  60. ViewModeUI.SetViewModeUI(pdfView.ModeView);
  61. ViewModeUI.SetCropUI(pdfView.IsCropMode());
  62. }
  63. }
  64. public void SetVisibilityWhenContentEdit(Visibility visible)
  65. {
  66. ViewModeUI?.SetSplitContainerVisibility(visible);
  67. ViewModeUI?.SetCropContainerVisibility(visible);
  68. }
  69. private void PdfView_InfoChanged(object sender, KeyValuePair<string, object> e)
  70. {
  71. if (e.Key == "ActiveViewIndex")
  72. {
  73. if (pdfView != null)
  74. {
  75. ViewModeUI.SetSplitModeUI(pdfView.Mode);
  76. ViewModeUI.SetViewModeUI(pdfView.ModeView);
  77. ViewModeUI.SetCropUI(pdfView.IsCropMode());
  78. }
  79. }
  80. }
  81. }
  82. }