NSWindow+PopOver.swift 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //
  2. // NSWindow+PopOver.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by kdanmobile on 2023/10/26.
  6. //
  7. import Foundation
  8. //var KMWindowPopOverKey = "KMWindowPopOverKey"
  9. //var KMWindowPopOverSourcesRectKey = "KMWindowPopOverSourcesRectKey"
  10. //extension NSWindow {
  11. // var popover: NSPopover? {
  12. // get {
  13. // return objc_getAssociatedObject(self, &KMWindowPopOverKey) as? NSPopover
  14. // }
  15. // set {
  16. // objc_setAssociatedObject(self, &KMWindowPopOverKey, newValue, .OBJC_ASSOCIATION_RETAIN)
  17. // }
  18. // }
  19. //
  20. // var sourcesRect: CGRect? {
  21. // get {
  22. // guard let value = objc_getAssociatedObject(self, &KMWindowPopOverSourcesRectKey) as? NSValue else {
  23. // return nil
  24. // }
  25. // return value.rectValue
  26. // }
  27. // set {
  28. // if let newValue = newValue {
  29. // let value = NSValue(rect: newValue)
  30. // objc_setAssociatedObject(self, &KMWindowPopOverSourcesRectKey, value, .OBJC_ASSOCIATION_RETAIN)
  31. // } else {
  32. // objc_setAssociatedObject(self, &KMWindowPopOverSourcesRectKey, nil, .OBJC_ASSOCIATION_RETAIN)
  33. // }
  34. // }
  35. // }
  36. //
  37. // open override func mouseMoved(with event: NSEvent) {
  38. // super.mouseMoved(with: event)
  39. // let point = event.locationInWindow
  40. // if NSStringFromClass(event.window!.classForCoder).elementsEqual("_NSPopoverWindow") == false {
  41. // if let data = sourcesRect?.contains(point), data == false {
  42. // if (self.popover != nil) {
  43. // NotificationCenter.default.post(name: NSNotification.Name("KMPopOverClosedByWindowNotification"), object: self.popover)
  44. // popover!.close()
  45. // self.popover = nil
  46. // self.sourcesRect = CGRect.null
  47. // }
  48. // }
  49. // }
  50. // }
  51. //}