KMAnnotationPropertiesViewController.m 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147
  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. NSString *subTitle = self.subTitleLabel.stringValue != nil ? self.subTitleLabel.stringValue : @"";
  96. self.subTitleLabel.attributedStringValue = [[NSAttributedString alloc] initWithString:subTitle attributes:@{
  97. NSForegroundColorAttributeName : [NSColor colorWithRed:148/255.f green:152/255.f blue:156/255.f alpha:1.f],
  98. NSFontAttributeName : [NSFont fontWithName:@"SFProText-Regular" size:12],
  99. NSParagraphStyleAttributeName : ps}];
  100. self.subTitleLabel.textColor = [NSColor grayColor];
  101. self.titleLabel.font = [NSFont SFProTextSemiboldFont:14.0];
  102. self.titleLabel.textColor = [KMAppearance KMColor_Layout_H0];
  103. // [NSColor colorWithRed:0.145 green:0.149 blue:0.161 alpha:1];
  104. self.buttonView.hidden = YES;
  105. self.formGeneralButton.wantsLayer = YES;
  106. self.formAppearanceButton.wantsLayer = YES;
  107. self.formOptionsButton.wantsLayer = YES;
  108. [self updateFormContentButtonUI:self.formAppearanceButton];
  109. self.formAppearanceButton.toolTip = NSLocalizedString(@"Appearance", nil);
  110. [self.formAppearanceButton setTitle:NSLocalizedString(@"Appearance", nil)];
  111. self.formGeneralButton.toolTip = NSLocalizedString(@"General", nil);
  112. [self.formGeneralButton setTitle:NSLocalizedString(@"General", nil)];
  113. self.formOptionsButton.toolTip = NSLocalizedString(@"Preferences", nil);
  114. [self.formOptionsButton setTitle:NSLocalizedString(@"Preferences", nil)];
  115. self.tipsView.hidden = YES;
  116. self.tipsView.wantsLayer = YES;
  117. self.tipsView.layer.cornerRadius = 1.0;
  118. self.oneLineImageView.wantsLayer = YES;
  119. self.lastLineImageView.wantsLayer = YES;
  120. self.oneLineImageView.hidden = YES;
  121. }
  122. #pragma mark - Setter Methods
  123. -(void)setAnnotations:(NSArray *)annotations
  124. {
  125. if (_annotations != annotations) {
  126. _annotations = annotations;
  127. }
  128. self.buttonView.hidden = YES;
  129. CPDFAnnotation *annotation = _annotations.firstObject;
  130. if (self.contentViewController) {
  131. [self.contentViewController.view removeFromSuperview];
  132. self.contentViewController = nil;
  133. }
  134. if (!annotation || [annotation isKindOfClass:[CPDFRedactAnnotation class]]) {
  135. return;
  136. }
  137. if (_annotations.count > 1) {
  138. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]] ||
  139. [annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]] ||
  140. [annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
  141. } else {
  142. [self selectAnnotations:_annotations];
  143. return;
  144. }
  145. }
  146. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]){
  147. self.titleLabel.stringValue = NSLocalizedString(@"Text Field", nil);
  148. } else if ([annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
  149. CPDFButtonWidgetAnnotation *buttonWidget = (CPDFButtonWidgetAnnotation *)annotation;
  150. if (buttonWidget.controlType == 1) {
  151. self.titleLabel.stringValue = NSLocalizedString(@"Radio Button", nil);
  152. } else if (buttonWidget.controlType == 2) {
  153. self.titleLabel.stringValue = NSLocalizedString(@"Check Box", nil);
  154. } else if (buttonWidget.controlType == 0) {
  155. self.titleLabel.stringValue = NSLocalizedString(@"Button", nil);
  156. }
  157. } else if ([annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
  158. CPDFChoiceWidgetAnnotation *choiceWidget = (CPDFChoiceWidgetAnnotation *)annotation;
  159. if (choiceWidget.isListChoice) {
  160. self.titleLabel.stringValue = NSLocalizedString(@"List Box", nil);
  161. } else {
  162. self.titleLabel.stringValue = NSLocalizedString(@"Combo Box", nil);
  163. }
  164. } else if ([annotation isKindOfClass:[KMSelfSignAnnotation class]]) {
  165. KMSelfSignAnnotation *newAnnotation = (KMSelfSignAnnotation *)annotation;
  166. CAnnotationType type = newAnnotation.annotationType;
  167. NSString *returnString = @"";
  168. if (type == CAnnotationTypeSignFalse) {
  169. returnString = NSLocalizedString(@"X", nil);
  170. } else if (type == CAnnotationTypeSignTure) {
  171. returnString = NSLocalizedString(@"Check mark", nil);
  172. } else if (type == CAnnotationTypeSignCircle) {
  173. returnString = NSLocalizedString(@"Circle", nil);
  174. } else if (type == CAnnotationTypeSignLine) {
  175. returnString = NSLocalizedString(@"Line", nil);
  176. } else if (type == CAnnotationTypeSignDot) {
  177. returnString = NSLocalizedString(@"Dot", nil);
  178. } else if (type == CAnnotationTypeSignText) {
  179. returnString = NSLocalizedString(@"Text", nil);
  180. }
  181. self.titleLabel.stringValue = returnString;
  182. } else if ([annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
  183. self.titleLabel.stringValue = NSLocalizedString(@"Link", @"Description for export");
  184. } else if ([annotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
  185. if ([annotation isKindOfClass:[KMSelfSignAnnotationFreeText class]]) {
  186. KMSelfSignAnnotationFreeText *signFreeText = (KMSelfSignAnnotationFreeText *)annotation;
  187. if (signFreeText.subType == KMSelfSignAnnotationFreeTextSubTypeProfile) {
  188. self.titleLabel.stringValue = NSLocalizedString(@"Text", nil);
  189. } else {
  190. self.titleLabel.stringValue = NSLocalizedString(@"Date", nil);
  191. }
  192. } else {
  193. self.titleLabel.stringValue = [annotation type].typeName;
  194. }
  195. } else if ([annotation isKindOfClass:[CPDFSignatureWidgetAnnotation class]] ||
  196. [annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
  197. self.titleLabel.stringValue = NSLocalizedString(@"Signature", nil);
  198. } else if ([annotation isKindOfClass:[CSelfSignAnnotation class]]) {
  199. CSelfSignAnnotation *newAnnotation = (CSelfSignAnnotation *)annotation;
  200. if (newAnnotation.annotationType == CAnnotationTypeSignFalse) {
  201. self.titleLabel.stringValue = NSLocalizedString(@"X", nil);
  202. } else if (newAnnotation.annotationType == CAnnotationTypeSignTure) {
  203. self.titleLabel.stringValue = NSLocalizedString(@"Check mark", nil);
  204. } else if (newAnnotation.annotationType == CAnnotationTypeSignCircle) {
  205. self.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
  206. } else if (newAnnotation.annotationType == CAnnotationTypeSignLine) {
  207. self.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
  208. } else if (newAnnotation.annotationType == CAnnotationTypeSignDot) {
  209. self.titleLabel.stringValue = NSLocalizedString(@"Dot", nil);
  210. } else if (newAnnotation.annotationType == CAnnotationTypeSignText) {
  211. self.titleLabel.stringValue = NSLocalizedString(@"Text", nil);
  212. } else if (newAnnotation.annotationType == CAnnotationTypeSignDate) {
  213. self.titleLabel.stringValue = NSLocalizedString(@"Date", nil);
  214. }
  215. } else if ([annotation isKindOfClass:[CPDFStampAnnotation class]]) {
  216. self.titleLabel.stringValue = NSLocalizedString(@"Stamp", nil);
  217. } else if ([annotation isKindOfClass:[KMTableAnnotation class]]) {
  218. self.titleLabel.stringValue = NSLocalizedString(@"Table", nil);
  219. } else if ([annotation isKindOfClass:[CPDFLineAnnotation class]]) {
  220. if (self.pdfView.toolMode == CMeasureToolMode ||
  221. [(CPDFLineAnnotation *)annotation isMeasure]) {
  222. self.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
  223. }
  224. } else if ([annotation isKindOfClass:[CPDFPolylineAnnotation class]]) {
  225. self.titleLabel.stringValue = NSLocalizedString(@"Multilines", nil);
  226. } else if ([annotation isKindOfClass:[CPDFPolygonAnnotation class]]) {
  227. if (self.pdfView.annotationType == CAnnotationTypeSquare) {
  228. self.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
  229. } else {
  230. self.titleLabel.stringValue = NSLocalizedString(@"Polygon", nil);
  231. }
  232. } else {
  233. self.titleLabel.stringValue = [annotation type].typeName;
  234. }
  235. self.titleViewHeightConstraint.constant = 40;
  236. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  237. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]] ||
  238. [annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]] ||
  239. [annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
  240. self.buttonView.hidden = NO;
  241. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]) {
  242. [self updateFormContentButtonUI:_formGeneralButton];
  243. KMAnnotationGeneralViewController *vc = [[KMAnnotationGeneralViewController alloc] init];
  244. vc.pdfview = self.pdfView;
  245. vc.annotationModel = annotationModel;
  246. vc.view.frame = [self viewControllerRect];
  247. [self.view addSubview:vc.view];
  248. self.contentViewController = vc;
  249. } else if ([annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
  250. [self fromContentButtonAction:_formOptionsButton];
  251. } else if ([annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
  252. CPDFButtonWidgetAnnotation *newAnnotation = (CPDFButtonWidgetAnnotation *)annotation;
  253. if (newAnnotation.controlType == CPDFWidgetRadioButtonControl || newAnnotation.controlType == CPDFWidgetCheckBoxControl) {
  254. [self updateFormContentButtonUI:_formGeneralButton];
  255. KMAnnotationGeneralViewController *vc = [[KMAnnotationGeneralViewController alloc] init];
  256. vc.pdfview = self.pdfView;
  257. vc.annotations = self.annotations;
  258. vc.view.frame = [self viewControllerRect];
  259. [self.view addSubview:vc.view];
  260. self.contentViewController = vc;
  261. } else if (newAnnotation.controlType == CPDFWidgetPushButtonControl) {
  262. [self fromContentButtonAction:_formOptionsButton];
  263. }
  264. }
  265. } else if ([annotation isKindOfClass:[KMAnnotationFromSignature class]]) {
  266. KMAnnotationGeneralViewController *vc = [[KMAnnotationGeneralViewController alloc] init];
  267. vc.pdfview = self.pdfView;
  268. vc.annotationModel = annotationModel;
  269. vc.view.frame = [self viewControllerRect];
  270. [self.view addSubview:vc.view];
  271. self.contentViewController = vc;
  272. } else if ([annotation isKindOfClass:[CPDFSignatureWidgetAnnotation class]]) {
  273. if (!_isClickFormSignature) {
  274. KMAnnotationGeneralViewController *vc = [[KMAnnotationGeneralViewController alloc] init];
  275. vc.pdfview = self.pdfView;
  276. vc.annotationModel = annotationModel;
  277. vc.view.frame = [self viewControllerRect];
  278. [self.view addSubview:vc.view];
  279. self.contentViewController = vc;
  280. }
  281. _isClickFormSignature = NO;
  282. } else if ([annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
  283. CPDFLinkAnnotation *linkAnnotation = annotations.firstObject;
  284. NSString *contents = nil;
  285. if ([linkAnnotation URL]) {
  286. contents = [linkAnnotation URL];
  287. if (contents) {
  288. contents = [NSString stringWithFormat:@"1%@", contents];
  289. } else {
  290. contents = @"";
  291. }
  292. } else {
  293. contents = [NSString stringWithFormat:@"0%@", @([[linkAnnotation destination] pageIndex]+1)];
  294. }
  295. KMAnnotationSelectLinkViewController *vc = [[KMAnnotationSelectLinkViewController alloc] init];
  296. vc.annotations = self.annotations;
  297. vc.pdfDocument = self.pdfView.document;
  298. vc.pdfview = self.pdfView;
  299. vc.view.frame = [self viewControllerRect];
  300. [self.view addSubview:vc.view];
  301. self.contentViewController = vc;
  302. } else if ([annotation isKindOfClass:[CSelfSignAnnotation class]]) {
  303. CSelfSignAnnotation *newAnnotation = (CSelfSignAnnotation *)annotation;
  304. if (newAnnotation.annotationType == CAnnotationTypeSignFalse ||
  305. newAnnotation.annotationType == CAnnotationTypeSignTure ||
  306. newAnnotation.annotationType == CAnnotationTypeSignCircle ||
  307. newAnnotation.annotationType == CAnnotationTypeSignLine ||
  308. newAnnotation.annotationType == CAnnotationTypeSignDot) {
  309. KMAnnotationSelfSignViewController *vc = [[KMAnnotationSelfSignViewController alloc] init];
  310. vc.pdfView = self.pdfView;
  311. vc.annotationModel = annotationModel;
  312. self.propertiesBox.contentView = vc.view;
  313. self.contentViewController = vc;
  314. __weak typeof (self) weakSelf = self;
  315. vc.callBack = ^(CAnnotationType type) {
  316. if (type == CAnnotationTypeSignFalse) {
  317. weakSelf.titleLabel.stringValue = NSLocalizedString(@"X", nil);
  318. } else if (type == CAnnotationTypeSignTure) {
  319. weakSelf.titleLabel.stringValue = NSLocalizedString(@"Check mark", nil);
  320. } else if (type == CAnnotationTypeSignCircle) {
  321. weakSelf.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
  322. } else if (type == CAnnotationTypeSignLine) {
  323. weakSelf.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
  324. } else if (type == CAnnotationTypeSignDot) {
  325. weakSelf.titleLabel.stringValue = NSLocalizedString(@"Dot", nil);
  326. }
  327. if (weakSelf.annoTypeDidChange != nil) {
  328. weakSelf.annoTypeDidChange(annotation);
  329. }
  330. };
  331. } else if (newAnnotation.annotationType == CAnnotationTypeSignText ||
  332. newAnnotation.annotationType == CAnnotationTypeSignDate) {
  333. KMSelfSignAnnotationFreeTextSubType subType = KMSelfSignAnnotationFreeTextSubTypeNone;
  334. if (annotationModel.annotationType == CAnnotationTypeSignConfig) {
  335. subType = KMSelfSignAnnotationFreeTextSubTypeProfile;
  336. } else if (annotationModel.annotationType == CAnnotationTypeSignText) {
  337. subType = KMSelfSignAnnotationFreeTextSubTypeFreeText;
  338. } else if (annotationModel.annotationType == CAnnotationTypeSignDate) {
  339. subType = KMSelfSignAnnotationFreeTextSubTypeDate;
  340. }
  341. KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
  342. vc.subType = subType;
  343. vc.pdfView = self.pdfView;
  344. vc.annotationModel = annotationModel;
  345. self.propertiesBox.contentView = vc.view;
  346. self.contentViewController = vc;
  347. }
  348. } else if ([annotation isKindOfClass:[CSelfSignAnnotationFreeText class]]) {
  349. CSelfSignAnnotationFreeText *newAnnotation = (CSelfSignAnnotationFreeText *)annotation;
  350. if (newAnnotation.subType == CAnnotationTypeSignText ||
  351. newAnnotation.subType == CAnnotationTypeSignDate) {
  352. KMSelfSignAnnotationFreeTextSubType subType = KMSelfSignAnnotationFreeTextSubTypeNone;
  353. if (annotationModel.annotationType == CAnnotationTypeSignConfig) {
  354. subType = KMSelfSignAnnotationFreeTextSubTypeProfile;
  355. } else if (annotationModel.annotationType == CAnnotationTypeSignText) {
  356. subType = KMSelfSignAnnotationFreeTextSubTypeFreeText;
  357. } else if (annotationModel.annotationType == CAnnotationTypeSignDate) {
  358. subType = KMSelfSignAnnotationFreeTextSubTypeDate;
  359. }
  360. KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
  361. vc.subType = subType;
  362. vc.pdfView = self.pdfView;
  363. vc.annotationModel = annotationModel;
  364. self.propertiesBox.contentView = vc.view;
  365. self.contentViewController = vc;
  366. }
  367. } else if ([annotation isKindOfClass:[CPDFSignatureAnnotation class]] ||
  368. [annotation isKindOfClass:[CPDFStampAnnotation class]]) {
  369. KMAnnotationStampViewController *vc = [[KMAnnotationStampViewController alloc] init];
  370. vc.pdfView = self.pdfView;
  371. vc.annotationModel = annotationModel;
  372. self.propertiesBox.contentView = vc.view;
  373. self.contentViewController = vc;
  374. } else if ([annotation isKindOfClass:[KMTableAnnotation class]]) {
  375. KMAnnotationTableViewController *vc = [[KMAnnotationTableViewController alloc] init];
  376. vc.pdfView = self.pdfView;
  377. vc.annotationModel = annotationModel;
  378. self.propertiesBox.contentView = vc.view;
  379. self.contentViewController = vc;
  380. } else if (([annotation isKindOfClass:[CPDFPolylineAnnotation class]]) ||
  381. ([annotation isKindOfClass:[CPDFPolygonAnnotation class]])) {
  382. KMMeasureSideVC *vc = [[KMMeasureSideVC alloc] init];
  383. vc.pdfView = self.pdfView;
  384. vc.annotationModel = annotationModel;
  385. self.propertiesBox.contentView = vc.view;
  386. self.contentViewController = vc;
  387. } else if ([annotation isKindOfClass:[CPDFLineAnnotation class]]) {
  388. if ((self.pdfView.toolMode == CMeasureToolMode) ||
  389. [(CPDFLineAnnotation *)annotation isMeasure]) {
  390. KMMeasureSideVC *vc = [[KMMeasureSideVC alloc] init];
  391. vc.pdfView = self.pdfView;
  392. vc.annotationModel = annotationModel;
  393. self.propertiesBox.contentView = vc.view;
  394. self.contentViewController = vc;
  395. } else {
  396. KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
  397. vc.pdfView = self.pdfView;
  398. vc.annotationModel = annotationModel;
  399. self.propertiesBox.contentView = vc.view;
  400. self.contentViewController = vc;
  401. }
  402. } else {
  403. if ([annotation isKindOfClass:[CPDFInkAnnotation class]]) {
  404. KMFreehandAnnotationController *vc = [[KMFreehandAnnotationController alloc] init];
  405. vc.pdfView = self.pdfView;
  406. vc.annotationModel = annotationModel;
  407. self.propertiesBox.contentView = vc.view;
  408. self.contentViewController = vc;
  409. } else if ([annotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
  410. CPDFMarkupAnnotation *markupA = (CPDFMarkupAnnotation *)annotation;
  411. if (markupA.markupType == CPDFMarkupTypeSquiggly) {
  412. KMWavyLineAnnotationController *vc = [[KMWavyLineAnnotationController alloc] init];
  413. vc.pdfView = self.pdfView;
  414. vc.annotationModel = annotationModel;
  415. self.propertiesBox.contentView = vc.view;
  416. self.contentViewController = vc;
  417. } else {
  418. KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
  419. vc.pdfView = self.pdfView;
  420. vc.annotationModel = annotationModel;
  421. self.propertiesBox.contentView = vc.view;
  422. self.contentViewController = vc;
  423. }
  424. } else {
  425. KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
  426. vc.pdfView = self.pdfView;
  427. vc.annotationModel = annotationModel;
  428. self.propertiesBox.contentView = vc.view;
  429. self.contentViewController = vc;
  430. }
  431. }
  432. // self.buttonbuttonLayoutConstraint.constant = self.buttonView.hidden ? -36 : 0;
  433. }
  434. - (void)selectAnnotations:(NSArray *)annotations {
  435. CPDFAnnotation *fristAnnotation = annotations.firstObject;
  436. CAnnotationType annotationMode = CAnnotationTypeUnkown;
  437. if ([fristAnnotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
  438. annotationMode = CAnnotationTypeHighlight;
  439. } else if ([fristAnnotation isKindOfClass:[CPDFInkAnnotation class]]) {
  440. annotationMode = CAnnotationTypeInk;
  441. } else if ([fristAnnotation isKindOfClass:[CPDFTextAnnotation class]]) {
  442. annotationMode = CAnnotationTypeAnchored;
  443. } else if ([fristAnnotation isKindOfClass:[CPDFSquareAnnotation class]]) {
  444. annotationMode = CAnnotationTypeSquare;
  445. } else if ([fristAnnotation isKindOfClass:[CPDFCircleAnnotation class]]) {
  446. annotationMode = CAnnotationTypeCircle;
  447. } else if ([fristAnnotation isKindOfClass:[CPDFLineAnnotation class]]) {
  448. if(((CPDFLineAnnotation *)fristAnnotation).startLineStyle == CPDFLineStyleNone &&
  449. ((CPDFLineAnnotation *)fristAnnotation).endLineStyle == CPDFLineStyleOpenArrow ) {
  450. annotationMode = CAnnotationTypeArrow;
  451. } else {
  452. annotationMode = CAnnotationTypeLine;
  453. }
  454. } else if ([fristAnnotation isKindOfClass:[CPDFLinkAnnotation class]]) {
  455. annotationMode = CAnnotationTypeLink;
  456. } else if ([fristAnnotation isKindOfClass:[CPDFStampAnnotation class]]) {
  457. if ([fristAnnotation isKindOfClass:[CSelfSignAnnotation class]]) {
  458. CSelfSignAnnotation *newAnnotation = (CSelfSignAnnotation *)fristAnnotation;
  459. if (newAnnotation.annotationType == CAnnotationTypeSignFalse)
  460. annotationMode = CAnnotationTypeSignFalse;
  461. else if(newAnnotation.annotationType == CAnnotationTypeSignTure)
  462. annotationMode = CAnnotationTypeSignTure;
  463. else if(newAnnotation.annotationType == CAnnotationTypeSignCircle)
  464. annotationMode = CAnnotationTypeSignCircle;
  465. else if(newAnnotation.annotationType == CAnnotationTypeSignLine)
  466. annotationMode = CAnnotationTypeSignLine;
  467. else if(newAnnotation.annotationType == CAnnotationTypeSignDot)
  468. annotationMode = CAnnotationTypeSignDot;
  469. else if(newAnnotation.annotationType == CAnnotationTypeSignDot)
  470. annotationMode = CAnnotationTypeSignDot;
  471. } else if ([fristAnnotation isKindOfClass:[CSelfSignAnnotationFreeText class]]) {
  472. CSelfSignAnnotationFreeText *newAnnotation = (CSelfSignAnnotationFreeText *)fristAnnotation;
  473. if (newAnnotation.subType == CAnnotationTypeSignText)
  474. annotationMode = CAnnotationTypeSignText;
  475. else if(newAnnotation.subType == CAnnotationTypeSignDate)
  476. annotationMode = CAnnotationTypeSignDate;
  477. } else {
  478. annotationMode = CAnnotationTypeStamp;
  479. }
  480. } else if ([fristAnnotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
  481. annotationMode = CAnnotationTypeSignature;
  482. } else if ([fristAnnotation isKindOfClass:[CPDFFreeTextAnnotation class]]) {
  483. if ([fristAnnotation isKindOfClass:[CSelfSignAnnotationFreeText class]]) {
  484. CSelfSignAnnotationFreeText *newAnnotation = (CSelfSignAnnotationFreeText *)fristAnnotation;
  485. if (newAnnotation.subType == CAnnotationTypeSignText)
  486. annotationMode = CAnnotationTypeSignText;
  487. else if(newAnnotation.subType == CAnnotationTypeSignDate)
  488. annotationMode = CAnnotationTypeSignDate;
  489. } else {
  490. annotationMode = CAnnotationTypeFreeText;
  491. }
  492. }
  493. self.annotationMode = annotationMode;
  494. }
  495. - (void)setAnnotationMode:(CAnnotationType)annotationMode {
  496. _annotationMode = annotationMode;
  497. if (self.contentViewController) {
  498. [self.contentViewController.view removeFromSuperview];
  499. self.contentViewController = nil;
  500. }
  501. NSString *title = @"";
  502. if (annotationMode == CAnnotationTypeFreeText)
  503. title = NSLocalizedString(@"Text", @"Description for export");
  504. else if (annotationMode == CAnnotationTypeCircle)
  505. title = NSLocalizedString(@"Circle", @"Description for export");
  506. else if (annotationMode == CAnnotationTypeSquare)
  507. title = NSLocalizedString(@"Rectangle", @"Description for export");
  508. else if (annotationMode == CAnnotationTypeHighlight) {
  509. title = NSLocalizedString(@"Highlight", @"Description for export");
  510. if (_annotations.count > 1)
  511. title = NSLocalizedString(@"General", @"Description for export");
  512. }
  513. else if (annotationMode == CAnnotationTypeUnderline) {
  514. title = NSLocalizedString(@"Underline", @"Description for export");
  515. if (_annotations.count > 1)
  516. title = NSLocalizedString(@"General", @"Description for export");
  517. }
  518. else if (annotationMode == CAnnotationTypeStrikeOut)
  519. title = NSLocalizedString(@"Strikethrough", @"Description for export");
  520. else if (annotationMode == CAnnotationTypeLine)
  521. title = NSLocalizedString(@"Line", @"Description for export");
  522. else if (annotationMode == CAnnotationTypeArrow)
  523. title = NSLocalizedString(@"Arrow", @"Description for export");
  524. else if (annotationMode == CAnnotationTypeInk)
  525. title = NSLocalizedString(@"Freehand", @"Description for export");
  526. else if (annotationMode == CAnnotationTypeEraser)
  527. title = NSLocalizedString(@"Eraser", @"Description for export");
  528. else if (annotationMode == CAnnotationTypeAnchored)
  529. title = NSLocalizedString(@"Note", @"Description for export");
  530. else if (annotationMode == CAnnotationTypeLink)
  531. title = NSLocalizedString(@"Link", @"Description for export");
  532. else if (annotationMode == CAnnotationTypeTextField)
  533. title = NSLocalizedString(@"Text Field", @"Description for export");
  534. else if (annotationMode == CAnnotationTypeCheckBox)
  535. title = NSLocalizedString(@"Check Box", @"Description for export");
  536. else if (annotationMode == CAnnotationTypeListMenu)
  537. title = NSLocalizedString(@"List Box", @"Description for export");
  538. else if (annotationMode == CAnnotationTypeComboBox)
  539. title = NSLocalizedString(@"Combo Box", @"Description for export");
  540. else if (annotationMode == CAnnotationTypeRadioButton)
  541. title = NSLocalizedString(@"Radio Button", @"Description for export");
  542. else if (annotationMode == CAnnotationTypeActionButton)
  543. title = NSLocalizedString(@"Button", @"Description for export");
  544. else if (annotationMode == CAnnotationTypeSignature)
  545. title = NSLocalizedString(@"Sample", @"Description for export");
  546. else if (annotationMode == CAnnotationTypeSignDot)
  547. title = NSLocalizedString(@"Dot", @"Description for export");
  548. else if (annotationMode == CAnnotationTypeSignLine)
  549. title = NSLocalizedString(@"Line", @"Description for export");
  550. else if (annotationMode == CAnnotationTypeSignCircle)
  551. title = NSLocalizedString(@"Rectangle", @"Description for export");
  552. else if (annotationMode == CAnnotationTypeSignFalse)
  553. title = NSLocalizedString(@"X", nil);
  554. else if (annotationMode == CAnnotationTypeSignTure)
  555. title = NSLocalizedString(@"Check mark", nil);
  556. else if (annotationMode == CAnnotationTypeSignText)
  557. title = NSLocalizedString(@"Text", nil);
  558. else if (annotationMode == CAnnotationTypeSignDate)
  559. title = NSLocalizedString(@"Date", nil);
  560. else if (annotationMode == CAnnotationTypeStamp)
  561. title = NSLocalizedString(@"Stamp", nil);
  562. else if (annotationMode == CAnnotationTypeSquiggly)
  563. title = NSLocalizedString(@"Squiggly", nil);
  564. else
  565. title = @"";
  566. if(_annotations.count > 1) {
  567. title = NSLocalizedString(@"Properties", nil);
  568. }
  569. self.titleLabel.stringValue = title;
  570. self.titleViewHeightConstraint.constant = 40;
  571. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithAnnotationType:annotationMode];
  572. if (annotationMode == CAnnotationTypeFreeText ||
  573. annotationMode == CAnnotationTypeAnchored ||
  574. annotationMode == CAnnotationTypeCircle ||
  575. annotationMode == CAnnotationTypeSquare ||
  576. annotationMode == CAnnotationTypeHighlight ||
  577. annotationMode == CAnnotationTypeUnderline ||
  578. annotationMode == CAnnotationTypeStrikeOut ||
  579. annotationMode == CAnnotationTypeSquiggly ||
  580. annotationMode == CAnnotationTypeLine ||
  581. annotationMode == CAnnotationTypeInk ||
  582. annotationMode == CAnnotationTypeEraser ||
  583. annotationMode == CAnnotationTypeArrow) {
  584. //处理多选
  585. if(_annotations.count > 1) {
  586. annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  587. }
  588. if (annotationMode == CAnnotationTypeInk) {
  589. KMFreehandAnnotationController *vc = [[KMFreehandAnnotationController alloc] init];
  590. vc.pdfView = self.pdfView;
  591. vc.annotationModel = annotationModel;
  592. self.propertiesBox.contentView = vc.view;
  593. self.contentViewController = vc;
  594. } else if (annotationMode == CAnnotationTypeSquiggly) {
  595. KMWavyLineAnnotationController *vc = [[KMWavyLineAnnotationController alloc] init];
  596. vc.pdfView = self.pdfView;
  597. vc.annotationModel = annotationModel;
  598. self.propertiesBox.contentView = vc.view;
  599. self.contentViewController = vc;
  600. } else if (annotationMode == CAnnotationTypeEraser) {
  601. KMEraserAnnotationController *vc = [[KMEraserAnnotationController alloc] init];
  602. vc.pdfView = self.pdfView;
  603. vc.annotationModel = annotationModel;
  604. self.propertiesBox.contentView = vc.view;
  605. self.contentViewController = vc;
  606. } else {
  607. KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
  608. vc.pdfView = self.pdfView;
  609. vc.annotationModel = annotationModel;
  610. self.propertiesBox.contentView = vc.view;
  611. self.contentViewController = vc;
  612. }
  613. } else if (annotationMode == CAnnotationTypeLink) {
  614. } else if (annotationMode == CAnnotationTypeRadioButton ||
  615. annotationMode == CAnnotationTypeCheckBox ||
  616. annotationMode == CAnnotationTypeTextField ||
  617. annotationMode == CAnnotationTypeComboBox ||
  618. annotationMode == CAnnotationTypeListMenu ||
  619. annotationMode == CAnnotationTypeActionButton) {
  620. if (annotationMode == CAnnotationTypeTextField) {
  621. KMAnnotationFromViewController *vc = [[KMAnnotationFromViewController alloc] init];
  622. vc.pdfView = self.pdfView;
  623. vc.annotationModel = annotationModel;
  624. self.propertiesBox.contentView = vc.view;
  625. self.contentViewController = vc;
  626. } else if (annotationMode == CAnnotationTypeListMenu ||
  627. annotationMode == CAnnotationTypeComboBox ||
  628. annotationMode == CAnnotationTypeActionButton) {
  629. KMAnnotationChoiceWidgetAppearanceViewController *vc = [[KMAnnotationChoiceWidgetAppearanceViewController alloc] init];
  630. vc.annotationModel = annotationModel;
  631. vc.pdfView = self.pdfView;
  632. self.propertiesBox.contentView = vc.view;
  633. self.contentViewController = vc;
  634. } else if (annotationMode == CAnnotationTypeRadioButton ||
  635. annotationMode == CAnnotationTypeCheckBox) {
  636. KMAnnotationButtonWidgetAppearanceViewController *vc = [[KMAnnotationButtonWidgetAppearanceViewController alloc] init];
  637. vc.annotationModel = annotationModel;
  638. vc.pdfView = self.pdfView;
  639. self.propertiesBox.contentView = vc.view;
  640. self.contentViewController = vc;
  641. }
  642. } else if (annotationMode == CAnnotationTypeSignFalse ||
  643. annotationMode == CAnnotationTypeSignTure ||
  644. annotationMode == CAnnotationTypeSignCircle ||
  645. annotationMode == CAnnotationTypeSignLine ||
  646. annotationMode == CAnnotationTypeSignDot) {
  647. if(_annotations.count > 1) {
  648. annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  649. }
  650. KMAnnotationSelfSignViewController *vc = [[KMAnnotationSelfSignViewController alloc] init];
  651. vc.pdfView = self.pdfView;
  652. vc.annotationModel = annotationModel;
  653. self.propertiesBox.contentView = vc.view;
  654. self.contentViewController = vc;
  655. __weak typeof(self) weakSelf = self;
  656. vc.callBack = ^(CAnnotationType type) {
  657. if (type == CAnnotationTypeSignFalse) {
  658. weakSelf.titleLabel.stringValue = NSLocalizedString(@"X", nil);
  659. } else if (type == CAnnotationTypeSignTure) {
  660. weakSelf.titleLabel.stringValue = NSLocalizedString(@"Check mark", nil);
  661. } else if (type == CAnnotationTypeSignCircle) {
  662. weakSelf.titleLabel.stringValue = NSLocalizedString(@"Rectangle", nil);
  663. } else if (type == CAnnotationTypeSignLine) {
  664. weakSelf.titleLabel.stringValue = NSLocalizedString(@"Line", nil);
  665. } else if (type == CAnnotationTypeSignDot) {
  666. weakSelf.titleLabel.stringValue = NSLocalizedString(@"Dot", nil);
  667. }
  668. if (weakSelf.annoTypeDidChange != nil) {
  669. weakSelf.annoTypeDidChange(weakSelf.annotations.firstObject);
  670. }
  671. };
  672. } else if (annotationMode == CAnnotationTypeSignText ||
  673. annotationMode == CAnnotationTypeSignDate) {
  674. if(_annotations.count > 1) {
  675. annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  676. }
  677. KMSelfSignAnnotationFreeTextSubType subType = KMSelfSignAnnotationFreeTextSubTypeNone;
  678. if (annotationModel.annotationType == CAnnotationTypeSignConfig) {
  679. subType = KMSelfSignAnnotationFreeTextSubTypeProfile;
  680. } else if (annotationModel.annotationType == CAnnotationTypeSignText) {
  681. subType = KMSelfSignAnnotationFreeTextSubTypeFreeText;
  682. } else if (annotationModel.annotationType == CAnnotationTypeSignDate) {
  683. subType = KMSelfSignAnnotationFreeTextSubTypeDate;
  684. }
  685. KMGeneralAnnotationViewController *vc = [[KMGeneralAnnotationViewController alloc] init];
  686. vc.subType = subType;
  687. vc.pdfView = self.pdfView;
  688. vc.annotationModel = annotationModel;
  689. self.propertiesBox.contentView = vc.view;
  690. self.contentViewController = vc;
  691. } else if (annotationMode == CAnnotationTypeStamp) {
  692. KMAnnotationStampViewController *vc = [[KMAnnotationStampViewController alloc] init];
  693. vc.pdfView = self.pdfView;
  694. vc.annotationModel = annotationModel;
  695. self.propertiesBox.contentView = vc.view;
  696. self.contentViewController = vc;
  697. } else if (annotationMode == CAnnotationTypeSignSignature) {
  698. KMSignatureAnnotationViewController *vc = [[KMSignatureAnnotationViewController alloc] init];
  699. self.titleViewHeightConstraint.constant = 0;
  700. vc.annotationModel = annotationModel;
  701. vc.pdfView = self.pdfView;
  702. vc.kEventTag = self.kEventTag;
  703. self.kEventTag = 0;
  704. self.propertiesBox.contentView = vc.view;
  705. self.contentViewController = vc;
  706. }
  707. }
  708. - (void)setMeasureMode:(CAnnotationType)annotationMode {
  709. _annotationMode = annotationMode;
  710. if (self.contentViewController) {
  711. [self.contentViewController.view removeFromSuperview];
  712. self.contentViewController = nil;
  713. }
  714. NSString *title = @"";
  715. if (annotationMode == CAnnotationTypeSquare)
  716. title = NSLocalizedString(@"Rectangle", @"Description for export");
  717. else if (annotationMode == CAnnotationTypeLine)
  718. title = NSLocalizedString(@"Line", @"Description for export");
  719. else if (annotationMode == CAnnotationTypePolyLine)
  720. title = NSLocalizedString(@"Multilines", nil);
  721. else if (annotationMode == CAnnotationTypePolyGon)
  722. title = NSLocalizedString(@"Polygon", nil);
  723. else
  724. title = @"";
  725. if(_annotations.count > 1) {
  726. title = NSLocalizedString(@"Properties", nil);
  727. }
  728. self.titleLabel.stringValue = title;
  729. self.titleViewHeightConstraint.constant = 40;
  730. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithAnnotationType:annotationMode];
  731. KMMeasureSideVC *vc = [[KMMeasureSideVC alloc] init];
  732. vc.pdfView = self.pdfView;
  733. vc.annotationModel = annotationModel;
  734. self.propertiesBox.contentView = vc.view;
  735. self.contentViewController = vc;
  736. }
  737. - (void)setIsEmptyAnnotation:(BOOL)isEmptyAnnotation
  738. {
  739. _isEmptyAnnotation = isEmptyAnnotation;
  740. if (isEmptyAnnotation) {
  741. self.titleLabel.hidden = YES;
  742. self.emptyView.hidden = NO;
  743. } else {
  744. self.titleLabel.hidden = NO;
  745. self.emptyView.hidden = YES;
  746. }
  747. }
  748. - (void)setOpenPropertiesType:(KMOpenPropertiesType)openPropertiesType {
  749. self.contentViewController = nil;
  750. self.titleLabel.stringValue = @"";
  751. self.titleViewHeightConstraint.constant = 0;
  752. _openPropertiesType = openPropertiesType;
  753. if (openPropertiesType == KMOpenPropertiesType_PageDisplay) {
  754. if (self.contentViewController) {
  755. [self.contentViewController.view removeFromSuperview];
  756. self.contentViewController = nil;
  757. }
  758. self.titleLabel.stringValue = NSLocalizedString(@"View Settings", nil);
  759. KMPageDisplayPropertiesViewController *vc = [[KMPageDisplayPropertiesViewController alloc] init];
  760. vc.mainController = self.mainController;
  761. vc.pdfView = self.pdfView;
  762. __weak typeof(self) weakSelf = self;
  763. vc.readerModeBlock = ^(BOOL isReaderMode) {
  764. if (weakSelf.pageDisplayReaderMode) {
  765. weakSelf.pageDisplayReaderMode(isReaderMode);
  766. }
  767. };
  768. self.propertiesBox.contentView = vc.view;
  769. self.contentViewController = vc;
  770. } else if (openPropertiesType == KMOpenPropertiesType_Stamp) {
  771. self.titleLabel.stringValue = NSLocalizedString(@"Stamp", nil);
  772. } else if (openPropertiesType == KMOpenPropertiesType_Link) {
  773. self.titleLabel.stringValue = NSLocalizedString(@"Link", nil);
  774. KMAnnotationLinkViewController *vc = [[KMAnnotationLinkViewController alloc] init];
  775. self.propertiesBox.contentView = vc.view;
  776. } else if (openPropertiesType == KMOpenPropertiesType_ListBox ||
  777. openPropertiesType == KMOpenPropertiesType_ComboBox ||
  778. openPropertiesType == KMOpenPropertiesType_Button) {
  779. } else if (openPropertiesType == KMOpenPropertiesType_FormSignatureClick) {
  780. self.contentViewController = nil;
  781. self.titleLabel.stringValue = @"";
  782. self.titleViewHeightConstraint.constant = 0;
  783. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  784. KMSignatureAnnotationViewController *vc = [[KMSignatureAnnotationViewController alloc] init];
  785. vc.isClickSignatureList = YES;
  786. vc.annotationModel = annotationModel;
  787. vc.pdfView = self.pdfView;
  788. self.propertiesBox.contentView = vc.view;
  789. self.contentViewController = vc;
  790. }
  791. }
  792. - (void)setIsContinuousAddStamp:(BOOL)isContinuousAddStamp {
  793. if (_annotations.count <= 0) {
  794. return;
  795. }
  796. CPDFAnnotation *annotation = _annotations.firstObject;
  797. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  798. if ([annotation isKindOfClass:[CPDFStampAnnotation class]]) {
  799. if (isContinuousAddStamp) {
  800. self.titleViewHeightConstraint.constant = 0;
  801. }
  802. } else if ([annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
  803. if (isContinuousAddStamp) {
  804. KMSignatureAnnotationViewController *vc = [[KMSignatureAnnotationViewController alloc] init];
  805. self.titleViewHeightConstraint.constant = 0;
  806. vc.annotationModel = annotationModel;
  807. vc.pdfView = self.pdfView;
  808. self.propertiesBox.contentView = vc.view;
  809. self.contentViewController = vc;
  810. }
  811. }
  812. }
  813. + (CGFloat)heightWithAnnotation:(CPDFAnnotation *)annotation {
  814. if (!annotation) {
  815. return 0;
  816. }
  817. if ([annotation isKindOfClass:[CPDFLinkAnnotation class]] ||
  818. [annotation isKindOfClass:[CPDFMovieAnnotation class]] ||
  819. [annotation isKindOfClass:[CPDFSoundAnnotation class]]) {
  820. return 0;
  821. } else if ([annotation isKindOfClass:[CSelfSignAnnotation class]]) {
  822. return 279;
  823. } else if ([annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
  824. return 279;
  825. } else if ([annotation isKindOfClass:[CPDFListStampAnnotation class]]) {
  826. return 279;
  827. } else if ([annotation isKindOfClass:[CPDFStampAnnotation class]]) {
  828. return 0;
  829. } else if ([annotation isKindOfClass:[CPDFSignatureWidgetAnnotation class]]) {
  830. return 279;
  831. } else {
  832. return 279;
  833. }
  834. }
  835. + (CGFloat)heightWithAnnotationMode:(CAnnotationType)annotationMode {
  836. if (CAnnotationTypeSignature == annotationMode ||
  837. CAnnotationTypeUnkown == annotationMode) {
  838. return 0;
  839. }
  840. return 279;
  841. }
  842. #pragma mark - Private Method
  843. - (CGRect)viewControllerRect {
  844. CGFloat viewFloat = 0;
  845. if (_buttonView == nil || self.gradientView == nil) {
  846. return CGRectMake(0, 0, NSWidth(self.view.frame), viewFloat);
  847. }
  848. if (_buttonView.hidden) {
  849. viewFloat = NSHeight(self.view.frame) - NSHeight(self.gradientView.frame);
  850. } else {
  851. viewFloat = NSHeight(self.view.frame) - NSHeight(self.gradientView.frame)-KMFromContentButtonHeightFloat;
  852. }
  853. return CGRectMake(0, 0, NSWidth(self.view.frame), viewFloat);
  854. }
  855. - (void)updateFormContentButtonUI:(NSButton *)button {
  856. self.clickBtn = button;
  857. switch (button.tag) {
  858. case 100:
  859. [_formGeneralButton setTitleColor:[KMAppearance KMColor_Layout_W0]];
  860. [_formAppearanceButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
  861. [_formOptionsButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
  862. if([KMAppearance isDarkMode]) {
  863. _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:34/255. green:122/255. blue:255/255. alpha:1.].CGColor;
  864. _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
  865. _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
  866. } else {
  867. _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:73/255. green:130/255. blue:230/255. alpha:1.].CGColor;
  868. _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
  869. _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
  870. }
  871. break;
  872. case 101:
  873. [_formGeneralButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
  874. [_formAppearanceButton setTitleColor:[KMAppearance KMColor_Layout_W0]];
  875. [_formOptionsButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
  876. if([KMAppearance isDarkMode]) {
  877. _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:34/255. green:122/255. blue:255/255. alpha:1.].CGColor;
  878. _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
  879. _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
  880. } else {
  881. _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:73/255. green:130/255. blue:230/255. alpha:1.].CGColor;
  882. _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
  883. _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
  884. }
  885. break;
  886. case 102:
  887. [_formGeneralButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
  888. [_formAppearanceButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
  889. [_formOptionsButton setTitleColor:[KMAppearance KMColor_Layout_W0]];
  890. if([KMAppearance isDarkMode]) {
  891. _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:34/255. green:122/255. blue:255/255. alpha:1.].CGColor;
  892. _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
  893. _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
  894. } else {
  895. _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:73/255. green:130/255. blue:230/255. alpha:1.].CGColor;
  896. _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
  897. _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
  898. }
  899. break;
  900. default:
  901. break;
  902. }
  903. }
  904. #pragma mark - NSButton Action
  905. - (IBAction)fromContentButtonAction:(NSButton *)sender {
  906. [self updateFormContentButtonUI:sender];
  907. self.tipsView.hidden = YES;
  908. switch (sender.tag) {
  909. case 100:
  910. {
  911. self.lastLineImageView.hidden = NO;
  912. self.oneLineImageView.hidden = YES;
  913. [self formGeneralProperties];
  914. }
  915. break;
  916. case 101:
  917. {
  918. self.lastLineImageView.hidden = YES;
  919. self.oneLineImageView.hidden = YES;
  920. [self formAppearanceProperties];
  921. }
  922. break;
  923. case 102:
  924. {
  925. self.lastLineImageView.hidden = YES;
  926. self.oneLineImageView.hidden = NO;
  927. [self formOptionProperties];
  928. }
  929. break;
  930. default:
  931. break;
  932. }
  933. }
  934. - (void)formGeneralProperties {
  935. CPDFAnnotation *annotation = _annotations.firstObject;
  936. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]] ||
  937. [annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]] ||
  938. [annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
  939. if ([self.contentViewController isKindOfClass:[KMAnnotationGeneralViewController class]]) {
  940. return;
  941. }
  942. [self.contentViewController.view removeFromSuperview];
  943. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  944. KMAnnotationGeneralViewController *vc = [[KMAnnotationGeneralViewController alloc] init];
  945. vc.pdfview = self.pdfView;
  946. vc.annotationModel = annotationModel;
  947. vc.view.frame = [self viewControllerRect];
  948. [self.view addSubview:vc.view];
  949. self.contentViewController = vc;
  950. }
  951. }
  952. - (void)formAppearanceProperties {
  953. CPDFAnnotation *annotation = _annotations.firstObject;
  954. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  955. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]) {
  956. if ([self.contentViewController isKindOfClass:[KMAnnotationFromViewController class]]) {
  957. return;
  958. }
  959. [self.contentViewController.view removeFromSuperview];
  960. KMAnnotationFromViewController *vc = [[KMAnnotationFromViewController alloc] init];
  961. vc.pdfView = self.pdfView;
  962. vc.annotationModel = annotationModel;
  963. vc.view.frame = [self viewControllerRect];
  964. [self.view addSubview:vc.view];
  965. self.contentViewController = vc;
  966. } else if ([annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
  967. CPDFButtonWidgetAnnotation *newAnnotation = (CPDFButtonWidgetAnnotation *)annotation;
  968. if (newAnnotation.controlType == 1 || newAnnotation.controlType == 2) {
  969. if ([self.contentViewController isKindOfClass:[KMAnnotationButtonWidgetAppearanceViewController class]]) {
  970. return;
  971. }
  972. [self.contentViewController.view removeFromSuperview];
  973. KMAnnotationButtonWidgetAppearanceViewController *vc = [[KMAnnotationButtonWidgetAppearanceViewController alloc] init];
  974. vc.pdfView = self.pdfView;
  975. vc.annotationModel = annotationModel;
  976. vc.view.frame = [self viewControllerRect];
  977. [self.view addSubview:vc.view];
  978. self.contentViewController = vc;
  979. } else if (newAnnotation.controlType == 0) {
  980. if ([self.contentViewController isKindOfClass:[KMAnnotationChoiceWidgetAppearanceViewController class]]) {
  981. return;
  982. }
  983. [self.contentViewController.view removeFromSuperview];
  984. KMAnnotationChoiceWidgetAppearanceViewController *vc = [[KMAnnotationChoiceWidgetAppearanceViewController alloc] init];
  985. vc.pdfView = self.pdfView;
  986. vc.annotationModel = annotationModel;
  987. vc.view.frame = [self viewControllerRect];
  988. [self.view addSubview:vc.view];
  989. self.contentViewController = vc;
  990. }
  991. } else if ([annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
  992. if ([self.contentViewController isKindOfClass:[KMAnnotationChoiceWidgetAppearanceViewController class]]) {
  993. return;
  994. }
  995. [self.contentViewController.view removeFromSuperview];
  996. KMAnnotationChoiceWidgetAppearanceViewController *vc = [[KMAnnotationChoiceWidgetAppearanceViewController alloc] init];
  997. vc.pdfView = self.pdfView;
  998. vc.annotationModel = annotationModel;
  999. vc.view.frame = [self viewControllerRect];
  1000. [self.view addSubview:vc.view];
  1001. self.contentViewController = vc;
  1002. }
  1003. }
  1004. - (void)formOptionProperties {
  1005. CPDFAnnotation *annotation = _annotations.firstObject;
  1006. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  1007. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]) {
  1008. if ([self.contentViewController isKindOfClass:[KMAnnotationTextWidgetOptionsViewController class]]) {
  1009. return;
  1010. }
  1011. [self.contentViewController.view removeFromSuperview];
  1012. KMAnnotationTextWidgetOptionsViewController *vc = [[KMAnnotationTextWidgetOptionsViewController alloc] init];
  1013. vc.pdfView = self.pdfView;
  1014. vc.annotationModel = annotationModel;
  1015. vc.view.frame = [self viewControllerRect];
  1016. [self.view addSubview:vc.view];
  1017. self.contentViewController = vc;
  1018. } else if ([annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
  1019. CPDFButtonWidgetAnnotation *newAnnotation = (CPDFButtonWidgetAnnotation *)annotation;
  1020. if (newAnnotation.controlType == CPDFWidgetRadioButtonControl || newAnnotation.controlType == CPDFWidgetCheckBoxControl) {
  1021. if ([self.contentViewController isKindOfClass:[KMAnnotationButtonWidgetOptionsViewController class]]) {
  1022. return;
  1023. }
  1024. [self.contentViewController.view removeFromSuperview];
  1025. if (newAnnotation.controlType == CPDFWidgetRadioButtonControl) {
  1026. self.tipsView.hidden = NO;
  1027. 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)];;
  1028. } else {
  1029. self.tipsView.hidden = YES;
  1030. }
  1031. KMAnnotationButtonWidgetOptionsViewController *vc = [[KMAnnotationButtonWidgetOptionsViewController alloc] init];
  1032. vc.pdfView = self.pdfView;
  1033. vc.annotationModel = annotationModel;
  1034. vc.view.frame = [self viewControllerRect];
  1035. [self.view addSubview:vc.view];
  1036. self.contentViewController = vc;
  1037. } else if (newAnnotation.controlType == CPDFWidgetPushButtonControl) {
  1038. if ([self.contentViewController isKindOfClass:[KMAnnotationButtonOptionsViewController class]]) {
  1039. return;
  1040. }
  1041. [self.contentViewController.view removeFromSuperview];
  1042. KMAnnotationButtonOptionsViewController *vc = [[KMAnnotationButtonOptionsViewController alloc] init];
  1043. vc.pdfView = self.pdfView;
  1044. vc.annotationModel = annotationModel;
  1045. vc.view.frame = [self viewControllerRect];
  1046. [self.view addSubview:vc.view];
  1047. self.contentViewController = vc;
  1048. }
  1049. } else if ([annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
  1050. if ([self.contentViewController isKindOfClass:[KMAnnotationChoiceWidgetOptionsViewController class]]) {
  1051. return;
  1052. }
  1053. [self.contentViewController.view removeFromSuperview];
  1054. self.tipsView.hidden = YES;
  1055. self.tipsLabel.stringValue = [NSString stringWithFormat:@" %@", NSLocalizedString(@"Select an item in the list to make it the default choice.", nil)];;
  1056. KMAnnotationChoiceWidgetOptionsViewController *vc = [[KMAnnotationChoiceWidgetOptionsViewController alloc] init];
  1057. vc.pdfView = self.pdfView;
  1058. vc.annotationModel = annotationModel;
  1059. vc.view.frame = [self viewControllerRect];
  1060. [self.view addSubview:vc.view];
  1061. self.contentViewController = vc;
  1062. }
  1063. }
  1064. @end