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