KMAnnotationPropertiesViewController.m 56 KB

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