12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130 |
- //
- // 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 (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) NSViewController *contentViewController;
- @property (nonatomic, retain) NSButton *clickBtn;
- @end
- @implementation KMAnnotationPropertiesViewController
- #pragma mark - View Methods
- - (void)dealloc {
- [self removeNotification];
- // self.annotations = nil;
- // self.pdfView = nil;
- // self.pageDisplayReaderMode = nil;
- // self.annoTypeDidChange = nil;
- // self.clickBtn = nil;
-
- }
- - (void)addNotification {
- [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(changeEffectiveAppearance) name:@"kEffectiveAppearance" object:nil];
- }
- - (void)removeNotification {
- [NSNotificationCenter.defaultCenter removeObserver:self];
- }
- - (void)changeEffectiveAppearance {
- BOOL isDarkModel = [NSView 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 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];
-
- 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;
- }
- }
- }
- - (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
|