@@ -47,9 +47,13 @@ Some of this code was funded via a grant from the European Smalltalk User Group
47
47
extern struct VirtualMachine* interpreterProxy;
48
48
extern SqueakOSXAppDelegate *gDelegateApp ;
49
49
50
- static int buttonState= 0 ;
50
+ static int buttonState = 0 ;
51
51
52
52
static int firstScreenHeight = 0 ;
53
+
54
+ #define MouseButtonMask 0x7
55
+ #define MouseButtonShift 3
56
+
53
57
/*
54
58
* Answer (cache) the height of the main display, needed for transforming
55
59
* mac screen coordinates to Squeak screen coordinates.
@@ -204,7 +208,7 @@ - (void) recordCharEvent:(NSString *) unicodeString fromView: (NSView <sqSqueakO
204
208
unicode = [unicodeString characterAtIndex: i];
205
209
206
210
if (mainView.lastSeenKeyBoardStrokeDetails ) {
207
- evt.modifiers = [self translateCocoaModifiersToSqueakModifiers : mainView.lastSeenKeyBoardStrokeDetails.modifierFlags];
211
+ evt.modifiers = [self translateCocoaModifiersToSqueak : mainView.lastSeenKeyBoardStrokeDetails.modifierFlags];
208
212
evt.charCode = mainView.lastSeenKeyBoardStrokeDetails .keyCode ;
209
213
} else {
210
214
evt.modifiers = 0 ;
@@ -255,7 +259,7 @@ - (void) recordKeyDownEvent:(NSEvent *)theEvent fromView: (NSView <sqSqueakOSXVi
255
259
evt.timeStamp = ioMSecs ();
256
260
evt.charCode = [theEvent keyCode ];
257
261
evt.pressCode = EventKeyDown;
258
- evt.modifiers = [self translateCocoaModifiersToSqueakModifiers : [theEvent modifierFlags ]];
262
+ evt.modifiers = [self translateCocoaModifiersToSqueak : [theEvent modifierFlags ]];
259
263
evt.utf32Code = 0 ;
260
264
evt.reserved1 = 0 ;
261
265
evt.windowIndex = [[aView windowLogic ] windowIndex ];
@@ -271,7 +275,7 @@ - (void) recordKeyUpEvent:(NSEvent *)theEvent fromView: (NSView <sqSqueakOSXView
271
275
evt.timeStamp = ioMSecs ();
272
276
evt.charCode = [theEvent keyCode ];
273
277
evt.pressCode = EventKeyUp;
274
- evt.modifiers = [self translateCocoaModifiersToSqueakModifiers : [theEvent modifierFlags ]];
278
+ evt.modifiers = [self translateCocoaModifiersToSqueak : [theEvent modifierFlags ]];
275
279
evt.utf32Code = 0 ;
276
280
evt.reserved1 = 0 ;
277
281
evt.windowIndex = aView.windowLogic .windowIndex ;
@@ -292,8 +296,8 @@ - (void) recordMouseEvent:(NSEvent *)theEvent fromView: (NSView <sqSqueakOSXView
292
296
evt.y = lrintf ((float )local_point.y );
293
297
294
298
int buttonAndModifiers = [self mapMouseAndModifierStateToSqueakBits: theEvent];
295
- evt.buttons = buttonAndModifiers & 0x07 ;
296
- evt.modifiers = buttonAndModifiers >> 3 ;
299
+ evt.buttons = buttonAndModifiers & MouseButtonMask ;
300
+ evt.modifiers = buttonAndModifiers >> MouseButtonShift ;
297
301
#if COGVM | STACKVM
298
302
evt.nrClicks = 0 ;
299
303
#else
@@ -318,8 +322,8 @@ - (void) recordMouseButtonEvent:(NSEvent *)theEvent fromView: (NSView <sqSqueakO
318
322
evt.y = lrintf ((float )local_point.y );
319
323
320
324
int buttonAndModifiers = [self mapMouseAndModifierStateToSqueakBits: theEvent];
321
- evt.buttons = buttonAndModifiers & 0x07 ;
322
- evt.modifiers = buttonAndModifiers >> 3 ;
325
+ evt.buttons = buttonAndModifiers & MouseButtonMask ;
326
+ evt.modifiers = buttonAndModifiers >> MouseButtonShift ;
323
327
#if COGVM | STACKVM
324
328
evt.nrClicks = theEvent.clickCount ;
325
329
#else
@@ -391,8 +395,8 @@ - (void) recordWheelEvent:(NSEvent *) theEvent fromView: (NSView <sqSqueakOSXVie
391
395
prevYDelta = 0 ;
392
396
393
397
int buttonAndModifiers = [self mapMouseAndModifierStateToSqueakBits: theEvent];
394
- evt.buttons = buttonAndModifiers & 7 ;
395
- evt.modifiers = buttonAndModifiers >> 3 ;
398
+ evt.buttons = buttonAndModifiers & MouseButtonMask ;
399
+ evt.modifiers = buttonAndModifiers >> MouseButtonShift ;
396
400
evt.windowIndex = aView.windowLogic .windowIndex ;
397
401
[self pushEventToQueue: (sqInputEvent *) &evt];
398
402
}
@@ -470,7 +474,7 @@ - (void) fakeMouseWheelKeyboardEventsKeyCode: (int) keyCode ascii: (int) ascii w
470
474
*
471
475
* While we could just shift and mask, let's be clean an just check.
472
476
*/
473
- - (int ) translateCocoaModifiersToSqueakModifiers : (NSUInteger ) modifiers {
477
+ - (int ) translateCocoaModifiersToSqueak : (NSUInteger ) modifiers {
474
478
return
475
479
(modifiers & NSEventModifierFlagShift ? ShiftKeyBit : 0 ) |
476
480
(modifiers & NSEventModifierFlagControl ? CtrlKeyBit : 0 ) |
@@ -538,7 +542,8 @@ - (int) mapMouseAndModifierStateToSqueakBits: (NSEvent *) event {
538
542
}
539
543
540
544
// button state: low three bits are mouse buttons; next 8 bits are modifier bits
541
- buttonState = ([self translateCocoaModifiersToSqueakModifiers: flags] << 3 ) | (stButtons & 0x7 );
545
+ buttonState = ([self translateCocoaModifiersToSqueak: flags] << MouseButtonShift)
546
+ | (stButtons & MouseButtonMask);
542
547
return buttonState;
543
548
}
544
549
@@ -553,7 +558,7 @@ - (void) recordDragEvent:(int)dragType numberOfFiles:(int)numFiles where:(NSPoin
553
558
evt.dragType = dragType;
554
559
evt.x = lrintf (local_point.x );
555
560
evt.y = lrintf (local_point.y );
556
- evt.modifiers = ( buttonState >> 3 ) ;
561
+ evt.modifiers = buttonState >> MouseButtonShift ;
557
562
evt.numFiles = numFiles;
558
563
evt.windowIndex = windowIndex;
559
564
[self pushEventToQueue: (sqInputEvent *) &evt];
0 commit comments