Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Now displays the PDF and our areas on it

  • Loading branch information...
commit 504439f72dd6d6cd7cb42f5b0abbaadcb3561df8 1 parent 30c6f07
@p2 authored
View
4 .gitignore
@@ -0,0 +1,4 @@
+.DS_Store
+
+xcuserdata
+
View
16 growth-charts-helper.xcodeproj/project.pbxproj
@@ -25,6 +25,9 @@
EEEB2DD61680F1E0004DC719 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EEEB2DD51680F1E0004DC719 /* QuartzCore.framework */; };
EEEB2DD91680FA96004DC719 /* CHWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = EEEB2DD81680FA95004DC719 /* CHWindowController.m */; };
EEEB2DDC1680FFC7004DC719 /* CHEnumToNumberTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = EEEB2DDB1680FFC7004DC719 /* CHEnumToNumberTransformer.m */; };
+ EEEB2DE016810423004DC719 /* CHChartPDFView.m in Sources */ = {isa = PBXBuildFile; fileRef = EEEB2DDF16810422004DC719 /* CHChartPDFView.m */; };
+ EEEB2DE21681047B004DC719 /* Quartz.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EEEB2DE11681047B004DC719 /* Quartz.framework */; };
+ EEEB2DE51681075A004DC719 /* CHDropView.m in Sources */ = {isa = PBXBuildFile; fileRef = EEEB2DE41681075A004DC719 /* CHDropView.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -65,6 +68,11 @@
EEEB2DD81680FA95004DC719 /* CHWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CHWindowController.m; sourceTree = "<group>"; };
EEEB2DDA1680FFC7004DC719 /* CHEnumToNumberTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CHEnumToNumberTransformer.h; sourceTree = "<group>"; };
EEEB2DDB1680FFC7004DC719 /* CHEnumToNumberTransformer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CHEnumToNumberTransformer.m; sourceTree = "<group>"; };
+ EEEB2DDE16810422004DC719 /* CHChartPDFView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CHChartPDFView.h; sourceTree = "<group>"; };
+ EEEB2DDF16810422004DC719 /* CHChartPDFView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CHChartPDFView.m; sourceTree = "<group>"; };
+ EEEB2DE11681047B004DC719 /* Quartz.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quartz.framework; path = System/Library/Frameworks/Quartz.framework; sourceTree = SDKROOT; };
+ EEEB2DE31681075A004DC719 /* CHDropView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CHDropView.h; sourceTree = "<group>"; };
+ EEEB2DE41681075A004DC719 /* CHDropView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CHDropView.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -72,6 +80,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
+ EEEB2DE21681047B004DC719 /* Quartz.framework in Frameworks */,
EEEB2DD61680F1E0004DC719 /* QuartzCore.framework in Frameworks */,
EEEB2D761680E014004DC719 /* Cocoa.framework in Frameworks */,
);
@@ -83,6 +92,7 @@
EEEB2D661680E014004DC719 = {
isa = PBXGroup;
children = (
+ EEEB2DE11681047B004DC719 /* Quartz.framework */,
EEEB2DD51680F1E0004DC719 /* QuartzCore.framework */,
EEEB2D7B1680E014004DC719 /* growth-charts-helper */,
EEEB2D741680E014004DC719 /* Frameworks */,
@@ -125,6 +135,8 @@
EEEB2DD71680FA95004DC719 /* CHWindowController.h */,
EEEB2DD81680FA95004DC719 /* CHWindowController.m */,
EEEB2D8A1680E014004DC719 /* CHDocument.xib */,
+ EEEB2DDE16810422004DC719 /* CHChartPDFView.h */,
+ EEEB2DDF16810422004DC719 /* CHChartPDFView.m */,
EEEB2DD21680EE70004DC719 /* CHChartAreaView.h */,
EEEB2DD31680EE70004DC719 /* CHChartAreaView.m */,
EEEB2DB91680EA29004DC719 /* FromCharts */,
@@ -173,6 +185,8 @@
EEEB2DDD168100EA004DC719 /* Helpers */ = {
isa = PBXGroup;
children = (
+ EEEB2DE31681075A004DC719 /* CHDropView.h */,
+ EEEB2DE41681075A004DC719 /* CHDropView.m */,
EEEB2DDA1680FFC7004DC719 /* CHEnumToNumberTransformer.h */,
EEEB2DDB1680FFC7004DC719 /* CHEnumToNumberTransformer.m */,
);
@@ -257,6 +271,8 @@
EEEB2DD41680EE70004DC719 /* CHChartAreaView.m in Sources */,
EEEB2DD91680FA96004DC719 /* CHWindowController.m in Sources */,
EEEB2DDC1680FFC7004DC719 /* CHEnumToNumberTransformer.m in Sources */,
+ EEEB2DE016810423004DC719 /* CHChartPDFView.m in Sources */,
+ EEEB2DE51681075A004DC719 /* CHDropView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
BIN  growth-charts-helper.xcworkspace/xcuserdata/pp.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown
View
26 growth-charts-helper/CHChartAreaView.m
@@ -47,8 +47,8 @@ - (id)initWithFrame:(CGRect)frame
// self.clearsContextBeforeDrawing = NO;
// self.contentMode = UIViewContentModeRedraw;
- ((CATiledLayer *)self.layer).levelsOfDetail = 4;
- ((CATiledLayer *)self.layer).levelsOfDetailBias = 3; // we use (levelsOfDetail - 1) because we only need more detail when zoomed in, no less details when zoomed out
+// ((CATiledLayer *)self.layer).levelsOfDetail = 4;
+// ((CATiledLayer *)self.layer).levelsOfDetailBias = 3; // we use (levelsOfDetail - 1) because we only need more detail when zoomed in, no less details when zoomed out
}
return self;
}
@@ -63,8 +63,7 @@ - (void)setFromDictionary:(NSDictionary *)dict
// rect to origin and size
NSString *rectString = [dict objectForKey:@"rect"];
if ([rectString isKindOfClass:[NSString class]]) {
- DLog(@"Should use %@", rectString);
- CGRect rect = CGRectZero;//CGRectFromString(rectString);
+ NSRect rect = NSRectFromString(rectString);
self.origin = rect.origin;
self.size = rect.size;
}
@@ -81,8 +80,7 @@ - (void)setFromDictionary:(NSDictionary *)dict
if ([points count] > 2) {
CGMutablePathRef outlinePath = nil;
for (NSString *point in points) {
- DLog(@"Should use %@", point);
- CGPoint p = CGPointZero;//CGPointFromString(point);
+ NSPoint p = NSPointFromString(point);
if (!outlinePath) {
outlinePath = CGPathCreateMutable();
CGPathMoveToPoint(outlinePath, NULL, p.x, p.y);
@@ -188,7 +186,8 @@ - (void)positionInFrame:(CGRect)targetRect onView:(NSView *)aView pageSize:(CGSi
CGRect appliedRect = targetRect;
appliedRect.origin.x += _origin.x * appliedRect.size.width;
- appliedRect.origin.y += _origin.y * appliedRect.size.height;
+ //appliedRect.origin.y += _origin.y * appliedRect.size.height;
+ appliedRect.origin.y += (1.f - _origin.y) * appliedRect.size.height - (_size.height * appliedRect.size.height);
appliedRect.size.width *= _size.width;
appliedRect.size.height *= _size.height;
@@ -287,6 +286,12 @@ - (CGRect)contentBox
#pragma mark - Drawing
+- (void)drawRect:(NSRect)dirtyRect
+{
+ [[NSColor colorWithDeviceRed:1.f green:0.f blue:0.f alpha:0.25f] setFill];
+ [NSBezierPath fillRect:self.bounds];
+}
+
/**
* This is the drawing method we use, "drawRect:" is the wrong one if you intend to create subclasses!
*/
@@ -400,12 +405,7 @@ + (BOOL)registerClass:(Class)areaClass forType:(NSString *)aType
+ (Class)registeredClassForType:(NSString *)aType
{
- if (registeredAreaClasses) {
- return [registeredAreaClasses objectForKey:aType];
- }
-
- DLog(@"No class registered for type \"%@\"", aType);
- return nil;
+ return self;
}
View
38 growth-charts-helper/CHChartPDFView.h
@@ -0,0 +1,38 @@
+/*
+ CHChartPDFView.h
+ growth-charts-helper
+
+ Created by Pascal Pfiffner on 12/18/12.
+ Copyright (c) 2012 CHIP. All rights reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#import <Quartz/Quartz.h>
+
+@class CHChart;
+
+
+/**
+ * Top level object to display a PDF chart.
+ */
+@interface CHChartPDFView : PDFView
+
+@property (nonatomic, strong) CHChart *chart;
+
+- (void)layoutSubviews;
+
+
+@end
View
223 growth-charts-helper/CHChartPDFView.m
@@ -0,0 +1,223 @@
+/*
+ CHChartPDFView.m
+ growth-charts-helper
+
+ Created by Pascal Pfiffner on 12/18/12.
+ Copyright (c) 2012 CHIP. All rights reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#import "CHChartPDFView.h"
+#import "CHChart.h"
+#import "CHChartArea.h"
+#import "CHChartAreaView.h"
+
+
+@interface CHChartPDFView (){
+ CGSize lastSizeWhenPositioningAreas;
+}
+
+@property (nonatomic, strong) NSButton *zoomIn;
+@property (nonatomic, strong) NSButton *zoomOut;
+
+@property (nonatomic, strong) NSMutableSet *addedAreas;
+
+@end
+
+
+@implementation CHChartPDFView
+
+
+#pragma mark - PDF Drawing
+/**
+ * Called after the page has been drawn
+ */
+- (void)drawPagePost:(PDFPage *)page
+{
+ NSView *docView = [self documentView];
+ if (CGSizeEqualToSize(lastSizeWhenPositioningAreas, docView.bounds.size)) {
+ return;
+ }
+
+ NSUInteger pageNum = [self.document indexForPage:page] + 1;
+ NSSize pageSize = [self rowSizeForPage:page];
+ //NSRect pageBounds = [page boundsForBox:[self displayBox]]; // kPDFDisplayBoxCropBox is our default display mode, not kPDFDisplayBoxMediaBox
+ NSRect pageFrame = NSMakeRect(0.f, 0.f, pageSize.width, pageSize.height);
+
+ // remove old areas
+ if ([_addedAreas count] > 0) {
+ // TODO: Do NOT remove areas on other pages
+ [_addedAreas makeObjectsPerformSelector:@selector(removeFromSuperviewWithoutNeedingDisplay)];
+ [_addedAreas removeAllObjects];
+ }
+ if (!_addedAreas) {
+ self.addedAreas = [NSMutableSet set];
+ }
+
+ // add our areas
+ NSSet *areas = _chart.chartAreas;
+ if ([areas count] > 0) {
+ for (CHChartArea *area in areas) {
+ if (pageNum == area.page) {
+ CHChartAreaView *areaView = [area view];
+ [areaView positionInFrame:pageFrame onView:docView pageSize:docView.bounds.size];
+
+ [_addedAreas addObject:areaView];
+ }
+ else {
+ DLog(@"Skipping area %@, not on page %lu", area, pageNum);
+ }
+ }
+ }
+
+ lastSizeWhenPositioningAreas = docView.bounds.size;
+}
+
+
+
+#pragma mark - View Tasks
+- (void)viewWillMoveToSuperview:(NSView *)newSuperview
+{
+ if (newSuperview) {
+ [self addSubview:self.zoomIn];
+ [self addSubview:self.zoomOut];
+ }
+}
+
+- (void)resizeWithOldSuperviewSize:(NSSize)oldBoundsSize
+{
+ [super resizeWithOldSuperviewSize:oldBoundsSize];
+ [self layoutSubviews];
+}
+
+- (void)layoutSubviews
+{
+ // realign zoom buttons
+ NSSize mySize = self.bounds.size;
+
+ NSRect zoomFrame = _zoomIn.frame;
+ zoomFrame.origin.x = mySize.width - zoomFrame.size.width;
+ zoomFrame.origin.y = mySize.height - zoomFrame.size.height;
+ _zoomIn.frame = zoomFrame;
+
+ zoomFrame.origin.x -= zoomFrame.size.width;
+ _zoomOut.frame = zoomFrame;
+}
+
+
+/**
+ * We need this to override PDFView subviews intercepting our mouse events.
+ */
+- (NSView *)hitTest:(NSPoint)aPoint
+{
+ /*/
+ for (NSView *view in [self subviews]) {
+ DLog(@"-> %@", view);
+ for (NSView *view2 in [view subviews]) {
+ DLog(@"--> %@", view2);
+ for (NSView *view3 in [view2 subviews]) {
+ DLog(@"---> %@", view3);
+ for (NSView *view4 in [view3 subviews]) {
+ DLog(@"----> %@", view4);
+ if ([view4 isKindOfClass:NSClassFromString(@"PDFDisplayView")]) {
+ CGPoint inPoint = [view4 convertPoint:aPoint fromView:self];
+ if (NSPointInRect(inPoint, view4.bounds)) {
+ return self;
+ }
+ }
+ }
+ }
+ }
+ } //*/
+ return [super hitTest:aPoint];
+}
+
+
+
+#pragma mark - Mouse Clicks and Drags
+- (void)mouseDown:(NSEvent *)theEvent
+{
+ // mouseInCloseBox and trackingCloseBoxHit are instance variables
+ if (NSPointInRect([self convertPoint:[theEvent locationInWindow] fromView:nil], NSZeroRect)) {
+ }
+ else if ([theEvent clickCount] > 1) {
+ [[self window] miniaturize:self];
+ return;
+ }
+}
+
+- (void)mouseDragged:(NSEvent *)theEvent
+{
+ //NSPoint windowOrigin;
+ //NSWindow *window = [self window];
+
+ //[self convertPoint:[theEvent locationInWindow] fromView:nil]
+}
+
+- (void)mouseUp:(NSEvent *)theEvent
+{
+
+}
+
+
+
+#pragma mark - Mouse Wheel
+- (void)scrollWheel:(NSEvent *)event
+{
+ if (event.deltaY < 0.f) {
+ [self zoomOut:event];
+ }
+ else if (event.deltaY > 0.f) {
+ [self zoomIn:event];
+ }
+ //DLog(@"%f %f %f", event.deltaX, event.deltaY, event.deltaZ);
+}
+
+
+
+#pragma mark - KVC
+- (NSButton *)zoomIn
+{
+ if (!_zoomIn) {
+ self.zoomIn = [[NSButton alloc] initWithFrame:NSMakeRect(0.f, 0.f, 39.f, 38.f)];
+ //[_zoomIn setAutoresizingMask:NSViewMinXMargin]; // no luck, overriding setFrame:
+ [_zoomIn setButtonType:NSMomentaryPushInButton];
+ [_zoomIn setBezelStyle:NSCircularBezelStyle];
+ [_zoomIn setTitle:@"+"];
+ [_zoomIn setFont:[NSFont boldSystemFontOfSize:19.f]];
+ [_zoomIn setAction:@selector(zoomIn:)];
+ [_zoomIn setTarget:self];
+ }
+ return _zoomIn;
+}
+
+- (NSButton *)zoomOut
+{
+ if (!_zoomOut) {
+ self.zoomOut = [[NSButton alloc] initWithFrame:NSMakeRect(0.f, 0.f, 39.f, 38.f)];
+ //[_zoomIn setAutoresizingMask:NSViewMinXMargin]; // no luck, overriding setFrame:
+ [_zoomOut setButtonType:NSMomentaryPushInButton];
+ [_zoomOut setBezelStyle:NSCircularBezelStyle];
+ [_zoomOut setTitle:@"-"];
+ [_zoomOut setFont:[NSFont boldSystemFontOfSize:19.f]];
+ [_zoomOut setAction:@selector(zoomOut:)];
+ [_zoomOut setTarget:self];
+ }
+ return _zoomOut;
+}
+
+
+@end
View
2  growth-charts-helper/CHDocument.h
@@ -18,5 +18,7 @@
@property (nonatomic, strong) CHChart *chart;
+- (NSURL *)pdfWithSameName;
+
@end
View
29 growth-charts-helper/CHDocument.m
@@ -41,6 +41,28 @@ + (BOOL)autosavesInPlace
+#pragma mark - Chart Handling
+/**
+ * When loading a JSON, looks if there is a PDF with the same name in that directory, and returns the URL.
+ */
+- (NSURL *)pdfWithSameName
+{
+ if (!_chart) {
+ return nil;
+ }
+
+ NSString *fileName = [[self.fileURL lastPathComponent] stringByDeletingPathExtension];
+ NSString *pdfName = [fileName stringByAppendingString:@".pdf"];
+ NSString *pdfPath = [[[self.fileURL path] stringByDeletingLastPathComponent] stringByAppendingPathComponent:pdfName];
+ NSFileManager *fm = [NSFileManager defaultManager];
+ if ([fm fileExistsAtPath:pdfPath]) {
+ return [NSURL fileURLWithPath:pdfPath];
+ }
+ return nil;
+}
+
+
+
#pragma mark - File Reading and Writing
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
@@ -54,11 +76,16 @@ - (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
{
- DLog(@"type: %@", typeName);
+ if (![@"DocumentType" isEqualToString:typeName]) {
+ return NO;
+ }
+
+ self.chart = nil;
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:outError];
if ([dict isKindOfClass:[NSDictionary class]]) {
self.chart = [CHChart newFromJSONObject:dict];
}
+
return (nil != _chart);
}
View
38 growth-charts-helper/CHDropView.h
@@ -0,0 +1,38 @@
+/*
+ CHDropView.h
+ growth-charts-helper
+
+ Created by Pascal Pfiffner on 12/18/12.
+ Copyright (c) 2012 CHIP. All rights reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#import <Cocoa/Cocoa.h>
+
+extern NSString *const CHDropViewDroppedItemsNotificationName;
+extern NSString *const CHDropViewDroppedItemsKey;
+
+/**
+ * View accepting a drop action.
+ */
+@interface CHDropView : NSBox
+
+@property (nonatomic, copy) NSSet *acceptedTypes; ///< Accepted drop UTIs
+@property (nonatomic, assign) BOOL acceptMultiple;
+@property (nonatomic, assign) BOOL highlighted;
+
+
+@end
View
131 growth-charts-helper/CHDropView.m
@@ -0,0 +1,131 @@
+/*
+ CHDropView.m
+ growth-charts-helper
+
+ Created by Pascal Pfiffner on 12/18/12.
+ Copyright (c) 2012 CHIP. All rights reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#import "CHDropView.h"
+
+NSString *const CHDropViewDroppedItemsNotificationName = @"CHDropViewDroppedItemsNotification";
+NSString *const CHDropViewDroppedItemsKey = @"CHDropViewDroppedItems";
+
+
+@interface CHDropView ()
+
+@end
+
+
+@implementation CHDropView
+
+
+#pragma mark - Dragging and Dropping
+- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
+{
+ NSPasteboard *pboard = [sender draggingPasteboard];
+
+ // too many?
+ NSArray *items = [pboard pasteboardItems];
+ if (!_acceptMultiple && [items count] > 1) {
+ return NSDragOperationNone;
+ }
+
+ // the right kind?
+ NSWorkspace *ws = [NSWorkspace sharedWorkspace];
+ for (NSPasteboardItem *item in items) {
+ NSString *urlString = [item stringForType:(NSString *)kUTTypeFileURL];
+ NSURL *url = [NSURL URLWithString:urlString];
+
+ // determine file type
+ NSString *utiType = [ws typeOfFile:[url path] error:nil];
+ for (NSString *accType in _acceptedTypes) {
+ if (![ws type:utiType conformsToType:accType]) {
+ self.highlighted = NO;
+ return NSDragOperationNone;
+ }
+ }
+ }
+
+ self.highlighted = YES;
+ return NSDragOperationEvery;
+}
+
+- (void)draggingExited:(id <NSDraggingInfo>)sender
+{
+ self.highlighted = NO;
+}
+
+/**
+ * Sent when the item is being dropped.
+ */
+- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
+{
+ return YES;
+}
+
+/**
+ * Sent when "prepareForDragOperation:" returns YES.
+ */
+- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
+{
+ // notify of dropped items
+ NSPasteboard *pboard = [sender draggingPasteboard];
+ NSArray *dropped = [pboard pasteboardItems];
+ [[NSNotificationCenter defaultCenter] postNotificationName:CHDropViewDroppedItemsNotificationName object:self userInfo:@{CHDropViewDroppedItemsKey: dropped}];
+
+ return YES;
+}
+
+/**
+ * Sent when "performDragOperation:" returned YES.
+ */
+- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
+{
+ self.highlighted = NO;
+}
+
+
+
+#pragma mark - KVC
+- (void)setHighlighted:(BOOL)flag
+{
+ if (flag != _highlighted) {
+ _highlighted = flag;
+
+ // highlight
+ if (_highlighted) {
+ [self setBoxType:NSBoxCustom];
+ [self setBorderColor:[NSColor keyboardFocusIndicatorColor]];
+ [self setCornerRadius:5.f];
+ [self setBorderWidth:5.f];
+ [self setFillColor:[NSColor colorWithDeviceWhite:0.f alpha:0.1f]];
+ [self setContentViewMargins:CGSizeMake(-4.f, -4.f)];
+ }
+
+ // not
+ else {
+ [self setBoxType:NSBoxPrimary];
+ [self setContentViewMargins:CGSizeZero];
+ }
+
+ [self setNeedsDisplay:YES];
+ }
+}
+
+
+@end
View
8 growth-charts-helper/CHWindowController.h
@@ -23,6 +23,8 @@
#import <Cocoa/Cocoa.h>
@class CHChart;
+@class CHChartPDFView;
+@class CHDropView;
/**
@@ -31,5 +33,11 @@
@interface CHWindowController : NSWindowController <NSSplitViewDelegate>
@property (nonatomic, readonly, strong) CHChart *chart;
+@property (nonatomic, readonly, strong) CHChartPDFView *pdf;
+
+@property (nonatomic, weak) IBOutlet NSView *leftPane;
+@property (nonatomic, weak) IBOutlet NSView *rightPane;
+@property (nonatomic, strong) IBOutlet CHDropView *dropWell;
+
@end
View
74 growth-charts-helper/CHWindowController.m
@@ -22,16 +22,88 @@
#import "CHWindowController.h"
#import "CHDocument.h"
+#import "CHChartPDFView.h"
+#import "CHDropView.h"
@interface CHWindowController ()
+@property (nonatomic, readwrite, strong) CHChartPDFView *pdf;
+
+- (void)loadPDFAt:(NSURL *)url;
+- (void)didDropFiles:(NSNotification *)notification;
+
@end
@implementation CHWindowController
+#pragma mark - View Handling
+- (void)awakeFromNib
+{
+ // setup drop area
+ _dropWell.acceptedTypes = [NSSet setWithObject:NSPasteboardTypePDF];
+ [_dropWell registerForDraggedTypes:@[NSFilenamesPboardType]];
+
+ // does our file have a PDF?
+ [self loadPDFAt:[((CHDocument *)self.document) pdfWithSameName]];
+
+ // register for notifications
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didDropFiles:) name:CHDropViewDroppedItemsNotificationName object:nil];
+}
+
+- (void)didDropFiles:(NSNotification *)notification
+{
+ NSArray *items = [[notification userInfo] objectForKey:CHDropViewDroppedItemsKey];
+ if (1 == [items count]) {
+ NSPasteboardItem *item = [items lastObject];
+ NSString *urlString = [item stringForType:(NSString *)kUTTypeFileURL];
+ NSURL *url = [NSURL URLWithString:urlString];
+
+ [self loadPDFAt:url];
+ }
+ else {
+ DLog(@"We can only accept one item");
+ }
+}
+
+
+
+#pragma mark - PDF Handling
+- (void)loadPDFAt:(NSURL *)url
+{
+ DLog(@"--> %@", url);
+ if (!url) {
+ return;
+ }
+ if ([_pdf.document.documentURL isEqual:url]) {
+ DLog(@"Already loaded");
+ return;
+ }
+
+ [_pdf removeFromSuperview];
+
+ // create the PDF doc view
+ self.pdf = [CHChartPDFView new];
+ _pdf.autoresizingMask = NSViewHeightSizable | NSViewWidthSizable;
+ [_pdf setAllowsDragging:NO];
+ //[_pdf setAutoScales:YES];
+ [_pdf setDisplaysPageBreaks:NO]; // if we set this to YES, PDFKit adds a nice border around the page which offsets the actual PDF page and our areas are not correctly aligned
+
+ PDFDocument *pdfDoc = [[PDFDocument alloc] initWithURL:url];
+ [_pdf setDocument:pdfDoc];
+ _pdf.chart = self.chart;
+
+ // add as subview
+ _pdf.frame = _leftPane.bounds;
+ [_dropWell removeFromSuperview];
+ [_leftPane addSubview:_pdf];
+ [_pdf layoutSubviews];
+}
+
+
+
#pragma mark - Properties
- (CHChart *)chart
{
@@ -43,7 +115,7 @@ - (CHChart *)chart
#pragma mark - Split View Delegate
- (BOOL)splitView:(NSSplitView *)splitView shouldAdjustSizeOfSubview:(NSView *)subview
{
- return ([[splitView subviews] lastObject] != subview);
+ return (_rightPane != subview);
}
- (CGFloat)splitView:(NSSplitView *)splitView constrainSplitPosition:(CGFloat)proposedPosition ofSubviewAt:(NSInteger)dividerIndex
View
113 growth-charts-helper/en.lproj/CHDocument.xib
@@ -74,6 +74,7 @@
<int key="NSvFlags">268</int>
<string key="NSFrame">{{81, 71}, {64, 17}}</string>
<reference key="NSSuperview" ref="302773068"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="923488404"/>
<string key="NSReuseIdentifierKey">_NS:1535</string>
<bool key="NSEnabled">YES</bool>
@@ -112,12 +113,14 @@
</array>
<string key="NSFrame">{{1, 1}, {226, 156}}</string>
<reference key="NSSuperview" ref="770754110"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="238635562"/>
<string key="NSReuseIdentifierKey">_NS:11</string>
</object>
</array>
<string key="NSFrame">{{258, 366}, {228, 158}}</string>
<reference key="NSSuperview" ref="637764218"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="302773068"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<string key="NSOffsets">{0, 0}</string>
@@ -153,6 +156,7 @@
</array>
<string key="NSFrameSize">{746, 892}</string>
<reference key="NSSuperview" ref="586073561"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="770754110"/>
<string key="NSReuseIdentifierKey">_NS:11</string>
<string key="NSClassName">NSView</string>
@@ -166,6 +170,7 @@
<int key="NSvFlags">18</int>
<string key="NSFrame">{{13, 10}, {374, 868}}</string>
<reference key="NSSuperview" ref="923488404"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="94279693"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<array class="NSMutableArray" key="NSTabViewItems">
@@ -180,6 +185,7 @@
<int key="NSvFlags">266</int>
<string key="NSFrame">{{14, 747}, {326, 17}}</string>
<reference key="NSSuperview" ref="94279693"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="1060693171"/>
<string key="NSReuseIdentifierKey">_NS:1535</string>
<bool key="NSEnabled">YES</bool>
@@ -200,6 +206,7 @@
<int key="NSvFlags">266</int>
<string key="NSFrame">{{17, 717}, {320, 22}}</string>
<reference key="NSSuperview" ref="94279693"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="751776583"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="NSEnabled">YES</bool>
@@ -227,6 +234,7 @@
<int key="NSvFlags">266</int>
<string key="NSFrame">{{17, 662}, {320, 22}}</string>
<reference key="NSSuperview" ref="94279693"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="1050704721"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="NSEnabled">YES</bool>
@@ -249,6 +257,7 @@
<int key="NSvFlags">266</int>
<string key="NSFrame">{{17, 607}, {320, 22}}</string>
<reference key="NSSuperview" ref="94279693"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="863888780"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="NSEnabled">YES</bool>
@@ -271,6 +280,7 @@
<int key="NSvFlags">266</int>
<string key="NSFrame">{{17, 554}, {320, 22}}</string>
<reference key="NSSuperview" ref="94279693"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="287523268"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="NSEnabled">YES</bool>
@@ -293,6 +303,7 @@
<int key="NSvFlags">266</int>
<string key="NSFrame">{{14, 692}, {326, 17}}</string>
<reference key="NSSuperview" ref="94279693"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="763037372"/>
<string key="NSReuseIdentifierKey">_NS:1535</string>
<bool key="NSEnabled">YES</bool>
@@ -313,6 +324,7 @@
<int key="NSvFlags">266</int>
<string key="NSFrame">{{14, 637}, {326, 17}}</string>
<reference key="NSSuperview" ref="94279693"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="1038006853"/>
<string key="NSReuseIdentifierKey">_NS:1535</string>
<bool key="NSEnabled">YES</bool>
@@ -333,6 +345,7 @@
<int key="NSvFlags">266</int>
<string key="NSFrame">{{14, 582}, {326, 17}}</string>
<reference key="NSSuperview" ref="94279693"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="504544885"/>
<string key="NSReuseIdentifierKey">_NS:1535</string>
<bool key="NSEnabled">YES</bool>
@@ -353,6 +366,7 @@
<int key="NSvFlags">266</int>
<string key="NSFrame">{{14, 527}, {126, 17}}</string>
<reference key="NSSuperview" ref="94279693"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="9922798"/>
<string key="NSReuseIdentifierKey">_NS:1535</string>
<bool key="NSEnabled">YES</bool>
@@ -373,6 +387,7 @@
<int key="NSvFlags">266</int>
<string key="NSFrame">{{14, 499}, {326, 17}}</string>
<reference key="NSSuperview" ref="94279693"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="146738582"/>
<string key="NSReuseIdentifierKey">_NS:1535</string>
<bool key="NSEnabled">YES</bool>
@@ -393,6 +408,7 @@
<int key="NSvFlags">265</int>
<string key="NSFrame">{{145, 522}, {194, 25}}</string>
<reference key="NSSuperview" ref="94279693"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="266308193"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="NSEnabled">YES</bool>
@@ -430,7 +446,8 @@
<int key="NSvFlags">266</int>
<string key="NSFrame">{{17, 386}, {320, 105}}</string>
<reference key="NSSuperview" ref="94279693"/>
- <reference key="NSNextKeyView" ref="1064016189"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="356821382"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<string key="NSAntiCompressionPriority">{250, 750}</string>
<bool key="NSEnabled">YES</bool>
@@ -452,6 +469,7 @@
<int key="NSvFlags">266</int>
<string key="NSFrame">{{17, 772}, {320, 22}}</string>
<reference key="NSSuperview" ref="94279693"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="792253015"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="NSEnabled">YES</bool>
@@ -474,6 +492,7 @@
<int key="NSvFlags">266</int>
<string key="NSFrame">{{14, 802}, {326, 17}}</string>
<reference key="NSSuperview" ref="94279693"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="457686569"/>
<string key="NSReuseIdentifierKey">_NS:1535</string>
<bool key="NSEnabled">YES</bool>
@@ -489,21 +508,22 @@
</object>
<bool key="NSAllowsLogicalLayoutDirection">NO</bool>
</object>
- <object class="NSTextField" id="1064016189">
+ <object class="NSTextField" id="356821382">
<reference key="NSNextResponder" ref="94279693"/>
<int key="NSvFlags">268</int>
<string key="NSFrame">{{14, 361}, {326, 17}}</string>
<reference key="NSSuperview" ref="94279693"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:1535</string>
<bool key="NSEnabled">YES</bool>
- <object class="NSTextFieldCell" key="NSCell" id="126504592">
+ <object class="NSTextFieldCell" key="NSCell" id="687410529">
<int key="NSCellFlags">68157504</int>
<int key="NSCellFlags2">272630784</int>
<string key="NSContents"># Top Level Areas</string>
<reference key="NSSupport" ref="653464429"/>
<string key="NSCellIdentifier">_NS:1535</string>
- <reference key="NSControlView" ref="1064016189"/>
+ <reference key="NSControlView" ref="356821382"/>
<reference key="NSBackgroundColor" ref="238096786"/>
<reference key="NSTextColor" ref="448304600"/>
</object>
@@ -512,6 +532,7 @@
</array>
<string key="NSFrame">{{10, 33}, {354, 822}}</string>
<reference key="NSSuperview" ref="632799389"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="973488353"/>
<string key="NSReuseIdentifierKey">_NS:11</string>
</object>
@@ -544,6 +565,7 @@
</array>
<string key="NSFrame">{{747, 0}, {400, 892}}</string>
<reference key="NSSuperview" ref="586073561"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="632799389"/>
<string key="NSReuseIdentifierKey">_NS:13</string>
<string key="NSClassName">NSView</string>
@@ -551,6 +573,7 @@
</array>
<string key="NSFrameSize">{1147, 892}</string>
<reference key="NSSuperview" ref="568628114"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="637764218"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="NSIsVertical">YES</bool>
@@ -559,6 +582,7 @@
</array>
<string key="NSFrameSize">{1147, 892}</string>
<reference key="NSSuperview"/>
+ <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="586073561"/>
</object>
<string key="NSScreenRect">{{0, 0}, {2560, 1418}}</string>
@@ -585,6 +609,30 @@
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
+ <string key="label">leftPane</string>
+ <reference key="source" ref="512844837"/>
+ <reference key="destination" ref="637764218"/>
+ </object>
+ <int key="connectionID">100132</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">rightPane</string>
+ <reference key="source" ref="512844837"/>
+ <reference key="destination" ref="923488404"/>
+ </object>
+ <int key="connectionID">100133</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">dropWell</string>
+ <reference key="source" ref="512844837"/>
+ <reference key="destination" ref="770754110"/>
+ </object>
+ <int key="connectionID">100134</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
<string key="label">delegate</string>
<reference key="source" ref="275939982"/>
<reference key="destination" ref="512844837"/>
@@ -718,10 +766,10 @@
<object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
<string key="label">displayPatternValue1: chart.numAreas</string>
- <reference key="source" ref="1064016189"/>
+ <reference key="source" ref="356821382"/>
<reference key="destination" ref="512844837"/>
<object class="NSNibBindingConnector" key="connector">
- <reference key="NSSource" ref="1064016189"/>
+ <reference key="NSSource" ref="356821382"/>
<reference key="NSDestination" ref="512844837"/>
<string key="NSLabel">displayPatternValue1: chart.numAreas</string>
<string key="NSBinding">displayPatternValue1</string>
@@ -872,7 +920,7 @@
<reference ref="1050704721"/>
<reference ref="973488353"/>
<reference ref="457686569"/>
- <reference ref="1064016189"/>
+ <reference ref="356821382"/>
<reference ref="287523268"/>
</array>
<reference key="parent" ref="791241501"/>
@@ -1066,16 +1114,16 @@
</object>
<object class="IBObjectRecord">
<int key="objectID">100118</int>
- <reference key="object" ref="1064016189"/>
+ <reference key="object" ref="356821382"/>
<array class="NSMutableArray" key="children">
- <reference ref="126504592"/>
+ <reference ref="687410529"/>
</array>
<reference key="parent" ref="94279693"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">100119</int>
- <reference key="object" ref="126504592"/>
- <reference key="parent" ref="1064016189"/>
+ <reference key="object" ref="687410529"/>
+ <reference key="parent" ref="356821382"/>
</object>
</array>
</object>
@@ -1086,6 +1134,7 @@
<string key="100034.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="100035.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="100036.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string key="100046.CustomClassName">CHDropView</string>
<string key="100046.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="100047.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="100048.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -1137,9 +1186,47 @@
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
- <int key="maxID">100131</int>
+ <int key="maxID">100138</int>
+ </object>
+ <object class="IBClassDescriber" key="IBDocument.Classes">
+ <array class="NSMutableArray" key="referencedPartialClassDescriptions">
+ <object class="IBPartialClassDescription">
+ <string key="className">CHDropView</string>
+ <string key="superclassName">NSBox</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">./Classes/CHDropView.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">CHWindowController</string>
+ <string key="superclassName">NSWindowController</string>
+ <dictionary class="NSMutableDictionary" key="outlets">
+ <string key="dropWell">CHDropView</string>
+ <string key="leftPane">NSView</string>
+ <string key="rightPane">NSView</string>
+ </dictionary>
+ <dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
+ <object class="IBToOneOutletInfo" key="dropWell">
+ <string key="name">dropWell</string>
+ <string key="candidateClassName">CHDropView</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="leftPane">
+ <string key="name">leftPane</string>
+ <string key="candidateClassName">NSView</string>
+ </object>
+ <object class="IBToOneOutletInfo" key="rightPane">
+ <string key="name">rightPane</string>
+ <string key="candidateClassName">NSView</string>
+ </object>
+ </dictionary>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">./Classes/CHWindowController.h</string>
+ </object>
+ </object>
+ </array>
</object>
- <object class="IBClassDescriber" key="IBDocument.Classes"/>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaFramework</string>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencies">
Please sign in to comment.
Something went wrong with that request. Please try again.