|
@@ -32,11 +32,14 @@ enum KMLineWellDisplayStyle: Int {
|
|
|
|
|
|
class KMLineWell: NSControl {
|
|
|
|
|
|
- public static let widthKey = SKLineWellLineWidthKey
|
|
|
- public static let styleKey = SKLineWellStyleKey
|
|
|
- public static let dashPatternKey = SKLineWellDashPatternKey
|
|
|
- public static let startLineStyleKey = SKLineWellStartLineStyleKey
|
|
|
- public static let endLineStyleKey = SKLineWellEndLineStyleKey
|
|
|
+ public static let widthKey = SKLineWellLineWidthKey
|
|
|
+ public static let styleKey = SKLineWellStyleKey
|
|
|
+ public static let dashPatternKey = SKLineWellDashPatternKey
|
|
|
+ public static let startLineStyleKey = SKLineWellStartLineStyleKey
|
|
|
+ public static let endLineStyleKey = SKLineWellEndLineStyleKey
|
|
|
+
|
|
|
+ public static let lineStylePboardTypeString = SKPasteboardTypeLineStyle
|
|
|
+ public static let lineStylePboardType = NSPasteboard.PasteboardType(rawValue: SKPasteboardTypeLineStyle)
|
|
|
|
|
|
private var _lineWidth: CGFloat = 2
|
|
|
var lineWidth: CGFloat {
|
|
@@ -265,11 +268,13 @@ class KMLineWell: NSControl {
|
|
|
NSGraphicsContext.restoreGraphicsState()
|
|
|
}
|
|
|
|
|
|
- if self.refusesFirstResponder == false && NSApp.isActive && self.window!.isKeyWindow && self.window!.firstResponder == self {
|
|
|
- NSGraphicsContext.saveGraphicsState()
|
|
|
- NSFocusRingPlacement.only.set()
|
|
|
- bounds.fill()
|
|
|
- NSGraphicsContext.restoreGraphicsState()
|
|
|
+ if self.refusesFirstResponder == false && NSApp.isActive && self.isEqual(to: self.window?.firstResponder) {
|
|
|
+ if let data = self.window?.isKeyWindow, data {
|
|
|
+ NSGraphicsContext.saveGraphicsState()
|
|
|
+ NSFocusRingPlacement.only.set()
|
|
|
+ bounds.fill()
|
|
|
+ NSGraphicsContext.restoreGraphicsState()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -305,12 +310,11 @@ class KMLineWell: NSControl {
|
|
|
|
|
|
let pboard = NSPasteboard(name: .drag)
|
|
|
pboard.clearContents()
|
|
|
- pboard.setPropertyList(dict, forType: NSPasteboard.PasteboardType(rawValue: SKPasteboardTypeLineStyle))
|
|
|
+ pboard.setPropertyList(dict, forType: Self.lineStylePboardType)
|
|
|
|
|
|
let bounds = self.bounds
|
|
|
/*beginDraggingSessionWithItems:event:source: instead*/
|
|
|
// [self dragImage:[self dragImage] at:bounds.origin offset:NSZeroSize event:theEvent pasteboard:pboard source:self slideBack:YES];
|
|
|
-
|
|
|
keepOn = false
|
|
|
break
|
|
|
// }
|
|
@@ -376,6 +380,69 @@ class KMLineWell: NSControl {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // MARK: - NSDraggingDestination
|
|
|
+// - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal {
|
|
|
+// return NSDragOperationGeneric;
|
|
|
+// }
|
|
|
+
|
|
|
+ override func draggingEntered(_ sender: NSDraggingInfo) -> NSDragOperation {
|
|
|
+ if self.isEnabled && self.isEqual(to: sender.draggingSource) == false && sender.draggingPasteboard.canReadItem(withDataConformingToTypes: [Self.lineStylePboardTypeString]) {
|
|
|
+ self.isHighlighted = true
|
|
|
+ self.setKeyboardFocusRingNeedsDisplay(self.bounds)
|
|
|
+ self.needsDisplay = true
|
|
|
+ return .every
|
|
|
+ }
|
|
|
+ return NSDragOperation(rawValue: 0)
|
|
|
+ }
|
|
|
+
|
|
|
+ override func draggingExited(_ sender: NSDraggingInfo?) {
|
|
|
+ if self.isEnabled && self.isEqual(to: sender?.draggingSource) == false {
|
|
|
+ if let pboard = sender?.draggingPasteboard, pboard.canReadItem(withDataConformingToTypes: [Self.lineStylePboardTypeString]) {
|
|
|
+ self.isHighlighted = false
|
|
|
+ self.setKeyboardFocusRingNeedsDisplay(self.bounds)
|
|
|
+ self.needsDisplay = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override func prepareForDragOperation(_ sender: NSDraggingInfo) -> Bool {
|
|
|
+ if self.isEnabled == false {
|
|
|
+ return self.isEnabled
|
|
|
+ }
|
|
|
+ if self.isEqual(to: sender.draggingSource) == false {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return sender.draggingPasteboard.canReadItem(withDataConformingToTypes: [Self.lineStylePboardTypeString])
|
|
|
+ }
|
|
|
+
|
|
|
+ override func performDragOperation(_ sender: NSDraggingInfo) -> Bool {
|
|
|
+ let pboard = sender.draggingPasteboard
|
|
|
+ _ = pboard.types
|
|
|
+
|
|
|
+ let dict = pboard.propertyList(forType: Self.lineStylePboardType) as? [String : Any]
|
|
|
+ if let data = dict?[Self.widthKey] as? NSNumber {
|
|
|
+ self.lineWidth = data.floatValue.cgFloat
|
|
|
+ } else if let data = dict?[Self.styleKey] as? NSNumber {
|
|
|
+ self.style = CPDFBorderStyle(rawValue: data.intValue) ?? .solid
|
|
|
+ } else if let data = dict?[Self.dashPatternKey] {
|
|
|
+ self.dashPattern = data as? NSArray ?? []
|
|
|
+ } else {
|
|
|
+ if self.displayStyle == .line || self.displayStyle == .simpleLine {
|
|
|
+ if let data = dict?[Self.startLineStyleKey] as? NSNumber {
|
|
|
+ self.startLineStyle = CPDFLineStyle(rawValue: data.intValue) ?? .none
|
|
|
+ } else if let data = dict?[Self.endLineStyleKey] as? NSNumber {
|
|
|
+ self.endLineStyle = CPDFLineStyle(rawValue: data.intValue) ?? .none
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self.sendAction(self.action, to: self.target)
|
|
|
+
|
|
|
+ self.isHighlighted = false
|
|
|
+ self.setKeyboardFocusRingNeedsDisplay(self.bounds)
|
|
|
+ self.needsDisplay = true
|
|
|
+ return dict != nil
|
|
|
+ }
|
|
|
+
|
|
|
// - (void)takeValueForKey:(NSString *)key from:(id)object {
|
|
|
// [self setValue:[object valueForKey:key] forKey:key];
|
|
|
// NSDictionary *info = [self infoForBinding:key];
|
|
@@ -604,7 +671,7 @@ extension KMLineWell {
|
|
|
|
|
|
self.isEnabled = true
|
|
|
|
|
|
-// [self registerForDraggedTypes:[NSArray arrayWithObjects:SKPasteboardTypeLineStyle, nil]];
|
|
|
+ self.registerForDraggedTypes([Self.lineStylePboardType])
|
|
|
}
|
|
|
|
|
|
private func _deactivate() {
|