00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 @import <Foundation/CPObject.j>
00024
00025 #include "CoreGraphics/CGGeometry.h"
00026
00027
00028
00029
00030
00031
00032 CPLeftMouseDown = 1;
00033
00034
00035
00036
00037 CPLeftMouseUp = 2;
00038
00039
00040
00041
00042 CPRightMouseDown = 3;
00043
00044
00045
00046
00047 CPRightMouseUp = 4;
00048
00049
00050
00051
00052 CPMouseMoved = 5;
00053
00054
00055
00056
00057 CPLeftMouseDragged = 6;
00058
00059
00060
00061
00062 CPRightMouseDragged = 7;
00063
00064
00065
00066
00067 CPMouseEntered = 8;
00068
00069
00070
00071
00072 CPMouseExited = 9;
00073
00074
00075
00076
00077 CPKeyDown = 10;
00078
00079
00080
00081
00082 CPKeyUp = 11;
00083
00084
00085
00086
00087 CPFlagsChanged = 12;
00088
00089
00090
00091
00092 CPAppKitDefined = 13;
00093
00094
00095
00096
00097 CPSystemDefined = 14;
00098
00099
00100
00101
00102 CPApplicationDefined = 15;
00103
00104
00105
00106
00107 CPPeriodic = 16;
00108
00109
00110
00111
00112 CPCursorUpdate = 17;
00113
00114
00115
00116
00117 CPScrollWheel = 22;
00118
00119
00120
00121
00122 CPOtherMouseDown = 25;
00123
00124
00125
00126
00127 CPOtherMouseUp = 26;
00128
00129
00130
00131
00132 CPOtherMouseDragged = 27;
00133
00134
00135 CPTouchStart = 28;
00136 CPTouchMove = 29;
00137 CPTouchEnd = 30;
00138 CPTouchCancel = 31;
00139
00140
00141 CPAlphaShiftKeyMask = 1 << 16;
00142 CPShiftKeyMask = 1 << 17;
00143 CPControlKeyMask = 1 << 18;
00144 CPAlternateKeyMask = 1 << 19;
00145 CPCommandKeyMask = 1 << 20;
00146 CPNumericPadKeyMask = 1 << 21;
00147 CPHelpKeyMask = 1 << 22;
00148 CPFunctionKeyMask = 1 << 23;
00149 CPDeviceIndependentModifierFlagsMask = 0xffff0000;
00150
00151 CPLeftMouseDownMask = 1 << CPLeftMouseDown;
00152 CPLeftMouseUpMask = 1 << CPLeftMouseUp;
00153 CPRightMouseDownMask = 1 << CPRightMouseDown;
00154 CPRightMouseUpMask = 1 << CPRightMouseUp;
00155 CPOtherMouseDownMask = 1 << CPOtherMouseDown;
00156 CPOtherMouseUpMask = 1 << CPOtherMouseUp;
00157 CPMouseMovedMask = 1 << CPMouseMoved;
00158 CPLeftMouseDraggedMask = 1 << CPLeftMouseDragged;
00159 CPRightMouseDraggedMask = 1 << CPRightMouseDragged;
00160 CPOtherMouseDragged = 1 << CPOtherMouseDragged;
00161 CPMouseEnteredMask = 1 << CPMouseEntered;
00162 CPMouseExitedMask = 1 << CPMouseExited;
00163 CPCursorUpdateMask = 1 << CPCursorUpdate;
00164 CPKeyDownMask = 1 << CPKeyDown;
00165 CPKeyUpMask = 1 << CPKeyUp;
00166 CPFlagsChangedMask = 1 << CPFlagsChanged;
00167 CPAppKitDefinedMask = 1 << CPAppKitDefined;
00168 CPSystemDefinedMask = 1 << CPSystemDefined;
00169 CPApplicationDefinedMask = 1 << CPApplicationDefined;
00170 CPPeriodicMask = 1 << CPPeriodic;
00171 CPScrollWheelMask = 1 << CPScrollWheel;
00172 CPAnyEventMask = 0xffffffff;
00173
00174 CPDOMEventDoubleClick = "dblclick",
00175 CPDOMEventMouseDown = "mousedown",
00176 CPDOMEventMouseUp = "mouseup",
00177 CPDOMEventMouseMoved = "mousemove",
00178 CPDOMEventMouseDragged = "mousedrag",
00179 CPDOMEventKeyUp = "keyup",
00180 CPDOMEventKeyDown = "keydown",
00181 CPDOMEventKeyPress = "keypress";
00182 CPDOMEventCopy = "copy";
00183 CPDOMEventPaste = "paste";
00184 CPDOMEventScrollWheel = "mousewheel";
00185 CPDOMEventTouchStart = "touchstart";
00186 CPDOMEventTouchMove = "touchmove";
00187 CPDOMEventTouchEnd = "touchend";
00188 CPDOMEventTouchCancel = "touchcancel";
00189
00190 var _CPEventPeriodicEventPeriod = 0,
00191 _CPEventPeriodicEventTimer = nil;
00192
00198 @implementation CPEvent : CPObject
00199 {
00200 CPEventType _type;
00201 CPPoint _location;
00202 unsigned _modifierFlags;
00203 CPTimeInterval _timestamp;
00204 CPGraphicsContext _context;
00205 int _eventNumber;
00206 unsigned _clickCount;
00207 float _pressure;
00208 CPWindow _window;
00209 Number _windowNumber;
00210 CPString _characters;
00211 CPString _charactersIgnoringModifiers
00212 BOOL _isARepeat;
00213 unsigned _keyCode;
00214 DOMEvent _DOMEvent;
00215
00216 float _deltaX;
00217 float _deltaY;
00218 float _deltaZ;
00219 }
00220
00237 + (CPEvent)keyEventWithType:(CPEventType)anEventType location:(CGPoint)aPoint modifierFlags:(unsigned int)modifierFlags
00238 timestamp:(CPTimeInterval)aTimestamp windowNumber:(int)aWindowNumber context:(CPGraphicsContext)aGraphicsContext
00239 characters:(CPString)characters charactersIgnoringModifiers:(CPString)unmodCharacters isARepeat:(BOOL)repeatKey keyCode:(unsigned short)code
00240 {
00241 return [[self alloc] _initKeyEventWithType:anEventType location:aPoint modifierFlags:modifierFlags
00242 timestamp:aTimestamp windowNumber:aWindowNumber context:aGraphicsContext
00243 characters:characters charactersIgnoringModifiers:unmodCharacters isARepeat:repeatKey keyCode:code];
00244 }
00245
00260 + (id)mouseEventWithType:(CPEventType)anEventType location:(CGPoint)aPoint modifierFlags:(unsigned)modifierFlags
00261 timestamp:(CPTimeInterval)aTimestamp windowNumber:(int)aWindowNumber context:(CPGraphicsContext)aGraphicsContext
00262 eventNumber:(int)anEventNumber clickCount:(int)aClickCount pressure:(float)aPressure
00263 {
00264 return [[self alloc] _initMouseEventWithType:anEventType location:aPoint modifierFlags:modifierFlags
00265 timestamp:aTimestamp windowNumber:aWindowNumber context:aGraphicsContext eventNumber:anEventNumber clickCount:aClickCount pressure:aPressure];
00266 }
00267
00282 + (CPEvent)otherEventWithType:(CPEventType)anEventType location:(CGPoint)aLocation modifierFlags:(unsigned)modifierFlags
00283 timestamp:(CPTimeInterval)aTimestamp windowNumber:(int)aWindowNumber context:(CPGraphicsContext)aGraphicsContext
00284 subtype:(short)aSubtype data1:(int)aData1 data2:(int)aData2
00285 {
00286 return [[self alloc] _initOtherEventWithType:anEventType location:aLocation modifierFlags:modifierFlags
00287 timestamp:aTimestamp windowNumber:aWindowNumber context:aGraphicsContext subtype:aSubtype data1:aData1 data2:aData2];
00288 }
00289
00290
00291 - (id)_initMouseEventWithType:(CPEventType)anEventType location:(CPPoint)aPoint modifierFlags:(unsigned)modifierFlags
00292 timestamp:(CPTimeInterval)aTimestamp windowNumber:(int)aWindowNumber context:(CPGraphicsContext)aGraphicsContext
00293 eventNumber:(int)anEventNumber clickCount:(int)aClickCount pressure:(float)aPressure
00294 {
00295 self = [super init];
00296
00297 if (self)
00298 {
00299 _type = anEventType;
00300 _location = CPPointCreateCopy(aPoint);
00301 _modifierFlags = modifierFlags;
00302 _timestamp = aTimestamp;
00303 _context = aGraphicsContext;
00304 _eventNumber = anEventNumber;
00305 _clickCount = aClickCount;
00306 _pressure = aPressure;
00307 _window = [CPApp windowWithWindowNumber:aWindowNumber];
00308 }
00309
00310 return self;
00311 }
00312
00313
00314 - (id)_initKeyEventWithType:(CPEventType)anEventType location:(CPPoint)aPoint modifierFlags:(unsigned int)modifierFlags
00315 timestamp:(CPTimeInterval)aTimestamp windowNumber:(int)aWindowNumber context:(CPGraphicsContext)aGraphicsContext
00316 characters:(CPString)characters charactersIgnoringModifiers:(CPString)unmodCharacters isARepeat:(BOOL)isARepeat keyCode:(unsigned short)code
00317 {
00318 self = [super init];
00319
00320 if (self)
00321 {
00322 _type = anEventType;
00323 _location = CPPointCreateCopy(aPoint);
00324 _modifierFlags = modifierFlags;
00325 _timestamp = aTimestamp;
00326 _context = aGraphicsContext;
00327 _characters = characters;
00328 _charactersIgnoringModifiers = unmodCharacters;
00329 _isARepeat = isARepeat;
00330 _keyCode = code;
00331 _windowNumber = aWindowNumber;
00332 }
00333
00334 return self;
00335 }
00336
00337
00338 - (id)_initOtherEventWithType:(CPEventType)anEventType location:(CGPoint)aPoint modifierFlags:(unsigned)modifierFlags
00339 timestamp:(CPTimeInterval)aTimestamp windowNumber:(int)aWindowNumber context:(CPGraphicsContext)aGraphicsContext
00340 subtype:(short)aSubtype data1:(int)aData1 data2:(int)aData2
00341 {
00342 self = [super init];
00343
00344 if (self)
00345 {
00346 _type = anEventType;
00347 _location = CPPointCreateCopy(aPoint);
00348 _modifierFlags = modifierFlags;
00349 _timestamp = aTimestamp;
00350 _context = aGraphicsContext;
00351 _subtype = aSubtype;
00352 _data1 = aData1;
00353 _data2 = aData2;
00354 }
00355
00356 return self;
00357 }
00358
00367 - (CGPoint)locationInWindow
00368 {
00369 return _location;
00370 }
00371
00375 - (unsigned)modifierFlags
00376 {
00377 return _modifierFlags;
00378 }
00379
00383 - (CPTimeInterval)timestamp
00384 {
00385 return _timestamp;
00386 }
00387
00391 - (CPEventType)type
00392 {
00393 return _type;
00394 }
00395
00399 - (CPWindow)window
00400 {
00401 if (!_window)
00402 _window = [CPApp windowWithWindowNumber:_windowNumber];
00403
00404 return _window;
00405 }
00406
00410 - (int)windowNumber
00411 {
00412 return _windowNumber;
00413 }
00414
00415
00419 - (int)buttonNumber
00420 {
00421 return _buttonNumber;
00422 }
00423
00427 - (int)clickCount
00428 {
00429 return _clickCount;
00430 }
00431
00436 - (CPString)characters
00437 {
00438 return _characters;
00439 }
00440
00445 - (CPString)charactersIgnoringModifiers
00446 {
00447 return _charactersIgnoringModifiers;
00448 }
00449
00454 - (BOOL)isARepeat
00455 {
00456 return _isARepeat;
00457 }
00458
00463 - (unsigned short)keyCode
00464 {
00465 return _keyCode;
00466 }
00467
00468 - (float)pressure
00469 {
00470 return _pressure;
00471 }
00472
00473
00474
00475
00476 - (DOMEvent)_DOMEvent
00477 {
00478 return _DOMEvent;
00479 }
00480
00481
00485 - (float)deltaX
00486 {
00487 return _deltaX;
00488 }
00489
00493 - (float)deltaY
00494 {
00495 return _deltaY;
00496 }
00497
00501 - (float)deltaZ
00502 {
00503 return _deltaZ;
00504 }
00505
00511 + (void)startPeriodicEventsAfterDelay:(CPTimeInterval)aDelay withPeriod:(CPTimeInterval)aPeriod
00512 {
00513 _CPEventPeriodicEventPeriod = aPeriod;
00514
00515
00516 _CPEventPeriodicEventTimer = window.setTimeout(function() { _CPEventPeriodicEventTimer = window.setInterval(_CPEventFirePeriodEvent, aPeriod * 1000.0); }, aDelay * 1000.0);
00517 }
00518
00522 + (void)stopPeriodicEvents
00523 {
00524 if (_CPEventPeriodicEventTimer === nil)
00525 return;
00526
00527 window.clearTimeout(_CPEventPeriodicEventTimer);
00528
00529 _CPEventPeriodicEventTimer = nil;
00530 }
00531
00532 @end
00533
00534 function _CPEventFirePeriodEvent()
00535 {
00536 [CPApp sendEvent:[CPEvent otherEventWithType:CPPeriodic location:_CGPointMakeZero() modifierFlags:0 timestamp:0 windowNumber:0 context:nil subtype:0 data1:0 data2:0]];
00537 }
00538
00539 var CPEventClass = [CPEvent class];
00540
00541 function _CPEventFromNativeMouseEvent(aNativeEvent, anEventType, aPoint, modifierFlags, aTimestamp, aWindowNumber, aGraphicsContext, anEventNumber, aClickCount, aPressure)
00542 {
00543 aNativeEvent.isa = CPEventClass;
00544
00545 aNativeEvent._type = anEventType;
00546 aNativeEvent._location = aPoint;
00547 aNativeEvent._modifierFlags = modifierFlags;
00548 aNativeEvent._timestamp = aTimestamp;
00549 aNativeEvent._windowNumber = aWindowNumber;
00550 aNativeEvent._window = nil;
00551 aNativeEvent._context = aGraphicsContext;
00552 aNativeEvent._eventNumber = anEventNumber;
00553 aNativeEvent._clickCount = aClickCount;
00554 aNativeEvent._pressure = aPressure;
00555
00556 return aNativeEvent;
00557 }
00558