From e67d8cfb2a4d71c9c5d080e270a7ae87f6517eb9 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sun, 24 Sep 2023 22:00:38 -0400 Subject: [PATCH] MacPDF: Show current page and page count in subtitle --- Meta/Lagom/Contrib/MacPDF/LagomPDFDocument.h | 2 +- Meta/Lagom/Contrib/MacPDF/LagomPDFDocument.mm | 9 +++++++++ Meta/Lagom/Contrib/MacPDF/LagomPDFView.h | 9 +++++++-- Meta/Lagom/Contrib/MacPDF/LagomPDFView.mm | 12 ++++++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Meta/Lagom/Contrib/MacPDF/LagomPDFDocument.h b/Meta/Lagom/Contrib/MacPDF/LagomPDFDocument.h index a00cbc151f..54615473ee 100644 --- a/Meta/Lagom/Contrib/MacPDF/LagomPDFDocument.h +++ b/Meta/Lagom/Contrib/MacPDF/LagomPDFDocument.h @@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN -@interface LagomPDFDocument : NSDocument +@interface LagomPDFDocument : NSDocument { IBOutlet LagomPDFView* _pdfView; } diff --git a/Meta/Lagom/Contrib/MacPDF/LagomPDFDocument.mm b/Meta/Lagom/Contrib/MacPDF/LagomPDFDocument.mm index fcd71e5c6f..d36f91064c 100644 --- a/Meta/Lagom/Contrib/MacPDF/LagomPDFDocument.mm +++ b/Meta/Lagom/Contrib/MacPDF/LagomPDFDocument.mm @@ -68,6 +68,7 @@ NSLog(@"failed to load 2: %@", @(err.error().message().characters())); } else { [_pdfView setDocument:_doc->make_weak_ptr()]; + [self pageChanged]; } } @@ -82,6 +83,8 @@ { [super windowControllerDidLoadNib:aController]; + [_pdfView setDelegate:self]; + if (_doc) { if (auto handler = _doc->security_handler(); handler && !handler->has_user_password()) { [self promptForPassword:aController.window]; @@ -166,4 +169,10 @@ }]; } +- (void)pageChanged +{ + [_pdfView.window setSubtitle: + [NSString stringWithFormat:@"Page %d of %d", [_pdfView page], _doc -> get_page_count()]]; +} + @end diff --git a/Meta/Lagom/Contrib/MacPDF/LagomPDFView.h b/Meta/Lagom/Contrib/MacPDF/LagomPDFView.h index 71a095a54c..14dfee67d2 100644 --- a/Meta/Lagom/Contrib/MacPDF/LagomPDFView.h +++ b/Meta/Lagom/Contrib/MacPDF/LagomPDFView.h @@ -15,11 +15,16 @@ #include #include +@protocol LagomPDFViewDelegate +- (void)pageChanged; +@end + @interface LagomPDFView : NSView -{ -} - (void)setDocument:(WeakPtr)doc; - (void)goToPage:(int)page; +- (int)page; + +- (void)setDelegate:(id)delegate; @end diff --git a/Meta/Lagom/Contrib/MacPDF/LagomPDFView.mm b/Meta/Lagom/Contrib/MacPDF/LagomPDFView.mm index ad9a8e554b..4bf8930674 100644 --- a/Meta/Lagom/Contrib/MacPDF/LagomPDFView.mm +++ b/Meta/Lagom/Contrib/MacPDF/LagomPDFView.mm @@ -16,6 +16,7 @@ WeakPtr _doc; NSBitmapImageRep* _cachedBitmap; int _page_index; + __weak id _delegate; } @end @@ -82,6 +83,17 @@ static NSBitmapImageRep* ns_from_gfx(NonnullRefPtr bitmap_p) _page_index = new_index; [self invalidateRestorableState]; [self invalidateCachedBitmap]; + [_delegate pageChanged]; +} + +- (int)page +{ + return _page_index + 1; +} + +- (void)setDelegate:(id)delegate +{ + _delegate = delegate; } #pragma mark Drawing