mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-03-03 20:15:53 +00:00
MacPDF: Show current page and page count in subtitle
This commit is contained in:
committed by
Andreas Kling
parent
bd19fcc039
commit
e67d8cfb2a
@@ -14,7 +14,7 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface LagomPDFDocument : NSDocument
|
||||
@interface LagomPDFDocument : NSDocument <LagomPDFViewDelegate>
|
||||
{
|
||||
IBOutlet LagomPDFView* _pdfView;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -15,11 +15,16 @@
|
||||
#include <AK/WeakPtr.h>
|
||||
#include <LibPDF/Document.h>
|
||||
|
||||
@protocol LagomPDFViewDelegate
|
||||
- (void)pageChanged;
|
||||
@end
|
||||
|
||||
@interface LagomPDFView : NSView
|
||||
{
|
||||
}
|
||||
|
||||
- (void)setDocument:(WeakPtr<PDF::Document>)doc;
|
||||
- (void)goToPage:(int)page;
|
||||
- (int)page;
|
||||
|
||||
- (void)setDelegate:(id<LagomPDFViewDelegate>)delegate;
|
||||
|
||||
@end
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
WeakPtr<PDF::Document> _doc;
|
||||
NSBitmapImageRep* _cachedBitmap;
|
||||
int _page_index;
|
||||
__weak id<LagomPDFViewDelegate> _delegate;
|
||||
}
|
||||
@end
|
||||
|
||||
@@ -82,6 +83,17 @@ static NSBitmapImageRep* ns_from_gfx(NonnullRefPtr<Gfx::Bitmap> bitmap_p)
|
||||
_page_index = new_index;
|
||||
[self invalidateRestorableState];
|
||||
[self invalidateCachedBitmap];
|
||||
[_delegate pageChanged];
|
||||
}
|
||||
|
||||
- (int)page
|
||||
{
|
||||
return _page_index + 1;
|
||||
}
|
||||
|
||||
- (void)setDelegate:(id<LagomPDFViewDelegate>)delegate
|
||||
{
|
||||
_delegate = delegate;
|
||||
}
|
||||
|
||||
#pragma mark Drawing
|
||||
|
||||
Reference in New Issue
Block a user