123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- using ComPDFKitViewer;
- using System;
- using System.Collections.Generic;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Controls.Primitives;
- using System.Windows.Media;
- using System.Windows.Shapes;
- namespace ComPDFKit.Controls.PDFControlUI
- {
- public partial class CPDFViewModeUI : UserControl
- {
- public event EventHandler<string> SetContinuousEvent;
- public event EventHandler<string> SetViewModeEvent;
- public event EventHandler<SplitMode> SplitModeChanged;
- public event EventHandler<ViewMode> ViewModeChanged;
- public event EventHandler<bool> CropModeChanged;
- private SolidColorBrush ActivePathBrush = new SolidColorBrush(Color.FromRgb(0x14,0x60,0xF3));
- private SolidColorBrush NormalPathBrush = new SolidColorBrush(Color.FromRgb(0x99, 0x99, 0x99));
- public CPDFViewModeUI()
- {
- InitializeComponent();
- }
- private void ViewModeRadioButton_Checked(object sender, RoutedEventArgs e)
- {
- var viewModeRadioButton = sender as RadioButton;
- SetViewModeEvent?.Invoke(sender, viewModeRadioButton.Tag as string);
- }
- private void ContinuousRadioButton_Click(object sender, RoutedEventArgs e)
- {
- var continuousRadioButton = sender as RadioButton;
- SetContinuousEvent?.Invoke(sender,(continuousRadioButton.Tag as string));
- }
- private void HorizonBtn_Click(object sender, RoutedEventArgs e)
- {
- VerticalBtn.IsChecked = false;
- HorizonPath.Fill = HorizonBtn.IsChecked == true ? ActivePathBrush : NormalPathBrush;
- VerticalPath.Fill = NormalPathBrush;
- SplitModeChanged?.Invoke(this, HorizonBtn.IsChecked == true ? SplitMode.Horizontal : SplitMode.None);
- }
- private void VerticalBtn_Click(object sender, RoutedEventArgs e)
- {
- HorizonBtn.IsChecked = false;
- HorizonPath.Fill = NormalPathBrush;
- VerticalPath.Fill = VerticalBtn.IsChecked == true ? ActivePathBrush : NormalPathBrush;
- SplitModeChanged?.Invoke(this, VerticalBtn.IsChecked == true ? SplitMode.Vertical : SplitMode.None);
- }
- private void ClearViewState()
- {
- List<ToggleButton> viewBtnList = new List<ToggleButton>()
- {
- SingleViewBtn,
- DoubleViewBtn,
- BookViewBtn,
- };
- List<Path> viewPathList = new List<Path>()
- {
- BookViewPath,
- DoubleViewPath,
- SingleViewPath
- };
- foreach (ToggleButton item in viewBtnList)
- {
- item.IsChecked = false;
- }
- foreach(Path path in viewPathList)
- {
- path.Fill = NormalPathBrush;
- }
- }
- private void BookViewBtn_Click(object sender, RoutedEventArgs e)
- {
- ClearViewState();
- BookViewBtn.IsChecked = true;
- BookViewPath.Fill = ActivePathBrush;
- ViewModeChanged?.Invoke(this, ContinuePageBtn.IsChecked==true? ViewMode.BookContinuous: ViewMode.Book);
- }
- private void DoubleViewBtn_Click(object sender, RoutedEventArgs e)
- {
- ClearViewState();
- DoubleViewBtn.IsChecked = true;
- DoubleViewPath.Fill = ActivePathBrush;
- ViewModeChanged?.Invoke(this, ContinuePageBtn.IsChecked == true ? ViewMode.DoubleContinuous: ViewMode.Double);
- }
- private void SingleViewBtn_Click(object sender, RoutedEventArgs e)
- {
- ClearViewState();
- SingleViewBtn.IsChecked = true;
- SingleViewPath.Fill = ActivePathBrush;
- ViewModeChanged?.Invoke(this, ContinuePageBtn.IsChecked == true ? ViewMode.SingleContinuous: ViewMode.Single);
- }
- private void CropModeBtn_Click(object sender, RoutedEventArgs e)
- {
- CropModeChanged?.Invoke(this, CropModeBtn.IsChecked == true);
- }
- private void ContinuePageBtn_Click(object sender, RoutedEventArgs e)
- {
- if(SingleViewBtn.IsChecked==true)
- {
- ViewModeChanged?.Invoke(this, ContinuePageBtn.IsChecked == true ? ViewMode.SingleContinuous : ViewMode.Single);
- return;
- }
- if (DoubleViewBtn.IsChecked == true)
- {
- ViewModeChanged?.Invoke(this, ContinuePageBtn.IsChecked == true ? ViewMode.DoubleContinuous : ViewMode.Double);
- return;
- }
- if(BookViewBtn.IsChecked == true)
- {
- ViewModeChanged?.Invoke(this, ContinuePageBtn.IsChecked == true ? ViewMode.BookContinuous : ViewMode.Book);
- }
- }
- public enum SplitMode
- {
- None = 0,
- Vertical,
- Horizontal
- }
- public void SetSplitModeUI(SplitMode mode)
- {
- switch (mode)
- {
- case SplitMode.None:
- HorizonBtn.IsChecked = false;
- VerticalBtn.IsChecked = false;
- HorizonPath.Fill = NormalPathBrush;
- VerticalPath.Fill = NormalPathBrush;
- break;
- case SplitMode.Vertical:
- VerticalBtn.IsChecked = true;
- HorizonBtn.IsChecked = false;
- HorizonPath.Fill = NormalPathBrush;
- VerticalPath.Fill = ActivePathBrush;
- break;
- case SplitMode.Horizontal:
- VerticalBtn.IsChecked = false;
- HorizonBtn.IsChecked = true;
- HorizonPath.Fill = ActivePathBrush;
- VerticalPath.Fill = NormalPathBrush;
- break;
- default:
- break;
- }
- }
- public void SetViewModeUI(ViewMode mode)
- {
- ClearViewState();
- switch (mode)
- {
- case ViewMode.Book:
- BookViewBtn.IsChecked = true;
- BookViewPath.Fill = ActivePathBrush;
- ContinuePageBtn.IsChecked = false;
- break;
- case ViewMode.BookContinuous:
- BookViewBtn.IsChecked = true;
- BookViewPath.Fill = ActivePathBrush;
- ContinuePageBtn.IsChecked = true;
- break;
- case ViewMode.Single:
- SingleViewBtn.IsChecked = true;
- SingleViewPath.Fill = ActivePathBrush;
- ContinuePageBtn.IsChecked = false;
- break;
- case ViewMode.SingleContinuous:
- SingleViewBtn.IsChecked = true;
- SingleViewPath.Fill = ActivePathBrush;
- ContinuePageBtn.IsChecked = true;
- break;
- case ViewMode.Double:
- DoubleViewBtn.IsChecked = true;
- DoubleViewPath.Fill = ActivePathBrush;
- ContinuePageBtn.IsChecked = false;
- break;
- case ViewMode.DoubleContinuous:
- DoubleViewBtn.IsChecked = true;
- DoubleViewPath.Fill = ActivePathBrush;
- ContinuePageBtn.IsChecked = true;
- break;
- default:
- break;
- }
- }
- public void SetCropUI(bool isAutoCrop)
- {
- CropModeBtn.IsChecked=isAutoCrop;
- }
- public void SetSplitContainerVisibility(Visibility visibility)
- {
- SplitContainer.Visibility = visibility;
- if (visibility == Visibility.Visible)
- {
- DisplayContainer.Margin = new Thickness(0,30,0,0);
- if((bool)VerticalBtn.IsChecked)
- {
- SplitModeChanged.Invoke(this,SplitMode.Vertical);
- }
- if ((bool)HorizonBtn.IsChecked)
- {
- SplitModeChanged.Invoke(this, SplitMode.Horizontal);
- }
- }
- else
- {
- if((bool)VerticalBtn.IsChecked || (bool)HorizonBtn.IsChecked)
- {
- SplitModeChanged.Invoke(this,SplitMode.None);
- }
- DisplayContainer.Margin = new Thickness(0);
- }
- }
- public void SetCropContainerVisibility(Visibility visibility)
- {
- CropContainer.Visibility = visibility;
- if (visibility == Visibility.Visible)
- {
- DisplayContainer.Margin = new Thickness(0, 30, 0, 0);
- }
- else
- {
- DisplayContainer.Margin = new Thickness(0);
- }
- }
- }
- }
|