Parcourir la source

Merge branch 'dev' of http://git.kdan.cc:8865/Windows/PDFOffice_Windows_exe into dev

ZhouJieSheng il y a 2 ans
Parent
commit
c78b2e9801

BIN
PDF Office/ComPDFKit.Viewer.dll


+ 7 - 6
PDF Office/CustomControl/WritableComboBox.xaml

@@ -9,8 +9,6 @@
     d:DesignWidth="200"
     d:DesignWidth="200"
     mc:Ignorable="d">
     mc:Ignorable="d">
     <Grid>
     <Grid>
-
-
         <ComboBox
         <ComboBox
             x:Name="writableComboBox"
             x:Name="writableComboBox"
             Grid.Column="1"
             Grid.Column="1"
@@ -20,10 +18,10 @@
             SelectionChanged="writableComboBox_SelectionChanged"
             SelectionChanged="writableComboBox_SelectionChanged"
             SelectedIndex="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:WritableComboBox}, Path=SelectedIndex}"
             SelectedIndex="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:WritableComboBox}, Path=SelectedIndex}"
             Visibility="Visible">
             Visibility="Visible">
-            <ComboBoxItem Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:WritableComboBox}, Path=IsAllPageVisible}">全部页面</ComboBoxItem>
-            <ComboBoxItem>奇数页</ComboBoxItem>
-            <ComboBoxItem>偶数页</ComboBoxItem>
-            <ComboBoxItem>自定义页面</ComboBoxItem>
+            <ComboBoxItem Tag="AllPage" Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:WritableComboBox}, Path=IsAllPageVisible}">全部页面</ComboBoxItem>
+            <ComboBoxItem Tag="OddPage">奇数页</ComboBoxItem>
+            <ComboBoxItem Tag="EvenPage">偶数页</ComboBoxItem>
+            <ComboBoxItem Tag="CustomPage">自定义页面</ComboBoxItem>
         </ComboBox>
         </ComboBox>
         <TextBox
         <TextBox
             x:Name="writableTextBox"
             x:Name="writableTextBox"
@@ -31,7 +29,10 @@
             MinHeight="{Binding ElementName=writableComboBox, Path=MinHeight}"
             MinHeight="{Binding ElementName=writableComboBox, Path=MinHeight}"
             HorizontalAlignment="Left"
             HorizontalAlignment="Left"
             VerticalContentAlignment="Center"
             VerticalContentAlignment="Center"
+            LostFocus="writableTextBox_LostFocus"
+            PreviewKeyDown="writableTextBox_PreviewKeyDown"
             TextChanged="writableTextBox_TextChange"
             TextChanged="writableTextBox_TextChange"
             Visibility="Hidden" />
             Visibility="Hidden" />
+
     </Grid>
     </Grid>
 </UserControl>
 </UserControl>

+ 126 - 5
PDF Office/CustomControl/WritableComboBox.xaml.cs

@@ -1,5 +1,6 @@
 using ImTools;
 using ImTools;
 using Newtonsoft.Json.Linq;
 using Newtonsoft.Json.Linq;
+using PDF_Office.Helper;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.Diagnostics;
@@ -39,14 +40,17 @@ namespace PDF_Office.CustomControl
         public Visibility IsAllPageVisible
         public Visibility IsAllPageVisible
         {
         {
             get { return (Visibility)GetValue(IsAllPageVisibleProperty); }
             get { return (Visibility)GetValue(IsAllPageVisibleProperty); }
-            set { SetValue(IsAllPageVisibleProperty, value); 
+            set
+            {
+                SetValue(IsAllPageVisibleProperty, value);
             }
             }
         }
         }
 
 
         // Using a DependencyProperty as the backing store for IsAllPageVisible.  This enables animation, styling, binding, etc...
         // Using a DependencyProperty as the backing store for IsAllPageVisible.  This enables animation, styling, binding, etc...
         public static readonly DependencyProperty IsAllPageVisibleProperty =
         public static readonly DependencyProperty IsAllPageVisibleProperty =
-            DependencyProperty.Register("IsAllPageVisible", typeof(Visibility), typeof(WritableComboBox), new PropertyMetadata(Visibility.Visible,(d,e)=> {
-                if((Visibility)e.NewValue!=Visibility.Visible)
+            DependencyProperty.Register("IsAllPageVisible", typeof(Visibility), typeof(WritableComboBox), new PropertyMetadata(Visibility.Visible, (d, e) =>
+            {
+                if ((Visibility)e.NewValue != Visibility.Visible)
                 {
                 {
 
 
                     (d as WritableComboBox).SetIndexByVisiblity((Visibility)e.NewValue);
                     (d as WritableComboBox).SetIndexByVisiblity((Visibility)e.NewValue);
@@ -89,6 +93,33 @@ namespace PDF_Office.CustomControl
 
 
             DependencyProperty.Register("Text", typeof(string), typeof(WritableComboBox), new PropertyMetadata(""));
             DependencyProperty.Register("Text", typeof(string), typeof(WritableComboBox), new PropertyMetadata(""));
 
 
+
+        private List<int> pageIndexList = new List<int>();
+
+        public List<int> PageIndexList
+        {
+            private get { return (List<int>)GetValue(PageIndexListProperty); }
+            set { SetValue(PageIndexListProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for PageIndexList.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty PageIndexListProperty =
+            DependencyProperty.Register("PageIndexList", typeof(List<int>), typeof(WritableComboBox), new PropertyMetadata(new List<int>()));
+
+
+
+        public int MaxPageRange
+        {
+            get { return (int)GetValue(MaxPageRangeProperty); }
+            set { SetValue(MaxPageRangeProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for MaxPageRange.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty MaxPageRangeProperty =
+            DependencyProperty.Register("MaxPageRange", typeof(int), typeof(WritableComboBox), new PropertyMetadata(0));
+
+
+
         /// <summary>
         /// <summary>
         /// 把子控件的事件传递出去,方便绑定
         /// 把子控件的事件传递出去,方便绑定
         /// </summary>
         /// </summary>
@@ -135,8 +166,77 @@ namespace PDF_Office.CustomControl
                 }
                 }
             }
             }
             this.SelectedIndex = this.writableComboBox.SelectedIndex.ToString();
             this.SelectedIndex = this.writableComboBox.SelectedIndex.ToString();
+            if (writableComboBox.SelectedItem as ComboBoxItem == null)
+            {
+                return;
+            }
 
 
-            SelectionChanged?.Invoke(sender,e);
+            switch ((writableComboBox.SelectedItem as ComboBoxItem).Tag.ToString())
+            {
+                case "AllPage":
+                    if (CommonHelper.GetPagesInRange(ref pageIndexList, "1-" + MaxPageRange, MaxPageRange, new char[] { ',' }, new char[] { '-' }))
+                    {
+                        PageIndexList = pageIndexList;
+                        Text = "1-" + MaxPageRange;
+                    }
+                    break;
+                case "OddPage":
+                    {
+                        string pageRange = "";
+                        for (int i = 1; i <= MaxPageRange; i++)
+                        {
+                            if (i % 2 != 0 || MaxPageRange == 1)
+                            {
+                                if (string.IsNullOrEmpty(pageRange))
+                                {
+                                    pageRange = i.ToString();
+                                }
+                                else
+                                {
+                                    pageRange += "," + i;
+                                }
+                            }
+
+                        }
+                        if (CommonHelper.GetPagesInRange(ref pageIndexList, pageRange, MaxPageRange, new char[] { ',' }, new char[] { '-' }))
+                        {
+                            PageIndexList = pageIndexList;
+                            Text = pageRange;
+                        }
+                        break;
+                    }
+                case "EvenPage":
+                    {
+                        string pageRange = "";
+                        for (int i = 1; i <= MaxPageRange; i++)
+                        {
+                            if (i % 2 == 0 || MaxPageRange == 1)
+                            {
+                                if (string.IsNullOrEmpty(pageRange))
+                                {
+                                    pageRange = i.ToString();
+                                }
+                                else
+                                {
+                                    pageRange += "," + i;
+                                }
+                            }
+
+                        }
+                        if (CommonHelper.GetPagesInRange(ref pageIndexList, pageRange, MaxPageRange, new char[] { ',' }, new char[] { '-' }))
+                        {
+                            PageIndexList = pageIndexList;
+                            Text = pageRange;
+                        }
+                        break;
+                    }
+                case "CustomPage":
+                    break;
+                default:
+                    break;
+            }
+
+            SelectionChanged?.Invoke(sender, e);
         }
         }
 
 
         private void writableTextBox_TextChange(object sender, TextChangedEventArgs e)
         private void writableTextBox_TextChange(object sender, TextChangedEventArgs e)
@@ -148,7 +248,28 @@ namespace PDF_Office.CustomControl
             else { Text = ""; }
             else { Text = ""; }
 
 
 
 
-            TextChanged?.Invoke(sender,e);
+            TextChanged?.Invoke(sender, e);
+        }
+
+        private void writableTextBox_LostFocus(object sender, RoutedEventArgs e)
+        {
+            if (CommonHelper.GetPagesInRange(ref pageIndexList, writableTextBox.Text, MaxPageRange, new char[] { ',' }, new char[] { '-' }))
+            {
+                PageIndexList = pageIndexList;
+                Text = writableTextBox.Text;
+            }
+            else
+            {
+                writableTextBox.Text = "";
+            }
+        }
+
+        private void writableTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
+        {
+            if (e.Key == Key.Enter)
+            {
+                writableComboBox.Focus();
+            }
         }
         }
     }
     }
 }
 }

+ 29 - 0
PDF Office/Model/Dialog/ToolsDialogs/MergeObject.cs

@@ -4,6 +4,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
 using System.Text;
 using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
+using System.Windows.Media.Imaging;
 
 
 namespace PDF_Office.Model.Dialog.ToolsDialogs
 namespace PDF_Office.Model.Dialog.ToolsDialogs
 {
 {
@@ -37,6 +38,34 @@ namespace PDF_Office.Model.Dialog.ToolsDialogs
             }
             }
         }
         }
 
 
+        private BitmapSource docThumbnail;
+
+        /// <summary>
+        /// 文档首张图片
+        /// </summary>
+        public BitmapSource DocThumbnail
+        {
+            get { return docThumbnail; }
+            set
+            {
+                SetProperty(ref docThumbnail, value);
+            }
+        }
+
+        private int sdkPageCount;
+        /// <summary>
+        /// SDK获取到的页面数量
+        /// </summary>
+        public int SDKPageCount
+        {
+            get { return sdkPageCount; }
+            set
+            {
+                SetProperty(ref sdkPageCount, value);
+            }
+        }
+
+
         private string docPageCount;
         private string docPageCount;
 
 
         /// <summary>
         /// <summary>

+ 6 - 2
PDF Office/ViewModels/BottomToolContentViewModel.cs

@@ -461,8 +461,12 @@ namespace PDF_Office.ViewModels
         {
         {
             if (e.Key == "PageNum")
             if (e.Key == "PageNum")
             {
             {
-                CurrentPage = (int)e.Value;
-                PageCount = PDFViewer.Document.PageCount;
+                RenderData renderData=e.Value as RenderData;
+                if (renderData != null)
+                {
+                    CurrentPage = renderData.PageIndex;
+                    PageCount = PDFViewer.Document.PageCount;
+                }
             }
             }
             if (e.Key == "ViewMode")
             if (e.Key == "ViewMode")
             {
             {

+ 165 - 61
PDF Office/ViewModels/Dialog/ToolsDialogs/MergeDialogViewModel.cs

@@ -10,10 +10,14 @@ using Prism.Services.Dialogs;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Collections.ObjectModel;
+using System.IO;
 using System.Linq;
 using System.Linq;
 using System.Text;
 using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
+using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Controls;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
 
 
 namespace PDF_Office.ViewModels.Dialog.ToolsDialogs
 namespace PDF_Office.ViewModels.Dialog.ToolsDialogs
 {
 {
@@ -65,13 +69,35 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs
 
 
         private PageSizeType pageSizeType = PageSizeType.kDefault;
         private PageSizeType pageSizeType = PageSizeType.kDefault;
 
 
+        private string inputWidth;
+
+        public string InputWidth
+        {
+            get { return inputWidth; }
+            set
+            {
+                SetProperty(ref inputWidth, value);
+            }
+        }
+
+        private string inputHeight;
+
+        public string InputHeight
+        {
+            get { return inputHeight; }
+            set
+            {
+                SetProperty(ref inputHeight, value);
+            }
+        }
+
 
 
         public MergeDialogViewModel(IDialogService dialogService)
         public MergeDialogViewModel(IDialogService dialogService)
         {
         {
             dialogs = dialogService;
             dialogs = dialogService;
             MergeObjectlist = new ObservableCollection<MergeObject>();
             MergeObjectlist = new ObservableCollection<MergeObject>();
             CancelCommand = new DelegateCommand(Cancel);
             CancelCommand = new DelegateCommand(Cancel);
-            AddFilesCommand = new DelegateCommand(AddFiles);
+            AddFilesCommand = new DelegateCommand(ButtonAddFiles);
             MergeCommand = new DelegateCommand(Merge);
             MergeCommand = new DelegateCommand(Merge);
             ClearCommand = new DelegateCommand(Clear);
             ClearCommand = new DelegateCommand(Clear);
             SetPageSizeTypeCommand = new DelegateCommand<object>(SetPageSizeType);
             SetPageSizeTypeCommand = new DelegateCommand<object>(SetPageSizeType);
@@ -85,7 +111,12 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs
             RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
             RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
         }
         }
 
 
-        private void AddFiles()
+        public void ButtonAddFiles()
+        {
+            AddFiles(OpenFile());
+        }
+
+        private string[] OpenFile()
         {
         {
             OpenFileDialog openFile = new OpenFileDialog();
             OpenFileDialog openFile = new OpenFileDialog();
             openFile.Multiselect = true;
             openFile.Multiselect = true;
@@ -99,57 +130,9 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs
                 "(*.tiff)|*.tiff";
                 "(*.tiff)|*.tiff";
             if (openFile.ShowDialog() == false)
             if (openFile.ShowDialog() == false)
             {
             {
-                return;
-            }
-            bool result = true;
-            for (int i = 0; i < openFile.FileNames.Length; i++)
-            {
-                MergeObject mergeObject = new MergeObject();
-                mergeObject.FilePath = openFile.FileNames[i];
-                
-                //通过路径判断文件是否已添加
-                bool IsExists = false;
-                for (int j = 0; j < MergeObjectlist.Count; j++)
-                {
-                    if (MergeObjectlist[i].FilePath == mergeObject.FilePath)
-                    {
-                        IsExists = true;
-                    }
-                }
-                if (IsExists)
-                {
-                    continue;
-                }
-
-                CPDFDocument doc = CPDFDocument.InitWithFilePath(mergeObject.FilePath);
-                if (doc.IsLocked)
-                {
-                    DialogParameters value = new DialogParameters();
-                    value.Add(ParameterNames.PDFDocument, doc);
-                    dialogs.ShowDialog(DialogNames.VerifyPassWordDialog, value, e =>
-                    {
-                        if (e.Result != ButtonResult.OK)
-                        {
-                            result = false;
-                        }
-                        else
-                        {
-                            mergeObject.Password = e.Parameters.GetValue<string>(ParameterNames.PassWord);
-                        }
-
-                    });
-                    if (!result)
-                    {
-                        doc.Release();
-                        continue;
-                    }
-                }
-                mergeObject.DocName = doc.FileName;
-                mergeObject.DocPageCount = doc.PageCount.ToString() + "页";
-                mergeObject.DocSize = GetFileSize(mergeObject.FilePath);
-                MergeObjectlist.Add(mergeObject);
-                doc.Release();
+                return null;
             }
             }
+            return openFile.FileNames;
         }
         }
 
 
         private string GetFileSize(string path)
         private string GetFileSize(string path)
@@ -197,19 +180,45 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs
             CPDFDocument SaveDoc = CPDFDocument.CreateDocument();
             CPDFDocument SaveDoc = CPDFDocument.CreateDocument();
             for (int i = 0; i < MergeObjectlist.Count; i++)
             for (int i = 0; i < MergeObjectlist.Count; i++)
             {
             {
-                CPDFDocument tempDoc = CPDFDocument.InitWithFilePath(MergeObjectlist[i].FilePath);
-                if (!string.IsNullOrEmpty(MergeObjectlist[i].Password))
+                //图片
+                if (Path.GetExtension(MergeObjectlist[i].FilePath).Trim().ToLower() != "pdf")
                 {
                 {
-                    tempDoc.UnlockWithPassword(MergeObjectlist[i].Password);
+                    BitmapSource frame = MergeObjectlist[i].DocThumbnail;
+                    byte[] imageData = new byte[frame.PixelWidth * frame.PixelHeight * 4];
+                    if (frame.Format != PixelFormats.Bgra32)
+                    {
+                        FormatConvertedBitmap covert = new FormatConvertedBitmap(frame, PixelFormats.Bgra32, frame.Palette, 0);
+                        covert.CopyPixels(imageData, frame.PixelWidth * 4, 0);
+                    }
+                    else
+                    {
+                        frame.CopyPixels(imageData, frame.PixelWidth * 4, 0);
+                    }
+                    frame.CopyPixels(imageData, frame.PixelWidth * 4, 0);
+                    result = SaveDoc.InsertPage(0, frame.PixelWidth, frame.PixelHeight, imageData, CPDFDocumentImageMode.CPDFDocumentImageModeScaleToFill);
+                    if (!result)
+                    {
+                        SaveDoc.Release();
+                        return;
+                    }
+                    continue;
                 }
                 }
-                result = SaveDoc.ImportPages(tempDoc, "1-1"/*MergeObjectlist[i].SetPageRange*/);
-                if (!result)
+                else
                 {
                 {
-                    SaveDoc.Release();
+                    CPDFDocument tempDoc = CPDFDocument.InitWithFilePath(MergeObjectlist[i].FilePath);
+                    if (!string.IsNullOrEmpty(MergeObjectlist[i].Password))
+                    {
+                        tempDoc.UnlockWithPassword(MergeObjectlist[i].Password);
+                    }
+                    result = SaveDoc.ImportPages(tempDoc, MergeObjectlist[i].SetPageRange);
+                    if (!result)
+                    {
+                        SaveDoc.Release();
+                        tempDoc.Release();
+                        return;
+                    }
                     tempDoc.Release();
                     tempDoc.Release();
-                    return;
                 }
                 }
-                tempDoc.Release();
             }
             }
 
 
             string path = App.CachePath.MergeFilePath;
             string path = App.CachePath.MergeFilePath;
@@ -237,11 +246,20 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs
                 case PageSizeType.Legal:
                 case PageSizeType.Legal:
                     break;
                     break;
                 case PageSizeType.Customized:
                 case PageSizeType.Customized:
+                    if (!string.IsNullOrEmpty(InputWidth) && !string.IsNullOrEmpty(InputHeight))
+                    {
+                        rect.Width = Convert.ToInt32(InputWidth);
+                        rect.Height = Convert.ToInt32(InputHeight);
+                    }
+                    else
+                    {
+                        rect.Width = 595;
+                        rect.Height = 841;
+                    }
                     break;
                     break;
                 default:
                 default:
                     break;
                     break;
             }
             }
-
             if (rect.Width > 0 && rect.Height > 0)
             if (rect.Width > 0 && rect.Height > 0)
             {
             {
                 //裁剪
                 //裁剪
@@ -303,6 +321,92 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs
             }
             }
         }
         }
 
 
+        public void AddFiles(string[] FilePath)
+        {
+            if (FilePath == null)
+            {
+                return;
+            }
+            bool result = true;
+            for (int i = 0; i < FilePath.Length; i++)
+            {
+                MergeObject mergeObject = new MergeObject();
+                mergeObject.FilePath = FilePath[i];
+
+                //通过路径判断文件是否已添加
+                bool IsExists = false;
+                for (int j = 0; j < MergeObjectlist.Count; j++)
+                {
+                    if (MergeObjectlist[j].FilePath == mergeObject.FilePath)
+                    {
+                        IsExists = true;
+                    }
+                }
+                if (IsExists)
+                {
+                    continue;
+                }
+                string FileType = Path.GetExtension(mergeObject.FilePath).Trim().ToLower();
+                if (FileType != ".pdf")
+                {
+                    if (!Properties.Resources.imageex.Contains(FileType))
+                    {
+                        //图片格式不支持
+                        continue;
+                    };
+
+                    mergeObject.DocName = Path.GetFileName(mergeObject.FilePath);
+                    mergeObject.DocPageCount = 1 + "页";
+                    mergeObject.SDKPageCount = 1;
+                    mergeObject.DocSize = GetFileSize(mergeObject.FilePath);
+                    mergeObject.DocThumbnail = new BitmapImage(new Uri(mergeObject.FilePath)); ;
+                }
+                else
+                {
+                    CPDFDocument doc = CPDFDocument.InitWithFilePath(mergeObject.FilePath);
+                    if (doc.IsLocked)
+                    {
+                        DialogParameters value = new DialogParameters();
+                        value.Add(ParameterNames.PDFDocument, doc);
+                        dialogs.ShowDialog(DialogNames.VerifyPassWordDialog, value, e =>
+                        {
+                            if (e.Result != ButtonResult.OK)
+                            {
+                                result = false;
+                            }
+                            else
+                            {
+                                mergeObject.Password = e.Parameters.GetValue<string>(ParameterNames.PassWord);
+                            }
+
+                        });
+                        if (!result)
+                        {
+                            doc.Release();
+                            continue;
+                        }
+                    }
+                    mergeObject.DocName = doc.FileName;
+                    mergeObject.DocPageCount = doc.PageCount.ToString() + "页";
+                    mergeObject.SDKPageCount = doc.PageCount;
+                    mergeObject.DocSize = GetFileSize(mergeObject.FilePath);
+
+                    //获取第一页缩略图
+                    CPDFPage page = doc.PageAtIndex(0);
+                    Size size = doc.GetPageSize(0);
+
+                    byte[] bmpData = new byte[(int)(size.Width * size.Height * 4)];
+                    WriteableBitmap WirteBitmap = new WriteableBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Bgra32, null);
+                    page.RenderPageBitmap(0, 0, (int)size.Width, (int)size.Height, 0xFFFFFFFF, bmpData, 1);
+                    WirteBitmap.WritePixels(new Int32Rect(0, 0, (int)size.Width, (int)size.Height), bmpData, WirteBitmap.BackBufferStride, 0);
+                    WirteBitmap.Freeze();
+                    mergeObject.DocThumbnail = WirteBitmap;
+
+                    doc.Release();
+                }
+                MergeObjectlist.Add(mergeObject);
+            }
+        }
         #endregion
         #endregion
     }
     }
 }
 }

+ 6 - 5
PDF Office/Views/Dialog/ToolsDialogs/MergeDialog.xaml

@@ -34,6 +34,7 @@
             <Grid >
             <Grid >
                 <ListView x:Name="MergeView" AllowDrop="True" 
                 <ListView x:Name="MergeView" AllowDrop="True" 
                 Drop="MergeView_Drop"
                 Drop="MergeView_Drop"
+                DragEnter="MergeView_DragEnter"
                 DragOver="MergeView_DragOver"
                 DragOver="MergeView_DragOver"
                 DragLeave="MergeView_DragLeave"
                 DragLeave="MergeView_DragLeave"
                 PreviewMouseMove="MergeView_PreviewMouseMove" 
                 PreviewMouseMove="MergeView_PreviewMouseMove" 
@@ -54,14 +55,14 @@
                                          AncestorType={x:Type ListViewItem}}, 
                                          AncestorType={x:Type ListViewItem}}, 
                                          Converter={StaticResource IndexConverter}}"
                                          Converter={StaticResource IndexConverter}}"
                                  VerticalAlignment="Center"  HorizontalAlignment="Center"/>
                                  VerticalAlignment="Center"  HorizontalAlignment="Center"/>
-                                <Image Grid.Column="1" Width="50" Height="50" HorizontalAlignment="Center" VerticalAlignment="Center" Source="pack://application:,,,/PDF Office;component/Resources/Dialog/AddImage.png"  />
+                                <Image Grid.Column="1" Width="50" Height="50" HorizontalAlignment="Center" VerticalAlignment="Center" Source="{Binding DocThumbnail}"  Stretch="Uniform"  />
                                 <StackPanel Grid.Column="2">
                                 <StackPanel Grid.Column="2">
                                     <TextBlock Text="{Binding DocName}"  HorizontalAlignment="Left" VerticalAlignment="Top"/>
                                     <TextBlock Text="{Binding DocName}"  HorizontalAlignment="Left" VerticalAlignment="Top"/>
                                     <TextBlock Text="{Binding DocSize}"  HorizontalAlignment="Left" VerticalAlignment="Top"/>
                                     <TextBlock Text="{Binding DocSize}"  HorizontalAlignment="Left" VerticalAlignment="Top"/>
                                     <TextBlock Text="{Binding DocPageCount}"  HorizontalAlignment="Left" VerticalAlignment="Top"/>
                                     <TextBlock Text="{Binding DocPageCount}"  HorizontalAlignment="Left" VerticalAlignment="Top"/>
                                 </StackPanel>
                                 </StackPanel>
                                 <StackPanel Grid.Column="3" HorizontalAlignment="Center" VerticalAlignment="Center">
                                 <StackPanel Grid.Column="3" HorizontalAlignment="Center" VerticalAlignment="Center">
-                                    <customcontrol:WritableComboBox SelectedIndex="0"/>
+                                    <customcontrol:WritableComboBox SelectedIndex="0" MaxPageRange="{Binding SDKPageCount}" Text="{Binding SetPageRange,Mode=TwoWay}"/>
                                 </StackPanel>
                                 </StackPanel>
                                 <StackPanel Grid.Column="4" VerticalAlignment="Center">
                                 <StackPanel Grid.Column="4" VerticalAlignment="Center">
                                     <Button Content="删除" Click="Delete_Click"/>
                                     <Button Content="删除" Click="Delete_Click"/>
@@ -135,9 +136,9 @@
                             <ColumnDefinition Width="20"/>
                             <ColumnDefinition Width="20"/>
                             <ColumnDefinition Width="*"/>
                             <ColumnDefinition Width="*"/>
                         </Grid.ColumnDefinitions>
                         </Grid.ColumnDefinitions>
-                        <customcontrol:TextBoxEx PlaceholderText="595"/>
+                        <customcontrol:TextBoxEx PreviewKeyDown="TextBoxEx_PreviewKeyDown" x:Name="TextWidth" PlaceholderText="595" Text="{Binding InputWidth,Mode=TwoWay}"  PreviewTextInput="TextBox_PreviewTextInput" LostFocus="TextBoxEx_LostFocus"/>
                         <TextBlock Text="X" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                         <TextBlock Text="X" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center"/>
-                        <customcontrol:TextBoxEx PlaceholderText="841" Grid.Column="2"/>
+                        <customcontrol:TextBoxEx PreviewKeyDown="TextBoxEx_PreviewKeyDown" x:Name="TextHeight" PlaceholderText="841" Grid.Column="2" Text="{Binding InputHeight,Mode=TwoWay}" PreviewTextInput="TextBox_PreviewTextInput" LostFocus="TextBoxEx_LostFocus"/>
                     </Grid>
                     </Grid>
                 </StackPanel>
                 </StackPanel>
             </Grid>
             </Grid>
@@ -145,7 +146,7 @@
         <Button Grid.Column="3" Grid.Row="5"  Content="Clear"  HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="80" Height="32" Style="{StaticResource btn.sec}" Command="{Binding ClearCommand}"/>
         <Button Grid.Column="3" Grid.Row="5"  Content="Clear"  HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="80" Height="32" Style="{StaticResource btn.sec}" Command="{Binding ClearCommand}"/>
         <StackPanel Grid.Column="3" Grid.Row="5" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom">
         <StackPanel Grid.Column="3" Grid.Row="5" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom">
             <Button Content="Cancel" Width="80" Height="32" Style="{StaticResource btn.sec}" Command="{Binding CancelCommand}"/>
             <Button Content="Cancel" Width="80" Height="32" Style="{StaticResource btn.sec}" Command="{Binding CancelCommand}"/>
-            <Button Content="Add" Width="80" Height="32" Margin="16,0,0,0" Style="{StaticResource Btn.cta}" Command="{Binding MergeCommand}"/>
+            <Button x:Name="BtnAdd" Content="Add" Width="80" Height="32" Margin="16,0,0,0" Style="{StaticResource Btn.cta}" Command="{Binding MergeCommand}"/>
         </StackPanel>
         </StackPanel>
     </Grid>
     </Grid>
 </UserControl>
 </UserControl>

+ 86 - 1
PDF Office/Views/Dialog/ToolsDialogs/MergeDialog.xaml.cs

@@ -1,10 +1,12 @@
-using PDF_Office.Helper;
+using PDF_Office.CustomControl;
+using PDF_Office.Helper;
 using PDF_Office.Model.Dialog.ToolsDialogs;
 using PDF_Office.Model.Dialog.ToolsDialogs;
 using PDF_Office.ViewModels.Dialog.ToolsDialogs;
 using PDF_Office.ViewModels.Dialog.ToolsDialogs;
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
 using System.Text;
 using System.Text;
+using System.Text.RegularExpressions;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Controls;
@@ -27,6 +29,7 @@ namespace PDF_Office.Views.Dialog.ToolsDialogs
         /// 当前显示了线段的Item
         /// 当前显示了线段的Item
         /// </summary>
         /// </summary>
         private ListViewItem listViewItem = null;
         private ListViewItem listViewItem = null;
+        private bool IsFile = false;
         public MergeDialog()
         public MergeDialog()
         {
         {
             InitializeComponent();
             InitializeComponent();
@@ -47,6 +50,18 @@ namespace PDF_Office.Views.Dialog.ToolsDialogs
                 {
                 {
                     return;
                     return;
                 }
                 }
+                //点击删除按钮
+                Button Button = CommonHelper.FindVisualParent<Button>(result.VisualHit);
+                if (Button != null)
+                {
+                    return;
+                }
+                //点击下拉框
+                WritableComboBox writableComboBox = CommonHelper.FindVisualParent<WritableComboBox>(result.VisualHit);
+                if (writableComboBox != null)
+                {
+                    return;
+                }
                 var treeViewItem = CommonHelper.FindVisualParent<ListViewItem>(result.VisualHit);
                 var treeViewItem = CommonHelper.FindVisualParent<ListViewItem>(result.VisualHit);
                 if (treeViewItem == null)
                 if (treeViewItem == null)
                 {
                 {
@@ -61,7 +76,17 @@ namespace PDF_Office.Views.Dialog.ToolsDialogs
 
 
         private void MergeView_Drop(object sender, DragEventArgs e)
         private void MergeView_Drop(object sender, DragEventArgs e)
         {
         {
+            if (IsFile)
+            {
+                DragDropHelper.Drop(this, e);
+                string[] file = (string[])e.Data.GetData(DataFormats.FileDrop);
+                (DataContext as MergeDialogViewModel).AddFiles(file);
+            }
             ListViewItem souredata = e.Data.GetData(typeof(ListViewItem)) as ListViewItem;
             ListViewItem souredata = e.Data.GetData(typeof(ListViewItem)) as ListViewItem;
+            if (souredata == null)
+            {
+                return;
+            }
             MergeObject soureNode = souredata.DataContext as MergeObject;
             MergeObject soureNode = souredata.DataContext as MergeObject;
             Point pos = e.GetPosition(MergeView);
             Point pos = e.GetPosition(MergeView);
             HitTestResult result = VisualTreeHelper.HitTest(MergeView, pos);
             HitTestResult result = VisualTreeHelper.HitTest(MergeView, pos);
@@ -89,6 +114,10 @@ namespace PDF_Office.Views.Dialog.ToolsDialogs
 
 
         private void MergeView_DragOver(object sender, DragEventArgs e)
         private void MergeView_DragOver(object sender, DragEventArgs e)
         {
         {
+            if (IsFile)
+            {
+                DragDropHelper.DragOver(this, e);
+            }
             ListViewItem sourceitem = e.Data.GetData(typeof(ListViewItem)) as ListViewItem;
             ListViewItem sourceitem = e.Data.GetData(typeof(ListViewItem)) as ListViewItem;
             if (sourceitem == null)
             if (sourceitem == null)
             {
             {
@@ -137,6 +166,11 @@ namespace PDF_Office.Views.Dialog.ToolsDialogs
 
 
         private void MergeView_DragLeave(object sender, DragEventArgs e)
         private void MergeView_DragLeave(object sender, DragEventArgs e)
         {
         {
+            if (IsFile)
+            {
+                DragDropHelper.DragLeave();
+            }
+
             HiddenaAllLine();
             HiddenaAllLine();
         }
         }
 
 
@@ -152,5 +186,56 @@ namespace PDF_Office.Views.Dialog.ToolsDialogs
                 listViewItem = null;
                 listViewItem = null;
             }
             }
         }
         }
+
+        private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
+        {
+            Regex regex = new Regex("[^0-9.]+");
+            e.Handled = regex.IsMatch(e.Text);
+        }
+
+        private void TextBoxEx_LostFocus(object sender, RoutedEventArgs e)
+        {
+            try
+            {
+                double Tag = Double.Parse((sender as TextBox).Text);
+                if (Tag <= 0)
+                {
+                    (sender as TextBox).Text = "";
+                }
+            }
+            catch (Exception)
+            {
+                (sender as TextBox).Text = "";
+            }
+        }
+
+        private void TextBoxEx_PreviewKeyDown(object sender, KeyEventArgs e)
+        {
+            if (e.Key == Key.Enter)
+            {
+                BtnAdd.Focus();
+                e.Handled = true;
+            }
+        }
+
+        private void MergeView_DragEnter(object sender, DragEventArgs e)
+        {
+            IsFile = false;
+            var file = (System.Array)e.Data.GetData(DataFormats.FileDrop);
+            if (file == null)//为null 表示内部拖动 触发的
+            {
+                return;
+            }
+            foreach (string f in file)
+            {
+                System.IO.FileInfo info = new System.IO.FileInfo(f);
+                //只要拖拽进来的文件里包含有pdf格式文件,就允许拖入
+                if (System.IO.Path.GetExtension(f).ToLower() == ".pdf" && info.Length > 0)
+                {
+                    DragDropHelper.DragEnter(this, e);
+                    IsFile = true;
+                }
+            }
+        }
     }
     }
 }
 }