From 0cbed08aa9bf88b22dbc734be620addd4926c463 Mon Sep 17 00:00:00 2001 From: "jose.pereda" Date: Fri, 22 May 2020 13:35:59 +0200 Subject: [PATCH] Use iOS long press gesture to generate a menu event --- .../main/native-glass/ios/GlassApplication.m | 2 ++ .../main/native-glass/ios/GlassViewDelegate.m | 29 +++++++++++++++++++ .../src/main/native-glass/ios/common.h | 1 + 3 files changed, 32 insertions(+) diff --git a/modules/javafx.graphics/src/main/native-glass/ios/GlassApplication.m b/modules/javafx.graphics/src/main/native-glass/ios/GlassApplication.m index d8e0df80f2a..a2a41380b2d 100644 --- a/modules/javafx.graphics/src/main/native-glass/ios/GlassApplication.m +++ b/modules/javafx.graphics/src/main/native-glass/ios/GlassApplication.m @@ -62,6 +62,7 @@ jmethodID mat_jViewNotifyRepaint = 0; jmethodID mat_jViewNotifyKey = 0; jmethodID mat_jViewNotifyMouse = 0; +jmethodID mat_jViewNotifyMenu = 0; jmethodID mat_jViewNotifyInputMethod = 0; jmethodID mat_jViewNotifyView = 0; @@ -671,6 +672,7 @@ - (void)dealloc { mat_jViewNotifyResize = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyResize", "(II)V"); mat_jViewNotifyRepaint = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyRepaint", "(IIII)V"); mat_jViewNotifyMouse = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyMouse", "(IIIIIIIZZ)V"); + mat_jViewNotifyMenu = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyMenu", "(IIIIZ)V"); mat_jViewNotifyInputMethod = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyInputMethod", "(Ljava/lang/String;[I[I[BIII)V"); mat_jViewNotifyView = (*env)->GetMethodID(env, mat_jViewBaseClass, "notifyView", "(I)V"); GLASS_CHECK_EXCEPTION(env); diff --git a/modules/javafx.graphics/src/main/native-glass/ios/GlassViewDelegate.m b/modules/javafx.graphics/src/main/native-glass/ios/GlassViewDelegate.m index d0dc7ba2808..024a4a6b695 100644 --- a/modules/javafx.graphics/src/main/native-glass/ios/GlassViewDelegate.m +++ b/modules/javafx.graphics/src/main/native-glass/ios/GlassViewDelegate.m @@ -375,6 +375,19 @@ - (void)handleRotateGesture:(UIRotationGestureRecognizer*)sender { } +- (void)handleLongPressGesture:(UILongPressGestureRecognizer*)sender { + if (sender.state == UIGestureRecognizerStateBegan) { + // Simulate right-click + CGPoint viewPoint = [sender locationInView:self.uiView.superview]; + [self sendJavaMouseEvent:viewPoint type:com_sun_glass_events_MouseEvent_ENTER button:com_sun_glass_events_MouseEvent_BUTTON_NONE]; + [self sendJavaMouseEvent:viewPoint type:com_sun_glass_events_MouseEvent_DOWN button:com_sun_glass_events_MouseEvent_BUTTON_RIGHT]; + } else if (sender.state == UIGestureRecognizerStateEnded) { + // Prevent touch ended event + self.mouseTouch = nil; + } +} + + - (id)initWithView:(UIScrollView*)view withJview:(jobject)jview { self = [super init]; @@ -422,6 +435,15 @@ - (id)initWithView:(UIScrollView*)view withJview:(jobject)jview [panGestureRecognizer setCancelsTouchesInView:NO]; [panGestureRecognizer setDelaysTouchesBegan:NO]; [panGestureRecognizer setDelaysTouchesEnded:NO]; + //LongPress + UILongPressGestureRecognizer *longPressGesture = + [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGesture:)]; + [longPressGesture setCancelsTouchesInView:NO]; + [longPressGesture setDelaysTouchesEnded:NO]; + [longPressGesture setDelaysTouchesBegan:NO]; + [self.uiView addGestureRecognizer:longPressGesture]; + [longPressGesture setDelegate:ggDelegate]; + [longPressGesture release]; } return self; } @@ -551,6 +573,13 @@ - (void)sendJavaMouseEvent:(CGPoint)viewPoint type:(int)type button:(int)button (jint)viewPoint.x, (jint)viewPoint.y, (jint)viewPoint.x, (jint)viewPoint.y, modifiers, isPopupTrigger, isSynthesized); GLASS_CHECK_EXCEPTION(env); + + if (isPopupTrigger) { + jboolean isKeyboardTrigger = JNI_FALSE; + (*env)->CallVoidMethod(env, self.jView, mat_jViewNotifyMenu, + (jint)viewPoint.x, (jint)viewPoint.y, (jint)viewPoint.x, (jint)viewPoint.y, isKeyboardTrigger); + GLASS_CHECK_EXCEPTION(env); + } } diff --git a/modules/javafx.graphics/src/main/native-glass/ios/common.h b/modules/javafx.graphics/src/main/native-glass/ios/common.h index 70153aeb9f4..282fbc57e28 100644 --- a/modules/javafx.graphics/src/main/native-glass/ios/common.h +++ b/modules/javafx.graphics/src/main/native-glass/ios/common.h @@ -53,6 +53,7 @@ extern jmethodID mat_jViewNotifyResize; extern jmethodID mat_jViewNotifyRepaint; extern jmethodID mat_jViewNotifyKey; extern jmethodID mat_jViewNotifyMouse; +extern jmethodID mat_jViewNotifyMenu; extern jmethodID mat_jViewNotifyInputMethod; extern jmethodID mat_jViewNotifyView;