KMAnnotationPropertiesViewController.m 46 KB

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