123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- 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<string> fontFamilyList = new List<string>() { "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<C_ACTION_TYPE, string> ActionDict = (Dictionary<C_ACTION_TYPE, string>)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<Color?> e)
- {
- CurrentAttribEvent?.UpdateAttrib(AnnotAttrib.Color, e.NewValue);
- CurrentAttribEvent?.UpdateAnnot();
- }
- private void FillColorPicker_SelectedColorChanged(object sender, RoutedPropertyChangedEventArgs<Color?> 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<Color?> 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<C_ACTION_TYPE, string> ActionDict = new Dictionary<C_ACTION_TYPE, string>();
- 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();
- }
- }
- }
- }
|