KMAnnotationPropertiesViewController.m 50 KB

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