Revision: 15682
http://sourceforge.net/p/skim-app/code/15682
Author: hofman
Date: 2025-10-02 17:02:55 +0000 (Thu, 02 Oct 2025)
Log Message:
-----------
make loupe controller an NSWindowController
Modified Paths:
--------------
trunk/SKLoupeController.h
trunk/SKLoupeController.m
Modified: trunk/SKLoupeController.h
===================================================================
--- trunk/SKLoupeController.h 2025-10-02 16:54:33 UTC (rev 15681)
+++ trunk/SKLoupeController.h 2025-10-02 17:02:55 UTC (rev 15682)
@@ -42,8 +42,7 @@
@class PDFView;
-@interface SKLoupeController : NSObject <CALayerDelegate> {
- NSWindow *window;
+@interface SKLoupeController : NSWindowController <CALayerDelegate> {
CALayer *layer;
__weak PDFView *pdfView;
CGFloat magnification;
@@ -51,7 +50,8 @@
}
- (instancetype)initWithPDFView:(PDFView *)aPdfView NS_DESIGNATED_INITIALIZER;
-- (instancetype)init NS_UNAVAILABLE;
+- (instancetype)initWithWindow:(nullable NSWindow *)window NS_UNAVAILABLE;
+- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_UNAVAILABLE;
@property (nonatomic) CGFloat magnification;
@property (nonatomic) NSInteger level;
Modified: trunk/SKLoupeController.m
===================================================================
--- trunk/SKLoupeController.m 2025-10-02 16:54:33 UTC (rev 15681)
+++ trunk/SKLoupeController.m 2025-10-02 17:02:55 UTC (rev 15682)
@@ -57,7 +57,7 @@
#define SKLargeMagnificationHeightKey @"SKLargeMagnificationHeight"
@interface SKLoupeController ()
-- (void)makeWindow;
++ (NSWindow *)makeWindowForView:(NSView *)pdfView;
- (void)handlePDFContentViewFrameChangedNotification:(NSNotification
*)notification;
@end
@@ -66,12 +66,15 @@
@synthesize magnification, level;
- (instancetype)initWithPDFView:(PDFView *)aPdfView {
- self = [super init];
+ NSWindow *window = [[self class] makeWindowForView:aPdfView];
+ self = [super initWithWindow:window];
if (self) {
pdfView = aPdfView;
- [self makeWindow];
magnification = 0.0;
level = 0;
+ layer = [[window contentView] layer];
+ [layer setDelegate:self];
+ [self updateColorFilters];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handlePDFContentViewFrameChangedNotification:)
name:NSViewBoundsDidChangeNotification object:[[pdfView
scrollView] contentView]];
@@ -83,8 +86,8 @@
[layer setDelegate:nil];
}
-- (void)makeWindow {
- layer = [[CALayer alloc] init];
++ (NSWindow *)makeWindowForView:(NSView *)pdfView {
+ CALayer *layer = [[CALayer alloc] init];
[layer setCornerRadius:LOUPE_RADIUS];
[layer setMasksToBounds:YES];
[layer setActions:@{@"contents":[NSNull null]}];
@@ -95,13 +98,12 @@
[layer setBorderWidth:LOUPE_BORDER_WIDTH];
CGColorRelease(borderColor);
}
- [layer setDelegate:self];
- window = [[SKAnimatedBorderlessWindow alloc] initWithContentRect:[pdfView
convertRectToScreen:[pdfView bounds]]];
+ NSWindow *window = [[SKAnimatedBorderlessWindow alloc]
initWithContentRect:[pdfView convertRectToScreen:[pdfView bounds]]];
[[window contentView] setLayer:layer];
[[window contentView] setWantsLayer:YES];
[window setHasShadow:YES];
- [self updateColorFilters];
+ return window;
}
- (void)handlePDFContentViewFrameChangedNotification:(NSNotification
*)notification {
@@ -110,6 +112,7 @@
- (void)updateBackgroundColor {
if (@available(macOS 10.14, *)) {
+ NSWindow *window = [self window];
BOOL hasBackgroundView = NO;
NSView *loupeView = [window contentView];
if ([[loupeView subviews] count] > 0) {
@@ -161,6 +164,7 @@
}
- (void)updateColorFilters {
+ NSWindow *window = [self window];
[[window contentView] setContentFilters:SKColorEffectFilters()];
if (@available(macOS 10.14, *)) {
if ([[NSUserDefaults standardUserDefaults]
boolForKey:SKInvertColorsInDarkModeKey])
@@ -191,6 +195,7 @@
magRect = NSIntegralRect(SKRectFromCenterAndSize(mouseLoc,
magSize));
}
+ NSWindow *window = [self window];
NSView *loupeView = [window contentView];
if (@available(macOS 10.14, *))
loupeView = [[loupeView subviews] firstObject] ?: loupeView;
@@ -212,6 +217,7 @@
}
- (void)updateContents {
+ NSWindow *window = [self window];
if ([window parentWindow]) {
if (level > 2 && NSEqualSizes([window frame].size, [pdfView
visibleContentRect].size) == NO)
[self update];
@@ -221,6 +227,7 @@
}
- (BOOL)hide {
+ NSWindow *window = [self window];
if ([window parentWindow] == nil)
return NO;
// show cursor
@@ -236,7 +243,7 @@
if (NSPointInRect(mouseLoc, [pdfView visibleContentRect]) == NO)
return;
- NSRect magRect = [pdfView convertRectFromScreen:[window frame]];
+ NSRect magRect = [pdfView convertRectFromScreen:[[self window] frame]];
CGFloat scaleFactor = [pdfView scaleFactor];
CGColorRef shadowColor = NULL;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit