KMAnnotationPropertiesViewController.m 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  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.hidden) {
  728. viewFloat = NSHeight(self.view.frame) - NSHeight(self.gradientView.frame);
  729. } else {
  730. viewFloat = NSHeight(self.view.frame) - NSHeight(self.gradientView.frame)-KMFromContentButtonHeightFloat;
  731. }
  732. return CGRectMake(0, 0, NSWidth(self.view.frame), viewFloat);
  733. }
  734. - (void)updateFormContentButtonUI:(NSButton *)button {
  735. self.clickBtn = button;
  736. switch (button.tag) {
  737. case 100:
  738. [_formGeneralButton setTitleColor:[KMAppearance KMColor_Layout_W0]];
  739. [_formAppearanceButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
  740. [_formOptionsButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
  741. if([KMAppearance isDarkMode]) {
  742. _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:34/255. green:122/255. blue:255/255. alpha:1.].CGColor;
  743. _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
  744. _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
  745. } else {
  746. _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:73/255. green:130/255. blue:230/255. alpha:1.].CGColor;
  747. _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
  748. _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
  749. }
  750. break;
  751. case 101:
  752. [_formGeneralButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
  753. [_formAppearanceButton setTitleColor:[KMAppearance KMColor_Layout_W0]];
  754. [_formOptionsButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
  755. if([KMAppearance isDarkMode]) {
  756. _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:34/255. green:122/255. blue:255/255. alpha:1.].CGColor;
  757. _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
  758. _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
  759. } else {
  760. _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:73/255. green:130/255. blue:230/255. alpha:1.].CGColor;
  761. _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
  762. _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
  763. }
  764. break;
  765. case 102:
  766. [_formGeneralButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
  767. [_formAppearanceButton setTitleColor:[KMAppearance KMColor_Layout_H1]];
  768. [_formOptionsButton setTitleColor:[KMAppearance KMColor_Layout_W0]];
  769. if([KMAppearance isDarkMode]) {
  770. _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:34/255. green:122/255. blue:255/255. alpha:1.].CGColor;
  771. _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
  772. _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:57/255. green:60/255. blue:62/255. alpha:1.].CGColor;
  773. } else {
  774. _formOptionsButton.layer.backgroundColor = [NSColor colorWithRed:73/255. green:130/255. blue:230/255. alpha:1.].CGColor;
  775. _formGeneralButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
  776. _formAppearanceButton.layer.backgroundColor = [NSColor colorWithRed:235/255. green:236/255. blue:240/255. alpha:1.].CGColor;
  777. }
  778. break;
  779. default:
  780. break;
  781. }
  782. }
  783. #pragma mark - NSButton Action
  784. - (IBAction)fromContentButtonAction:(NSButton *)sender {
  785. [self updateFormContentButtonUI:sender];
  786. self.tipsView.hidden = YES;
  787. switch (sender.tag) {
  788. case 100:
  789. {
  790. self.lastLineImageView.hidden = NO;
  791. self.oneLineImageView.hidden = YES;
  792. [self formGeneralProperties];
  793. }
  794. break;
  795. case 101:
  796. {
  797. self.lastLineImageView.hidden = YES;
  798. self.oneLineImageView.hidden = YES;
  799. [self formAppearanceProperties];
  800. }
  801. break;
  802. case 102:
  803. {
  804. self.lastLineImageView.hidden = YES;
  805. self.oneLineImageView.hidden = NO;
  806. [self formOptionProperties];
  807. }
  808. break;
  809. default:
  810. break;
  811. }
  812. }
  813. - (void)formGeneralProperties {
  814. CPDFAnnotation *annotation = _annotations.firstObject;
  815. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]] ||
  816. [annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]] ||
  817. [annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
  818. if ([self.contentViewController isKindOfClass:[KMAnnotationGeneralViewController class]]) {
  819. return;
  820. }
  821. [self.contentViewController.view removeFromSuperview];
  822. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  823. KMAnnotationGeneralViewController *vc = [[KMAnnotationGeneralViewController alloc] init];
  824. vc.pdfview = self.pdfView;
  825. vc.annotationModel = annotationModel;
  826. vc.view.frame = [self viewControllerRect];
  827. [self.view addSubview:vc.view];
  828. self.contentViewController = vc;
  829. }
  830. }
  831. - (void)formAppearanceProperties {
  832. CPDFAnnotation *annotation = _annotations.firstObject;
  833. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  834. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]) {
  835. if ([self.contentViewController isKindOfClass:[KMAnnotationFromViewController class]]) {
  836. return;
  837. }
  838. [self.contentViewController.view removeFromSuperview];
  839. KMAnnotationFromViewController *vc = [[KMAnnotationFromViewController alloc] init];
  840. vc.pdfView = self.pdfView;
  841. vc.annotationModel = annotationModel;
  842. vc.view.frame = [self viewControllerRect];
  843. [self.view addSubview:vc.view];
  844. self.contentViewController = vc;
  845. } else if ([annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
  846. CPDFButtonWidgetAnnotation *newAnnotation = (CPDFButtonWidgetAnnotation *)annotation;
  847. if (newAnnotation.controlType == 1 || newAnnotation.controlType == 2) {
  848. if ([self.contentViewController isKindOfClass:[KMAnnotationButtonWidgetAppearanceViewController class]]) {
  849. return;
  850. }
  851. [self.contentViewController.view removeFromSuperview];
  852. KMAnnotationButtonWidgetAppearanceViewController *vc = [[KMAnnotationButtonWidgetAppearanceViewController alloc] init];
  853. vc.pdfView = self.pdfView;
  854. vc.annotationModel = annotationModel;
  855. vc.view.frame = [self viewControllerRect];
  856. [self.view addSubview:vc.view];
  857. self.contentViewController = vc;
  858. } else if (newAnnotation.controlType == 0) {
  859. if ([self.contentViewController isKindOfClass:[KMAnnotationChoiceWidgetAppearanceViewController class]]) {
  860. return;
  861. }
  862. [self.contentViewController.view removeFromSuperview];
  863. KMAnnotationChoiceWidgetAppearanceViewController *vc = [[KMAnnotationChoiceWidgetAppearanceViewController alloc] init];
  864. vc.pdfView = self.pdfView;
  865. vc.annotationModel = annotationModel;
  866. vc.view.frame = [self viewControllerRect];
  867. [self.view addSubview:vc.view];
  868. self.contentViewController = vc;
  869. }
  870. } else if ([annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
  871. if ([self.contentViewController isKindOfClass:[KMAnnotationChoiceWidgetAppearanceViewController class]]) {
  872. return;
  873. }
  874. [self.contentViewController.view removeFromSuperview];
  875. KMAnnotationChoiceWidgetAppearanceViewController *vc = [[KMAnnotationChoiceWidgetAppearanceViewController alloc] init];
  876. vc.pdfView = self.pdfView;
  877. vc.annotationModel = annotationModel;
  878. vc.view.frame = [self viewControllerRect];
  879. [self.view addSubview:vc.view];
  880. self.contentViewController = vc;
  881. }
  882. }
  883. - (void)formOptionProperties {
  884. CPDFAnnotation *annotation = _annotations.firstObject;
  885. CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithPDFAnnotations:_annotations];
  886. if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]) {
  887. if ([self.contentViewController isKindOfClass:[KMAnnotationTextWidgetOptionsViewController class]]) {
  888. return;
  889. }
  890. [self.contentViewController.view removeFromSuperview];
  891. KMAnnotationTextWidgetOptionsViewController *vc = [[KMAnnotationTextWidgetOptionsViewController alloc] init];
  892. vc.pdfView = self.pdfView;
  893. vc.annotationModel = annotationModel;
  894. vc.view.frame = [self viewControllerRect];
  895. [self.view addSubview:vc.view];
  896. self.contentViewController = vc;
  897. } else if ([annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
  898. CPDFButtonWidgetAnnotation *newAnnotation = (CPDFButtonWidgetAnnotation *)annotation;
  899. if (newAnnotation.controlType == CPDFWidgetRadioButtonControl || newAnnotation.controlType == CPDFWidgetCheckBoxControl) {
  900. if ([self.contentViewController isKindOfClass:[KMAnnotationButtonWidgetOptionsViewController class]]) {
  901. return;
  902. }
  903. [self.contentViewController.view removeFromSuperview];
  904. if (newAnnotation.controlType == CPDFWidgetRadioButtonControl) {
  905. self.tipsView.hidden = NO;
  906. 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)];;
  907. } else {
  908. self.tipsView.hidden = YES;
  909. }
  910. KMAnnotationButtonWidgetOptionsViewController *vc = [[KMAnnotationButtonWidgetOptionsViewController alloc] init];
  911. vc.pdfView = self.pdfView;
  912. vc.annotationModel = annotationModel;
  913. vc.view.frame = [self viewControllerRect];
  914. [self.view addSubview:vc.view];
  915. self.contentViewController = vc;
  916. } else if (newAnnotation.controlType == CPDFWidgetPushButtonControl) {
  917. if ([self.contentViewController isKindOfClass:[KMAnnotationButtonOptionsViewController class]]) {
  918. return;
  919. }
  920. [self.contentViewController.view removeFromSuperview];
  921. KMAnnotationButtonOptionsViewController *vc = [[KMAnnotationButtonOptionsViewController alloc] init];
  922. vc.pdfView = self.pdfView;
  923. vc.annotationModel = annotationModel;
  924. vc.view.frame = [self viewControllerRect];
  925. [self.view addSubview:vc.view];
  926. self.contentViewController = vc;
  927. }
  928. } else if ([annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
  929. if ([self.contentViewController isKindOfClass:[KMAnnotationChoiceWidgetOptionsViewController class]]) {
  930. return;
  931. }
  932. [self.contentViewController.view removeFromSuperview];
  933. self.tipsView.hidden = YES;
  934. self.tipsLabel.stringValue = [NSString stringWithFormat:@" %@", NSLocalizedString(@"Select an item in the list to make it the default choice.", nil)];;
  935. KMAnnotationChoiceWidgetOptionsViewController *vc = [[KMAnnotationChoiceWidgetOptionsViewController alloc] init];
  936. vc.pdfView = self.pdfView;
  937. vc.annotationModel = annotationModel;
  938. vc.view.frame = [self viewControllerRect];
  939. [self.view addSubview:vc.view];
  940. self.contentViewController = vc;
  941. }
  942. }
  943. @end