Revision: 13631
http://sourceforge.net/p/skim-app/code/13631
Author: hofman
Date: 2023-09-03 15:39:49 +0000 (Sun, 03 Sep 2023)
Log Message:
-----------
use private PDFPageView methods to update snapshot and secondary pdfview
annotation display, as it does not update by itself becaise the page does not
know its page view
Modified Paths:
--------------
trunk/PDFView_SKExtensions.h
trunk/PDFView_SKExtensions.m
trunk/SKMainWindowController.m
trunk/SKSnapshotWindowController.h
trunk/SKSnapshotWindowController.m
Modified: trunk/PDFView_SKExtensions.h
===================================================================
--- trunk/PDFView_SKExtensions.h 2023-09-03 08:49:17 UTC (rev 13630)
+++ trunk/PDFView_SKExtensions.h 2023-09-03 15:39:49 UTC (rev 13631)
@@ -53,6 +53,8 @@
- (void)setNeedsDisplayInRect:(NSRect)rect ofPage:(PDFPage *)page;
- (void)setNeedsDisplayForAnnotation:(PDFAnnotation *)annotation
onPage:(PDFPage *)page;
- (void)setNeedsDisplayForAnnotation:(PDFAnnotation *)annotation;
+- (void)setNeedsDisplayForAddedAnnotation:(PDFAnnotation *)annotation
onPage:(PDFPage *)page;
+- (void)setNeedsDisplayForRemovedAnnotation:(PDFAnnotation *)annotation
onPage:(PDFPage *)page;
- (void)requiresDisplay;
- (void)doPdfsyncWithEvent:(NSEvent *)theEvent;
Modified: trunk/PDFView_SKExtensions.m
===================================================================
--- trunk/PDFView_SKExtensions.m 2023-09-03 08:49:17 UTC (rev 13630)
+++ trunk/PDFView_SKExtensions.m 2023-09-03 15:39:49 UTC (rev 13631)
@@ -69,6 +69,16 @@
#endif
+@interface PDFView (SKPrivatePageViewDeclarations)
+- (id)pageViewForPageAtIndex:(NSUInteger)index;
+@end
+
+@interface NSView (SKPrivatePageViewDeclarations)
+- (void)addAnnotation:(PDFAnnotation *)annotation;
+- (void)updateAnnotation:(PDFAnnotation *)annotation;
+- (void)removeAnnotation:(PDFAnnotation *)annotation;
+@end
+
#define PAGE_BREAK_MARGIN 4.0
@implementation PDFView (SKExtensions)
@@ -100,6 +110,15 @@
return [self descendantOfClass:[NSScrollView class]];
}
+- (NSView *)safePageViewForPage:(PDFPage *)page {
+ if ([self respondsToSelector:@selector(pageViewForPageAtIndex:)] == NO)
+ return nil;
+ NSView *pageView = [self pageViewForPageAtIndex:[page pageIndex]];
+ if ([pageView respondsToSelector:@selector(addAnnotation:)] && [pageView
respondsToSelector:@selector(updateAnnotation:)] && [pageView
respondsToSelector:@selector(removeAnnotation:)])
+ return pageView;
+ return nil;
+}
+
- (void)setNeedsDisplayInRect:(NSRect)rect ofPage:(PDFPage *)page {
if ([self isPageAtIndexDisplayed:[page pageIndex]]) {
// for some versions we need to dirty the documentView, otherwise it
won't redisplay when scrolled out of view,
@@ -114,6 +133,9 @@
- (void)setNeedsDisplayForAnnotation:(PDFAnnotation *)annotation
onPage:(PDFPage *)page {
[self setNeedsDisplayInRect:[annotation displayRect] ofPage:page];
+ NSView *pageView = [self safePageViewForPage:page];
+ if (pageView)
+ [pageView updateAnnotation:annotation];
[self annotationsChangedOnPage:page];
}
@@ -126,6 +148,22 @@
[view setNeedsDisplay:YES];
}
+- (void)setNeedsDisplayForAddedAnnotation:(PDFAnnotation *)annotation
onPage:(PDFPage *)page {
+ [self setNeedsDisplayInRect:[annotation displayRect] ofPage:page];
+ NSView *pageView = [self safePageViewForPage:page];
+ if (pageView)
+ [pageView addAnnotation:annotation];
+ [self annotationsChangedOnPage:page];
+}
+
+- (void)setNeedsDisplayForRemovedAnnotation:(PDFAnnotation *)annotation
onPage:(PDFPage *)page {
+ [self setNeedsDisplayInRect:[annotation displayRect] ofPage:page];
+ NSView *pageView = [self safePageViewForPage:page];
+ if (pageView)
+ [pageView removeAnnotation:annotation];
+ [self annotationsChangedOnPage:page];
+}
+
- (void)doPdfsyncWithEvent:(NSEvent *)theEvent {
// eat up mouseDragged/mouseUp events, so we won't get their event handlers
while (YES) {
Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m 2023-09-03 08:49:17 UTC (rev 13630)
+++ trunk/SKMainWindowController.m 2023-09-03 15:39:49 UTC (rev 13631)
@@ -2360,7 +2360,7 @@
if ([wc isPageVisible:page])
[self snapshotNeedsUpdate:wc];
}
- [secondaryPdfView setNeedsDisplayForAnnotation:annotation
onPage:page];
+ [secondaryPdfView setNeedsDisplayForAddedAnnotation:annotation
onPage:page];
}
}
}
@@ -2397,7 +2397,7 @@
if ([wc isPageVisible:page])
[self snapshotNeedsUpdate:wc];
}
- [secondaryPdfView setNeedsDisplayForAnnotation:annotation
onPage:page];
+ [secondaryPdfView setNeedsDisplayForRemovedAnnotation:annotation
onPage:page];
}
}
}
@@ -2419,7 +2419,8 @@
if ([wc isPageVisible:oldPage] || [wc isPageVisible:newPage])
[self snapshotNeedsUpdate:wc];
}
- [secondaryPdfView requiresDisplay];
+ [secondaryPdfView setNeedsDisplayForRemovedAnnotation:annotation
onPage:oldPage];
+ [secondaryPdfView setNeedsDisplayForAddedAnnotation:annotation
onPage:newPage];
}
[rightSideController.noteArrayController rearrangeObjects];
Modified: trunk/SKSnapshotWindowController.h
===================================================================
--- trunk/SKSnapshotWindowController.h 2023-09-03 08:49:17 UTC (rev 13630)
+++ trunk/SKSnapshotWindowController.h 2023-09-03 15:39:49 UTC (rev 13631)
@@ -97,7 +97,8 @@
- (void)handleDocumentDidUnlockNotification:(NSNotification *)notification;
- (void)handlePDFViewFrameChangedNotification:(NSNotification *)notification;
- (void)handleViewChangedNotification:(NSNotification *)notification;
-- (void)handleDidAddRemoveAnnotationNotification:(NSNotification
*)notification;
+- (void)handleDidAddAnnotationNotification:(NSNotification *)notification;
+- (void)handleDidRemoveAnnotationNotification:(NSNotification *)notification;
- (void)handleDidMoveAnnotationNotification:(NSNotification *)notification;
- (void)setNeedsDisplayInRect:(NSRect)rect ofPage:(PDFPage *)page;
Modified: trunk/SKSnapshotWindowController.m
===================================================================
--- trunk/SKSnapshotWindowController.m 2023-09-03 08:49:17 UTC (rev 13630)
+++ trunk/SKSnapshotWindowController.m 2023-09-03 15:39:49 UTC (rev 13631)
@@ -145,20 +145,11 @@
}
- (void)setNeedsDisplayInRect:(NSRect)rect ofPage:(PDFPage *)page {
- NSRect aRect = [pdfView convertRect:rect fromPage:page];
- CGFloat scale = [pdfView scaleFactor];
- CGFloat maxX = ceil(NSMaxX(aRect) + scale);
- CGFloat maxY = ceil(NSMaxY(aRect) + scale);
- CGFloat minX = floor(NSMinX(aRect) - scale);
- CGFloat minY = floor(NSMinY(aRect) - scale);
-
- aRect = NSIntersectionRect([pdfView bounds], NSMakeRect(minX, minY, maxX -
minX, maxY - minY));
- if (NSIsEmptyRect(aRect) == NO)
- [pdfView setNeedsDisplayInRect:aRect];
+ [pdfView setNeedsDisplayInRect:rect ofPage:page];
}
- (void)setNeedsDisplayForAnnotation:(PDFAnnotation *)annotation
onPage:(PDFPage *)page {
- [self setNeedsDisplayInRect:[annotation displayRect] ofPage:page];
+ [pdfView setNeedsDisplayForAnnotation:annotation onPage:page];
}
- (void)redisplay {
@@ -207,21 +198,28 @@
[[self delegate] snapshotControllerDidChange:self];
}
-- (void)handleDidAddRemoveAnnotationNotification:(NSNotification
*)notification {
+- (void)handleDidAddAnnotationNotification:(NSNotification *)notification {
PDFAnnotation *annotation = [[notification userInfo]
objectForKey:SKPDFDocumentAnnotationKey];
PDFPage *page = [[notification userInfo]
objectForKey:SKPDFDocumentPageKey];
if ([self isPageVisible:page])
- [self setNeedsDisplayForAnnotation:annotation onPage:page];
+ [pdfView setNeedsDisplayForAddedAnnotation:annotation onPage:page];
}
+- (void)handleDidRemoveAnnotationNotification:(NSNotification *)notification {
+ PDFAnnotation *annotation = [[notification userInfo]
objectForKey:SKPDFDocumentAnnotationKey];
+ PDFPage *page = [[notification userInfo]
objectForKey:SKPDFDocumentPageKey];
+ if ([self isPageVisible:page])
+ [pdfView setNeedsDisplayForRemovedAnnotation:annotation onPage:page];
+}
+
- (void)handleDidMoveAnnotationNotification:(NSNotification *)notification {
PDFAnnotation *annotation = [notification object];
PDFPage *oldPage = [[notification userInfo]
objectForKey:SKPDFDocumentOldPageKey];
PDFPage *newPage = [[notification userInfo]
objectForKey:SKPDFDocumentPageKey];
if ([self isPageVisible:oldPage])
- [self setNeedsDisplayForAnnotation:annotation onPage:oldPage];
+ [pdfView setNeedsDisplayForRemovedAnnotation:annotation
onPage:oldPage];
if ([self isPageVisible:newPage])
- [self setNeedsDisplayForAnnotation:annotation onPage:newPage];
+ [pdfView setNeedsDisplayForAddedAnnotation:annotation onPage:newPage];
}
- (void)windowWillClose:(NSNotification *)notification {
@@ -272,9 +270,9 @@
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleViewChangedNotification:)
name:SKSnapshotViewChangedNotification object:self];
PDFDocument *pdfDoc = [pdfView document];
- [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleDidAddRemoveAnnotationNotification:)
+ [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleDidAddAnnotationNotification:)
name:SKPDFDocumentDidAddAnnotationNotification object:pdfDoc];
- [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleDidAddRemoveAnnotationNotification:)
+ [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleDidRemoveAnnotationNotification:)
name:SKPDFDocumentDidRemoveAnnotationNotification object:pdfDoc];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleDidMoveAnnotationNotification:)
name:SKPDFDocumentDidMoveAnnotationNotification object:pdfDoc];
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