Skip to content

Commit

Permalink
Mac UI: Work in progress to include unicode in keyUp and keyDowqn eve…
Browse files Browse the repository at this point in the history
…nts if VM

is compiled with INCLUDE_UNICODE_IN_ALL_KEYBOARD_EVENTS, or the abbreviation
IUIAKE.  This code works for keyDown but not for the trailing keyUp.
Anyone who understands this code better than I is welcome to fix that issue :-)
  • Loading branch information
eliotmiranda committed Nov 3, 2021
1 parent 634e4e3 commit 0d706fc
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 57 deletions.
37 changes: 20 additions & 17 deletions platforms/iOS/vm/OSX/sqSqueakOSXApplication+events.m
Expand Up @@ -191,21 +191,21 @@ - (void) pushEventToQueue: (sqInputEvent *) evt {

- (void) recordCharEvent:(NSString *) unicodeString fromView: (NSView <sqSqueakOSXView> *) mainView {
sqKeyboardEvent evt;
unichar unicode;
unsigned char isoCharacter;
NSInteger i;
NSRange picker;
NSUInteger totaLength;

evt.type = EventTypeKeyboard;
evt.timeStamp = ioMSecs();
evt.timeStamp = ioMSecs();
evt.reserved1 = 0;
evt.windowIndex = mainView.windowLogic.windowIndex;
picker.location = 0;
picker.length = 1;
totaLength = [unicodeString length];

for (i=0;i < totaLength;i++) {

unicode = [unicodeString characterAtIndex: i];
unsigned char isoCharacter;
unichar unicode = [unicodeString characterAtIndex: i];

if (mainView.lastSeenKeyBoardStrokeDetails) {
evt.modifiers = [self translateCocoaModifiersToSqueak: mainView.lastSeenKeyBoardStrokeDetails.modifierFlags];
Expand All @@ -215,41 +215,44 @@ - (void) recordCharEvent:(NSString *) unicodeString fromView: (NSView <sqSqueakO
evt.charCode = 0;
}

if ((evt.modifiers & CommandKeyBit) && (evt.modifiers & ShiftKeyBit)) { /* command and shift */
if ((unicode >= 97) && (unicode <= 122)) {
/* convert ascii code of command-shift-letter to upper case */
unicode = unicode - 32;
}
}
// convert ascii code of command-shift-letter to upper case
if ((evt.modifiers & CommandKeyBit) && (evt.modifiers & ShiftKeyBit)
&& (unicode >= 97) && (unicode <= 122))
unicode = unicode - 32;

NSString *lookupString = AUTORELEASEOBJ([[NSString alloc] initWithCharacters: &unicode length: 1]);
[lookupString getBytes: &isoCharacter maxLength: 1 usedLength: NULL encoding: NSISOLatin1StringEncoding
options: 0 range: picker remainingRange: NULL];

evt.pressCode = EventKeyDown;
unsigned short keyCodeRemembered = evt.charCode;
#if INCLUDE_UTF_IN_ALL_KEYBOARD_EVENTS || IUIAKE
evt.utf32Code = unicode;
#else
evt.utf32Code = 0;
evt.reserved1 = 0;
evt.windowIndex = mainView.windowLogic.windowIndex;
#endif
[self pushEventToQueue: (sqInputEvent *)&evt];

evt.charCode = isoCharacter;
sqIntptr_t keyCodeRemembered = evt.charCode;
evt.charCode = isoCharacter;
evt.pressCode = EventKeyChar;
evt.modifiers = evt.modifiers;
evt.modifiers = evt.modifiers;
evt.utf32Code = unicode;

[self pushEventToQueue: (sqInputEvent *) &evt];

if (i > 1 || !mainView.lastSeenKeyBoardStrokeDetails) {
evt.pressCode = EventKeyUp;
evt.charCode = keyCodeRemembered;
#if INCLUDE_UTF_IN_ALL_KEYBOARD_EVENTS || IUIAKE
evt.utf32Code = unicode;
#else
evt.utf32Code = 0;
#endif
[self pushEventToQueue: (sqInputEvent *) &evt];
}
}

interpreterProxy->signalSemaphoreWithIndex(gDelegateApp.squeakApplication.inputSemaphoreIndex);

}

- (void) recordKeyDownEvent:(NSEvent *)theEvent fromView: (NSView <sqSqueakOSXView> *) aView {
Expand Down
87 changes: 47 additions & 40 deletions platforms/iOS/vm/iPhone/Classes/SqueakUIView.m
Expand Up @@ -15,10 +15,10 @@ Some of this code was funded via a grant from the European Smalltalk User Group
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Expand All @@ -27,11 +27,11 @@ Some of this code was funded via a grant from the European Smalltalk User Group
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
The end-user documentation included with the redistribution, if any, must include the following acknowledgment:
"This product includes software developed by Corporate Smalltalk Consulting Ltd (http://www.smalltalkconsulting.com)
and its contributors", in the same place and form as other third-party acknowledgments.
Alternately, this acknowledgment may appear in the software itself, in the same form and location as other
The end-user documentation included with the redistribution, if any, must include the following acknowledgment:
"This product includes software developed by Corporate Smalltalk Consulting Ltd (http://www.smalltalkconsulting.com)
and its contributors", in the same place and form as other third-party acknowledgments.
Alternately, this acknowledgment may appear in the software itself, in the same form and location as other
such third-party acknowledgments.
*/

Expand All @@ -53,10 +53,10 @@ - (instancetype)initWithFrame:(CGRect) aFrame {
self = [super initWithFrame: aFrame];
self.autoresizingMask = UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
colorspace = CGColorSpaceCreateDeviceRGB();

// jdr - hack cmd-z undo support
self.arrowsNames = @[UIKeyInputLeftArrow, UIKeyInputRightArrow, UIKeyInputUpArrow, UIKeyInputDownArrow];

dispatch_async(dispatch_get_main_queue(), ^{
[self setUndoFlag: undoCounter];
});
Expand All @@ -81,15 +81,15 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
}

// Handles the continuation of a touch.
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
//Called by Main Thread, beware of calling Squeak routines in Squeak Thread
[(sqSqueakIPhoneApplication *) gDelegateApp.squeakApplication recordTouchEvent: touches type: UITouchPhaseMoved];

}

// Handles the end of a touch event.
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
//Called by Main Thread, beware of calling Squeak routines in Squeak Thread
[(sqSqueakIPhoneApplication *) gDelegateApp.squeakApplication recordTouchEvent: touches type: UITouchPhaseEnded];
Expand Down Expand Up @@ -237,24 +237,24 @@ - (void)deleteBackward {
[self recordCharEvent:[NSString stringWithCharacters: delete length: 1]];
}

- (void) pushEventToQueue: (sqInputEvent *) evt {
- (void) pushEventToQueue: (sqInputEvent *) evt {
NSMutableArray* data = [NSMutableArray arrayWithCapacity: 2];
[data addObject: @7];
[data addObject: [NSData dataWithBytes:(const void *) evt length: sizeof(sqInputEvent)]];
[[gDelegateApp.squeakApplication eventQueue] addItem: data];
}

- (int) figureOutKeyCode: (unichar) unicode {
static int unicodeToKeyCode[] = {54, 115, 11, 52, 119, 114, 3, 5, 51, 48, 38, 116, 121, 36, 45, 31,
96, 12, 15, 1, 17, 32, 9, 13, 7, 16, 6, 53, 123, 124, 126, 125, 49, 18, 39, 20, 21, 23, 26, 39,
25, 29, 67, 69, 43, 27, 47, 44, 29, 18, 19, 20, 21, 23, 22, 26, 28, 25, 41, 41, 43, 24, 47,
44, 19, 0, 11, 8, 2, 14, 3, 5, 4, 34, 38, 40, 37, 46, 45, 31, 35, 12, 15, 1, 17, 32, 9, 13,
7, 16, 6, 33, 42, 30, 22, 27, 50, 0, 11, 8, 2, 14, 3, 5, 4, 34, 38, 40, 37, 46, 45, 31, 35,
static int unicodeToKeyCode[] = {54, 115, 11, 52, 119, 114, 3, 5, 51, 48, 38, 116, 121, 36, 45, 31,
96, 12, 15, 1, 17, 32, 9, 13, 7, 16, 6, 53, 123, 124, 126, 125, 49, 18, 39, 20, 21, 23, 26, 39,
25, 29, 67, 69, 43, 27, 47, 44, 29, 18, 19, 20, 21, 23, 22, 26, 28, 25, 41, 41, 43, 24, 47,
44, 19, 0, 11, 8, 2, 14, 3, 5, 4, 34, 38, 40, 37, 46, 45, 31, 35, 12, 15, 1, 17, 32, 9, 13,
7, 16, 6, 33, 42, 30, 22, 27, 50, 0, 11, 8, 2, 14, 3, 5, 4, 34, 38, 40, 37, 46, 45, 31, 35,
12, 15, 1, 17, 32, 9, 13, 7, 16, 6, 33, 42, 30, 50, 117};
if (unicode > 127)
if (unicode > 127)
return 0;
return unicodeToKeyCode[unicode];

}

- (void) recordCharEvent:(NSString *) unicodeString {
Expand All @@ -264,61 +264,68 @@ - (void) recordCharEvent:(NSString *) unicodeString {
NSInteger i;
NSRange picker;
NSUInteger totaLength;

evt.type = EventTypeKeyboard;
evt.timeStamp = (int) ioMSecs();
picker.location = 0;
picker.length = 1;
totaLength = [unicodeString length];
for (i=0;i < totaLength;i++) {

unicode = [unicodeString characterAtIndex: i];
NSString *lookupString = [[NSString alloc] initWithCharacters: &unicode length: 1];
[lookupString getBytes: &isoCharacter maxLength: 1 usedLength: NULL encoding: NSISOLatin1StringEncoding
options: 0 range: picker remainingRange: NULL];

// LF -> CR
if (isoCharacter == 10) {
unicode = 13;
isoCharacter = 13;
}

evt.pressCode = EventKeyDown;
BOOL isUppercase = [[NSCharacterSet uppercaseLetterCharacterSet] characterIsMember: unicode];
evt.modifiers = isUppercase ? ShiftKeyBit : 0;
evt.charCode = [self figureOutKeyCode: unicode];

unsigned int keyCodeRemembered = evt.charCode;
// convert ascii code of command-shift-letter to upper case
if ((evt.modifiers & CommandKeyBit) && (evt.modifiers & ShiftKeyBit)
&& (unicode >= 97) && (unicode <= 122))
unicode = unicode - 32;

#if INCLUDE_UNICODE_IN_ALL_KEYBOARD_EVENTS || IUIAKE
evt.utf32Code = unicode;
#else
evt.utf32Code = 0;
#endif
evt.reserved1 = 0;
evt.windowIndex = 1;
[self pushEventToQueue: (sqInputEvent *)&evt];

evt.charCode = isoCharacter;

sqIntptr_t keyCodeRemembered = evt.charCode;
evt.charCode = isoCharacter;
evt.pressCode = EventKeyChar;
evt.modifiers = evt.modifiers;
if ((evt.modifiers & CommandKeyBit) && (evt.modifiers & ShiftKeyBit)) { /* command and shift */
if ((unicode >= 97) && (unicode <= 122)) {
/* convert ascii code of command-shift-letter to upper case */
unicode = unicode - 32;
}
}


evt.utf32Code = unicode;
evt.timeStamp++;
evt.timeStamp++;
[self pushEventToQueue: (sqInputEvent *) &evt];
if (YES) {
evt.pressCode = EventKeyUp;
evt.charCode = keyCodeRemembered;
#if INCLUDE_UNICODE_IN_ALL_KEYBOARD_EVENTS || IUIAKE
evt.utf32Code = unicode;
#else
evt.utf32Code = 0;
evt.timeStamp++;
#endif
evt.timeStamp++;
[self pushEventToQueue: (sqInputEvent *) &evt];
}
}

interpreterProxy->signalSemaphoreWithIndex(gDelegateApp.squeakApplication.inputSemaphoreIndex);

}

@end

0 comments on commit 0d706fc

Please sign in to comment.