Permalink
Browse files

Initial commit from archive.

This is a port of the sample code from Max OS X to iOS (iPad). WWDC 2010
Session 141, “Crafting Custom Cocoa Views”
  • Loading branch information...
0 parents commit da5fbff30525f6ce592c7463b6639d7e9dc851e3 @epreston committed Aug 18, 2011
Showing with 4,662 additions and 0 deletions.
  1. +30 −0 .gitignore
  2. +23 −0 Example 1/Classes/Controller/PSHTreeGraphAppDelegate.h
  3. +69 −0 Example 1/Classes/Controller/PSHTreeGraphAppDelegate.m
  4. +29 −0 Example 1/Classes/Controller/PSHTreeGraphViewController.h
  5. +133 −0 Example 1/Classes/Controller/PSHTreeGraphViewController.m
  6. +59 −0 Example 1/Classes/Model/ObjCClass/ObjCClassWrapper.h
  7. +138 −0 Example 1/Classes/Model/ObjCClass/ObjCClassWrapper.m
  8. +26 −0 Example 1/Classes/View/PSHLeafView.h
  9. +29 −0 Example 1/Classes/View/PSHLeafView.m
  10. +18 −0 Example 1/Classes/View/PSHTreeGraphView.h
  11. +28 −0 Example 1/Classes/View/PSHTreeGraphView.m
  12. +12 −0 Example 1/Entitlements.plist
  13. BIN Example 1/Graphics/GObject.png
  14. BIN Example 1/Graphics/Icon-72.png
  15. BIN Example 1/Graphics/TreeViewDirectLinesButton.png
  16. BIN Example 1/Graphics/TreeViewOrthogonalLinesButton.png
  17. BIN Example 1/Graphics/TreeViewSubtreeCollapsedButton.png
  18. BIN Example 1/Graphics/TreeViewSubtreeExpandedButton.png
  19. +221 −0 Example 1/Interface/MainWindow.xib
  20. +325 −0 Example 1/Interface/ObjCClassTreeNodeView.xib
  21. +236 −0 Example 1/Interface/PSHTreeGraphViewController.xib
  22. +51 −0 Example 1/PSHTreeGraph-Info.plist
  23. +414 −0 Example 1/PSHTreeGraph.xcodeproj/project.pbxproj
  24. +72 −0 Example 1/PSHTreeGraph.xcodeproj/xcshareddata/xcschemes/PSHTreeGraph.xcscheme
  25. +8 −0 Example 1/PSHTreeGraph_Prefix.pch
  26. +17 −0 Example 1/main.m
  27. +30 −0 PSTreeGraphView/PSBaseBranchView.h
  28. +248 −0 PSTreeGraphView/PSBaseBranchView.m
  29. +56 −0 PSTreeGraphView/PSBaseLeafView.h
  30. +207 −0 PSTreeGraphView/PSBaseLeafView.m
  31. +142 −0 PSTreeGraphView/PSBaseSubtreeView.h
  32. +629 −0 PSTreeGraphView/PSBaseSubtreeView.m
  33. +319 −0 PSTreeGraphView/PSBaseTreeGraphView.h
  34. +958 −0 PSTreeGraphView/PSBaseTreeGraphView.m
  35. +87 −0 PSTreeGraphView/PSBaseTreeGraphView_Internal.h
  36. +48 −0 PSTreeGraphView/PSTreeGraphModelNode.h
  37. BIN horizontal.png
  38. BIN vertical.png
@@ -0,0 +1,30 @@
+# OSX Specific System Files
+.DS_Store
+profile
+*.swp
+ehthumbs.db
+Thumbs.db
+
+# Backup files
+*~.nib
+
+# Xcode Specific Files
+build/*
+*.pbxuser
+!default.pbxuser
+*.mode1v3
+!default.mode1v3
+*.mode2v3
+!default.mode2v3
+*.perspectivev3
+!default.perspectivev3
+*.xcworkspace
+!default.xcworkspace
+xcuserdata
+*.moved-aside
+
+# Textmate - if you build your xcode projects with it
+*.tm_build_errors
+
+# old skool
+.svn
@@ -0,0 +1,23 @@
+//
+// PSHTreeGraphAppDelegate.h
+// PSHTreeGraph - Example 1
+//
+// Created by Ed Preston on 7/25/10.
+// Copyright Preston Software 2010. All rights reserved.
+//
+
+
+#import <UIKit/UIKit.h>
+
+@class PSHTreeGraphViewController;
+
+@interface PSHTreeGraphAppDelegate : NSObject <UIApplicationDelegate> {
+ UIWindow *window;
+ PSHTreeGraphViewController *viewController;
+}
+
+@property (nonatomic, retain) IBOutlet UIWindow *window;
+@property (nonatomic, retain) IBOutlet PSHTreeGraphViewController *viewController;
+
+@end
+
@@ -0,0 +1,69 @@
+//
+// PSHTreeGraphAppDelegate.m
+// PSHTreeGraph - Example 1
+//
+// Created by Ed Preston on 7/25/10.
+// Copyright Preston Software 2010. All rights reserved.
+//
+
+
+#import "PSHTreeGraphAppDelegate.h"
+#import "PSHTreeGraphViewController.h"
+
+@implementation PSHTreeGraphAppDelegate
+
+@synthesize window;
+@synthesize viewController;
+
+
+#pragma mark -
+#pragma mark Application Lifecycle
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
+
+ // Override point for customization after app launch.
+ [window addSubview:viewController.view];
+ [window makeKeyAndVisible];
+
+ return YES;
+}
+
+
+- (void)applicationWillResignActive:(UIApplication *)application {
+ // Sent when the application is about to move from active to inactive state. This can occur for
+ // certain types of temporary interruptions (such as an incoming phone call or SMS message) or
+ // when the user quits the application and it begins the transition to the background state.
+ //
+ // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates.
+ // Games should use this method to pause the game.
+}
+
+
+- (void)applicationDidBecomeActive:(UIApplication *)application {
+ // Restart any tasks that were paused (or not yet started) while the application was inactive.
+ // If the application was previously in the background, optionally refresh the user interface.
+}
+
+
+- (void)applicationWillTerminate:(UIApplication *)application {
+ // Called when the application is about to terminate.
+ // See also applicationDidEnterBackground:.
+}
+
+
+#pragma mark -
+#pragma mark Memory Management
+
+- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
+ // Free up as much memory as possible by purging cached data objects that can be recreated
+ // (or reloaded from disk) later.
+}
+
+- (void)dealloc {
+ [viewController release];
+ [window release];
+ [super dealloc];
+}
+
+
+@end
@@ -0,0 +1,29 @@
+//
+// PSHTreeGraphViewController.h
+// PSHTreeGraph - Example 1
+//
+// Created by Ed Preston on 7/25/10.
+// Copyright Preston Software 2010. All rights reserved.
+//
+
+
+#import <UIKit/UIKit.h>
+#import "PSTreeGraphModelNode.h"
+
+
+@class PSBaseTreeGraphView;
+
+@interface PSHTreeGraphViewController : UIViewController <PSTreeGraphDelegate> {
+ PSBaseTreeGraphView *treeGraphView;
+ NSString *rootClassName;
+}
+
+// The TreeGraph
+@property(assign) IBOutlet PSBaseTreeGraphView *treeGraphView;
+
+// The name of the root class that the TreeGraph is currently showing.
+@property(copy) NSString *rootClassName;
+
+
+@end
+
@@ -0,0 +1,133 @@
+//
+// PSHTreeGraphViewController.m
+// PSHTreeGraph - Example 1
+//
+// Created by Ed Preston on 7/25/10.
+// Copyright Preston Software 2010. All rights reserved.
+//
+
+
+#import "PSHTreeGraphViewController.h"
+
+#import "PSBaseTreeGraphView.h"
+#import "PSHLeafView.h"
+
+#import "ObjCClassWrapper.h"
+
+@implementation PSHTreeGraphViewController
+
+
+#pragma mark -
+#pragma mark Property Accessors
+
+@synthesize treeGraphView;
+
+- (NSString *)rootClassName {
+ return rootClassName;
+}
+
+- (void)setRootClassName:(NSString *)newRootClassName {
+
+ NSParameterAssert(newRootClassName != nil);
+
+ if (![rootClassName isEqualToString:newRootClassName]) {
+ [rootClassName release];
+ rootClassName = [newRootClassName copy];
+
+ // Get an ObjCClassWrapper for the named Objective-C Class, and set it as the TreeGraph's root.
+ [treeGraphView setModelRoot:[ObjCClassWrapper wrapperForClassNamed:rootClassName]];
+ }
+}
+
+
+#pragma mark -
+#pragma mark View Creation and Initializer
+
+// The designated initializer. Override to perform setup that is required before the view is loaded.
+//- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
+// if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
+// // Custom initialization
+// }
+// return self;
+//}
+
+
+// Implement loadView to create a view hierarchy programmatically, without using a nib.
+//- (void)loadView {
+//}
+
+
+// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
+- (void)viewDidLoad {
+ [super viewDidLoad];
+
+ // Set the delegate to self.
+ [treeGraphView setDelegate:self];
+
+ // Specify a .nib file for the TreeGraph to load each time it needs to create a new node view.
+ [treeGraphView setNodeViewNibName:@"ObjCClassTreeNodeView"];
+
+ // Specify a starting root class to inspect on launch.
+ [self setRootClassName:@"UIControl"];
+}
+
+
+// Override to allow orientations other than the default portrait orientation.
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
+ return YES;
+}
+
+- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+ duration:(NSTimeInterval)duration {
+
+ // Keep the view in sync
+ [treeGraphView parentClipViewDidResize:nil];
+}
+
+
+#pragma mark -
+#pragma mark TreeGraph Delegate
+
+-(void) configureNodeView:(UIView *)nodeView
+ withModelNode:(id <PSTreeGraphModelNode> )modelNode {
+
+ NSParameterAssert(nodeView != nil);
+ NSParameterAssert(modelNode != nil);
+
+ // NOT FLEXIBLE: treat it like a model node instead of the interface.
+ ObjCClassWrapper *objectWrapper = (ObjCClassWrapper *)modelNode;
+ PSHLeafView *leafView = (PSHLeafView *)nodeView;
+
+ // button
+ if ( [[objectWrapper childModelNodes] count] == 0 ) {
+ [leafView.expandButton setHidden:YES];
+ }
+
+ // labels
+ leafView.titleLabel.text = [objectWrapper name];
+ leafView.detailLabel.text = [NSString stringWithFormat:@"%d bytes", [objectWrapper wrappedClassInstanceSize]];
+
+}
+
+
+#pragma mark -
+#pragma mark Memory Management
+
+- (void)didReceiveMemoryWarning {
+ // Releases the view if it doesn't have a superview.
+ [super didReceiveMemoryWarning];
+
+ // Release any cached data, images, etc that aren't in use.
+}
+
+- (void)viewDidUnload {
+ // Release any retained subviews of the main view.
+ // e.g. self.myOutlet = nil;
+}
+
+- (void)dealloc {
+ [rootClassName release];
+ [super dealloc];
+}
+
+@end
@@ -0,0 +1,59 @@
+
+// File: ObjCClassWrapper.h
+// Abstract: ObjCClassWrapper Interface
+// Version: 1.1
+//
+// Based largely on Apple TreeView's example.
+
+
+#import <Foundation/Foundation.h>
+#import "PSTreeGraphModelNode.h"
+
+
+// Wraps an Objective-C Class in an NSObject, that we can conveninently query to find
+// related classes (superclass and subclasses) and the instance size. Conforms to
+// the PSTreeGraphModelNode protocol, so that we can use these as model nodes with a TreeGraph.
+
+@interface ObjCClassWrapper : NSObject <PSTreeGraphModelNode, NSCopying>
+{
+ Class wrappedClass;
+ NSMutableArray *subclassesCache;
+}
+
+
+#pragma mark -
+#pragma mark Creating Instances
+
+// Returns an ObjCClassWrapper for the given Objective-C class. ObjCClassWrapper maintains
+// a set of unique instances, so this will always return the same ObjCClassWrapper for a given Class.
+
++ (ObjCClassWrapper *)wrapperForClass:(Class)aClass;
+
+// Returns an ObjCClassWrapper for the given Objective-C class, by looking the Class up by
+// name and then invoking +wrapperForClass:
+
++ (ObjCClassWrapper *)wrapperForClassNamed:(NSString *)aClassName;
+
+
+#pragma mark -
+#pragma mark Property Accessors
+
+// The wrappedClass' name (e.g. @"UIButton")
+
+@property(readonly) NSString *name;
+
+// An ObjCClassWrapper representing the wrappedClass' superclass.
+
+@property(readonly) ObjCClassWrapper *superclassWrapper;
+
+// An array of ObjCClassWrappers representing the wrappedClass' subclasses.
+// (For convenience, the subclasses are sorted by name.)
+
+@property(readonly) NSArray *subclasses;
+
+// The wrappedClass' intrinsic instance size (which doesn't include external/auxiliary storage).
+
+@property(readonly) size_t wrappedClassInstanceSize;
+
+
+@end
Oops, something went wrong.

0 comments on commit da5fbff

Please sign in to comment.