Quellcode durchsuchen

Undo Redo - 注释属性面板部分

weixiangjie vor 10 Monaten
Ursprung
Commit
6d71a5277e

+ 37 - 9
Demo/Examples/Compdfkit_Tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFFreeTextUI.xaml.cs

@@ -5,10 +5,14 @@ using Compdfkit_Tools.Data;
 using Compdfkit_Tools.PDFControl;
 using ComPDFKitViewer;
 using System;
+using System.Linq;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Forms;
 using System.Windows.Media;
+using ComPDFKit.Tool.Help;
+using ComPDFKit.Tool.UndoManger;
+using ComPDFKitViewer.Helper;
 using static ComPDFKit.PDFAnnotation.CTextAttribute.CFontNameHelper;
 
 namespace Compdfkit_Tools.PDFControlUI
@@ -151,11 +155,18 @@ namespace Compdfkit_Tools.PDFControlUI
             }
             else
             {
-                textAnnot.SetTransparency((byte)(CPDFOpacityControl.OpacityValue / 100.0*255));
-                textAnnot.UpdateAp();
-                if (viewControl != null && viewControl.PDFViewTool != null)
+                if (viewControl != null && textParam.Transparency != CPDFOpacityControl.OpacityValue)
                 {
+                    FreeTextAnnotHistory history = new FreeTextAnnotHistory();
+                    history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
+                    history.Action = HistoryAction.Update;
+                    history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, textAnnot.Page.PageIndex, textAnnot);
+                    textAnnot.SetTransparency((byte)(CPDFOpacityControl.OpacityValue / 100.0*255));
+                    textAnnot.UpdateAp();
                     viewControl.UpdateAnnotFrame();
+                    
+                    history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, textAnnot.Page.PageIndex, textAnnot);
+                    viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
                 }
             }
             CPDFAnnotationPreviewerControl.DrawFreeTextPreview(GetFreeTextData());
@@ -177,11 +188,20 @@ namespace Compdfkit_Tools.PDFControlUI
                     fontColor.G, 
                     fontColor.B,
                 };
-                textAnnot.SetFreetextDa(textAttr);
-                textAnnot.UpdateAp();
-                if (viewControl != null && viewControl.PDFViewTool != null)
+                
+                if (viewControl != null && !textAnnot.FreeTextDa.FontColor.SequenceEqual(textAttr.FontColor))
                 {
+                    FreeTextAnnotHistory history = new FreeTextAnnotHistory();
+                    history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
+                    history.Action = HistoryAction.Update;
+                    history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, textAnnot.Page.PageIndex, textAnnot);
+                    
+                    textAnnot.SetFreetextDa(textAttr);
+                    textAnnot.UpdateAp();
                     viewControl.UpdateAnnotFrame() ;
+                    
+                    history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, textAnnot.Page.PageIndex, textAnnot);
+                    viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
                 }
             }
             CPDFAnnotationPreviewerControl.DrawFreeTextPreview(GetFreeTextData());
@@ -195,11 +215,19 @@ namespace Compdfkit_Tools.PDFControlUI
             }
             else
             {
-                textAnnot.SetContent(NoteTextBox.Text);
-                textAnnot.UpdateAp();
-                if (viewControl != null && viewControl.PDFViewTool != null)
+                if (viewControl != null && textParam.Content != NoteTextBox.Text)
                 {
+                    FreeTextAnnotHistory history = new FreeTextAnnotHistory();
+                    history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
+                    history.Action = HistoryAction.Update;
+                    history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, textAnnot.Page.PageIndex, textAnnot);
+                    
                     viewControl.UpdateAnnotFrame();
+                    textAnnot.SetContent(NoteTextBox.Text);
+                    textAnnot.UpdateAp();
+                    
+                    history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, textAnnot.Page.PageIndex, textAnnot);
+                    viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
                 }
             }
         }

+ 62 - 17
Demo/Examples/Compdfkit_Tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFFreehandUI.xaml.cs

@@ -6,9 +6,12 @@ using ComPDFKit.Tool.Help;
 using Compdfkit_Tools.Data;
 using Compdfkit_Tools.PDFControl;
 using System;
+using System.Linq;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Media;
+using ComPDFKit.Tool.UndoManger;
+using ComPDFKitViewer.Helper;
 
 namespace Compdfkit_Tools.PDFControlUI
 {
@@ -56,8 +59,20 @@ namespace Compdfkit_Tools.PDFControlUI
                 {
                     transparent = transparent * 255;
                 }
-                cPDFAnnotation.SetTransparency((byte)transparent);
-                pdfViewerControl.UpdateAnnotFrame();
+                if (inkParam.Transparency != (byte)transparent && pdfViewerControl != null)
+                {
+                    InkAnnotHistory history = new InkAnnotHistory();
+                    history.PDFDoc = pdfViewerControl.GetCPDFViewer().GetDocument();
+                    history.Action = HistoryAction.Update;
+                    history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
+                
+                    cPDFAnnotation.SetTransparency((byte)transparent);
+                    pdfViewerControl.UpdateAnnotFrame();
+
+
+                    history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
+                    pdfViewerControl.GetCPDFViewer().UndoManager.AddHistory(history);
+                }
             }
             CPDFAnnotationPreviewerControl.DrawFreehandPreview(GetFreehandData());
 
@@ -71,11 +86,21 @@ namespace Compdfkit_Tools.PDFControlUI
             }
             else
             {
-                cPDFAnnotation.SetThickness(CPDFThicknessControl.Thickness);
-                pdfViewerControl.UpdateAnnotFrame();
+                if (Math.Abs(inkParam.Thickness - CPDFThicknessControl.Thickness) > 0.01 && pdfViewerControl != null)
+                {
+                    InkAnnotHistory history = new InkAnnotHistory();
+                    history.PDFDoc = pdfViewerControl.GetCPDFViewer().GetDocument();
+                    history.Action = HistoryAction.Update;
+                    history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
+
+                    cPDFAnnotation.SetThickness(CPDFThicknessControl.Thickness);
+                    pdfViewerControl.UpdateAnnotFrame();
+                    
+                    history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
+                    pdfViewerControl.GetCPDFViewer().UndoManager.AddHistory(history);
+                }
             }
             CPDFAnnotationPreviewerControl.DrawFreehandPreview(GetFreehandData());
-
         }
 
         private void ColorPickerControl_ColorChanged(object sender, EventArgs e)
@@ -87,12 +112,25 @@ namespace Compdfkit_Tools.PDFControlUI
             }
             else
             {
-                byte[] Color = new byte[3];
-                Color[0] = ((SolidColorBrush)ColorPickerControl.Brush).Color.R;
-                Color[1] = ((SolidColorBrush)ColorPickerControl.Brush).Color.G;
-                Color[2] = ((SolidColorBrush)ColorPickerControl.Brush).Color.B;
-                cPDFAnnotation.SetInkColor(Color);
-                pdfViewerControl.UpdateAnnotFrame();
+                byte[] color = new byte[3];
+                color[0] = ((SolidColorBrush)ColorPickerControl.Brush).Color.R;
+                color[1] = ((SolidColorBrush)ColorPickerControl.Brush).Color.G;
+                color[2] = ((SolidColorBrush)ColorPickerControl.Brush).Color.B;
+                
+                if (!cPDFAnnotation.InkColor.SequenceEqual(color) && pdfViewerControl != null)
+                {
+                    InkAnnotHistory history = new InkAnnotHistory();
+                    history.PDFDoc = pdfViewerControl.GetCPDFViewer().GetDocument();
+                    history.Action = HistoryAction.Update;
+                    history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
+                    
+                    cPDFAnnotation.SetInkColor(color);
+                    pdfViewerControl.UpdateAnnotFrame();
+                    
+                    history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
+                    pdfViewerControl.GetCPDFViewer().UndoManager.AddHistory(history);
+                }
+                
             }
             CPDFAnnotationPreviewerControl.DrawFreehandPreview(GetFreehandData());
 
@@ -106,12 +144,19 @@ namespace Compdfkit_Tools.PDFControlUI
             }
             else
             {
-                byte[] Color = new byte[3];
-                Color[0] = ((SolidColorBrush)ColorPickerControl.Brush).Color.R;
-                Color[1] = ((SolidColorBrush)ColorPickerControl.Brush).Color.G;
-                Color[2] = ((SolidColorBrush)ColorPickerControl.Brush).Color.B;
-                cPDFAnnotation.SetContent(NoteTextBox.Text);
-                pdfViewerControl.UpdateAnnotFrame();
+                if (inkParam.Content != NoteTextBox.Text && pdfViewerControl != null)
+                {
+                    InkAnnotHistory history = new InkAnnotHistory();
+                    history.PDFDoc = pdfViewerControl.GetCPDFViewer().GetDocument();
+                    history.Action = HistoryAction.Update;
+                    history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
+                    
+                    cPDFAnnotation.SetContent(NoteTextBox.Text);
+                    pdfViewerControl.UpdateAnnotFrame();
+                    
+                    history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, cPDFAnnotation.Page.PageIndex, cPDFAnnotation);
+                    pdfViewerControl.GetCPDFViewer().UndoManager.AddHistory(history);
+                }
             }
         }
 

+ 15 - 3
Demo/Examples/Compdfkit_Tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFLinkUI.xaml.cs

@@ -13,6 +13,8 @@ using ComPDFKit.PDFDocument;
 using ComPDFKitViewer;
 using Compdfkit_Tools.PDFControl;
 using ComPDFKit.Tool.Help;
+using ComPDFKit.Tool.UndoManger;
+using ComPDFKitViewer.Helper;
 
 namespace Compdfkit_Tools.Annotation.PDFAnnotationUI
 {
@@ -177,10 +179,20 @@ namespace Compdfkit_Tools.Annotation.PDFAnnotationUI
                     default:
                         break;
                 }
-                if (ParamConverter.SetParamForPDFAnnot(viewControl.GetCPDFViewer().GetDocument(), linkAnnot, linkParam))
+
+                if (viewControl != null)
                 {
-                    viewControl.UpdateAnnotFrame();
-                };
+                    LinkAnnotHistory history = new LinkAnnotHistory();
+                    history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
+                    history.Action = HistoryAction.Update;
+                    history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, linkAnnot.Page.PageIndex, linkAnnot);
+                    if (ParamConverter.SetParamForPDFAnnot(viewControl.GetCPDFViewer().GetDocument(), linkAnnot, linkParam))
+                    {
+                        viewControl.UpdateAnnotFrame();
+                        history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, linkAnnot.Page.PageIndex, linkAnnot);
+                        viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
+                    };
+                }
             }
             else
             {

+ 55 - 6
Demo/Examples/Compdfkit_Tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFMarkupUI.xaml.cs

@@ -5,9 +5,13 @@ using Compdfkit_Tools.Data;
 using Compdfkit_Tools.PDFControl;
 using ComPDFKitViewer;
 using System;
+using System.Linq;
 using System.Windows.Controls;
 using System.Windows.Media;
 using Compdfkit_Tools.Helper;
+using ComPDFKit.Tool.Help;
+using ComPDFKit.Tool.UndoManger;
+using ComPDFKitViewer.Helper;
 
 namespace Compdfkit_Tools.PDFControlUI
 {
@@ -28,6 +32,25 @@ namespace Compdfkit_Tools.PDFControlUI
             ColorPickerControl.ColorChanged += ColorPickerControl_ColorChanged;
             CPDFOpacityControl.OpacityChanged += CPDFOpacityControl_OpacityChanged;
         }
+        
+        private AnnotHistory GetAnnotHistory()
+        {
+            if (markupAnnot != null && markupAnnot.IsValid())
+            {
+                switch (markupAnnot.Type)
+                {
+                    case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
+                        return new LineAnnotHistory();
+                    case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
+                        return new UnderlineAnnotHistory();
+                    case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
+                        return new StrikeoutAnnotHistory();
+                    case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
+                        return new SquigglyAnnotHistory();
+                }
+            }
+            return new AnnotHistory();
+        }
 
         private void CPDFOpacityControl_OpacityChanged(object sender, EventArgs e)
         {
@@ -39,10 +62,19 @@ namespace Compdfkit_Tools.PDFControlUI
             {
                 if(markupAnnot!=null && markupAnnot.IsValid())
                 {
-                    markupAnnot.SetTransparency((byte)(CPDFOpacityControl.OpacityValue / 100.0 * 255));
+                    byte opacity = (byte)(CPDFOpacityControl.OpacityValue / 100.0 * 255);
                     if (viewControl != null && viewControl.PDFViewTool != null)
                     {
+                        AnnotHistory history = GetAnnotHistory();
+                        history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
+                        history.Action = HistoryAction.Update;
+                        history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, markupAnnot.Page.PageIndex, markupAnnot);
+                        
+                        markupAnnot.SetTransparency(opacity);
                         viewControl.UpdateAnnotFrame();
+                        
+                        history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, markupAnnot.Page.PageIndex, markupAnnot);
+                        viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
                     }
                 }
             }
@@ -60,15 +92,24 @@ namespace Compdfkit_Tools.PDFControlUI
                 SolidColorBrush colorBrush = ColorPickerControl.Brush as SolidColorBrush;
                 if (markupAnnot != null && markupAnnot.IsValid() && colorBrush!=null)
                 {
-                    markupAnnot.SetColor(new byte[3]
+                    byte[] color = new byte[3]
                     {
                         colorBrush.Color.R,
                         colorBrush.Color.G,
                         colorBrush.Color.B
-                    });
-                    if (viewControl != null && viewControl.PDFViewTool != null)
+                    };
+                    if (viewControl != null && !markupAnnot.Color.SequenceEqual(color))
                     {
+                        AnnotHistory history = GetAnnotHistory();
+                        history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
+                        history.Action = HistoryAction.Update;
+                        history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, markupAnnot.Page.PageIndex, markupAnnot);
+                        
+                        markupAnnot.SetColor(color);
                         viewControl.UpdateAnnotFrame();
+                        
+                        history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, markupAnnot.Page.PageIndex, markupAnnot);
+                        viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
                     }
                 }
             }
@@ -85,10 +126,18 @@ namespace Compdfkit_Tools.PDFControlUI
             {
                 if (markupAnnot != null && markupAnnot.IsValid())
                 {
-                    markupAnnot.SetContent(NoteTextBox.Text);
-                    if (viewControl != null && viewControl.PDFViewTool != null)
+                    if (viewControl != null && markupAnnot.GetContent() != NoteTextBox.Text)
                     {
+                        AnnotHistory history = GetAnnotHistory();
+                        history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
+                        history.Action = HistoryAction.Update;
+                        history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, markupAnnot.Page.PageIndex, markupAnnot);
+                        
+                        markupAnnot.SetContent(NoteTextBox.Text);
                         viewControl.UpdateAnnotFrame();
+                        
+                        history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, markupAnnot.Page.PageIndex, markupAnnot);
+                        viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
                     }
                 }
             }

+ 27 - 5
Demo/Examples/Compdfkit_Tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFNoteUI.xaml.cs

@@ -5,8 +5,12 @@ using Compdfkit_Tools.Data;
 using Compdfkit_Tools.PDFControl;
 using ComPDFKitViewer;
 using System;
+using System.Linq;
 using System.Windows.Controls;
 using System.Windows.Media;
+using ComPDFKit.Tool.Help;
+using ComPDFKit.Tool.UndoManger;
+using ComPDFKitViewer.Helper;
 
 namespace Compdfkit_Tools.PDFControlUI
 {
@@ -36,15 +40,25 @@ namespace Compdfkit_Tools.PDFControlUI
                 SolidColorBrush colorBrush= ColorPickerControl.Brush as SolidColorBrush;
                 if (textAnnot!=null && textAnnot.IsValid() && colorBrush!=null)
                 {
-                    textAnnot.SetColor(new byte[3]
+                    byte[] color = new byte[3]
                     {
                         colorBrush.Color.R,
                         colorBrush.Color.G,
                         colorBrush.Color.B
-                    });
-                    if (viewControl != null && viewControl.PDFViewTool != null)
+                    };
+                    
+                    if (viewControl != null && !textAnnot.Color.SequenceEqual(color))
                     {
+                        StickyNoteAnnotHistory history = new StickyNoteAnnotHistory();
+                        history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
+                        history.Action = HistoryAction.Update;
+                        history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, textAnnot.Page.PageIndex, textAnnot);
+                        
+                        textAnnot.SetColor(color);
                         viewControl.UpdateAnnotFrame();
+                        
+                        history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, textAnnot.Page.PageIndex, textAnnot);
+                        viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
                     }
                 }
             }
@@ -61,10 +75,18 @@ namespace Compdfkit_Tools.PDFControlUI
             {
                 if (textAnnot != null && textAnnot.IsValid())
                 {
-                    textAnnot.SetContent(NoteTextBox.Text);
-                    if (viewControl != null && viewControl.PDFViewTool != null)
+                    if (viewControl != null && textAnnot.GetContent() != NoteTextBox.Text)
                     {
+                        StickyNoteAnnotHistory history = new StickyNoteAnnotHistory();
+                        history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
+                        history.Action = HistoryAction.Update;
+                        history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, textAnnot.Page.PageIndex, textAnnot);
+                        
+                        textAnnot.SetContent(NoteTextBox.Text);
                         viewControl.UpdateAnnotFrame();
+                        
+                        history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, textAnnot.Page.PageIndex, textAnnot);
+                        viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
                     }
                 }
             }

+ 175 - 107
Demo/Examples/Compdfkit_Tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFShapeUI.xaml.cs

@@ -8,11 +8,15 @@ using ComPDFKitViewer.Annot;
 using System;
 using System.Collections.Generic;
 using System.IO.Ports;
+using System.Linq;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Media;
 using Compdfkit_Tools.Helper;
 using ComPDFKit.PDFAnnotation;
+using ComPDFKit.Tool.Help;
+using ComPDFKit.Tool.UndoManger;
+using ComPDFKitViewer.Helper;
 
 namespace Compdfkit_Tools.PDFControlUI
 {
@@ -41,6 +45,23 @@ namespace Compdfkit_Tools.PDFControlUI
             CPDFAnnotationPreviewerControl.DrawShapePreview(GetShapeData());
         }
 
+        private AnnotHistory GetHistory()
+        {
+            if (annotCore != null && annotCore.IsValid())
+            {
+                switch (annotCore.Type)
+                {
+                    case C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE:
+                        return new SquareAnnotHistory();
+                    case C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE:
+                        return new CircleAnnotHistory();
+                    case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
+                        return new LineAnnotHistory();
+                }
+            }
+            return new AnnotHistory();
+        }
+
         private void BorderColorPickerControl_ColorChanged(object sender, EventArgs e)
         {
             if (annotParam == null)
@@ -52,41 +73,46 @@ namespace Compdfkit_Tools.PDFControlUI
                 SolidColorBrush borderBrush=BorderColorPickerControl.Brush as SolidColorBrush;
                 if(annotCore!=null && annotCore.IsValid() && borderBrush!=null)
                 {
-                    if(annotCore.Type==C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE)
+                    byte[] color = new byte[3]
                     {
-                        CPDFSquareAnnotation squareAnnot = annotCore as CPDFSquareAnnotation;
-                        squareAnnot?.SetLineColor(new byte[3]
-                        {
-                            borderBrush.Color.R,
-                            borderBrush.Color.G,
-                            borderBrush.Color.B
-                        });
-                    }
-                   
-                    if(annotCore.Type==C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE)
+                        borderBrush.Color.R,
+                        borderBrush.Color.G,
+                        borderBrush.Color.B
+                    };
+                    if (viewControl != null)
                     {
-                        CPDFCircleAnnotation circleAnnot= annotCore as CPDFCircleAnnotation;
-                        circleAnnot?.SetLineColor(new byte[3]
+                        AnnotHistory history = GetHistory();
+                        history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
+                        history.Action = HistoryAction.Update;
+                        if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE)
                         {
-                            borderBrush.Color.R,
-                            borderBrush.Color.G,
-                            borderBrush.Color.B
-                        });
-                    }
+                            CPDFSquareAnnotation squareAnnot = annotCore as CPDFSquareAnnotation;
+                            if (squareAnnot == null || squareAnnot.LineColor.SequenceEqual(color)) return;
+                            history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, squareAnnot);
+                            squareAnnot?.SetLineColor(color);
+                            history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, squareAnnot);
+                            
+                        }
 
-                    if(annotCore.Type==C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
-                    {
-                        CPDFLineAnnotation lineAnnot = annotCore as CPDFLineAnnotation;
-                        lineAnnot?.SetLineColor(new byte[3]
+                        if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE)
                         {
-                            borderBrush.Color.R,
-                            borderBrush.Color.G,
-                            borderBrush.Color.B
-                        });
-                    }
+                            CPDFCircleAnnotation circleAnnot = annotCore as CPDFCircleAnnotation;
+                            if (circleAnnot == null || circleAnnot.LineColor.SequenceEqual(color)) return;
+                            history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, circleAnnot);
+                            circleAnnot?.SetLineColor(color);
+                            history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, circleAnnot);
+                        }
 
-                    if (viewControl != null && viewControl.PDFViewTool != null)
-                    {
+                        if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
+                        {
+                            CPDFLineAnnotation lineAnnot = annotCore as CPDFLineAnnotation;
+                            if (lineAnnot == null || lineAnnot.LineColor.SequenceEqual(color)) return;
+                            history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, lineAnnot);
+                            lineAnnot?.SetLineColor(color);
+                            history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, lineAnnot);
+                        }
+
+                        viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
                         viewControl.UpdateAnnotFrame();
                     }
                 } 
@@ -105,41 +131,44 @@ namespace Compdfkit_Tools.PDFControlUI
                 SolidColorBrush fillBrush = FillColorPickerControl.Brush as SolidColorBrush;
                 if (annotCore != null && annotCore.IsValid() && fillBrush != null)
                 {
-                    if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE)
+                    byte[] color = new byte[3]
                     {
-                        CPDFSquareAnnotation squareAnnot = annotCore as CPDFSquareAnnotation;
-                        squareAnnot?.SetBgColor(new byte[3]
-                        {
-                            fillBrush.Color.R,
-                            fillBrush.Color.G,
-                            fillBrush.Color.B
-                        });
-                    }
-
-                    if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE)
+                        fillBrush.Color.R,
+                        fillBrush.Color.G,
+                        fillBrush.Color.B
+                    };
+                    if (viewControl != null && viewControl.PDFViewTool != null)
                     {
-                        CPDFCircleAnnotation circleAnnot = annotCore as CPDFCircleAnnotation;
-                        circleAnnot?.SetBgColor(new byte[3]
+                        AnnotHistory history = GetHistory();
+                        history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
+                        history.Action = HistoryAction.Update;
+                        if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE)
                         {
-                            fillBrush.Color.R,
-                            fillBrush.Color.G,
-                            fillBrush.Color.B
-                        });
-                    }
+                            CPDFSquareAnnotation squareAnnot = annotCore as CPDFSquareAnnotation;
+                            if (squareAnnot == null || squareAnnot.BgColor.SequenceEqual(color)) return;
+                            history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, squareAnnot);
+                            squareAnnot?.SetBgColor(color);
+                            history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, squareAnnot);
+                        }
 
-                    if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
-                    {
-                        CPDFLineAnnotation lineAnnot = annotCore as CPDFLineAnnotation;
-                        lineAnnot?.SetBgColor(new byte[3]
+                        if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE)
                         {
-                            fillBrush.Color.R,
-                            fillBrush.Color.G,
-                            fillBrush.Color.B
-                        });
-                    }
+                            CPDFCircleAnnotation circleAnnot = annotCore as CPDFCircleAnnotation;
+                            if (circleAnnot == null || circleAnnot.BgColor.SequenceEqual(color)) return;
+                            history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, circleAnnot);
+                            circleAnnot?.SetBgColor(color);
+                            history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, circleAnnot);
+                        }
 
-                    if (viewControl != null && viewControl.PDFViewTool != null)
-                    {
+                        if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
+                        {
+                            CPDFLineAnnotation lineAnnot = annotCore as CPDFLineAnnotation;
+                            if (lineAnnot == null || lineAnnot.BgColor.SequenceEqual(color)) return;
+                            history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, lineAnnot);
+                            lineAnnot?.SetBgColor(color);
+                            history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, lineAnnot);
+                        }
+                        viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
                         viewControl.UpdateAnnotFrame();
                     }
                 }
@@ -155,30 +184,39 @@ namespace Compdfkit_Tools.PDFControlUI
             }
             else
             {
-                
                 if (annotCore != null && annotCore.IsValid())
                 {
-                    if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE)
+                    if (viewControl != null && Math.Abs(CPDFThicknessControl.Thickness - annotCore.GetBorderWidth()) > 0.01)
                     {
-                        CPDFSquareAnnotation squareAnnot = annotCore as CPDFSquareAnnotation;
-                        squareAnnot?.SetLineWidth(CPDFThicknessControl.Thickness);
-                    }
+                        AnnotHistory history = GetHistory();
+                        history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
+                        history.Action = HistoryAction.Update;
 
-                    if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE)
-                    {
-                        CPDFCircleAnnotation circleAnnot = annotCore as CPDFCircleAnnotation;
-                        circleAnnot?.SetLineWidth(CPDFThicknessControl.Thickness);
+                        if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE)
+                        {
+                            CPDFSquareAnnotation squareAnnot = annotCore as CPDFSquareAnnotation;
+                            history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, squareAnnot);
+                            squareAnnot?.SetLineWidth(CPDFThicknessControl.Thickness);
+                            history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, squareAnnot);
+                        }
 
-                    }
+                        if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE)
+                        {
+                            CPDFCircleAnnotation circleAnnot = annotCore as CPDFCircleAnnotation;
+                            history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, circleAnnot);
+                            circleAnnot?.SetLineWidth(CPDFThicknessControl.Thickness);
+                            history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, circleAnnot);
 
-                    if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
-                    {
-                        CPDFLineAnnotation lineAnnot = annotCore as CPDFLineAnnotation;
-                        lineAnnot?.SetLineWidth(CPDFThicknessControl.Thickness);
-                    }
+                        }
 
-                    if (viewControl != null && viewControl.PDFViewTool != null)
-                    {
+                        if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
+                        {
+                            CPDFLineAnnotation lineAnnot = annotCore as CPDFLineAnnotation;
+                            history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, lineAnnot);
+                            lineAnnot?.SetLineWidth(CPDFThicknessControl.Thickness);
+                            history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, lineAnnot);
+                        }
+                        viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
                         viewControl.UpdateAnnotFrame();
                     }
                 }
@@ -201,26 +239,35 @@ namespace Compdfkit_Tools.PDFControlUI
                 }
                 if (annotCore != null && annotCore.IsValid())
                 {
-                    if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE)
+                    if (viewControl != null && Math.Abs(opacity - annotCore.GetTransparency()) > 0.01)
                     {
-                        CPDFSquareAnnotation squareAnnot = annotCore as CPDFSquareAnnotation;
-                        squareAnnot?.SetTransparency((byte)opacity);
-                    }
-
-                    if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE)
-                    {
-                        CPDFCircleAnnotation circleAnnot = annotCore as CPDFCircleAnnotation;
-                        circleAnnot?.SetTransparency((byte)opacity);
-                    }
+                        AnnotHistory history = GetHistory();
+                        history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
+                        history.Action = HistoryAction.Update;
+                        if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE)
+                        {
+                            CPDFSquareAnnotation squareAnnot = annotCore as CPDFSquareAnnotation;
+                            history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, squareAnnot);
+                            squareAnnot?.SetTransparency((byte)opacity);
+                            history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, squareAnnot);
+                        }
 
-                    if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
-                    {
-                        CPDFLineAnnotation lineAnnot = annotCore as CPDFLineAnnotation;
-                        lineAnnot?.SetTransparency((byte)opacity);
-                    }
+                        if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE)
+                        {
+                            CPDFCircleAnnotation circleAnnot = annotCore as CPDFCircleAnnotation;
+                            history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, circleAnnot);
+                            circleAnnot?.SetTransparency((byte)opacity);
+                            history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, circleAnnot);
+                        }
 
-                    if (viewControl != null && viewControl.PDFViewTool != null)
-                    {
+                        if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
+                        {
+                            CPDFLineAnnotation lineAnnot = annotCore as CPDFLineAnnotation;
+                            history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, lineAnnot);
+                            lineAnnot?.SetTransparency((byte)opacity);
+                            history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, lineAnnot);
+                        }
+                        viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
                         viewControl.UpdateAnnotFrame();
                     }
                 }
@@ -256,30 +303,40 @@ namespace Compdfkit_Tools.PDFControlUI
                         borderStyle = C_BORDER_STYLE.BS_DASHDED;
                     }
 
-                    if (dashArray != null)
+                    if (viewControl != null && viewControl.PDFViewTool != null)
                     {
+                        AnnotHistory history = GetHistory();
+                        history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
+                        history.Action = HistoryAction.Update;
+                        
                         if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE)
                         {
                             CPDFSquareAnnotation squareAnnot = annotCore as CPDFSquareAnnotation;
-                            squareAnnot?.SetBorderStyle(borderStyle, dashArray);
+                            if(squareAnnot == null || squareAnnot.Dash.SequenceEqual(dashArray))return;
+                            history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, squareAnnot);
+                            squareAnnot.SetBorderStyle(borderStyle, dashArray);
+                            history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, squareAnnot);
                         }
 
                         if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE)
                         {
                             CPDFCircleAnnotation circleAnnot = annotCore as CPDFCircleAnnotation;
-                            circleAnnot?.SetBorderStyle(borderStyle, dashArray);
+                            if (circleAnnot == null || circleAnnot.Dash.SequenceEqual(dashArray)) return;
+                            history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, circleAnnot);
+                            circleAnnot.SetBorderStyle(borderStyle, dashArray);
+                            history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, circleAnnot);
                         }
 
                         if (annotCore.Type == C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
                         {
                             CPDFLineAnnotation lineAnnot = annotCore as CPDFLineAnnotation;
-                            lineAnnot?.SetBorderStyle(borderStyle, dashArray);
-                        }
-
-                        if (viewControl != null && viewControl.PDFViewTool != null)
-                        {
-                            viewControl.UpdateAnnotFrame();
+                            if (lineAnnot == null || lineAnnot.Dash.SequenceEqual(dashArray)) return;
+                            history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, lineAnnot);
+                            lineAnnot.SetBorderStyle(borderStyle, dashArray);
+                            history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, lineAnnot);
                         }
+                        viewControl.UpdateAnnotFrame();
+                        viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
                     }
                 }
             }
@@ -299,11 +356,17 @@ namespace Compdfkit_Tools.PDFControlUI
                     if(annotCore.Type==C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
                     {
                         CPDFLineAnnotation lineAnnot= annotCore as CPDFLineAnnotation;
-                        if(lineAnnot!=null)
+                        if(lineAnnot!=null && viewControl != null)
                         {
-                            lineAnnot.SetLineType(CPDFArrowControl.LineType.HeadLineType, CPDFArrowControl.LineType.TailLineType);
-                            if (viewControl != null && viewControl.PDFViewTool != null)
+                            if(lineAnnot.HeadLineType != CPDFArrowControl.LineType.HeadLineType || lineAnnot.TailLineType != CPDFArrowControl.LineType.TailLineType)
                             {
+                                LineAnnotHistory history = new LineAnnotHistory();
+                                history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
+                                history.Action = HistoryAction.Update;
+                                history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, lineAnnot);
+                                lineAnnot.SetLineType(CPDFArrowControl.LineType.HeadLineType, CPDFArrowControl.LineType.TailLineType);
+                                history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, lineAnnot);
+                                viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
                                 viewControl.UpdateAnnotFrame();
                             }
                         }
@@ -323,11 +386,16 @@ namespace Compdfkit_Tools.PDFControlUI
             {
                 if (annotCore != null && annotCore.IsValid())
                 {
-                    annotCore.SetContent(NoteTextBox.Text);
-
-                    if (viewControl != null && viewControl.PDFViewTool != null)
+                    if (viewControl != null && annotCore.GetContent()!=NoteTextBox.Text)
                     {
+                        AnnotHistory history = GetHistory();
+                        history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
+                        history.Action = HistoryAction.Update;
+                        history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, annotCore);
+                        annotCore.SetContent(NoteTextBox.Text);
                         viewControl.UpdateAnnotFrame();
+                        history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, annotCore);
+                        viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
                     }
                 }
             }

+ 13 - 2
Demo/Examples/Compdfkit_Tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFTempStampUI.xaml.cs

@@ -8,6 +8,9 @@ using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
+using ComPDFKit.Tool.Help;
+using ComPDFKit.Tool.UndoManger;
+using ComPDFKitViewer.Helper;
 
 namespace Compdfkit_Tools.PDFControlUI
 {
@@ -38,11 +41,19 @@ namespace Compdfkit_Tools.PDFControlUI
         {
             if(stampAnnot != null && stampAnnot.IsValid())
             {
-                stampAnnot.SetContent(NoteTextBox.Text);
-                stampAnnot.UpdateAp();
                 if (viewControl != null && viewControl.PDFViewTool != null)
                 {
+                    StampAnnotHistory history = new StampAnnotHistory();
+                    history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
+                    history.Action = HistoryAction.Update;
+                    history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, stampAnnot.Page.PageIndex, stampAnnot);
+                    
+                    stampAnnot.SetContent(NoteTextBox.Text);
+                    stampAnnot.UpdateAp();
                     viewControl.UpdateAnnotFrame();
+                    
+                    history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, stampAnnot.Page.PageIndex, stampAnnot);
+                    viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
                 }
             }
         }

+ 7 - 4
Demo/Examples/Compdfkit_Tools/Common/PropertyControl/PDFThickness/CPDThicknessUI.xaml.cs

@@ -20,10 +20,13 @@ namespace Compdfkit_Tools.Common
             }
             set
             {
-                _thickness = value;
-                DropDownNumberBoxControl.SelectValueItem(_thickness);
-                OnPropertyChanged(nameof(Thickness));
-                OnThicknessChanged();
+                if (_thickness != value)
+                {
+                    _thickness = value;
+                    DropDownNumberBoxControl.SelectValueItem(_thickness);
+                    OnPropertyChanged(nameof(Thickness));
+                    OnThicknessChanged();
+                }
             }
         }
 

+ 4 - 4
Demo/Examples/PDFViewer/PDFViewer.csproj

@@ -24,10 +24,10 @@
     <DebugType>full</DebugType>
     <Optimize>false</Optimize>
     <OutputPath>bin\Debug\</OutputPath>
-    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DefineConstants>TRACE;DEBUG;Windows</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
-    <Prefer32bit>true</Prefer32bit>
+    <Prefer32bit>false</Prefer32bit>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <PlatformTarget>AnyCPU</PlatformTarget>
@@ -45,12 +45,12 @@
   <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
     <DebugSymbols>true</DebugSymbols>
     <OutputPath>bin\x64\Debug\</OutputPath>
-    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DefineConstants>DEBUG;TRACE;Windows</DefineConstants>
     <DebugType>full</DebugType>
     <PlatformTarget>x64</PlatformTarget>
     <LangVersion>7</LangVersion>
     <ErrorReport>prompt</ErrorReport>
-    <Prefer32Bit>true</Prefer32Bit>
+    <Prefer32Bit>false</Prefer32Bit>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
     <OutputPath>bin\x64\Release\</OutputPath>