CPDFViewModeUI.xaml.cs 8.8 KB

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