123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410 |
- 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 ComPDFKitViewer;
- using ComPDFKitViewer.AnnotEvent;
- namespace ComPDFKitDemo.WidgetForm
- {
- public partial class ComboBoxFormProperty : Window
- {
- public WidgetAttribEvent CurrentAttribEvent;
- private Dictionary<string, string> optionsList;
- public ComboBoxFormProperty()
- {
- 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)
- {
- optionsList = null;
- 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.ListOptions:
- {
- optionsList = (Dictionary<string, string>)annotEvent.Attribs[attr];
- if (optionsList != null)
- {
- foreach (string key in optionsList.Keys)
- {
- ListBoxItem item = new ListBoxItem();
- item.Content = key;
- item.Tag = optionsList[key];
- OptionsListBox.Items.Add(item);
- }
- hideOptions = false;
- }
- }
- break;
- case AnnotAttrib.DefaultChoice:
- {
- List<int> selectedIndexList = (List<int>)annotEvent.Attribs[attr];
- if (selectedIndexList != null)
- {
- foreach (int index in selectedIndexList)
- {
- if (OptionsListBox.Items.Count > index)
- {
- (OptionsListBox.Items[index] as ListBoxItem).IsSelected = true;
- }
- }
- hideOptions = false;
- }
- }
- break;
- default:
- break;
- }
- }
- 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 OptionsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- ListBoxItem selectItem = OptionsListBox.SelectedItem as ListBoxItem;
- if (selectItem != null)
- {
- OptionName.Text = selectItem.Content.ToString();
- OptionValue.Text = selectItem.Tag.ToString();
- }
- }
- 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 OptionName_TextChanged(object sender, TextChangedEventArgs e)
- {
- string currentKey = OptionName.Text.Trim();
- AddOptionBtn.IsEnabled = true;
- if (optionsList != null && optionsList.ContainsKey(currentKey))
- {
- AddOptionBtn.IsEnabled = false;
- }
- if (currentKey == string.Empty)
- {
- AddOptionBtn.IsEnabled = false;
- }
- }
- private void OptionValue_TextChanged(object sender, TextChangedEventArgs e)
- {
- string currentKey = OptionName.Text.Trim();
- string currentValue = OptionValue.Text.Trim();
- if (currentKey == string.Empty || currentValue == string.Empty)
- {
- AddOptionBtn.IsEnabled = false;
- return;
- }
- AddOptionBtn.IsEnabled = true;
- if (optionsList != null)
- {
- if (optionsList.ContainsKey(currentKey))
- {
- AddOptionBtn.IsEnabled = false;
- return;
- }
- if (optionsList.Values.Contains(currentValue))
- {
- AddOptionBtn.IsEnabled = false;
- return;
- }
- }
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- string currentKey = OptionName.Text.Trim();
- string currentValue = OptionValue.Text.Trim();
- if (currentKey == string.Empty || currentValue == string.Empty)
- {
- return;
- }
- if (optionsList == null)
- {
- optionsList = new Dictionary<string, string>();
- }
- optionsList[currentKey] = currentValue;
- CurrentAttribEvent?.UpdateAttrib(AnnotAttrib.ListOptions, optionsList);
- CurrentAttribEvent?.UpdateAnnot();
- OptionsListBox.Items.Clear();
- foreach (string key in optionsList.Keys)
- {
- ListBoxItem item = new ListBoxItem();
- item.Content = key;
- item.Tag = optionsList[key];
- OptionsListBox.Items.Add(item);
- }
- }
- private void ButtonDel_Click(object sender, RoutedEventArgs e)
- {
- if (OptionsListBox.SelectedIndex != -1)
- {
- OptionsListBox.Items.RemoveAt(OptionsListBox.SelectedIndex);
- Dictionary<string, string> currentList = new Dictionary<string, string>();
- foreach (ListBoxItem item in OptionsListBox.Items)
- {
- currentList[item.Content.ToString()] = item.Tag.ToString();
- }
- CurrentAttribEvent?.UpdateAttrib(AnnotAttrib.ListOptions, currentList);
- CurrentAttribEvent?.UpdateAnnot();
- optionsList = currentList;
- }
- }
- 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();
- }
- 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;
- OptionName.IsEnabled = isEnable;
- OptionValue.IsEnabled = isEnable;
- AddOptionBtn.IsEnabled = isEnable;
- OptionsListBox.IsEnabled = isEnable;
- OptionDelBtn.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();
- }
- }
- }
- }
|