KMAnnotationPropertiesViewController.m 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028
  1. //
  2. // KMAnnotationPropertiesViewController.m
  3. // SignFlow
  4. //
  5. // Created by wanjun on 2021/6/15.
  6. //
  7. #import "KMAnnotationPropertiesViewController.h"
  8. //#import "NSString_SKExtensions.h"
  9. #import <PDF_Reader_Pro-Swift.h>
  10. #import "KMSignatureAnnotationViewController.h"
  11. #import "CSelfSignAnnotation.h"
  12. #import "CSelfSignAnnotationFreeText.h"
  13. #define KMFromContentButtonHeightFloat 32
  14. @interface KMClipView : NSClipView
  15. @end
  16. @implementation KMClipView
  17. - (BOOL)isFlipped {
  18. return YES;
  19. }
  20. @end
  21. @interface KMAnnotationPropertiesViewController ()
  22. @property (assign) IBOutlet NSBox *propertiesBox;
  23. @property (nonatomic,assign) IBOutlet NSView *gradientView;
  24. @property (weak) IBOutlet NSImageView *emptyImageView;
  25. @property (nonatomic,assign) IBOutlet NSTextField *titleLabel;
  26. @property (nonatomic,assign) IBOutlet NSTextField *subTitleLabel;
  27. @property (nonatomic,assign) IBOutlet NSView *emptyView;
  28. @property (nonatomic,retain) NSViewController *contentViewController;
  29. @property (weak) IBOutlet NSLayoutConstraint *titleViewHeightConstraint;
  30. @property (weak) IBOutlet NSLayoutConstraint *buttonbuttonLayoutConstraint;
  31. @property (assign) IBOutlet NSView *buttonView;
  32. @property (assign) IBOutlet NSButton *formGeneralButton;
  33. @property (assign) IBOutlet NSButton *formAppearanceButton;
  34. @property (assign) IBOutlet NSButton *formOptionsButton;
  35. @property (assign) IBOutlet NSView *tipsView;
  36. @property (assign) IBOutlet NSTextField *tipsLabel;
  37. @property (assign) IBOutlet NSImageView *oneLineImageView;
  38. @property (assign) IBOutlet NSImageView *lastLineImageView;
  39. @property (nonatomic, retain) NSButton *clickBtn;
  40. @end
  41. @implementation KMAnnotationPropertiesViewController
  42. #pragma mark - View Methods
  43. //func addNotification() {
  44. // NotificationCenter.default.addObserver(self, selector: #selector(changeEffectiveAppearance), name: NSNotification.Name(rawValue: "kEffectiveAppearance"), object: nil)
  45. //}
  46. //
  47. //func removeNotification() {
  48. // NotificationCenter.default.removeObserver(self)
  49. // DistributedNotificationCenter.default().removeObserver(self)
  50. //}
  51. //
  52. //@objc func changeEffectiveAppearance() {
  53. // let isDarkModel = KMAdvertisementConfig.isDarkModel()
  54. // if isDarkModel {
  55. // self.appearance = NSAppearance(named: .darkAqua)
  56. // } else {
  57. // self.appearance = NSAppearance(named: .aqua)
  58. // }
  59. // self.updateUI()
  60. //}
  61. - (void)dealloc {
  62. [self removeNotification];
  63. }
  64. - (void)addNotification {
  65. [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(changeEffectiveAppearance) name:@"kEffectiveAppearance" object:nil];
  66. }
  67. - (void)removeNotification {
  68. [NSNotificationCenter.defaultCenter removeObserver:self];
  69. }
  70. - (void)changeEffectiveAppearance {
  71. BOOL isDarkModel = [KMAdvertisementConfig isDarkModel];
  72. if (isDarkModel) {
  73. self.view.appearance = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
  74. self.view.layer.backgroundColor = [NSColor km_initWithHex:@"#252526" alpha:1].CGColor;
  75. } else {
  76. self.view.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
  77. self.view.layer.backgroundColor = [NSColor km_initWithHex:@"#FAFAFA" alpha:1].CGColor;
  78. }
  79. }
  80. - (void)loadView {
  81. [super loadView];
  82. [self addNotification];
  83. self.view.wantsLayer = YES;
  84. // self.view.layer.backgroundColor = [KMAppearance viewBackgroundColor].CGColor;
  85. // self.view.layer.backgroundColor = [NSColor colorWithRed:247.0/255.0 green:248.0/255.0 blue:250.0/255.0 alpha:1].CGColor;
  86. [self changeEffectiveAppearance];
  87. self.view.layer.shadowColor = [NSColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.15].CGColor;
  88. self.view.layer.shadowOffset = NSMakeSize(0, 0);
  89. self.view.layer.shadowRadius = 4;
  90. self.emptyImageView.image = [NSImage imageNamed:@"KMImageNameMarkupEmpty"];
  91. self.subTitleLabel.stringValue = NSLocalizedString(@"Show/Hide Annotation Properties Panel", nil);
  92. NSMutableParagraphStyle *ps = [[NSMutableParagraphStyle alloc] init];
  93. ps.lineSpacing = 10;
  94. ps.alignment = NSTextAlignmentCenter;
  95. self.subTitleLabel.attributedStringValue = [[NSAttributedString alloc] initWithString:self.subTitleLabel.stringValue attributes:@{
  96. NSForegroundColorAttributeName : [NSColor colorWithRed:148/255.f green:152/255.f blue:156/255.f alpha:1.f],
  97. NSFontAttributeName : [NSFont fontWithName:@"SFProText-Regular" size:12],
  98. NSParagraphStyleAttributeName : ps}];
  99. self.subTitleLabel.textColor = [NSColor grayColor];
  100. self.titleLabel.font = [NSFont SFProTextSemiboldFont:14.0];
  101. self.titleLabel.textColor = [KMAppearance KMColor_Layout_H0];
  102. // [NSColor colorWithRed:0.145 green:0.149 blue:0.161 alpha:1];
  103. self.buttonView.hidden = YES;
  104. self.formGeneralButton.wantsLayer = YES;
  105. self.formAppearanceButton.wantsLayer = YES;
  106. self.formOptionsButton.wantsLayer = YES;
  107. [self updateFormContentButtonUI:self.formAppearanceButton];
  108. self.formAppearanceButton.toolTip = NSLocalizedString(@"Appearance", nil);
  109. [self.formAppearanceButton setTitle:NSLocalizedString(@"Appearance", nil)];
  110. self.formGeneralButton.toolTip = NSLocalizedString(@"General", nil);
  111. [self.formGeneralButton setTitle:NSLocalizedString(@"General", nil)];
  112. self.formOptionsButton.toolTip = NSLocalizedString(@"Preferences", nil);
  113. [self.formOptionsButton setTitle:NSLocalizedString(@"Preferences", nil)];
  114. self.tipsView.hidden = YES;
  115. self.tipsView.wantsLayer = YES;
  116. self.tipsView.layer.cornerRadius = 1.0;
  117. self.oneLineImageView.wantsLayer = YES;
  118. self.lastLineImageView.wantsLayer = YES;
  119. self.oneLineImageView.hidden = YES;
  120. }
  121. #pragma mark - Setter Methods
  122. -(void)setAnnotations:(NSArray *)annotations
  123. {
  124. if (_annotations != annotations) {
  125. _annotations = annotations;
  126. }
  127. self.buttonView.hidden = YES;
  128. CPDFAnnotation *annotation = _annotations.firstObject;
  129. if (self.contentViewController) {
  130. [self.contentViewController.view removeFromSuperview];
  131. self.contentViewController = nil;
  132. }
  133. if (!annotation || [annotation isKindOfClass:[CPDFRedactAnnotation class]]) {
  134. return;
  135. }
  136. if (_annotations.count > 1) {
  137. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]] ||
  138. [annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]] ||
  139. [annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
  140. } else {
  141. [self selectAnnotations:_annotations];
  142. return;
  143. }
  144. }
  145. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]){
  146. self.titleLabel.stringValue = NSLocalizedString(@"Text Field", nil);
  147. } else if ([annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
  148. CPDFButtonWidgetAnnotation *buttonWidget = (CPDFButtonWidgetAnnotation *)annotation;
  149. if (buttonWidget.controlType == 1) {
  150. self.titleLabel.stringValue = NSLocalizedString(@"Radio Button", nil);
  151. } else if (buttonWidget.controlType == 2) {
  152. self.titleLabel.stringValue = NSLocalizedString(@"Check Box", nil);
  153. } else if (buttonWidget.controlType == 0) {
  154. self.titleLabel.stringValue = NSLocalizedString(@"Button", nil);
  155. }
  156. } else if ([annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
  157. CPDFChoiceWidgetAnnotation *choiceWidget = (CPDFChoiceWidgetAnnotation *)annotation;
  158. if (choiceWidget.isListChoice) {
  159. self.titleLabel.stringValue = NSLocalizedString(@"List Box", nil);
  160. } else {
  161. self.titleLabel.stringValue = NSLocalizedString(@"Combo Box", nil);
  162. }
  163. } else if ([annotation isKindOfClass:[KMSelfSignAnnotation class]]) {
  164. KMSelfSignAnnotation *newAnnotation = (KMSelfSignAnnotation *)annotation;
  165. CAnnotationType type = newAnnotation.annotationType;
  166. NSString *returnString = @"";
  167. if (type == CAnnotationTypeSignFalse) {
  168. returnString = NSLocalizedString(@"X", nil);
  169. } else if (type == CAnnotationTypeSignTure) {
  170. returnString = NSLocalizedString(@"Check mark", nil);
  171. } else if (type == CAnnotationTypeSignCircle) {
  172. returnString = NSLocalizedString(@"Circle", nil);
  173. } else if (type == CAnnotationTypeSignLine) {
  174. returnString = NSLocalizedString(@"Line", nil);
  175. } else if (type == CAnnotationTypeSignDot) {
  176. returnString = NSLocalizedString(@"Dot", nil);
  177. } else if (type == CAnnotationTypeSignText) {
  178. returnString = NSLocalizedString(@"Text", nil);
  179. }
  180. self.titleLabel.stringValue = returnString;
  181. } else if ([annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
  182. self.titleLabel.stringValue = NSLocalizedString(@"Link", @"Description for export");
  183. } else if ([annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
  184. if ([annotation isKindOfClass:[KMSelfSignAnnotationFreeText class]]) {
  185. KMSelfSignAnnotationFreeText *signFreeText = (KMSelfSignAnnotationFreeText *)annotation;
  186. if (signFreeText.subType == KMSelfSignAnnotationFreeTextSubTypeProfile) {
  187. self.titleLabel.stringValue = NSLocalizedString(@"Text", nil);
  188. } else {
  189. self.titleLabel.stringValue = NSLocalizedString(@"Date", nil);
  190. }
  191. } else {
  192. self.titleLabel.stringValue = [annotation type].typeName;
  193. }
  194. } else if ([annotation isKindOfClass:[CPDFSignatureWidgetAnnotation class]] ||
  195. [annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
  196. self.titleLabel.stringValue = NSLocalizedString(@"Signature", nil);
  197. } else if ([annotation isKindOfClass:[CSelfSignAnnotation class]]) {
  198. CSelfSignAnnotation *newAnnotation = (CSelfSignAnnotation *)annotation;
  199. if (newAnnotation.annotationType == CAnnotationTypeSignFalse) {
  200. self.titleLabel.stringValue = NSLocalizedString(@"X", nil);
  201. } else if (newAnnotation.annotationType == CAnnotationTypeSignTure) {
  202. self.titleLabel.stringValue = NSLocalizedString(@"Check mark", nil);
  203. } else if (newAnnotation.annotationType == CAnnotationTypeSignCircle) {
  204. self.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
  205. } else if (newAnnotation.annotationType == CAnnotationTypeSignLine) {
  206. self.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
  207. } else if (newAnnotation.annotationType == CAnnotationTypeSignDot) {
  208. self.titleLabel.stringValue = NSLocalizedString(@"Dot", nil);
  209. } else if (newAnnotation.annotationType == CAnnotationTypeSignText) {
  210. self.titleLabel.stringValue = NSLocalizedString(@"Text", nil);
  211. } else if (newAnnotation.annotationType == CAnnotationTypeSignDate) {
  212. self.titleLabel.stringValue = NSLocalizedString(@"Date", nil);
  213. }
  214. } else if ([annotation isKindOfClass:[CPDFStampAnnotation class]]) {
  215. self.titleLabel.stringValue = NSLocalizedString(@"Stamp", nil);
  216. } else if ([annotation isKindOfClass:[KMTableAnnotation class]]) {
  217. self.titleLabel.stringValue = NSLocalizedString(@"Table", nil);
  218. } else {
  219. self.titleLabel.stringValue = [annotation type].typeName;
  220. }
  221. self.titleViewHeightConstraint.constant = 40;
  222. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  223. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]] ||
  224. [annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]] ||
  225. [annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]){
  226. self.buttonView.hidden = NO;
  227. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]) {
  228. [self updateFormContentButtonUI:_formGeneralButton];
  229. KMAnnotationGeneralViewController *vc = [[KMAnnotationGeneralViewController alloc] init];
  230. vc.pdfview = self.pdfView;
  231. vc.annotationModel = annotationModel;
  232. vc.view.frame = [self viewControllerRect];
  233. [self.view addSubview:vc.view];
  234. self.contentViewController = vc;
  235. } else if ([annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
  236. [self fromContentButtonAction:_formOptionsButton];
  237. } else if ([annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
  238. CPDFButtonWidgetAnnotation *newAnnotation = (CPDFButtonWidgetAnnotation *)annotation;
  239. if (newAnnotation.controlType == CPDFWidgetRadioButtonControl || newAnnotation.controlType == CPDFWidgetCheckBoxControl) {
  240. [self updateFormContentButtonUI:_formGeneralButton];
  241. KMAnnotationGeneralViewController *vc = [[KMAnnotationGeneralViewController alloc] init];
  242. vc.pdfview = self.pdfView;
  243. vc.annotations = self.annotations;
  244. vc.view.frame = [self viewControllerRect];
  245. [self.view addSubview:vc.view];
  246. self.contentViewController = vc;
  247. } else if (newAnnotation.controlType == CPDFWidgetPushButtonControl) {
  248. [self fromContentButtonAction:_formOptionsButton];
  249. }
  250. }
  251. } else if ([annotation isKindOfClass:[KMAnnotationFromSignature class]]) {
  252. KMAnnotationGeneralViewController *vc = [[KMAnnotationGeneralViewController alloc] init];
  253. vc.pdfview = self.pdfView;
  254. vc.annotationModel = annotationModel;
  255. vc.view.frame = [self viewControllerRect];
  256. [self.view addSubview:vc.view];
  257. self.contentViewController = vc;
  258. } else if ([annotation isKindOfClass:[CPDFSignatureWidgetAnnotation class]]) {
  259. if (!_isClickFormSignature) {
  260. KMAnnotationGeneralViewController *vc = [[KMAnnotationGeneralViewController alloc] init];
  261. vc.pdfview = self.pdfView;
  262. vc.annotationModel = annotationModel;
  263. vc.view.frame = [self viewControllerRect];
  264. [self.view addSubview:vc.view];
  265. self.contentViewController = vc;
  266. }
  267. _isClickFormSignature = NO;
  268. } else if ([annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
  269. CPDFLinkAnnotation *linkAnnotation = annotations.firstObject;
  270. NSString *contents = nil;
  271. if ([linkAnnotation URL]) {
  272. contents = [linkAnnotation URL];
  273. if (contents) {
  274. contents = [NSString stringWithFormat:@"1%@", contents];
  275. } else {
  276. contents = @"";
  277. }
  278. } else {
  279. contents = [NSString stringWithFormat:@"0%@", @([[linkAnnotation destination] pageIndex]+1)];
  280. }
  281. KMLinkViewController *vc = [[KMLinkViewController alloc] init];
  282. vc.pdfView = self.pdfView;
  283. vc.annotations = self.annotations;
  284. vc.view.frame = [self viewControllerRect];
  285. vc.view.autoresizingMask = NSViewWidthSizable|NSViewHeightSizable;
  286. [self.view addSubview:vc.view];
  287. self.contentViewController = vc;
  288. [vc reloadData];
  289. } else if ([annotation isKindOfClass:[CSelfSignAnnotation class]]) {
  290. CSelfSignAnnotation *newAnnotation = (CSelfSignAnnotation *)annotation;
  291. if (newAnnotation.annotationType == CAnnotationTypeSignFalse ||
  292. newAnnotation.annotationType == CAnnotationTypeSignTure ||
  293. newAnnotation.annotationType == CAnnotationTypeSignCircle ||
  294. newAnnotation.annotationType == CAnnotationTypeSignLine ||
  295. newAnnotation.annotationType == CAnnotationTypeSignDot) {
  296. KMAnnotationSelfSignViewController *vc = [[KMAnnotationSelfSignViewController alloc] init];
  297. vc.pdfView = self.pdfView;
  298. vc.annotationModel = annotationModel;
  299. self.propertiesBox.contentView = vc.view;
  300. self.contentViewController = vc;
  301. __weak typeof (self) weakSelf = self;
  302. vc.callBack = ^(CAnnotationType type) {
  303. if (type == CAnnotationTypeSignFalse) {
  304. weakSelf.titleLabel.stringValue = NSLocalizedString(@"X", nil);
  305. } else if (type == CAnnotationTypeSignTure) {
  306. weakSelf.titleLabel.stringValue = NSLocalizedString(@"Check mark", nil);
  307. } else if (type == CAnnotationTypeSignCircle) {
  308. weakSelf.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
  309. } else if (type == CAnnotationTypeSignLine) {
  310. weakSelf.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
  311. } else if (type == CAnnotationTypeSignDot) {
  312. weakSelf.titleLabel.stringValue = NSLocalizedString(@"Dot", nil);
  313. }
  314. if (weakSelf.annoTypeDidChange != nil) {
  315. weakSelf.annoTypeDidChange(annotation);
  316. }
  317. };
  318. } else if (newAnnotation.annotationType == CAnnotationTypeSignText ||
  319. newAnnotation.annotationType == CAnnotationTypeSignDate) {
  320. KMSelfSignAnnotationFreeTextSubType subType = KMSelfSignAnnotationFreeTextSubTypeNone;
  321. if (annotationModel.annotationType == CAnnotationTypeSignConfig) {
  322. subType = KMSelfSignAnnotationFreeTextSubTypeProfile;
  323. } else if (annotationModel.annotationType == CAnnotationTypeSignText) {
  324. subType = KMSelfSignAnnotationFreeTextSubTypeFreeText;
  325. } else if (annotationModel.annotationType == CAnnotationTypeSignDate) {
  326. subType = KMSelfSignAnnotationFreeTextSubTypeDate;
  327. }
  328. KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
  329. vc.subType = subType;
  330. vc.pdfView = self.pdfView;
  331. vc.annotationModel = annotationModel;
  332. self.propertiesBox.contentView = vc.view;
  333. self.contentViewController = vc;
  334. }
  335. } else if ([annotation isKindOfClass:[CSelfSignAnnotationFreeText class]]) {
  336. CSelfSignAnnotationFreeText *newAnnotation = (CSelfSignAnnotationFreeText *)annotation;
  337. if (newAnnotation.subType == CAnnotationTypeSignText ||
  338. newAnnotation.subType == CAnnotationTypeSignDate) {
  339. KMSelfSignAnnotationFreeTextSubType subType = KMSelfSignAnnotationFreeTextSubTypeNone;
  340. if (annotationModel.annotationType == CAnnotationTypeSignConfig) {
  341. subType = KMSelfSignAnnotationFreeTextSubTypeProfile;
  342. } else if (annotationModel.annotationType == CAnnotationTypeSignText) {
  343. subType = KMSelfSignAnnotationFreeTextSubTypeFreeText;
  344. } else if (annotationModel.annotationType == CAnnotationTypeSignDate) {
  345. subType = KMSelfSignAnnotationFreeTextSubTypeDate;
  346. }
  347. KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
  348. vc.subType = subType;
  349. vc.pdfView = self.pdfView;
  350. vc.annotationModel = annotationModel;
  351. self.propertiesBox.contentView = vc.view;
  352. self.contentViewController = vc;
  353. }
  354. } else if ([annotation isKindOfClass:[CPDFSignatureAnnotation class]] ||
  355. [annotation isKindOfClass:[CPDFStampAnnotation class]]) {
  356. KMAnnotationStampViewController *vc = [[KMAnnotationStampViewController alloc] init];
  357. vc.pdfView = self.pdfView;
  358. vc.annotationModel = annotationModel;
  359. self.propertiesBox.contentView = vc.view;
  360. self.contentViewController = vc;
  361. } else if ([annotation isKindOfClass:[KMTableAnnotation class]]) {
  362. KMAnnotationTableViewController *vc = [[KMAnnotationTableViewController alloc] init];
  363. vc.pdfView = self.pdfView;
  364. vc.annotationModel = annotationModel;
  365. self.propertiesBox.contentView = vc.view;
  366. self.contentViewController = vc;
  367. } else {
  368. KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
  369. vc.pdfView = self.pdfView;
  370. vc.annotationModel = annotationModel;
  371. self.propertiesBox.contentView = vc.view;
  372. self.contentViewController = vc;
  373. }
  374. // self.buttonbuttonLayoutConstraint.constant = self.buttonView.hidden ? -36 : 0;
  375. }
  376. - (void)selectAnnotations:(NSArray *)annotations {
  377. CPDFAnnotation *fristAnnotation = annotations.firstObject;
  378. CAnnotationType annotationMode = CAnnotationTypeUnkown;
  379. if ([fristAnnotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
  380. annotationMode = CAnnotationTypeHighlight;
  381. } else if ([fristAnnotation isKindOfClass:[CPDFInkAnnotation class]]) {
  382. annotationMode = CAnnotationTypeInk;
  383. } else if ([fristAnnotation isKindOfClass:[CPDFTextAnnotation class]]) {
  384. annotationMode = CAnnotationTypeAnchored;
  385. } else if ([fristAnnotation isKindOfClass:[CPDFSquareAnnotation class]]) {
  386. annotationMode = CAnnotationTypeSquare;
  387. } else if ([fristAnnotation isKindOfClass:[CPDFCircleAnnotation class]]) {
  388. annotationMode = CAnnotationTypeCircle;
  389. } else if ([fristAnnotation isKindOfClass:[CPDFLineAnnotation class]]) {
  390. if(((CPDFLineAnnotation *)fristAnnotation).startLineStyle == CPDFLineStyleNone &&
  391. ((CPDFLineAnnotation *)fristAnnotation).endLineStyle == CPDFLineStyleOpenArrow ) {
  392. annotationMode = CAnnotationTypeArrow;
  393. } else {
  394. annotationMode = CAnnotationTypeLine;
  395. }
  396. } else if ([fristAnnotation isKindOfClass:[CPDFLinkAnnotation class]]) {
  397. annotationMode = CAnnotationTypeLink;
  398. } else if ([fristAnnotation isKindOfClass:[CPDFStampAnnotation class]]) {
  399. if ([fristAnnotation isKindOfClass:[CSelfSignAnnotation class]]) {
  400. CSelfSignAnnotation *newAnnotation = (CSelfSignAnnotation *)fristAnnotation;
  401. if (newAnnotation.annotationType == CAnnotationTypeSignFalse)
  402. annotationMode = CAnnotationTypeSignFalse;
  403. else if(newAnnotation.annotationType == CAnnotationTypeSignTure)
  404. annotationMode = CAnnotationTypeSignTure;
  405. else if(newAnnotation.annotationType == CAnnotationTypeSignCircle)
  406. annotationMode = CAnnotationTypeSignCircle;
  407. else if(newAnnotation.annotationType == CAnnotationTypeSignLine)
  408. annotationMode = CAnnotationTypeSignLine;
  409. else if(newAnnotation.annotationType == CAnnotationTypeSignDot)
  410. annotationMode = CAnnotationTypeSignDot;
  411. else if(newAnnotation.annotationType == CAnnotationTypeSignDot)
  412. annotationMode = CAnnotationTypeSignDot;
  413. } else if ([fristAnnotation isKindOfClass:[CSelfSignAnnotationFreeText class]]) {
  414. CSelfSignAnnotationFreeText *newAnnotation = (CSelfSignAnnotationFreeText *)fristAnnotation;
  415. if (newAnnotation.subType == CAnnotationTypeSignText)
  416. annotationMode = CAnnotationTypeSignText;
  417. else if(newAnnotation.subType == CAnnotationTypeSignDate)
  418. annotationMode = CAnnotationTypeSignDate;
  419. } else {
  420. annotationMode = CAnnotationTypeStamp;
  421. }
  422. } else if ([fristAnnotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
  423. annotationMode = CAnnotationTypeSignature;
  424. } else if ([fristAnnotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
  425. if ([fristAnnotation isKindOfClass:[CSelfSignAnnotationFreeText class]]) {
  426. CSelfSignAnnotationFreeText *newAnnotation = (CSelfSignAnnotationFreeText *)fristAnnotation;
  427. if (newAnnotation.subType == CAnnotationTypeSignText)
  428. annotationMode = CAnnotationTypeSignText;
  429. else if(newAnnotation.subType == CAnnotationTypeSignDate)
  430. annotationMode = CAnnotationTypeSignDate;
  431. } else {
  432. annotationMode = CAnnotationTypeFreeText;
  433. }
  434. }
  435. self.annotationMode = annotationMode;
  436. }
  437. - (void)setAnnotationMode:(CAnnotationType)annotationMode {
  438. _annotationMode = annotationMode;
  439. if (self.contentViewController) {
  440. [self.contentViewController.view removeFromSuperview];
  441. self.contentViewController = nil;
  442. }
  443. NSString *title = @"";
  444. if (annotationMode == CAnnotationTypeFreeText)
  445. title = NSLocalizedString(@"Text", @"Description for export");
  446. else if (annotationMode == CAnnotationTypeCircle)
  447. title = NSLocalizedString(@"Circle", @"Description for export");
  448. else if (annotationMode == CAnnotationTypeSquare)
  449. title = NSLocalizedString(@"Rectangle", @"Description for export");
  450. else if (annotationMode == CAnnotationTypeHighlight) {
  451. title = NSLocalizedString(@"Highlight", @"Description for export");
  452. if (_annotations.count > 1)
  453. title = NSLocalizedString(@"General", @"Description for export");
  454. }
  455. else if (annotationMode == CAnnotationTypeUnderline) {
  456. title = NSLocalizedString(@"Underline", @"Description for export");
  457. if (_annotations.count > 1)
  458. title = NSLocalizedString(@"General", @"Description for export");
  459. }
  460. else if (annotationMode == CAnnotationTypeStrikeOut)
  461. title = NSLocalizedString(@"Strikethrough", @"Description for export");
  462. else if (annotationMode == CAnnotationTypeLine)
  463. title = NSLocalizedString(@"Line", @"Description for export");
  464. else if (annotationMode == CAnnotationTypeArrow)
  465. title = NSLocalizedString(@"Arrow", @"Description for export");
  466. else if (annotationMode == CAnnotationTypeInk || annotationMode == CAnnotationTypeEraser)
  467. title = NSLocalizedString(@"Freehand", @"Description for export");
  468. else if (annotationMode == CAnnotationTypeAnchored)
  469. title = NSLocalizedString(@"Note", @"Description for export");
  470. else if (annotationMode == CAnnotationTypeLink)
  471. title = NSLocalizedString(@"Link", @"Description for export");
  472. else if (annotationMode == CAnnotationTypeTextField)
  473. title = NSLocalizedString(@"Text Field", @"Description for export");
  474. else if (annotationMode == CAnnotationTypeCheckBox)
  475. title = NSLocalizedString(@"Check Box", @"Description for export");
  476. else if (annotationMode == CAnnotationTypeListMenu)
  477. title = NSLocalizedString(@"List Box", @"Description for export");
  478. else if (annotationMode == CAnnotationTypeComboBox)
  479. title = NSLocalizedString(@"Combo Box", @"Description for export");
  480. else if (annotationMode == CAnnotationTypeRadioButton)
  481. title = NSLocalizedString(@"Radio Button", @"Description for export");
  482. else if (annotationMode == CAnnotationTypeActionButton)
  483. title = NSLocalizedString(@"Button", @"Description for export");
  484. else if (annotationMode == CAnnotationTypeSignature)
  485. title = NSLocalizedString(@"Sample", @"Description for export");
  486. else if (annotationMode == CAnnotationTypeSignDot)
  487. title = NSLocalizedString(@"Dot", @"Description for export");
  488. else if (annotationMode == CAnnotationTypeSignLine)
  489. title = NSLocalizedString(@"Line", @"Description for export");
  490. else if (annotationMode == CAnnotationTypeSignCircle)
  491. title = NSLocalizedString(@"Rectangle", @"Description for export");
  492. else if (annotationMode == CAnnotationTypeSignFalse)
  493. title = NSLocalizedString(@"X", nil);
  494. else if (annotationMode == CAnnotationTypeSignTure)
  495. title = NSLocalizedString(@"Check mark", nil);
  496. else if (annotationMode == CAnnotationTypeSignText)
  497. title = NSLocalizedString(@"Text", nil);
  498. else if (annotationMode == CAnnotationTypeSignDate)
  499. title = NSLocalizedString(@"Date", nil);
  500. else if (annotationMode == CAnnotationTypeStamp)
  501. title = NSLocalizedString(@"Stamp", nil);
  502. else
  503. title = @"";
  504. if(_annotations.count > 1) {
  505. title = NSLocalizedString(@"Properties", nil);
  506. }
  507. self.titleLabel.stringValue = title;
  508. self.titleViewHeightConstraint.constant = 40;
  509. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithAnnotationType:annotationMode];
  510. if (annotationMode == CAnnotationTypeFreeText ||
  511. annotationMode == CAnnotationTypeAnchored ||
  512. annotationMode == CAnnotationTypeCircle ||
  513. annotationMode == CAnnotationTypeSquare ||
  514. annotationMode == CAnnotationTypeHighlight ||
  515. annotationMode == CAnnotationTypeUnderline ||
  516. annotationMode == CAnnotationTypeStrikeOut ||
  517. annotationMode == CAnnotationTypeLine ||
  518. annotationMode == CAnnotationTypeInk ||
  519. annotationMode == CAnnotationTypeEraser ||
  520. annotationMode == CAnnotationTypeArrow) {
  521. //处理多选
  522. if(_annotations.count > 1) {
  523. annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  524. }
  525. KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
  526. vc.pdfView = self.pdfView;
  527. vc.annotationModel = annotationModel;
  528. self.propertiesBox.contentView = vc.view;
  529. self.contentViewController = vc;
  530. } else if (annotationMode == CAnnotationTypeLink) {
  531. } else if (annotationMode == CAnnotationTypeRadioButton ||
  532. annotationMode == CAnnotationTypeCheckBox ||
  533. annotationMode == CAnnotationTypeTextField ||
  534. annotationMode == CAnnotationTypeComboBox ||
  535. annotationMode == CAnnotationTypeListMenu ||
  536. annotationMode == CAnnotationTypeActionButton) {
  537. if (annotationMode == CAnnotationTypeTextField) {
  538. KMAnnotationFromViewController *vc = [[KMAnnotationFromViewController alloc] init];
  539. vc.pdfView = self.pdfView;
  540. vc.annotationModel = annotationModel;
  541. self.propertiesBox.contentView = vc.view;
  542. self.contentViewController = vc;
  543. } else if (annotationMode == CAnnotationTypeListMenu ||
  544. annotationMode == CAnnotationTypeComboBox ||
  545. annotationMode == CAnnotationTypeActionButton) {
  546. KMAnnotationChoiceWidgetAppearanceViewController *vc = [[KMAnnotationChoiceWidgetAppearanceViewController alloc] init];
  547. vc.annotationModel = annotationModel;
  548. vc.pdfView = self.pdfView;
  549. self.propertiesBox.contentView = vc.view;
  550. self.contentViewController = vc;
  551. } else if (annotationMode == CAnnotationTypeRadioButton ||
  552. annotationMode == CAnnotationTypeCheckBox) {
  553. KMAnnotationButtonWidgetAppearanceViewController *vc = [[KMAnnotationButtonWidgetAppearanceViewController alloc] init];
  554. vc.annotationModel = annotationModel;
  555. vc.pdfView = self.pdfView;
  556. self.propertiesBox.contentView = vc.view;
  557. self.contentViewController = vc;
  558. }
  559. } else if (annotationMode == CAnnotationTypeSignFalse ||
  560. annotationMode == CAnnotationTypeSignTure ||
  561. annotationMode == CAnnotationTypeSignCircle ||
  562. annotationMode == CAnnotationTypeSignLine ||
  563. annotationMode == CAnnotationTypeSignDot) {
  564. if(_annotations.count > 1) {
  565. annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  566. }
  567. KMAnnotationSelfSignViewController *vc = [[KMAnnotationSelfSignViewController alloc] init];
  568. vc.pdfView = self.pdfView;
  569. vc.annotationModel = annotationModel;
  570. self.propertiesBox.contentView = vc.view;
  571. self.contentViewController = vc;
  572. __weak typeof(self) weakSelf = self;
  573. vc.callBack = ^(CAnnotationType type) {
  574. if (type == CAnnotationTypeSignFalse) {
  575. weakSelf.titleLabel.stringValue = NSLocalizedString(@"X", nil);
  576. } else if (type == CAnnotationTypeSignTure) {
  577. weakSelf.titleLabel.stringValue = NSLocalizedString(@"Check mark", nil);
  578. } else if (type == CAnnotationTypeSignCircle) {
  579. weakSelf.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
  580. } else if (type == CAnnotationTypeSignLine) {
  581. weakSelf.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
  582. } else if (type == CAnnotationTypeSignDot) {
  583. weakSelf.titleLabel.stringValue = NSLocalizedString(@"Dot", nil);
  584. }
  585. if (weakSelf.annoTypeDidChange != nil) {
  586. weakSelf.annoTypeDidChange(weakSelf.annotations.firstObject);
  587. }
  588. };
  589. } else if (annotationMode == CAnnotationTypeSignText ||
  590. annotationMode == CAnnotationTypeSignDate) {
  591. if(_annotations.count > 1) {
  592. annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  593. }
  594. KMSelfSignAnnotationFreeTextSubType subType = KMSelfSignAnnotationFreeTextSubTypeNone;
  595. if (annotationModel.annotationType == CAnnotationTypeSignConfig) {
  596. subType = KMSelfSignAnnotationFreeTextSubTypeProfile;
  597. } else if (annotationModel.annotationType == CAnnotationTypeSignText) {
  598. subType = KMSelfSignAnnotationFreeTextSubTypeFreeText;
  599. } else if (annotationModel.annotationType == CAnnotationTypeSignDate) {
  600. subType = KMSelfSignAnnotationFreeTextSubTypeDate;
  601. }
  602. KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
  603. vc.subType = subType;
  604. vc.pdfView = self.pdfView;
  605. vc.annotationModel = annotationModel;
  606. self.propertiesBox.contentView = vc.view;
  607. self.contentViewController = vc;
  608. } else if (annotationMode == CAnnotationTypeStamp) {
  609. KMAnnotationStampViewController *vc = [[KMAnnotationStampViewController alloc] init];
  610. vc.pdfView = self.pdfView;
  611. vc.annotationModel = annotationModel;
  612. self.propertiesBox.contentView = vc.view;
  613. self.contentViewController = vc;
  614. } else if (annotationMode == CAnnotationTypeSignSignature) {
  615. KMSignatureAnnotationViewController *vc = [[KMSignatureAnnotationViewController alloc] init];
  616. self.titleViewHeightConstraint.constant = 0;
  617. vc.annotationModel = annotationModel;
  618. vc.pdfView = self.pdfView;
  619. self.propertiesBox.contentView = vc.view;
  620. self.contentViewController = vc;
  621. }
  622. }
  623. - (void)setIsEmptyAnnotation:(BOOL)isEmptyAnnotation
  624. {
  625. _isEmptyAnnotation = isEmptyAnnotation;
  626. if (isEmptyAnnotation) {
  627. self.titleLabel.hidden = YES;
  628. self.emptyView.hidden = NO;
  629. } else {
  630. self.titleLabel.hidden = NO;
  631. self.emptyView.hidden = YES;
  632. }
  633. }
  634. - (void)setOpenPropertiesType:(KMOpenPropertiesType)openPropertiesType {
  635. _openPropertiesType = openPropertiesType;
  636. if (openPropertiesType == KMOpenPropertiesType_PageDisplay) {
  637. if (self.contentViewController) {
  638. [self.contentViewController.view removeFromSuperview];
  639. self.contentViewController = nil;
  640. }
  641. self.titleLabel.stringValue = NSLocalizedString(@"View Settings", nil);
  642. KMPageDisplayPropertiesViewController *vc = [[KMPageDisplayPropertiesViewController alloc] init];
  643. vc.mainController = self.mainController;
  644. vc.pdfView = self.pdfView;
  645. __block typeof(self) blockSelf = self;
  646. vc.readerModeBlock = ^(BOOL isReaderMode) {
  647. if (blockSelf.pageDisplayReaderMode) {
  648. blockSelf.pageDisplayReaderMode(isReaderMode);
  649. }
  650. };
  651. self.propertiesBox.contentView = vc.view;
  652. self.contentViewController = vc;
  653. } else if (openPropertiesType == KMOpenPropertiesType_Stamp) {
  654. self.titleLabel.stringValue = NSLocalizedString(@"Stamp", nil);
  655. } else if (openPropertiesType == KMOpenPropertiesType_Link) {
  656. self.titleLabel.stringValue = NSLocalizedString(@"Link", nil);
  657. KMAnnotationLinkViewController *vc = [[KMAnnotationLinkViewController alloc] init];
  658. self.propertiesBox.contentView = vc.view;
  659. } else if (openPropertiesType == KMOpenPropertiesType_ListBox ||
  660. openPropertiesType == KMOpenPropertiesType_ComboBox ||
  661. openPropertiesType == KMOpenPropertiesType_Button) {
  662. } else if (openPropertiesType == KMOpenPropertiesType_FormSignatureClick) {
  663. self.contentViewController = nil;
  664. self.titleLabel.stringValue = @"";
  665. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  666. KMSignatureAnnotationViewController *vc = [[KMSignatureAnnotationViewController alloc] init];
  667. vc.isClickSignatureList = YES;
  668. vc.annotationModel = annotationModel;
  669. vc.pdfView = self.pdfView;
  670. vc.view.frame = [self viewControllerRect];
  671. [self.view addSubview:vc.view];
  672. self.contentViewController = vc;
  673. }
  674. }
  675. - (void)setIsContinuousAddStamp:(BOOL)isContinuousAddStamp {
  676. if (_annotations.count <= 0) {
  677. return;
  678. }
  679. CPDFAnnotation *annotation = _annotations.firstObject;
  680. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  681. if ([annotation isKindOfClass:[CPDFStampAnnotation class]]) {
  682. if (isContinuousAddStamp) {
  683. self.titleViewHeightConstraint.constant = 0;
  684. }
  685. } else if ([annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
  686. if (isContinuousAddStamp) {
  687. KMSignatureAnnotationViewController *vc = [[KMSignatureAnnotationViewController alloc] init];
  688. self.titleViewHeightConstraint.constant = 0;
  689. vc.annotationModel = annotationModel;
  690. vc.pdfView = self.pdfView;
  691. self.propertiesBox.contentView = vc.view;
  692. self.contentViewController = vc;
  693. }
  694. }
  695. }
  696. + (CGFloat)heightWithAnnotation:(CPDFAnnotation *)annotation {
  697. if (!annotation) {
  698. return 0;
  699. }
  700. if ([annotation isKindOfClass:[CPDFLinkAnnotation class]] ||
  701. [annotation isKindOfClass:[CPDFMovieAnnotation class]] ||
  702. [annotation isKindOfClass:[CPDFSoundAnnotation class]]) {
  703. return 0;
  704. } else if ([annotation isKindOfClass:[CSelfSignAnnotation class]]) {
  705. return 279;
  706. } else if ([annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
  707. return 279;
  708. } else if ([annotation isKindOfClass:[CPDFListStampAnnotation class]]) {
  709. return 279;
  710. } else if ([annotation isKindOfClass:[CPDFStampAnnotation class]]) {
  711. return 0;
  712. } else if ([annotation isKindOfClass:[CPDFSignatureWidgetAnnotation class]]) {
  713. return 279;
  714. } else {
  715. return 279;
  716. }
  717. }
  718. + (CGFloat)heightWithAnnotationMode:(CAnnotationType)annotationMode {
  719. if (CAnnotationTypeSignature == annotationMode ||
  720. CAnnotationTypeUnkown == annotationMode) {
  721. return 0;
  722. }
  723. return 279;
  724. }
  725. #pragma mark - Private Method
  726. - (CGRect)viewControllerRect {
  727. CGFloat viewFloat = 0;
  728. if (_buttonView == nil || self.gradientView == nil) {
  729. return CGRectMake(0, 0, NSWidth(self.view.frame), viewFloat);
  730. }
  731. if (_buttonView.hidden) {
  732. viewFloat = NSHeight(self.view.frame) - NSHeight(self.gradientView.frame);
  733. } else {
  734. viewFloat = NSHeight(self.view.frame) - NSHeight(self.gradientView.frame)-KMFromContentButtonHeightFloat;
  735. }
  736. return CGRectMake(0, 0, NSWidth(self.view.frame), viewFloat);
  737. }
  738. - (void)updateFormContentButtonUI:(NSButton *)button {
  739. self.clickBtn = button;
  740. switch (button.tag) {
  741. case 100:
  742. [_formGeneralButton setTitleColor:[KMAppearance KMColor_Layout_W0]];
  743. [_formAppearanceButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
  744. [_formOptionsButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
  745. if([KMAppearance isDarkMode]) {
  746. _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:34/255. green:122/255. blue:255/255. alpha:1.].CGColor;
  747. _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
  748. _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
  749. } else {
  750. _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:73/255. green:130/255. blue:230/255. alpha:1.].CGColor;
  751. _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
  752. _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
  753. }
  754. break;
  755. case 101:
  756. [_formGeneralButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
  757. [_formAppearanceButton setTitleColor:[KMAppearance KMColor_Layout_W0]];
  758. [_formOptionsButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
  759. if([KMAppearance isDarkMode]) {
  760. _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:34/255. green:122/255. blue:255/255. alpha:1.].CGColor;
  761. _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
  762. _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
  763. } else {
  764. _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:73/255. green:130/255. blue:230/255. alpha:1.].CGColor;
  765. _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
  766. _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
  767. }
  768. break;
  769. case 102:
  770. [_formGeneralButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
  771. [_formAppearanceButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
  772. [_formOptionsButton setTitleColor:[KMAppearance KMColor_Layout_W0]];
  773. if([KMAppearance isDarkMode]) {
  774. _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:34/255. green:122/255. blue:255/255. alpha:1.].CGColor;
  775. _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
  776. _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
  777. } else {
  778. _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:73/255. green:130/255. blue:230/255. alpha:1.].CGColor;
  779. _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
  780. _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
  781. }
  782. break;
  783. default:
  784. break;
  785. }
  786. }
  787. #pragma mark - NSButton Action
  788. - (IBAction)fromContentButtonAction:(NSButton *)sender {
  789. [self updateFormContentButtonUI:sender];
  790. self.tipsView.hidden = YES;
  791. switch (sender.tag) {
  792. case 100:
  793. {
  794. self.lastLineImageView.hidden = NO;
  795. self.oneLineImageView.hidden = YES;
  796. [self formGeneralProperties];
  797. }
  798. break;
  799. case 101:
  800. {
  801. self.lastLineImageView.hidden = YES;
  802. self.oneLineImageView.hidden = YES;
  803. [self formAppearanceProperties];
  804. }
  805. break;
  806. case 102:
  807. {
  808. self.lastLineImageView.hidden = YES;
  809. self.oneLineImageView.hidden = NO;
  810. [self formOptionProperties];
  811. }
  812. break;
  813. default:
  814. break;
  815. }
  816. }
  817. - (void)formGeneralProperties {
  818. CPDFAnnotation *annotation = _annotations.firstObject;
  819. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]] ||
  820. [annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]] ||
  821. [annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
  822. if ([self.contentViewController isKindOfClass:[KMAnnotationGeneralViewController class]]) {
  823. return;
  824. }
  825. [self.contentViewController.view removeFromSuperview];
  826. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  827. KMAnnotationGeneralViewController *vc = [[KMAnnotationGeneralViewController alloc] init];
  828. vc.pdfview = self.pdfView;
  829. vc.annotationModel = annotationModel;
  830. vc.view.frame = [self viewControllerRect];
  831. [self.view addSubview:vc.view];
  832. self.contentViewController = vc;
  833. }
  834. }
  835. - (void)formAppearanceProperties {
  836. CPDFAnnotation *annotation = _annotations.firstObject;
  837. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  838. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]) {
  839. if ([self.contentViewController isKindOfClass:[KMAnnotationFromViewController class]]) {
  840. return;
  841. }
  842. [self.contentViewController.view removeFromSuperview];
  843. KMAnnotationFromViewController *vc = [[KMAnnotationFromViewController alloc] init];
  844. vc.pdfView = self.pdfView;
  845. vc.annotationModel = annotationModel;
  846. vc.view.frame = [self viewControllerRect];
  847. [self.view addSubview:vc.view];
  848. self.contentViewController = vc;
  849. } else if ([annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
  850. CPDFButtonWidgetAnnotation *newAnnotation = (CPDFButtonWidgetAnnotation *)annotation;
  851. if (newAnnotation.controlType == 1 || newAnnotation.controlType == 2) {
  852. if ([self.contentViewController isKindOfClass:[KMAnnotationButtonWidgetAppearanceViewController class]]) {
  853. return;
  854. }
  855. [self.contentViewController.view removeFromSuperview];
  856. KMAnnotationButtonWidgetAppearanceViewController *vc = [[KMAnnotationButtonWidgetAppearanceViewController alloc] init];
  857. vc.pdfView = self.pdfView;
  858. vc.annotationModel = annotationModel;
  859. vc.view.frame = [self viewControllerRect];
  860. [self.view addSubview:vc.view];
  861. self.contentViewController = vc;
  862. } else if (newAnnotation.controlType == 0) {
  863. if ([self.contentViewController isKindOfClass:[KMAnnotationChoiceWidgetAppearanceViewController class]]) {
  864. return;
  865. }
  866. [self.contentViewController.view removeFromSuperview];
  867. KMAnnotationChoiceWidgetAppearanceViewController *vc = [[KMAnnotationChoiceWidgetAppearanceViewController alloc] init];
  868. vc.pdfView = self.pdfView;
  869. vc.annotationModel = annotationModel;
  870. vc.view.frame = [self viewControllerRect];
  871. [self.view addSubview:vc.view];
  872. self.contentViewController = vc;
  873. }
  874. } else if ([annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
  875. if ([self.contentViewController isKindOfClass:[KMAnnotationChoiceWidgetAppearanceViewController class]]) {
  876. return;
  877. }
  878. [self.contentViewController.view removeFromSuperview];
  879. KMAnnotationChoiceWidgetAppearanceViewController *vc = [[KMAnnotationChoiceWidgetAppearanceViewController alloc] init];
  880. vc.pdfView = self.pdfView;
  881. vc.annotationModel = annotationModel;
  882. vc.view.frame = [self viewControllerRect];
  883. [self.view addSubview:vc.view];
  884. self.contentViewController = vc;
  885. }
  886. }
  887. - (void)formOptionProperties {
  888. CPDFAnnotation *annotation = _annotations.firstObject;
  889. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  890. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]) {
  891. if ([self.contentViewController isKindOfClass:[KMAnnotationTextWidgetOptionsViewController class]]) {
  892. return;
  893. }
  894. [self.contentViewController.view removeFromSuperview];
  895. KMAnnotationTextWidgetOptionsViewController *vc = [[KMAnnotationTextWidgetOptionsViewController alloc] init];
  896. vc.pdfView = self.pdfView;
  897. vc.annotationModel = annotationModel;
  898. vc.view.frame = [self viewControllerRect];
  899. [self.view addSubview:vc.view];
  900. self.contentViewController = vc;
  901. } else if ([annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
  902. CPDFButtonWidgetAnnotation *newAnnotation = (CPDFButtonWidgetAnnotation *)annotation;
  903. if (newAnnotation.controlType == CPDFWidgetRadioButtonControl || newAnnotation.controlType == CPDFWidgetCheckBoxControl) {
  904. if ([self.contentViewController isKindOfClass:[KMAnnotationButtonWidgetOptionsViewController class]]) {
  905. return;
  906. }
  907. [self.contentViewController.view removeFromSuperview];
  908. if (newAnnotation.controlType == CPDFWidgetRadioButtonControl) {
  909. self.tipsView.hidden = NO;
  910. 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)];;
  911. } else {
  912. self.tipsView.hidden = YES;
  913. }
  914. KMAnnotationButtonWidgetOptionsViewController *vc = [[KMAnnotationButtonWidgetOptionsViewController alloc] init];
  915. vc.pdfView = self.pdfView;
  916. vc.annotationModel = annotationModel;
  917. vc.view.frame = [self viewControllerRect];
  918. [self.view addSubview:vc.view];
  919. self.contentViewController = vc;
  920. } else if (newAnnotation.controlType == CPDFWidgetPushButtonControl) {
  921. if ([self.contentViewController isKindOfClass:[KMAnnotationButtonOptionsViewController class]]) {
  922. return;
  923. }
  924. [self.contentViewController.view removeFromSuperview];
  925. KMAnnotationButtonOptionsViewController *vc = [[KMAnnotationButtonOptionsViewController alloc] init];
  926. vc.pdfView = self.pdfView;
  927. vc.annotationModel = annotationModel;
  928. vc.view.frame = [self viewControllerRect];
  929. [self.view addSubview:vc.view];
  930. self.contentViewController = vc;
  931. }
  932. } else if ([annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
  933. if ([self.contentViewController isKindOfClass:[KMAnnotationChoiceWidgetOptionsViewController class]]) {
  934. return;
  935. }
  936. [self.contentViewController.view removeFromSuperview];
  937. self.tipsView.hidden = YES;
  938. self.tipsLabel.stringValue = [NSString stringWithFormat:@" %@", NSLocalizedString(@"Select an item in the list to make it the default choice.", nil)];;
  939. KMAnnotationChoiceWidgetOptionsViewController *vc = [[KMAnnotationChoiceWidgetOptionsViewController alloc] init];
  940. vc.pdfView = self.pdfView;
  941. vc.annotationModel = annotationModel;
  942. vc.view.frame = [self viewControllerRect];
  943. [self.view addSubview:vc.view];
  944. self.contentViewController = vc;
  945. }
  946. }
  947. @end