Revision: 15076
          http://sourceforge.net/p/skim-app/code/15076
Author:   hofman
Date:     2025-04-03 16:21:42 +0000 (Thu, 03 Apr 2025)
Log Message:
-----------
Override mouseDown to start dragging, so it can start immediately when 
dragging. Draw drag imae with current appearance.

Modified Paths:
--------------
    trunk/SKFontWell.m

Modified: trunk/SKFontWell.m
===================================================================
--- trunk/SKFontWell.m  2025-04-03 15:58:07 UTC (rev 15075)
+++ trunk/SKFontWell.m  2025-04-03 16:21:42 UTC (rev 15076)
@@ -41,6 +41,7 @@
 #import "NSColor_SKExtensions.h"
 #import "NSObject_SKExtensions.h"
 #import "NSImage_SKExtensions.h"
+#import "SKApplication.h"
 
 #define SKNSFontPanelDescriptorsPboardType @"NSFontPanelDescriptorsPboardType"
 #define SKNSFontPanelFamiliesPboardType @"NSFontPanelFamiliesPboardType"
@@ -259,6 +260,42 @@
     }
 }
 
+#pragma mark Dragging
+
+- (void)mouseDown:(NSEvent *)theEvent {
+    [[self cell] setHighlighted:YES];
+    [self setNeedsDisplay:YES];
+    
+    if ([NSApp willDragMouse]) {
+        [[self cell] setHighlighted:NO];
+        [self setNeedsDisplay:YES];
+        
+        NSRect bounds = [self bounds];
+        
+        NSImage *dragImage = [NSImage bitmapImageWithSize:bounds.size 
forView:self drawingHandler:^(NSRect rect){
+            SKRunWithAppearance(self, ^{
+                [[self cell] drawInteriorWithFrame:rect inView:self];
+            });
+        }];
+        
+        NSDictionary *dict = @{SKNSFontCollectionFontDescriptors: @[[[self 
font] fontDescriptor]], NSFontSizeAttribute: [NSNumber numberWithDouble:[[self 
font] pointSize]]};
+        NSData *data = [NSKeyedArchiver archivedDataWithRootObject:dict];
+        NSPasteboardItem *item = [[NSPasteboardItem alloc] init];
+        [item setData:data 
forType:UTIForNSPboardType(SKNSFontPanelDescriptorsPboardType)];
+        
+        NSDraggingItem *dragItem = [[NSDraggingItem alloc] 
initWithPasteboardWriter:item];
+        [dragItem setDraggingFrame:bounds contents:dragImage];
+        
+        [self beginDraggingSessionWithItems:@[dragItem] event:theEvent 
source:self];
+    } else {
+        [super mouseDown:theEvent];
+    }
+}
+
+- (NSString *)accessibilitySubrole {
+    return @"AXFontWell";
+}
+
 #pragma mark NSDraggingSource protocol
 
 - (NSDragOperation)draggingSession:(NSDraggingSession *)session 
sourceOperationMaskForDraggingContext:(NSDraggingContext)context {
@@ -420,32 +457,6 @@
     }
 }
 
-- (BOOL)trackMouse:(NSEvent *)event inRect:(NSRect)cellFrame ofView:(NSView 
*)controlView untilMouseUp:(BOOL)flag {
-    BOOL didTrack = [super trackMouse:event inRect:cellFrame 
ofView:controlView untilMouseUp:flag];
-    if (didTrack == NO) {
-        NSRect bounds = [controlView bounds];
-        
-        NSImage *dragImage = [NSImage bitmapImageWithSize:bounds.size 
forView:controlView drawingHandler:^(NSRect rect){
-            [self drawInteriorWithFrame:rect inView:controlView];
-        }];
-        
-        NSDictionary *dict = @{SKNSFontCollectionFontDescriptors: @[[[self 
font] fontDescriptor]], NSFontSizeAttribute: [NSNumber numberWithDouble:[[self 
font] pointSize]]};
-        NSData *data = [NSKeyedArchiver archivedDataWithRootObject:dict];
-        NSPasteboardItem *item = [[NSPasteboardItem alloc] init];
-        [item setData:data 
forType:UTIForNSPboardType(SKNSFontPanelDescriptorsPboardType)];
-        
-        NSDraggingItem *dragItem = [[NSDraggingItem alloc] 
initWithPasteboardWriter:item];
-        [dragItem setDraggingFrame:bounds contents:dragImage];
-        
-        [controlView beginDraggingSessionWithItems:@[dragItem] event:event 
source:(id<NSDraggingSource>)controlView];
-    }
-    return YES;
-}
-
-- (NSString *)accessibilitySubrole {
-    return @"AXFontWell";
-}
-
 - (NSString *)accessibilityRoleDescription {
     return NSLocalizedString(@"font well", @"Accessibility description");
 }

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to