CPDFViewModeUI.xaml.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. using ComPDFKitViewer;
  2. using ComPDFKitViewer.PdfViewer;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Controls.Primitives;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Navigation;
  17. using System.Windows.Shapes;
  18. namespace Compdfkit_Tools.PDFControlUI
  19. {
  20. public partial class CPDFViewModeUI : UserControl
  21. {
  22. public event EventHandler<string> SetContinuousEvent;
  23. public event EventHandler<string> SetViewModeEvent;
  24. public event EventHandler<SplitMode> SplitModeChanged;
  25. public event EventHandler<ViewMode> ViewModeChanged;
  26. public event EventHandler<bool> CropModeChanged;
  27. private SolidColorBrush ActivePathBrush = new SolidColorBrush(Color.FromRgb(0x14,0x60,0xF3));
  28. private SolidColorBrush NormalPathBrush = new SolidColorBrush(Color.FromRgb(0x99, 0x99, 0x99));
  29. public CPDFViewModeUI()
  30. {
  31. InitializeComponent();
  32. }
  33. private void ViewModeRadioButton_Checked(object sender, RoutedEventArgs e)
  34. {
  35. var viewModeRadioButton = sender as RadioButton;
  36. SetViewModeEvent?.Invoke(sender, viewModeRadioButton.Tag as string);
  37. }
  38. private void ContinuousRadioButton_Click(object sender, RoutedEventArgs e)
  39. {
  40. var continuousRadioButton = sender as RadioButton;
  41. SetContinuousEvent?.Invoke(sender,(continuousRadioButton.Tag as string));
  42. }
  43. private void HorizonBtn_Click(object sender, RoutedEventArgs e)
  44. {
  45. VerticalBtn.IsChecked = false;
  46. HorizonPath.Fill = HorizonBtn.IsChecked == true ? ActivePathBrush : NormalPathBrush;
  47. VerticalPath.Fill = NormalPathBrush;
  48. SplitModeChanged?.Invoke(this, HorizonBtn.IsChecked == true ? SplitMode.Horizontal:SplitMode.None);
  49. }
  50. private void VerticalBtn_Click(object sender, RoutedEventArgs e)
  51. {
  52. HorizonBtn.IsChecked = false;
  53. HorizonPath.Fill = NormalPathBrush;
  54. VerticalPath.Fill = VerticalBtn.IsChecked == true ? ActivePathBrush : NormalPathBrush;
  55. SplitModeChanged?.Invoke(this, VerticalBtn.IsChecked == true ? SplitMode.Vertical : SplitMode.None);
  56. }
  57. private void ClearViewState()
  58. {
  59. List<ToggleButton> viewBtnList = new List<ToggleButton>()
  60. {
  61. SingleViewBtn,
  62. DoubleViewBtn,
  63. BookViewBtn,
  64. };
  65. List<Path> viewPathList = new List<Path>()
  66. {
  67. BookViewPath,
  68. DoubleViewPath,
  69. SingleViewPath
  70. };
  71. foreach (ToggleButton item in viewBtnList)
  72. {
  73. item.IsChecked = false;
  74. }
  75. foreach(Path path in viewPathList)
  76. {
  77. path.Fill = NormalPathBrush;
  78. }
  79. }
  80. private void BookViewBtn_Click(object sender, RoutedEventArgs e)
  81. {
  82. ClearViewState();
  83. BookViewBtn.IsChecked = true;
  84. BookViewPath.Fill = ActivePathBrush;
  85. ViewModeChanged?.Invoke(this, ContinuePageBtn.IsChecked==true? ViewMode.BookContinuous:ViewMode.Book);
  86. }
  87. private void DoubleViewBtn_Click(object sender, RoutedEventArgs e)
  88. {
  89. ClearViewState();
  90. DoubleViewBtn.IsChecked = true;
  91. DoubleViewPath.Fill = ActivePathBrush;
  92. ViewModeChanged?.Invoke(this, ContinuePageBtn.IsChecked == true ? ViewMode.DoubleContinuous:ViewMode.Double);
  93. }
  94. private void SingleViewBtn_Click(object sender, RoutedEventArgs e)
  95. {
  96. ClearViewState();
  97. SingleViewBtn.IsChecked = true;
  98. SingleViewPath.Fill = ActivePathBrush;
  99. ViewModeChanged?.Invoke(this, ContinuePageBtn.IsChecked == true ? ViewMode.SingleContinuous:ViewMode.Single);
  100. }
  101. private void CropModeBtn_Click(object sender, RoutedEventArgs e)
  102. {
  103. CropModeChanged?.Invoke(this, CropModeBtn.IsChecked == true);
  104. }
  105. private void ContinuePageBtn_Click(object sender, RoutedEventArgs e)
  106. {
  107. if(SingleViewBtn.IsChecked==true)
  108. {
  109. ViewModeChanged?.Invoke(this, ContinuePageBtn.IsChecked == true ? ViewMode.SingleContinuous : ViewMode.Single);
  110. return;
  111. }
  112. if (DoubleViewBtn.IsChecked == true)
  113. {
  114. ViewModeChanged?.Invoke(this, ContinuePageBtn.IsChecked == true ? ViewMode.DoubleContinuous : ViewMode.Double);
  115. return;
  116. }
  117. if(BookViewBtn.IsChecked == true)
  118. {
  119. ViewModeChanged?.Invoke(this, ContinuePageBtn.IsChecked == true ? ViewMode.BookContinuous : ViewMode.Book);
  120. }
  121. }
  122. public void SetSplitModeUI(SplitMode mode)
  123. {
  124. switch(mode)
  125. {
  126. case SplitMode.None:
  127. HorizonBtn.IsChecked = false;
  128. VerticalBtn.IsChecked = false;
  129. HorizonPath.Fill = NormalPathBrush;
  130. VerticalPath.Fill = NormalPathBrush;
  131. break;
  132. case SplitMode.Vertical:
  133. VerticalBtn.IsChecked = true;
  134. HorizonBtn.IsChecked = false;
  135. HorizonPath.Fill = NormalPathBrush;
  136. VerticalPath.Fill = ActivePathBrush;
  137. break;
  138. case SplitMode.Horizontal:
  139. VerticalBtn.IsChecked = false;
  140. HorizonBtn.IsChecked = true;
  141. HorizonPath.Fill = ActivePathBrush;
  142. VerticalPath.Fill = NormalPathBrush;
  143. break;
  144. default:
  145. break;
  146. }
  147. }
  148. public void SetViewModeUI(ViewMode mode)
  149. {
  150. ClearViewState();
  151. switch (mode)
  152. {
  153. case ViewMode.Book:
  154. BookViewBtn.IsChecked = true;
  155. BookViewPath.Fill = ActivePathBrush;
  156. ContinuePageBtn.IsChecked = false;
  157. break;
  158. case ViewMode.BookContinuous:
  159. BookViewBtn.IsChecked = true;
  160. BookViewPath.Fill = ActivePathBrush;
  161. ContinuePageBtn.IsChecked = true;
  162. break;
  163. case ViewMode.Single:
  164. SingleViewBtn.IsChecked = true;
  165. SingleViewPath.Fill = ActivePathBrush;
  166. ContinuePageBtn.IsChecked = false;
  167. break;
  168. case ViewMode.SingleContinuous:
  169. SingleViewBtn.IsChecked = true;
  170. SingleViewPath.Fill = ActivePathBrush;
  171. ContinuePageBtn.IsChecked = true;
  172. break;
  173. case ViewMode.Double:
  174. DoubleViewBtn.IsChecked = true;
  175. DoubleViewPath.Fill = ActivePathBrush;
  176. ContinuePageBtn.IsChecked = false;
  177. break;
  178. case ViewMode.DoubleContinuous:
  179. DoubleViewBtn.IsChecked = true;
  180. DoubleViewPath.Fill = ActivePathBrush;
  181. ContinuePageBtn.IsChecked = true;
  182. break;
  183. default:
  184. break;
  185. }
  186. }
  187. public void SetCropUI(bool isAutoCrop)
  188. {
  189. CropModeBtn.IsChecked=isAutoCrop;
  190. }
  191. public void SetSplitContainerVisibility(Visibility visibility)
  192. {
  193. SplitContainer.Visibility = visibility;
  194. if (visibility == Visibility.Visible)
  195. {
  196. DisplayContainer.Margin = new Thickness(0,30,0,0);
  197. }
  198. else
  199. {
  200. DisplayContainer.Margin = new Thickness(0);
  201. }
  202. }
  203. public void SetCropContainerVisibility(Visibility visibility)
  204. {
  205. CropContainer.Visibility = visibility;
  206. if (visibility == Visibility.Visible)
  207. {
  208. DisplayContainer.Margin = new Thickness(0, 30, 0, 0);
  209. }
  210. else
  211. {
  212. DisplayContainer.Margin = new Thickness(0);
  213. }
  214. }
  215. }
  216. }