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 <JavaNativeFoundation/JavaNativeFoundation.h>
27 #import <JavaRuntimeSupport/JavaRuntimeSupport.h>
28
29
30 #import "CMenu.h"
31 #import "CMenuBar.h"
32 #import "ThreadUtilities.h"
33
34 #import "sun_lwawt_macosx_CMenu.h"
35
36 @implementation CMenu
37
38 - (id)initWithPeer:(jobject)peer {
39 AWT_ASSERT_APPKIT_THREAD;
40 // Create the new NSMenu
41 self = [super initWithPeer:peer asSeparator:NO];
42 if (self) {
43 fMenu = [NSMenu javaMenuWithTitle:@""];
44 [fMenu retain];
45 [fMenu setAutoenablesItems:NO];
46 }
47 return self;
48 }
49
50 - (void)dealloc {
51 [fMenu release];
52 fMenu = nil;
142 }];
143
144 if (aCMenu == nil) {
145 return 0L;
146 }
147
148 return aCMenu;
149
150 }
151
152 /*
153 * Class: sun_lwawt_macosx_CMenu
154 * Method: nativeCreateSubMenu
155 * Signature: (J)J
156 */
157 JNIEXPORT jlong JNICALL
158 Java_sun_lwawt_macosx_CMenu_nativeCreateSubMenu
159 (JNIEnv *env, jobject peer, jlong parentMenu)
160 {
161 CMenu *aCMenu = nil;
162 JNF_COCOA_ENTER(env);
163
164 jobject cPeerObjGlobal = (*env)->NewGlobalRef(env, peer);
165
166 aCMenu = createCMenu (cPeerObjGlobal);
167
168 // Add it to the parent menu
169 [((CMenu *)jlong_to_ptr(parentMenu)) addJavaSubmenu: aCMenu];
170
171 JNF_COCOA_EXIT(env);
172
173 return ptr_to_jlong(aCMenu);
174 }
175
176
177
178 /*
179 * Class: sun_lwawt_macosx_CMenu
180 * Method: nativeCreateMenu
181 * Signature: (JZ)J
182 */
183 JNIEXPORT jlong JNICALL
184 Java_sun_lwawt_macosx_CMenu_nativeCreateMenu
185 (JNIEnv *env, jobject peer,
186 jlong parentMenuBar, jboolean isHelpMenu, jint insertLocation)
187 {
188 CMenu *aCMenu = nil;
189 CMenuBar *parent = (CMenuBar *)jlong_to_ptr(parentMenuBar);
190 JNF_COCOA_ENTER(env);
191
192 jobject cPeerObjGlobal = (*env)->NewGlobalRef(env, peer);
193
194 aCMenu = createCMenu (cPeerObjGlobal);
195
196 // Add it to the menu bar.
197 [parent javaAddMenu:aCMenu atIndex:insertLocation];
198
199 // If the menu is already the help menu (because we are creating an entire
200 // menu bar) we need to note that now, because we can't rely on
201 // setHelpMenu() being called again.
202 if (isHelpMenu == JNI_TRUE) {
203 [parent javaSetHelpMenu: aCMenu];
204 }
205
206 JNF_COCOA_EXIT(env);
207 return ptr_to_jlong(aCMenu);
208 }
209
210
211 /*
212 * Class: sun_lwawt_macosx_CMenu
213 * Method: nativeSetMenuTitle
214 * Signature: (JLjava/lang/String;)V
215 */
216 JNIEXPORT void JNICALL
217 Java_sun_lwawt_macosx_CMenu_nativeSetMenuTitle
218 (JNIEnv *env, jobject peer, jlong menuObject, jstring label)
219 {
220 JNF_COCOA_ENTER(env);
221 // Set the menu's title.
222 [((CMenu *)jlong_to_ptr(menuObject)) setJavaMenuTitle:JNFJavaToNSString(env, label)];
223 JNF_COCOA_EXIT(env);
224 }
225
226 /*
227 * Class: sun_lwawt_macosx_CMenu
228 * Method: nativeAddSeparator
229 * Signature: (J)V
230 */
231 JNIEXPORT void JNICALL
232 Java_sun_lwawt_macosx_CMenu_nativeAddSeparator
233 (JNIEnv *env, jobject peer, jlong menuObject)
234 {
235 JNF_COCOA_ENTER(env);
236 // Add a separator item.
237 [((CMenu *)jlong_to_ptr(menuObject))addSeparator];
238 JNF_COCOA_EXIT(env);
239 }
240
241 /*
242 * Class: sun_lwawt_macosx_CMenu
243 * Method: nativeDeleteItem
244 * Signature: (JI)V
245 */
246 JNIEXPORT void JNICALL
247 Java_sun_lwawt_macosx_CMenu_nativeDeleteItem
248 (JNIEnv *env, jobject peer, jlong menuObject, jint index)
249 {
250 JNF_COCOA_ENTER(env);
251 // Remove the specified item.
252 [((CMenu *)jlong_to_ptr(menuObject)) deleteJavaItem: index];
253 JNF_COCOA_EXIT(env);
254 }
255
256 /*
257 * Class: sun_lwawt_macosx_CMenu
258 * Method: nativeGetNSMenu
259 * Signature: (J)J
260 */
261 JNIEXPORT jlong JNICALL
262 Java_sun_lwawt_macosx_CMenu_nativeGetNSMenu
263 (JNIEnv *env, jobject peer, jlong menuObject)
264 {
265 NSMenu* nsMenu = NULL;
266
267 JNF_COCOA_ENTER(env);
268 // Strong retain this menu; it'll get released in Java_apple_laf_ScreenMenu_addMenuListeners
269 nsMenu = [[((CMenu *)jlong_to_ptr(menuObject)) menu] retain];
270 JNF_COCOA_EXIT(env);
271
272 return ptr_to_jlong(nsMenu);
273 }
|
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 <JavaRuntimeSupport/JavaRuntimeSupport.h>
27
28
29 #import "CMenu.h"
30 #import "CMenuBar.h"
31 #import "ThreadUtilities.h"
32 #import "JNIUtilities.h"
33
34 #import "sun_lwawt_macosx_CMenu.h"
35
36 @implementation CMenu
37
38 - (id)initWithPeer:(jobject)peer {
39 AWT_ASSERT_APPKIT_THREAD;
40 // Create the new NSMenu
41 self = [super initWithPeer:peer asSeparator:NO];
42 if (self) {
43 fMenu = [NSMenu javaMenuWithTitle:@""];
44 [fMenu retain];
45 [fMenu setAutoenablesItems:NO];
46 }
47 return self;
48 }
49
50 - (void)dealloc {
51 [fMenu release];
52 fMenu = nil;
142 }];
143
144 if (aCMenu == nil) {
145 return 0L;
146 }
147
148 return aCMenu;
149
150 }
151
152 /*
153 * Class: sun_lwawt_macosx_CMenu
154 * Method: nativeCreateSubMenu
155 * Signature: (J)J
156 */
157 JNIEXPORT jlong JNICALL
158 Java_sun_lwawt_macosx_CMenu_nativeCreateSubMenu
159 (JNIEnv *env, jobject peer, jlong parentMenu)
160 {
161 CMenu *aCMenu = nil;
162 JNI_COCOA_ENTER(env);
163
164 jobject cPeerObjGlobal = (*env)->NewGlobalRef(env, peer);
165
166 aCMenu = createCMenu (cPeerObjGlobal);
167
168 // Add it to the parent menu
169 [((CMenu *)jlong_to_ptr(parentMenu)) addJavaSubmenu: aCMenu];
170
171 JNI_COCOA_EXIT(env);
172
173 return ptr_to_jlong(aCMenu);
174 }
175
176
177
178 /*
179 * Class: sun_lwawt_macosx_CMenu
180 * Method: nativeCreateMenu
181 * Signature: (JZ)J
182 */
183 JNIEXPORT jlong JNICALL
184 Java_sun_lwawt_macosx_CMenu_nativeCreateMenu
185 (JNIEnv *env, jobject peer,
186 jlong parentMenuBar, jboolean isHelpMenu, jint insertLocation)
187 {
188 CMenu *aCMenu = nil;
189 CMenuBar *parent = (CMenuBar *)jlong_to_ptr(parentMenuBar);
190 JNI_COCOA_ENTER(env);
191
192 jobject cPeerObjGlobal = (*env)->NewGlobalRef(env, peer);
193
194 aCMenu = createCMenu (cPeerObjGlobal);
195
196 // Add it to the menu bar.
197 [parent javaAddMenu:aCMenu atIndex:insertLocation];
198
199 // If the menu is already the help menu (because we are creating an entire
200 // menu bar) we need to note that now, because we can't rely on
201 // setHelpMenu() being called again.
202 if (isHelpMenu == JNI_TRUE) {
203 [parent javaSetHelpMenu: aCMenu];
204 }
205
206 JNI_COCOA_EXIT(env);
207 return ptr_to_jlong(aCMenu);
208 }
209
210
211 /*
212 * Class: sun_lwawt_macosx_CMenu
213 * Method: nativeSetMenuTitle
214 * Signature: (JLjava/lang/String;)V
215 */
216 JNIEXPORT void JNICALL
217 Java_sun_lwawt_macosx_CMenu_nativeSetMenuTitle
218 (JNIEnv *env, jobject peer, jlong menuObject, jstring label)
219 {
220 JNI_COCOA_ENTER(env);
221 // Set the menu's title.
222 [((CMenu *)jlong_to_ptr(menuObject)) setJavaMenuTitle:JavaStringToNSString(env, label)];
223 JNI_COCOA_EXIT(env);
224 }
225
226 /*
227 * Class: sun_lwawt_macosx_CMenu
228 * Method: nativeAddSeparator
229 * Signature: (J)V
230 */
231 JNIEXPORT void JNICALL
232 Java_sun_lwawt_macosx_CMenu_nativeAddSeparator
233 (JNIEnv *env, jobject peer, jlong menuObject)
234 {
235 JNI_COCOA_ENTER(env);
236 // Add a separator item.
237 [((CMenu *)jlong_to_ptr(menuObject))addSeparator];
238 JNI_COCOA_EXIT(env);
239 }
240
241 /*
242 * Class: sun_lwawt_macosx_CMenu
243 * Method: nativeDeleteItem
244 * Signature: (JI)V
245 */
246 JNIEXPORT void JNICALL
247 Java_sun_lwawt_macosx_CMenu_nativeDeleteItem
248 (JNIEnv *env, jobject peer, jlong menuObject, jint index)
249 {
250 JNI_COCOA_ENTER(env);
251 // Remove the specified item.
252 [((CMenu *)jlong_to_ptr(menuObject)) deleteJavaItem: index];
253 JNI_COCOA_EXIT(env);
254 }
255
256 /*
257 * Class: sun_lwawt_macosx_CMenu
258 * Method: nativeGetNSMenu
259 * Signature: (J)J
260 */
261 JNIEXPORT jlong JNICALL
262 Java_sun_lwawt_macosx_CMenu_nativeGetNSMenu
263 (JNIEnv *env, jobject peer, jlong menuObject)
264 {
265 NSMenu* nsMenu = NULL;
266
267 JNI_COCOA_ENTER(env);
268 // Strong retain this menu; it'll get released in Java_apple_laf_ScreenMenu_addMenuListeners
269 nsMenu = [[((CMenu *)jlong_to_ptr(menuObject)) menu] retain];
270 JNI_COCOA_EXIT(env);
271
272 return ptr_to_jlong(nsMenu);
273 }
|