using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using ComPDFKit.PDFAnnotation; using ComPDFKit.PDFAnnotation.Form; using ComPDFKit.PDFDocument.Action; using ComPDFKitViewer; using ComPDFKitViewer.AnnotEvent; namespace ComPDFKitDemo.WidgetForm { public partial class PushButtonFormProperty : Window { public WidgetAttribEvent CurrentAttribEvent; public PushButtonFormProperty() { InitializeComponent(); } private void NavClick(object sender, MouseButtonEventArgs e) { foreach (TextBlock child in FormStack.Children) { child.Foreground = Brushes.Black; child.Background = Brushes.Transparent; } TextBlock clickBlock = sender as TextBlock; clickBlock.Background = new SolidColorBrush(Color.FromRgb(0xD1, 0xE2, 0xF2)); RegularPanel.Visibility = Visibility.Collapsed; AppearancePanel.Visibility = Visibility.Collapsed; OptionPanel.Visibility = Visibility.Collapsed; switch (clickBlock.Tag.ToString()) { case "Regular": RegularPanel.Visibility = Visibility.Visible; break; case "Appearance": AppearancePanel.Visibility = Visibility.Visible; break; case "Option": OptionPanel.Visibility = Visibility.Visible; break; default: break; } } public void SetFormData(WidgetAttribEvent annotEvent) { if (annotEvent != null) { FontStyleBox.SelectedIndex = 0; bool hideOptions = true; foreach (AnnotAttrib attr in annotEvent.Attribs.Keys) { switch (attr) { case AnnotAttrib.FieldName: GroupNameText.Text = annotEvent.Attribs[attr].ToString(); break; case AnnotAttrib.Color: BorderColorPicker.SelectedColor = (Color)annotEvent.Attribs[attr]; break; case AnnotAttrib.FillColor: FillColorPicker.SelectedColor = (Color)annotEvent.Attribs[attr]; break; case AnnotAttrib.FontFamily: List fontFamilyList = new List() { "Helvetica", "Courier", "Times" }; string currentFont = annotEvent.Attribs[attr].ToString(); FontFamilyBox.SelectedIndex = -1; for (int i = 0; i < fontFamilyList.Count; i++) { if (fontFamilyList[i].ToLower().Contains(currentFont.ToLower())) { FontFamilyBox.SelectedIndex = i; } } break; case AnnotAttrib.FontSize: FontSizeBox.Text = annotEvent.Attribs[attr].ToString(); break; case AnnotAttrib.FontColor: { FontColorPicker.SelectedColor = (Color)annotEvent.Attribs[attr]; } break; case AnnotAttrib.FontStyle: { FontStyle currentStyle = (FontStyle)annotEvent.Attribs[attr]; if (currentStyle == FontStyles.Italic) { FontStyleBox.SelectedIndex = FontStyleBox.SelectedIndex + 1; } } break; case AnnotAttrib.FontWeight: { FontWeight currentWeight = (FontWeight)annotEvent.Attribs[attr]; if (currentWeight == FontWeights.Bold) { FontStyleBox.SelectedIndex = FontStyleBox.SelectedIndex + 1; } } break; case AnnotAttrib.Thickness: ThicknessText.SelectedIndex = Convert.ToInt32(annotEvent.Attribs[attr])-1; break; case AnnotAttrib.LineStyle: if ((C_BORDER_STYLE)annotEvent.Attribs[attr] == C_BORDER_STYLE.BS_DASHDED) { LineStyleBox.SelectedIndex = 1; } else { LineStyleBox.SelectedIndex = 0; } break; case AnnotAttrib.Locked: { LockBox.IsChecked = (bool)annotEvent.Attribs[attr] == true; EnableControls(!(LockBox.IsChecked == true)); } break; case AnnotAttrib.ReadOnly: { ReadOnlyBox.IsChecked = (bool)annotEvent.Attribs[attr] == true; } break; case AnnotAttrib.FormField: { FormField field = (FormField)annotEvent.Attribs[attr]; FormFieldBox.SelectedIndex = (int)field; } break; case AnnotAttrib.Text: TextContentBox.Text = (string)annotEvent.Attribs[attr]; hideOptions = false; break; case AnnotAttrib.FormAction: { Dictionary ActionDict = (Dictionary)annotEvent.Attribs[attr]; foreach (C_ACTION_TYPE key in ActionDict.Keys) { if (key == C_ACTION_TYPE.ACTION_TYPE_GOTO) { ActionBox.SelectedIndex = 0; ActionText.Text = ActionDict[key]; break; } if (key == C_ACTION_TYPE.ACTION_TYPE_URI) { ActionBox.SelectedIndex = 1; ActionText.Text = ActionDict[key]; break; } } hideOptions = false; } break; default: break; } } OptionRadio.Visibility = hideOptions == false ? Visibility.Visible : Visibility.Collapsed; OptinTab.Visibility = hideOptions == false ? Visibility.Visible : Visibility.Collapsed; if (hideOptions) { foreach (UIElement child in OptionPanel.Children) { child.Visibility = Visibility.Collapsed; } OptinTab.Visibility = Visibility.Collapsed; } } } private void GroupNameText_TextChanged(object sender, TextChangedEventArgs e) { if (GroupNameText.Text.Length > 0) { CurrentAttribEvent?.UpdateAttrib(AnnotAttrib.FieldName, GroupNameText.Text); CurrentAttribEvent?.UpdateAnnot(); } } private void BorderColorPicker_SelectedColorChanged(object sender, RoutedPropertyChangedEventArgs e) { CurrentAttribEvent?.UpdateAttrib(AnnotAttrib.Color, e.NewValue); CurrentAttribEvent?.UpdateAnnot(); } private void FillColorPicker_SelectedColorChanged(object sender, RoutedPropertyChangedEventArgs e) { CurrentAttribEvent?.UpdateAttrib(AnnotAttrib.FillColor, e.NewValue); CurrentAttribEvent?.UpdateAnnot(); } private void FontFamilyBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { string fontName = (FontFamilyBox.SelectedItem as ComboBoxItem).Content.ToString(); CurrentAttribEvent?.UpdateAttrib(AnnotAttrib.FontFamily, fontName); CurrentAttribEvent?.UpdateAnnot(); } private void FontSizeBox_TextChanged(object sender, TextChangedEventArgs e) { int currentSize = 12; if (int.TryParse(FontSizeBox.Text, out currentSize)) { CurrentAttribEvent?.UpdateAttrib(AnnotAttrib.FontSize, currentSize); CurrentAttribEvent?.UpdateAnnot(); } } private void FontStyleBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { switch (FontStyleBox.SelectedIndex) { case 0: CurrentAttribEvent?.UpdateAttrib(AnnotAttrib.FontStyle, FontStyles.Normal); CurrentAttribEvent?.UpdateAttrib(AnnotAttrib.FontWeight, FontWeights.Normal); break; case 1: CurrentAttribEvent?.UpdateAttrib(AnnotAttrib.FontStyle, FontStyles.Normal); CurrentAttribEvent?.UpdateAttrib(AnnotAttrib.FontWeight, FontWeights.Bold); break; case 2: CurrentAttribEvent?.UpdateAttrib(AnnotAttrib.FontStyle, FontStyles.Italic); CurrentAttribEvent?.UpdateAttrib(AnnotAttrib.FontWeight, FontWeights.Normal); break; case 3: CurrentAttribEvent?.UpdateAttrib(AnnotAttrib.FontStyle, FontStyles.Italic); CurrentAttribEvent?.UpdateAttrib(AnnotAttrib.FontWeight, FontWeights.Bold); break; } CurrentAttribEvent?.UpdateAnnot(); } private void FontColorPicker_SelectedColorChanged(object sender, RoutedPropertyChangedEventArgs e) { CurrentAttribEvent?.UpdateAttrib(AnnotAttrib.FontColor, e.NewValue); CurrentAttribEvent?.UpdateAnnot(); } private void TextContentBox_TextChanged(object sender, TextChangedEventArgs e) { CurrentAttribEvent?.UpdateAttrib(AnnotAttrib.Text, TextContentBox.Text.Trim()); CurrentAttribEvent?.UpdateAnnot(); } private void ThicknessText_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (ThicknessText.SelectedIndex >= 0 && ThicknessText.SelectedIndex < 3) { CurrentAttribEvent?.UpdateAttrib(AnnotAttrib.Thickness, ThicknessText.SelectedIndex + 1); CurrentAttribEvent?.UpdateAnnot(); } } private void LineStyleBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { CurrentAttribEvent?.UpdateAttrib(AnnotAttrib.LineStyle, LineStyleBox.SelectedIndex == 0 ? C_BORDER_STYLE.BS_SOLID : C_BORDER_STYLE.BS_DASHDED); CurrentAttribEvent?.UpdateAnnot(); } private void ActionAdd_Click(object sender, RoutedEventArgs e) { Dictionary ActionDict = new Dictionary(); if (ActionBox.SelectedIndex == 0) { ActionDict[C_ACTION_TYPE.ACTION_TYPE_GOTO] = ActionText.Text; } if (ActionBox.SelectedIndex == 1) { ActionDict[C_ACTION_TYPE.ACTION_TYPE_URI] = ActionText.Text; } CurrentAttribEvent?.UpdateAttrib(AnnotAttrib.FormAction, ActionDict); CurrentAttribEvent?.UpdateAnnot(); } private void ActionDel_Click(object sender, RoutedEventArgs e) { //CurrentAttribEvent?.UpdateAttrib(AnnotAttrib.FormAction, null); //CurrentAttribEvent?.UpdateAnnot(); } public void EnableControls(bool isEnable) { GroupNameText.IsEnabled = isEnable; FormFieldBox.IsEnabled = isEnable; ReadOnlyBox.IsEnabled = isEnable; BorderColorPicker.IsEnabled = isEnable; ThicknessText.IsEnabled = isEnable; FillColorPicker.IsEnabled = isEnable; LineStyleBox.IsEnabled = isEnable; FontFamilyBox.IsEnabled = isEnable; FontSizeBox.IsEnabled = isEnable; FontStyleBox.IsEnabled = isEnable; FontColorPicker.IsEnabled = isEnable; TextContentBox.IsEnabled = isEnable; ActionBox.IsEnabled = isEnable; ActionText.IsEnabled = isEnable; OptionAddBtn.IsEnabled = isEnable; } private void LockBox_Checked(object sender, RoutedEventArgs e) { EnableControls(!(LockBox.IsChecked == true)); CurrentAttribEvent?.UpdateAttrib(AnnotAttrib.Locked, (LockBox.IsChecked == true)); CurrentAttribEvent?.UpdateAnnot(); } private void ReadOnlyBox_Checked(object sender, RoutedEventArgs e) { CurrentAttribEvent?.UpdateAttrib(AnnotAttrib.ReadOnly, (ReadOnlyBox.IsChecked == true)); CurrentAttribEvent?.UpdateAnnot(); } private void FormFieldBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (FormFieldBox.SelectedIndex != -1) { CurrentAttribEvent?.UpdateAttrib(AnnotAttrib.FormField, (FormField)FormFieldBox.SelectedIndex); CurrentAttribEvent?.UpdateAnnot(); } } } }