KMAnnotationPropertiesViewController.m 49 KB

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