KMNPDFInsertBlankWindowController.swift 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  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. override func updateUIThemeColor() {
  92. super.updateUIThemeColor()
  93. window?.contentView?.wantsLayer = true
  94. window?.contentView?.layer?.backgroundColor = ComponentLibrary.shared.getComponentColorFromKey("colorBorder/popUp").cgColor
  95. titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/1")
  96. sizeLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  97. directionLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  98. positionLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  99. currentRadioButton.reloadData()
  100. standardRadioButton.reloadData()
  101. customizationRadioButton.reloadData()
  102. firstRadioButton.reloadData()
  103. lastRadioButton.reloadData()
  104. pageRadioButton.reloadData()
  105. insertButton.reloadData()
  106. cancelButton.reloadData()
  107. unitSelect.reloadData()
  108. standardSelect.reloadData()
  109. positionSelect.reloadData()
  110. }
  111. override func updateUILanguage() {
  112. super.updateUILanguage()
  113. titleLabel.stringValue = KMLocalizedString("Insert Blank Page")
  114. sizeLabel.stringValue = KMLocalizedString("Page Size")
  115. directionLabel.stringValue = KMLocalizedString("Direction")
  116. positionLabel.stringValue = KMLocalizedString("Where to insert?")
  117. currentRadioButton.properties.text = KMLocalizedString("Current Size")
  118. standardRadioButton.properties.text = KMLocalizedString("Standard")
  119. customizationRadioButton.properties.text = KMLocalizedString("Custom")
  120. firstRadioButton.properties.text = KMLocalizedString("First")
  121. lastRadioButton.properties.text = KMLocalizedString(("Last"))
  122. pageRadioButton.properties.text = KMLocalizedString("Page")
  123. verticalRadioButton.properties.text = KMLocalizedString("Landscape pages")
  124. horizontalRadioButton.properties.text = KMLocalizedString("Portrait pages")
  125. setUpPositionSelctProperty()
  126. setUpUnitSelctProperty()
  127. setUpPageSizeSelctProperty()
  128. insertButton.properties.buttonText = KMLocalizedString("Insert")
  129. cancelButton.properties.buttonText = KMLocalizedString("Cancel")
  130. let positionSelectIndex = positionSelect.indexOfSelect()
  131. if positionSelectIndex == 0 {
  132. positionSelect.properties.text = KMLocalizedString("After")
  133. } else {
  134. positionSelect.properties.text = KMLocalizedString("Before")
  135. }
  136. currentRadioButton.reloadData()
  137. standardRadioButton.reloadData()
  138. customizationRadioButton.reloadData()
  139. firstRadioButton.reloadData()
  140. lastRadioButton.reloadData()
  141. pageRadioButton.reloadData()
  142. insertButton.reloadData()
  143. cancelButton.reloadData()
  144. positionSelect.reloadData()
  145. }
  146. override func initContentView() {
  147. super.initContentView()
  148. titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-medium")
  149. sizeLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-medium")
  150. directionLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-medium")
  151. sizeLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-medium")
  152. positionLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-medium")
  153. var currentPageDex = 0
  154. if(selectionIndexPaths?.count ?? 0 > 0) {
  155. pageRadioButton.properties.checkboxType = .selected
  156. let maxmumIndexPath = selectionIndexPaths?.max(by: { $0 < $1 })
  157. currentPageDex = maxmumIndexPath?.item ?? 0
  158. }
  159. let page = self.orgDocument?.page(at: UInt(currentPageDex)) as? CPDFPage
  160. let rect = page?.bounds ?? CGRectZero
  161. var width = KMNPageSizeTool.conversion(withUnit: "mm", value: (NSWidth(rect)/595 * 210))
  162. var height = KMNPageSizeTool.conversion(withUnit: "mm", value: (NSHeight(rect)/842 * 297))
  163. if((page?.rotation ?? 0) % 180 != 0) {
  164. width = KMNPageSizeTool.conversion(withUnit: "mm", value: (NSHeight(rect)/595 * 210))
  165. height = KMNPageSizeTool.conversion(withUnit: "mm", value: (NSWidth(rect)/842 * 297))
  166. }
  167. currentRadioButton.properties = ComponentCheckBoxProperty(size: .s,
  168. state: .normal,
  169. isDisabled: false,
  170. showhelp: false,
  171. text: String(format: "%@(%@ x %@mm)", KMLocalizedString("Current Size"),width,height),
  172. checkboxType: .selected)
  173. standardRadioButton.properties = ComponentCheckBoxProperty(size: .s,
  174. state: .normal,
  175. isDisabled: false,
  176. showhelp: false,
  177. text: KMLocalizedString("Standard"),
  178. checkboxType: .normal)
  179. customizationRadioButton.properties = ComponentCheckBoxProperty(size: .s,
  180. state: .normal,
  181. isDisabled: false,
  182. showhelp: false,
  183. text: KMLocalizedString("Custom"),
  184. checkboxType: .normal)
  185. firstRadioButton.properties = ComponentCheckBoxProperty(size: .s,
  186. state: .normal,
  187. isDisabled: false,
  188. showhelp: false,
  189. text: KMLocalizedString("First"),
  190. checkboxType: .normal)
  191. lastRadioButton.properties = ComponentCheckBoxProperty(size: .s,
  192. state: .normal,
  193. isDisabled: false,
  194. showhelp: false,
  195. text: KMLocalizedString("Last"),
  196. checkboxType: .normal)
  197. pageRadioButton.properties = ComponentCheckBoxProperty(size: .s,
  198. state: .normal,
  199. isDisabled: false,
  200. showhelp: false,
  201. text: KMLocalizedString("Page"),
  202. checkboxType: .normal)
  203. verticalRadioButton.properties = ComponentCheckBoxProperty(size: .s,
  204. state: .normal,
  205. isDisabled: false,
  206. showhelp: false,
  207. text: KMLocalizedString("Landscape pages"),
  208. checkboxType: .normal)
  209. horizontalRadioButton.properties = ComponentCheckBoxProperty(size: .s,
  210. state: .normal,
  211. isDisabled: false,
  212. showhelp: false,
  213. text: KMLocalizedString("Portrait pages"),
  214. checkboxType: .selected)
  215. unitSelect.properties = ComponentSelectProperties(size: .s,
  216. state: .normal,
  217. isDisabled: true,
  218. isError: false,
  219. leftIcon: false,
  220. placeholder: nil,
  221. errorText: nil,
  222. creatable: false,
  223. text: KMLocalizedString("mm", comment: ""))
  224. unitSelect.delegate = self
  225. standardSelect.properties = ComponentSelectProperties(size: .s,
  226. state: .normal,
  227. isDisabled: true,
  228. isError: false,
  229. leftIcon: false,
  230. placeholder: nil,
  231. errorText: nil,
  232. creatable: false,
  233. text: KMLocalizedString("A4", comment: ""))
  234. standardSelect.delegate = self
  235. positionSelect.properties = ComponentSelectProperties(size: .s,
  236. state: .normal,
  237. isDisabled: false,
  238. isError: false,
  239. leftIcon: false,
  240. placeholder: nil,
  241. errorText: nil,
  242. creatable: false,
  243. text: KMLocalizedString("After", comment: ""))
  244. positionSelect.delegate = self
  245. insertButton.properties = ComponentButtonProperty(type: .primary,
  246. size: .s,
  247. state: .normal,
  248. isDisable: false,
  249. buttonText: KMLocalizedString("Insert"))
  250. insertButton.setTarget(self, action: #selector(insertButtonClicked(_ :)))
  251. insertWidthButton.constant = insertButton.properties.propertyInfo.viewWidth
  252. cancelButton.properties = ComponentButtonProperty(type: .default_tertiary,
  253. size: .s,
  254. state: .normal,
  255. buttonText: KMLocalizedString("Cancel"))
  256. cancelButton.setTarget(self, action: #selector(cancelButtonClicked(_ :)))
  257. cancelWidthButton.constant = cancelButton.properties.propertyInfo.viewWidth
  258. firstRadioButton.setTarget(self, action: #selector(insertPositionAction(_:)))
  259. lastRadioButton.setTarget(self, action: #selector(insertPositionAction(_:)))
  260. pageRadioButton.setTarget(self, action: #selector(insertPositionAction(_:)))
  261. verticalRadioButton.setTarget(self, action: #selector(insertDirectionAction(_:)))
  262. horizontalRadioButton.setTarget(self, action: #selector(insertDirectionAction(_:)))
  263. currentRadioButton.setTarget(self, action: #selector(insertPageSizeAction(_:)))
  264. standardRadioButton.setTarget(self, action: #selector(insertPageSizeAction(_:)))
  265. customizationRadioButton.setTarget(self, action: #selector(insertPageSizeAction(_:)))
  266. pageNumInput.properties = ComponentInputNumberProperty(alignment: .left,
  267. size: .s,
  268. state: .normal,
  269. isError: false,
  270. showErrorInfo: false,
  271. isDisabled: true,
  272. showPrefix: false,
  273. showSuffix: false,
  274. minSize: 1,
  275. maxSize: Int(orgDocument?.pageCount ?? 1),
  276. text: SettingsManager.sharedInstance.autoSaveMinutes)
  277. pageNumInput.delegate = self
  278. let inputWidthProperty: ComponentInputProperty = ComponentInputProperty(size: .s,
  279. state:.pressed ,
  280. isError: false,
  281. showPrefix: false,
  282. showSuffix: false,
  283. showClear: false,
  284. isDisabled: true,
  285. placeholder: "210",
  286. text: "210")
  287. widthInput.properties = inputWidthProperty
  288. widthInput.delegate = self
  289. let inputHeightProperty: ComponentInputProperty = ComponentInputProperty(size: .s,
  290. state:.pressed ,
  291. isError: false,
  292. showPrefix: false,
  293. showSuffix: false,
  294. showClear: false,
  295. isDisabled: true,
  296. placeholder: "297",
  297. text: "297")
  298. heightInput.properties = inputHeightProperty
  299. heightInput.delegate = self
  300. pageCountLabel.stringValue = "/" + String(format: "%d", orgDocument?.pageCount ?? 0)
  301. setUpPositionSelctProperty()
  302. setUpUnitSelctProperty()
  303. setUpPageSizeSelctProperty()
  304. pageRadioWidthButton.constant = pageRadioButton.properties.propertyInfo.viewWidth
  305. cancelWidthButton.constant = cancelButton.properties.propertyInfo.viewWidth
  306. insertWidthButton.constant = insertButton.properties.propertyInfo.viewWidth
  307. standardRadioWidthButton.constant = standardRadioButton.properties.propertyInfo.viewWidth
  308. customizationRadioWidthButton.constant = customizationRadioButton.properties.propertyInfo.viewWidth
  309. verticalRadioWidthButton.constant = verticalRadioButton.properties.propertyInfo.viewWidth
  310. }
  311. override func windowDidLoad() {
  312. super.windowDidLoad()
  313. positionSelect.selectItemAtIndex(0)
  314. unitSelect.selectItemAtIndex(0)
  315. standardSelect.selectItemAtIndex(1)
  316. pageCountLabel.stringValue = "/" + String(format: "%d", orgDocument?.pageCount ?? 0)
  317. if(selectionIndexPaths?.count ?? 0 > 0) {
  318. pageRadioButton.properties.checkboxType = .selected
  319. let maxmumIndexPath = selectionIndexPaths?.max(by: { $0 < $1 })
  320. pageNumInput.properties.text = String((maxmumIndexPath?.item ?? 0)+1)
  321. pageNumInput.properties.isDisabled = false
  322. pageRadioButton.reloadData()
  323. pageNumInput.reloadData()
  324. } else {
  325. firstRadioButton.properties.checkboxType = .selected
  326. pageRadioButton.properties.checkboxType = .normal
  327. positionSelect.properties.isDisabled = true
  328. pageNumInput.properties.isDisabled = true
  329. firstRadioButton.reloadData()
  330. pageRadioButton.reloadData()
  331. pageNumInput.reloadData()
  332. positionSelect.reloadData()
  333. }
  334. }
  335. //MARK: - Action
  336. @objc func cancelButtonClicked(_ sender: NSView) {
  337. own_closeEndSheet()
  338. }
  339. @objc func insertButtonClicked(_ sender: NSView) {
  340. self.window?.makeFirstResponder(nil)
  341. var currentPageDex = 0
  342. if(selectionIndexPaths?.count ?? 0 > 0) {
  343. pageRadioButton.properties.checkboxType = .selected
  344. let maxmumIndexPath = selectionIndexPaths?.max(by: { $0 < $1 })
  345. currentPageDex = maxmumIndexPath?.item ?? 0
  346. }
  347. var height: CGFloat = 0
  348. var width: CGFloat = 0
  349. if currentRadioButton.properties.checkboxType == .selected {
  350. let page = self.orgDocument?.page(at: UInt(currentPageDex)) as? CPDFPage
  351. let rect = page?.bounds ?? .zero
  352. width = rect.size.width
  353. height = rect.size.height
  354. let w = KMPageSizeTool.conversion(withUnit: "mm", value: (NSWidth(rect)/595 * 210))
  355. let h = KMPageSizeTool.conversion(withUnit: "mm", value: (NSHeight(rect)/842 * 297))
  356. width = w.stringToCGFloat()
  357. height = h.stringToCGFloat()
  358. if((page?.rotation ?? 0) % 180 != 0) {
  359. width = h.stringToCGFloat()
  360. height = w.stringToCGFloat()
  361. }
  362. } else if standardRadioButton.properties.checkboxType == .selected {
  363. let sizeString = standardSelect.properties.text ?? KMNPaperSizeNameA4
  364. let tSize = KMPageSizeTool.getPaperSize(paperName: sizeString)
  365. width = KMPageSizeTool.conversion(withUnit: "mm", value: tSize.width).stringToCGFloat()
  366. height = KMPageSizeTool.conversion(withUnit: "mm", value: tSize.height).stringToCGFloat()
  367. } else if customizationRadioButton.properties.checkboxType == .selected {
  368. let unitString = unitSelect.properties.text ?? "mm"
  369. height = widthInput.properties.text.stringToCGFloat()
  370. width = heightInput.properties.text.stringToCGFloat()
  371. width = KMPageSizeTool.conversion(with: "mm", from: unitString, value: width).stringToCGFloat()
  372. height = KMPageSizeTool.conversion(with: "mm", from: unitString, value: height).stringToCGFloat()
  373. if(!(width > 0 && height > 0)) {
  374. let alert = NSAlert()
  375. alert.alertStyle = .critical
  376. alert.messageText = KMLocalizedString("Please enter the correct size.")
  377. alert.runModal()
  378. return
  379. }
  380. }
  381. width *= 595 / 210
  382. height *= 842 / 297
  383. var insertSize = CGSize(width: width, height: height)
  384. if(verticalRadioButton.properties.checkboxType == .selected) {
  385. if(width < height) {
  386. insertSize = CGSize(width: height, height: width)
  387. }
  388. } else if(horizontalRadioButton.properties.checkboxType == .selected){
  389. if(width > height) {
  390. insertSize = CGSize(width: height, height: width)
  391. }
  392. }
  393. var insetPageDex:Int = 0
  394. if firstRadioButton.properties.checkboxType == .selected {
  395. insetPageDex = 0
  396. } else if lastRadioButton.properties.checkboxType == .selected {
  397. insetPageDex = Int(orgDocument?.pageCount ?? 0)
  398. } else if pageRadioButton.properties.checkboxType == .selected {
  399. insetPageDex = Int(pageNumInput.properties.text ?? "0") ?? 0
  400. let positionSelectIndex = positionSelect.indexOfSelect()
  401. if (1 == positionSelectIndex) {
  402. insetPageDex -= 1
  403. }
  404. }
  405. callback?(insertSize, insetPageDex)
  406. own_closeEndSheet()
  407. }
  408. @objc func insertPositionAction(_ sender: NSView) {
  409. var oldSelectRadioBtn:ComponentRadio? = nil
  410. if sender == lastRadioButton {
  411. if(firstRadioButton.properties.checkboxType == .selected) {
  412. oldSelectRadioBtn = firstRadioButton
  413. } else if (pageRadioButton.properties.checkboxType == .selected){
  414. oldSelectRadioBtn = pageRadioButton
  415. pageNumInput.properties.isDisabled = true
  416. positionSelect.properties.isDisabled = true
  417. pageNumInput.reloadData()
  418. positionSelect.reloadData()
  419. }
  420. } else if sender == firstRadioButton {
  421. if(lastRadioButton.properties.checkboxType == .selected) {
  422. oldSelectRadioBtn = lastRadioButton
  423. } else if (pageRadioButton.properties.checkboxType == .selected){
  424. oldSelectRadioBtn = pageRadioButton
  425. pageNumInput.properties.isDisabled = true
  426. positionSelect.properties.isDisabled = true
  427. pageNumInput.reloadData()
  428. positionSelect.reloadData()
  429. }
  430. } else if sender == pageRadioButton {
  431. if(lastRadioButton.properties.checkboxType == .selected) {
  432. oldSelectRadioBtn = lastRadioButton
  433. } else if (firstRadioButton.properties.checkboxType == .selected){
  434. oldSelectRadioBtn = firstRadioButton
  435. }
  436. pageNumInput.properties.isDisabled = false
  437. positionSelect.properties.isDisabled = false
  438. pageNumInput.reloadData()
  439. positionSelect.reloadData()
  440. }
  441. if(oldSelectRadioBtn != nil) {
  442. oldSelectRadioBtn?.properties.checkboxType = .normal
  443. oldSelectRadioBtn?.reloadData()
  444. }
  445. }
  446. @objc func insertDirectionAction(_ sender: NSView) {
  447. var oldSelectRadioBtn:ComponentRadio? = nil
  448. if sender == verticalRadioButton {
  449. if(horizontalRadioButton.properties.checkboxType == .selected) {
  450. oldSelectRadioBtn = horizontalRadioButton
  451. }
  452. } else if sender == horizontalRadioButton {
  453. if(verticalRadioButton.properties.checkboxType == .selected) {
  454. oldSelectRadioBtn = verticalRadioButton
  455. }
  456. }
  457. if(oldSelectRadioBtn != nil) {
  458. oldSelectRadioBtn?.properties.checkboxType = .normal
  459. oldSelectRadioBtn?.reloadData()
  460. }
  461. let widthString = widthInput.properties.text
  462. let heightString = heightInput.properties.text
  463. var width = widthString.stringToCGFloat()
  464. var height = heightString.stringToCGFloat()
  465. if(verticalRadioButton.properties.checkboxType == .selected) {
  466. if(width < height) {
  467. widthInput.properties.text = heightString
  468. heightInput.properties.text = widthString
  469. widthInput.reloadData()
  470. heightInput.reloadData()
  471. }
  472. } else if(horizontalRadioButton.properties.checkboxType == .selected){
  473. if(width > height) {
  474. widthInput.properties.text = heightString
  475. heightInput.properties.text = widthString
  476. widthInput.reloadData()
  477. heightInput.reloadData()
  478. }
  479. }
  480. }
  481. @objc func insertPageSizeAction(_ sender: NSView) {
  482. var oldSelectRadioBtn:ComponentRadio? = nil
  483. if sender == currentRadioButton {
  484. if(standardRadioButton.properties.checkboxType == .selected) {
  485. oldSelectRadioBtn = standardRadioButton
  486. standardSelect.properties.isDisabled = true
  487. standardSelect.reloadData()
  488. } else if (customizationRadioButton.properties.checkboxType == .selected){
  489. oldSelectRadioBtn = customizationRadioButton
  490. widthInput.properties.isDisabled = true
  491. widthInput.reloadData()
  492. heightInput.properties.isDisabled = true
  493. heightInput.reloadData()
  494. unitSelect.properties.isDisabled = true
  495. unitSelect.reloadData()
  496. }
  497. } else if sender == standardRadioButton {
  498. if(currentRadioButton.properties.checkboxType == .selected) {
  499. oldSelectRadioBtn = currentRadioButton
  500. } else if (customizationRadioButton.properties.checkboxType == .selected){
  501. oldSelectRadioBtn = customizationRadioButton
  502. widthInput.properties.isDisabled = true
  503. widthInput.reloadData()
  504. heightInput.properties.isDisabled = true
  505. heightInput.reloadData()
  506. unitSelect.properties.isDisabled = true
  507. unitSelect.reloadData()
  508. }
  509. standardSelect.properties.isDisabled = false
  510. standardSelect.reloadData()
  511. } else if sender == customizationRadioButton {
  512. if(currentRadioButton.properties.checkboxType == .selected) {
  513. oldSelectRadioBtn = currentRadioButton
  514. } else if (standardRadioButton.properties.checkboxType == .selected){
  515. oldSelectRadioBtn = standardRadioButton
  516. standardSelect.properties.isDisabled = true
  517. standardSelect.reloadData()
  518. }
  519. widthInput.properties.isDisabled = false
  520. widthInput.reloadData()
  521. heightInput.properties.isDisabled = false
  522. heightInput.reloadData()
  523. unitSelect.properties.isDisabled = false
  524. unitSelect.reloadData()
  525. }
  526. if(oldSelectRadioBtn != nil) {
  527. oldSelectRadioBtn?.properties.checkboxType = .normal
  528. oldSelectRadioBtn?.reloadData()
  529. }
  530. }
  531. }
  532. extension KMNPDFInsertBlankWindowController: ComponentInputNumberDelegate {
  533. func componentInputNumberDidValueChanged(inputNumber: ComponentInputNumber?) {
  534. if(inputNumber == pageNumInput) {
  535. }
  536. }
  537. }
  538. extension KMNPDFInsertBlankWindowController: ComponentSelectDelegate {
  539. func componentSelectDidSelect(view: ComponentSelect?, menuItemProperty: ComponentMenuitemProperty?) {
  540. if(view == unitSelect) {
  541. let width = widthInput.properties.text.stringToCGFloat()
  542. let height = heightInput.properties.text.stringToCGFloat()
  543. widthInput.properties.text = KMNPageSizeTool.conversion(with: unitSelect.properties.text ?? "mm", from: lastUnitString, value: width)
  544. heightInput.properties.text = KMNPageSizeTool.conversion(with: unitSelect.properties.text ?? "mm", from: lastUnitString, value: height)
  545. lastUnitString = unitSelect.properties.text ?? "mm"
  546. widthInput.reloadData()
  547. heightInput.reloadData()
  548. } else if (view == standardSelect) {
  549. } else if (view == positionSelect) {
  550. }
  551. }
  552. }
  553. extension KMNPDFInsertBlankWindowController: ComponentInputDelegate {
  554. //文字变化
  555. func componentInputDidChanged(inputView: ComponentInput) {
  556. if (inputView == widthInput) {
  557. let fValue = widthInput.properties.text.stringToCGFloat()
  558. if fValue > heightInput.properties.text.stringToCGFloat() {
  559. verticalRadioButton.properties.checkboxType = .selected
  560. horizontalRadioButton.properties.checkboxType = .normal
  561. } else {
  562. verticalRadioButton.properties.checkboxType = .normal
  563. horizontalRadioButton.properties.checkboxType = .selected
  564. }
  565. verticalRadioButton.reloadData()
  566. horizontalRadioButton.reloadData()
  567. } else if (inputView == heightInput) {
  568. let fValue = heightInput.properties.text.stringToCGFloat()
  569. if fValue > widthInput.properties.text.stringToCGFloat() {
  570. verticalRadioButton.properties.checkboxType = .normal
  571. horizontalRadioButton.properties.checkboxType = .selected
  572. } else {
  573. verticalRadioButton.properties.checkboxType = .selected
  574. horizontalRadioButton.properties.checkboxType = .normal
  575. }
  576. verticalRadioButton.reloadData()
  577. horizontalRadioButton.reloadData()
  578. }
  579. }
  580. }