KMAnnotationPropertiesViewController.m 50 KB

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