// // KMBrowserWindowController+Actions.swift // PDF Reader Pro // // Created by tangchao on 2024/2/20. // import Foundation // MARK: - 幻灯片 extension KMBrowserWindowController { func canEnterFullscreen() -> Bool { if self.isSwitchingFullScreen { return false } if let mainVc = (self.document as? KMMainDocument)?.mainViewController { if mainVc.canEnterFullscreen() == false { return false } } let mode = self.interactionMode if mode == .fullScreen || mode == .legacyFullScreen { return false } let cnt = self.window?.tabbedWindows?.count ?? 0 return cnt < 2 } override func canEnterPresentation() -> Bool { let can = super.canEnterPresentation() if can == false { return false } if let mainVc = (self.document as? KMMainDocument)?.mainViewController { if mainVc.canEnterPresentation() == false { return false } } return can } func canExitFullscreen() -> Bool { if self.isSwitchingFullScreen == false { return false } let mode = self.interactionMode if mode == .fullScreen || mode == .legacyFullScreen { return true } return false } func enterPresentation() { self.window?.enterPresentation() } func exitFullscreen() { let wasInteractionMode = self.interactionMode if self.canExitFullscreen() == false && self.canExitPresentation() == false { return } if wasInteractionMode == .fullScreen { self.window?.toggleFullScreen(nil) return } var view: NSView? var contentView: NSView? self.window?.isSwitchingFullScreen = true if wasInteractionMode == .legacyFullScreen { let doc = self.document as? KMMainDocument view = doc?.mainViewController?.pdfSplitView } else { let doc = self.document as? KMMainDocument view = doc?.mainViewController?.listView } let doc = self.document as? KMMainDocument let mainViewController = doc?.mainViewController mainViewController?.presentationTopViewController?.view.removeFromSuperview() if let v = view { self.fadeOutFullScreenView(v) view?.frame = contentView?.bounds ?? .zero view?.autoresizingMask = [.width, .height] contentView?.addSubview(v) (v as? CPDFListView)?.isPresentationMode = false (v as? CPDFListView)?.layoutDocumentView() (v as? CPDFListView)?.requiresDisplay() if (v as? CPDFListView)?.isEnterPresentationDrawMode() == true { (v as? CPDFListView)?.exitPresentationDrawMode() } } if let mainVc = (self.document as? KMMainDocument)?.mainViewController { mainVc.exitFullscreenMode() } self.window?.isSwitchingFullScreen = false self.forceSubwindowsOnTop(false) self.window?.interactionMode = .normal self.fadeOutFullScreenWindow() self.synchronizeWindowTitleWithDocumentName() } func fadeOutFullScreenView(_ view: NSView) { guard let fullScreenWindow = self.window as? KMFullScreenWindow else { NSSound.beep() return } let fadeWindow = KMFullScreenWindow(screen: fullScreenWindow.screen ?? NSScreen.main!, bgColor: fullScreenWindow.backgroundColor, level: fullScreenWindow.level.rawValue, isMain: false) fadeWindow.alphaValue = 0 fadeWindow.order(.above, relativeTo: fullScreenWindow.windowNumber) fadeWindow.fadeInBlocking() view.removeFromSuperview() fullScreenWindow.display() fullScreenWindow.delegate = nil fullScreenWindow.makeFirstResponder(nil) fadeWindow.orderOut(nil) } func fadeOutFullScreenWindow() { guard let fullScreenWindow = self.window as? KMFullScreenWindow else { NSSound.beep() return } let mainVc = (self.document as? KMMainDocument)?.mainViewController let mainWindow = fullScreenWindow.interactionParent let collectionBehavior = mainWindow?.collectionBehavior self.window = mainWindow mainWindow?.alphaValue = 0 if let data = mainWindow?.responds(to: NSSelectorFromString("setAnimationBehavior:")), data { mainWindow?.animationBehavior = .none } // trick to make sure the main window shows up in the same space as the fullscreen window fullScreenWindow.addChildWindow(mainWindow!, ordered: .below) fullScreenWindow.removeChildWindow(mainWindow!) fullScreenWindow.level = .popUpMenu // these can change due to the child window trick mainWindow?.level = .normal mainWindow?.alphaValue = 1.0 mainWindow?.collectionBehavior = collectionBehavior! mainWindow?.display() mainWindow?.makeFirstResponder(mainVc?.listView) mainWindow?.recalculateKeyViewLoop() mainWindow?.delegate = self mainWindow?.makeKey() if let data = mainWindow?.responds(to: NSSelectorFromString("setAnimationBehavior:")), data { mainWindow?.animationBehavior = .default } NSApp.removeWindowsItem(fullScreenWindow) fullScreenWindow.fadeOut() } }