1 /*
2 * Copyright (c) 1996, 2014, 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
200 /*
201 * Link the C++, Java peer together
202 */
203 void AwtMenuItem::LinkObjects(JNIEnv *env, jobject peer)
204 {
205 m_peerObject = env->NewGlobalRef(peer);
206 JNI_SET_PDATA(peer, this);
207 }
208
209 AwtMenuItem* AwtMenuItem::Create(jobject peer, jobject menuPeer)
210 {
211 JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
212
213 jobject target = NULL;
214 AwtMenuItem* item = NULL;
215
216 try {
217 if (env->EnsureLocalCapacity(1) < 0) {
218 return NULL;
219 }
220 JNI_CHECK_NULL_RETURN_NULL(menuPeer, "peer");
221
222 /* target is a java.awt.MenuItem */
223 target = env->GetObjectField(peer, AwtObject::targetID);
224
225 AwtMenu* menu = (AwtMenu *)JNI_GET_PDATA(menuPeer);
226 item = new AwtMenuItem();
227 jboolean isCheckbox =
228 (jboolean)env->GetBooleanField(peer, AwtMenuItem::isCheckboxID);
229 if (isCheckbox) {
230 item->SetCheckbox();
231 }
232
233 item->LinkObjects(env, peer);
234 item->SetMenuContainer(menu);
235 item->SetNewID();
236 if (menu != NULL) {
237 menu->AddItem(item);
238 }
239 } catch (...) {
|
1 /*
2 * Copyright (c) 1996, 2017, 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
200 /*
201 * Link the C++, Java peer together
202 */
203 void AwtMenuItem::LinkObjects(JNIEnv *env, jobject peer)
204 {
205 m_peerObject = env->NewGlobalRef(peer);
206 JNI_SET_PDATA(peer, this);
207 }
208
209 AwtMenuItem* AwtMenuItem::Create(jobject peer, jobject menuPeer)
210 {
211 JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
212
213 jobject target = NULL;
214 AwtMenuItem* item = NULL;
215
216 try {
217 if (env->EnsureLocalCapacity(1) < 0) {
218 return NULL;
219 }
220 if (!AwtToolkit::GetInstance().isFreeIDAvailable()) {
221 return NULL;
222 }
223
224 JNI_CHECK_NULL_RETURN_NULL(menuPeer, "peer");
225
226 /* target is a java.awt.MenuItem */
227 target = env->GetObjectField(peer, AwtObject::targetID);
228
229 AwtMenu* menu = (AwtMenu *)JNI_GET_PDATA(menuPeer);
230 item = new AwtMenuItem();
231 jboolean isCheckbox =
232 (jboolean)env->GetBooleanField(peer, AwtMenuItem::isCheckboxID);
233 if (isCheckbox) {
234 item->SetCheckbox();
235 }
236
237 item->LinkObjects(env, peer);
238 item->SetMenuContainer(menu);
239 item->SetNewID();
240 if (menu != NULL) {
241 menu->AddItem(item);
242 }
243 } catch (...) {
|