using ComPDFKit.PDFDocument; using Compdfkit_Tools.PDFControlUI; using ComPDFKitViewer.PdfViewer; 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.Controls.Primitives; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Compdfkit_Tools.DigitalSignature.CPDFSignatureListControl; using ComPDFKit.DigitalSign; namespace Compdfkit_Tools.PDFControl { public enum BOTATools { Bookmark = 1 << 0, Outline = 1 << 1, Thumbnail = 1 << 2, Annotation = 1 << 3, Search = 1 << 4, Signature = 1 << 5, } public partial class CPDFBOTABarControl : UserControl { private CPDFViewer pdfViewer; private ToggleButton bookmarkButton; private ToggleButton outlineButton; private ToggleButton thumbnailButton; private ToggleButton annotButton; private ToggleButton searchButton; private CPDFSearchControl searchControl; private ToggleButton signatureButton; public event EventHandler DeleteSignatureEvent; public event EventHandler ViewCertificateEvent; public event EventHandler ViewSignatureEvent; public CPDFBOTABarControl(BOTATools botaTools) { InitializeComponent(); AddBOTAContent(botaTools); } public CPDFBOTABarControl() { InitializeComponent(); } public void InitWithPDFViewer(CPDFViewer pdfViewer) { this.pdfViewer = pdfViewer; UIElement currentBotaTool = GetBotaTool(); if (currentBotaTool is CPDFSearchControl) { ((CPDFSearchControl)currentBotaTool).InitWithPDFViewer(pdfViewer); } if (currentBotaTool is CPDFThumbnailControl) { ((CPDFThumbnailControl)currentBotaTool).InitWithPDFViewer(pdfViewer); ((CPDFThumbnailControl)currentBotaTool).ThumbLoaded = false; ((CPDFThumbnailControl)currentBotaTool).LoadThumb(); } if (currentBotaTool is CPDFBookmarkControl) { ((CPDFBookmarkControl)currentBotaTool).InitWithPDFViewer(pdfViewer); ((CPDFBookmarkControl)currentBotaTool).LoadBookmark(); } if (currentBotaTool is CPDFOutlineControl) { ((CPDFOutlineControl)currentBotaTool).InitWithPDFViewer(pdfViewer); } if (currentBotaTool is CPDFAnnotationListControl) { CPDFAnnotationListControl annotListControl= currentBotaTool as CPDFAnnotationListControl; annotListControl.InitWithPDFViewer(pdfViewer); annotListControl.LoadAnnotationList(); } } public void AddBOTAContent(BOTATools botaTools) { var brush = (Brush)FindResource("btn.bg.bota"); while (botaTools > 0) { if ((botaTools & BOTATools.Thumbnail) > 0) { thumbnailButton = new ToggleButton(); thumbnailButton.Background = brush; Geometry thumbnailGeometry = Geometry.Parse("M1.6001 0.850098H0.850098V1.6001V12.8001V13.5501H1.6001H4.0001V13.7001V15.2001H5.5001H13.7001H15.2001V13.7001V5.5001V4.0001H13.7001H13.5501V1.6001V0.850098H12.8001H1.6001ZM12.0501 4.0001V2.3501H2.3501V12.0501H4.0001V5.5001V4.0001H5.5001H12.0501ZM5.5001 5.5001H13.7001V13.7001H5.5001V5.5001Z"); Path path = new Path { Width = 16, Height = 16, Data = thumbnailGeometry, Fill = new SolidColorBrush(Color.FromRgb(0x27, 0x3C, 0x62)) }; thumbnailButton.Height = 40; thumbnailButton.Width = 52; thumbnailButton.BorderThickness = new Thickness(0); thumbnailButton.Style = FindResource("ToggleButtonStyle") as Style; thumbnailButton.Content = path; BOTABarTitleGrid.Children.Add(thumbnailButton); thumbnailButton.Click += ThumbnailButton_Click; botaTools -= BOTATools.Thumbnail; } else if ((botaTools & BOTATools.Outline) > 0) { outlineButton = new ToggleButton(); outlineButton.Background = brush; Geometry outlineGeometry = Geometry.Parse("M3 0.5H0V3.5H3V0.5ZM3 5.5H0V8.5H3V5.5ZM0 10.5H3V13.5H0V10.5ZM14 2.75V1.25H5V2.75H14ZM14 6.25V7.75H5V6.25H14ZM14 12.75V11.25H5V12.75H14Z"); Path path = new Path { Width = 16, Height = 16, Data = outlineGeometry, Fill = new SolidColorBrush(Color.FromRgb(0x27, 0x3C, 0x62)) }; outlineButton.Height = 40; outlineButton.Width = 52; outlineButton.BorderThickness= new Thickness(0); outlineButton.Style = FindResource("ToggleButtonStyle") as Style; outlineButton.Content = path; BOTABarTitleGrid.Children.Add(outlineButton); outlineButton.Click += OutlineButton_Click; outlineButton.ToolTip = botaTools.ToString(); botaTools -= BOTATools.Outline; } else if ((botaTools & BOTATools.Bookmark) > 0) { bookmarkButton = new ToggleButton(); bookmarkButton.Background = brush; Geometry bookmarkGeometry = Geometry.Parse("M5.6221 9.85217L0.75 12.6942V0.75H11.25V12.6942L6.3779 9.85217L6 9.63172L5.6221 9.85217Z"); Path path = new Path { Width = 16, Height = 16, Data = bookmarkGeometry, StrokeThickness = 1.5, Stroke = new SolidColorBrush(Color.FromRgb(0x27, 0x3C, 0x62)) }; bookmarkButton.Height = 40; bookmarkButton.Width = 52; bookmarkButton.BorderThickness = new Thickness(0); bookmarkButton.Style = FindResource("ToggleButtonStyle") as Style; bookmarkButton.Content = path; BOTABarTitleGrid.Children.Add(bookmarkButton); bookmarkButton.Click += BookmarkButton_Click; botaTools -= BOTATools.Bookmark; } else if ((botaTools & BOTATools.Annotation) > 0) { annotButton = new ToggleButton(); annotButton.Background = brush; Geometry thumbnailGeometry = Geometry.Parse("M16 0H1.6L0 14H14.4L16 0ZM8.34885 1.8143L12.0693 11.1154H13.2692V12.1154H10.1923V11.1154H10.9922L10.2384 9.23077H5.53048L4.77689 11.1154H5.57692V12.1154H2.5V11.1154H3.69995L7.42038 1.8143H8.34885ZM7.884 3.345L9.83837 8.23077H5.93035L7.884 3.345Z"); Path path = new Path { Width = 16, Height = 16, Data = thumbnailGeometry, Fill = (Brush)FindResource("btn.logo.bota") }; annotButton.Height = 40; annotButton.Width = 52; annotButton.BorderThickness = new Thickness(0); annotButton.Style = FindResource("ToggleButtonStyle") as Style; annotButton.Content = path; BOTABarTitleGrid.Children.Add(annotButton); annotButton.Click += AnnotButton_Click; botaTools -= BOTATools.Annotation; } else if ((botaTools & BOTATools.Search) > 0) { searchButton = new ToggleButton(); searchButton.Background = brush; Geometry thumbnailGeometry = Geometry.Parse("M3.4284 10.1635C1.56851 8.30364 1.56851 5.28816 3.4284 3.42827C5.28829 1.56838 8.30377 1.56838 10.1637 3.42827C12.0235 5.28816 12.0235 8.30364 10.1637 10.1635C8.30377 12.0234 5.28829 12.0234 3.4284 10.1635ZM2.36774 2.36761C-0.0779349 4.81329 -0.0779349 8.77851 2.36774 11.2242C4.63397 13.4904 8.20494 13.6567 10.6626 11.723L12.8875 13.9479C13.1804 14.2408 13.6552 14.2408 13.9481 13.9479C14.241 13.655 14.241 13.1801 13.9481 12.8872L11.7233 10.6624C13.6568 8.20466 13.4905 4.63379 11.2243 2.36761C8.77864 -0.078065 4.81342 -0.078065 2.36774 2.36761Z"); Path path = new Path { Width = 16, Height = 16, Data = thumbnailGeometry, Fill = (Brush)FindResource("btn.logo.bota"), }; searchButton.Height = 40; searchButton.Width = 52; searchButton.BorderThickness = new Thickness(0); searchButton.Style = FindResource("ToggleButtonStyle") as Style; searchButton.Content = path; BOTABarTitleGrid.Children.Add(searchButton); searchButton.Click += SearchButton_Click; botaTools -= BOTATools.Search; } else if ((botaTools & BOTATools.Signature) > 0) { signatureButton = new ToggleButton(); signatureButton.Background = brush; Geometry thumbnailGeometry = Geometry.Parse("M12.5 0H3.5C1.57 0 0 1.57 0 3.5V12.5C0 14.43 1.57 16 3.5 16H12.5C14.43 16 16 14.43 16 12.5V3.5C16 1.57 14.43 0 12.5 0ZM14 12.5C14 13.88 13.13 15 12 15H4C2.9 15 2 14.1 2 13V3C2 1.9 2.9 1 4 1H12C13.13 1 14 1.9 14 3V12.5ZM5 5H7V7H5V5ZM5 9H11V11H5V9ZM5 13H7V15H5V13Z"); Path path = new Path { Width = 16, Height = 16, Data = thumbnailGeometry, Fill = (Brush)FindResource("btn.logo.bota"), }; signatureButton.Height = 40; signatureButton.Width = 52; signatureButton.BorderThickness = new Thickness(0); signatureButton.Style = FindResource("ToggleButtonStyle") as Style; signatureButton.Content = path; BOTABarTitleGrid.Children.Add(signatureButton); signatureButton.Click += SignatureButton_Click; botaTools -= BOTATools.Signature; } } } private UIElement GetBotaTool() { return BotaToolContainer.Child; } private void SetBotaTool(UIElement newChild) { BotaToolContainer.Child = newChild; } private void ExpandTool(bool isExpand) { BotaToolContainer.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed; } private void ClearToolState(UIElement ignoreTool) { foreach (UIElement child in BOTABarTitleGrid.Children) { if (child != ignoreTool && child is ToggleButton buttonTool) { buttonTool.IsChecked = false; } } } private void SearchButton_Click(object sender, RoutedEventArgs e) { SelectBotaTool(BOTATools.Search); } private void AnnotButton_Click(object sender, RoutedEventArgs e) { SelectBotaTool(BOTATools.Annotation); } private void ThumbnailButton_Click(object sender, RoutedEventArgs e) { SelectBotaTool(BOTATools.Thumbnail); } private void OutlineButton_Click(object sender, RoutedEventArgs e) { SelectBotaTool(BOTATools.Outline); } private void BookmarkButton_Click(object sender, RoutedEventArgs e) { SelectBotaTool(BOTATools.Bookmark); } private void SignatureButton_Click(object sender, RoutedEventArgs e) { SelectBotaTool(BOTATools.Signature); } public void SelectBotaTool(BOTATools tool) { UIElement botaTool = GetBotaTool(); ToggleButton checkBtn = null; switch(tool) { case BOTATools.Thumbnail: { if(thumbnailButton != null) { thumbnailButton.IsChecked = true; if (botaTool == null || !(botaTool is CPDFThumbnailControl)) { CPDFThumbnailControl thumbnailControl = new CPDFThumbnailControl(); if (pdfViewer != null && pdfViewer.Document != null) { thumbnailControl.InitWithPDFViewer(pdfViewer); thumbnailControl.LoadThumb(); } SetBotaTool(thumbnailControl); checkBtn = thumbnailButton; } } } break; case BOTATools.Outline: { if(outlineButton != null) { outlineButton.IsChecked = true; if (botaTool == null || !(botaTool is CPDFOutlineControl)) { CPDFOutlineControl outlineControl = new CPDFOutlineControl(); if (pdfViewer != null && pdfViewer.Document != null) { outlineControl.InitWithPDFViewer(pdfViewer); } SetBotaTool(outlineControl); checkBtn = outlineButton; } } } break; case BOTATools.Bookmark: { if(bookmarkButton!=null) { bookmarkButton.IsChecked = true; if (botaTool == null || !(botaTool is CPDFBookmarkControl)) { CPDFBookmarkControl pdfBookmarkControl = new CPDFBookmarkControl(); if (pdfViewer != null && pdfViewer.Document != null) { pdfBookmarkControl.InitWithPDFViewer(pdfViewer); pdfBookmarkControl.LoadBookmark(); } SetBotaTool(pdfBookmarkControl); } checkBtn = bookmarkButton; } } break; case BOTATools.Search: { if(searchButton!=null) { searchButton.IsChecked = true; if (botaTool == null || !(botaTool is CPDFSearchControl)) { if (searchControl == null) { searchControl = new CPDFSearchControl(); if (pdfViewer != null && pdfViewer.Document != null) { searchControl.InitWithPDFViewer(pdfViewer); } } SetBotaTool(searchControl); checkBtn = searchButton; } } } break; case BOTATools.Annotation: { if(annotButton!=null) { annotButton.IsChecked = true; if (botaTool == null || !(botaTool is CPDFAnnotationListControl)) { CPDFAnnotationListControl annotationListControl = new CPDFAnnotationListControl(); if (pdfViewer != null && pdfViewer.Document != null) { annotationListControl.InitWithPDFViewer(pdfViewer); annotationListControl.LoadAnnotationList(); } SetBotaTool(annotationListControl); checkBtn = annotButton; } } } break; case BOTATools.Signature: { if (signatureButton != null) { signatureButton.IsChecked = true; if (botaTool == null || !(botaTool is CPDFSignatureListControl)) { CPDFSignatureListControl signatureControl = new CPDFSignatureListControl(); if (pdfViewer != null && pdfViewer.Document != null) { signatureControl.InitWithPDFViewer(pdfViewer); signatureControl.LoadSignatureList(); } SetBotaTool(signatureControl); checkBtn = signatureButton; signatureControl.DeleteSignatureEvent += (sender, args) => { DeleteSignatureEvent?.Invoke(this, null); }; signatureControl.ViewCertificateEvent += (sender, args) => { ViewCertificateEvent?.Invoke(this, args); }; signatureControl.ViewSignatureEvent += (sender, args) => { ViewSignatureEvent?.Invoke(this, args); }; } } } break; default: break; } if(checkBtn!=null) { ExpandTool(checkBtn.IsChecked == true); ClearToolState(checkBtn); } } public void LoadAnnotationList() { UIElement currentBotaTool = GetBotaTool(); if (currentBotaTool is CPDFAnnotationListControl) { ((CPDFAnnotationListControl)currentBotaTool).LoadAnnotationList(); } } public void LoadSignatureList() { UIElement currentBotaTool = GetBotaTool(); if (currentBotaTool is CPDFSignatureListControl) { ((CPDFSignatureListControl)currentBotaTool).LoadSignatureList(); } } } }