KMNPDFInsertBlankWindowController.swift 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. //
  2. // KMNPDFInsertBlankWindowController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by 丁林圭 on 2024/10/23.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class KMNPDFInsertBlankWindowController: KMNBaseWindowController {
  10. @IBOutlet var titleLabel: NSTextField!
  11. @IBOutlet var sizeLabel: NSTextField!
  12. @IBOutlet var currentRadioButton: ComponentRadio!
  13. @IBOutlet var standardRadioButton: ComponentRadio!
  14. @IBOutlet var standardSelect: ComponentSelect!
  15. @IBOutlet var customizationRadioButton: ComponentRadio!
  16. @IBOutlet var widthInput: ComponentInput!
  17. @IBOutlet var heightInput: ComponentInput!
  18. @IBOutlet var unitSelect: ComponentSelect!
  19. @IBOutlet var directionLabel: NSTextField!
  20. @IBOutlet var verticalRadioButton: ComponentRadio!
  21. @IBOutlet var horizontalRadioButton: ComponentRadio!
  22. @IBOutlet var positionLabel: NSTextField!
  23. @IBOutlet var firstRadioButton: ComponentRadio!
  24. @IBOutlet var lastRadioButton: ComponentRadio!
  25. @IBOutlet var pageRadioButton: ComponentRadio!
  26. @IBOutlet var pageNumInput: ComponentInputNumber!
  27. @IBOutlet var pageCountLabel: NSTextField!
  28. @IBOutlet var positionSelect: ComponentSelect!
  29. @IBOutlet var cancelButton: ComponentButton!
  30. @IBOutlet var insertButton: ComponentButton!
  31. @IBOutlet var standardRadioWidthButton:NSLayoutConstraint!
  32. @IBOutlet var customizationRadioWidthButton:NSLayoutConstraint!
  33. @IBOutlet var verticalRadioWidthButton:NSLayoutConstraint!
  34. @IBOutlet var cancelWidthButton:NSLayoutConstraint!
  35. @IBOutlet var insertWidthButton:NSLayoutConstraint!
  36. @IBOutlet var pageRadioWidthButton:NSLayoutConstraint!
  37. private var orgDocument:CPDFDocument?
  38. private var selectionIndexPaths:Set<IndexPath>?
  39. private var lastUnitString: String = "mm"
  40. var callback: ((CGSize, Int) -> Void)?
  41. convenience init(_ document: CPDFDocument?, selectionIndexPaths: Set<IndexPath>?) {
  42. self.init(windowNibName: "KMNPDFInsertBlankWindowController")
  43. orgDocument = document
  44. self.selectionIndexPaths = selectionIndexPaths
  45. }
  46. convenience init(_ filePath: String,password:String?) {
  47. self.init(windowNibName: "KMNPDFInsertBlankWindowController")
  48. let document = CPDFDocument.init(url: URL(fileURLWithPath: filePath))
  49. if password != nil {
  50. document?.unlock(withPassword: password as String?)
  51. }
  52. orgDocument = document
  53. }
  54. private func setUpPositionSelctProperty() {
  55. var menuItemArr: [ComponentMenuitemProperty] = []
  56. for language in [KMLocalizedString("After"),KMLocalizedString("Before")] {
  57. let itemProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
  58. itemSelected: false,
  59. isDisabled: false,
  60. keyEquivalent: nil,
  61. text: language)
  62. menuItemArr.append(itemProperty)
  63. }
  64. positionSelect.updateMenuItemsArr(menuItemArr)
  65. }
  66. private func setUpUnitSelctProperty() {
  67. var menuItemArr: [ComponentMenuitemProperty] = []
  68. for language in ["mm","cm","in"] {
  69. let itemProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
  70. itemSelected: false,
  71. isDisabled: false,
  72. keyEquivalent: nil,
  73. text: language)
  74. menuItemArr.append(itemProperty)
  75. }
  76. unitSelect.updateMenuItemsArr(menuItemArr)
  77. }
  78. private func setUpPageSizeSelctProperty() {
  79. let paperArray = KMNPageSizeTool.paperSize()
  80. var menuItemArr: [ComponentMenuitemProperty] = []
  81. for pageSizeString in paperArray {
  82. let itemProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
  83. itemSelected: false,
  84. isDisabled: false,
  85. keyEquivalent: nil,
  86. text: pageSizeString)
  87. menuItemArr.append(itemProperty)
  88. }
  89. standardSelect.updateMenuItemsArr(menuItemArr)
  90. }
  91. private func setUpProperty() {
  92. titleLabel.stringValue = KMLocalizedString("Insert Blank Page")
  93. titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-medium")
  94. titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/1")
  95. sizeLabel.stringValue = KMLocalizedString("Form File")
  96. sizeLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-medium")
  97. sizeLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  98. directionLabel.stringValue = KMLocalizedString("Direction")
  99. directionLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-medium")
  100. directionLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  101. sizeLabel.stringValue = KMLocalizedString("Page Size")
  102. sizeLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-medium")
  103. sizeLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  104. positionLabel.stringValue = KMLocalizedString("Where to insert?")
  105. positionLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-medium")
  106. positionLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  107. var currentPageDex = 0
  108. if(selectionIndexPaths?.count ?? 0 > 0) {
  109. pageRadioButton.properties.checkboxType = .selected
  110. let maxmumIndexPath = selectionIndexPaths?.max(by: { $0 < $1 })
  111. currentPageDex = maxmumIndexPath?.item ?? 0
  112. }
  113. let page = self.orgDocument?.page(at: UInt(currentPageDex)) as? CPDFPage
  114. let rect = page?.bounds ?? CGRectZero
  115. var width = KMNPageSizeTool.conversion(withUnit: "mm", value: (NSWidth(rect)/595 * 210))
  116. var height = KMNPageSizeTool.conversion(withUnit: "mm", value: (NSHeight(rect)/842 * 297))
  117. if((page?.rotation ?? 0) % 180 != 0) {
  118. width = KMNPageSizeTool.conversion(withUnit: "mm", value: (NSHeight(rect)/595 * 210))
  119. height = KMNPageSizeTool.conversion(withUnit: "mm", value: (NSWidth(rect)/842 * 297))
  120. }
  121. currentRadioButton.properties = ComponentCheckBoxProperty(size: .s,
  122. state: .normal,
  123. isDisabled: false,
  124. showhelp: false,
  125. text: String(format: "%@(%@ x %@mm)", KMLocalizedString("Current Size"),width,height),
  126. checkboxType: .selected)
  127. standardRadioButton.properties = ComponentCheckBoxProperty(size: .s,
  128. state: .normal,
  129. isDisabled: false,
  130. showhelp: false,
  131. text: KMLocalizedString("Standard"),
  132. checkboxType: .normal)
  133. customizationRadioButton.properties = ComponentCheckBoxProperty(size: .s,
  134. state: .normal,
  135. isDisabled: false,
  136. showhelp: false,
  137. text: KMLocalizedString("Custom"),
  138. checkboxType: .normal)
  139. firstRadioButton.properties = ComponentCheckBoxProperty(size: .s,
  140. state: .normal,
  141. isDisabled: false,
  142. showhelp: false,
  143. text: KMLocalizedString("First"),
  144. checkboxType: .normal)
  145. lastRadioButton.properties = ComponentCheckBoxProperty(size: .s,
  146. state: .normal,
  147. isDisabled: false,
  148. showhelp: false,
  149. text: KMLocalizedString("Last"),
  150. checkboxType: .normal)
  151. pageRadioButton.properties = ComponentCheckBoxProperty(size: .s,
  152. state: .normal,
  153. isDisabled: false,
  154. showhelp: false,
  155. text: KMLocalizedString("Page"),
  156. checkboxType: .normal)
  157. verticalRadioButton.properties = ComponentCheckBoxProperty(size: .s,
  158. state: .normal,
  159. isDisabled: false,
  160. showhelp: false,
  161. text: KMLocalizedString("Landscape pages"),
  162. checkboxType: .normal)
  163. horizontalRadioButton.properties = ComponentCheckBoxProperty(size: .s,
  164. state: .normal,
  165. isDisabled: false,
  166. showhelp: false,
  167. text: KMLocalizedString("Portrait pages"),
  168. checkboxType: .selected)
  169. unitSelect.properties = ComponentSelectProperties(size: .s,
  170. state: .normal,
  171. isDisabled: true,
  172. isError: false,
  173. leftIcon: false,
  174. placeholder: nil,
  175. errorText: nil,
  176. creatable: false,
  177. text: KMLocalizedString("mm", comment: ""))
  178. unitSelect.delegate = self
  179. standardSelect.properties = ComponentSelectProperties(size: .s,
  180. state: .normal,
  181. isDisabled: true,
  182. isError: false,
  183. leftIcon: false,
  184. placeholder: nil,
  185. errorText: nil,
  186. creatable: false,
  187. text: KMLocalizedString("A4", comment: ""))
  188. standardSelect.delegate = self
  189. positionSelect.properties = ComponentSelectProperties(size: .s,
  190. state: .normal,
  191. isDisabled: false,
  192. isError: false,
  193. leftIcon: false,
  194. placeholder: nil,
  195. errorText: nil,
  196. creatable: false,
  197. text: KMLocalizedString("After", comment: ""))
  198. positionSelect.delegate = self
  199. insertButton.properties = ComponentButtonProperty(type: .primary,
  200. size: .s,
  201. state: .normal,
  202. isDisable: false,
  203. buttonText: KMLocalizedString("Insert"))
  204. insertButton.setTarget(self, action: #selector(insertButtonClicked(_ :)))
  205. insertWidthButton.constant = insertButton.properties.propertyInfo.viewWidth
  206. cancelButton.properties = ComponentButtonProperty(type: .default_tertiary,
  207. size: .s,
  208. state: .normal,
  209. buttonText: KMLocalizedString("Cancel"))
  210. cancelButton.setTarget(self, action: #selector(cancelButtonClicked(_ :)))
  211. cancelWidthButton.constant = cancelButton.properties.propertyInfo.viewWidth
  212. firstRadioButton.setTarget(self, action: #selector(insertPositionAction(_:)))
  213. lastRadioButton.setTarget(self, action: #selector(insertPositionAction(_:)))
  214. pageRadioButton.setTarget(self, action: #selector(insertPositionAction(_:)))
  215. verticalRadioButton.setTarget(self, action: #selector(insertDirectionAction(_:)))
  216. horizontalRadioButton.setTarget(self, action: #selector(insertDirectionAction(_:)))
  217. currentRadioButton.setTarget(self, action: #selector(insertPageSizeAction(_:)))
  218. standardRadioButton.setTarget(self, action: #selector(insertPageSizeAction(_:)))
  219. customizationRadioButton.setTarget(self, action: #selector(insertPageSizeAction(_:)))
  220. pageNumInput.properties = ComponentInputNumberProperty(alignment: .left,
  221. size: .s,
  222. state: .normal,
  223. isError: false,
  224. showErrorInfo: false,
  225. isDisabled: true,
  226. showPrefix: false,
  227. showSuffix: false,
  228. minSize: 1,
  229. maxSize: Int(orgDocument?.pageCount ?? 1),
  230. text: SettingsManager.sharedInstance.autoSaveMinutes)
  231. pageNumInput.delegate = self
  232. let inputWidthProperty: ComponentInputProperty = ComponentInputProperty(size: .s,
  233. state:.pressed ,
  234. isError: false,
  235. showPrefix: false,
  236. showSuffix: false,
  237. showClear: false,
  238. isDisabled: true,
  239. placeholder: "210",
  240. text: "210")
  241. widthInput.properties = inputWidthProperty
  242. widthInput.delegate = self
  243. let inputHeightProperty: ComponentInputProperty = ComponentInputProperty(size: .s,
  244. state:.pressed ,
  245. isError: false,
  246. showPrefix: false,
  247. showSuffix: false,
  248. showClear: false,
  249. isDisabled: true,
  250. placeholder: "297",
  251. text: "297")
  252. heightInput.properties = inputHeightProperty
  253. heightInput.delegate = self
  254. pageCountLabel.stringValue = "/" + String(format: "%d", orgDocument?.pageCount ?? 0)
  255. setUpPositionSelctProperty()
  256. setUpUnitSelctProperty()
  257. setUpPageSizeSelctProperty()
  258. pageRadioWidthButton.constant = pageRadioButton.properties.propertyInfo.viewWidth
  259. cancelWidthButton.constant = cancelButton.properties.propertyInfo.viewWidth
  260. insertWidthButton.constant = insertButton.properties.propertyInfo.viewWidth
  261. standardRadioWidthButton.constant = standardRadioButton.properties.propertyInfo.viewWidth
  262. customizationRadioWidthButton.constant = customizationRadioButton.properties.propertyInfo.viewWidth
  263. verticalRadioWidthButton.constant = verticalRadioButton.properties.propertyInfo.viewWidth
  264. }
  265. override func windowDidLoad() {
  266. super.windowDidLoad()
  267. setUpProperty()
  268. positionSelect.selectItemAtIndex(0)
  269. unitSelect.selectItemAtIndex(0)
  270. standardSelect.selectItemAtIndex(1)
  271. pageCountLabel.stringValue = "/" + String(format: "%d", orgDocument?.pageCount ?? 0)
  272. if(selectionIndexPaths?.count ?? 0 > 0) {
  273. pageRadioButton.properties.checkboxType = .selected
  274. let maxmumIndexPath = selectionIndexPaths?.max(by: { $0 < $1 })
  275. pageNumInput.properties.text = String((maxmumIndexPath?.item ?? 0)+1)
  276. pageNumInput.properties.isDisabled = false
  277. pageRadioButton.reloadData()
  278. pageNumInput.reloadData()
  279. } else {
  280. firstRadioButton.properties.checkboxType = .selected
  281. pageRadioButton.properties.checkboxType = .normal
  282. positionSelect.properties.isDisabled = true
  283. pageNumInput.properties.isDisabled = true
  284. firstRadioButton.reloadData()
  285. pageRadioButton.reloadData()
  286. pageNumInput.reloadData()
  287. positionSelect.reloadData()
  288. }
  289. }
  290. //MARK: - Action
  291. @objc func cancelButtonClicked(_ sender: NSView) {
  292. own_closeEndSheet()
  293. }
  294. @objc func insertButtonClicked(_ sender: NSView) {
  295. self.window?.makeFirstResponder(nil)
  296. var currentPageDex = 0
  297. if(selectionIndexPaths?.count ?? 0 > 0) {
  298. pageRadioButton.properties.checkboxType = .selected
  299. let maxmumIndexPath = selectionIndexPaths?.max(by: { $0 < $1 })
  300. currentPageDex = maxmumIndexPath?.item ?? 0
  301. }
  302. var height: CGFloat = 0
  303. var width: CGFloat = 0
  304. if currentRadioButton.properties.checkboxType == .selected {
  305. let page = self.orgDocument?.page(at: UInt(currentPageDex)) as? CPDFPage
  306. let rect = page?.bounds ?? .zero
  307. width = rect.size.width
  308. height = rect.size.height
  309. let w = KMPageSizeTool.conversion(withUnit: "mm", value: (NSWidth(rect)/595 * 210))
  310. let h = KMPageSizeTool.conversion(withUnit: "mm", value: (NSHeight(rect)/842 * 297))
  311. width = w.stringToCGFloat()
  312. height = h.stringToCGFloat()
  313. if((page?.rotation ?? 0) % 180 != 0) {
  314. width = h.stringToCGFloat()
  315. height = w.stringToCGFloat()
  316. }
  317. } else if standardRadioButton.properties.checkboxType == .selected {
  318. let sizeString = standardSelect.properties.text ?? KMNPaperSizeNameA4
  319. let tSize = KMPageSizeTool.getPaperSize(paperName: sizeString)
  320. width = KMPageSizeTool.conversion(withUnit: "mm", value: tSize.width).stringToCGFloat()
  321. height = KMPageSizeTool.conversion(withUnit: "mm", value: tSize.height).stringToCGFloat()
  322. } else if customizationRadioButton.properties.checkboxType == .selected {
  323. let unitString = unitSelect.properties.text ?? "mm"
  324. height = widthInput.properties.text.stringToCGFloat()
  325. width = heightInput.properties.text.stringToCGFloat()
  326. width = KMPageSizeTool.conversion(with: "mm", from: unitString, value: width).stringToCGFloat()
  327. height = KMPageSizeTool.conversion(with: "mm", from: unitString, value: height).stringToCGFloat()
  328. if(!(width > 0 && height > 0)) {
  329. let alert = NSAlert()
  330. alert.alertStyle = .critical
  331. alert.messageText = KMLocalizedString("Please enter the correct size.")
  332. alert.runModal()
  333. return
  334. }
  335. }
  336. width *= 595 / 210
  337. height *= 842 / 297
  338. var insertSize = CGSize(width: width, height: height)
  339. if(verticalRadioButton.properties.checkboxType == .selected) {
  340. if(width < height) {
  341. insertSize = CGSize(width: height, height: width)
  342. }
  343. } else if(horizontalRadioButton.properties.checkboxType == .selected){
  344. if(width > height) {
  345. insertSize = CGSize(width: height, height: width)
  346. }
  347. }
  348. var insetPageDex:Int = 0
  349. if firstRadioButton.properties.checkboxType == .selected {
  350. insetPageDex = 0
  351. } else if lastRadioButton.properties.checkboxType == .selected {
  352. insetPageDex = Int(orgDocument?.pageCount ?? 0)
  353. } else if pageRadioButton.properties.checkboxType == .selected {
  354. insetPageDex = Int(pageNumInput.properties.text ?? "0") ?? 0
  355. let positionSelectIndex = positionSelect.indexOfSelect()
  356. if (1 == positionSelectIndex) {
  357. insetPageDex -= 1
  358. }
  359. }
  360. callback?(insertSize, insetPageDex)
  361. own_closeEndSheet()
  362. }
  363. @objc func insertPositionAction(_ sender: NSView) {
  364. var oldSelectRadioBtn:ComponentRadio? = nil
  365. if sender == lastRadioButton {
  366. if(firstRadioButton.properties.checkboxType == .selected) {
  367. oldSelectRadioBtn = firstRadioButton
  368. } else if (pageRadioButton.properties.checkboxType == .selected){
  369. oldSelectRadioBtn = pageRadioButton
  370. pageNumInput.properties.isDisabled = true
  371. positionSelect.properties.isDisabled = true
  372. pageNumInput.reloadData()
  373. positionSelect.reloadData()
  374. }
  375. } else if sender == firstRadioButton {
  376. if(lastRadioButton.properties.checkboxType == .selected) {
  377. oldSelectRadioBtn = lastRadioButton
  378. } else if (pageRadioButton.properties.checkboxType == .selected){
  379. oldSelectRadioBtn = pageRadioButton
  380. pageNumInput.properties.isDisabled = true
  381. positionSelect.properties.isDisabled = true
  382. pageNumInput.reloadData()
  383. positionSelect.reloadData()
  384. }
  385. } else if sender == pageRadioButton {
  386. if(lastRadioButton.properties.checkboxType == .selected) {
  387. oldSelectRadioBtn = lastRadioButton
  388. } else if (firstRadioButton.properties.checkboxType == .selected){
  389. oldSelectRadioBtn = firstRadioButton
  390. }
  391. pageNumInput.properties.isDisabled = false
  392. positionSelect.properties.isDisabled = false
  393. pageNumInput.reloadData()
  394. positionSelect.reloadData()
  395. }
  396. if(oldSelectRadioBtn != nil) {
  397. oldSelectRadioBtn?.properties.checkboxType = .normal
  398. oldSelectRadioBtn?.reloadData()
  399. }
  400. }
  401. @objc func insertDirectionAction(_ sender: NSView) {
  402. var oldSelectRadioBtn:ComponentRadio? = nil
  403. if sender == verticalRadioButton {
  404. if(horizontalRadioButton.properties.checkboxType == .selected) {
  405. oldSelectRadioBtn = horizontalRadioButton
  406. }
  407. } else if sender == horizontalRadioButton {
  408. if(verticalRadioButton.properties.checkboxType == .selected) {
  409. oldSelectRadioBtn = verticalRadioButton
  410. }
  411. }
  412. if(oldSelectRadioBtn != nil) {
  413. oldSelectRadioBtn?.properties.checkboxType = .normal
  414. oldSelectRadioBtn?.reloadData()
  415. }
  416. let widthString = widthInput.properties.text
  417. let heightString = heightInput.properties.text
  418. var width = widthString.stringToCGFloat()
  419. var height = heightString.stringToCGFloat()
  420. if(verticalRadioButton.properties.checkboxType == .selected) {
  421. if(width < height) {
  422. widthInput.properties.text = heightString
  423. heightInput.properties.text = widthString
  424. widthInput.reloadData()
  425. heightInput.reloadData()
  426. }
  427. } else if(horizontalRadioButton.properties.checkboxType == .selected){
  428. if(width > height) {
  429. widthInput.properties.text = heightString
  430. heightInput.properties.text = widthString
  431. widthInput.reloadData()
  432. heightInput.reloadData()
  433. }
  434. }
  435. }
  436. @objc func insertPageSizeAction(_ sender: NSView) {
  437. var oldSelectRadioBtn:ComponentRadio? = nil
  438. if sender == currentRadioButton {
  439. if(standardRadioButton.properties.checkboxType == .selected) {
  440. oldSelectRadioBtn = standardRadioButton
  441. standardSelect.properties.isDisabled = true
  442. standardSelect.reloadData()
  443. } else if (customizationRadioButton.properties.checkboxType == .selected){
  444. oldSelectRadioBtn = customizationRadioButton
  445. widthInput.properties.isDisabled = true
  446. widthInput.reloadData()
  447. heightInput.properties.isDisabled = true
  448. heightInput.reloadData()
  449. unitSelect.properties.isDisabled = true
  450. unitSelect.reloadData()
  451. }
  452. } else if sender == standardRadioButton {
  453. if(currentRadioButton.properties.checkboxType == .selected) {
  454. oldSelectRadioBtn = currentRadioButton
  455. } else if (customizationRadioButton.properties.checkboxType == .selected){
  456. oldSelectRadioBtn = customizationRadioButton
  457. widthInput.properties.isDisabled = true
  458. widthInput.reloadData()
  459. heightInput.properties.isDisabled = true
  460. heightInput.reloadData()
  461. unitSelect.properties.isDisabled = true
  462. unitSelect.reloadData()
  463. }
  464. standardSelect.properties.isDisabled = false
  465. standardSelect.reloadData()
  466. } else if sender == customizationRadioButton {
  467. if(currentRadioButton.properties.checkboxType == .selected) {
  468. oldSelectRadioBtn = currentRadioButton
  469. } else if (standardRadioButton.properties.checkboxType == .selected){
  470. oldSelectRadioBtn = standardRadioButton
  471. standardSelect.properties.isDisabled = true
  472. standardSelect.reloadData()
  473. }
  474. widthInput.properties.isDisabled = false
  475. widthInput.reloadData()
  476. heightInput.properties.isDisabled = false
  477. heightInput.reloadData()
  478. unitSelect.properties.isDisabled = false
  479. unitSelect.reloadData()
  480. }
  481. if(oldSelectRadioBtn != nil) {
  482. oldSelectRadioBtn?.properties.checkboxType = .normal
  483. oldSelectRadioBtn?.reloadData()
  484. }
  485. }
  486. }
  487. extension KMNPDFInsertBlankWindowController: ComponentInputNumberDelegate {
  488. func componentInputNumberDidValueChanged(inputNumber: ComponentInputNumber?) {
  489. if(inputNumber == pageNumInput) {
  490. }
  491. }
  492. }
  493. extension KMNPDFInsertBlankWindowController: ComponentSelectDelegate {
  494. func componentSelectDidSelect(view: ComponentSelect?, menuItemProperty: ComponentMenuitemProperty?) {
  495. if(view == unitSelect) {
  496. let width = widthInput.properties.text.stringToCGFloat()
  497. let height = heightInput.properties.text.stringToCGFloat()
  498. widthInput.properties.text = KMNPageSizeTool.conversion(with: unitSelect.properties.text ?? "mm", from: lastUnitString, value: width)
  499. heightInput.properties.text = KMNPageSizeTool.conversion(with: unitSelect.properties.text ?? "mm", from: lastUnitString, value: height)
  500. lastUnitString = unitSelect.properties.text ?? "mm"
  501. widthInput.reloadData()
  502. heightInput.reloadData()
  503. } else if (view == standardSelect) {
  504. } else if (view == positionSelect) {
  505. }
  506. }
  507. }
  508. extension KMNPDFInsertBlankWindowController: ComponentInputDelegate {
  509. //文字变化
  510. func componentInputDidChanged(inputView: ComponentInput) {
  511. if (inputView == widthInput) {
  512. let fValue = widthInput.properties.text.stringToCGFloat()
  513. if fValue > heightInput.properties.text.stringToCGFloat() {
  514. verticalRadioButton.properties.checkboxType = .selected
  515. horizontalRadioButton.properties.checkboxType = .normal
  516. } else {
  517. verticalRadioButton.properties.checkboxType = .normal
  518. horizontalRadioButton.properties.checkboxType = .selected
  519. }
  520. verticalRadioButton.reloadData()
  521. horizontalRadioButton.reloadData()
  522. } else if (inputView == heightInput) {
  523. let fValue = heightInput.properties.text.stringToCGFloat()
  524. if fValue > widthInput.properties.text.stringToCGFloat() {
  525. verticalRadioButton.properties.checkboxType = .normal
  526. horizontalRadioButton.properties.checkboxType = .selected
  527. } else {
  528. verticalRadioButton.properties.checkboxType = .selected
  529. horizontalRadioButton.properties.checkboxType = .normal
  530. }
  531. verticalRadioButton.reloadData()
  532. horizontalRadioButton.reloadData()
  533. }
  534. }
  535. }