KMAnnotationPropertiesViewController.m 48 KB

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