62 _CPAttachedWindow _attachedWindow;
63 int _implementedDelegateMethods;
68 #pragma mark Initialization
77 if (
self = [super init])
80 _appearance = CPPopoverAppearanceMinimal;
89 #pragma mark Getters / Setters
96 - (CGRect)positioningRect
98 if (![_attachedWindow isVisible])
99 return CGRectMakeZero();
100 return [_attachedWindow frame];
106 - (void)setPositioningRect:(CGRect)aRect
108 if (![_attachedWindow isVisible])
110 [_attachedWindow setFrame:aRect];
118 - (CGSize)contentSize
120 if (![_attachedWindow isVisible])
121 return CGRectMakeZero();
122 return [[_contentViewController view] frameSize];
130 - (void)setContentSize:(CPSize)aSize
132 [[_contentViewController view] setFrameSize:aSize];
142 return [_attachedWindow isVisible];
153 - (void)setBehavior:(
int)aBehavior
155 if (_behavior == aBehavior)
158 _behavior = aBehavior;
162 - (void)setDelegate:(
id)aDelegate
164 if (_delegate === aDelegate)
167 _delegate = aDelegate;
168 _implementedDelegateMethods = 0;
170 if ([_delegate respondsToSelector:
@selector(popoverWillShow:)])
173 if ([_delegate respondsToSelector:
@selector(popoverDidShow:)])
176 if ([_delegate respondsToSelector:
@selector(popoverShouldClose:)])
179 if ([_delegate respondsToSelector:
@selector(popoverWillClose:)])
182 if ([_delegate respondsToSelector:
@selector(popoverDidClose:)])
187 #pragma mark Positioning
196 - (void)showRelativeToRect:(CGRect)positioningRect ofView:(
CPView)positioningView preferredEdge:(CPRectEdge)preferredEdge
198 if (!positioningView)
201 if (!_contentViewController)
205 if ([_attachedWindow isClosing])
209 [_delegate popoverWillShow:self];
211 if (!_attachedWindow)
213 _attachedWindow = [[_CPAttachedWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:[
self styleMaskForBehavior]];
215 var parentWindow = [positioningView
window];
217 if (![parentWindow isKindOfClass:_CPAttachedWindow])
221 [_attachedWindow setAppearance:_appearance];
222 [_attachedWindow setAnimates:_animates];
223 [_attachedWindow setDelegate:self];
224 [_attachedWindow setMovableByWindowBackground:NO];
225 [_attachedWindow setFrame:[_attachedWindow frameRectForContentRect:[[_contentViewController view] frame]]];
226 [_attachedWindow setContentView:[_contentViewController view]];
227 [_attachedWindow positionRelativeToRect:positioningRect ofView:positioningView preferredEdge:preferredEdge];
230 [_delegate popoverDidShow:self];
233 - (unsigned)styleMaskForBehavior
251 if ([_attachedWindow isClosing] || ![
self isShown])
255 [_delegate popoverWillClose:self];
257 [_attachedWindow close];
272 - (IBAction)performClose:(
id)sender
274 if ([_attachedWindow isClosing])
278 if (![_delegate popoverShouldClose:
self])
286 #pragma mark Delegates
289 - (BOOL)attachedWindowShouldClose:(_CPAttachedWindow)anAttachedWindow
300 - (void)attachedWindowDidClose:(_CPAttachedWindow)anAttachedWindow
303 [_delegate popoverDidClose:self];
307 - (void)attachedWindowDidShow:(_CPAttachedWindow)anAttachedWindow
310 [_delegate popoverDidShow:self];
315 #pragma mark Notifications
325 [_attachedWindow orderOut:nil];
333 - (void)setBehaviour:(
int)aBehavior
335 _CPReportLenientDeprecation(
self, _cmd,
@selector(setBehavior:));
357 _appearance = [aCoder decodeIntForKey:CPPopoverAppearanceKey];
358 _animates = [aCoder decodeBoolForKey:CPPopoverAnimatesKey];
359 _contentViewController = [aCoder decodeObjectForKey:CPPopoverContentViewControllerKey];
360 [
self setDelegate:[aCoder decodeObjectForKey:CPPopoverDelegateKey]];
361 [
self setBehavior:[aCoder decodeIntForKey:CPPopoverBehaviorKey]];
370 [aCoder encodeInt:_appearance forKey:CPPopoverAppearanceKey];
371 [aCoder encodeBool:_animates forKey:CPPopoverAnimatesKey];
372 [aCoder encodeObject:_contentViewController forKey:CPPopoverContentViewControllerKey];
373 [aCoder encodeObject:_delegate forKey:CPPopoverDelegateKey];
374 [aCoder encodeInt:_behavior forKey:CPPopoverBehaviorKey];
386 return _contentViewController;
394 _contentViewController = aValue;
416 - (void)setAnimates:(BOOL)aValue
432 - (void)setAppearance:(
int)aValue
434 _appearance = aValue;