123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303 |
- //
- // KMPDFMergeFileNameTabelViewCell.m
- // PDF Master
- //
- // Created by tangchao on 2023/2/23.
- //
- #import "KMPDFMergeFileNameTabelViewCell.h"
- #if VERSION_DMG
- #import <PDF_Master-Swift.h>
- #else
- #import <PDF_Master-Swift.h>
- #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 ()<KMSelectPopButtonDelegate>
- @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
|