KMAnnotationPropertiesViewController.m 46 KB

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