123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- //
- // NSWindowController+KMExtension.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2023/7/27.
- //
- import Foundation
- @objc protocol KMForceProtocol: NSObjectProtocol {
- @objc optional func setForceOnTop(_ flag: Bool)
- }
- extension NSWindowController {
- override func km_window() -> NSWindow? {
- return self.window
- }
-
- func forceSubwindowsOnTop(_ flag: Bool) {
- guard let doc = self.document as? NSDocument else {
- NSSound.beep()
- return
- }
- for wc in doc.windowControllers {
- if wc.responds(to: #selector(setForceOnTop)) {
- wc.setForceOnTop(flag)
- }
- }
- }
- }
- extension NSWindowController: KMForceProtocol {
- func setForceOnTop(_ flag: Bool) {
- // no things.
- }
- }
- // MARK: - 互动模式
- @objc enum KMInteractionMode: Int {
- case normal = 0 // 常规模式
- case fullScreen
- case presentation // 幻灯片模式
- case legacyFullScreen
- }
- @objc protocol KMInteractionModeProtocol: NSObjectProtocol {
- @objc optional var interactionMode: KMInteractionMode { get }
- @objc optional var isSwitchingFullScreen: Bool { get }
-
- @objc optional func canEnterPresentation() -> Bool
- @objc optional func canExitPresentation() -> Bool
-
- @objc optional func enterPresentation()
- @objc optional func exitPresentation()
- }
- @objc protocol KMInteractionProviderProtocol: NSObjectProtocol {
- @objc optional func providerContentView(fullScreenWindow: NSWindow, inset: CGFloat) -> NSView?
- }
- extension NSWindowController: KMInteractionModeProtocol {
- var interactionMode: KMInteractionMode {
- get {
- if let win = self.window?.interactionParent {
- return win.interactionMode
- }
- return self.window?.interactionMode ?? .normal
- }
- }
-
- var isSwitchingFullScreen: Bool {
- get {
- if let win = self.window?.interactionParent {
- return win.isSwitchingFullScreen
- }
- return self.window?.isSwitchingFullScreen ?? false
- }
- }
-
- func canEnterPresentation() -> Bool {
- if let win = self.window?.interactionParent {
- return win.canEnterPresentation()
- }
- return self.window?.canEnterPresentation() ?? false
- }
-
- func canExitPresentation() -> Bool {
- if let win = self.window?.interactionParent {
- return win.canExitPresentation()
- }
- return self.window?.canExitPresentation() ?? false
- }
- }
- @objc extension NSView: KMInteractionModeProtocol {
- var interactionMode: KMInteractionMode {
- get {
- if let win = self.window?.interactionParent {
- return win.interactionMode
- }
- return self.window?.interactionMode ?? .normal
- }
- }
-
- var isSwitchingFullScreen: Bool {
- get {
- if let win = self.window?.interactionParent {
- return win.isSwitchingFullScreen
- }
- return self.window?.isSwitchingFullScreen ?? false
- }
- }
-
- func canEnterPresentation() -> Bool {
- if let win = self.window?.interactionParent {
- return win.canEnterPresentation()
- }
- return self.window?.canEnterPresentation() ?? false
- }
-
- func canExitPresentation() -> Bool {
- if let win = self.window?.interactionParent {
- return win.canExitPresentation()
- }
- return self.window?.canExitPresentation() ?? false
- }
- }
- @objc extension NSViewController: KMInteractionModeProtocol {
- var interactionMode: KMInteractionMode {
- get {
- if let win = self.view.window?.interactionParent {
- return win.interactionMode
- }
- return self.view.window?.interactionMode ?? .normal
- }
- }
-
- var isSwitchingFullScreen: Bool {
- get {
- if let win = self.view.window?.interactionParent {
- return win.isSwitchingFullScreen
- }
- return self.view.window?.isSwitchingFullScreen ?? false
- }
- }
-
- func canEnterPresentation() -> Bool {
- if let win = self.view.window?.interactionParent {
- return win.canEnterPresentation()
- }
- return self.view.window?.canEnterPresentation() ?? false
- }
-
- func canExitPresentation() -> Bool {
- if let win = self.view.window?.interactionParent {
- return win.canExitPresentation()
- }
- return self.view.window?.canExitPresentation() ?? false
- }
- }
|