Revision: 29099 http://sourceforge.net/p/bibdesk/svn/29099 Author: hofman Date: 2025-04-06 16:37:27 +0000 (Sun, 06 Apr 2025) Log Message: ----------- Support draging from font well
Modified Paths: -------------- trunk/bibdesk/BDSKFontWell.m Modified: trunk/bibdesk/BDSKFontWell.m =================================================================== --- trunk/bibdesk/BDSKFontWell.m 2025-04-06 16:15:56 UTC (rev 29098) +++ trunk/bibdesk/BDSKFontWell.m 2025-04-06 16:37:27 UTC (rev 29099) @@ -38,9 +38,11 @@ #import "BDSKFontWell.h" #import "NSFont_BDSKExtensions.h" +#import "NSImage_BDSKExtensions.h" #define BDSKNSFontPanelDescriptorsPboardType @"NSFontPanelDescriptorsPboardType" #define BDSKNSFontPanelFamiliesPboardType @"NSFontPanelFamiliesPboardType" +#define UTIForNSPboardType(type) CFBridgingRelease(UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, (__bridge CFStringRef)type, NULL)) #define BDSKNSFontCollectionFontDescriptors @"NSFontCollectionFontDescriptors" #define BDSKFontWellWillBecomeActiveNotification @"BDSKFontWellWillBecomeActiveNotification" @@ -227,8 +229,53 @@ [self setFont:newFont]; } -#pragma mark NSDraggingDestination protocol +- (void)mouseDown:(NSEvent *)theEvent { + [[self cell] setHighlighted:YES]; + [self setNeedsDisplay:YES]; + + if (NSEventTypeLeftMouseDragged == [[NSApp nextEventMatchingMask:(NSEventMaskLeftMouseUp | NSEventMaskLeftMouseDragged) untilDate:[NSDate distantFuture] inMode:NSEventTrackingRunLoopMode dequeue:NO] type]) { + [[self cell] setHighlighted:NO]; + [self setNeedsDisplay:YES]; + + NSRect bounds = [self bounds]; + + NSImage *dragImage = [[NSImage alloc] initBitmapWithSize:bounds.size scale:[[self window] backingScaleFactor] drawingHandler:^(NSRect rect){ + if (@available(macOS 11.0, *)) { + [[self effectiveAppearance] performAsCurrentDrawingAppearance:^{ + [[self cell] drawInteriorWithFrame:rect inView:self]; + }]; + } else if (@available(macOS 10.14, *)) { + NSAppearance *appearance = [NSAppearance currentAppearance]; + [NSAppearance setCurrentAppearance:[self effectiveAppearance]]; + [[self cell] drawInteriorWithFrame:rect inView:self]; + [NSAppearance setCurrentAppearance:appearance]; + } else { + [[self cell] drawInteriorWithFrame:rect inView:self]; + } + }]; + + NSDictionary *dict = @{BDSKNSFontCollectionFontDescriptors: @[[[self font] fontDescriptor]], NSFontSizeAttribute: [NSNumber numberWithDouble:[[self font] pointSize]]}; + NSData *data = [NSKeyedArchiver archivedDataWithRootObject:dict]; + NSPasteboardItem *item = [[NSPasteboardItem alloc] init]; + [item setData:data forType:UTIForNSPboardType(BDSKNSFontPanelDescriptorsPboardType)]; + + NSDraggingItem *dragItem = [[NSDraggingItem alloc] initWithPasteboardWriter:item]; + [dragItem setDraggingFrame:bounds contents:dragImage]; + + [self beginDraggingSessionWithItems:@[dragItem] event:theEvent source:self]; + } else { + [super mouseDown:theEvent]; + } +} +#pragma mark NSDraggingSource protocol + +- (NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationMaskForDraggingContext:(NSDraggingContext)context { + return NSDragOperationGeneric; +} + +#pragma mark NSDraggingDestination protocol + - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender { if ([self isEnabled] && [sender draggingSource] != self && [[sender draggingPasteboard] availableTypeFromArray:@[BDSKNSFontPanelDescriptorsPboardType, BDSKNSFontPanelFamiliesPboardType]]) { [[self cell] setHighlighted:YES]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Bibdesk-commit mailing list Bibdesk-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bibdesk-commit