# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1626598452 0 # Node ID da51be03659908e2227140f97bf53297688f625f # Parent 1ee59f231f6c65c10b44a080c755bc0a32002813 iOS: Implement button press/release and motion notify. We do this overriding touchesBegan, touchesEnded and touchesMoved methods respectively. A long touch on a supported widget will generate a button 2 event, any other will generate a button 1. Motion isn't supported without a touch, so there will always be a button masked. diff -r 1ee59f231f6c -r da51be036599 ios/dw.m --- a/ios/dw.m Sat Jul 17 01:24:03 2021 +0000 +++ b/ios/dw.m Sun Jul 18 08:54:12 2021 +0000 @@ -409,19 +409,29 @@ case 4: { int (* API buttonfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; - int button = 1; + /* Event will be nil when handling the context menu events... + * So button should default to 2 if event is nil + */ + int button = event ? 1 : 2; CGPoint p = _dw_event_point; - if(event && [event isMemberOfClass:[UIEvent class]]) + if(event && [event isKindOfClass:[UIEvent class]]) { - UITouch *touch = [[event allTouches] anyObject]; - - p = [touch locationInView:[touch view]]; - - if(@available(ios 13.4, *)) + NSSet *touches = [event allTouches]; + + for(id touch in touches) { - if([event buttonMask] & UIEventButtonMaskSecondary) - button = 2; + if((message == 3 && [touch phase] == UITouchPhaseBegan) || + (message == 4 && [touch phase] == UITouchPhaseEnded)) + { + p = [touch locationInView:[touch view]]; + + if(@available(ios 13.4, *)) + { + if([event buttonMask] & UIEventButtonMaskSecondary) + button = 2; + } + } } } @@ -430,11 +440,23 @@ /* Motion notify event */ case 5: { -#if 0 /* TODO: See if this can be replicated with gestures/swipes */ int (* API motionfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; - - return motionfunc(object, (int)p.x, (int)p.y, (int)buttonmask, handler->data); -#endif + int button = 1; + + if(event && [event isKindOfClass:[UIEvent class]]) + { + NSSet *touches = [event allTouches]; + + for(id touch in touches) + { + if([touch phase] == UITouchPhaseMoved) + { + CGPoint p = [touch locationInView:[touch view]]; + + return motionfunc(object, (int)p.x, (int)p.y, button, handler->data); + } + } + } return -1; } /* Window close event */ @@ -859,6 +881,21 @@ } } -(void)keyDown:(UIKey *)key API_AVAILABLE(ios(13.4)){ _dw_event_handler(self, key, 2); } +-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event +{ + _dw_event_handler(self, event, 3); + [super touchesBegan:touches withEvent:event]; +} +-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event +{ + _dw_event_handler(self, event, 4); + [super touchesEnded:touches withEvent:event]; +} +-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event +{ + _dw_event_handler(self, event, 5); + [super touchesMoved:touches withEvent:event]; +} -(UIContextMenuConfiguration *)contextMenuInteraction:(UIContextMenuInteraction *)interaction configurationForMenuAtLocation:(CGPoint)location { DWWindow *window = (DWWindow *)[self window];