KMHeaderFooterPageInfoView.swift 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // KMHeaderFooterPageInfoView.swift
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2022/12/28.
  6. //
  7. import Cocoa
  8. class KMHeaderFooterPageInfoView: KMHeaderFooterAdjectiveInfoBaseView {
  9. var leftLabel = NSTextField(labelWithString: "")
  10. var leftComboBox = NSComboBox()
  11. private var rigthLabel = NSTextField(labelWithString: "")
  12. var rightComboBox = NSComboBox()
  13. override func initSubviews() {
  14. super.initSubviews()
  15. self.addSubview(self.leftLabel)
  16. self.addSubview(self.leftComboBox)
  17. self.addSubview(self.rigthLabel)
  18. self.addSubview(self.rightComboBox)
  19. self.titleLabel.isHidden = true
  20. self.rigthLabel.stringValue = NSLocalizedString("Start Page:", comment: "")
  21. self.leftComboBox.isEditable = false
  22. self.leftComboBox.delegate = self
  23. self.rightComboBox.isEditable = false
  24. self.rightComboBox.delegate = self
  25. }
  26. override func layout() {
  27. super.layout()
  28. let width: CGFloat = NSWidth(self.bounds)
  29. let hSpace: CGFloat = 10
  30. let leftMargin = self.contentInset.left
  31. let labelWidth: CGFloat = (width-leftMargin*2-hSpace)*0.5
  32. let labelHeight: CGFloat = 16
  33. self.leftLabel.frame = NSMakeRect(leftMargin, 0, labelWidth, labelHeight)
  34. self.rigthLabel.frame = NSMakeRect(self.rigthLabel.frame.maxX+hSpace, 0, labelWidth, labelHeight)
  35. let comboBoxY: CGFloat = self.leftLabel.frame.maxY+6
  36. let comboBoxSize: NSSize = NSMakeSize(labelWidth, 22)
  37. self.leftComboBox.frame = NSMakeRect(leftMargin, comboBoxY, comboBoxSize.width, comboBoxSize.height)
  38. self.rightComboBox.frame = NSMakeRect(self.leftComboBox.frame.maxX+hSpace, comboBoxY, comboBoxSize.width, comboBoxSize.height)
  39. }
  40. override var model: KMHeaderFooterAdjectiveModel {
  41. get {
  42. super.model
  43. }
  44. set {
  45. super.model = newValue
  46. }
  47. }
  48. }
  49. extension KMHeaderFooterPageInfoView: NSComboBoxDelegate {
  50. func comboBoxSelectionDidChange(_ notification: Notification) {
  51. guard let callback = self.itemClick else {
  52. return
  53. }
  54. var sender: NSComboBox?
  55. var itemID: Int = 0
  56. if (self.leftComboBox.isEqual(to: notification.object)) {
  57. sender = self.leftComboBox
  58. itemID = 1
  59. } else if (self.rightComboBox.isEqual(to: notification.object)) {
  60. sender = self.rightComboBox
  61. itemID = 2
  62. }
  63. if (sender == nil) {
  64. return
  65. }
  66. var index: Int = sender!.indexOfSelectedItem
  67. if (index < 0) {
  68. index = 0
  69. }
  70. callback(itemID, index)
  71. }
  72. }