From 975e11abfc29f675b1cb7e9b41e1f1645b70394d Mon Sep 17 00:00:00 2001 From: Saikat Chakrabarti Date: Fri, 4 Feb 2011 17:41:40 -0800 Subject: [PATCH] CPCursor refactor according to discussion in http://groups.google.com/group/objectivej-dev/browse_thread/thread/eabe59dc7d71122b/ddc6f1b61e5f3c2a?lnk=gst&q=cpcursor#ddc6f1b61e5f3c2a and new test for CPCursor that is easier to go through. --- AppKit/CPCursor.j | 377 ++++++++---------- .../Resources/CPCursor/closedHandCursor.cur | Bin 2238 -> 326 bytes AppKit/Resources/CPCursor/openHandCursor.cur | Bin 4286 -> 326 bytes .../Resources/CPCursor/resizeDownCursor.cur | Bin 4286 -> 0 bytes .../Resources/CPCursor/resizeLeftCursor.cur | Bin 4286 -> 0 bytes .../Resources/CPCursor/resizeRightCursor.cur | Bin 4286 -> 0 bytes AppKit/Resources/CPCursor/resizeUpCursor.cur | Bin 4286 -> 0 bytes Tests/Manual/CPCursor/AppController.j | 164 +++++--- Tests/Manual/CPCursor/test.html | 18 - 9 files changed, 287 insertions(+), 272 deletions(-) delete mode 100644 AppKit/Resources/CPCursor/resizeDownCursor.cur delete mode 100644 AppKit/Resources/CPCursor/resizeLeftCursor.cur delete mode 100644 AppKit/Resources/CPCursor/resizeRightCursor.cur delete mode 100644 AppKit/Resources/CPCursor/resizeUpCursor.cur delete mode 100644 Tests/Manual/CPCursor/test.html diff --git a/AppKit/CPCursor.j b/AppKit/CPCursor.j index a8b09e218..968b146a5 100755 --- a/AppKit/CPCursor.j +++ b/AppKit/CPCursor.j @@ -1,36 +1,41 @@ /* -Testing browsers: - WebKit r50235 (Safari 4.0.3+) - FireFox 3.5 - Opera 10.0.0 - -Implemented class methods: - Webkit : All - IE : All - FireFox Win : All - FireFox Mac : All except closedHandCursor disappearingItemCursor // Firefox mac does not support url cursors - Opera : All except resizeLeftRightCursor resizeUpDownCursor operationNotAllowedCursor dragCopyCursor dragLinkCursor contextualMenuCursor openHandCursor closedHandCursor disappearingItemCursor // Opera does not support url cursors so these won't work with images +Cursor support by browser: + OS X 10.6/Chrome 8 : All + OS X 10.6/Safari 5 : All + OS X 10.6/Firefox 3 : All except disappearingItemCursor (no url() support) + OS X 10.6/Firefox 3.5 : All except disappearingItemCursor (no url() support) + OS X 10.6/Firefox 3.6 : All except disappearingItemCursor, contextualMenuCursor, dragLinkCursor, dragCopyCursor, operationNotAllowedCursor (no url() support) + OS X 10.6/Firefox 4.0b10 : All + OS X/Opera 9 : All except disappearingItemCursor, closedHandCursor, openHandCursor, contextualMenuCursor, dragLinkCursor, dragCopyCursor, operationNotAllowedCursor, resizeUpDownCursor, resizeLeftRightCursor (no url() support) + OS X/Opera 10 : All except disappearingItemCursor, closedHandCursor, contextualMenuCursor, dragLinkCursor, dragCopyCursor, operationNotAllowedCursor (no url() support) + OS X/Opera 11 : All except disappearingItemCursor, closedHandCursor, contextualMenuCursor, dragLinkCursor, dragCopyCursor, operationNotAllowedCursor (no url() support) + Win XP/Chrome 8 : All + Win XP/Safari 5 : All + Win XP/Firefox 3 : All + Win XP/Firefox 3.5 : All + Win XP/Firefox 3.6 : All + Win XP/Firefox 4.0b10 : All + Win XP/Opera 10 : All except disappearingItemCursor, closedHandCursor, openHandCursor, contextualMenuCursor, dragLinkCursor, dragCopyCursor, operationNotAllowedCursor, resizeUpDownCursor, resizeLeftRightCursor (no url() support) + Win XP/Opera 11 : All except disappearingItemCursor, closedHandCursor, openHandCursor, contextualMenuCursor, dragLinkCursor, dragCopyCursor, operationNotAllowedCursor, resizeUpDownCursor, resizeLeftRightCursor (no url() support) + Win XP/IE 7 : All + Win XP/IE 8 : All */ @import var currentCursor = nil, cursorStack = [], - cursors = {}, - cursorURLFormat = nil; + cursors = {}; @implementation CPCursor : CPObject { - CPString _cssString; + CPString _cssString @accessors(readonly); + CPString _hotSpot @accessors(readonly, getter=hotSpot); + CPImage _image @accessors(readonly, getter=image); BOOL _isSetOnMouseEntered @accessors(readwrite, getter=isSetOnMouseEntered, setter=setOnMouseEntered:); BOOL _isSetOnMouseExited @accessors(readwrite, getter=isSetOnMouseExited, setter=setOnMouseExited:); } -+ (CPCursor)currentCursor -{ - return currentCursor; -} - - (id)initWithCSSString:(CPString)aString { if (self = [super init]) @@ -39,155 +44,18 @@ var currentCursor = nil, return self; } -+ (CPCursor)cursorWithCSSString:(CPString)cssString +// hotspot is supported in CSS3 (but not IE). +- (id)initWithImage:(CPImage)image hotSpot:(CPPoint)hotSpot { - var cursor = cursors[cssString]; - - if (typeof cursor == 'undefined') - { - cursor = [[CPCursor alloc] initWithCSSString:cssString]; - cursors[cssString] = cursor; - } - - return cursor; + _hotSpot = hotSpot; + _image = image; + return [self initWithCSSString:"url(" + [_image filename] + ")" + hotSpot.x + " " + hotSpot.y + ", auto"]; } -+ (CPCursor)cursorWithImageNamed:(CPString)imageName +// foregroundColor and backgroundColor are ignored in Cocoa as well. See http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSCursor_Class/Reference/Reference.html +– (id)initWithImage:(CPImage)image foregroundColorHint:(CPColor)foregroundColor backgroundColorHint:(CPColor)backgroundColor hotSpot:(CPPoint)aHotSpot { - if (!cursorURLFormat) - { - cursorURLFormat = @"url(" + [[CPBundle bundleForClass:self] resourcePath] + @"/CPCursor/%@.cur)"; - - if (CPBrowserIsEngine(CPGeckoBrowserEngine)) - cursorURLFormat += ", default"; - } - - var url = [CPString stringWithFormat:cursorURLFormat, imageName]; - - return [[CPCursor alloc] initWithCSSString:url]; -} - -- (CPString)_cssString -{ - return _cssString; -} - -+ (CPCursor)arrowCursor -{ - return [CPCursor cursorWithCSSString:@"default"]; // WebKit | FF | opera | IE -} - -+ (CPCursor)crosshairCursor -{ - return [CPCursor cursorWithCSSString:@"crosshair"]; // WebKit | FF | opera | IE -} - -+ (CPCursor)IBeamCursor -{ - return [CPCursor cursorWithCSSString:@"text"]; // WebKit | FF | opera | IE -} - -+ (CPCursor)pointingHandCursor -{ - return [CPCursor cursorWithCSSString:@"pointer"]; // WebKit | FF | opera | IE -} - -+ (CPCursor)resizeDownCursor -{ - if (CPBrowserIsEngine(CPInternetExplorerBrowserEngine)) - return [CPCursor cursorWithImageNamed:CPStringFromSelector(_cmd)]; - - return [CPCursor cursorWithCSSString:"s-resize"]; // WebKit | FF | opera -} - -+ (CPCursor)resizeUpCursor -{ - if (CPBrowserIsEngine(CPInternetExplorerBrowserEngine)) - return [CPCursor cursorWithImageNamed:CPStringFromSelector(_cmd)]; - - return [CPCursor cursorWithCSSString:@"n-resize"]; // WebKit | FF | opera -} - -+ (CPCursor)resizeLeftCursor -{ - if (CPBrowserIsEngine(CPInternetExplorerBrowserEngine)) - return [CPCursor cursorWithImageNamed:CPStringFromSelector(_cmd)]; - - return [CPCursor cursorWithCSSString:@"w-resize"]; // WebKit | FF | opera -} - -+ (CPCursor)resizeRightCursor -{ - if (CPBrowserIsEngine(CPInternetExplorerBrowserEngine)) - return [CPCursor cursorWithImageNamed:CPStringFromSelector(_cmd)]; - - return [CPCursor cursorWithCSSString:@"e-resize"]; // WebKit | FF | opera -} - -+ (CPCursor)resizeLeftRightCursor -{ - return [CPCursor cursorWithCSSString:@"col-resize"]; // WebKit | FF | IE -} - -+ (CPCursor)resizeUpDownCursor -{ - return [CPCursor cursorWithCSSString:@"row-resize"]; // WebKit | FF | IE -} - -+ (CPCursor)operationNotAllowedCursor -{ - return [CPCursor cursorWithCSSString:@"not-allowed"]; // WebKit | FF | IE -} - -+ (CPCursor)dragCopyCursor -{ - if (CPBrowserIsEngine(CPInternetExplorerBrowserEngine)) - return [CPCursor cursorWithImageNamed:CPStringFromSelector(_cmd)]; - - return [CPCursor cursorWithCSSString:@"copy"]; // WebKit | FF -} - -+ (CPCursor)dragLinkCursor -{ - if (CPBrowserIsEngine(CPInternetExplorerBrowserEngine)) - return [CPCursor cursorWithImageNamed:CPStringFromSelector(_cmd)]; - - return [CPCursor cursorWithCSSString:@"alias"]; // WebKit | FF -} - -+ (CPCursor)contextualMenuCursor -{ - if (CPBrowserIsEngine(CPInternetExplorerBrowserEngine)) - return [CPCursor cursorWithImageNamed:CPStringFromSelector(_cmd)]; - - return [CPCursor cursorWithCSSString:@"context-menu"]; // WebKit | FF Mac . Not impl FF Win. -} - -+ (CPCursor)openHandCursor -{ - if (CPBrowserIsEngine(CPWebKitBrowserEngine)) - return [CPCursor cursorWithCSSString:@"-webkit-grab"]; - else if (CPBrowserIsEngine(CPGeckoBrowserEngine)) - return [CPCursor cursorWithCSSString:@"-moz-grab"]; - else if (CPBrowserIsEngine(CPOperaBrowserEngine)) - return [CPCursor cursorWithCSSString:@"move"]; - - return [CPCursor cursorWithImageNamed:CPStringFromSelector(_cmd)]; // WebKit only. move in FFMac|Opera -} - -+ (CPCursor)closedHandCursor -{ - if (CPBrowserIsEngine(CPWebKitBrowserEngine)) - return [CPCursor cursorWithCSSString:@"-webkit-grabbing"]; - else if (CPBrowserIsEngine(CPGeckoBrowserEngine)) - return [CPCursor cursorWithCSSString:@"-moz-grabbing"]; - - return [CPCursor cursorWithImageNamed:CPStringFromSelector(_cmd)]; // WebKit || FF -} - -+ (CPCursor)disappearingItemCursor -{ - return [CPCursor cursorWithImageNamed:CPStringFromSelector(_cmd)]; // None + return [self initWithImage:image hotSpot:hotSpot]; } + (void)hide @@ -208,44 +76,6 @@ var currentCursor = nil, [CPCursor unhide]; } -- (id)initWithImage:(CPImage)image hotSpot:(CPPoint)hotSpot -{ - return [self initWithCSSString:"url(" + [image filename] + "), auto"]; -} - - -- (void)mouseEntered:(CPEvent)event -{ -} - -- (void)mouseExited:(CPEvent)event -{ -} - -- (void)set -{ - currentCursor = self; - -#if PLATFORM(DOM) - [[self class] _setCursorCSS:_cssString]; -#endif - -} - -+ (void)_setCursorCSS:(CPString)aString -{ -#if PLATFORM(DOM) - var platformWindows = [[CPPlatformWindow visiblePlatformWindows] allObjects]; - for (var i = 0, count = [platformWindows count]; i < count; i++) - platformWindows[i]._DOMBodyElement.style.cursor = aString; -#endif -} - -- (void)push -{ - currentCursor = cursorStack.push(self); -} - - (void)pop { [CPCursor pop]; @@ -260,6 +90,148 @@ var currentCursor = nil, } } +- (void)push +{ + currentCursor = cursorStack.push(self); +} + +- (void)set +{ + currentCursor = self; + +#if PLATFORM(DOM) + [[self class] _setCursorCSS:_cssString]; +#endif +} + +- (void)mouseEntered:(CPEvent)event +{ +} + +- (void)mouseExited:(CPEvent)event +{ +} + ++ (CPCursor)currentCursor +{ + return currentCursor; +} + ++ (void)_setCursorCSS:(CPString)aString +{ +#if PLATFORM(DOM) + var platformWindows = [[CPPlatformWindow visiblePlatformWindows] allObjects]; + for (var i = 0, count = [platformWindows count]; i < count; i++) + platformWindows[i]._DOMBodyElement.style.cursor = aString; +#endif +} + +// Internal method that is used to return the system cursors. Caches the system cursors for performance. ++ (CPCursor)_systemCursorWithName:(CPString)cursorName cssString:(CPString)aString hasImage:(BOOL)doesHaveImage +{ + var cursor = cursors[cursorName]; + if (typeof cursor === 'undefined') + { + var cssString; + if (doesHaveImage) + cssString = @"url(" + [[CPBundle bundleForClass:self] resourcePath] + @"/CPCursor/" + cursorName + ".cur), " + aString; + else + cssString = aString + cursor = [[CPCursor alloc] initWithCSSString:cssString]; + cursors[cursorName] = cursor; + } + return cursor; +} + ++ (CPCursor)arrowCursor +{ + return [CPCursor _systemCursorWithName:CPStringFromSelector(_cmd) cssString:"default" hasImage:NO]; +} + ++ (CPCursor)crosshairCursor +{ + return [CPCursor _systemCursorWithName:CPStringFromSelector(_cmd) cssString:@"crosshair" hasImage:NO]; +} + ++ (CPCursor)IBeamCursor +{ + return [CPCursor _systemCursorWithName:CPStringFromSelector(_cmd) cssString:@"text" hasImage:NO]; +} + ++ (CPCursor)pointingHandCursor +{ + return [CPCursor _systemCursorWithName:CPStringFromSelector(_cmd) cssString:@"pointer" hasImage:NO]; +} + ++ (CPCursor)resizeDownCursor +{ + return [CPCursor _systemCursorWithName:CPStringFromSelector(_cmd) cssString:@"s-resize" hasImage:NO]; +} + ++ (CPCursor)resizeUpCursor +{ + return [CPCursor _systemCursorWithName:CPStringFromSelector(_cmd) cssString:@"n-resize" hasImage:NO]; +} + ++ (CPCursor)resizeLeftCursor +{ + return [CPCursor _systemCursorWithName:CPStringFromSelector(_cmd) cssString:@"w-resize" hasImage:NO]; +} + ++ (CPCursor)resizeRightCursor +{ + return [CPCursor _systemCursorWithName:CPStringFromSelector(_cmd) cssString:@"e-resize" hasImage:NO]; +} + ++ (CPCursor)resizeLeftRightCursor +{ + return [CPCursor _systemCursorWithName:CPStringFromSelector(_cmd) cssString:@"col-resize" hasImage:NO]; +} + ++ (CPCursor)resizeUpDownCursor +{ + return [CPCursor _systemCursorWithName:CPStringFromSelector(_cmd) cssString:@"row-resize" hasImage:NO]; +} + ++ (CPCursor)operationNotAllowedCursor +{ + return [CPCursor _systemCursorWithName:CPStringFromSelector(_cmd) cssString:@"not-allowed" hasImage:NO]; +} + ++ (CPCursor)dragCopyCursor +{ + return [CPCursor _systemCursorWithName:CPStringFromSelector(_cmd) cssString:@"copy" hasImage:YES]; +} + ++ (CPCursor)dragLinkCursor +{ + return [CPCursor _systemCursorWithName:CPStringFromSelector(_cmd) cssString:@"alias" hasImage:YES]; +} + ++ (CPCursor)contextualMenuCursor +{ + return [CPCursor _systemCursorWithName:CPStringFromSelector(_cmd) cssString:@"context-menu" hasImage:YES]; +} + ++ (CPCursor)openHandCursor +{ + return [CPCursor _systemCursorWithName:CPStringFromSelector(_cmd) cssString:@"move" hasImage:YES]; +} + ++ (CPCursor)closedHandCursor +{ + return [CPCursor _systemCursorWithName:CPStringFromSelector(_cmd) cssString:@"-moz-grabbing" hasImage:YES]; +} + ++ (CPCursor)disappearingItemCursor +{ + return [CPCursor _systemCursorWithName:CPStringFromSelector(_cmd) cssString:@"auto" hasImage:YES]; +} + +@end + +@implementation CPCursor(CPCoding) + - (id)initWithCoder:(CPCoder)coder { if (self = [super init]) @@ -274,4 +246,3 @@ var currentCursor = nil, } @end - diff --git a/AppKit/Resources/CPCursor/closedHandCursor.cur b/AppKit/Resources/CPCursor/closedHandCursor.cur index eb9548bc505dda01d1162ad2e3ac7509be4cd3a6..41aaa62a596f9e973f333e084e004da35bfdd9bf 100644 GIT binary patch literal 326 zcmbu(y$ypf5QgE`Mv<$CE-fxoW&}3Ks*J!W8Nosn6iAovz(opZ!dZ{+r#KrTft(|W z8?OKl;3-*p2|8QU69A^^lN|pnm=OG-%KONl8hhq@<9RmZo9DhBRu_h{lZ@BO@b2 zlO|1&m6fGw)27JD$ssQ zR;_5=x;1KQYQnwMY15_+ZQHh`UAuN@XlS6Rsfm`B7TVg{=;-LszI}T-bm&0GjveXL zsS}+$ccx31F6ip&qNk^azP>(PyLQFEzyL!-L%MbAM)&UB>CvMHMn*;$8yjO{VnWZJ zJ?Yh}7rlG;rca+fn3|emW@d)Dxj7aV7WD1gmwx^F(Z7Fx1`HU$z<~o9G-wcm2M=b* zkRe!FT4H5og|)RcHa0d49Xb?STU&+=8-|^o9m9tY$KKwa5hF%0a^y%xjT*)1(W4nN zW(;G;j%D1qaf}~7o(U5s;NakZqoX5EPEJgmIFU({CNX*PWSpIynKESxE-o%iojMg) zS6AHJ+;DeyXWF!BOrJiT88c=ubLLDuJUsC9^kmkoS$KJQ;qC2>kB<+tXV1ph*OxhS z<}i2eT;|Q2$Nc&8@$>Uz!GZ-WT)2=$ix%PU?@vHL0E-tdCNMCNpr9a@ELp({Sm!-frP z+_;fVn>G<19!^9=1d)-EL`6jr9UV#Fr1xQ-2e@?TH*9jE4*)mk0t z{Tu&!{~yb#lM7R7+P|_NhyO=Gv6@I!qYOa-vcj!uBw4Ef!Dk4n@ii>lR3!Qa?4L{S diff --git a/AppKit/Resources/CPCursor/openHandCursor.cur b/AppKit/Resources/CPCursor/openHandCursor.cur index f589121bedff1afade43bb423be3eff3d7bf4c25..fba3ddc807fd2e29b41d09af0b14d6db6bdb879c 100644 GIT binary patch literal 326 zcmbu(u?@m75QX92i6U1h9TF8ODcJzFVFXGt0;3=b>Wq?t0aBq9D39kj1vQ-Y*=OHL zXDA3XO+ln$A7Bmatg)j7uQ`?@la<+x_h6sG+m?*Z%Tfs literal 4286 zcmeH{F%H5o3`KuIh>=dr9XSR!qsQSGJxT`-z{rI8uHvd7rHxca6;fQespI57$5IOH zP@!pnn$Nuk&HyfSPT@*tmT#bCu2|_n=|Jhg$__}(s4FYAQ?|$O%FfM?vNe&JKg+gc zrW#Csaon1(1v=NTc;?>)j{Gla)lIP+{GgeFAJ%x*VCS|mR>U;#$fwj`BbHIpci87O zq%wzfTB8?OwakL9g~MI5V8Zld>oE*rcl#^0V8Yiu-ezpoHKfhi=*^td+k!b)Psx=I vln(q+2gaXR?BjJ5QGe3=y-25CiL`X6^FP?q`{3Pyd9Hn&MBcZU>Nx)a8c~!R diff --git a/AppKit/Resources/CPCursor/resizeDownCursor.cur b/AppKit/Resources/CPCursor/resizeDownCursor.cur deleted file mode 100644 index f33cd374026d1ac715a13a3bb4866cc4c0124224..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4286 zcmeH{I}XAy5Jbnw9THH{l9F4%&EPm3kCFm0?1C-10EC0(P|QdhC$@KI^YQ^^2p9%n zfjLeqU=3hvVN=*!*s2|Yqpe9IAOa%Lf&i0R)T*uF)|T^#bY5Fx^#0PjcMq?;d-mY| zS*33=H=1irqWhKpHMuSJ%AbrePV)Wv^K#{uKOPcW?g_B>(^b diff --git a/AppKit/Resources/CPCursor/resizeLeftCursor.cur b/AppKit/Resources/CPCursor/resizeLeftCursor.cur deleted file mode 100644 index d93171b6d186cece58a809d24ac7d71fff1ca0ba..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4286 zcmeH@u?@p85Cf^GNSi9P%8ZfGJWe*rC?3Nmga1HHphmG9K0yD&5=8z17ZkLHPrYuy zozsJA)RW>VzreyXmkF4F37CKhn1BhGfC-p@35dWJbp{PtXN05u(>whG!_PJ|U+*pd zk>dWe2qXVm>sCtn=9=xVMfwbyM>TEv?jd)%T4 DzxNf+ diff --git a/AppKit/Resources/CPCursor/resizeRightCursor.cur b/AppKit/Resources/CPCursor/resizeRightCursor.cur deleted file mode 100644 index 4b20f862b5e0af1bd749fe4d58e0c07e763840d8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4286 zcmeH_F%H8Z3`Jdpl(C(iX?PZ25dkk+Kf?Taf8*b*GHG>(4 zeknz3t;cuN&%578X-=H|p*ZxmeujS+9V{`|Z0|b+-Lp@3=l<+Ffn~OC=!JgTzC(G% OKmJ56o;X`gchx_8r4mE{ diff --git a/AppKit/Resources/CPCursor/resizeUpCursor.cur b/AppKit/Resources/CPCursor/resizeUpCursor.cur deleted file mode 100644 index eb24ddb20a32d8d26fa2f927253a968119d6cccd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4286 zcmeH_u?@p83 -var selectors = ["pointingHandCursor", "resizeDownCursor", "resizeLeftCursor", "resizeRightCursor", "resizeUpCursor", "resizeLeftRightCursor", "resizeUpDownCursor", "operationNotAllowedCursor", "dragCopyCursor", "dragLinkCursor", "contextualMenuCursor", "openHandCursor", "closedHandCursor", "disappearingItemCursor"]; +@implementation CursorTester : CPView +{ + CPCursor testCursor; + CPTextField label; +} + +- (id)initWithText:(CPString)aLabel + origin:(CGPoint)anOrigin + cursor:(CPCursor)aCursor +{ + self = [super init]; + if (self) + { + testCursor = aCursor; + label = [CPTextField labelWithTitle:aLabel]; + [label setBackgroundColor:[CPColor redColor]]; + [label setTextColor:[CPColor whiteColor]]; + [self addSubview:label]; + [self setFrame:CGRectMake(anOrigin.x, + anOrigin.y, + [label frame].size.width, + [label frame].size.height)]; + } + return self; +} + +- (void)mouseEntered:(CPEvent)anEvent +{ + [testCursor set]; +} + +- (void)mouseExited:(CPEvent)anEvent +{ + [[CPCursor arrowCursor] set]; +} +@end @implementation AppController : CPObject { - CPPopUpButton popup; } - (void)applicationDidFinishLaunching:(CPNotification)aNotification { - var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask], - contentView = [theWindow contentView]; - - popup = [[CPPopUpButton alloc] initWithFrame:CGRectMake(100,100,150,24)]; - var menu = [popup menu]; - for (var i = 0 , count = [selectors count];i < count;i++) - { - var selector = selectors[i]; - var item = [[CPMenuItem alloc] initWithTitle:selector action:nil keyEquivalent:@""]; - [item setTarget:self]; - [menu addItem:item]; - } - [contentView addSubview:popup]; - - var button = [[CPButton alloc] initWithFrame:CGRectMake(270,100,100,24)]; - [button setAction:@selector(setCursor:)]; - [button setTarget:self]; - [button setTitle:@"set Cursor"]; - [contentView addSubview:button]; - - var button = [[CPButton alloc] initWithFrame:CGRectMake(270,150,150,24)]; - [button setAction:@selector(setUrlCursor:)]; - [button setTarget:self]; - [button setTitle:@"set Cursor from url"]; - [contentView addSubview:button]; + var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask]; + [theWindow setAcceptsMouseMovedEvents:YES]; + var contentView = [theWindow contentView], + imageCursorTester = [[CursorTester alloc] initWithText:@"Image cursor" + origin:CGPointMake(0, 0) + cursor:[[CPCursor alloc] initWithImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle bundleForClass:[CPCursor class]] resourcePath] + @"/CPCursor/openHandCursor.cur"] + hotSpot:CGPointMakeZero()]], + arrowCursorTester = [[CursorTester alloc] initWithText:@"Arrow cursor" + origin:CGPointMake(0, 20) + cursor:[CPCursor arrowCursor]], + crosshairCursorTester = [[CursorTester alloc] initWithText:@"Crosshair cursor" + origin:CGPointMake(0, 40) + cursor:[CPCursor crosshairCursor]] + IBeamCursorTester = [[CursorTester alloc] initWithText:@"IBeam cursor" + origin:CGPointMake(0, 60) + cursor:[CPCursor IBeamCursor]], + pointingHandCursorTester = [[CursorTester alloc] initWithText:@"Pointing hand cursor" + origin:CGPointMake(0, 80) + cursor:[CPCursor pointingHandCursor]], + resizeDownCursorTester = [[CursorTester alloc] initWithText:@"Resize down cursor" + origin:CGPointMake(0, 100) + cursor:[CPCursor resizeDownCursor]], + resizeUpCursorTester = [[CursorTester alloc] initWithText:@"Resize up cursor" + origin:CGPointMake(0, 120) + cursor:[CPCursor resizeUpCursor]], + resizeLeftCursorTester = [[CursorTester alloc] initWithText:@"Resize left cursor" + origin:CGPointMake(0, 140) + cursor:[CPCursor resizeLeftCursor]], + resizeRightCursorTester = [[CursorTester alloc] initWithText:@"Resize right cursor" + origin:CGPointMake(0, 160) + cursor:[CPCursor resizeRightCursor]], + resizeLeftRightCursorTester = [[CursorTester alloc] initWithText:@"Resize left-right cursor" + origin:CGPointMake(0, 180) + cursor:[CPCursor resizeLeftRightCursor]], + resizeUpDownCursorTester = [[CursorTester alloc] initWithText:@"Resize up-down cursor" + origin:CGPointMake(0, 200) + cursor:[CPCursor resizeUpDownCursor]], + operationNotAllowedCursorTester = [[CursorTester alloc] initWithText:@"Operation not allowed cursor" + origin:CGPointMake(0, 220) + cursor:[CPCursor operationNotAllowedCursor]], + dragCopyCursorTester = [[CursorTester alloc] initWithText:@"Drag copy cursor" + origin:CGPointMake(0, 240) + cursor:[CPCursor dragCopyCursor]], + dragLinkCursorTester = [[CursorTester alloc] initWithText:@"Drag link cursor" + origin:CGPointMake(0, 260) + cursor:[CPCursor dragLinkCursor]], + contextualMenuCursorTester = [[CursorTester alloc] initWithText:@"Contextual menu cursor" + origin:CGPointMake(0, 280) + cursor:[CPCursor contextualMenuCursor]], + openHandCursorTester = [[CursorTester alloc] initWithText:@"Open hand cursor" + origin:CGPointMake(0, 300) + cursor:[CPCursor openHandCursor]], + closedHandCursorTester = [[CursorTester alloc] initWithText:@"Closed hand cursor" + origin:CGPointMake(0, 320) + cursor:[CPCursor closedHandCursor]], + disappearingItemCursorTester = [[CursorTester alloc] initWithText:@"Disappearing item cursor" + origin:CGPointMake(0, 340) + cursor:[CPCursor disappearingItemCursor]]; + + [contentView addSubview:imageCursorTester]; + [contentView addSubview:arrowCursorTester]; + [contentView addSubview:crosshairCursorTester]; + [contentView addSubview:IBeamCursorTester]; + [contentView addSubview:pointingHandCursorTester]; + [contentView addSubview:resizeDownCursorTester]; + [contentView addSubview:resizeUpCursorTester]; + [contentView addSubview:resizeLeftCursorTester]; + [contentView addSubview:resizeRightCursorTester]; + [contentView addSubview:resizeLeftRightCursorTester]; + [contentView addSubview:resizeUpDownCursorTester]; + [contentView addSubview:operationNotAllowedCursorTester]; + [contentView addSubview:dragCopyCursorTester]; + [contentView addSubview:dragLinkCursorTester]; + [contentView addSubview:contextualMenuCursorTester]; + [contentView addSubview:openHandCursorTester]; + [contentView addSubview:closedHandCursorTester]; + [contentView addSubview:disappearingItemCursorTester]; [theWindow orderFront:self]; - // Uncomment the following line to turn on the standard menu bar. - //[CPMenu setMenuBarVisible:YES]; -} - -- (void)setCursor:(id)sender -{ - var selector = CPSelectorFromString([popup titleOfSelectedItem]); - var cursor = [CPCursor performSelector:selector]; - [cursor set]; -} - -- (void)setUrlCursor:(id)sender -{ // note gifs don't animate when they are used as a cursor. - var aImage = [[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:@"spinner.gif"]]; - var cursor = [[CPCursor alloc] initWithImage:aImage hotSpot:CGPointMakeZero()]; - [cursor set]; } @end diff --git a/Tests/Manual/CPCursor/test.html b/Tests/Manual/CPCursor/test.html deleted file mode 100644 index 14d4490fe..000000000 --- a/Tests/Manual/CPCursor/test.html +++ /dev/null @@ -1,18 +0,0 @@ - - - - -
Test custom cursors with .cur images.
-
disappearingItemCursor
-
closedHandCursor
-
contextMenuCursor
-
dragCopyCursor
-
dragLinkCursor
-
openHandCursor
-
resizeDownCursor
-
resizeLeftCursor
-
resizeRightCursor
-
resizeUpCursor
- - -