KMAnnotationPropertiesViewController.m 52 KB

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