123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- //
- // KMBrowserWindowController+Actions.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2024/2/20.
- //
- import Foundation
- // MARK: - Actions
- @objc extension KMBrowserWindowController {
-
- }
- // MARK: - 幻灯片
- extension KMBrowserWindowController {
- func canEnterFullscreen() -> Bool {
- if self.isSwitchingFullScreen {
- return false
- }
- // if useNativeFullScreen() {
- // return interactionMode == .SKNormalMode || interactionMode == .SKPresentationMode
- // } else {
- 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
- }
- // let backgroundColor = UserDefaults.standard.color(forKey: "SKBackgroundColorKey")
- var view: NSView?
- var contentView: NSView?
- // PDFPage *page = [[self pdfView] currentPage];
- //
- self.window?.isSwitchingFullScreen = true
- //
- // if ([[findController view] window])
- // [findController toggleAboveView:nil animate:NO];
- //
- if wasInteractionMode == .legacyFullScreen {
- let doc = self.document as? KMMainDocument
- view = doc?.mainViewController?.pdfSplitView
- contentView = doc?.mainViewController?.centerContentView
- } else {
- let doc = self.document as? KMMainDocument
- view = doc?.mainViewController?.listView
- contentView = doc?.mainViewController?.readContentView
- }
- self.hideLeftSideWindow()
- self.hideRightSideWindow()
- // do this first, otherwise the navigation window may be covered by fadeWindow and then reveiled again, which looks odd
- // [pdfView setInteractionMode:SKNormalMode];
- //
- // this should be done before exitPresentationMode to get a smooth transition
- if let v = view {
- self.fadeOutFullScreenView(v)
- view?.frame = contentView?.bounds ?? .zero
- contentView?.addSubview(v)
- v.mas_makeConstraints { make in
- make?.left.mas_equalTo()(0)
- make?.right.mas_equalTo()(0)
- make?.top.mas_equalTo()(0)
- make?.bottom.mas_equalTo()(0)
- }
-
- (v as? CPDFListView)?.layoutDocumentView()
- (v as? CPDFListView)?.requiresDisplay()
- }
- if let mainVc = (self.document as? KMMainDocument)?.mainViewController {
- mainVc.exitFullscreenMode()
- }
- self.window?.isSwitchingFullScreen = false
- self.forceSubwindowsOnTop(false)
- //
- self.window?.interactionMode = .normal
- // if (_isShowToolbar) {
- // [self.toolbarViewController hiddenToolbar:NO];
- // }
- self.fadeOutFullScreenWindow()
- // the page number may have changed
- self.synchronizeWindowTitleWithDocumentName()
- self.removeBlankingWindows()
- }
-
- func hideLeftSideWindow() {
- // if leftSideViewController.view.window == leftSideWindow {
- // self.leftView.remove()
- // if leftSideWindow.firstResponder()?.isDescendant(of: leftSideController.view()) {
- // leftSideWindow.makeFirstResponder(nil)
- // }
- // leftSideController.view().setFrame(SKShrinkRect(NSInsetRect(leftSideContentView.bounds, -1.0, -1.0), 1.0, .maxYEdge))
- // leftSideContentView.addSubview(leftSideController.view())
- //
- // if self.interactionMode() == SKPresentationMode {
- // self.setLeftSidePaneState(mwcFlags.savedLeftSidePaneState)
- // }
- //
- // leftSideWindow = nil
- // }
- }
-
- func hideRightSideWindow() {
- // if rightSideController.view().window() == rightSideWindow {
- // rightSideWindow.remove()
- // if rightSideWindow.firstResponder()?.isDescendant(of: rightSideController.view()) {
- // rightSideWindow.makeFirstResponder(nil)
- // }
- // rightSideController.view().setFrame(SKShrinkRect(NSInsetRect(rightSideContentView.bounds, -1.0, -1.0), 1.0, .maxYEdge))
- // rightSideContentView.addSubview(rightSideController.view())
- //
- // rightSideWindow = nil
- // }
- }
-
- func removeBlankingWindows() {
- // [blankingWindows makeObjectsPerformSelector:@selector(fadeOut)];
- // blankingWindows = nil;
- }
-
- // func fadeInFullScreenWindow(with backgroundColor: NSColor, level: Int) {
- // self._mainWindow = self.view.window
- // let fullScreenWindow = KMFullScreenWindow(screen: (self.mainWindow?.screen ?? NSScreen.main)!, bgColor: backgroundColor, level: NSWindow.Level.popUpMenu.rawValue, isMain: true)
- //
- // self.mainWindow?.delegate = nil
- // fullScreenWindow.fadeInBlocking()
- // self.browserWindowController?.window = fullScreenWindow
- // fullScreenWindow.makeKey()
- //
- //// NSApp.updatePresentationOptions(for: fullScreenWindow)
- //
- // let sel = NSSelectorFromString("setAnimationBehavior:")
- // if self.mainWindow?.responds(to: sel) ?? false{
- // self.mainWindow?.animationBehavior = .none
- // }
- // self.mainWindow?.orderOut(nil)
- // if self.mainWindow?.responds(to: sel) ?? false{
- // self.mainWindow?.animationBehavior = .default
- // }
- // fullScreenWindow.level = NSWindow.Level(rawValue: level)
- // fullScreenWindow.orderFront(nil)
- //// NSApp.addWindowsItem(fullScreenWindow, title: windowTitleForDocumentDisplayName(self.document?.displayName) ?? "", filename: false)
- // }
-
- 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 = mainVc?.mainWindow
- 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()
- // [NSApp updatePresentationOptionsForWindow:mainWindow];
-
- if let data = mainWindow?.responds(to: NSSelectorFromString("setAnimationBehavior:")), data {
- mainWindow?.animationBehavior = .default
- }
- NSApp.removeWindowsItem(fullScreenWindow)
- fullScreenWindow.fadeOut()
- }
- }
|