comparison ios/dw.m @ 2610:da51be036599

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.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 18 Jul 2021 08:54:12 +0000
parents 6c30fcc79402
children 4628c8c34125
comparison
equal deleted inserted replaced
2609:1ee59f231f6c 2610:da51be036599
407 /* Button press and release event */ 407 /* Button press and release event */
408 case 3: 408 case 3:
409 case 4: 409 case 4:
410 { 410 {
411 int (* API buttonfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; 411 int (* API buttonfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction;
412 int button = 1; 412 /* Event will be nil when handling the context menu events...
413 * So button should default to 2 if event is nil
414 */
415 int button = event ? 1 : 2;
413 CGPoint p = _dw_event_point; 416 CGPoint p = _dw_event_point;
414 417
415 if(event && [event isMemberOfClass:[UIEvent class]]) 418 if(event && [event isKindOfClass:[UIEvent class]])
416 { 419 {
417 UITouch *touch = [[event allTouches] anyObject]; 420 NSSet *touches = [event allTouches];
418 421
419 p = [touch locationInView:[touch view]]; 422 for(id touch in touches)
420
421 if(@available(ios 13.4, *))
422 { 423 {
423 if([event buttonMask] & UIEventButtonMaskSecondary) 424 if((message == 3 && [touch phase] == UITouchPhaseBegan) ||
424 button = 2; 425 (message == 4 && [touch phase] == UITouchPhaseEnded))
426 {
427 p = [touch locationInView:[touch view]];
428
429 if(@available(ios 13.4, *))
430 {
431 if([event buttonMask] & UIEventButtonMaskSecondary)
432 button = 2;
433 }
434 }
425 } 435 }
426 } 436 }
427 437
428 return buttonfunc(object, (int)p.x, (int)p.y, button, handler->data); 438 return buttonfunc(object, (int)p.x, (int)p.y, button, handler->data);
429 } 439 }
430 /* Motion notify event */ 440 /* Motion notify event */
431 case 5: 441 case 5:
432 { 442 {
433 #if 0 /* TODO: See if this can be replicated with gestures/swipes */
434 int (* API motionfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; 443 int (* API motionfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction;
435 444 int button = 1;
436 return motionfunc(object, (int)p.x, (int)p.y, (int)buttonmask, handler->data); 445
437 #endif 446 if(event && [event isKindOfClass:[UIEvent class]])
447 {
448 NSSet *touches = [event allTouches];
449
450 for(id touch in touches)
451 {
452 if([touch phase] == UITouchPhaseMoved)
453 {
454 CGPoint p = [touch locationInView:[touch view]];
455
456 return motionfunc(object, (int)p.x, (int)p.y, button, handler->data);
457 }
458 }
459 }
438 return -1; 460 return -1;
439 } 461 }
440 /* Window close event */ 462 /* Window close event */
441 case 6: 463 case 6:
442 { 464 {
857 [_DWDirtyDrawables removeObject:self]; 879 [_DWDirtyDrawables removeObject:self];
858 [self setNeedsDisplay]; 880 [self setNeedsDisplay];
859 } 881 }
860 } 882 }
861 -(void)keyDown:(UIKey *)key API_AVAILABLE(ios(13.4)){ _dw_event_handler(self, key, 2); } 883 -(void)keyDown:(UIKey *)key API_AVAILABLE(ios(13.4)){ _dw_event_handler(self, key, 2); }
884 -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
885 {
886 _dw_event_handler(self, event, 3);
887 [super touchesBegan:touches withEvent:event];
888 }
889 -(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
890 {
891 _dw_event_handler(self, event, 4);
892 [super touchesEnded:touches withEvent:event];
893 }
894 -(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
895 {
896 _dw_event_handler(self, event, 5);
897 [super touchesMoved:touches withEvent:event];
898 }
862 -(UIContextMenuConfiguration *)contextMenuInteraction:(UIContextMenuInteraction *)interaction configurationForMenuAtLocation:(CGPoint)location 899 -(UIContextMenuConfiguration *)contextMenuInteraction:(UIContextMenuInteraction *)interaction configurationForMenuAtLocation:(CGPoint)location
863 { 900 {
864 DWWindow *window = (DWWindow *)[self window]; 901 DWWindow *window = (DWWindow *)[self window];
865 UIContextMenuConfiguration *config = nil; 902 UIContextMenuConfiguration *config = nil;
866 903