1 /*
2 * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 #import "JavaAccessibilityAction.h"
27 #import "JavaAccessibilityUtilities.h"
28
29 #import "ThreadUtilities.h"
30
31
32 @implementation JavaAxAction
33
34 - (id)initWithEnv:(JNIEnv *)env withAccessibleAction:(jobject)accessibleAction withIndex:(jint)index withComponent:(jobject)component
35 {
36 self = [super init];
37 if (self) {
38 fAccessibleAction = JNFNewWeakGlobalRef(env, accessibleAction);
39 fIndex = index;
40 fComponent = JNFNewWeakGlobalRef(env, component);
41 }
42 return self;
43 }
44
45 - (void)dealloc
46 {
47 JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
48
49 JNFDeleteWeakGlobalRef(env, fAccessibleAction);
50 fAccessibleAction = NULL;
51
52 JNFDeleteWeakGlobalRef(env, fComponent);
53 fComponent = NULL;
54
55 [super dealloc];
56 }
57
58 - (NSString *)getDescription
59 {
60 static JNF_STATIC_MEMBER_CACHE(jm_getAccessibleActionDescription, sjc_CAccessibility, "getAccessibleActionDescription", "(Ljavax/accessibility/AccessibleAction;ILjava/awt/Component;)Ljava/lang/String;");
61
62 JNIEnv* env = [ThreadUtilities getJNIEnv];
63
64 jobject fCompLocal = (*env)->NewLocalRef(env, fComponent);
65 if ((*env)->IsSameObject(env, fCompLocal, NULL)) {
66 return nil;
67 }
68 NSString *str = nil;
69 jstring jstr = JNFCallStaticObjectMethod( env,
70 jm_getAccessibleActionDescription,
71 fAccessibleAction,
72 fIndex,
73 fCompLocal );
74 if (jstr != NULL) {
75 str = JNFJavaToNSString(env, jstr); // AWT_THREADING Safe (AWTRunLoopMode)
76 (*env)->DeleteLocalRef(env, jstr);
77 }
78 (*env)->DeleteLocalRef(env, fCompLocal);
79 return str;
80 }
81
82 - (void)perform
83 {
84 static JNF_STATIC_MEMBER_CACHE(jm_doAccessibleAction, sjc_CAccessibility, "doAccessibleAction", "(Ljavax/accessibility/AccessibleAction;ILjava/awt/Component;)V");
85
86 JNIEnv* env = [ThreadUtilities getJNIEnv];
87
88 JNFCallStaticVoidMethod(env, jm_doAccessibleAction, fAccessibleAction, fIndex, fComponent); // AWT_THREADING Safe (AWTRunLoopMode)
89 }
90
91 @end
92
93
94 @implementation TabGroupAction
95
96 - (id)initWithEnv:(JNIEnv *)env withTabGroup:(jobject)tabGroup withIndex:(jint)index withComponent:(jobject)component
97 {
98 self = [super init];
99 if (self) {
100 fTabGroup = JNFNewWeakGlobalRef(env, tabGroup);
101 fIndex = index;
102 fComponent = JNFNewWeakGlobalRef(env, component);
103 }
104 return self;
105 }
106
107 - (void)dealloc
108 {
109 JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
110
111 JNFDeleteWeakGlobalRef(env, fTabGroup);
112 fTabGroup = NULL;
113
114 JNFDeleteWeakGlobalRef(env, fComponent);
115 fComponent = NULL;
116
117 [super dealloc];
118 }
119
120 - (NSString *)getDescription
121 {
122 return @"click";
123 }
124
125 - (void)perform
126 {
127 JNIEnv* env = [ThreadUtilities getJNIEnv];
128
129 setAxContextSelection(env, fTabGroup, fIndex, fComponent);
130 }
131
132 @end
|
1 /*
2 * Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 #import "JavaAccessibilityAction.h"
27 #import "JavaAccessibilityUtilities.h"
28
29 #import "ThreadUtilities.h"
30 #import "JNIUtilities.h"
31
32
33 @implementation JavaAxAction
34
35 - (id)initWithEnv:(JNIEnv *)env withAccessibleAction:(jobject)accessibleAction withIndex:(jint)index withComponent:(jobject)component
36 {
37 self = [super init];
38 if (self) {
39 fAccessibleAction = (*env)->NewWeakGlobalRef(env, accessibleAction);
40 CHECK_EXCEPTION();
41 fIndex = index;
42 fComponent = (*env)->NewWeakGlobalRef(env, component);
43 CHECK_EXCEPTION();
44 }
45 return self;
46 }
47
48 - (void)dealloc
49 {
50 JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
51
52 (*env)->DeleteWeakGlobalRef(env, fAccessibleAction);
53 fAccessibleAction = NULL;
54
55 (*env)->DeleteWeakGlobalRef(env, fComponent);
56 fComponent = NULL;
57
58 [super dealloc];
59 }
60
61 - (NSString *)getDescription
62 {
63 JNIEnv* env = [ThreadUtilities getJNIEnv];
64 DECLARE_CLASS_RETURN(sjc_CAccessibility, "sun/lwawt/macosx/CAccessibility", nil);
65 DECLARE_STATIC_METHOD_RETURN(jm_getAccessibleActionDescription, sjc_CAccessibility,
66 "getAccessibleActionDescription",
67 "(Ljavax/accessibility/AccessibleAction;ILjava/awt/Component;)Ljava/lang/String;", nil);
68
69 /* WeakGlobalRefs can be cleared at any time, so first get strong local refs and use those */
70 jobject fCompLocal = (*env)->NewLocalRef(env, fComponent);
71 if ((*env)->IsSameObject(env, fCompLocal, NULL)) {
72 return nil;
73 }
74 jobject fAccessibleActionLocal = (*env)->NewLocalRef(env, fAccessibleAction);
75 if ((*env)->IsSameObject(env, fAccessibleActionLocal, NULL)) {
76 (*env)->DeleteLocalRef(env, fCompLocal);
77 return nil;
78 }
79 NSString *str = nil;
80 jstring jstr = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility,
81 jm_getAccessibleActionDescription,
82 fAccessibleActionLocal,
83 fIndex,
84 fCompLocal );
85 CHECK_EXCEPTION();
86 if (jstr != NULL) {
87 str = JavaStringToNSString(env, jstr);
88 (*env)->DeleteLocalRef(env, jstr);
89 }
90 (*env)->DeleteLocalRef(env, fCompLocal);
91 (*env)->DeleteLocalRef(env, fAccessibleActionLocal);
92 return str;
93 }
94
95 - (void)perform
96 {
97 JNIEnv* env = [ThreadUtilities getJNIEnv];
98 DECLARE_CLASS(sjc_CAccessibility, "sun/lwawt/macosx/CAccessibility");
99 DECLARE_STATIC_METHOD(jm_doAccessibleAction, sjc_CAccessibility, "doAccessibleAction",
100 "(Ljavax/accessibility/AccessibleAction;ILjava/awt/Component;)V");
101
102 (*env)->CallStaticVoidMethod(env, sjc_CAccessibility, jm_doAccessibleAction,
103 fAccessibleAction, fIndex, fComponent);
104 CHECK_EXCEPTION();
105 }
106
107 @end
108
109
110 @implementation TabGroupAction
111
112 - (id)initWithEnv:(JNIEnv *)env withTabGroup:(jobject)tabGroup withIndex:(jint)index withComponent:(jobject)component
113 {
114 self = [super init];
115 if (self) {
116 fTabGroup = (*env)->NewWeakGlobalRef(env, tabGroup);
117 CHECK_EXCEPTION();
118 fIndex = index;
119 fComponent = (*env)->NewWeakGlobalRef(env, component);
120 CHECK_EXCEPTION();
121 }
122 return self;
123 }
124
125 - (void)dealloc
126 {
127 JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
128
129 (*env)->DeleteWeakGlobalRef(env, fTabGroup);
130 fTabGroup = NULL;
131
132 (*env)->DeleteWeakGlobalRef(env, fComponent);
133 fComponent = NULL;
134
135 [super dealloc];
136 }
137
138 - (NSString *)getDescription
139 {
140 return @"click";
141 }
142
143 - (void)perform
144 {
145 JNIEnv* env = [ThreadUtilities getJNIEnv];
146
147 setAxContextSelection(env, fTabGroup, fIndex, fComponent);
148 }
149
150 @end
|