123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605 |
- using ComPDFKit.PDFAnnotation;
- using ComPDFKitViewer;
- using ComPDFKitViewer.AnnotEvent;
- using ComPDFKitViewer.PdfViewer;
- using PDF_Office.Helper;
- using PDF_Office.Model;
- using PDF_Office.Model.From;
- using Prism.Commands;
- using Prism.Mvvm;
- using Prism.Regions;
- using Prism.Services.Dialogs;
- 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.Media;
- namespace PDF_Office.ViewModels.Form
- {
- public class TextFieldPropertyViewModel : FormBaseVM, INavigationAware
- {
- #region 属性
- #region 一般
- private FormFieldType _formPos;
- public FormFieldType FormPos
- {
- get { return _formPos; }
- set { SetProperty(ref _formPos, value); ChangeFieldValue("FormPos"); }
- }
- #endregion
- #region 选项
- //默认值
- private string _defaultValue;
- public string DefaultValue
- {
- get { return _defaultValue; }
- set { SetProperty(ref _defaultValue, value); }
- }
- //多行
- private bool _isMultiline = false;
- public bool IsMultiLine
- {
- get { return _isMultiline; }
- set { SetProperty(ref _isMultiline, value); ChangeFieldValue("IsMultiLine"); }
- }
- //滚动显示长文本
- private bool _isScrollText = false;
- public bool IsScrollText
- {
- get { return _isScrollText; }
- set { SetProperty(ref _isScrollText, value); ChangeFieldValue("IsScrollText"); }
- }
- #endregion
- private FontFamily _fontFamily;
- public FontFamily FontFamilyItem
- {
- get { return _fontFamily; }
- set { SetProperty(ref _fontFamily, value); ChangeFieldValue("FontFamilyItem"); }
- }
- private FontStyle _fontStyle;
- public FontStyle FontStyleItem
- {
- get { return _fontStyle; }
- set { SetProperty(ref _fontStyle, value); ChangeFieldValue("FontStyleItem"); }
- }
- private FontWeight _fontWeight;
- public FontWeight FontWeightItem
- {
- get { return _fontWeight; }
- set { SetProperty(ref _fontWeight, value); ChangeFieldValue("FontWeightItem"); }
- }
- private C_TEXT_ALIGNMENT _textAlignment;
- public C_TEXT_ALIGNMENT TextAlignmentItem
- {
- get { return _textAlignment; }
- set { SetProperty(ref _textAlignment, value); ChangeFieldValue("TextAlignmentItem"); }
- }
- private string _content;
- public string FormContent
- {
- get { return _content; }
- set { SetProperty(ref _content, value); ChangeFieldValue("FormContent"); }
- }
- #endregion
- #region Command变量
- public DelegateCommand<string> NameTextChangedCommand { get; set; }
- public DelegateCommand<string> ToolTipTextChangedCommand { get; set; }
- public DelegateCommand<object> IsReadOnlyCheckedCommand { get; set; }
- public DelegateCommand<object> RequiredFieldCheckedCommand { get; set; }
- //外观
- public DelegateCommand<object> ThicknessChangedCommand { get; set; }
- public DelegateCommand<object> ResetColorCommand { get; set; }
- public DelegateCommand<object> ResetColorCheckedBtnCommand { get; set; }
- public DelegateCommand<object> FontFamilyChangedCommand { get; set; }
- public DelegateCommand<object> FontStyleChangedCommand { get; set; }
- public DelegateCommand<object> AlignmentChangedCommand { get; set; }
- public DelegateCommand<string> FormContentTextChangedCommand { get; set; }
- public DelegateCommand<object> IsMultiLineCheckedCommand { get; set; }
- public DelegateCommand<object> IsScrollToDisplayCheckedCommand { get; set; }
- public DelegateCommand<object> LineStyleCommand { get; set; }
- #endregion
- #region 变量
- public UpdateAttributeHelper AttribEvent;
- private CPDFViewer PDFViewer;
- private WidgetTextBoxArgs textBoxArgs;
- private bool IsCurrentWidget = false;
- private IDialogService dialogs;
- #endregion
- #region 初始化
- public TextFieldPropertyViewModel(IDialogService dialogService)
- {
- dialogs = dialogService;
- InitVariable();
- InitCommand();
- }
- private void InitVariable()
- {
- ResetColorOne = new ResetColor() {
- BorderColor = new SolidColorBrush(Colors.Transparent),
- FontColor = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0x00, 0x00)),
- FillColor = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0x00, 0x00))
- };
- ResetColorTwo = new ResetColor()
- {
- BorderColor = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0x00, 0x00)),
- FontColor = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0x00, 0x00)),
- FillColor = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0x00, 0x00))
- };
- ResetColorThree = new ResetColor()
- {
- BorderColor = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0x00, 0x00)),
- FontColor = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0x00, 0x00)),
- FillColor = new SolidColorBrush(Color.FromArgb(0xFF, 0xBD, 0xDF, 0xFD))
- };
- ResetColorForth = new ResetColor()
- {
- BorderColor = new SolidColorBrush(Color.FromArgb(0xFF, 0xff, 0x00, 0x00)),
- FontColor = new SolidColorBrush(Color.FromArgb(0xFF, 0xff, 0x00, 0x00)),
- FillColor = new SolidColorBrush(Colors.Transparent)
- };
- }
- private void InitCommand()
- {
- NameTextChangedCommand = new DelegateCommand<string>(NameTextChanged);
- ToolTipTextChangedCommand = new DelegateCommand<string>(ToolTipTextChanged);
- IsReadOnlyCheckedCommand = new DelegateCommand<object>(IsReadOnlyChecked);
- RequiredFieldCheckedCommand = new DelegateCommand<object>(RequiredFieldChecked);
- //外观
- ThicknessChangedCommand = new DelegateCommand<object>(ThicknessChanged);
- ResetColorCommand = new DelegateCommand<object>(ResetColorEvent);
- ResetColorCheckedBtnCommand = new DelegateCommand<object>(ResetColorCheckedBtn);
- FontFamilyChangedCommand = new DelegateCommand<object>(FontFamilyChanged);
- FontStyleChangedCommand = new DelegateCommand<object>(FontStyleChanged);
- AlignmentChangedCommand = new DelegateCommand<object>(AlignmentChanged);
- FormContentTextChangedCommand = new DelegateCommand<string>(FormContentTextChanged);
- IsMultiLineCheckedCommand = new DelegateCommand<object>(IsMultiLineChecked);
- IsScrollToDisplayCheckedCommand = new DelegateCommand<object>(IsScrollToDisplayChecked);
- LineStyleCommand = new DelegateCommand<object>(LineStyleBtnEvent);
- ChangeValueHandler -= ChangeValue;
- ChangeValueHandler += ChangeValue;
- }
- private void LineStyleBtnEvent(object obj)
- {
- if(obj != null)
- {
- switch((string)obj)
- {
- case "Solid":
- IsSolid = ComPDFKit.PDFAnnotation.C_BORDER_STYLE.BS_SOLID;
- break;
- case "Dotted":
- IsSolid = ComPDFKit.PDFAnnotation.C_BORDER_STYLE.BS_DASHDED;
- break;
- }
- }
- }
- private void IsScrollToDisplayChecked(object obj)
- {
- if(obj != null)
- {
- IsScrollText = (bool)obj;
- }
- }
- private void IsMultiLineChecked(object obj)
- {
- if (obj != null)
- {
- IsMultiLine = (bool)obj;
- }
- }
- private void FormContentTextChanged(string obj)
- {
- if(obj != null)
- {
- FormContent = obj;
- }
- }
- private void AlignmentChanged(object obj)
- {
- if (obj != null)
- {
- var combo = (ComboBoxItem)obj;
- if (combo != null)
- {
- switch (combo.Content)
- {
- case "Left":
- TextAlignmentItem = C_TEXT_ALIGNMENT.ALIGNMENT_LEFT;
- break;
- case "Center":
- TextAlignmentItem = C_TEXT_ALIGNMENT.ALIGNMENT_CENTER;
- break;
- case "Right":
- TextAlignmentItem = C_TEXT_ALIGNMENT.ALIGNMENT_RIGHT;
- break;
- }
- }
- }
- }
- private void FontStyleChanged(object obj)
- {
- if(obj != null)
- {
- var combo = (ComboBoxItem)obj;
- if(combo != null)
- {
- switch(combo.Content)
- {
- case "Regular":
- FontStyleItem = FontStyles.Normal;
- FontWeightItem = FontWeights.Normal;
- break;
- case "Bold":
- FontStyleItem = FontStyles.Normal;
- FontWeightItem = FontWeights.Bold;
- break;
- case "Italic":
- FontStyleItem = FontStyles.Italic;
- FontWeightItem = FontWeights.Normal;
- break;
- case "Bold Italic":
- FontStyleItem = FontStyles.Italic;
- FontWeightItem = FontWeights.Bold;
- break;
- }
- }
- }
- }
- private void FontFamilyChanged(object obj)
- {
- if(obj!= null)
- {
- switch((int)obj)
- {
- case 0:
- FontFamilyItem = new FontFamily("Courier");
- break;
- case 1:
- FontFamilyItem = new FontFamily("Helvetica");
- break;
- case 2:
- FontFamilyItem = new FontFamily("Times Roman");
- break;
- }
- }
- }
- private void ResetColorCheckedBtn(object obj)
- {
- if(obj != null)
- {
- var str = obj as string;
- if(str != null)
- {
- switch(str)
- {
- case "One":
- BorderColor = ResetColorOne.BorderColor.Color;
- ContentColor = ResetColorOne.FontColor.Color;
-
- break;
- case "Two":
- BorderColor = ResetColorTwo.BorderColor.Color;
- ContentColor = ResetColorTwo.FontColor.Color;
- break;
- case "Three":
- BorderColor = ResetColorThree.BorderColor.Color;
- ContentColor = ResetColorThree.FontColor.Color;
- break;
- case "Forth":
- BorderColor = ResetColorForth.BorderColor.Color;
- ContentColor = ResetColorForth.FontColor.Color;
- break;
- }
- }
- }
- }
- private void ResetColorEvent(object obj)
- {
- //if(obj != null && (ResetColor)obj != null)
- // {
- // var resetcolor = obj as ResetColor;
- // }
- bool result = true;
- DialogParameters value = new DialogParameters();
- value.Add(ParameterNames.PDFViewer, PDFViewer);
- dialogs.ShowDialog(DialogNames.EditPresetColorsDialog, value, e =>
- {
- if (e.Result != ButtonResult.OK)
- {
- result = false;
- }
- EditPresetColorsDialogViewModel DialogVM = e.Parameters.GetValue<EditPresetColorsDialogViewModel>(ParameterNames.DataModel);
- if (DialogVM != null)
- {
- // CreateSignature(DialogVM);
- }
- });
- if (!result)
- {
- return;
- }
- }
- private void ThicknessChanged(object obj)
- {
- if(obj != null)
- {
- BorderThiness = (double)obj;
- }
- }
- #endregion
- #region 一般处理
- private void NameTextChanged(string obj)
- {
- if(string.IsNullOrEmpty(obj) == false && IsCurrentWidget == true)
- {
- NameStr = obj;
- }
- }
- private void ToolTipTextChanged(string obj)
- {
- if (string.IsNullOrEmpty(obj) == false)
- {
- ToolTipStr = obj;
- }
- }
- private void IsReadOnlyChecked(object obj)
- {
- if(obj is bool)
- {
- IsReadOnly = (bool)obj;
- }
- }
- private void RequiredFieldChecked(object obj)
- {
- if (obj is bool)
- {
- IsRequiredField = (bool)obj;
- }
- }
- #endregion
- #region 外观处理
- #endregion
- #region 选项处理
- #endregion
- #region Navegation
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- isCreateWidget = false;
- IsCurrentWidget = false;
- textBoxArgs = null;
- }
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
- navigationContext.Parameters.TryGetValue<UpdateAttributeHelper>(ParameterNames.AnnotEvent, out AttribEvent);
- navigationContext.Parameters.TryGetValue<WidgetTextBoxArgs>("WidgetArgs", out textBoxArgs);
-
- GetWidgeText();
- }
- bool isCreateWidget = false;
- private void GetWidgeText()
- {
- //新建的form表单
- if (textBoxArgs == null)
- {
- PDFViewer.SetMouseMode(MouseModes.FormEditTool);
- WidgetTextBoxArgs textArgs = new WidgetTextBoxArgs();
- textArgs.BgColor = Colors.Transparent;
- textArgs.FontSize = 12;
- textArgs.FontFamily = "Courier New";
- textArgs.FontColor = Colors.Black;
- textArgs.FieldName = "TextBox";
- textBoxArgs = textArgs;
- PDFViewer.SetToolParam(textBoxArgs);
- isCreateWidget = true;
- }
- else
- {
-
- PDFViewer.SetToolParam(new AnnotHandlerEventArgs());
- isCreateWidget = false;
- }
- GetProperty();
- IsCurrentWidget = true;
- }
- private void GetProperty()
- {
- if(textBoxArgs != null)
- {
- NameStr = textBoxArgs.FieldName;
- IsRequiredField = textBoxArgs.IsRequired;
- IsMultiLine = textBoxArgs.IsMultiLine;
- IsLocked = textBoxArgs.Locked;
- ToolTipStr = textBoxArgs.Tooltip;
- }
- }
- //更改基类公共属性后,触发的事件
- private void ChangeValue(object sender, FormAttributeType e)
- {
- switch(e)
- {
- case FormAttributeType.Name:
- textBoxArgs.FieldName = NameStr;
- AttribEvent?.UpdateAttrib(AnnotAttrib.FieldName, NameStr);
- break;
- case FormAttributeType.ToolTip:
- textBoxArgs.Tooltip = ToolTipStr;
- AttribEvent?.UpdateAttrib(AnnotAttrib.Tooltip, ToolTipStr);
- break;
- case FormAttributeType.IsSolid:
- textBoxArgs.BorderStyle = IsSolid;
- AttribEvent?.UpdateAttrib(AnnotAttrib.LineStyle, IsSolid);
- break;
- case FormAttributeType.IsLocked:
- textBoxArgs.Locked = IsLocked;
- AttribEvent?.UpdateAttrib(AnnotAttrib.Locked, IsLocked);
- break;
- case FormAttributeType.HeightSize:
- textBoxArgs.Height = HeightSize;
- //AttribEvent?.UpdateAttrib(AnnotAttrib.w, HeightSize);
- break;
- case FormAttributeType.BorderThiness:
- textBoxArgs.LineWidth = BorderThiness;
- AttribEvent?.UpdateAttrib(AnnotAttrib.Thickness, BorderThiness);
- break;
- case FormAttributeType.BorderColor:
- textBoxArgs.BgColor = BorderColor;
- AttribEvent?.UpdateAttrib(AnnotAttrib.Color, BorderColor);
- break;
- case FormAttributeType.ContentColor:
- textBoxArgs.FontColor = ContentColor;
- AttribEvent?.UpdateAttrib(AnnotAttrib.FontColor, ContentColor);
- break;
- case FormAttributeType.FillColor:
- textBoxArgs.BgColor = FillColor;
- AttribEvent?.UpdateAttrib(AnnotAttrib.FillColor, FillColor);
- break;
- case FormAttributeType.IsReadOnly:
- textBoxArgs.ReadOnly = IsReadOnly;
- AttribEvent?.UpdateAttrib(AnnotAttrib.ReadOnly, IsReadOnly);
- break;
- case FormAttributeType.WidthSize:
- textBoxArgs.Width = WidthSize;
-
- break;
- case FormAttributeType.IsRequiredField:
- textBoxArgs.IsRequired = IsRequiredField;
- AttribEvent?.UpdateAttrib(AnnotAttrib.IsRequired, IsRequiredField);
- break;
- }
- AttribEvent?.UpdateAnnot();
- }
- private void ChangeFieldValue(string tag)
- {
- switch(tag)
- {
- case "FormPos":
- textBoxArgs.FormField = FormField.Visible;
- AttribEvent?.UpdateAttrib(AnnotAttrib.FormField,FormPos);
- break;
- case "FontFamilyItem":
- textBoxArgs.FontFamily = FontFamilyItem.Source;
- AttribEvent?.UpdateAttrib(AnnotAttrib.FontFamily, FontFamilyItem.Source);
- break;
- case "FontStyleItem":
- textBoxArgs.FontStyle = FontStyleItem;
- AttribEvent?.UpdateAttrib(AnnotAttrib.FontStyle, FontStyleItem);
- break;
- case "FontWeightItem":
- textBoxArgs.FontWeight = FontWeightItem;
- AttribEvent?.UpdateAttrib(AnnotAttrib.FontWeight, FontWeightItem);
- break;
- case "TextAlignmentItem":
- textBoxArgs.Alignment = TextAlignmentItem;
- AttribEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignmentItem);
- break;
- case "FormContent":
- textBoxArgs.Content = FormContent;
- AttribEvent?.UpdateAttrib(AnnotAttrib.Text, FormContent);
- break;
- case "IsScrollText":
- textBoxArgs.ScrollFlag = IsScrollText;
- AttribEvent?.UpdateAttrib(AnnotAttrib.ScrollFlag, IsScrollText);
- break;
- case "IsMultiLine":
- textBoxArgs.IsMultiLine = IsMultiLine;
- AttribEvent?.UpdateAttrib(AnnotAttrib.IsMutilLine, IsMultiLine);
- break;
- }
- AttribEvent?.UpdateAnnot();
- }
- #endregion
- }
- }
|