// // KMPDFMergeFileNameTabelViewCell.m // PDF Master // // Created by tangchao on 2023/2/23. // #import "KMPDFMergeFileNameTabelViewCell.h" #if VERSION_DMG #import #else #import #endif @interface KMPDFMergeFileNameTabelViewCell () @property (nonatomic, strong) NSTextField *numberLabel; @property (nonatomic, strong) NSImageView *iconImageView; @property (nonatomic, strong) NSTextField *fileNameLabel; @property (nonatomic, strong) NSTextField *pageNumberLabel; @end @implementation KMPDFMergeFileNameTabelViewCell - (instancetype)initWithFrame:(NSRect)frameRect { if (self = [super initWithFrame:frameRect]) { [self addSubview:self.numberLabel]; [self addSubview:self.iconImageView]; [self addSubview:self.fileNameLabel]; [self addSubview:self.pageNumberLabel]; } return self; } - (BOOL)isFlipped { return YES; } - (void)layout { [super layout]; CGFloat width = NSWidth(self.bounds); CGFloat height = NSHeight(self.bounds); CGFloat labelH = 22; self.numberLabel.frame = NSMakeRect(16, (height-labelH)*0.5, 30+16, labelH); CGFloat iconSize = 60; self.iconImageView.frame = NSMakeRect(NSMaxX(self.numberLabel.frame)+6, (height-iconSize)*0.5, iconSize, iconSize); CGFloat fileNameX = NSMaxX(self.iconImageView.frame)+8; self.fileNameLabel.frame = NSMakeRect(fileNameX, 13, width-fileNameX, labelH); self.pageNumberLabel.frame = NSMakeRect(fileNameX, NSMaxY(self.fileNameLabel.frame)+8, width-fileNameX, labelH); } #pragma mark - Getting - (NSTextField *)numberLabel { if (!_numberLabel) { _numberLabel = [NSTextField labelWithString:@""]; _numberLabel.textColor = [NSColor colorWithRed:37/255.f green:38/255.f blue:41/255.f alpha:1.f]; _numberLabel.font = [NSFont fontWithName:@"SFProText-Regular" size:14]; _numberLabel.alignment = NSTextAlignmentCenter; _numberLabel.lineBreakMode = NSLineBreakByTruncatingTail; } return _numberLabel; } - (NSImageView *)iconImageView { if (!_iconImageView) { _iconImageView = [[NSImageView alloc] init]; } return _iconImageView; } - (NSTextField *)fileNameLabel { if (!_fileNameLabel) { _fileNameLabel = [NSTextField labelWithString:@""]; _fileNameLabel.textColor = [NSColor colorWithRed:37/255.f green:38/255.f blue:41/255.f alpha:1.f]; _fileNameLabel.font = [NSFont fontWithName:@"SFProText-Regular" size:14]; _fileNameLabel.lineBreakMode = NSLineBreakByTruncatingTail; } return _fileNameLabel; } - (NSTextField *)pageNumberLabel { if (!_pageNumberLabel) { _pageNumberLabel = [NSTextField labelWithString:@""]; _pageNumberLabel.textColor = [NSColor colorWithRed:148/255.f green:152/255.f blue:156/255.f alpha:1.f]; _pageNumberLabel.font = [NSFont fontWithName:@"SFProText-Regular" size:14]; } return _pageNumberLabel; } @end @interface KMPDFMergePageRangeTabelViewCell () @property (nonatomic, strong) KMMergeSelect *comboBox; @end @implementation KMPDFMergePageRangeTabelViewCell - (instancetype)initWithFrame:(NSRect)frameRect { if (self = [super initWithFrame:frameRect]) { [self addSubview:self.comboBox.view]; [self.comboBox removeAllItems]; [self.comboBox addItemsWithObjectValues:@[NSLocalizedString(@"All Pages", nil),NSLocalizedString(@"Odd Pages", nil),NSLocalizedString(@"Even Pages", nil),NSLocalizedString(@"Customized", nil)]]; self.comboBox.stringValue = NSLocalizedString(@"All Pages", nil); self.comboBox.editable = false; self.comboBox.delete = self; self.comboBox.placeholderString = NSLocalizedString(@"eg .1,3-5,10", nil); } return self; } - (BOOL)isFlipped { return YES; } - (void)updatePageRange:(KMPDFSelectPageStringType)pageRange pageStrings:(nonnull NSString *)pageStrings { [self updatePageRange:pageRange pageStrings:pageStrings isFirstResponser:YES]; } - (void)updatePageRange:(KMPDFSelectPageStringType)pageRange pageStrings:(NSString *)pageStrings isFirstResponser:(BOOL)isFirstResponser { if (pageRange == KMPDFSeleectPageType_AllPages) { self.comboBox.stringValue = NSLocalizedString(@"All Pages", nil); self.comboBox.editable = false; self.comboBox.alert = NO; } else if (pageRange == KMPDFSeleectPageType_OnlyOdd) { self.comboBox.stringValue = NSLocalizedString(@"Odd Pages", nil); self.comboBox.editable = false; self.comboBox.alert = NO; } else if (pageRange == KMPDFSeleectPageType_OnlyEven) { self.comboBox.stringValue = NSLocalizedString(@"Even Pages", nil); self.comboBox.editable = false; self.comboBox.alert = NO; } else { self.comboBox.stringValue = pageStrings; self.comboBox.editable = YES; if ([pageStrings isEqual: @""]) { self.comboBox.alert = YES; } else { self.comboBox.alert = NO; } if (isFirstResponser || [pageStrings isEqual: @""]) { if (![self.window.firstResponder isEqual:self.comboBox.textField]) { if ([NSThread isMainThread]) { [self.window makeFirstResponder:self.comboBox.textField]; } else { dispatch_async(dispatch_get_main_queue(), ^{ [self.window makeFirstResponder:self.comboBox.textField]; }); } } } } } - (void)updateRageRangeState:(NSInteger)state { if (state == 9) { self.comboBox.state = KMDesignTokenStateError_def; } else if (state == 10) { self.comboBox.state = KMDesignTokenStateError_focus; } } - (void)layout { [super layout]; CGFloat width = NSWidth(self.bounds); CGFloat height = NSHeight(self.bounds); CGFloat comboBoxH = 26; self.comboBox.view.frame = NSMakeRect(10, (height-comboBoxH)*0.5, width-10, comboBoxH); } #pragma mark - KMSelectPopButtonDelegate - (void)km_comboBoxSelectionDidChange:(KMDesignSelect *)obj { if (self.callback) { NSInteger index = obj.indexOfSelectedItem; if (index < 0) { index = 0; } if (index == self.comboBox.numberOfItems-1) { self.comboBox.editable = true; dispatch_async(dispatch_get_main_queue(), ^{ self.comboBox.stringValue = @""; }); [self.window makeFirstResponder:self.comboBox.textField]; } else { self.comboBox.editable = false; self.comboBox.alert = false; } self.callback(index); } } - (void)km_controlTextDidChange:(KMDesignSelect *)obj { if (self.textDidChange) { self.textDidChange(obj.stringValue); } } - (void)km_controlTextDidEndEditing:(KMDesignSelect *)obj { if (self.textDidEndEdit) { self.textDidEndEdit(obj.stringValue, self); } } - (void)km_SelectPopoverWillShow:(KMDesignSelect *)obj { if ([self.comboBox isEqual:obj]) { NSMutableArray *disableItems = [NSMutableArray array]; if (self.pageCount <= 1) { [disableItems addObject:NSLocalizedString(@"Even Pages", nil)]; } self.comboBox.disItems = disableItems.copy; } } #pragma mark - Getting - (KMDesignSelect *)comboBox { if (!_comboBox) { _comboBox = [[KMMergeSelect alloc] initWithType:1]; } return _comboBox; } @end @interface KMPDFMergeSizeTabelViewCell () @property (nonatomic, strong) NSTextField *label; @property (nonatomic, strong) NSButton *button; @end @implementation KMPDFMergeSizeTabelViewCell - (instancetype)initWithFrame:(NSRect)frameRect { if (self = [super initWithFrame:frameRect]) { [self addSubview:self.label]; [self addSubview:self.button]; self.button.target = self; self.button.action = @selector(buttonAction); } return self; } - (BOOL)isFlipped { return YES; } - (void)layout { [super layout]; CGFloat height = NSHeight(self.bounds); CGFloat labelH = 22; self.label.frame = NSMakeRect(16, (height-labelH)*0.5, 70, labelH); CGFloat buttonSize = 20; self.button.frame = NSMakeRect(NSMaxX(self.label.frame)+5, (height-buttonSize)*0.5, buttonSize, buttonSize); } - (void)buttonAction { if (self.callback) { self.callback(); } } #pragma mark - Getting - (NSTextField *)label { if (!_label) { _label = [NSTextField labelWithString:@""]; _label.textColor = [NSColor colorWithRed:148/255.f green:152/255.f blue:156/255.f alpha:1.f]; _label.font = [NSFont fontWithName:@"SFProText-Regular" size:14]; } return _label; } - (NSButton *)button { if (!_button) { _button = [[NSButton alloc] init]; _button.bordered = false; _button.image = [NSImage imageNamed:@"KMImageNameSecureClearIcon"]; } return _button; } @end