mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-12-06 12:45:32 +00:00
full support for CPPopover and nib2cib + enchanced delegates
This commit is contained in:
1 parent
3d5b30ab9e
commit
0246d501e2
4 files changed
+135
-12
No files matched your search
+71
-6
@@ -36,6 +36,13 @@ CPPopoverBehaviorTransient = 1;
|
||||
CPPopoverBehaviorSemitransient = 2;
|
||||
|
||||
|
||||
var CPPopoverDelegate_popover_willShow_ = 1 << 0,
|
||||
CPPopoverDelegate_popover_didShow_ = 1 << 1,
|
||||
CPPopoverDelegate_popover_shouldClose_ = 1 << 2,
|
||||
CPPopoverDelegate_popover_willClose_ = 1 << 3,
|
||||
CPPopoverDelegate_popover_didClose_ = 1 << 4;
|
||||
|
||||
|
||||
/*! @ingroup appkit
|
||||
@class CPPopover
|
||||
|
||||
@@ -52,7 +59,7 @@ CPPopoverBehaviorSemitransient = 2;
|
||||
@implementation CPPopover : CPResponder
|
||||
{
|
||||
@outlet CPViewController _contentViewController @accessors(property=contentViewController);
|
||||
@outlet id _delegate @accessors(property=delegate);
|
||||
@outlet id _delegate @accessors(getter=delegate);
|
||||
|
||||
BOOL _animates @accessors(property=animates);
|
||||
BOOL _shown @accessors(getter=shown);
|
||||
@@ -61,6 +68,7 @@ CPPopoverBehaviorSemitransient = 2;
|
||||
|
||||
BOOL _needsCompute;
|
||||
_CPAttachedWindow _attachedWindow;
|
||||
int _implementedDelegateMethods;
|
||||
}
|
||||
|
||||
|
||||
@@ -163,6 +171,30 @@ CPPopoverBehaviorSemitransient = 2;
|
||||
}
|
||||
|
||||
|
||||
- (void)setDelegate:(id)aDelegate
|
||||
{
|
||||
if (_delegate === aDelegate)
|
||||
return;
|
||||
|
||||
_delegate = aDelegate;
|
||||
_implementedDelegateMethods = 0;
|
||||
|
||||
if ([_delegate respondsToSelector:@selector(popoverWillShow:)])
|
||||
_implementedDelegateMethods |= CPPopoverDelegate_popover_willShow_;
|
||||
|
||||
if ([_delegate respondsToSelector:@selector(popoverDidShow:)])
|
||||
_implementedDelegateMethods |= CPPopoverDelegate_popover_didShow_;
|
||||
|
||||
if ([_delegate respondsToSelector:@selector(popoverShouldClose:)])
|
||||
_implementedDelegateMethods |= CPPopoverDelegate_popover_shouldClose_;
|
||||
|
||||
if ([_delegate respondsToSelector:@selector(popoverWillClose:)])
|
||||
_implementedDelegateMethods |= CPPopoverDelegate_popover_willClose_;
|
||||
|
||||
if ([_delegate respondsToSelector:@selector(popoverDidClose:)])
|
||||
_implementedDelegateMethods |= CPPopoverDelegate_popover_didClose_;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Positionning
|
||||
|
||||
@@ -175,7 +207,7 @@ CPPopoverBehaviorSemitransient = 2;
|
||||
*/
|
||||
- (void)showRelativeToRect:(CPRect)positioningRect ofView:(CPView)positioningView preferredEdge:(CPRectEdge)preferredEdge
|
||||
{
|
||||
if (_delegate && [_delegate respondsToSelector:@selector(popoverWillShow:)])
|
||||
if (_implementedDelegateMethods & CPPopoverDelegate_popover_willShow_)
|
||||
[_delegate popoverWillShow:self];
|
||||
|
||||
if (!_contentViewController)
|
||||
@@ -200,7 +232,7 @@ CPPopoverBehaviorSemitransient = 2;
|
||||
else
|
||||
[CPException raise:CPInvalidArgumentException reason:@"you must set positioningRect or positioningRect"];
|
||||
|
||||
if (_delegate && [_delegate respondsToSelector:@selector(popoverDidShow:)])
|
||||
if (_implementedDelegateMethods & CPPopoverDelegate_popover_didShow_)
|
||||
[_delegate popoverDidShow:self];
|
||||
}
|
||||
|
||||
@@ -209,16 +241,16 @@ CPPopoverBehaviorSemitransient = 2;
|
||||
*/
|
||||
- (void)close
|
||||
{
|
||||
if (_delegate && [_delegate respondsToSelector:@selector(popoverShouldClose:)]);
|
||||
if (_implementedDelegateMethods & CPPopoverDelegate_popover_shouldClose_)
|
||||
if (![_delegate popoverShouldClose:self])
|
||||
return;
|
||||
|
||||
if (_delegate && [_delegate respondsToSelector:@selector(popoverWillClose:)])
|
||||
if (_implementedDelegateMethods & CPPopoverDelegate_popover_willClose_)
|
||||
[_delegate popoverWillClose:self];
|
||||
|
||||
[_attachedWindow close];
|
||||
|
||||
if (_delegate && [_delegate respondsToSelector:@selector(popoverDidClose:)])
|
||||
if (_implementedDelegateMethods & CPPopoverDelegate_popover_didClose_)
|
||||
[_delegate popoverDidClose:self];
|
||||
}
|
||||
|
||||
@@ -236,4 +268,37 @@ CPPopoverBehaviorSemitransient = 2;
|
||||
[self close];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation CPPopover (CPCoding)
|
||||
|
||||
- (id)initWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
self = [super initWithCoder:aCoder];
|
||||
|
||||
if (self)
|
||||
{
|
||||
_needsCompute = [aCoder decodeIntForKey:@"_needsCompute"];
|
||||
_appearance = [aCoder decodeIntForKey:@"_appearance"];
|
||||
_animates = [aCoder decodeBoolForKey:@"_animates"];
|
||||
_contentViewController = [aCoder decodeObjectForKey:@"_contentViewController"];
|
||||
[self setDelegate:[aCoder decodeObjectForKey:@"_delegate"]];
|
||||
[self setBehaviour:[aCoder decodeIntForKey:@"_behavior"]];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)encodeWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
[super encodeWithCoder:aCoder];
|
||||
|
||||
[aCoder encodeInt:_behavior forKey:@"_behavior"];
|
||||
[aCoder encodeInt:_appearance forKey:@"_appearance"];
|
||||
[aCoder encodeBool:_needsCompute forKey:@"_needsCompute"];
|
||||
[aCoder encodeObject:_contentViewController forKey:@"_contentViewController"];
|
||||
[aCoder encodeObject:_delegate forKey:@"_delegate"];
|
||||
[aCoder encodeObject:_animates forKey:@"_animates"];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -133,12 +133,12 @@
|
||||
|
||||
if (_appearance == CPPopoverAppearanceMinimal)
|
||||
{
|
||||
_strokeColor = [CPColor colorWithCalibratedRed:(172.0 / 255) green:(172.0 / 255) blue:(172.0 / 255) alpha:1.0];
|
||||
_strokeColor = [CPColor colorWithCalibratedRed:(187.0 / 255) green:(187.0 / 255) blue:(187.0 / 255) alpha:0.7];
|
||||
_backgroundColor = [CPColor colorWithCalibratedRed:(241.0 / 255) green:(241.0 / 255) blue:(241.0 / 255) alpha:0.93];
|
||||
}
|
||||
else
|
||||
{
|
||||
_strokeColor = [CPColor colorWithCalibratedRed:(172.0 / 255) green:(172.0 / 255) blue:(172.0 / 255) alpha:1.0];
|
||||
_strokeColor = [CPColor colorWithCalibratedRed:(187.0 / 255) green:(187.0 / 255) blue:(187.0 / 255) alpha:0.7];
|
||||
_backgroundColor = [CPColor colorWithCalibratedRed:(50.0 / 255) green:(50.0 / 255) blue:(50.0 / 255) alpha:0.93];
|
||||
}
|
||||
|
||||
@@ -161,17 +161,16 @@
|
||||
if (_useGlowingEffect)
|
||||
{
|
||||
var shadowColor = [[CPColor blackColor] colorWithAlphaComponent:.2],
|
||||
shadowSize = CGSizeMake(0, 0),
|
||||
shadowSize = CGSizeMake(0, 7),
|
||||
shadowBlur = 15;
|
||||
|
||||
//compensate for the shadow blur
|
||||
aRect.origin.x += shadowBlur;
|
||||
aRect.origin.y += shadowBlur;
|
||||
aRect.origin.y += shadowBlur + shadowSize.height / 2;
|
||||
aRect.size.width -= shadowBlur * 2;
|
||||
aRect.size.height -= shadowBlur * 2;
|
||||
aRect.size.height -= shadowBlur * 2 + shadowSize.height;
|
||||
|
||||
//set the shadow
|
||||
CGContextSetShadow(context, CGSizeMake(0,0), 20);
|
||||
CGContextSetShadowWithColor(context, shadowSize, shadowBlur, shadowColor);
|
||||
}
|
||||
|
||||
|
||||
@@ -79,6 +79,7 @@
|
||||
@import "NSWindowTemplate.j"
|
||||
@import "WebView.j"
|
||||
@import "NSSortDescriptor.j"
|
||||
@import "NSPopover.j"
|
||||
|
||||
|
||||
function CP_NSMapClassName(aClassName)
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* NSPopover.j
|
||||
* nib2cib
|
||||
*
|
||||
* Created by Francisco Tolmasky.
|
||||
* Copyright 2008, 280 North, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
@import <AppKit/CPPopover.j>
|
||||
|
||||
|
||||
@implementation CPPopover (NSCoding)
|
||||
|
||||
- (id)NS_initWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
self = [super NS_initWithCoder:aCoder];
|
||||
|
||||
if (self)
|
||||
{
|
||||
_needsCompute = YES;
|
||||
_shown = NO;
|
||||
_behavior = [aCoder decodeIntForKey:@"NSBehavior"];
|
||||
_appearance = [aCoder decodeIntForKey:@"NSAppearance"];
|
||||
_animates = [aCoder decodeBoolForKey:@"NSAnimates"];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSPopover : CPPopover
|
||||
|
||||
- (id)initWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
return [self NS_initWithCoder:aCoder];
|
||||
}
|
||||
|
||||
- (Class)classForKeyedArchiver
|
||||
{
|
||||
return [CPPopover class];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user