Skip to content

Commit

Permalink
fixed alloc, dealloc. Now supporting arc enable/disable
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvise Susmel committed Feb 25, 2013
1 parent f661694 commit ac2e13e
Show file tree
Hide file tree
Showing 53 changed files with 4,235 additions and 29 deletions.
62 changes: 62 additions & 0 deletions ARCMacros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// ARCMacros.h
//
// Created by John Blanco on 1/28/2011.
// Rapture In Venice releases all rights to this code. Feel free use and/or copy it openly and freely!
//

#define FP_DEBUG

#if !defined(__clang__) || __clang_major__ < 3
#ifndef __bridge
#define __bridge
#endif

#ifndef __bridge_retain
#define __bridge_retain
#endif

#ifndef __bridge_retained
#define __bridge_retained
#endif

#ifndef __autoreleasing
#define __autoreleasing
#endif

#ifndef __strong
#define __strong
#endif

#ifndef __unsafe_unretained
#define __unsafe_unretained
#endif

#ifndef __weak
#define __weak
#endif
#endif

#if __has_feature(objc_arc)
#define SAFE_ARC_PROP_RETAIN strong
#define SAFE_ARC_RETAIN(x) (x)
#define SAFE_ARC_RELEASE(x)
#define SAFE_ARC_AUTORELEASE(x) (x)
#define SAFE_ARC_BLOCK_COPY(x) (x)
#define SAFE_ARC_BLOCK_RELEASE(x)
#define SAFE_ARC_SUPER_DEALLOC()
#define SAFE_ARC_AUTORELEASE_POOL_START() @autoreleasepool {
#define SAFE_ARC_AUTORELEASE_POOL_END() }
#else
#define SAFE_ARC_PROP_RETAIN retain
#define SAFE_ARC_RETAIN(x) ([(x) retain])
#define SAFE_ARC_RELEASE(x) ([(x) release])
#define SAFE_ARC_AUTORELEASE(x) ([(x) autorelease])
#define SAFE_ARC_BLOCK_COPY(x) (Block_copy(x))
#define SAFE_ARC_BLOCK_RELEASE(x) (Block_release(x))
#define SAFE_ARC_SUPER_DEALLOC() ([super dealloc])
#define SAFE_ARC_AUTORELEASE_POOL_START() NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
#define SAFE_ARC_AUTORELEASE_POOL_END() [pool release];
#endif


24 changes: 11 additions & 13 deletions FPPopoverController.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>

#import "ARCMacros.h"

#import "FPPopoverView.h"
#import "FPTouchView.h"


@class FPPopoverController;
@protocol FPPopoverControllerDelegate <NSObject>

Expand All @@ -22,19 +25,14 @@
@end

@interface FPPopoverController : UIViewController
{
FPTouchView *_touchView;
FPPopoverView *_contentView;
UIViewController *_viewController;
UIWindow *_window;
UIView *_parentView;
UIView *_fromView;
UIDeviceOrientation _deviceOrientation;

BOOL _shadowsHidden;
CGColorRef _shadowColor;
}
@property(nonatomic,weak) id<FPPopoverControllerDelegate> delegate;

//ARC-enable and disable support
#if __has_feature(objc_arc)
@property(nonatomic,weak) id<FPPopoverControllerDelegate> delegate;
#else
@property(nonatomic,assign) id<FPPopoverControllerDelegate> delegate;
#endif

/** @brief FPPopoverArrowDirectionAny, FPPopoverArrowDirectionVertical or FPPopoverArrowDirectionHorizontal for automatic arrow direction.
**/

Expand Down
32 changes: 31 additions & 1 deletion FPPopoverController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@

#import "FPPopoverController.h"

//ivars
@interface FPPopoverController()
{
FPTouchView *_touchView;
FPPopoverView *_contentView;
UIViewController *_viewController;
UIWindow *_window;
UIView *_parentView;
UIView *_fromView;
UIDeviceOrientation _deviceOrientation;

BOOL _shadowsHidden;
CGColorRef _shadowColor;
}
@end


//private methods
@interface FPPopoverController(Private)
-(CGPoint)originFromView:(UIView*)fromView;

Expand Down Expand Up @@ -66,6 +84,17 @@ -(void)dealloc
{
[self removeObservers];
if(_shadowColor) CGColorRelease(_shadowColor);

#ifdef FP_DEBUG
NSLog(@"FPPopoverController dealloc");
#endif

SAFE_ARC_RELEASE(_contentView);
SAFE_ARC_RELEASE(_touchView);
self.delegate = nil;
_viewController = nil;

SAFE_ARC_SUPER_DEALLOC();
}

-(id)initWithViewController:(UIViewController*)viewController {
Expand All @@ -89,7 +118,8 @@ -(id)initWithViewController:(UIViewController*)viewController
_touchView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_touchView.clipsToBounds = NO;
[self.view addSubview:_touchView];



__block typeof (self) bself = self;
[_touchView setTouchedOutsideBlock:^{
[bself dismissPopoverAnimated:YES];
Expand Down
Loading

0 comments on commit ac2e13e

Please sign in to comment.