123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424 |
- using ComPDFKit.PDFAnnotation;
- using ComPDFKitViewer;
- using ComPDFKitViewer.AnnotEvent;
- using ComPDFKitViewer.PdfViewer;
- using PDF_Master.CustomControl.CompositeControl;
- using PDF_Master.Helper;
- using PDF_Master.Model;
- using PDF_Master.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_Master.ViewModels.Form
- {
- public class TextFieldPropertyViewModel : FormBaseVM, INavigationAware
- {
- #region Command变量
- public DelegateCommand<string> FieldNameTextChangedCommand { get; set; }
- public DelegateCommand<string> ToolTipTextChangedCommand { get; set; }
- //外观
- public DelegateCommand<object> ResetColorCommand { get; set; }
- public DelegateCommand<object> ResetColorCheckedBtnCommand { get; set; }
-
- public DelegateCommand<string> FormContentTextChangedCommand { get; set; }
- public DelegateCommand<object> LineStyleCommand { get; set; }
- #endregion
- #region 变量
- private CPDFViewer PDFViewer;
- private WidgetTextBoxArgs textBoxArgs;
- private IDialogService dialogs;
- public event EventHandler<int> SelectResetColorBtnHandler;
- public List<ComboDataItem> FontFamilyItems { get; private set; }
- public List<ComboDataItem> FontStyleItems { get; private set; }
- public List<ComboDataItem> AglinmentItems { get; private set; }
- #endregion
- #region 初始化
- public TextFieldPropertyViewModel(IDialogService dialogService)
- {
- dialogs = dialogService;
- InitVariable();
- InitCommand();
- }
- private void InitVariable()
- {
- InitAllResetColor();
- InitFontFamilyComboBox();
- InitFontStyleComboBox();
- InitAglinmentItemsComboBox();
- }
- private void InitAllResetColor()
- {
- ResetColorOne = InitResetColor(Colors.Transparent, Color.FromArgb(0xFF, 0x00, 0x00, 0x00), Colors.Transparent);
- ResetColorTwo = InitResetColor(Color.FromArgb(0xFF, 0x00, 0x00, 0x00), Color.FromArgb(0xFF, 0x00, 0x00, 0x00), Colors.Transparent);
- ResetColorThree = InitResetColor(Colors.Transparent, Color.FromArgb(0xFF, 0x00, 0x00, 0x00), Color.FromArgb(0xFF, 0xBD, 0xDF, 0xFD));
- ResetColorForth = InitResetColor(Color.FromArgb(0xFF, 0xff, 0x00, 0x00), Color.FromArgb(0xFF, 0xff, 0x00, 0x00), Colors.Transparent);
- }
- private void InitFontFamilyComboBox()
- {
- FontFamilyItems = new List<ComboDataItem>();
- ComboDataItem item = new ComboDataItem("Courier", "Courier New");
- FontFamilyItems.Add(item);
- item = new ComboDataItem("Helvetica", "Helvetica");
- FontFamilyItems.Add(item);
- item = new ComboDataItem("Times-Roman", "Times New Roman");
- FontFamilyItems.Add(item);
- }
- private void InitFontStyleComboBox()
- {
- FontStyleItems = new List<ComboDataItem>();
- ComboDataItem item = new ComboDataItem("Regular", "Regular");
- FontStyleItems.Add(item);
- item = new ComboDataItem("Bold", "Bold");
- FontStyleItems.Add(item);
- item = new ComboDataItem("Italic", "Italic");
- FontStyleItems.Add(item);
- item = new ComboDataItem("Bold Italic", "Bold Italic");
- FontStyleItems.Add(item);
- }
- private void InitAglinmentItemsComboBox()
- {
- AglinmentItems = new List<ComboDataItem>();
- ComboDataItem item = new ComboDataItem("Left", "Left");
- AglinmentItems.Add(item);
- item = new ComboDataItem("Center", "Center");
- AglinmentItems.Add(item);
- item = new ComboDataItem("Right", "Right");
- AglinmentItems.Add(item);
- }
- private void InitCommand()
- {
- //一般
- FieldNameTextChangedCommand = new DelegateCommand<string>(FieldNameTextChanged);
- ToolTipTextChangedCommand = new DelegateCommand<string>(ToolTipTextChanged);
- //外观
- ResetColorCheckedBtnCommand = new DelegateCommand<object>(ResetColorCheckedBtn);
- ResetColorCommand = new DelegateCommand<object>(ResetColorEvent);
- LineStyleCommand = new DelegateCommand<object>(LineStyleBtnEvent);
- //选项
- FormContentTextChangedCommand = new DelegateCommand<string>(FormContentTextChanged);
- }
- #endregion
- #region 事件
-
- private void FieldNameTextChanged(string obj)
- {
- if (string.IsNullOrEmpty(obj) == false && IsCurrentWidget == true)
- {
- FieldName = obj;
- }
- }
- private void ToolTipTextChanged(string obj)
- {
- if (string.IsNullOrEmpty(obj) == false && IsCurrentWidget == true)
- {
- ToolTipStr = obj;
- }
- }
- private void LineStyleBtnEvent(object obj)
- {
- if (obj != null)
- {
- switch ((string)obj)
- {
- case "Solid":
- BorderStyle = ComPDFKit.PDFAnnotation.C_BORDER_STYLE.BS_SOLID;
- break;
- case "Dotted":
- BorderStyle = ComPDFKit.PDFAnnotation.C_BORDER_STYLE.BS_DASHDED;
- break;
- }
- }
- }
- private void FormContentTextChanged(string obj)
- {
- if (obj != null && IsCurrentWidget == true)
- {
- FormContent = obj;
- }
- }
- 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;
- FillColor = ResetColorOne.FillColor.Color;
- break;
- case "Two":
- BorderColor = ResetColorTwo.BorderColor.Color;
- ContentColor = ResetColorTwo.FontColor.Color;
- FillColor = ResetColorTwo.FillColor.Color;
- break;
- case "Three":
- BorderColor = ResetColorThree.BorderColor.Color;
- ContentColor = ResetColorThree.FontColor.Color;
- FillColor = ResetColorThree.FillColor.Color;
- break;
- case "Forth":
- BorderColor = ResetColorForth.BorderColor.Color;
- ContentColor = ResetColorForth.FontColor.Color;
- FillColor = ResetColorForth.FillColor.Color;
- break;
- }
- }
- }
- }
- private void ResetColorEvent(object obj)
- {
- 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)
- {
- }
- });
- if (!result)
- {
- return;
- }
- }
- #endregion
- #region 外部XAML触发事件
- private void UpdataSelectResetColorBtn()
- {
- int result = 0;
- if (UpdataSelectResetColor(ResetColorOne))
- {
- result = 1;
- }
- else if (UpdataSelectResetColor(ResetColorTwo))
- {
- result = 2;
- }
- else if (UpdataSelectResetColor(ResetColorThree))
- {
- result = 3;
- }
- else if (UpdataSelectResetColor(ResetColorForth))
- {
- result = 4;
- }
- SelectResetColorBtnHandler?.Invoke(null, result);
- }
- private bool UpdataSelectResetColor(ResetColor reset)
- {
- if (reset.FillColor.Color == FillColor &&
- reset.FontColor.Color == ContentColor &&
- reset.BorderColor.Color == BorderColor
- )
- {
- return true;
- }
- return false;
- }
- #endregion
- #region Navegation
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- isCreateWidget = false;
- IsCurrentWidget = false;
- textBoxArgs = null;
- PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
- }
- 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);
- PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
- PDFViewer.AnnotEditHandler += PDFViewer_AnnotEditHandler;
- GetWidgeText();
- UpdataSelectResetColorBtn();
- }
- private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
- {
- if (e != null && e.Count > 0)
- {
- var widgeArgs = e[e.Count - 1].EditAnnotArgs as WidgetArgs;
- if (widgeArgs != null)
- {
- AnnotEditEvent editEvent = e[e.Count - 1];
- if (editEvent.EditAction == ActionType.Modify)
- {
- SetSizeNoUpdateValue(widgeArgs.Width, widgeArgs.Height);
- }
- }
- }
- }
- private void GetWidgeText()
- {
- //新建的form表单
- if (textBoxArgs == null)
- {
- PDFViewer.SetMouseMode(MouseModes.FormEditTool);
- WidgetTextBoxArgs textArgs = new WidgetTextBoxArgs();
- textArgs.BgColor = Colors.LightGray;
- textArgs.Width = 150;
- textArgs.Height = 22;
- textBoxArgs = textArgs;
- textArgs.FontSize = 12;
- textArgs.FontFamily = "Helvatica";
- textArgs.LineWidth = 2;
- textArgs.FontColor = Colors.Black;
- textArgs.LineColor = Colors.Black;
-
- // textArgs.
- PDFViewer.SetToolParam(textBoxArgs);
- isCreateWidget = true;
- }
- else
- {
- PDFViewer.SetToolParam(new AnnotHandlerEventArgs());
- isCreateWidget = false;
- }
- GetProperty();
- IsCurrentWidget = true;
- }
- private void GetProperty()
- {
- if (textBoxArgs != null)
- {
- IsLocked = textBoxArgs.Locked;
- FieldName = textBoxArgs.FieldName;
- ToolTipStr = textBoxArgs.Tooltip;
- IsReadOnly = textBoxArgs.ReadOnly;
- IsRequiredField = textBoxArgs.IsRequired;
- FillColor = textBoxArgs.BgColor;
- ContentColor = textBoxArgs.FontColor;
- BorderColor = textBoxArgs.LineColor;
- BorderThiness = textBoxArgs.LineWidth;
- BorderStyle = textBoxArgs.BorderStyle;
- FormField = (FormFieldType)textBoxArgs.FormField;
- string fontWeightStyleStr = "";
- if (textBoxArgs.FontStyle == FontStyles.Normal)
- {
- if (textBoxArgs.FontWeight == FontWeights.Normal)
- fontWeightStyleStr = "Regular";
- else
- fontWeightStyleStr = "Bold";
- }
- else
- {
- if (textBoxArgs.FontWeight == FontWeights.Normal)
- fontWeightStyleStr = "Italic";
- else
- fontWeightStyleStr = "Bold Italic";
- }
- FontWeightStyleItem = new ComboDataItem(fontWeightStyleStr);
- FontFamilyData = new ComboDataItem(textBoxArgs.FontFamily);
- //避免BorderStyle跟上一个值相同,而没触发更改IsSolid属性
- if (BorderStyle == C_BORDER_STYLE.BS_SOLID)
- IsSolid = true;
- else
- IsSolid = false;
- FontSizeData = new ComboDataItem(textBoxArgs.FontSize);
- if (isCreateWidget == false)
- {
- HeightSize = textBoxArgs.Height;
- WidthSize = textBoxArgs.Width;
- }
- string alignmentStr = "";
- if (textBoxArgs.Alignment == C_TEXT_ALIGNMENT.ALIGNMENT_LEFT)
- alignmentStr = "left";
- else if (textBoxArgs.Alignment == C_TEXT_ALIGNMENT.ALIGNMENT_CENTER)
- alignmentStr = "Center";
- else
- alignmentStr = "Right";
- TextAlignmentData = new ComboDataItem(alignmentStr, alignmentStr);
- FormContent = textBoxArgs.Text;
- IsMultiLine = textBoxArgs.IsMultiLine;
- IsScrollText = textBoxArgs.ScrollFlag;
-
- }
- }
- #endregion
- }
- }
|