KMBrowserWindowController+Actions.swift 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. //
  2. // KMBrowserWindowController+Actions.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2024/2/20.
  6. //
  7. import Foundation
  8. // MARK: - Actions
  9. @objc extension KMBrowserWindowController {
  10. }
  11. // MARK: - 幻灯片
  12. extension KMBrowserWindowController {
  13. func canEnterFullscreen() -> Bool {
  14. if self.isSwitchingFullScreen {
  15. return false
  16. }
  17. // if useNativeFullScreen() {
  18. // return interactionMode == .SKNormalMode || interactionMode == .SKPresentationMode
  19. // } else {
  20. // if let mainVc = (self.document as? KMMainDocument)?.mainViewController {
  21. // if mainVc.canEnterFullscreen() == false {
  22. // return false
  23. // }
  24. // }
  25. let mode = self.interactionMode
  26. if mode == .fullScreen || mode == .legacyFullScreen {
  27. return false
  28. }
  29. let cnt = self.window?.tabbedWindows?.count ?? 0
  30. return cnt < 2
  31. }
  32. override func canEnterPresentation() -> Bool {
  33. let can = super.canEnterPresentation()
  34. if can == false {
  35. return false
  36. }
  37. // if let mainVc = (self.document as? KMMainDocument)?.pdfViewController {
  38. // if mainVc.canEnterPresentation() == false {
  39. // return false
  40. // }
  41. // }
  42. return can
  43. }
  44. func canExitFullscreen() -> Bool {
  45. if self.isSwitchingFullScreen == false {
  46. return false
  47. }
  48. let mode = self.interactionMode
  49. if mode == .fullScreen || mode == .legacyFullScreen {
  50. return true
  51. }
  52. return false
  53. }
  54. // 进入幻灯片
  55. func enterPresentation() {
  56. self.window?.enterPresentation()
  57. }
  58. func exitFullscreen() {
  59. let wasInteractionMode = self.interactionMode
  60. if self.canExitFullscreen() == false && self.canExitPresentation() == false {
  61. return
  62. }
  63. if wasInteractionMode == .fullScreen {
  64. self.window?.toggleFullScreen(nil)
  65. return
  66. }
  67. var view: NSView?
  68. var contentView: NSView?
  69. self.window?.isSwitchingFullScreen = true
  70. if wasInteractionMode == .legacyFullScreen {
  71. let doc = self.document as? KMMainDocument
  72. // view = doc?.mainViewController?.pdfSplitView
  73. // contentView = doc?.mainViewController?.centerContentView
  74. } else {
  75. let doc = self.document as? KMMainDocument
  76. // view = doc?.mainViewController?.listView
  77. // contentView = doc?.mainViewController?.readContentView
  78. }
  79. self.hideLeftSideWindow()
  80. self.hideRightSideWindow()
  81. let doc = self.document as? KMMainDocument
  82. // let mainViewController = doc?.mainViewController
  83. //
  84. // mainViewController?.presentationTopViewController?.view.removeFromSuperview()
  85. //
  86. // if let v = view {
  87. // self.fadeOutFullScreenView(v)
  88. // view?.frame = contentView?.bounds ?? .zero
  89. // contentView?.addSubview(v)
  90. // v.mas_makeConstraints { make in
  91. // make?.left.mas_equalTo()(0)
  92. // make?.right.mas_equalTo()(0)
  93. // make?.top.mas_equalTo()(0)
  94. // make?.bottom.mas_equalTo()(0)
  95. // }
  96. // (v as? CPDFListView)?.isPresentationMode = false
  97. // (v as? CPDFListView)?.layoutDocumentView()
  98. // (v as? CPDFListView)?.requiresDisplay()
  99. // if (v as? CPDFListView)?.isEnterPresentationDrawMode() == true {
  100. // (v as? CPDFListView)?.exitPresentationDrawMode()
  101. // }
  102. // }
  103. //
  104. // if let mainVc = (self.document as? KMMainDocument)?.mainViewController {
  105. // mainVc.exitFullscreenMode()
  106. // }
  107. self.window?.isSwitchingFullScreen = false
  108. self.forceSubwindowsOnTop(false)
  109. self.window?.interactionMode = .normal
  110. self.fadeOutFullScreenWindow()
  111. self.synchronizeWindowTitleWithDocumentName()
  112. self.removeBlankingWindows()
  113. }
  114. func hideLeftSideWindow() {
  115. }
  116. func hideRightSideWindow() {
  117. }
  118. func removeBlankingWindows() {
  119. }
  120. func fadeOutFullScreenView(_ view: NSView) {
  121. guard let fullScreenWindow = self.window as? KMFullScreenWindow else {
  122. NSSound.beep()
  123. return
  124. }
  125. let fadeWindow = KMFullScreenWindow(screen: fullScreenWindow.screen ?? NSScreen.main!, bgColor: fullScreenWindow.backgroundColor, level: fullScreenWindow.level.rawValue, isMain: false)
  126. fadeWindow.alphaValue = 0
  127. fadeWindow.order(.above, relativeTo: fullScreenWindow.windowNumber)
  128. fadeWindow.fadeInBlocking()
  129. view.removeFromSuperview()
  130. fullScreenWindow.display()
  131. fullScreenWindow.delegate = nil
  132. fullScreenWindow.makeFirstResponder(nil)
  133. fadeWindow.orderOut(nil)
  134. }
  135. func fadeOutFullScreenWindow() {
  136. guard let fullScreenWindow = self.window as? KMFullScreenWindow else {
  137. NSSound.beep()
  138. return
  139. }
  140. let mainVc = (self.document as? KMMainDocument)?.pdfViewController
  141. let mainWindow = fullScreenWindow.interactionParent
  142. let collectionBehavior = mainWindow?.collectionBehavior
  143. self.window = mainWindow
  144. mainWindow?.alphaValue = 0
  145. if let data = mainWindow?.responds(to: NSSelectorFromString("setAnimationBehavior:")), data {
  146. mainWindow?.animationBehavior = .none
  147. }
  148. // trick to make sure the main window shows up in the same space as the fullscreen window
  149. fullScreenWindow.addChildWindow(mainWindow!, ordered: .below)
  150. fullScreenWindow.removeChildWindow(mainWindow!)
  151. fullScreenWindow.level = .popUpMenu
  152. // these can change due to the child window trick
  153. mainWindow?.level = .normal
  154. mainWindow?.alphaValue = 1.0
  155. mainWindow?.collectionBehavior = collectionBehavior!
  156. mainWindow?.display()
  157. // mainWindow?.makeFirstResponder(mainVc?.listView)
  158. mainWindow?.recalculateKeyViewLoop()
  159. mainWindow?.delegate = self
  160. mainWindow?.makeKey()
  161. if let data = mainWindow?.responds(to: NSSelectorFromString("setAnimationBehavior:")), data {
  162. mainWindow?.animationBehavior = .default
  163. }
  164. NSApp.removeWindowsItem(fullScreenWindow)
  165. fullScreenWindow.fadeOut()
  166. }
  167. }