Skip to content

Commit

Permalink
Added ARC Support
Browse files Browse the repository at this point in the history
Added ARC Support and refactored to move the sidebar classes to a
separate directory
  • Loading branch information
erndev authored and erndev committed Nov 7, 2011
1 parent 75a0a51 commit ae4a7e3
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 34 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Expand Up @@ -15,7 +15,7 @@ EDSidebar.xcodeproj/ernesto.mode1v3
*.xcuserstate
project.xcworkspace/
xcuserdata/

DerivedData/
# Generated files
*.[oa]
*.pyc
Expand All @@ -28,4 +28,5 @@ dist/
build/

# Backup files
*~.nib
*~.nib

1 change: 1 addition & 0 deletions BlackCell.h
Expand Up @@ -11,6 +11,7 @@

@interface BlackCell : NSButtonCell {

NSShadow *_shadow;
}

@end
20 changes: 14 additions & 6 deletions BlackCell.m
Expand Up @@ -18,17 +18,26 @@ -(id)init
self = [super init];
if ( self )
{
_shadow = [[NSShadow alloc] init] ;

[self setHighlightsBy:NSContentsCellMask];

}
return self;

}
#if !__has_feature(objc_arc)
-(void)dealloc
{

[_shadow release];
}
#endif
- (void)drawWithFrame:(NSRect)frame inView:(NSView *)view {

[[NSColor blackColor] setFill];
NSRectFill(frame);
NSImage *img = nil;
NSShadow *shadow = nil;

// Just a test. Should handle highlight better
if( [self state] == NSOnState )
Expand All @@ -43,11 +52,10 @@ - (void)drawWithFrame:(NSRect)frame inView:(NSView *)view {
{
img = [self image];
// simulate outer glow using a shadow
shadow = [[[NSShadow alloc] init] autorelease];
[shadow setShadowColor:[NSColor colorWithDeviceRed:115.0/225.0 green:215.0/225.0 blue:245.0/225.0 alpha:1.0] ];
[shadow setShadowBlurRadius:5];
[shadow setShadowOffset:NSMakeSize(0, 0)]; //[NSColor colorWithDeviceRed:0.0 green:0.0 blue:0.0 alpha:1.0];
[shadow set];
[_shadow setShadowColor:[NSColor colorWithDeviceRed:115.0/225.0 green:215.0/225.0 blue:245.0/225.0 alpha:1.0] ];
[_shadow setShadowBlurRadius:5];
[_shadow setShadowOffset:NSMakeSize(0, 0)]; //[NSColor colorWithDeviceRed:0.0 green:0.0 blue:0.0 alpha:1.0];
[_shadow set];
}
NSRect imgRect = NSInsetRect(frame, ( NSWidth(frame) -[img size].width)/2.0, ( NSHeight(frame) -[img size].height)/2.0);
[img drawInRect:imgRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0 respectFlipped:YES hints:nil] ;
Expand Down
18 changes: 12 additions & 6 deletions EDSideBar.h → EDSideBar/EDSideBar.h
Expand Up @@ -10,7 +10,13 @@

@class EDSideBar;


#if __has_feature(objc_arc)
#define EDSideBarRetain nonatomic, strong
#define EDSideBarAssign nonatomic, unsafe_unretained
#else
#define EDSideBarRetain nonatomic, retain
#define EDSideBarAssign nonatomic, assign
#endif

@protocol EDSideBarDelegate <NSObject>
@required
Expand Down Expand Up @@ -47,11 +53,11 @@ typedef NSUInteger ECSideBarLayoutMode;
-(void)setSelectionImage:(NSImage*)image;
-(id)cellForItem:(NSInteger)index;

@property (nonatomic,retain) NSColor *backgroundColor;
@property (nonatomic,retain) id<EDSideBarDelegate>sidebarDelegate;
@property (nonatomic,retain,setter=setCellClass:) Class cellClass;
@property (setter=setLayoutMode:) ECSideBarLayoutMode layoutMode;
@property (setter=setButtonsHeight:) CGFloat buttonsHeight;
@property (EDSideBarRetain) NSColor *backgroundColor;
@property (EDSideBarRetain) id<EDSideBarDelegate>sidebarDelegate;
@property (EDSideBarAssign,setter=setCellClass:) Class cellClass;
@property (nonatomic, setter=setLayoutMode:) ECSideBarLayoutMode layoutMode;
@property (nonatomic, setter=setButtonsHeight:) CGFloat buttonsHeight;
@property BOOL animateSelection;
@property NSTimeInterval animationDuration;
@end
13 changes: 8 additions & 5 deletions EDSideBar.m → EDSideBar/EDSideBar.m
Expand Up @@ -30,7 +30,9 @@ - (void)setTextColor:(NSColor *)textColor
range:range];
[attrTitle fixAttributesInRange:range];
[self setAttributedTitle:attrTitle];
#if !__has_feature(objc_arc)
[attrTitle release];
#endif
}
-(id)init
{
Expand Down Expand Up @@ -111,9 +113,9 @@ - (void)drawBezelWithFrame:(NSRect)frame inView:(NSView *)view {
NSRect rectGradient = NSMakeRect(0-0.5, NSMinY(frame)-1-0.5, NSWidth(frame)-1, 4.0);
NSBezierPath *path = [NSBezierPath bezierPathWithRect:rectGradient];
[gradient drawInBezierPath:path angle:90];

#if !__has_feature(objc_arc)
[gradient release];

#endif
}

// Inset in the right
Expand Down Expand Up @@ -180,13 +182,14 @@ - (id)initWithFrame:(NSRect)frame {
}
return self;
}

-(void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
#if !__has_feature(objc_arc)
[_backgroundColor dealloc];
[_matrix dealloc];
[super dealloc];
#endif
}

-(void)drawBackground:(NSRect)rect
Expand All @@ -205,8 +208,8 @@ - (void)drawRect:(NSRect)dirtyRect {

-(void)selectButtonAtRow:(NSUInteger)row
{
int rowToSelect = row;
if( row <0 || [_matrix numberOfRows]< row )
NSUInteger rowToSelect = row;
if( [_matrix numberOfRows]< row )
rowToSelect =0;
[_matrix setState:(NSInteger)NSOnState atRow:(NSInteger)rowToSelect column:(NSInteger)0];
[self moveSelectionImage];
Expand Down
32 changes: 19 additions & 13 deletions EDSidebar.xcodeproj/project.pbxproj
Expand Up @@ -8,16 +8,16 @@

/* Begin PBXBuildFile section */
1DDD58160DA1D0A300B32029 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1DDD58140DA1D0A300B32029 /* MainMenu.xib */; };
256AC3DA0F4B6AC300CF3369 /* EDSidebarAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 256AC3D90F4B6AC300CF3369 /* EDSidebarAppDelegate.m */; };
256AC3DA0F4B6AC300CF3369 /* EDSidebarAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 256AC3D90F4B6AC300CF3369 /* EDSidebarAppDelegate.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); COMPILER_FLAGS = "-fno-objc-arc"; }; };
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
94B2BB8C14235019000FACDD /* EDSideBar.m in Sources */ = {isa = PBXBuildFile; fileRef = 94B2BB8B14235019000FACDD /* EDSideBar.m */; };
94B2BE9F1423BD86000FACDD /* icon1-white.png in Resources */ = {isa = PBXBuildFile; fileRef = 94B2BE9D1423BD86000FACDD /* icon1-white.png */; };
94B2BEA01423BD86000FACDD /* icon1-gray.png in Resources */ = {isa = PBXBuildFile; fileRef = 94B2BE9E1423BD86000FACDD /* icon1-gray.png */; };
94B2BF231423C272000FACDD /* BlackCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 94B2BF221423C272000FACDD /* BlackCell.m */; };
94B2BF371423C4BB000FACDD /* blue.png in Resources */ = {isa = PBXBuildFile; fileRef = 94B2BF361423C4BB000FACDD /* blue.png */; };
94B2BF431423C574000FACDD /* icon1-blue.png in Resources */ = {isa = PBXBuildFile; fileRef = 94B2BF421423C574000FACDD /* icon1-blue.png */; };
94E699161467F4BD00AFBE8A /* EDSideBar.m in Sources */ = {isa = PBXBuildFile; fileRef = 94E699151467F4BD00AFBE8A /* EDSideBar.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -33,14 +33,14 @@
29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
8D1107310486CEB800E47090 /* EDSidebar-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "EDSidebar-Info.plist"; sourceTree = "<group>"; };
8D1107320486CEB800E47090 /* EDSidebar.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = EDSidebar.app; sourceTree = BUILT_PRODUCTS_DIR; };
94B2BB8A14235019000FACDD /* EDSideBar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EDSideBar.h; sourceTree = "<group>"; };
94B2BB8B14235019000FACDD /* EDSideBar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EDSideBar.m; sourceTree = "<group>"; };
94B2BE9D1423BD86000FACDD /* icon1-white.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon1-white.png"; sourceTree = "<group>"; };
94B2BE9E1423BD86000FACDD /* icon1-gray.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon1-gray.png"; sourceTree = "<group>"; };
94B2BF211423C272000FACDD /* BlackCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BlackCell.h; sourceTree = "<group>"; };
94B2BF221423C272000FACDD /* BlackCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BlackCell.m; sourceTree = "<group>"; };
94B2BF361423C4BB000FACDD /* blue.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = blue.png; sourceTree = "<group>"; };
94B2BF421423C574000FACDD /* icon1-blue.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon1-blue.png"; sourceTree = "<group>"; };
94E699141467F4BD00AFBE8A /* EDSideBar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EDSideBar.h; sourceTree = "<group>"; };
94E699151467F4BD00AFBE8A /* EDSideBar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EDSideBar.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -95,7 +95,7 @@
29B97314FDCFA39411CA2CEA /* EDSidebar */ = {
isa = PBXGroup;
children = (
94B2BB891423500E000FACDD /* Sidebar */,
94E699131467F4BD00AFBE8A /* EDSideBar */,
080E96DDFE201D6D7F000001 /* Classes */,
29B97315FDCFA39411CA2CEA /* Other Sources */,
29B97317FDCFA39411CA2CEA /* Resources */,
Expand Down Expand Up @@ -137,13 +137,13 @@
name = Frameworks;
sourceTree = "<group>";
};
94B2BB891423500E000FACDD /* Sidebar */ = {
94E699131467F4BD00AFBE8A /* EDSideBar */ = {
isa = PBXGroup;
children = (
94B2BB8A14235019000FACDD /* EDSideBar.h */,
94B2BB8B14235019000FACDD /* EDSideBar.m */,
94E699141467F4BD00AFBE8A /* EDSideBar.h */,
94E699151467F4BD00AFBE8A /* EDSideBar.m */,
);
name = Sidebar;
path = EDSideBar;
sourceTree = "<group>";
};
/* End PBXGroup section */
Expand Down Expand Up @@ -214,8 +214,8 @@
files = (
8D11072D0486CEB800E47090 /* main.m in Sources */,
256AC3DA0F4B6AC300CF3369 /* EDSidebarAppDelegate.m in Sources */,
94B2BB8C14235019000FACDD /* EDSideBar.m in Sources */,
94B2BF231423C272000FACDD /* BlackCell.m in Sources */,
94E699161467F4BD00AFBE8A /* EDSideBar.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -245,15 +245,18 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = EDSidebar_Prefix.pch;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INFOPLIST_FILE = "EDSidebar-Info.plist";
INSTALL_PATH = "$(HOME)/Applications";
MACOSX_DEPLOYMENT_TARGET = 10.6;
PRODUCT_NAME = EDSidebar;
};
name = Debug;
Expand All @@ -262,12 +265,15 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ENABLE_OBJC_ARC = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = EDSidebar_Prefix.pch;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INFOPLIST_FILE = "EDSidebar-Info.plist";
INSTALL_PATH = "$(HOME)/Applications";
MACOSX_DEPLOYMENT_TARGET = 10.6;
PRODUCT_NAME = EDSidebar;
};
name = Release;
Expand All @@ -282,7 +288,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
ONLY_ACTIVE_ARCH = YES;
PREBINDING = NO;
SDKROOT = macosx10.6;
SDKROOT = macosx;
};
name = Debug;
};
Expand All @@ -294,7 +300,7 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
SDKROOT = macosx10.6;
SDKROOT = macosx;
};
name = Release;
};
Expand Down
4 changes: 2 additions & 2 deletions EDSidebarAppDelegate.m
Expand Up @@ -69,9 +69,9 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
}
-(void)sideBar:(EDSideBar*)tabBar didSelectButton:(NSInteger)button
{
NSString *str = [NSString stringWithFormat:@"Selected button #%d in %@",
NSString *str = [NSString stringWithFormat:@"Selected button #%lu in %@",
button, [tabBar isEqualTo:sideBarBlack]?@"Right sidebar":@"Left sidebar"];
NSLog(@"Button selected: %d", button );
NSLog(@"Button selected: %lu", button );
[textField setStringValue:str];

}
Expand Down

0 comments on commit ae4a7e3

Please sign in to comment.