00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "Platform/Platform.h"
00016
00017 var currentCursor = nil,
00018 cursorStack = [],
00019 cursors = {},
00020 cursorURLFormat = nil;
00021
00022 @implementation CPCursor : CPObject
00023 {
00024 CPString _cssString;
00025 BOOL _isSetOnMouseEntered @accessors(readwrite, getter=isSetOnMouseEntered, setter=setOnMouseEntered:);
00026 BOOL _isSetOnMouseExited @accessors(readwrite, getter=isSetOnMouseExited, setter=setOnMouseExited:);
00027 }
00028
00029 + (CPCursor)currentCursor
00030 {
00031 return currentCursor;
00032 }
00033
00034 - (id)initWithCSSString:(CPString)aString
00035 {
00036 if (self = [super init])
00037 _cssString = aString;
00038
00039 return self;
00040 }
00041
00042 + (CPCursor)cursorWithCSSString:(CPString)cssString
00043 {
00044 var cursor = cursors[cssString];
00045
00046 if (typeof cursor == 'undefined')
00047 {
00048 cursor = [[CPCursor alloc] initWithCSSString:cssString];
00049 cursors[cssString] = cursor;
00050 }
00051
00052 return cursor;
00053 }
00054
00055 + (CPCursor)cursorWithImageNamed:(CPString)imageName
00056 {
00057 if (!cursorURLFormat)
00058 {
00059 cursorURLFormat = @"url(" + [[CPBundle bundleForClass:self] resourcePath] + @"/CPCursor/%@.cur)";
00060
00061 if (CPBrowserIsEngine(CPGeckoBrowserEngine))
00062 cursorURLFormat += ", default";
00063 }
00064
00065 var url = [CPString stringWithFormat:cursorURLFormat, imageName];
00066
00067 return [[CPCursor alloc] initWithCSSString:url];
00068 }
00069
00070 - (CPString)_cssString
00071 {
00072 return _cssString;
00073 }
00074
00075 + (CPCursor)arrowCursor
00076 {
00077 return [CPCursor cursorWithCSSString:@"default"];
00078 }
00079
00080 + (CPCursor)crosshairCursor
00081 {
00082 return [CPCursor cursorWithCSSString:@"crosshair"];
00083 }
00084
00085 + (CPCursor)IBeamCursor
00086 {
00087 return [CPCursor cursorWithCSSString:@"text"];
00088 }
00089
00090 + (CPCursor)pointingHandCursor
00091 {
00092 return [CPCursor cursorWithCSSString:@"pointer"];
00093 }
00094
00095 + (CPCursor)resizeDownCursor
00096 {
00097 if (CPBrowserIsEngine(CPInternetExplorerBrowserEngine))
00098 return [CPCursor cursorWithImageNamed:CPStringFromSelector(_cmd)];
00099
00100 return [CPCursor cursorWithCSSString:"s-resize"];
00101 }
00102
00103 + (CPCursor)resizeUpCursor
00104 {
00105 if (CPBrowserIsEngine(CPInternetExplorerBrowserEngine))
00106 return [CPCursor cursorWithImageNamed:CPStringFromSelector(_cmd)];
00107
00108 return [CPCursor cursorWithCSSString:@"n-resize"];
00109 }
00110
00111 + (CPCursor)resizeLeftCursor
00112 {
00113 if (CPBrowserIsEngine(CPInternetExplorerBrowserEngine))
00114 return [CPCursor cursorWithImageNamed:CPStringFromSelector(_cmd)];
00115
00116 return [CPCursor cursorWithCSSString:@"w-resize"];
00117 }
00118
00119 + (CPCursor)resizeRightCursor
00120 {
00121 if (CPBrowserIsEngine(CPInternetExplorerBrowserEngine))
00122 return [CPCursor cursorWithImageNamed:CPStringFromSelector(_cmd)];
00123
00124 return [CPCursor cursorWithCSSString:@"e-resize"];
00125 }
00126
00127 + (CPCursor)resizeLeftRightCursor
00128 {
00129 return [CPCursor cursorWithCSSString:@"col-resize"];
00130 }
00131
00132 + (CPCursor)resizeUpDownCursor
00133 {
00134 return [CPCursor cursorWithCSSString:@"row-resize"];
00135 }
00136
00137 + (CPCursor)operationNotAllowedCursor
00138 {
00139 return [CPCursor cursorWithCSSString:@"not-allowed"];
00140 }
00141
00142 + (CPCursor)dragCopyCursor
00143 {
00144 if (CPBrowserIsEngine(CPInternetExplorerBrowserEngine))
00145 return [CPCursor cursorWithImageNamed:CPStringFromSelector(_cmd)];
00146
00147 return [CPCursor cursorWithCSSString:@"copy"];
00148 }
00149
00150 + (CPCursor)dragLinkCursor
00151 {
00152 if (CPBrowserIsEngine(CPInternetExplorerBrowserEngine))
00153 return [CPCursor cursorWithImageNamed:CPStringFromSelector(_cmd)];
00154
00155 return [CPCursor cursorWithCSSString:@"alias"];
00156 }
00157
00158 + (CPCursor)contextualMenuCursor
00159 {
00160 if (CPBrowserIsEngine(CPInternetExplorerBrowserEngine))
00161 return [CPCursor cursorWithImageNamed:CPStringFromSelector(_cmd)];
00162
00163 return [CPCursor cursorWithCSSString:@"context-menu"];
00164 }
00165
00166 + (CPCursor)openHandCursor
00167 {
00168 if (CPBrowserIsEngine(CPWebKitBrowserEngine))
00169 return [CPCursor cursorWithCSSString:@"-webkit-grab"];
00170 else if (CPBrowserIsEngine(CPGeckoBrowserEngine) || CPBrowserIsEngine(CPOperaBrowserEngine))
00171 return [CPCursor cursorWithCSSString:@"move"];
00172
00173 return [CPCursor cursorWithImageNamed:CPStringFromSelector(_cmd)];
00174 }
00175
00176 + (CPCursor)closedHandCursor
00177 {
00178 if (CPBrowserIsEngine(CPWebKitBrowserEngine))
00179 return [CPCursor cursorWithCSSString:@"-webkit-grabbing"];
00180
00181 return [CPCursor cursorWithImageNamed:CPStringFromSelector(_cmd)];
00182 }
00183
00184 + (CPCursor)disappearingItemCursor
00185 {
00186 return [CPCursor cursorWithImageNamed:CPStringFromSelector(_cmd)];
00187 }
00188
00189 + (void)hide
00190 {
00191 [self _setCursorCSS:"none"];
00192 }
00193
00194 + (void)unhide
00195 {
00196 [self _setCursorCSS:[currentCursor _cssString]]
00197 }
00198
00199 + (void)setHiddenUntilMouseMoves:(BOOL)flag
00200 {
00201 if (flag)
00202 [CPCursor hide];
00203 else
00204 [CPCursor unhide];
00205 }
00206
00207 - (id)initWithImage:(CPImage)image hotSpot:(CPPoint)hotSpot
00208 {
00209 return [self initWithCSSString:"url(" + [image filename] + ")"];
00210 }
00211
00212 - (void)mouseEntered:(CPEvent)event
00213 {
00214 }
00215
00216 - (void)mouseExited:(CPEvent)event
00217 {
00218 }
00219
00220 - (void)set
00221 {
00222 currentCursor = self;
00223
00224 #if PLATFORM(DOM)
00225 [[self class] _setCursorCSS:_cssString];
00226 #endif
00227
00228 }
00229
00230 + (void)_setCursorCSS:(CPString)aString
00231 {
00232 #if PLATFORM(DOM)
00233 var platformWindows = [[CPPlatformWindow visiblePlatformWindows] allObjects];
00234 for (var i = 0, count = [platformWindows count]; i < count; i++)
00235 platformWindows[i]._DOMBodyElement.style.cursor = aString;
00236 #endif
00237 }
00238
00239 - (void)push
00240 {
00241 currentCursor = cursorStack.push(self);
00242 }
00243
00244 - (void)pop
00245 {
00246 [CPCursor pop];
00247 }
00248
00249 + (void)pop
00250 {
00251 if (cursorStack.length > 1)
00252 {
00253 cursorStack.pop();
00254 currentCursor = cursorStack[cursorStack.length - 1];
00255 }
00256 }
00257
00258 - (id)initWithCoder:(CPCoder)coder
00259 {
00260 if (self = [super init])
00261 _cssString = [coder decodeObjectForKey:@"CPCursorNameKey"];
00262
00263 return self;
00264 }
00265
00266 - (void)encodeWithCoder:(CPCoder)coder
00267 {
00268 [coder encodeObject:_cssString forKey:@"CPCursorNameKey"];
00269 }
00270
00271 @end
00272