KMAnnotationPropertiesViewController.m 56 KB

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