TextFieldProperty.xaml.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. using ComPDFKitViewer;
  2. using ComPDFKitViewer.AnnotEvent;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Collections.ObjectModel;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Media;
  10. namespace Compdfkit_Tools.PDFControl
  11. {
  12. public partial class TextFieldProperty : UserControl
  13. {
  14. private WidgetTextBoxArgs widgetArgs = null;
  15. private AnnotAttribEvent annotAttribEvent = null;
  16. public ObservableCollection<int> SizeList { get; set; } = new ObservableCollection<int>
  17. {
  18. 6,8,9,10,12,14,18,20,24,26,28,32,30,32,48,72
  19. };
  20. bool IsLoadedData = false;
  21. public TextFieldProperty()
  22. {
  23. InitializeComponent();
  24. }
  25. #region Loaded
  26. public void SetProperty(WidgetArgs Args, AnnotAttribEvent e)
  27. {
  28. widgetArgs = (WidgetTextBoxArgs)Args;
  29. annotAttribEvent = e;
  30. }
  31. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  32. {
  33. Binding SizeListbinding = new Binding();
  34. SizeListbinding.Source = this;
  35. SizeListbinding.Path = new System.Windows.PropertyPath("SizeList");
  36. FontSizeCmb.SetBinding(ComboBox.ItemsSourceProperty, SizeListbinding);
  37. FieldNameText.Text = widgetArgs.FieldName;
  38. FormFieldCmb.SelectedIndex = (int)widgetArgs.FormField;
  39. BorderColorPickerControl.SetCheckedForColor(widgetArgs.LineColor);
  40. BackgroundColorPickerControl.SetCheckedForColor(widgetArgs.BgColor);
  41. TextColorPickerControl.SetCheckedForColor(widgetArgs.FontColor);
  42. SetFontName(widgetArgs.FontName);
  43. SetFontStyle(widgetArgs.IsItalic, widgetArgs.IsBold);
  44. SetFontSize(widgetArgs.FontSize);
  45. TextAlignmentCmb.SelectedIndex = (int)widgetArgs.Alignment;
  46. DefaultText.Text = widgetArgs.Text;
  47. chkMutiline.IsChecked = widgetArgs.IsMultiLine;
  48. IsLoadedData = true;
  49. }
  50. private void UserControl_Unloaded(object sender, RoutedEventArgs e)
  51. {
  52. IsLoadedData = false;
  53. }
  54. private void SetFontSize(double size)
  55. {
  56. int index = SizeList.IndexOf((int)size);
  57. FontSizeCmb.SelectedIndex = index;
  58. }
  59. private void SetFontStyle(bool IsItalic, bool IsBold)
  60. {
  61. int index = 0;
  62. if (IsItalic && IsBold)
  63. {
  64. index = 3;
  65. }
  66. else if (IsItalic)
  67. {
  68. index = 2;
  69. }
  70. else if (IsBold)
  71. {
  72. index = 1;
  73. }
  74. FontStyleCmb.SelectedIndex = index;
  75. }
  76. private void SetFontName(string fontName)
  77. {
  78. int index = -1;
  79. List<string> fontFamilyList = new List<string>() { "Helvetica", "Courier", "Times" };
  80. for (int i = 0; i < fontFamilyList.Count; i++)
  81. {
  82. if (fontFamilyList[i].ToLower().Contains(fontName.ToLower())
  83. || fontName.ToLower().Contains(fontFamilyList[i].ToLower()))
  84. {
  85. index = i;
  86. }
  87. }
  88. FontCmb.SelectedIndex = index;
  89. }
  90. #endregion
  91. #region Updata
  92. private void FieldNameText_TextChanged(object sender, TextChangedEventArgs e)
  93. {
  94. if (IsLoadedData)
  95. {
  96. annotAttribEvent.UpdateAttrib(AnnotAttrib.FieldName, (sender as TextBox).Text);
  97. annotAttribEvent.UpdateAnnot();
  98. }
  99. }
  100. private void FormFieldCmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
  101. {
  102. if (IsLoadedData)
  103. {
  104. annotAttribEvent.UpdateAttrib(AnnotAttrib.FormField, (sender as ComboBox).SelectedIndex);
  105. annotAttribEvent.UpdateAnnot();
  106. }
  107. }
  108. private void BorderColorPickerControl_ColorChanged(object sender, EventArgs e)
  109. {
  110. if (IsLoadedData)
  111. {
  112. annotAttribEvent.UpdateAttrib(AnnotAttrib.Color, ((SolidColorBrush)BorderColorPickerControl.Brush).Color);
  113. annotAttribEvent.UpdateAnnot();
  114. }
  115. }
  116. private void BackgroundColorPickerControl_ColorChanged(object sender, EventArgs e)
  117. {
  118. if (IsLoadedData)
  119. {
  120. annotAttribEvent.UpdateAttrib(AnnotAttrib.FillColor, ((SolidColorBrush)BackgroundColorPickerControl.Brush).Color);
  121. annotAttribEvent.UpdateAnnot();
  122. }
  123. }
  124. private void TextColorPickerControl_ColorChanged(object sender, EventArgs e)
  125. {
  126. if (IsLoadedData)
  127. {
  128. annotAttribEvent.UpdateAttrib(AnnotAttrib.FontColor, ((SolidColorBrush)TextColorPickerControl.Brush).Color);
  129. annotAttribEvent.UpdateAnnot();
  130. }
  131. }
  132. private void FontCmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
  133. {
  134. if (IsLoadedData)
  135. {
  136. annotAttribEvent.UpdateAttrib(AnnotAttrib.FontName, ((sender as ComboBox).SelectedItem as ComboBoxItem).Content.ToString());
  137. annotAttribEvent.UpdateAnnot();
  138. }
  139. }
  140. private void FontStyleCmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
  141. {
  142. if (IsLoadedData)
  143. {
  144. bool IsItalic = false;
  145. bool IsBold = false;
  146. switch ((sender as ComboBox).SelectedIndex)
  147. {
  148. case 0:
  149. break;
  150. case 1:
  151. IsBold = true;
  152. break;
  153. case 2:
  154. IsItalic = true;
  155. break;
  156. case 3:
  157. IsItalic = true;
  158. IsBold = true;
  159. break;
  160. default:
  161. break;
  162. }
  163. annotAttribEvent.UpdateAttrib(AnnotAttrib.IsBold, IsBold);
  164. annotAttribEvent.UpdateAttrib(AnnotAttrib.IsItalic, IsItalic);
  165. annotAttribEvent.UpdateAnnot();
  166. }
  167. }
  168. private void FontSizeCmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
  169. {
  170. if (IsLoadedData)
  171. {
  172. annotAttribEvent.UpdateAttrib(AnnotAttrib.FontSize, (sender as ComboBox).SelectedItem );
  173. annotAttribEvent.UpdateAnnot();
  174. }
  175. }
  176. private void TextAlignmentCmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
  177. {
  178. if (IsLoadedData)
  179. {
  180. annotAttribEvent.UpdateAttrib(AnnotAttrib.TextAlign, (sender as ComboBox).SelectedIndex);
  181. annotAttribEvent.UpdateAnnot();
  182. }
  183. }
  184. private void DefaultText_TextChanged(object sender, TextChangedEventArgs e)
  185. {
  186. if (IsLoadedData)
  187. {
  188. annotAttribEvent.UpdateAttrib(AnnotAttrib.Text, (sender as TextBox).Text);
  189. annotAttribEvent.UpdateAnnot();
  190. }
  191. }
  192. private void chkMutiline_Checked(object sender, RoutedEventArgs e)
  193. {
  194. if (IsLoadedData)
  195. {
  196. annotAttribEvent.UpdateAttrib(AnnotAttrib.IsMutilLine, true);
  197. annotAttribEvent.UpdateAnnot();
  198. }
  199. }
  200. private void chkMutiline_Unchecked(object sender, RoutedEventArgs e)
  201. {
  202. if (IsLoadedData)
  203. {
  204. annotAttribEvent.UpdateAttrib(AnnotAttrib.IsMutilLine, false);
  205. annotAttribEvent.UpdateAnnot();
  206. }
  207. }
  208. #endregion
  209. }
  210. }