Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 767b3de0e157889b3e452bc6fc47b41aa713d7a8 Alex Rozanski committed Apr 21, 2010
@@ -0,0 +1,20 @@
+//
+// PXNavigationBarAppDelegate.h
+// PXNavigationBar
+//
+// Created by Alex Rozanski on 14/02/2010.
+// Copyright 2010 Alex Rozanski http://perspx.com
+//
+
+#import <Cocoa/Cocoa.h>
+
+@class PXNavigationBar;
+
+@interface AppDelegate : NSObject <NSApplicationDelegate> {
+ IBOutlet NSWindow *window;
+ IBOutlet PXNavigationBar *navigationBar;
+}
+
+- (IBAction)pushLevel:(id)sender;
+
+@end
@@ -0,0 +1,41 @@
+//
+// PXNavigationBarAppDelegate.m
+// PXNavigationBar
+//
+// Created by Alex Rozanski on 14/02/2010.
+// Copyright 2010 Alex Rozanski http://perspx.com
+//
+
+#import "AppDelegate.h"
+
+#import "PXNavigationBar.h"
+
+@implementation AppDelegate
+
+- (void)awakeFromNib
+{
+ PXNavigationItem *item = [PXNavigationItem itemWithTitle:@"Root"];
+ PXNavigationLevel *rootLevel = [[PXNavigationLevel alloc] initWithItem:item];
+
+ [navigationBar pushNavigationLevel:rootLevel];
+}
+
+/* This method is simply to demonstrate pushing a level to the navigation hierarchy
+ so that the effects of moving up levels or between items in the current level can be seen */
+- (IBAction)pushLevel:(id)sender
+{
+
+ //Set up the navigation level
+ NSArray *itemArray = [NSArray arrayWithObjects:[PXNavigationItem itemWithTitle:@"Item 1"],
+ [PXNavigationItem itemWithTitle:@"Item 2"],
+ [PXNavigationItem itemWithTitle:@"Item 3"],
+ [PXNavigationItem itemWithTitle:@"Item 4"], nil];
+ PXNavigationLevel *level = [[PXNavigationLevel alloc] initWithItems:itemArray];
+
+ //Set the selected item to a random index
+ [level setCurrentItemIndex:random()%4];
+
+ [navigationBar pushNavigationLevel:level];
+}
+
+@end
@@ -0,0 +1,16 @@
+//
+// PXBackButtonCell.h
+// PXNavigationBar
+//
+// Created by Alex Rozanski on 15/02/2010.
+// Copyright 2010 Alex Rozanski http://perspx.com
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface PXBackButtonCell : NSButtonCell {
+
+}
+
+@end
@@ -0,0 +1,75 @@
+//
+// PXBackButtonCell.m
+// PXNavigationBar
+//
+// Created by Alex Rozanski on 15/02/2010.
+// Copyright 2010 Alex Rozanski http://perspx.com
+//
+
+#import "PXBackButtonCell.h"
+
+
+#define BUTTON_FONT [NSFont boldSystemFontOfSize:11]
+
+@implementation PXBackButtonCell
+
+#pragma mark -
+#pragma mark Sizing
+
+- (NSSize)cellSize
+{
+ NSAttributedString *string = [self attributedTitle];
+ NSSize size = [string size];
+
+ return NSMakeSize(size.width+20, size.height+10);
+}
+
+- (NSRect)titleRectForBounds:(NSRect)bounds
+{
+ NSSize titleSize = [[self attributedTitle] size];
+ NSRect titleRect = NSMakeRect(NSMidX(bounds)-(titleSize.width/2)+3, NSMidY(bounds)-(titleSize.height/2),
+ titleSize.width, titleSize.height);
+
+ titleRect.origin.y-=1;
+
+ return titleRect;
+}
+
+#pragma mark -
+#pragma mark Drawing
+
+- (NSAttributedString*)attributedTitle
+{
+ NSShadow *textShadow = [[[NSShadow alloc] init] autorelease];
+ [textShadow setShadowColor:[NSColor whiteColor]];
+ [textShadow setShadowOffset:NSMakeSize(0, -1)];
+ NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:BUTTON_FONT, NSFontAttributeName,
+ textShadow, NSShadowAttributeName, nil];
+
+ NSAttributedString *string = [[[NSAttributedString alloc] initWithString:[self title]
+ attributes:attributes] autorelease];
+
+ return string;
+}
+
+- (void)drawBezelWithFrame:(NSRect)frame inView:(NSView *)controlView
+{
+ NSImage *leftImage, *middleImage, *rightImage;
+
+ //Load the images based on the button state
+ if([self isHighlighted]) {
+ leftImage = [NSImage imageNamed:@"BackButtonPressedLeft"];
+ middleImage = [NSImage imageNamed:@"BackButtonPressedMiddle"];
+ rightImage = [NSImage imageNamed:@"BackButtonPressedRight"];
+ }
+ else {
+ leftImage = [NSImage imageNamed:@"BackButtonNormalLeft"];
+ middleImage = [NSImage imageNamed:@"BackButtonNormalMiddle"];
+ rightImage = [NSImage imageNamed:@"BackButtonNormalRight"];
+ }
+
+ NSDrawThreePartImage(frame, leftImage, middleImage, rightImage,
+ NO, NSCompositeSourceOver, 1, [[self controlView] isFlipped]);
+}
+
+@end
@@ -0,0 +1,44 @@
+//
+// PXNavigationBar.h
+// PXNavigationBar
+//
+// Created by Alex Rozanski on 14/02/2010.
+// Copyright 2010 Alex Rozanski http://perspx.com
+//
+
+#import <Cocoa/Cocoa.h>
+
+#import "PXNavigationLevel.h"
+#import "PXNavigationItem.h"
+
+@interface PXNavigationBar : NSView {
+ NSMutableArray *_navigationLevels;
+
+ id _delegate;
+}
+
+@property (retain) NSArray *navigationLevels;
+@property (assign) id delegate;
+
+- (void)pushNavigationLevel:(PXNavigationLevel*)level;
+- (void)popNavigationLevel;
+
+- (PXNavigationLevel*)currentNavigationLevel;
+- (PXNavigationItem*)currentNavigationItem;
+- (PXNavigationLevel*)parentLevel;
+- (PXNavigationItem*)parentItem;
+
+@end
+
+@protocol PXNavigationBarDelegate
+
+@optional
+- (BOOL)navigationBar:(PXNavigationBar*)aNavigationBar shouldPushLevel:(PXNavigationLevel*)aLevel;
+- (void)navigationBar:(PXNavigationBar*)aNavigationBar didPushLevel:(PXNavigationLevel*)aLevel;
+
+- (BOOL)navigationBar:(PXNavigationBar*)aNavigationBar shouldPopLevel:(PXNavigationLevel*)aLevel;
+- (void)navigationBar:(PXNavigationBar*)aNavigationBar didPopLevel:(PXNavigationLevel*)aLevel;
+
+@end
+
+
Oops, something went wrong.

0 comments on commit 767b3de

Please sign in to comment.