/
MyDocument.m
80 lines (67 loc) · 2.37 KB
/
MyDocument.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#import "MyDocument.h"
#import "BlitzPDFView.h"
@interface MyDocument ()
@property (retain, nonatomic) PDFDocument *pdfDocument;
@property (retain, nonatomic) NSTimer *timer;
@property (nonatomic) BOOL isInFullScreenMode;
@end
@implementation MyDocument
@synthesize pdfView, pdfDocument, timer, isInFullScreenMode;
- (void)toggleFullScreenMode {
if (self.isInFullScreenMode) {
[self.pdfView exitFullScreenModeWithOptions: nil];
self.isInFullScreenMode = NO;
}
else {
NSWindow *window = [[[self windowControllers] objectAtIndex:0 ] window];
self.isInFullScreenMode = [self.pdfView enterFullScreenMode: window.screen withOptions: nil];
}
}
- (void)windowControllerDidLoadNib:(NSWindowController*)controller_ {
[super windowControllerDidLoadNib:controller_];
if (!self.pdfDocument) {
self.pdfDocument = [[PDFDocument alloc] init];
}
[self.pdfView setDocument:self.pdfDocument];
self.pdfView.secondsElapsed = 0;
self.timer = [[NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(updateElapsedTimer:)
userInfo:nil
repeats:YES] retain];
self.isInFullScreenMode = NO;
[self toggleFullScreenMode];
}
- (BOOL)writeToURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError {
//return [self.pdfDocument writeToURL:absoluteURL];
[self doesNotRecognizeSelector:_cmd]; // Renounce writing the PDF to disk.
return NO;
}
- (BOOL)readFromURL:(NSURL *)initWithURL ofType:(NSString *)typeName error:(NSError **)outError {
self.pdfDocument = [[PDFDocument alloc] initWithURL:initWithURL];
return self.pdfDocument ? YES : NO;
}
- (void)updateElapsedTimer:(NSTimer*)timer_ {
if (self.pdfView.secondsElapsed != 0 && (self.pdfView.secondsElapsed % 15 == 0)) {
if ([self.pdfView canGoToNextPage]) {
[self.pdfView goToNextPage:nil];
}
else {
[self.pdfView atLastPage];
[timer_ invalidate];
}
}
self.pdfView.secondsElapsed += 1;
[self.pdfView setNeedsDisplay:YES];
}
//--
- (NSString *)windowNibName {
return @"MyDocument";
}
- (void)dealloc {
self.pdfDocument = nil;
[self.timer invalidate];
self.timer = nil;
[super dealloc];
}
@end