#import <AppKit/AppKit.h>
#import <Quartz/Quartz.h>
-@class GVGraph;
-
@interface GVWindowController : NSWindowController <NSUserInterfaceValidations>
{
IBOutlet PDFView *documentView;
-
- GVGraph *_graph;
}
-@property(readonly) GVGraph *graph;
-
- (id)init;
- (void)setDocument: (NSDocument *)document;
- (void)awakeFromNib;
-- (void)graphDidChange:(NSNotification*)notification;
+- (void)graphDocumentDidChange:(NSNotification*)notification;
- (NSRect)windowWillUseStandardFrame:(NSWindow *)window defaultFrame:(NSRect)defaultFrame;
- (IBAction)actualSizeView:(id)sender;
@implementation GVWindowController
-@synthesize graph = _graph;
-
- (id)init
{
if (self = [super initWithWindowNibName: @"Document"])
- _graph = nil;
+ ;
return self;
}
- (void)setDocument: (NSDocument *)document
{
- if ([document respondsToSelector:@selector(graph)]) {
- GVGraph *newGraph = [(GVDocument *)document graph];
- if (_graph != newGraph) {
- /* retain the new document graph and start observing any changes from it */
NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
- if (_graph) {
- [defaultCenter removeObserver:self name:@"GVGraphDidChange" object:_graph];
- [_graph release];
- }
- _graph = nil;
- if (newGraph) {
- _graph = [newGraph retain];
- [defaultCenter addObserver:self selector:@selector(graphDidChange:) name:@"GVGraphDidChange" object:newGraph];
- }
- }
- }
+ GVDocument *oldDocument = [self document];
+ if (oldDocument)
+ [defaultCenter removeObserver:self name:@"GVGraphDocumentDidChange" object:oldDocument];
[super setDocument:document];
+ [defaultCenter addObserver:self selector:@selector(graphDocumentDidChange:) name:@"GVGraphDocumentDidChange" object:document];
}
- (void)awakeFromNib
{
- [self graphDidChange:nil];
+ [self graphDocumentDidChange:nil];
/* if window is not at standard size, make it standard size */
NSWindow *window = [self window];
[window zoom:self];
}
-- (void)graphDidChange:(NSNotification*)notification
+- (void)graphDocumentDidChange:(NSNotification*)notification
{
/* whenever the graph changes, rerender its PDF and display that */
- [documentView setDocument:[[[PDFDocument alloc] initWithData:[_graph renderWithFormat:@"pdf:quartz"]] autorelease]];
+ GVDocument *document = [self document];
+ if ([document respondsToSelector:@selector(graph)])
+ [documentView setDocument:[[[PDFDocument alloc] initWithData:[[document graph] renderWithFormat:@"pdf:quartz"]] autorelease]];
}
- (NSRect)windowWillUseStandardFrame:(NSWindow *)window defaultFrame:(NSRect)defaultFrame
}
- (void)dealloc
{
- if (_graph) {
- [[NSNotificationCenter defaultCenter] removeObserver:self name:@"GVGraphDidChange" object:_graph];
- [_graph release];
- }
-
+ [[NSNotificationCenter defaultCenter] removeObserver:self name:@"GVGraphDocumentDidChange" object:[self document]];
[super dealloc];
}
D82649100DE58739009D6A44 /* ZoomOutToolbarImage.tiff in Resources */ = {isa = PBXBuildFile; fileRef = D826490C0DE58739009D6A44 /* ZoomOutToolbarImage.tiff */; };
D8264B0A0DE8111F009D6A44 /* GVExportViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D8264B090DE8111F009D6A44 /* GVExportViewController.m */; };
D8264B0D0DE81133009D6A44 /* Export.xib in Resources */ = {isa = PBXBuildFile; fileRef = D8264B0B0DE81133009D6A44 /* Export.xib */; };
+ D85D2EBC0DEAB83C00A69D07 /* GVFileNotificationCenter.m in Sources */ = {isa = PBXBuildFile; fileRef = D85D2EBB0DEAB83C00A69D07 /* GVFileNotificationCenter.m */; };
D86382D70D57118400D27D07 /* Document.xib in Resources */ = {isa = PBXBuildFile; fileRef = D86382D30D57118400D27D07 /* Document.xib */; };
D86382D80D57118400D27D07 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = D86382D50D57118400D27D07 /* MainMenu.xib */; };
D86CBB7D0D5AE541000FB42B /* GVGraph.m in Sources */ = {isa = PBXBuildFile; fileRef = D86CBB7C0D5AE541000FB42B /* GVGraph.m */; };
D8264B080DE8111F009D6A44 /* GVExportViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GVExportViewController.h; sourceTree = "<group>"; };
D8264B090DE8111F009D6A44 /* GVExportViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GVExportViewController.m; sourceTree = "<group>"; };
D8264B0C0DE81133009D6A44 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/Export.xib; sourceTree = "<group>"; };
+ D85D2EBA0DEAB83C00A69D07 /* GVFileNotificationCenter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GVFileNotificationCenter.h; sourceTree = "<group>"; };
+ D85D2EBB0DEAB83C00A69D07 /* GVFileNotificationCenter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GVFileNotificationCenter.m; sourceTree = "<group>"; };
D86382D40D57118400D27D07 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/Document.xib; sourceTree = "<group>"; };
D86382D60D57118400D27D07 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = "<group>"; };
D86CBB7B0D5AE541000FB42B /* GVGraph.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GVGraph.h; sourceTree = "<group>"; };
2A37F4ACFDCFA73011CA2CEA /* GVDocument.m */,
D8264B080DE8111F009D6A44 /* GVExportViewController.h */,
D8264B090DE8111F009D6A44 /* GVExportViewController.m */,
+ D85D2EBA0DEAB83C00A69D07 /* GVFileNotificationCenter.h */,
+ D85D2EBB0DEAB83C00A69D07 /* GVFileNotificationCenter.m */,
D86CBB7B0D5AE541000FB42B /* GVGraph.h */,
D86CBB7C0D5AE541000FB42B /* GVGraph.m */,
D8C09DEB0D6067BE00134D03 /* GVGraphArguments.h */,
D8798BDF0D5D5BD700CCC6E3 /* GVAttributeSchema.m in Sources */,
D8C09DED0D6067BE00134D03 /* GVGraphArguments.m in Sources */,
D8264B0A0DE8111F009D6A44 /* GVExportViewController.m in Sources */,
+ D85D2EBC0DEAB83C00A69D07 /* GVFileNotificationCenter.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};