CPDFViewModeUI.xaml.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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_Tools.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<ViewModes> 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? ViewModes.BookContinuous: ViewModes.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 ? ViewModes.DoubleContinuous: ViewModes.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 ? ViewModes.SingleContinuous: ViewModes.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 ? ViewModes.SingleContinuous : ViewModes.Single);
  101. return;
  102. }
  103. if (DoubleViewBtn.IsChecked == true)
  104. {
  105. ViewModeChanged?.Invoke(this, ContinuePageBtn.IsChecked == true ? ViewModes.DoubleContinuous : ViewModes.Double);
  106. return;
  107. }
  108. if(BookViewBtn.IsChecked == true)
  109. {
  110. ViewModeChanged?.Invoke(this, ContinuePageBtn.IsChecked == true ? ViewModes.BookContinuous : ViewModes.Book);
  111. }
  112. }
  113. //public void SetSplitModeUI(SplitMode mode)
  114. //{
  115. // switch(mode)
  116. // {
  117. // case SplitMode.None:
  118. // HorizonBtn.IsChecked = false;
  119. // VerticalBtn.IsChecked = false;
  120. // HorizonPath.Fill = NormalPathBrush;
  121. // VerticalPath.Fill = NormalPathBrush;
  122. // break;
  123. // case SplitMode.Vertical:
  124. // VerticalBtn.IsChecked = true;
  125. // HorizonBtn.IsChecked = false;
  126. // HorizonPath.Fill = NormalPathBrush;
  127. // VerticalPath.Fill = ActivePathBrush;
  128. // break;
  129. // case SplitMode.Horizontal:
  130. // VerticalBtn.IsChecked = false;
  131. // HorizonBtn.IsChecked = true;
  132. // HorizonPath.Fill = ActivePathBrush;
  133. // VerticalPath.Fill = NormalPathBrush;
  134. // break;
  135. // default:
  136. // break;
  137. // }
  138. //}
  139. public void SetViewModeUI(ViewModes mode)
  140. {
  141. ClearViewState();
  142. switch (mode)
  143. {
  144. case ViewModes.Book:
  145. BookViewBtn.IsChecked = true;
  146. BookViewPath.Fill = ActivePathBrush;
  147. ContinuePageBtn.IsChecked = false;
  148. break;
  149. case ViewModes.BookContinuous:
  150. BookViewBtn.IsChecked = true;
  151. BookViewPath.Fill = ActivePathBrush;
  152. ContinuePageBtn.IsChecked = true;
  153. break;
  154. case ViewModes.Single:
  155. SingleViewBtn.IsChecked = true;
  156. SingleViewPath.Fill = ActivePathBrush;
  157. ContinuePageBtn.IsChecked = false;
  158. break;
  159. case ViewModes.SingleContinuous:
  160. SingleViewBtn.IsChecked = true;
  161. SingleViewPath.Fill = ActivePathBrush;
  162. ContinuePageBtn.IsChecked = true;
  163. break;
  164. case ViewModes.Double:
  165. DoubleViewBtn.IsChecked = true;
  166. DoubleViewPath.Fill = ActivePathBrush;
  167. ContinuePageBtn.IsChecked = false;
  168. break;
  169. case ViewModes.DoubleContinuous:
  170. DoubleViewBtn.IsChecked = true;
  171. DoubleViewPath.Fill = ActivePathBrush;
  172. ContinuePageBtn.IsChecked = true;
  173. break;
  174. default:
  175. break;
  176. }
  177. }
  178. public void SetCropUI(bool isAutoCrop)
  179. {
  180. CropModeBtn.IsChecked=isAutoCrop;
  181. }
  182. public void SetSplitContainerVisibility(Visibility visibility)
  183. {
  184. SplitContainer.Visibility = visibility;
  185. if (visibility == Visibility.Visible)
  186. {
  187. DisplayContainer.Margin = new Thickness(0,30,0,0);
  188. }
  189. else
  190. {
  191. DisplayContainer.Margin = new Thickness(0);
  192. }
  193. }
  194. public void SetCropContainerVisibility(Visibility visibility)
  195. {
  196. CropContainer.Visibility = visibility;
  197. if (visibility == Visibility.Visible)
  198. {
  199. DisplayContainer.Margin = new Thickness(0, 30, 0, 0);
  200. }
  201. else
  202. {
  203. DisplayContainer.Margin = new Thickness(0);
  204. }
  205. }
  206. }
  207. }