//
//  CPDFListView.h
//  ComPDFKit
//
//  Copyright © 2014-2022 PDF Technologies, Inc. All Rights Reserved.
//
//  THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
//  AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
//  UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
//  This notice may not be removed from this file.
//

#import <ComPDFKit/ComPDFKit.h>
#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>
#import <KMDrawViewSDK_Mac/KMDrawViewSDK_Mac.h>
#define SKAnnotationKey @"SKAnnotation"

extern NSString *SKPasteboardTypeLineStyle;

extern NSNotificationName const CPDFListViewSelectionChangedNotification;

extern NSNotificationName const CPDFListViewToolModeChangeNotification;

extern NSNotificationName const CPDFListViewAnnotationTypeChangeNotification;

extern NSNotificationName const CPDFListViewMagnificationChangedNotification;

extern NSNotificationName const CPDFListViewDidAddAnnotationNotification;

extern NSNotificationName const CPDFListViewDidRemoveAnnotationNotification;

extern NSNotificationName const CPDFListViewActiveAnnotationsChangeNotification;

extern NSNotificationName const CPDFListViewAnnotationsAttributeHasChangeNotification;

extern NSNotificationName const KMPDFViewTableAnnotationDidChangeNotification;

extern NSNotificationName const CPDFListViewDisplayModeChangeNotification;

typedef NS_ENUM(NSInteger, CPDFViewSidebarSpeedMode) {
    CPDFViewSidebarSpeedModeLeft = 0,
    CPDFViewSidebarSpeedModeRight
};

typedef NS_ENUM(NSInteger, CAnnotationType) {
    CAnnotationTypeUnkown = 0,
    CAnnotationTypeAnchored,
    CAnnotationTypeLink,
    CAnnotationTypeFreeText,
    CAnnotationTypeLine,
    CAnnotationTypeArrow,
    CAnnotationTypeSquare,
    CAnnotationTypeCircle,
    CAnnotationTypePolyGon,
    CAnnotationTypePolyLine,
    CAnnotationTypeHighlight,
    CAnnotationTypeUnderline,
    CAnnotationTypeSquiggly,
    CAnnotationTypeStrikeOut,
    CAnnotationTypeStamp,
    CAnnotationTypeSignSignature,
    /*CAnnotationTypeCaret,*/
    CAnnotationTypeInk,
    /*CAnnotationTypePopUp,*/
    /*CAnnotationTypeFileattachment,*/
    /*CAnnotationTypeSound,*/
    /*CAnnotationTypeMovie,*/
    CAnnotationTypeRedact,
    CAnnotationTypeEraser,
    CAnnotationTypeEditTextImage,
    CAnnotationTypeAddText,
    CAnnotationTypeAddImage,
    
    CAnnotationTypeRadioButton = 100,
    CAnnotationTypeCheckBox,
    CAnnotationTypeTextField,
    CAnnotationTypeComboBox,
    CAnnotationTypeListMenu,
    CAnnotationTypeActionButton,
    CAnnotationTypeSignature,
    
    CAnnotationTypeSignText = 200,
    CAnnotationTypeSignFalse,
    CAnnotationTypeSignTure,
    CAnnotationTypeSignCircle,
    CAnnotationTypeSignLine,
    CAnnotationTypeSignDot,
    CAnnotationTypeSignConfig,
    CAnnotationTypeSignDate,
    
    CAnnotationTypeTable,
};

typedef NS_ENUM(NSInteger, CToolMode) {
    CTextToolMode = 0,
    CMoveToolMode,
    CMagnifyToolMode,
    CSelectToolMode,
    CNoteToolMode,
    CSelectZoomToolMode,
    CFormToolMode,
    CSelfSignMode,
    CRedactToolMode,
    CMeasureToolMode,
    CRedactErasureToolMode,
    CEditPDFToolMode,
};

typedef NS_ENUM(NSUInteger, KMPDFActiveFormsAlignType) {
    KMPDFActiveFormsAlignType_Left = 0,
    KMPDFActiveFormsAlignType_Vertical,
    KMPDFActiveFormsAlignType_Right,
    KMPDFActiveFormsAlignType_Top,
    KMPDFActiveFormsAlignType_Horizontally,
    KMPDFActiveFormsAlignType_Bottom,
    KMPDFActiveFormsAlignType_DisHorizontally,
    KMPDFActiveFormsAlignType_DisVertical
};

typedef NS_ENUM(NSUInteger, KMPDFViewActiveFormsType) {
    KMPDFViewActiveFormsType_NotAllform = -1,//注释类型不全为form类型
    KMPDFViewActiveFormsType_Mix = 0,//包含多种类型的form(全为form)
    KMPDFViewActiveFormsType_Pure,//单纯只有一种form(全为form)
    KMPDFViewActiveFormsType_PureSingle,//单纯只有一种form(全为form),个数为1
    KMPDFViewActiveFormsType_Text,//单纯只有一种form,并且是text(全为form)
    KMPDFViewActiveFormsType_TextSingle,//单纯只有一种form,并且是text(全为form),个数为1
    KMPDFViewActiveFormsType_None
};

typedef NS_ENUM(NSUInteger, KMPDFViewMode) {
    KMPDFViewModeNormal = 0,
    KMPDFViewModeSoft,
    KMPDFViewModeNight,
    KMPDFViewModeGreen,
    KMPDFViewModeThemes1,
    KMPDFViewModeThemes2,
    KMPDFViewModeThemes3,
    KMPDFViewModeThemes4,
    KMPDFViewModeOther
};

typedef NS_ENUM(NSInteger, KMPDFViewSplitMode) {
    KMPDFViewSplitModeDisable = 0,
    KMPDFViewSplitModeHorizontal,
    KMPDFViewSplitModeVertical
};

enum {
    SKDragArea = 1 << 16,
    SKResizeUpDownArea = 1 << 17,
    SKResizeLeftRightArea = 1 << 18,
    SKResizeDiagonal45Area = 1 << 19,
    SKResizeDiagonal135Area = 1 << 20,
    SKReadingBarArea = 1 << 21,
    SKSpecialToolArea = 1 << 22
};

@protocol CPDFListViewDelegate;

@class CStampSignatureObject,CPDFListStampAnnotation,CPDFListSignatureAnnotation, KMFormListMenuPopWindowController, KMTableCellData;

@interface CPDFListView : CPDFView

@property (nonatomic, weak) id<CPDFListViewDelegate>pdfListViewDelegate;

// Methods for The currently selected Annotation.

@property (nonatomic, readonly) NSMutableArray <CPDFAnnotation *>*activeAnnotations;

// Methods for The currently selected Annotation.

@property (nonatomic, readonly) CPDFAnnotation * activeAnnotation;

// Methods for The annotation type currently selected.

@property (nonatomic, assign) CAnnotationType annotationType;

// Method of the currently selected annotation mode.

@property (nonatomic, assign) CToolMode toolMode;

// The magnification times when the current magnifying glass is in mode

@property (nonatomic, readonly) CGFloat magnification;

@property (nonatomic, assign) BOOL isSetLinkDestinationArea;

// Show Annotation or not

@property (nonatomic, assign) BOOL hideNotes;

// Whether to display a Form comment hop number

@property (nonatomic, assign) BOOL showHopnumber;

// Whether to display the Form name

@property (nonatomic, assign) BOOL showFormFieldName;

// Auxiliary reference line
@property (nonatomic, strong) CAShapeLayer *shapeLayerLeftV;
@property (nonatomic, strong) CAShapeLayer *shapeLayerRightV;
@property (nonatomic, strong) CAShapeLayer *shapeLayerTopH;
@property (nonatomic, strong) CAShapeLayer *shapeLayerBottomH;

@property (nonatomic, assign) NSPoint lastAddAnnotationPoint;

@property (nonatomic, assign) BOOL isCreatAnnotation;
@property (nonatomic, assign) NSInteger toolBarCreateAnnotationMenuItem;

@property (nonatomic, assign) BOOL isTakeSnapeSelectConetent;

@property (nonatomic, assign) KMPDFViewMode viewMode;
@property (nonatomic, assign) KMPDFViewSplitMode viewSplitMode;

@property (nonatomic, strong) KMFormListMenuPopWindowController *listWindowController;
@property (nonatomic, strong) NSTrackingArea *trackingArea;
@property (nonatomic, strong) NSImage *originImage;

@property (nonatomic,retain) KMTableCellData *cellCopyData;
@property (nonatomic,retain) NSTextField  *tableTextField;
@property (nonatomic, assign) NSPoint dragTablePoint;

@property (nonatomic, assign) BOOL editAreaBoundUpdating;

// Measurement attribute setting
@property (nonatomic, retain) CPDFDistanceMeasureInfo *distanceMeasureInfo;
@property (nonatomic, retain) CPDFPerimeterMeasureInfo *perimeterMeasureInfo;
@property (nonatomic, retain) CPDFAreaMeasureInfo *polygonAreaMeasureInfo;
@property (nonatomic, retain) CPDFAreaMeasureInfo *squareAreaMeasureInfo;

@property (nonatomic, assign) BOOL isPresentationMode;

@property (nonatomic, strong) KMDrawView *presentationDrawView;

- (CPDFAnnotation *)addAnnotationWithType:(CAnnotationType)annotationType selection:(CPDFSelection *)selection page:(CPDFPage *)page bounds:(NSRect)bounds;
- (void)addAnnotationWithAnnotation:(CPDFAnnotation *)annotation toPage:(CPDFPage *)page;

// Add stamp Annotation, add directly after mouse click
// a new parameter.
//   stampObject    - stamp Object.
//   isToolModel    - Whether it is a pattern

- (void)setAddStampObject:(CStampSignatureObject *)stampObject keepToolModel:(BOOL)isToolModel;

// Add an image Stamp note

- (void)addAnnotationWithImage:(NSImage *)image page:(CPDFPage *)page point:(NSPoint)point;

// Refresh the currently selected Annotation

- (void)updateActiveAnnotations:(NSArray<CPDFAnnotation *> *)activeAnnotation;

// Edit Annotation

- (void)editAnnotation:(CPDFAnnotation *)annotation;

// Rotate Stamp notes, angle 0-360 degrees,Rotation is supported only by the current addition

- (void)rotateStampAnnotation:(CPDFListStampAnnotation *)annotation rotateAngle:(NSInteger)angle;

// Rotate Signature notes, angle 0-360 degrees,Rotation is supported only by the current addition

- (void)rotateSignatureAnnotation:(CPDFListSignatureAnnotation *)annotation rotateAngle:(NSInteger)angle;

// When selecting a region mode, the selected region is obtained

- (NSRect)currentSelectionRect;

// Scale the page to the specified range

- (void)zoomToRect:(NSRect)rect onPage:(CPDFPage *)page;

// Remove Auxiliary reference line

- (void)removeShapeLayer;

// Determines whether the current annotation is consistent with the selected annotation mode

- (BOOL)consistentTypeWithAnnotation:(CPDFAnnotation *)annotation;

- (void)formsAnnotationAlign:(KMPDFActiveFormsAlignType)type;

- (void)addImageAnnotation:(NSImage *)image center:(NSPoint)center isRemoveBGColor:(BOOL)isRemoveBGColor;

- (void)setPageBackgroundColorWithColor:(NSColor *)color viewMode:(KMPDFViewMode)viewMode;

- (BOOL)writeSelectionToPasteboard:(NSPasteboard *)pboard types:(NSArray *)types;

- (void)enterPresentationDrawMode;

- (BOOL)isEnterPresentationDrawMode;

- (void)changePresentationDrawModelColor:(NSColor *)color;

- (void)resetPresentationDrawMode;

- (void)exitPresentationDrawMode;

- (KMDrawView *)CreatePresentationDrawView;

@end

@protocol CPDFListViewDelegate <NSObject>

@optional

- (void)PDFListViewChangedSelectionOrMagnification:(CPDFListView *)pdfListView;

- (void)PDFListViewDidSelectionEnd:(CPDFListView *)pdfListView;

- (void)PDFListViewChangedMagnification:(CPDFListView *)pdfListView;

- (void)PDFListViewChangedToolMode:(CPDFListView *)pdfListView forToolMode:(CToolMode)toolMode;

- (void)PDFListViewChangedAnnotationType:(CPDFListView *)pdfListView forAnnotationType:(CAnnotationType)annotationType;

- (NSColor *)PDFListViewBackgroundColor;

- (void)PDFListViewAddAnnotations:(CPDFListView *)pdfListView forAddAnnotations:(NSArray<CPDFAnnotation *> *)annotations inPage:(CPDFPage *)pdfPage;

- (void)PDFListViewRemoveAnnotations:(CPDFListView *)pdfListView forRemoveAnnotations:(NSArray<CPDFAnnotation *> *)annotations inPage:(CPDFPage *)pdfPage;

- (void)PDFListViewDeleteAnnotations:(CPDFListView *)pdfListView forDeleteAnnotations:(NSArray<CPDFAnnotation *> *)annotations inPage:(CPDFPage *)pdfPage;

- (void)PDFListViewChangeatioActiveAnnotations:(CPDFListView *)pdfListView forActiveAnnotations:(NSArray<CPDFAnnotation *> *)annotations isRightMenu:(BOOL)isRightMenu;

- (void)PDFListViewMenuForEvent:(CPDFListView *)pdfListView forEvent:(NSEvent *)theEvent clickMenu:(NSMenu **)menu isMoveSelectAnno:(BOOL)isMoveSelectAnno;

- (BOOL)PDFListViewMenuValidate:(CPDFListView *)pdfListView menuItem:(NSMenuItem *)menuItem isTakesEffect:(BOOL *)isTakesEffect;

- (void)PDFListViewEditAnnotation:(CPDFListView *)pdfListView forAnnotation:(CPDFAnnotation *)anotation;

- (BOOL)PDFListViewKeyDownIsContinue:(CPDFListView *)pdfListView theEvent:(NSEvent *)theEvent;

- (NSArray<NSMenuItem *> *)PDFListViewMenuItemsEditingAtPoint:(CGPoint)point forPage:(CPDFPage *)page menuItems:(NSArray <NSMenuItem *>*)menuItems;

- (void)PDFListViewDidTextFontChanged:(CPDFListView *)pdfListView;

- (void)PDFListViewDidTextColorChanged:(CPDFListView *)pdfListView withColor:(NSColor *)color;

- (void)PDFListViewRedactErasure:(CPDFListView *)pdfListView;

- (void)PDFListViewLinkDestinationStart:(CPDFListView *)pdfListView withActiveAnnotation:(CPDFAnnotation *)annotation;

- (void)PDFListViewLinkDestinationEnd:(CPDFListView *)pdfListView withActiveAnnotation:(CPDFAnnotation *)annotation;

- (void)PDFListViewKeyDowClosePanel:(CPDFViewSidebarSpeedMode)speedy event:(NSEvent *)theEvent;

- (NSArray<NSColor *> *)PDFListViewEventMarkupColorWithAnnotation:(CPDFAnnotation *)annotation;

- (BOOL)PDFListViewHaveDocumentAttribute;

// 是否需要绘制注释 【文字、背景】
- (BOOL)PDFListView:(CPDFListView *)pdfListView needDrawAnnotation:(CPDFAnnotation *)annotation;

- (void)PDFListViewAnnotationAttributeHasChange:(CPDFListView *)pdfListView withAnnotation:(CPDFAnnotation *)annotation;

- (void)PDFListView:(CPDFListView *)sender showSnapshotAtPageNumber:(NSInteger)pageNum forRect:(NSRect)rect scaleFactor:(CGFloat)scaleFactor autoFits:(BOOL)autoFits;

- (void)PDFListView:(CPDFListView *)pdfView documentDataDidChanged:(id)docData withInfo:(NSDictionary *)info;

- (void)PDFListViewAnnotationMeasureInfoChange:(CPDFListView *)pdfListView withAnnotation:(CPDFAnnotation *)annotation;

- (void)PDFListViewMeasureCancel:(CPDFListView *)pdfListView;

@end