KMAnnotationPropertiesViewController.m 53 KB

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