// // KMNContentEditPopToolbarWindow.swift // PDF Reader Pro // // Created by 丁林圭 on 2025/2/6. // import Cocoa class KMNContentEditPopToolbarWindow: NSWindow { static let shared = KMNContentEditPopToolbarWindow() public var editContentPopMode:KMNEditContentPopMode = KMNEditContentPopMode(currentEditAreas: []) convenience init() { let rect = NSRect(x: 0, y: 0, width: 400, height: 44) let styleMask: NSWindow.StyleMask = [.fullSizeContentView] self.init(contentRect: rect, styleMask: styleMask, backing: .buffered, defer: false) } override init(contentRect: NSRect, styleMask style: NSWindow.StyleMask, backing backingStoreType: NSWindow.BackingStoreType, defer flag: Bool) { super.init(contentRect: contentRect, styleMask: style, backing: backingStoreType, defer: flag) let contentViewC = KMNPopContentEditViewController.shared self.contentViewController = contentViewC self.titlebarAppearsTransparent = true self.titleVisibility = .hidden self.isMovable = false self.contentView?.wantsLayer = true self.contentView?.layer?.cornerRadius = 4 self.contentView?.layer?.masksToBounds = true self.backgroundColor = .clear } func show(relativeTo positioningRect: NSRect, of positioningView: CPDFListView, preferredEdge: NSRectEdge) { self.orderFront(nil) let contentViewC = KMNPopContentEditViewController.shared } //MARK: - Public public func updateFrame(listView:CPDFListView) { let editingAreas = listView.km_EditingAreas() let page = editingAreas.first?.page let windowFram = listView.window?.frame ?? CGRectZero if(page != nil) { let pageRect = listView.selectionMultipleBounds(withEditArea: editingAreas) let positioningRect = listView.convert(pageRect, from: page!) let view: NSView? = nil let position = listView.convert(positioningRect, to: view) var positionNew = position.origin positionNew.x += windowFram.origin.x + position.width/2 positionNew.y += windowFram.origin.y + position.height var positionRect = self.frame positionRect.origin.x = positionNew.x - positionRect.width/2 positionRect.origin.y = positionNew.y + popOffSet + CGFloat(truncating: listView.editingConfig().editAreaMargin) var listViewWindRect = listView.convert(listView.frame, to: view) listViewWindRect.origin.x += windowFram.origin.x listViewWindRect.origin.y += windowFram.origin.y if CGRectGetMaxY(positionRect) > CGRectGetMaxY(listViewWindRect) { positionRect.origin.y = positionNew.y - popOffSet - position.height - positionRect.size.height } if CGRectGetMinX(positionRect) < CGRectGetMinX(listViewWindRect) { positionRect.origin.x = CGRectGetMinX(listViewWindRect) } if CGRectGetMaxX(positionRect) > CGRectGetMaxX(listViewWindRect) { positionRect.origin.x = CGRectGetMaxX(listViewWindRect) - positionRect.width } self.setFrame(positionRect, display: true) let popA = KMNPopAnnotationViewController.shared popA.updateUILanguage() } } public func closeWindow(listView:CPDFListView?) { if self.isVisible == true { listView?.window?.removeChildWindow(self) self.orderBack(nil) } let contentViewC = KMNPopContentEditViewController.shared contentViewC.closePopView() } }