KMAnnotationPropertiesViewController.m 48 KB

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