|
@@ -7,13 +7,759 @@
|
|
|
|
|
|
import Cocoa
|
|
|
|
|
|
+class KMLineStyleButtonCell: NSButtonCell {
|
|
|
+ override func highlight(_ flag: Bool, withFrame cellFrame: NSRect, in controlView: NSView) {
|
|
|
+ if flag {
|
|
|
+ print("111")
|
|
|
+ controlView.layer?.backgroundColor = KMAppearance.Status.selColor().cgColor
|
|
|
+ } else {
|
|
|
+ print("111")
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
class KMAnnotationTableViewController: NSViewController {
|
|
|
var annotation: KMTableAnnotation?
|
|
|
weak var pdfView: CPDFListView?
|
|
|
+
|
|
|
+ var point: NSPoint = NSPoint.zero
|
|
|
+
|
|
|
+ @IBOutlet weak var styleLabel: NSTextField!
|
|
|
+ @IBOutlet weak var styleBox0: KMBox!
|
|
|
+ @IBOutlet weak var styleBox1: KMBox!
|
|
|
+ @IBOutlet weak var styleBox2: KMBox!
|
|
|
+ @IBOutlet weak var styleBox3: KMBox!
|
|
|
+ @IBOutlet weak var styleBox4: KMBox!
|
|
|
+ @IBOutlet weak var styleBox5: KMBox!
|
|
|
+
|
|
|
+ @IBOutlet weak var cellSizeLabel: NSTextField!
|
|
|
+ @IBOutlet weak var cellWidthLabel: NSTextField!
|
|
|
+ @IBOutlet weak var cellHeightLabel: NSTextField!
|
|
|
+ @IBOutlet weak var cellWidthTextField: NSTextField!
|
|
|
+ @IBOutlet weak var cellHeightTextField: NSTextField!
|
|
|
+ @IBOutlet weak var cellWidthStepper: NSStepper!
|
|
|
+ @IBOutlet weak var cellHeightStepper: NSStepper!
|
|
|
+
|
|
|
+ @IBOutlet weak var titleEndTableLabel: NSTextField!
|
|
|
+ @IBOutlet weak var sidebarPopUpButton: KMPopUpButton!
|
|
|
+ @IBOutlet weak var headerPopUpButton: KMPopUpButton!
|
|
|
+ @IBOutlet weak var footerPopUpButton: KMPopUpButton!
|
|
|
+
|
|
|
+ @IBOutlet weak var bordersAndColorsLabel: NSTextField!
|
|
|
+ @IBOutlet weak var backgroundColorLabel: NSTextField!
|
|
|
+ @IBOutlet weak var backgroudColorBox: KMBox!
|
|
|
+ @IBOutlet weak var backgrourdColorView: NSView!
|
|
|
+ @IBOutlet weak var borderColorLabel: NSTextField!
|
|
|
+ @IBOutlet weak var borderColorBox: KMBox!
|
|
|
+ @IBOutlet weak var borderColorView: NSView!
|
|
|
+ @IBOutlet weak var widthLabel: NSTextField!
|
|
|
+ @IBOutlet weak var widthSlider: NSSlider!
|
|
|
+ @IBOutlet weak var widthPopUpButton: KMPopUpButton!
|
|
|
+ @IBOutlet weak var lineStyleLabel: NSTextField!
|
|
|
+ @IBOutlet weak var lineStyleButton: KMButton!
|
|
|
+ @IBOutlet weak var dottedLineStyleButton: KMButton!
|
|
|
+ @IBOutlet weak var rightArrowStyleButton: KMButton!
|
|
|
+
|
|
|
+ @IBOutlet weak var alternateColorButton: NSButton!
|
|
|
+ @IBOutlet weak var alternateColorLabel: NSTextField!
|
|
|
+ @IBOutlet weak var alternateColorBox: KMBox!
|
|
|
+ @IBOutlet weak var alternateColorView: NSView!
|
|
|
+
|
|
|
+ var backgroudColorBoxIsEnabled: Bool = false
|
|
|
+ var notUpdateBackgroundColor: Bool = false
|
|
|
+ var lineStyleCount: Int = 0
|
|
|
+
|
|
|
+// override init() {
|
|
|
+// super.init()
|
|
|
+// NotificationCenter.default.addObserver(self, selector: #selector(PDFViewTableAnnotationDidChangeNotification(_:)), name: Notification.Name(KMPDFViewTableAnnotationDidChangeNotification), object: nil)
|
|
|
+// }
|
|
|
+
|
|
|
+ required init?(coder: NSCoder) {
|
|
|
+ fatalError("init(coder:) has not been implemented")
|
|
|
+ }
|
|
|
+
|
|
|
+ deinit {
|
|
|
+ NotificationCenter.default.removeObserver(self)
|
|
|
+ DistributedNotificationCenter.default().removeObserver(self)
|
|
|
+ }
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
super.viewDidLoad()
|
|
|
// Do view setup here.
|
|
|
+
|
|
|
+ self.styleLabel.stringValue = NSLocalizedString("Table Styles", comment: "")
|
|
|
+ self.styleLabel.textColor = KMAppearance.Layout.h0Color()
|
|
|
+ self.cellSizeLabel.stringValue = NSLocalizedString("Cell Size", comment: "")
|
|
|
+ self.cellSizeLabel.textColor = KMAppearance.Layout.h0Color()
|
|
|
+ self.cellWidthLabel.stringValue = "\(NSLocalizedString("Cell Width", comment: ""))(cm)"
|
|
|
+ self.cellWidthLabel.toolTip = "\(NSLocalizedString("Cell Width", comment: ""))(cm)"
|
|
|
+ self.cellWidthLabel.allowsExpansionToolTips = true
|
|
|
+ self.cellWidthLabel.textColor = KMAppearance.Layout.h1Color()
|
|
|
+ self.cellHeightLabel.stringValue = "\(NSLocalizedString("Cell Height", comment: ""))(cm)"
|
|
|
+ self.cellHeightLabel.toolTip = "\(NSLocalizedString("Cell Height", comment: ""))(cm)"
|
|
|
+ self.cellHeightLabel.allowsExpansionToolTips = true
|
|
|
+ self.cellHeightLabel.textColor = KMAppearance.Layout.h1Color()
|
|
|
+ self.titleEndTableLabel.stringValue = NSLocalizedString("Headers & Footers", comment: "")
|
|
|
+ self.titleEndTableLabel.textColor = KMAppearance.Layout.h0Color()
|
|
|
+ self.bordersAndColorsLabel.stringValue = NSLocalizedString("Borders & Colors", comment: "")
|
|
|
+ self.bordersAndColorsLabel.textColor = KMAppearance.Layout.h0Color()
|
|
|
+ self.backgroundColorLabel.stringValue = NSLocalizedString("Background Color", comment: "")
|
|
|
+ self.backgroundColorLabel.textColor = KMAppearance.Layout.h1Color()
|
|
|
+ self.borderColorLabel.stringValue = NSLocalizedString("Border Color", comment: "")
|
|
|
+ self.borderColorLabel.textColor = KMAppearance.Layout.h1Color()
|
|
|
+ self.widthLabel.stringValue = NSLocalizedString("Line Width", comment: "")
|
|
|
+ self.widthLabel.textColor = KMAppearance.Layout.h1Color()
|
|
|
+ self.lineStyleLabel.stringValue = NSLocalizedString("Line Style", comment: "")
|
|
|
+ self.lineStyleLabel.textColor = KMAppearance.Layout.h1Color()
|
|
|
+
|
|
|
+ self.alternateColorLabel.stringValue = NSLocalizedString("Alternate", comment: "")
|
|
|
+ self.alternateColorLabel.textColor = KMAppearance.Layout.h0Color()
|
|
|
+
|
|
|
+ let styleBoxArr: [KMBox] = [self.styleBox0, self.styleBox1, self.styleBox2, self.styleBox3, self.styleBox4, self.styleBox5]
|
|
|
+ for box in styleBoxArr {
|
|
|
+ box.moveCallback = { mouseEntered, mouseBox in
|
|
|
+ if mouseEntered {
|
|
|
+ mouseBox.fillColor = KMAppearance.Status.selColor()
|
|
|
+ } else {
|
|
|
+ mouseBox.fillColor = NSColor.clear
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ self.widthPopUpButton.removeAllItems()
|
|
|
+ self.widthPopUpButton.addItems(withTitles: ["0.1 pt","0.2 pt","0.3 pt","0.4 pt","0.5 pt","0.6 pt","0.7 pt","0.8 pt","0.9 pt","1.0 pt","1.1 pt","1.2 pt","1.3 pt","1.4 pt","1.5 pt","1.6 pt","1.7 pt","1.8 pt","1.9 pt","2.0 pt","2.1 pt","2.2 pt","2.3 pt","2.4 pt","2.5 pt","2.6 pt","2.7 pt","2.8 pt","2.9 pt","3.0 pt"])
|
|
|
+ self.widthPopUpButton.type = .arrowDown
|
|
|
+
|
|
|
+ self.backgroudColorBox.borderWidth = 1.0
|
|
|
+ self.backgroudColorBox.borderColor = KMAppearance.Interactive.s0Color()
|
|
|
+ self.backgroudColorBox.fillColor = KMAppearance.Layout.l1Color()
|
|
|
+ self.backgroudColorBox.cornerRadius = 1.0
|
|
|
+ self.backgroudColorBox.downCallback = {downEntered, mouseBox, event in
|
|
|
+ if downEntered {
|
|
|
+ if self.backgroudColorBoxIsEnabled {
|
|
|
+ NSColorPanel.shared.setTarget(self)
|
|
|
+ NSColorPanel.shared.setAction(#selector(self.backgroudColorPanelColorDidChange(_:)))
|
|
|
+ NSColorPanel.shared.orderFront(nil)
|
|
|
+ } else {
|
|
|
+ NSSound.beep()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self.backgrourdColorView.wantsLayer = true
|
|
|
+ self.borderColorView.wantsLayer = true
|
|
|
+ self.alternateColorView.wantsLayer = true
|
|
|
+ self.backgrourdColorView.layer?.backgroundColor = NSColor.white.cgColor
|
|
|
+ self.backgrourdColorView.layer?.borderWidth = 0.5
|
|
|
+ self.borderColorView.layer?.borderWidth = 0.5
|
|
|
+ self.alternateColorView.layer?.borderWidth = 0.5
|
|
|
+
|
|
|
+ self.backgrourdColorView.layer?.borderColor = KMAppearance.Interactive.s0Color().cgColor
|
|
|
+ self.borderColorView.layer?.borderColor = KMAppearance.Interactive.s0Color().cgColor
|
|
|
+ self.alternateColorView.layer?.borderColor = KMAppearance.Interactive.s0Color().cgColor
|
|
|
+ self.borderColorBox.borderWidth = 1.0
|
|
|
+ self.borderColorBox.borderColor = KMAppearance.Interactive.s0Color()
|
|
|
+ self.borderColorBox.fillColor = KMAppearance.Layout.l1Color()
|
|
|
+ self.borderColorBox.cornerRadius = 1.0
|
|
|
+ self.borderColorBox.downCallback = { downEntered, mouseBox, event in
|
|
|
+ if downEntered {
|
|
|
+ NSColorPanel.shared.setTarget(self)
|
|
|
+ NSColorPanel.shared.setAction(#selector(self.borderColorPanelColorDidChange(_:)))
|
|
|
+ NSColorPanel.shared.orderFront(nil)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self.alternateColorBox.borderWidth = 1.0
|
|
|
+ self.alternateColorBox.borderColor = KMAppearance.Interactive.s0Color()
|
|
|
+ self.alternateColorBox.fillColor = KMAppearance.Layout.l1Color()
|
|
|
+ self.alternateColorBox.cornerRadius = 1.0
|
|
|
+ self.alternateColorBox.downCallback = { downEntered, mouseBox, event in
|
|
|
+ if downEntered {
|
|
|
+ NSColorPanel.shared.setTarget(self)
|
|
|
+ NSColorPanel.shared.setAction(#selector(self.alternateColorPanelColorDidChange(_:)))
|
|
|
+ NSColorPanel.shared.orderFront(nil)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ self.lineStyleButton.image = self.borderStyleSolid(isSelect: false)
|
|
|
+ self.lineStyleButton.wantsLayer = true
|
|
|
+ self.dottedLineStyleButton.image = self.borderStyleDashed(isSelect: false)
|
|
|
+ self.dottedLineStyleButton.wantsLayer = true
|
|
|
+ self.rightArrowStyleButton.image = self.borderStyleDashed(isSelect: false)
|
|
|
+ self.rightArrowStyleButton.wantsLayer = true
|
|
|
+ let buttonArray: [KMButton] = [self.lineStyleButton, self.dottedLineStyleButton, self.rightArrowStyleButton]
|
|
|
+ for button in buttonArray {
|
|
|
+ button.layer?.borderColor = KMAppearance.Interactive.s0Color().cgColor
|
|
|
+ button.layer?.borderWidth = 1.0
|
|
|
+ button.layer?.cornerRadius = 1.0
|
|
|
+ if button.tag == self.lineStyleCount {
|
|
|
+ button.layer?.backgroundColor = KMAppearance.Status.selColor().cgColor
|
|
|
+ } else {
|
|
|
+ button.layer?.backgroundColor = KMAppearance.Layout.l1Color().cgColor
|
|
|
+ }
|
|
|
+ button.mouseMoveCallback = {[weak self] mouseEntered in
|
|
|
+ if button.tag == self?.lineStyleCount {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if mouseEntered {
|
|
|
+ button.layer?.backgroundColor = KMAppearance.Status.selColor().cgColor
|
|
|
+ button.layer?.borderWidth = 0.0
|
|
|
+ if button.tag == 0 {
|
|
|
+ self?.lineStyleButton.image = self?.borderStyleSolid(isSelect: true)
|
|
|
+ } else if button.tag == 1 {
|
|
|
+ self?.dottedLineStyleButton.image = self?.borderStyleDashed(isSelect: true)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ button.layer?.backgroundColor = KMAppearance.Layout.l1Color().cgColor
|
|
|
+ button.layer?.borderWidth = 1.0
|
|
|
+ if button.tag == 0 {
|
|
|
+ self?.lineStyleButton.image = self?.borderStyleSolid(isSelect: false)
|
|
|
+ } else {
|
|
|
+ self?.dottedLineStyleButton.image = self?.borderStyleDashed(isSelect: false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self.rightArrowStyleButton.isHidden = true
|
|
|
+
|
|
|
+ self.sidebarPopUpButton.buttonImage = NSImage(named: KMImageNameUXIconPropertybarTableTitleLeft)
|
|
|
+ self.sidebarPopUpButton.type = .table
|
|
|
+ self.headerPopUpButton.buttonImage = NSImage(named: KMImageNameUXIconPropertybarTableTitleAbove)
|
|
|
+ self.headerPopUpButton.type = .table;
|
|
|
+
|
|
|
+ self.footerPopUpButton.buttonImage = NSImage(named: KMImageNameUXIconPropertybarTableBottom)
|
|
|
+ self.headerPopUpButton.type = .table;
|
|
|
+
|
|
|
+ self.cellWidthTextField.backgroundColor = KMAppearance.Layout.l1Color()
|
|
|
+ self.cellHeightTextField.backgroundColor = KMAppearance.Layout.l1Color()
|
|
|
+
|
|
|
+ self.cellWidthTextField.wantsLayer = true
|
|
|
+ self.cellHeightTextField.wantsLayer = true
|
|
|
+ self.sidebarPopUpButton.wantsLayer = true
|
|
|
+ self.widthPopUpButton.wantsLayer = true
|
|
|
+ self.headerPopUpButton.wantsLayer = true
|
|
|
+ self.footerPopUpButton.wantsLayer = true
|
|
|
+
|
|
|
+ self.cellWidthTextField.layer!.borderWidth = 1.0
|
|
|
+ self.cellHeightTextField.layer?.borderWidth = 1.0
|
|
|
+ self.sidebarPopUpButton.layer!.borderWidth = 1.0
|
|
|
+ self.widthPopUpButton.layer!.borderWidth = 1.0
|
|
|
+ self.headerPopUpButton.layer!.borderWidth = 1.0
|
|
|
+ self.footerPopUpButton.layer!.borderWidth = 1.0
|
|
|
+
|
|
|
+ self.cellWidthTextField.layer?.cornerRadius = 1.0
|
|
|
+ self.cellHeightTextField.layer?.cornerRadius = 1.0
|
|
|
+ self.sidebarPopUpButton.layer?.cornerRadius = 1.0
|
|
|
+ self.widthPopUpButton.layer?.cornerRadius = 1.0
|
|
|
+ self.headerPopUpButton.layer?.cornerRadius = 1.0
|
|
|
+
|
|
|
+ self.updateViewColor()
|
|
|
+//
|
|
|
+ NotificationCenter.default.addObserver(self, selector: #selector(controlTextDidEndEditingNotification(_:)), name: NSControl.textDidEndEditingNotification, object: self.cellWidthTextField)
|
|
|
+ NotificationCenter.default.addObserver(self, selector: #selector(controlTextDidEndEditingNotification(_:)), name: NSControl.textDidEndEditingNotification, object: self.cellHeightTextField)
|
|
|
+ DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChanged(_:)), name: Notification.Name(rawValue: "AppleInterfaceThemeChangedNotification"), object: nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ //MARK: Private Methods
|
|
|
+
|
|
|
+ func reloadData(with point: NSPoint) {
|
|
|
+ let rect = annotation!.isInCell(with: point)
|
|
|
+ if !NSEqualRects(rect, NSRectFromCGRect(CGRect.zero)) {
|
|
|
+ var color = annotation?.getCellData(row: annotation!.currentCell.row, column: annotation!.currentCell.column).backgroundColor
|
|
|
+
|
|
|
+ var maxWidth: CGFloat = 10
|
|
|
+ let minHeight: CGFloat = 10
|
|
|
+
|
|
|
+ if annotation!.currentCell.column == annotation!.columnNumber - 1 {
|
|
|
+ maxWidth = CGFloat(MAXFLOAT)
|
|
|
+ } else {
|
|
|
+ if let rect1 = annotation?.getCellBounds(row: annotation!.currentCell.row, column: annotation!.currentCell.column + 1) {
|
|
|
+ maxWidth = rect1.size.width + rect.size.width - 10
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ cellWidthStepper.maxValue = Double(maxWidth)
|
|
|
+ cellHeightStepper.minValue = Double(minHeight)
|
|
|
+
|
|
|
+ if color == nil {
|
|
|
+ color = NSColor(deviceRed: 1, green: 1, blue: 1, alpha: 1)
|
|
|
+ }
|
|
|
+
|
|
|
+ backgroudColorBoxIsEnabled = true
|
|
|
+ backgrourdColorView.wantsLayer = true
|
|
|
+ backgrourdColorView.layer?.backgroundColor = color!.cgColor
|
|
|
+ } else {
|
|
|
+ backgroudColorBoxIsEnabled = false
|
|
|
+ backgrourdColorView.wantsLayer = true
|
|
|
+ backgrourdColorView.layer?.backgroundColor = NSColor.white.cgColor
|
|
|
+ }
|
|
|
+
|
|
|
+ self.setCell(width: rect.size.width, height: rect.size.height)
|
|
|
+ widthSlider.floatValue = Float((annotation?.border.lineWidth)!)
|
|
|
+
|
|
|
+ let sliderString = String(format: "%.1f pt", (annotation?.border.lineWidth)!)
|
|
|
+
|
|
|
+ if widthPopUpButton.itemTitles.contains(sliderString) {
|
|
|
+ if let index = widthPopUpButton.itemTitles.firstIndex(of: sliderString) {
|
|
|
+ widthPopUpButton.selectItem(at: index)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ widthSlider.toolTip = sliderString
|
|
|
+
|
|
|
+ lineStyleCount = 0
|
|
|
+
|
|
|
+ if annotation?.border.style == .solid {
|
|
|
+ lineStyleButton.layer?.backgroundColor = KMAppearance.Status.selColor().cgColor
|
|
|
+ lineStyleButton.layer?.borderWidth = 0.0
|
|
|
+ lineStyleButton.image = borderStyleSolid(isSelect: true)
|
|
|
+ dottedLineStyleButton.layer?.backgroundColor = KMAppearance.Layout.l1Color().cgColor
|
|
|
+ dottedLineStyleButton.layer?.borderWidth = 1.0
|
|
|
+ dottedLineStyleButton.image = borderStyleSolid(isSelect: false)
|
|
|
+ } else if annotation?.border.style == .dashed {
|
|
|
+ dottedLineStyleButton.layer?.backgroundColor = KMAppearance.Status.selColor().cgColor
|
|
|
+ dottedLineStyleButton.layer?.borderWidth = 0.0
|
|
|
+ dottedLineStyleButton.image = borderStyleDashed(isSelect: true)
|
|
|
+
|
|
|
+ lineStyleButton.layer?.backgroundColor = KMAppearance.Layout.l1Color().cgColor
|
|
|
+ lineStyleButton.layer?.borderWidth = 1.0
|
|
|
+ lineStyleButton.image = borderStyleSolid(isSelect: false)
|
|
|
+
|
|
|
+ lineStyleCount = 1
|
|
|
+ }
|
|
|
+
|
|
|
+ borderColorView.wantsLayer = true
|
|
|
+ borderColorView.layer?.backgroundColor = annotation?.color.cgColor
|
|
|
+
|
|
|
+ if let alternateColor = annotation?.alternatingColor {
|
|
|
+ alternateColorView.wantsLayer = true
|
|
|
+ alternateColorView.layer?.backgroundColor = alternateColor.cgColor
|
|
|
+ }
|
|
|
+
|
|
|
+ alternateColorButton.state = annotation!.isAlternateColor ? .on : .off
|
|
|
+
|
|
|
+ sidebarPopUpButton.selectItem(at: (annotation?.sidebarCount())!)
|
|
|
+ headerPopUpButton.selectItem(at: (annotation?.headerCount())!)
|
|
|
+ footerPopUpButton.selectItem(at: (annotation?.footerCount())!)
|
|
|
+ }
|
|
|
+
|
|
|
+ func setCell(width cellWidth: CGFloat, height cellHeight: CGFloat) {
|
|
|
+ if cellWidth == 0 && cellHeight == 0 {
|
|
|
+ cellWidthStepper.isEnabled = false
|
|
|
+ cellHeightStepper.isEnabled = false
|
|
|
+ cellWidthTextField.isEnabled = false
|
|
|
+ cellHeightTextField.isEnabled = false
|
|
|
+ } else {
|
|
|
+ cellWidthStepper.isEnabled = true
|
|
|
+ cellHeightStepper.isEnabled = true
|
|
|
+ cellWidthTextField.isEnabled = true
|
|
|
+ cellHeightTextField.isEnabled = true
|
|
|
+ }
|
|
|
+
|
|
|
+ let widthText = String(format: "%0.2f", cellWidth * 0.04)
|
|
|
+ cellWidthTextField.stringValue = widthText
|
|
|
+ cellWidthStepper.doubleValue = Double(cellWidth)
|
|
|
+
|
|
|
+ let heightText = String(format: "%0.2f", cellHeight * 0.04)
|
|
|
+ cellHeightTextField.stringValue = heightText
|
|
|
+ cellHeightStepper.doubleValue = Double(cellHeight)
|
|
|
+ }
|
|
|
+
|
|
|
+ func reloadDataStepper(_ stepper: NSStepper) {
|
|
|
+ let table = self.annotation
|
|
|
+ if (table?.currentCell.row)! >= 0 && (table?.currentCell.column)! >= 0 {
|
|
|
+ let row = table?.currentCell.row
|
|
|
+ let column = table?.currentCell.column
|
|
|
+ if stepper == cellWidthStepper {
|
|
|
+ table?.moveVerticalLineOfIndex(column!+1, withDistance: self.cellWidthStepper.doubleValue - (table?.getCellBounds(row: row!, column: column!).size.width)!)
|
|
|
+ } else {
|
|
|
+ table?.moveCrossLineOfIndex(table!.rowNumber - row! - 1, withDistance: (table?.getCellBounds(row: row!, column: column!).size.height)! - self.cellHeightStepper.doubleValue)
|
|
|
+ table?.setOldRowHeights()
|
|
|
+ }
|
|
|
+ table?.afreshDrawLine()
|
|
|
+ }
|
|
|
+
|
|
|
+ self.pdfView?.needsDisplay = true
|
|
|
+ }
|
|
|
+
|
|
|
+ func colorWithCGColor(_ cgColor: CGColor?) -> NSColor? {
|
|
|
+ guard let cgColor = cgColor else { return nil }
|
|
|
+ return NSColor(cgColor: cgColor)
|
|
|
+ }
|
|
|
+
|
|
|
+ func borderStyleSolid(isSelect: Bool) -> NSImage {
|
|
|
+ let size = NSSize(width: 49.0, height: 12.0)
|
|
|
+
|
|
|
+ let image = NSImage.image(with: size) { rect in
|
|
|
+ let path = NSBezierPath(rect: NSRect(x: 15.0, y: 5.0, width: 20.0, height: 1.0))
|
|
|
+ path.lineWidth = 2.0
|
|
|
+ if isSelect {
|
|
|
+ KMAppearance.KM_273C62_ColorDarkChanged02().setStroke()
|
|
|
+ } else {
|
|
|
+ KMAppearance.Layout.h2Color().setStroke()
|
|
|
+ }
|
|
|
+ path.stroke()
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return image
|
|
|
+ }
|
|
|
+
|
|
|
+ func borderStyleDashed(isSelect: Bool) -> NSImage {
|
|
|
+ let size = NSSize(width: 49.0, height: 12.0)
|
|
|
+ let image = NSImage(size: size) { rect in
|
|
|
+ let path = NSBezierPath()
|
|
|
+ path.move(to: NSPoint(x: 15.0, y: 5.0))
|
|
|
+ path.line(to: NSPoint(x: 19.0, y: 5.0))
|
|
|
+ path.move(to: NSPoint(x: 23.0, y: 5.0))
|
|
|
+ path.line(to: NSPoint(x: 27.0, y: 5.0))
|
|
|
+ path.move(to: NSPoint(x: 31.0, y: 5.0))
|
|
|
+ path.line(to: NSPoint(x: 35.0, y: 5.0))
|
|
|
+ path.lineWidth = 2.0
|
|
|
+ if isSelect {
|
|
|
+ KMAppearance.KM_273C62_ColorDarkChanged02().setStroke()
|
|
|
+ } else {
|
|
|
+ KMAppearance.Layout.h2Color().setStroke()
|
|
|
+ }
|
|
|
+ path.stroke()
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return image!
|
|
|
+ }
|
|
|
+
|
|
|
+ //MARK: Button Actions
|
|
|
+
|
|
|
+ @IBAction func styleButtonAction(_ sender: NSButton) {
|
|
|
+ var tableStyle: KMTableStyle = .Default
|
|
|
+ if let button = sender as? NSButton {
|
|
|
+ switch button.tag {
|
|
|
+ case 300:
|
|
|
+ tableStyle = .Default
|
|
|
+ case 301:
|
|
|
+ tableStyle = .Style1
|
|
|
+ case 302:
|
|
|
+ tableStyle = .Style2
|
|
|
+ case 303:
|
|
|
+ tableStyle = .Style3
|
|
|
+ case 304:
|
|
|
+ tableStyle = .Style4
|
|
|
+ case 305:
|
|
|
+ tableStyle = .Style5
|
|
|
+ default:
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ annotation?.changeTableStyle(tableStyle)
|
|
|
+ reloadData(with: point)
|
|
|
+ pdfView?.needsDisplay = true
|
|
|
+ }
|
|
|
+
|
|
|
+ @IBAction func stepperAction(_ sender: Any) {
|
|
|
+ guard let stepper = sender as? NSStepper else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var text: String
|
|
|
+
|
|
|
+ switch stepper.tag {
|
|
|
+ case 201:
|
|
|
+ text = String(format: "%0.2f", self.cellWidthStepper.doubleValue * 0.04)
|
|
|
+ self.cellWidthTextField.stringValue = text
|
|
|
+ self.reloadDataStepper(self.cellWidthStepper)
|
|
|
+ case 202:
|
|
|
+ text = String(format: "%0.2f", self.cellHeightStepper.doubleValue * 0.04)
|
|
|
+ self.cellHeightTextField.stringValue = text
|
|
|
+ self.reloadDataStepper(self.cellHeightStepper)
|
|
|
+ default:
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @IBAction func colorWellAction(_ sender: Any) {
|
|
|
+ guard let table = self.annotation else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+// table.border.lineWidth = CGFloat(self.widthSlider.floatValue)
|
|
|
+ let sliderString = String(format: "%.1f pt", self.widthSlider.floatValue)
|
|
|
+ if widthPopUpButton.itemTitles.contains(sliderString) {
|
|
|
+ if let index = self.widthPopUpButton.itemTitles.firstIndex(of: sliderString) {
|
|
|
+ self.widthPopUpButton.selectItem(at: index)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ table.color = self.colorWithCGColor(self.borderColorView.layer!.backgroundColor)
|
|
|
+
|
|
|
+ if table.currentCell.row >= 0 && table.currentCell.column >= 0 {
|
|
|
+ if self.backgroudColorBoxIsEnabled {
|
|
|
+ if !self.notUpdateBackgroundColor {
|
|
|
+ table.getCellData(row: table.currentCell.row, column: table.currentCell.column).backgroundColor = self.colorWithCGColor(self.backgrourdColorView.layer?.backgroundColor)
|
|
|
+ } else {
|
|
|
+ var color = self.annotation?.getCellData(row: self.annotation!.currentCell.row, column: self.annotation!.currentCell.column).backgroundColor
|
|
|
+ if color == nil {
|
|
|
+ color = NSColor(deviceRed: 1, green: 1, blue: 1, alpha: 1)
|
|
|
+ }
|
|
|
+ self.backgrourdColorView.layer?.backgroundColor = color?.cgColor
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ table.isAlternateColor = self.alternateColorButton.state == .on
|
|
|
+ table.alternatingColor = self.colorWithCGColor(self.alternateColorView.layer!.backgroundColor)
|
|
|
+ table.writeFormDataToContents()
|
|
|
+
|
|
|
+ if let tableInk = table as? CPDFAnnotation {
|
|
|
+ if lineStyleCount == 1 {
|
|
|
+ let lineType = tableInk.border.dashPattern ?? []
|
|
|
+ if lineType.count == 0 {
|
|
|
+ let number = NSNumber(value: Float(4))
|
|
|
+ tableInk.setDashPattern([number])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tableInk.setBorderStyle(CPDFBorderStyle(rawValue: lineStyleCount) ?? .solid)
|
|
|
+ }
|
|
|
+
|
|
|
+ if self.notUpdateBackgroundColor {
|
|
|
+ self.notUpdateBackgroundColor = false
|
|
|
+ }
|
|
|
+ self.pdfView!.needsDisplay = true
|
|
|
+ }
|
|
|
+
|
|
|
+ @IBAction func titleEndTablePopUpButtonAction(_ sender: NSPopUpButton) {
|
|
|
+ guard let table = self.annotation else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ let bounds = self.annotation!.bounds
|
|
|
+ guard let popButton = sender as? NSPopUpButton else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ switch popButton.tag {
|
|
|
+ case 100:
|
|
|
+ let count = (popButton.titleOfSelectedItem as NSString?)?.integerValue ?? 0 - table.sidebarCount()
|
|
|
+ if count > 0 {
|
|
|
+ for _ in 0..<count {
|
|
|
+ table.insertColumn(atIndexBefore: 0, withLineJoinStyle: .round)
|
|
|
+ }
|
|
|
+ } else if count < 0 {
|
|
|
+ for _ in count..<0 {
|
|
|
+ table.removeColumn(at: 0)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ table.bounds.origin.x -= (bounds.size.width - table.bounds.size.width)
|
|
|
+ case 101:
|
|
|
+ let count = (popButton.titleOfSelectedItem as NSString?)?.integerValue ?? 0 - table.headerCount()
|
|
|
+ if count > 0 {
|
|
|
+ for _ in 0..<count {
|
|
|
+ table.insertColumn(atIndexBefore: 0, withLineJoinStyle: .round)
|
|
|
+ }
|
|
|
+ } else if count < 0 {
|
|
|
+ for _ in count..<0 {
|
|
|
+ table.removeRow(at: 0)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ table.bounds.origin.y -= (table.bounds.size.height - bounds.size.height)
|
|
|
+ case 102:
|
|
|
+ let count = (popButton.titleOfSelectedItem as NSString?)?.integerValue ?? 0 - table.footerCount()
|
|
|
+ if count > 0 {
|
|
|
+ for _ in 0..<count {
|
|
|
+ table.insertColumn(atIndexBefore: table.rowNumber - 1, withLineJoinStyle: .bevel)
|
|
|
+ }
|
|
|
+ } else if count < 0 {
|
|
|
+ for _ in count..<0 {
|
|
|
+ table.removeRowBehindLine(at: table.rowNumber - 1)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ break
|
|
|
+ }
|
|
|
+
|
|
|
+ table.drawLine(point: self.point)
|
|
|
+ reloadData(with: self.point)
|
|
|
+ pdfView!.needsDisplay = true
|
|
|
+ }
|
|
|
+
|
|
|
+ @IBAction func widthPopUpButtonAction(_ sender: NSPopUpButton) {
|
|
|
+ if let widthString = sender.titleOfSelectedItem, let width = Float(widthString.prefix(3)) {
|
|
|
+ widthSlider.floatValue = width
|
|
|
+ }
|
|
|
+
|
|
|
+ colorWellAction(sender)
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func backgroudColorPanelColorDidChange(_ sender: Any) {
|
|
|
+ guard NSColorPanel.sharedColorPanelExists, NSColorPanel.shared.isVisible else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if let color = (sender as? NSColorPanel)?.color {
|
|
|
+ var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0
|
|
|
+// if let rgbColor = color.usingColorSpace(NSColorSpace.sRGB) {
|
|
|
+// rgbColor.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
|
|
|
+// }
|
|
|
+ color.usingColorSpaceName(NSColorSpaceName.calibratedRGB)?.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
|
|
|
+
|
|
|
+ backgrourdColorView.wantsLayer = true
|
|
|
+ backgrourdColorView.layer?.backgroundColor = color.cgColor
|
|
|
+
|
|
|
+ colorWellAction(sender)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func borderColorPanelColorDidChange(_ sender: Any) {
|
|
|
+ guard NSColorPanel.sharedColorPanelExists, NSColorPanel.shared.isVisible else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if let color = (sender as? NSColorPanel)?.color {
|
|
|
+ var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0
|
|
|
+ color.usingColorSpaceName(NSColorSpaceName.calibratedRGB)?.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
|
|
|
+
|
|
|
+ borderColorView.wantsLayer = true
|
|
|
+ borderColorView.layer?.backgroundColor = color.cgColor
|
|
|
+
|
|
|
+ colorWellAction(sender)
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ @objc func alternateColorPanelColorDidChange(_ sender: Any) {
|
|
|
+ if let color = (sender as? NSColorPanel)?.color {
|
|
|
+ var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0
|
|
|
+ color.usingColorSpaceName(NSColorSpaceName.calibratedRGB)?.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
|
|
|
+
|
|
|
+ alternateColorView.wantsLayer = true
|
|
|
+ alternateColorView.layer?.backgroundColor = color.cgColor
|
|
|
+
|
|
|
+ colorWellAction(sender)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @IBAction func lineTypeButtonAction(_ sender: NSButton) {
|
|
|
+ let tag = sender.tag
|
|
|
+
|
|
|
+ switch tag {
|
|
|
+ case 0:
|
|
|
+ lineStyleCount = 0
|
|
|
+ lineStyleButton.layer?.backgroundColor = KMAppearance.Status.selColor().cgColor
|
|
|
+ lineStyleButton.layer?.borderWidth = 0.0
|
|
|
+ dottedLineStyleButton.layer?.backgroundColor = KMAppearance.Layout.l1Color().cgColor
|
|
|
+ dottedLineStyleButton.layer?.borderWidth = 1.0
|
|
|
+
|
|
|
+ lineStyleButton.image = borderStyleSolid(isSelect: true)
|
|
|
+ dottedLineStyleButton.image = borderStyleDashed(isSelect: false)
|
|
|
+ colorWellAction(sender)
|
|
|
+
|
|
|
+ case 1:
|
|
|
+ lineStyleCount = 1
|
|
|
+ lineStyleButton.layer?.backgroundColor = KMAppearance.Layout.l1Color().cgColor
|
|
|
+ lineStyleButton.layer?.borderWidth = 1.0
|
|
|
+ dottedLineStyleButton.layer?.backgroundColor = KMAppearance.Status.selColor().cgColor
|
|
|
+ dottedLineStyleButton.layer?.borderWidth = 0.0
|
|
|
+
|
|
|
+ lineStyleButton.image = borderStyleSolid(isSelect: false)
|
|
|
+ dottedLineStyleButton.image = borderStyleDashed(isSelect: true)
|
|
|
+ colorWellAction(sender)
|
|
|
+
|
|
|
+ case 3:
|
|
|
+ break
|
|
|
+
|
|
|
+ default:
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //MARK: Notification
|
|
|
|
|
|
+ @objc func PDFViewTableAnnotationDidChangeNotification(_ notification: Notification) {
|
|
|
+ if let pdfView = notification.object as? CPDFListView, pdfView == self.pdfView {
|
|
|
+ self.notUpdateBackgroundColor = true
|
|
|
+ if let pointValue = notification.userInfo?["point"] as? NSValue {
|
|
|
+ let point = pointValue.pointValue
|
|
|
+ self.point = point
|
|
|
+ if NSColorPanel.sharedColorPanelExists {
|
|
|
+ NSColorPanel.shared.close()
|
|
|
+ }
|
|
|
+ self.reloadData(with: point)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func controlTextDidEndEditingNotification(_ notification: Notification) {
|
|
|
+ guard let textField = notification.object as? NSTextField else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if textField == cellWidthTextField {
|
|
|
+ let width = (textField.stringValue as NSString).doubleValue / 0.04
|
|
|
+ if fabs(width - cellWidthStepper.doubleValue) < 0.01 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if width <= 0 {
|
|
|
+ let text = String(format: "%0.2f", cellWidthStepper.doubleValue * 0.04)
|
|
|
+ cellWidthTextField.stringValue = text
|
|
|
+ } else if width > 0 && width < cellWidthStepper.minValue {
|
|
|
+ let text = String(format: "%0.2f", cellWidthStepper.minValue * 0.04)
|
|
|
+ cellWidthTextField.stringValue = text
|
|
|
+ cellWidthStepper.doubleValue = cellWidthStepper.minValue
|
|
|
+ reloadDataStepper(cellWidthStepper)
|
|
|
+ } else if width >= cellWidthStepper.minValue && width <= cellWidthStepper.maxValue {
|
|
|
+ let text = String(format: "%0.2f", (textField.stringValue as NSString).doubleValue)
|
|
|
+ cellWidthTextField.stringValue = text
|
|
|
+ cellWidthStepper.doubleValue = width
|
|
|
+ reloadDataStepper(cellWidthStepper)
|
|
|
+ } else {
|
|
|
+ let text = String(format: "%0.2f", cellWidthStepper.maxValue * 0.04)
|
|
|
+ cellWidthTextField.stringValue = text
|
|
|
+ cellWidthStepper.doubleValue = cellWidthStepper.maxValue
|
|
|
+ reloadDataStepper(cellWidthStepper)
|
|
|
+ }
|
|
|
+ } else if textField == cellHeightTextField {
|
|
|
+ let height = (textField.stringValue as NSString).doubleValue / 0.04
|
|
|
+ if height == cellHeightStepper.doubleValue {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if height <= 0 {
|
|
|
+ let text = String(format: "%0.2f", cellHeightStepper.doubleValue * 0.04)
|
|
|
+ cellHeightTextField.stringValue = text
|
|
|
+ } else if height > 0 && height < cellHeightStepper.minValue {
|
|
|
+ let text = String(format: "%0.2f", cellHeightStepper.minValue * 0.04)
|
|
|
+ cellHeightTextField.stringValue = text
|
|
|
+ cellHeightStepper.doubleValue = cellHeightStepper.minValue
|
|
|
+ reloadDataStepper(cellHeightStepper)
|
|
|
+ } else {
|
|
|
+ let text = String(format: "%0.2f", (textField.stringValue as NSString).doubleValue)
|
|
|
+ cellHeightTextField.stringValue = text
|
|
|
+ cellHeightStepper.doubleValue = height
|
|
|
+ reloadDataStepper(cellHeightStepper)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func themeChanged(_ notification: Notification) {
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { [weak self] in
|
|
|
+ self?.updateViewColor()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func updateViewColor() {
|
|
|
+ if KMAppearance.isDarkMode() {
|
|
|
+ widthPopUpButton.layer?.backgroundColor = NSColor(red: 57/255.0, green: 60/255.0, blue: 62/255.0, alpha: 1.0).cgColor
|
|
|
+
|
|
|
+ cellWidthTextField.layer?.borderColor = NSColor(red: 86/255.0, green: 88/255.0, blue: 90/255.0, alpha: 1.0).cgColor
|
|
|
+ cellHeightTextField.layer?.borderColor = NSColor(red: 86/255.0, green: 88/255.0, blue: 90/255.0, alpha: 1.0).cgColor
|
|
|
+ sidebarPopUpButton.layer?.borderColor = NSColor(red: 86/255.0, green: 88/255.0, blue: 90/255.0, alpha: 1.0).cgColor
|
|
|
+ widthPopUpButton.layer?.borderColor = NSColor(red: 86/255.0, green: 88/255.0, blue: 90/255.0, alpha: 1.0).cgColor
|
|
|
+ headerPopUpButton.layer?.borderColor = NSColor(red: 86/255.0, green: 88/255.0, blue: 90/255.0, alpha: 1.0).cgColor
|
|
|
+ footerPopUpButton.layer?.borderColor = NSColor(red: 86/255.0, green: 88/255.0, blue: 90/255.0, alpha: 1.0).cgColor
|
|
|
+ } else {
|
|
|
+ widthPopUpButton.layer?.backgroundColor = NSColor.white.cgColor
|
|
|
+
|
|
|
+ cellWidthTextField.layer?.borderColor = NSColor(red: 218/255.0, green: 219/255.0, blue: 222/255.0, alpha: 1.0).cgColor
|
|
|
+ cellHeightTextField.layer?.borderColor = NSColor(red: 218/255.0, green: 219/255.0, blue: 222/255.0, alpha: 1.0).cgColor
|
|
|
+ sidebarPopUpButton.layer?.borderColor = NSColor(red: 218/255.0, green: 219/255.0, blue: 222/255.0, alpha: 1.0).cgColor
|
|
|
+ widthPopUpButton.layer?.borderColor = NSColor(red: 218/255.0, green: 219/255.0, blue: 222/255.0, alpha: 1.0).cgColor
|
|
|
+ headerPopUpButton.layer?.borderColor = NSColor(red: 218/255.0, green: 219/255.0, blue: 222/255.0, alpha: 1.0).cgColor
|
|
|
+ footerPopUpButton.layer?.borderColor = NSColor(red: 218/255.0, green: 219/255.0, blue: 222/255.0, alpha: 1.0).cgColor
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|