1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147 |
- //
- // KMAnnotationPropertiesViewController.m
- // SignFlow
- //
- // Created by wanjun on 2021/6/15.
- //
- #import "KMAnnotationPropertiesViewController.h"
- //#import "NSString_SKExtensions.h"
- #import <PDF_Reader_Pro-Swift.h>
- #import "KMSignatureAnnotationViewController.h"
- #import "CSelfSignAnnotation.h"
- #import "CSelfSignAnnotationFreeText.h"
- #define KMFromContentButtonHeightFloat 32
- @interface KMClipView : NSClipView
- @end
- @implementation KMClipView
- - (BOOL)isFlipped {
- return YES;
- }
- @end
- @interface KMAnnotationPropertiesViewController ()
- @property (assign) IBOutlet NSBox *propertiesBox;
- @property (nonatomic,assign) IBOutlet NSView *gradientView;
- @property (weak) IBOutlet NSImageView *emptyImageView;
- @property (nonatomic,assign) IBOutlet NSTextField *titleLabel;
- @property (nonatomic,assign) IBOutlet NSTextField *subTitleLabel;
- @property (nonatomic,assign) IBOutlet NSView *emptyView;
- @property (nonatomic,retain) NSViewController *contentViewController;
- @property (weak) IBOutlet NSLayoutConstraint *titleViewHeightConstraint;
- @property (weak) IBOutlet NSLayoutConstraint *buttonbuttonLayoutConstraint;
- @property (assign) IBOutlet NSView *buttonView;
- @property (assign) IBOutlet NSButton *formGeneralButton;
- @property (assign) IBOutlet NSButton *formAppearanceButton;
- @property (assign) IBOutlet NSButton *formOptionsButton;
- @property (assign) IBOutlet NSView *tipsView;
- @property (assign) IBOutlet NSTextField *tipsLabel;
- @property (assign) IBOutlet NSImageView *oneLineImageView;
- @property (assign) IBOutlet NSImageView *lastLineImageView;
- @property (nonatomic, retain) NSButton *clickBtn;
- @end
- @implementation KMAnnotationPropertiesViewController
- #pragma mark - View Methods
- //func addNotification() {
- // NotificationCenter.default.addObserver(self, selector: #selector(changeEffectiveAppearance), name: NSNotification.Name(rawValue: "kEffectiveAppearance"), object: nil)
- //}
- //
- //func removeNotification() {
- // NotificationCenter.default.removeObserver(self)
- // DistributedNotificationCenter.default().removeObserver(self)
- //}
- //
- //@objc func changeEffectiveAppearance() {
- // let isDarkModel = KMAdvertisementConfig.isDarkModel()
- // if isDarkModel {
- // self.appearance = NSAppearance(named: .darkAqua)
- // } else {
- // self.appearance = NSAppearance(named: .aqua)
- // }
- // self.updateUI()
- //}
- - (void)dealloc {
- [self removeNotification];
- }
- - (void)addNotification {
- [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(changeEffectiveAppearance) name:@"kEffectiveAppearance" object:nil];
- }
- - (void)removeNotification {
- [NSNotificationCenter.defaultCenter removeObserver:self];
- }
- - (void)changeEffectiveAppearance {
- BOOL isDarkModel = [KMAdvertisementConfig isDarkModel];
- if (isDarkModel) {
- self.view.appearance = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
- self.view.layer.backgroundColor = [NSColor km_initWithHex:@"#252526" alpha:1].CGColor;
- } else {
- self.view.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
- self.view.layer.backgroundColor = [NSColor km_initWithHex:@"#FAFAFA" alpha:1].CGColor;
- }
- }
- - (void)loadView {
- [super loadView];
-
- [self addNotification];
-
- self.view.wantsLayer = YES;
- // self.view.layer.backgroundColor = [KMAppearance viewBackgroundColor].CGColor;
- // self.view.layer.backgroundColor = [NSColor colorWithRed:247.0/255.0 green:248.0/255.0 blue:250.0/255.0 alpha:1].CGColor;
- [self changeEffectiveAppearance];
- self.view.layer.shadowColor = [NSColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.15].CGColor;
- self.view.layer.shadowOffset = NSMakeSize(0, 0);
- self.view.layer.shadowRadius = 4;
-
- self.emptyImageView.image = [NSImage imageNamed:@"KMImageNameMarkupEmpty"];
- self.subTitleLabel.stringValue = NSLocalizedString(@"Show/Hide Annotation Properties Panel", nil);
- NSMutableParagraphStyle *ps = [[NSMutableParagraphStyle alloc] init];
- ps.lineSpacing = 10;
- ps.alignment = NSTextAlignmentCenter;
- NSString *subTitle = self.subTitleLabel.stringValue != nil ? self.subTitleLabel.stringValue : @"";
- self.subTitleLabel.attributedStringValue = [[NSAttributedString alloc] initWithString:subTitle attributes:@{
- NSForegroundColorAttributeName : [NSColor colorWithRed:148/255.f green:152/255.f blue:156/255.f alpha:1.f],
- NSFontAttributeName : [NSFont fontWithName:@"SFProText-Regular" size:12],
- NSParagraphStyleAttributeName : ps}];
- self.subTitleLabel.textColor = [NSColor grayColor];
-
- self.titleLabel.font = [NSFont SFProTextSemiboldFont:14.0];
- self.titleLabel.textColor = [KMAppearance KMColor_Layout_H0];
- // [NSColor colorWithRed:0.145 green:0.149 blue:0.161 alpha:1];
-
- self.buttonView.hidden = YES;
- self.formGeneralButton.wantsLayer = YES;
- self.formAppearanceButton.wantsLayer = YES;
- self.formOptionsButton.wantsLayer = YES;
- [self updateFormContentButtonUI:self.formAppearanceButton];
- self.formAppearanceButton.toolTip = NSLocalizedString(@"Appearance", nil);
- [self.formAppearanceButton setTitle:NSLocalizedString(@"Appearance", nil)];
- self.formGeneralButton.toolTip = NSLocalizedString(@"General", nil);
- [self.formGeneralButton setTitle:NSLocalizedString(@"General", nil)];
- self.formOptionsButton.toolTip = NSLocalizedString(@"Preferences", nil);
- [self.formOptionsButton setTitle:NSLocalizedString(@"Preferences", nil)];
-
- self.tipsView.hidden = YES;
- self.tipsView.wantsLayer = YES;
- self.tipsView.layer.cornerRadius = 1.0;
-
- self.oneLineImageView.wantsLayer = YES;
- self.lastLineImageView.wantsLayer = YES;
-
- self.oneLineImageView.hidden = YES;
- }
- #pragma mark - Setter Methods
- -(void)setAnnotations:(NSArray *)annotations
- {
- if (_annotations != annotations) {
- _annotations = annotations;
- }
-
- self.buttonView.hidden = YES;
- CPDFAnnotation *annotation = _annotations.firstObject;
- if (self.contentViewController) {
- [self.contentViewController.view removeFromSuperview];
- self.contentViewController = nil;
- }
- if (!annotation || [annotation isKindOfClass:[CPDFRedactAnnotation class]]) {
- return;
- }
- if (_annotations.count > 1) {
- if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]] ||
- [annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]] ||
- [annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
-
- } else {
- [self selectAnnotations:_annotations];
- return;
- }
- }
-
- if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]){
- self.titleLabel.stringValue = NSLocalizedString(@"Text Field", nil);
- } else if ([annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
- CPDFButtonWidgetAnnotation *buttonWidget = (CPDFButtonWidgetAnnotation *)annotation;
- if (buttonWidget.controlType == 1) {
- self.titleLabel.stringValue = NSLocalizedString(@"Radio Button", nil);
- } else if (buttonWidget.controlType == 2) {
- self.titleLabel.stringValue = NSLocalizedString(@"Check Box", nil);
- } else if (buttonWidget.controlType == 0) {
- self.titleLabel.stringValue = NSLocalizedString(@"Button", nil);
- }
- } else if ([annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
- CPDFChoiceWidgetAnnotation *choiceWidget = (CPDFChoiceWidgetAnnotation *)annotation;
- if (choiceWidget.isListChoice) {
- self.titleLabel.stringValue = NSLocalizedString(@"List Box", nil);
- } else {
- self.titleLabel.stringValue = NSLocalizedString(@"Combo Box", nil);
- }
- } else if ([annotation isKindOfClass:[KMSelfSignAnnotation class]]) {
- KMSelfSignAnnotation *newAnnotation = (KMSelfSignAnnotation *)annotation;
- CAnnotationType type = newAnnotation.annotationType;
- NSString *returnString = @"";
- if (type == CAnnotationTypeSignFalse) {
- returnString = NSLocalizedString(@"X", nil);
- } else if (type == CAnnotationTypeSignTure) {
- returnString = NSLocalizedString(@"Check mark", nil);
- } else if (type == CAnnotationTypeSignCircle) {
- returnString = NSLocalizedString(@"Circle", nil);
- } else if (type == CAnnotationTypeSignLine) {
- returnString = NSLocalizedString(@"Line", nil);
- } else if (type == CAnnotationTypeSignDot) {
- returnString = NSLocalizedString(@"Dot", nil);
- } else if (type == CAnnotationTypeSignText) {
- returnString = NSLocalizedString(@"Text", nil);
- }
- self.titleLabel.stringValue = returnString;
- } else if ([annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
- self.titleLabel.stringValue = NSLocalizedString(@"Link", @"Description for export");
- } else if ([annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
- if ([annotation isKindOfClass:[KMSelfSignAnnotationFreeText class]]) {
- KMSelfSignAnnotationFreeText *signFreeText = (KMSelfSignAnnotationFreeText *)annotation;
- if (signFreeText.subType == KMSelfSignAnnotationFreeTextSubTypeProfile) {
- self.titleLabel.stringValue = NSLocalizedString(@"Text", nil);
- } else {
- self.titleLabel.stringValue = NSLocalizedString(@"Date", nil);
- }
- } else {
- self.titleLabel.stringValue = [annotation type].typeName;
- }
- } else if ([annotation isKindOfClass:[CPDFSignatureWidgetAnnotation class]] ||
- [annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
- self.titleLabel.stringValue = NSLocalizedString(@"Signature", nil);
- } else if ([annotation isKindOfClass:[CSelfSignAnnotation class]]) {
- CSelfSignAnnotation *newAnnotation = (CSelfSignAnnotation *)annotation;
- if (newAnnotation.annotationType == CAnnotationTypeSignFalse) {
- self.titleLabel.stringValue = NSLocalizedString(@"X", nil);
- } else if (newAnnotation.annotationType == CAnnotationTypeSignTure) {
- self.titleLabel.stringValue = NSLocalizedString(@"Check mark", nil);
- } else if (newAnnotation.annotationType == CAnnotationTypeSignCircle) {
- self.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
- } else if (newAnnotation.annotationType == CAnnotationTypeSignLine) {
- self.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
- } else if (newAnnotation.annotationType == CAnnotationTypeSignDot) {
- self.titleLabel.stringValue = NSLocalizedString(@"Dot", nil);
- } else if (newAnnotation.annotationType == CAnnotationTypeSignText) {
- self.titleLabel.stringValue = NSLocalizedString(@"Text", nil);
- } else if (newAnnotation.annotationType == CAnnotationTypeSignDate) {
- self.titleLabel.stringValue = NSLocalizedString(@"Date", nil);
- }
- } else if ([annotation isKindOfClass:[CPDFStampAnnotation class]]) {
- self.titleLabel.stringValue = NSLocalizedString(@"Stamp", nil);
- } else if ([annotation isKindOfClass:[KMTableAnnotation class]]) {
- self.titleLabel.stringValue = NSLocalizedString(@"Table", nil);
- } else if ([annotation isKindOfClass:[CPDFLineAnnotation class]]) {
- if (self.pdfView.toolMode == CMeasureToolMode ||
- [(CPDFLineAnnotation *)annotation isMeasure]) {
- self.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
- }
- } else if ([annotation isKindOfClass:[CPDFPolylineAnnotation class]]) {
- self.titleLabel.stringValue = NSLocalizedString(@"Multilines", nil);
- } else if ([annotation isKindOfClass:[CPDFPolygonAnnotation class]]) {
- if (self.pdfView.annotationType == CAnnotationTypeSquare) {
- self.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
- } else {
- self.titleLabel.stringValue = NSLocalizedString(@"Polygon", nil);
- }
- } else {
- self.titleLabel.stringValue = [annotation type].typeName;
- }
- self.titleViewHeightConstraint.constant = 40;
- CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
- if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]] ||
- [annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]] ||
- [annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
- self.buttonView.hidden = NO;
- if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]) {
- [self updateFormContentButtonUI:_formGeneralButton];
- KMAnnotationGeneralViewController *vc = [[KMAnnotationGeneralViewController alloc] init];
- vc.pdfview = self.pdfView;
- vc.annotationModel = annotationModel;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- } else if ([annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
- [self fromContentButtonAction:_formOptionsButton];
- } else if ([annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
- CPDFButtonWidgetAnnotation *newAnnotation = (CPDFButtonWidgetAnnotation *)annotation;
- if (newAnnotation.controlType == CPDFWidgetRadioButtonControl || newAnnotation.controlType == CPDFWidgetCheckBoxControl) {
- [self updateFormContentButtonUI:_formGeneralButton];
- KMAnnotationGeneralViewController *vc = [[KMAnnotationGeneralViewController alloc] init];
- vc.pdfview = self.pdfView;
- vc.annotations = self.annotations;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- } else if (newAnnotation.controlType == CPDFWidgetPushButtonControl) {
- [self fromContentButtonAction:_formOptionsButton];
- }
- }
- } else if ([annotation isKindOfClass:[KMAnnotationFromSignature class]]) {
- KMAnnotationGeneralViewController *vc = [[KMAnnotationGeneralViewController alloc] init];
- vc.pdfview = self.pdfView;
- vc.annotationModel = annotationModel;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- } else if ([annotation isKindOfClass:[CPDFSignatureWidgetAnnotation class]]) {
- if (!_isClickFormSignature) {
- KMAnnotationGeneralViewController *vc = [[KMAnnotationGeneralViewController alloc] init];
- vc.pdfview = self.pdfView;
- vc.annotationModel = annotationModel;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- }
- _isClickFormSignature = NO;
- } else if ([annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
- CPDFLinkAnnotation *linkAnnotation = annotations.firstObject;
- NSString *contents = nil;
- if ([linkAnnotation URL]) {
- contents = [linkAnnotation URL];
- if (contents) {
- contents = [NSString stringWithFormat:@"1%@", contents];
- } else {
- contents = @"";
- }
- } else {
- contents = [NSString stringWithFormat:@"0%@", @([[linkAnnotation destination] pageIndex]+1)];
- }
-
- KMAnnotationSelectLinkViewController *vc = [[KMAnnotationSelectLinkViewController alloc] init];
- vc.annotations = self.annotations;
- vc.pdfDocument = self.pdfView.document;
- vc.pdfview = self.pdfView;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- } else if ([annotation isKindOfClass:[CSelfSignAnnotation class]]) {
- CSelfSignAnnotation *newAnnotation = (CSelfSignAnnotation *)annotation;
- if (newAnnotation.annotationType == CAnnotationTypeSignFalse ||
- newAnnotation.annotationType == CAnnotationTypeSignTure ||
- newAnnotation.annotationType == CAnnotationTypeSignCircle ||
- newAnnotation.annotationType == CAnnotationTypeSignLine ||
- newAnnotation.annotationType == CAnnotationTypeSignDot) {
- KMAnnotationSelfSignViewController *vc = [[KMAnnotationSelfSignViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- __weak typeof (self) weakSelf = self;
- vc.callBack = ^(CAnnotationType type) {
- if (type == CAnnotationTypeSignFalse) {
- weakSelf.titleLabel.stringValue = NSLocalizedString(@"X", nil);
- } else if (type == CAnnotationTypeSignTure) {
- weakSelf.titleLabel.stringValue = NSLocalizedString(@"Check mark", nil);
- } else if (type == CAnnotationTypeSignCircle) {
- weakSelf.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
- } else if (type == CAnnotationTypeSignLine) {
- weakSelf.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
- } else if (type == CAnnotationTypeSignDot) {
- weakSelf.titleLabel.stringValue = NSLocalizedString(@"Dot", nil);
- }
-
- if (weakSelf.annoTypeDidChange != nil) {
- weakSelf.annoTypeDidChange(annotation);
- }
- };
- } else if (newAnnotation.annotationType == CAnnotationTypeSignText ||
- newAnnotation.annotationType == CAnnotationTypeSignDate) {
- KMSelfSignAnnotationFreeTextSubType subType = KMSelfSignAnnotationFreeTextSubTypeNone;
- if (annotationModel.annotationType == CAnnotationTypeSignConfig) {
- subType = KMSelfSignAnnotationFreeTextSubTypeProfile;
- } else if (annotationModel.annotationType == CAnnotationTypeSignText) {
- subType = KMSelfSignAnnotationFreeTextSubTypeFreeText;
- } else if (annotationModel.annotationType == CAnnotationTypeSignDate) {
- subType = KMSelfSignAnnotationFreeTextSubTypeDate;
- }
- KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
- vc.subType = subType;
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- }
- } else if ([annotation isKindOfClass:[CSelfSignAnnotationFreeText class]]) {
- CSelfSignAnnotationFreeText *newAnnotation = (CSelfSignAnnotationFreeText *)annotation;
- if (newAnnotation.subType == CAnnotationTypeSignText ||
- newAnnotation.subType == CAnnotationTypeSignDate) {
- KMSelfSignAnnotationFreeTextSubType subType = KMSelfSignAnnotationFreeTextSubTypeNone;
- if (annotationModel.annotationType == CAnnotationTypeSignConfig) {
- subType = KMSelfSignAnnotationFreeTextSubTypeProfile;
- } else if (annotationModel.annotationType == CAnnotationTypeSignText) {
- subType = KMSelfSignAnnotationFreeTextSubTypeFreeText;
- } else if (annotationModel.annotationType == CAnnotationTypeSignDate) {
- subType = KMSelfSignAnnotationFreeTextSubTypeDate;
- }
- KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
- vc.subType = subType;
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- }
-
- } else if ([annotation isKindOfClass:[CPDFSignatureAnnotation class]] ||
- [annotation isKindOfClass:[CPDFStampAnnotation class]]) {
- KMAnnotationStampViewController *vc = [[KMAnnotationStampViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- } else if ([annotation isKindOfClass:[KMTableAnnotation class]]) {
- KMAnnotationTableViewController *vc = [[KMAnnotationTableViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- } else if (([annotation isKindOfClass:[CPDFPolylineAnnotation class]]) ||
- ([annotation isKindOfClass:[CPDFPolygonAnnotation class]])) {
- KMMeasureSideVC *vc = [[KMMeasureSideVC alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- } else if ([annotation isKindOfClass:[CPDFLineAnnotation class]]) {
- if ((self.pdfView.toolMode == CMeasureToolMode) ||
- [(CPDFLineAnnotation *)annotation isMeasure]) {
- KMMeasureSideVC *vc = [[KMMeasureSideVC alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- } else {
- KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- }
- } else {
- if ([annotation isKindOfClass:[CPDFInkAnnotation class]]) {
- KMFreehandAnnotationController *vc = [[KMFreehandAnnotationController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- } else if ([annotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
- CPDFMarkupAnnotation *markupA = (CPDFMarkupAnnotation *)annotation;
- if (markupA.markupType == CPDFMarkupTypeSquiggly) {
- KMWavyLineAnnotationController *vc = [[KMWavyLineAnnotationController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- } else {
- KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- }
- } else {
- KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- }
- }
-
- // self.buttonbuttonLayoutConstraint.constant = self.buttonView.hidden ? -36 : 0;
- }
- - (void)selectAnnotations:(NSArray *)annotations {
- CPDFAnnotation *fristAnnotation = annotations.firstObject;
- CAnnotationType annotationMode = CAnnotationTypeUnkown;
- if ([fristAnnotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
- annotationMode = CAnnotationTypeHighlight;
- } else if ([fristAnnotation isKindOfClass:[CPDFInkAnnotation class]]) {
- annotationMode = CAnnotationTypeInk;
- } else if ([fristAnnotation isKindOfClass:[CPDFTextAnnotation class]]) {
- annotationMode = CAnnotationTypeAnchored;
- } else if ([fristAnnotation isKindOfClass:[CPDFSquareAnnotation class]]) {
- annotationMode = CAnnotationTypeSquare;
- } else if ([fristAnnotation isKindOfClass:[CPDFCircleAnnotation class]]) {
- annotationMode = CAnnotationTypeCircle;
- } else if ([fristAnnotation isKindOfClass:[CPDFLineAnnotation class]]) {
- if(((CPDFLineAnnotation *)fristAnnotation).startLineStyle == CPDFLineStyleNone &&
- ((CPDFLineAnnotation *)fristAnnotation).endLineStyle == CPDFLineStyleOpenArrow ) {
- annotationMode = CAnnotationTypeArrow;
- } else {
- annotationMode = CAnnotationTypeLine;
- }
- } else if ([fristAnnotation isKindOfClass:[CPDFLinkAnnotation class]]) {
- annotationMode = CAnnotationTypeLink;
- } else if ([fristAnnotation isKindOfClass:[CPDFStampAnnotation class]]) {
- if ([fristAnnotation isKindOfClass:[CSelfSignAnnotation class]]) {
- CSelfSignAnnotation *newAnnotation = (CSelfSignAnnotation *)fristAnnotation;
- if (newAnnotation.annotationType == CAnnotationTypeSignFalse)
- annotationMode = CAnnotationTypeSignFalse;
- else if(newAnnotation.annotationType == CAnnotationTypeSignTure)
- annotationMode = CAnnotationTypeSignTure;
- else if(newAnnotation.annotationType == CAnnotationTypeSignCircle)
- annotationMode = CAnnotationTypeSignCircle;
- else if(newAnnotation.annotationType == CAnnotationTypeSignLine)
- annotationMode = CAnnotationTypeSignLine;
- else if(newAnnotation.annotationType == CAnnotationTypeSignDot)
- annotationMode = CAnnotationTypeSignDot;
- else if(newAnnotation.annotationType == CAnnotationTypeSignDot)
- annotationMode = CAnnotationTypeSignDot;
- } else if ([fristAnnotation isKindOfClass:[CSelfSignAnnotationFreeText class]]) {
- CSelfSignAnnotationFreeText *newAnnotation = (CSelfSignAnnotationFreeText *)fristAnnotation;
- if (newAnnotation.subType == CAnnotationTypeSignText)
- annotationMode = CAnnotationTypeSignText;
- else if(newAnnotation.subType == CAnnotationTypeSignDate)
- annotationMode = CAnnotationTypeSignDate;
- } else {
- annotationMode = CAnnotationTypeStamp;
- }
- } else if ([fristAnnotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
- annotationMode = CAnnotationTypeSignature;
- } else if ([fristAnnotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
- if ([fristAnnotation isKindOfClass:[CSelfSignAnnotationFreeText class]]) {
- CSelfSignAnnotationFreeText *newAnnotation = (CSelfSignAnnotationFreeText *)fristAnnotation;
- if (newAnnotation.subType == CAnnotationTypeSignText)
- annotationMode = CAnnotationTypeSignText;
- else if(newAnnotation.subType == CAnnotationTypeSignDate)
- annotationMode = CAnnotationTypeSignDate;
- } else {
- annotationMode = CAnnotationTypeFreeText;
- }
- }
- self.annotationMode = annotationMode;
- }
- - (void)setAnnotationMode:(CAnnotationType)annotationMode {
- _annotationMode = annotationMode;
- if (self.contentViewController) {
- [self.contentViewController.view removeFromSuperview];
- self.contentViewController = nil;
- }
- NSString *title = @"";
- if (annotationMode == CAnnotationTypeFreeText)
- title = NSLocalizedString(@"Text", @"Description for export");
- else if (annotationMode == CAnnotationTypeCircle)
- title = NSLocalizedString(@"Circle", @"Description for export");
- else if (annotationMode == CAnnotationTypeSquare)
- title = NSLocalizedString(@"Rectangle", @"Description for export");
- else if (annotationMode == CAnnotationTypeHighlight) {
- title = NSLocalizedString(@"Highlight", @"Description for export");
- if (_annotations.count > 1)
- title = NSLocalizedString(@"General", @"Description for export");
- }
- else if (annotationMode == CAnnotationTypeUnderline) {
- title = NSLocalizedString(@"Underline", @"Description for export");
- if (_annotations.count > 1)
- title = NSLocalizedString(@"General", @"Description for export");
- }
- else if (annotationMode == CAnnotationTypeStrikeOut)
- title = NSLocalizedString(@"Strikethrough", @"Description for export");
- else if (annotationMode == CAnnotationTypeLine)
- title = NSLocalizedString(@"Line", @"Description for export");
- else if (annotationMode == CAnnotationTypeArrow)
- title = NSLocalizedString(@"Arrow", @"Description for export");
- else if (annotationMode == CAnnotationTypeInk)
- title = NSLocalizedString(@"Freehand", @"Description for export");
- else if (annotationMode == CAnnotationTypeEraser)
- title = NSLocalizedString(@"Eraser", @"Description for export");
- else if (annotationMode == CAnnotationTypeAnchored)
- title = NSLocalizedString(@"Note", @"Description for export");
- else if (annotationMode == CAnnotationTypeLink)
- title = NSLocalizedString(@"Link", @"Description for export");
- else if (annotationMode == CAnnotationTypeTextField)
- title = NSLocalizedString(@"Text Field", @"Description for export");
- else if (annotationMode == CAnnotationTypeCheckBox)
- title = NSLocalizedString(@"Check Box", @"Description for export");
- else if (annotationMode == CAnnotationTypeListMenu)
- title = NSLocalizedString(@"List Box", @"Description for export");
- else if (annotationMode == CAnnotationTypeComboBox)
- title = NSLocalizedString(@"Combo Box", @"Description for export");
- else if (annotationMode == CAnnotationTypeRadioButton)
- title = NSLocalizedString(@"Radio Button", @"Description for export");
- else if (annotationMode == CAnnotationTypeActionButton)
- title = NSLocalizedString(@"Button", @"Description for export");
- else if (annotationMode == CAnnotationTypeSignature)
- title = NSLocalizedString(@"Sample", @"Description for export");
- else if (annotationMode == CAnnotationTypeSignDot)
- title = NSLocalizedString(@"Dot", @"Description for export");
- else if (annotationMode == CAnnotationTypeSignLine)
- title = NSLocalizedString(@"Line", @"Description for export");
- else if (annotationMode == CAnnotationTypeSignCircle)
- title = NSLocalizedString(@"Rectangle", @"Description for export");
- else if (annotationMode == CAnnotationTypeSignFalse)
- title = NSLocalizedString(@"X", nil);
- else if (annotationMode == CAnnotationTypeSignTure)
- title = NSLocalizedString(@"Check mark", nil);
- else if (annotationMode == CAnnotationTypeSignText)
- title = NSLocalizedString(@"Text", nil);
- else if (annotationMode == CAnnotationTypeSignDate)
- title = NSLocalizedString(@"Date", nil);
- else if (annotationMode == CAnnotationTypeStamp)
- title = NSLocalizedString(@"Stamp", nil);
- else if (annotationMode == CAnnotationTypeSquiggly)
- title = NSLocalizedString(@"Squiggly", nil);
- else
- title = @"";
- if(_annotations.count > 1) {
- title = NSLocalizedString(@"Properties", nil);
- }
- self.titleLabel.stringValue = title;
- self.titleViewHeightConstraint.constant = 40;
- CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithAnnotationType:annotationMode];
- if (annotationMode == CAnnotationTypeFreeText ||
- annotationMode == CAnnotationTypeAnchored ||
- annotationMode == CAnnotationTypeCircle ||
- annotationMode == CAnnotationTypeSquare ||
- annotationMode == CAnnotationTypeHighlight ||
- annotationMode == CAnnotationTypeUnderline ||
- annotationMode == CAnnotationTypeStrikeOut ||
- annotationMode == CAnnotationTypeSquiggly ||
- annotationMode == CAnnotationTypeLine ||
- annotationMode == CAnnotationTypeInk ||
- annotationMode == CAnnotationTypeEraser ||
- annotationMode == CAnnotationTypeArrow) {
- //处理多选
- if(_annotations.count > 1) {
- annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
- }
- if (annotationMode == CAnnotationTypeInk) {
- KMFreehandAnnotationController *vc = [[KMFreehandAnnotationController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- } else if (annotationMode == CAnnotationTypeSquiggly) {
- KMWavyLineAnnotationController *vc = [[KMWavyLineAnnotationController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- } else if (annotationMode == CAnnotationTypeEraser) {
- KMEraserAnnotationController *vc = [[KMEraserAnnotationController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- } else {
- KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- }
- } else if (annotationMode == CAnnotationTypeLink) {
- } else if (annotationMode == CAnnotationTypeRadioButton ||
- annotationMode == CAnnotationTypeCheckBox ||
- annotationMode == CAnnotationTypeTextField ||
- annotationMode == CAnnotationTypeComboBox ||
- annotationMode == CAnnotationTypeListMenu ||
- annotationMode == CAnnotationTypeActionButton) {
- if (annotationMode == CAnnotationTypeTextField) {
- KMAnnotationFromViewController *vc = [[KMAnnotationFromViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- } else if (annotationMode == CAnnotationTypeListMenu ||
- annotationMode == CAnnotationTypeComboBox ||
- annotationMode == CAnnotationTypeActionButton) {
- KMAnnotationChoiceWidgetAppearanceViewController *vc = [[KMAnnotationChoiceWidgetAppearanceViewController alloc] init];
- vc.annotationModel = annotationModel;
- vc.pdfView = self.pdfView;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- } else if (annotationMode == CAnnotationTypeRadioButton ||
- annotationMode == CAnnotationTypeCheckBox) {
- KMAnnotationButtonWidgetAppearanceViewController *vc = [[KMAnnotationButtonWidgetAppearanceViewController alloc] init];
- vc.annotationModel = annotationModel;
- vc.pdfView = self.pdfView;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- }
- } else if (annotationMode == CAnnotationTypeSignFalse ||
- annotationMode == CAnnotationTypeSignTure ||
- annotationMode == CAnnotationTypeSignCircle ||
- annotationMode == CAnnotationTypeSignLine ||
- annotationMode == CAnnotationTypeSignDot) {
- if(_annotations.count > 1) {
- annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
- }
- KMAnnotationSelfSignViewController *vc = [[KMAnnotationSelfSignViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- __weak typeof(self) weakSelf = self;
- vc.callBack = ^(CAnnotationType type) {
- if (type == CAnnotationTypeSignFalse) {
- weakSelf.titleLabel.stringValue = NSLocalizedString(@"X", nil);
- } else if (type == CAnnotationTypeSignTure) {
- weakSelf.titleLabel.stringValue = NSLocalizedString(@"Check mark", nil);
- } else if (type == CAnnotationTypeSignCircle) {
- weakSelf.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
- } else if (type == CAnnotationTypeSignLine) {
- weakSelf.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
- } else if (type == CAnnotationTypeSignDot) {
- weakSelf.titleLabel.stringValue = NSLocalizedString(@"Dot", nil);
- }
-
- if (weakSelf.annoTypeDidChange != nil) {
- weakSelf.annoTypeDidChange(weakSelf.annotations.firstObject);
- }
- };
- } else if (annotationMode == CAnnotationTypeSignText ||
- annotationMode == CAnnotationTypeSignDate) {
- if(_annotations.count > 1) {
- annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
- }
- KMSelfSignAnnotationFreeTextSubType subType = KMSelfSignAnnotationFreeTextSubTypeNone;
- if (annotationModel.annotationType == CAnnotationTypeSignConfig) {
- subType = KMSelfSignAnnotationFreeTextSubTypeProfile;
- } else if (annotationModel.annotationType == CAnnotationTypeSignText) {
- subType = KMSelfSignAnnotationFreeTextSubTypeFreeText;
- } else if (annotationModel.annotationType == CAnnotationTypeSignDate) {
- subType = KMSelfSignAnnotationFreeTextSubTypeDate;
- }
- KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
- vc.subType = subType;
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- } else if (annotationMode == CAnnotationTypeStamp) {
- KMAnnotationStampViewController *vc = [[KMAnnotationStampViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- } else if (annotationMode == CAnnotationTypeSignSignature) {
- KMSignatureAnnotationViewController *vc = [[KMSignatureAnnotationViewController alloc] init];
- self.titleViewHeightConstraint.constant = 0;
- vc.annotationModel = annotationModel;
- vc.pdfView = self.pdfView;
- vc.kEventTag = self.kEventTag;
- self.kEventTag = 0;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- }
- }
- - (void)setMeasureMode:(CAnnotationType)annotationMode {
- _annotationMode = annotationMode;
- if (self.contentViewController) {
- [self.contentViewController.view removeFromSuperview];
- self.contentViewController = nil;
- }
- NSString *title = @"";
- if (annotationMode == CAnnotationTypeSquare)
- title = NSLocalizedString(@"Rectangle", @"Description for export");
- else if (annotationMode == CAnnotationTypeLine)
- title = NSLocalizedString(@"Line", @"Description for export");
- else if (annotationMode == CAnnotationTypePolyLine)
- title = NSLocalizedString(@"Multilines", nil);
- else if (annotationMode == CAnnotationTypePolyGon)
- title = NSLocalizedString(@"Polygon", nil);
- else
- title = @"";
- if(_annotations.count > 1) {
- title = NSLocalizedString(@"Properties", nil);
- }
- self.titleLabel.stringValue = title;
- self.titleViewHeightConstraint.constant = 40;
- CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithAnnotationType:annotationMode];
-
- KMMeasureSideVC *vc = [[KMMeasureSideVC alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- }
- - (void)setIsEmptyAnnotation:(BOOL)isEmptyAnnotation
- {
- _isEmptyAnnotation = isEmptyAnnotation;
- if (isEmptyAnnotation) {
- self.titleLabel.hidden = YES;
- self.emptyView.hidden = NO;
- } else {
- self.titleLabel.hidden = NO;
- self.emptyView.hidden = YES;
- }
- }
- - (void)setOpenPropertiesType:(KMOpenPropertiesType)openPropertiesType {
- self.contentViewController = nil;
- self.titleLabel.stringValue = @"";
- self.titleViewHeightConstraint.constant = 0;
- _openPropertiesType = openPropertiesType;
- if (openPropertiesType == KMOpenPropertiesType_PageDisplay) {
- if (self.contentViewController) {
- [self.contentViewController.view removeFromSuperview];
- self.contentViewController = nil;
- }
- self.titleLabel.stringValue = NSLocalizedString(@"View Settings", nil);
- KMPageDisplayPropertiesViewController *vc = [[KMPageDisplayPropertiesViewController alloc] init];
- vc.mainController = self.mainController;
- vc.pdfView = self.pdfView;
- __weak typeof(self) weakSelf = self;
- vc.readerModeBlock = ^(BOOL isReaderMode) {
- if (weakSelf.pageDisplayReaderMode) {
- weakSelf.pageDisplayReaderMode(isReaderMode);
- }
- };
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- } else if (openPropertiesType == KMOpenPropertiesType_Stamp) {
- self.titleLabel.stringValue = NSLocalizedString(@"Stamp", nil);
- } else if (openPropertiesType == KMOpenPropertiesType_Link) {
- self.titleLabel.stringValue = NSLocalizedString(@"Link", nil);
- KMAnnotationLinkViewController *vc = [[KMAnnotationLinkViewController alloc] init];
- self.propertiesBox.contentView = vc.view;
- } else if (openPropertiesType == KMOpenPropertiesType_ListBox ||
- openPropertiesType == KMOpenPropertiesType_ComboBox ||
- openPropertiesType == KMOpenPropertiesType_Button) {
-
- } else if (openPropertiesType == KMOpenPropertiesType_FormSignatureClick) {
- self.contentViewController = nil;
- self.titleLabel.stringValue = @"";
- self.titleViewHeightConstraint.constant = 0;
-
- CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
- KMSignatureAnnotationViewController *vc = [[KMSignatureAnnotationViewController alloc] init];
- vc.isClickSignatureList = YES;
- vc.annotationModel = annotationModel;
- vc.pdfView = self.pdfView;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- }
- }
- - (void)setIsContinuousAddStamp:(BOOL)isContinuousAddStamp {
- if (_annotations.count <= 0) {
- return;
- }
- CPDFAnnotation *annotation = _annotations.firstObject;
- CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
- if ([annotation isKindOfClass:[CPDFStampAnnotation class]]) {
- if (isContinuousAddStamp) {
- self.titleViewHeightConstraint.constant = 0;
- }
- } else if ([annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
- if (isContinuousAddStamp) {
- KMSignatureAnnotationViewController *vc = [[KMSignatureAnnotationViewController alloc] init];
- self.titleViewHeightConstraint.constant = 0;
- vc.annotationModel = annotationModel;
- vc.pdfView = self.pdfView;
- self.propertiesBox.contentView = vc.view;
- self.contentViewController = vc;
- }
- }
- }
- + (CGFloat)heightWithAnnotation:(CPDFAnnotation *)annotation {
- if (!annotation) {
- return 0;
- }
- if ([annotation isKindOfClass:[CPDFLinkAnnotation class]] ||
- [annotation isKindOfClass:[CPDFMovieAnnotation class]] ||
- [annotation isKindOfClass:[CPDFSoundAnnotation class]]) {
- return 0;
- } else if ([annotation isKindOfClass:[CSelfSignAnnotation class]]) {
- return 279;
- } else if ([annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
- return 279;
- } else if ([annotation isKindOfClass:[CPDFListStampAnnotation class]]) {
- return 279;
- } else if ([annotation isKindOfClass:[CPDFStampAnnotation class]]) {
- return 0;
- } else if ([annotation isKindOfClass:[CPDFSignatureWidgetAnnotation class]]) {
- return 279;
- } else {
- return 279;
- }
- }
- + (CGFloat)heightWithAnnotationMode:(CAnnotationType)annotationMode {
- if (CAnnotationTypeSignature == annotationMode ||
- CAnnotationTypeUnkown == annotationMode) {
- return 0;
- }
- return 279;
- }
- #pragma mark - Private Method
- - (CGRect)viewControllerRect {
- CGFloat viewFloat = 0;
- if (_buttonView == nil || self.gradientView == nil) {
- return CGRectMake(0, 0, NSWidth(self.view.frame), viewFloat);
- }
- if (_buttonView.hidden) {
- viewFloat = NSHeight(self.view.frame) - NSHeight(self.gradientView.frame);
- } else {
- viewFloat = NSHeight(self.view.frame) - NSHeight(self.gradientView.frame)-KMFromContentButtonHeightFloat;
- }
- return CGRectMake(0, 0, NSWidth(self.view.frame), viewFloat);
- }
- - (void)updateFormContentButtonUI:(NSButton *)button {
- self.clickBtn = button;
-
- switch (button.tag) {
- case 100:
- [_formGeneralButton setTitleColor:[KMAppearance KMColor_Layout_W0]];
- [_formAppearanceButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
- [_formOptionsButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
-
- if([KMAppearance isDarkMode]) {
- _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:34/255. green:122/255. blue:255/255. alpha:1.].CGColor;
- _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
- _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
- } else {
- _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:73/255. green:130/255. blue:230/255. alpha:1.].CGColor;
- _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
- _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
- }
- break;
- case 101:
- [_formGeneralButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
- [_formAppearanceButton setTitleColor:[KMAppearance KMColor_Layout_W0]];
- [_formOptionsButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
-
- if([KMAppearance isDarkMode]) {
- _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:34/255. green:122/255. blue:255/255. alpha:1.].CGColor;
- _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
- _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
- } else {
- _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:73/255. green:130/255. blue:230/255. alpha:1.].CGColor;
- _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
- _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
- }
- break;
- case 102:
- [_formGeneralButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
- [_formAppearanceButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
- [_formOptionsButton setTitleColor:[KMAppearance KMColor_Layout_W0]];
-
- if([KMAppearance isDarkMode]) {
- _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:34/255. green:122/255. blue:255/255. alpha:1.].CGColor;
- _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
- _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
- } else {
- _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:73/255. green:130/255. blue:230/255. alpha:1.].CGColor;
- _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
- _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
- }
- break;
- default:
- break;
- }
- }
- #pragma mark - NSButton Action
- - (IBAction)fromContentButtonAction:(NSButton *)sender {
- [self updateFormContentButtonUI:sender];
-
- self.tipsView.hidden = YES;
-
- switch (sender.tag) {
- case 100:
- {
- self.lastLineImageView.hidden = NO;
- self.oneLineImageView.hidden = YES;
- [self formGeneralProperties];
- }
- break;
- case 101:
- {
- self.lastLineImageView.hidden = YES;
- self.oneLineImageView.hidden = YES;
- [self formAppearanceProperties];
- }
- break;
- case 102:
- {
- self.lastLineImageView.hidden = YES;
- self.oneLineImageView.hidden = NO;
- [self formOptionProperties];
- }
- break;
- default:
- break;
- }
- }
- - (void)formGeneralProperties {
- CPDFAnnotation *annotation = _annotations.firstObject;
- if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]] ||
- [annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]] ||
- [annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
- if ([self.contentViewController isKindOfClass:[KMAnnotationGeneralViewController class]]) {
- return;
- }
- [self.contentViewController.view removeFromSuperview];
-
- CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
- KMAnnotationGeneralViewController *vc = [[KMAnnotationGeneralViewController alloc] init];
- vc.pdfview = self.pdfView;
- vc.annotationModel = annotationModel;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- }
- }
- - (void)formAppearanceProperties {
- CPDFAnnotation *annotation = _annotations.firstObject;
- CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
- if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]) {
- if ([self.contentViewController isKindOfClass:[KMAnnotationFromViewController class]]) {
- return;
- }
- [self.contentViewController.view removeFromSuperview];
-
- KMAnnotationFromViewController *vc = [[KMAnnotationFromViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- } else if ([annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
- CPDFButtonWidgetAnnotation *newAnnotation = (CPDFButtonWidgetAnnotation *)annotation;
- if (newAnnotation.controlType == 1 || newAnnotation.controlType == 2) {
- if ([self.contentViewController isKindOfClass:[KMAnnotationButtonWidgetAppearanceViewController class]]) {
- return;
- }
- [self.contentViewController.view removeFromSuperview];
-
- KMAnnotationButtonWidgetAppearanceViewController *vc = [[KMAnnotationButtonWidgetAppearanceViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- } else if (newAnnotation.controlType == 0) {
- if ([self.contentViewController isKindOfClass:[KMAnnotationChoiceWidgetAppearanceViewController class]]) {
- return;
- }
- [self.contentViewController.view removeFromSuperview];
-
- KMAnnotationChoiceWidgetAppearanceViewController *vc = [[KMAnnotationChoiceWidgetAppearanceViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- }
- } else if ([annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
- if ([self.contentViewController isKindOfClass:[KMAnnotationChoiceWidgetAppearanceViewController class]]) {
- return;
- }
- [self.contentViewController.view removeFromSuperview];
-
- KMAnnotationChoiceWidgetAppearanceViewController *vc = [[KMAnnotationChoiceWidgetAppearanceViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- }
- }
- - (void)formOptionProperties {
- CPDFAnnotation *annotation = _annotations.firstObject;
- CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
- if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]) {
- if ([self.contentViewController isKindOfClass:[KMAnnotationTextWidgetOptionsViewController class]]) {
- return;
- }
- [self.contentViewController.view removeFromSuperview];
-
- KMAnnotationTextWidgetOptionsViewController *vc = [[KMAnnotationTextWidgetOptionsViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- } else if ([annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
- CPDFButtonWidgetAnnotation *newAnnotation = (CPDFButtonWidgetAnnotation *)annotation;
- if (newAnnotation.controlType == CPDFWidgetRadioButtonControl || newAnnotation.controlType == CPDFWidgetCheckBoxControl) {
- if ([self.contentViewController isKindOfClass:[KMAnnotationButtonWidgetOptionsViewController class]]) {
- return;
- }
- [self.contentViewController.view removeFromSuperview];
-
- if (newAnnotation.controlType == CPDFWidgetRadioButtonControl) {
- self.tipsView.hidden = NO;
- self.tipsLabel.stringValue = [NSString stringWithFormat:@" %@", NSLocalizedString(@"To create a set of mutually exclusive radio buttons (i.e., where only one can be selected at a time), give the fields the same name but different button choices.", nil)];;
- } else {
- self.tipsView.hidden = YES;
- }
- KMAnnotationButtonWidgetOptionsViewController *vc = [[KMAnnotationButtonWidgetOptionsViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- } else if (newAnnotation.controlType == CPDFWidgetPushButtonControl) {
- if ([self.contentViewController isKindOfClass:[KMAnnotationButtonOptionsViewController class]]) {
- return;
- }
- [self.contentViewController.view removeFromSuperview];
-
- KMAnnotationButtonOptionsViewController *vc = [[KMAnnotationButtonOptionsViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- }
- } else if ([annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
- if ([self.contentViewController isKindOfClass:[KMAnnotationChoiceWidgetOptionsViewController class]]) {
- return;
- }
- [self.contentViewController.view removeFromSuperview];
- self.tipsView.hidden = YES;
- self.tipsLabel.stringValue = [NSString stringWithFormat:@" %@", NSLocalizedString(@"Select an item in the list to make it the default choice.", nil)];;
- KMAnnotationChoiceWidgetOptionsViewController *vc = [[KMAnnotationChoiceWidgetOptionsViewController alloc] init];
- vc.pdfView = self.pdfView;
- vc.annotationModel = annotationModel;
- vc.view.frame = [self viewControllerRect];
- [self.view addSubview:vc.view];
- self.contentViewController = vc;
- }
- }
- @end
|