author | leonidr |
Mon, 17 Sep 2012 17:25:54 +0400 | |
changeset 13781 | bf3d53b1fba7 |
parent 12283 | 253d9a09f674 |
child 14312 | 310bfcd9c932 |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
2 |
* Copyright (c) 2011, 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 <JavaNativeFoundation/JavaNativeFoundation.h> |
|
27 |
||
28 |
#import "CMenuItem.h" |
|
29 |
#import "CMenu.h" |
|
30 |
#import "AWTEvent.h" |
|
31 |
#import "ThreadUtilities.h" |
|
32 |
||
33 |
#import "java_awt_Event.h" |
|
34 |
#import "java_awt_event_KeyEvent.h" |
|
35 |
#import "sun_lwawt_macosx_CMenuItem.h" |
|
36 |
||
37 |
#define NOT_A_CHECKBOXMENU -2 |
|
38 |
||
39 |
||
40 |
@implementation CMenuItem |
|
41 |
||
42 |
- (id) initWithPeer:(jobject)peer asSeparator: (NSNumber *) asSeparator{ |
|
43 |
AWT_ASSERT_APPKIT_THREAD; |
|
44 |
self = [super initWithPeer:peer]; |
|
45 |
if (self) { |
|
46 |
if ([asSeparator boolValue]) { |
|
47 |
fMenuItem = (NSMenuItem*)[NSMenuItem separatorItem]; |
|
48 |
[fMenuItem retain]; |
|
49 |
} else { |
|
50 |
fMenuItem = [[NSMenuItem alloc] init]; |
|
51 |
[fMenuItem setAction:@selector(handleAction:)]; |
|
52 |
[fMenuItem setTarget:self]; |
|
53 |
} |
|
54 |
fIsCheckbox = NO; |
|
55 |
fIsEnabled = YES; |
|
56 |
} |
|
57 |
return self; |
|
58 |
} |
|
59 |
||
60 |
// This is because NSApplication doesn't check the target's window when sending |
|
61 |
// actions; they only check the target itself. We always return YES, |
|
62 |
// since we shouldn't even be installed unless our window is active. |
|
63 |
- (BOOL) worksWhenModal { |
|
64 |
return YES; |
|
65 |
} |
|
66 |
||
67 |
// Events |
|
68 |
- (void)handleAction:(NSMenuItem *)sender { |
|
69 |
AWT_ASSERT_APPKIT_THREAD; |
|
70 |
JNIEnv *env = [ThreadUtilities getJNIEnv]; |
|
71 |
JNF_COCOA_ENTER(env); |
|
72 |
||
13781
bf3d53b1fba7
7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents:
12283
diff
changeset
|
73 |
// If we are called as a result of user pressing a shorcut, do nothing, |
bf3d53b1fba7
7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents:
12283
diff
changeset
|
74 |
// because AVTView has already sent corresponding key event to the Java |
bf3d53b1fba7
7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents:
12283
diff
changeset
|
75 |
// layer from performKeyEquivalent |
bf3d53b1fba7
7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents:
12283
diff
changeset
|
76 |
NSEvent *currEvent = [[NSApplication sharedApplication] currentEvent]; |
bf3d53b1fba7
7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents:
12283
diff
changeset
|
77 |
if ([currEvent type] == NSKeyDown) { |
bf3d53b1fba7
7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents:
12283
diff
changeset
|
78 |
NSString *menuKey = [sender keyEquivalent]; |
bf3d53b1fba7
7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents:
12283
diff
changeset
|
79 |
NSString *eventKey = [currEvent characters]; |
bf3d53b1fba7
7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents:
12283
diff
changeset
|
80 |
if ([menuKey isEqualToString:eventKey]) { |
bf3d53b1fba7
7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents:
12283
diff
changeset
|
81 |
return; |
bf3d53b1fba7
7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents:
12283
diff
changeset
|
82 |
} |
bf3d53b1fba7
7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents:
12283
diff
changeset
|
83 |
} |
bf3d53b1fba7
7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents:
12283
diff
changeset
|
84 |
|
12047 | 85 |
if (fIsCheckbox) { |
86 |
static JNF_CLASS_CACHE(jc_CCheckboxMenuItem, "sun/lwawt/macosx/CCheckboxMenuItem"); |
|
87 |
static JNF_MEMBER_CACHE(jm_ckHandleAction, jc_CCheckboxMenuItem, "handleAction", "(Z)V"); |
|
88 |
||
89 |
// Send the opposite of what's currently checked -- the action |
|
90 |
// indicates what state we're going to. |
|
91 |
NSInteger state = [sender state]; |
|
92 |
jboolean newState = (state == NSOnState ? JNI_FALSE : JNI_TRUE); |
|
93 |
JNFCallVoidMethod(env, fPeer, jm_ckHandleAction, newState); |
|
94 |
} else { |
|
95 |
static JNF_CLASS_CACHE(jc_CMenuItem, "sun/lwawt/macosx/CMenuItem"); |
|
96 |
static JNF_MEMBER_CACHE(jm_handleAction, jc_CMenuItem, "handleAction", "(JI)V"); // AWT_THREADING Safe (event) |
|
97 |
||
98 |
NSUInteger modifiers = [currEvent modifierFlags]; |
|
13781
bf3d53b1fba7
7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents:
12283
diff
changeset
|
99 |
jint javaModifiers = NsKeyModifiersToJavaModifiers(modifiers, NO); |
12047 | 100 |
|
101 |
JNFCallVoidMethod(env, fPeer, jm_handleAction, UTC(currEvent), javaModifiers); // AWT_THREADING Safe (event) |
|
102 |
} |
|
103 |
JNF_COCOA_EXIT(env); |
|
104 |
} |
|
105 |
||
106 |
- (void) setJavaLabel:(NSString *)theLabel shortcut:(NSString *)theKeyEquivalent modifierMask:(jint)modifiers { |
|
107 |
AWT_ASSERT_NOT_APPKIT_THREAD; |
|
108 |
||
109 |
NSUInteger modifierMask = 0; |
|
110 |
||
111 |
if (![theKeyEquivalent isEqualToString:@""]) { |
|
112 |
// Force the key equivalent to lower case if not using the shift key. |
|
113 |
// Otherwise AppKit will draw a Shift glyph in the menu. |
|
114 |
if ((modifiers & java_awt_event_KeyEvent_SHIFT_MASK) == 0) { |
|
115 |
theKeyEquivalent = [theKeyEquivalent lowercaseString]; |
|
116 |
} |
|
117 |
||
118 |
// Hack for the question mark -- SHIFT and / means use the question mark. |
|
119 |
if ((modifiers & java_awt_event_KeyEvent_SHIFT_MASK) != 0 && |
|
120 |
[theKeyEquivalent isEqualToString:@"/"]) |
|
121 |
{ |
|
122 |
theKeyEquivalent = @"?"; |
|
123 |
modifiers &= ~java_awt_event_KeyEvent_SHIFT_MASK; |
|
124 |
} |
|
125 |
||
13781
bf3d53b1fba7
7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
leonidr
parents:
12283
diff
changeset
|
126 |
modifierMask = JavaModifiersToNsKeyModifiers(modifiers, NO); |
12047 | 127 |
} |
128 |
||
129 |
[JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ |
|
130 |
AWT_ASSERT_APPKIT_THREAD; |
|
12283
253d9a09f674
7124551: [macosx] Once added, Menu shortcut cannot be removed
serb
parents:
12047
diff
changeset
|
131 |
[fMenuItem setKeyEquivalent:theKeyEquivalent]; |
253d9a09f674
7124551: [macosx] Once added, Menu shortcut cannot be removed
serb
parents:
12047
diff
changeset
|
132 |
[fMenuItem setKeyEquivalentModifierMask:modifierMask]; |
12047 | 133 |
[fMenuItem setTitle:theLabel]; |
134 |
}]; |
|
135 |
} |
|
136 |
||
137 |
- (void) setJavaImage:(NSImage *)theImage { |
|
138 |
AWT_ASSERT_NOT_APPKIT_THREAD; |
|
139 |
||
140 |
[JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ |
|
141 |
AWT_ASSERT_APPKIT_THREAD; |
|
142 |
||
143 |
[fMenuItem setImage:theImage]; |
|
144 |
}]; |
|
145 |
} |
|
146 |
||
147 |
- (void) setJavaToolTipText:(NSString *)theText { |
|
148 |
AWT_ASSERT_NOT_APPKIT_THREAD; |
|
149 |
||
150 |
[JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ |
|
151 |
AWT_ASSERT_APPKIT_THREAD; |
|
152 |
||
153 |
[fMenuItem setToolTip:theText]; |
|
154 |
}]; |
|
155 |
} |
|
156 |
||
157 |
||
158 |
- (void)setJavaEnabled:(BOOL) enabled { |
|
159 |
AWT_ASSERT_NOT_APPKIT_THREAD; |
|
160 |
||
161 |
[JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ |
|
162 |
AWT_ASSERT_APPKIT_THREAD; |
|
163 |
||
164 |
@synchronized(self) { |
|
165 |
fIsEnabled = enabled; |
|
166 |
||
167 |
// Warning: This won't work if the parent menu is disabled. |
|
168 |
// See [CMenu syncFromJava]. We still need to call it here so |
|
169 |
// the NSMenuItem itself gets properly updated. |
|
170 |
[fMenuItem setEnabled:fIsEnabled]; |
|
171 |
} |
|
172 |
}]; |
|
173 |
} |
|
174 |
||
175 |
- (BOOL)isEnabled { |
|
176 |
// AWT_ASSERT_ANY_THREAD; |
|
177 |
||
178 |
BOOL enabled = NO; |
|
179 |
@synchronized(self) { |
|
180 |
enabled = fIsEnabled; |
|
181 |
} |
|
182 |
return enabled; |
|
183 |
} |
|
184 |
||
185 |
||
186 |
- (void)setJavaState:(BOOL)newState { |
|
187 |
AWT_ASSERT_NOT_APPKIT_THREAD; |
|
188 |
||
189 |
[JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ |
|
190 |
AWT_ASSERT_APPKIT_THREAD; |
|
191 |
||
192 |
[fMenuItem setState:(newState ? NSOnState : NSOffState)]; |
|
193 |
}]; |
|
194 |
} |
|
195 |
||
196 |
- (void)cleanup { |
|
197 |
[fMenuItem setAction:NULL]; |
|
198 |
[fMenuItem setTarget:nil]; |
|
199 |
} |
|
200 |
||
201 |
- (void)dealloc { |
|
202 |
[fMenuItem release]; |
|
203 |
fMenuItem = nil; |
|
204 |
||
205 |
[super dealloc]; |
|
206 |
} |
|
207 |
||
208 |
- (void)addNSMenuItemToMenu:(NSMenu *)inMenu { |
|
209 |
[inMenu addItem:fMenuItem]; |
|
210 |
} |
|
211 |
||
212 |
- (NSMenuItem *)menuItem { |
|
213 |
return [[fMenuItem retain] autorelease]; |
|
214 |
} |
|
215 |
||
216 |
- (void)setIsCheckbox { |
|
217 |
fIsCheckbox = YES; |
|
218 |
} |
|
219 |
||
220 |
- (void) _createMenuItem_OnAppKitThread: (NSMutableArray *)argValue { |
|
221 |
jobject cPeerObjGlobal = (jobject)[[argValue objectAtIndex: 0] pointerValue]; |
|
222 |
NSNumber * asSeparator = (NSNumber *)[argValue objectAtIndex: 1]; |
|
223 |
CMenuItem *aCMenuItem = [self initWithPeer: cPeerObjGlobal asSeparator: asSeparator]; |
|
224 |
[argValue removeAllObjects]; |
|
225 |
[argValue addObject: aCMenuItem]; |
|
226 |
} |
|
227 |
||
228 |
- (NSString *)description { |
|
229 |
return [NSString stringWithFormat:@"CMenuItem[ %@ ]", fMenuItem]; |
|
230 |
} |
|
231 |
||
232 |
@end |
|
233 |
||
234 |
/** Convert a Java keycode for SetMenuItemCmd */ |
|
235 |
static unichar AWTKeyToMacShortcut(jint awtKey, BOOL doShift) { |
|
236 |
unichar macKey = 0; |
|
237 |
||
238 |
if ((awtKey >= java_awt_event_KeyEvent_VK_0 && awtKey <= java_awt_event_KeyEvent_VK_9) || |
|
239 |
(awtKey >= java_awt_event_KeyEvent_VK_A && awtKey <= java_awt_event_KeyEvent_VK_Z)) |
|
240 |
{ |
|
241 |
// These ranges are the same in ASCII |
|
242 |
macKey = awtKey; |
|
243 |
} else if (awtKey >= java_awt_event_KeyEvent_VK_F1 && awtKey <= java_awt_event_KeyEvent_VK_F12) { |
|
244 |
// Support for F1 - F12 has been around since Java 1.0 and fall into a lower range. |
|
245 |
macKey = awtKey - java_awt_event_KeyEvent_VK_F1 + NSF1FunctionKey; |
|
246 |
} else if (awtKey >= java_awt_event_KeyEvent_VK_F13 && awtKey <= java_awt_event_KeyEvent_VK_F24) { |
|
247 |
// Support for F13-F24 came in Java 1.2 and are at a different range. |
|
248 |
macKey = awtKey - java_awt_event_KeyEvent_VK_F13 + NSF13FunctionKey; |
|
249 |
} else { |
|
250 |
// Special characters |
|
251 |
switch (awtKey) { |
|
252 |
case java_awt_event_KeyEvent_VK_BACK_QUOTE : macKey = '`'; break; |
|
253 |
case java_awt_event_KeyEvent_VK_QUOTE : macKey = '\''; break; |
|
254 |
||
255 |
case java_awt_event_KeyEvent_VK_ESCAPE : macKey = 0x1B; break; |
|
256 |
// case java_awt_event_KeyEvent_VK_SPACE : macKey = kMenuSpaceGlyph; break; |
|
257 |
case java_awt_event_KeyEvent_VK_PAGE_UP : macKey = NSPageUpFunctionKey; break; |
|
258 |
case java_awt_event_KeyEvent_VK_PAGE_DOWN : macKey = NSPageDownFunctionKey; break; |
|
259 |
case java_awt_event_KeyEvent_VK_END : macKey = NSEndFunctionKey; break; |
|
260 |
case java_awt_event_KeyEvent_VK_HOME : macKey = NSHomeFunctionKey; break; |
|
261 |
||
262 |
case java_awt_event_KeyEvent_VK_LEFT : macKey = NSLeftArrowFunctionKey; break; |
|
263 |
case java_awt_event_KeyEvent_VK_UP : macKey = NSUpArrowFunctionKey; break; |
|
264 |
case java_awt_event_KeyEvent_VK_RIGHT : macKey = NSRightArrowFunctionKey; break; |
|
265 |
case java_awt_event_KeyEvent_VK_DOWN : macKey = NSDownArrowFunctionKey; break; |
|
266 |
||
267 |
case java_awt_event_KeyEvent_VK_COMMA : macKey = ','; break; |
|
268 |
||
269 |
// Mac OS doesn't distinguish between the two '-' keys... |
|
270 |
case java_awt_event_KeyEvent_VK_MINUS : |
|
271 |
case java_awt_event_KeyEvent_VK_SUBTRACT : macKey = '-'; break; |
|
272 |
||
273 |
// or the two '.' keys... |
|
274 |
case java_awt_event_KeyEvent_VK_DECIMAL : |
|
275 |
case java_awt_event_KeyEvent_VK_PERIOD : macKey = '.'; break; |
|
276 |
||
277 |
// or the two '/' keys. |
|
278 |
case java_awt_event_KeyEvent_VK_DIVIDE : |
|
279 |
case java_awt_event_KeyEvent_VK_SLASH : macKey = '/'; break; |
|
280 |
||
281 |
case java_awt_event_KeyEvent_VK_SEMICOLON : macKey = ';'; break; |
|
282 |
case java_awt_event_KeyEvent_VK_EQUALS : macKey = '='; break; |
|
283 |
||
284 |
case java_awt_event_KeyEvent_VK_OPEN_BRACKET : macKey = '['; break; |
|
285 |
case java_awt_event_KeyEvent_VK_BACK_SLASH : macKey = '\\'; break; |
|
286 |
case java_awt_event_KeyEvent_VK_CLOSE_BRACKET : macKey = ']'; break; |
|
287 |
||
288 |
case java_awt_event_KeyEvent_VK_MULTIPLY : macKey = '*'; break; |
|
289 |
case java_awt_event_KeyEvent_VK_ADD : macKey = '+'; break; |
|
290 |
||
291 |
case java_awt_event_KeyEvent_VK_HELP : macKey = NSHelpFunctionKey; break; |
|
292 |
case java_awt_event_KeyEvent_VK_TAB : macKey = NSTabCharacter; break; |
|
293 |
case java_awt_event_KeyEvent_VK_ENTER : macKey = NSCarriageReturnCharacter; break; |
|
294 |
case java_awt_event_KeyEvent_VK_BACK_SPACE : macKey = NSBackspaceCharacter; break; |
|
295 |
case java_awt_event_KeyEvent_VK_DELETE : macKey = NSDeleteCharacter; break; |
|
296 |
case java_awt_event_KeyEvent_VK_CLEAR : macKey = NSClearDisplayFunctionKey; break; |
|
297 |
case java_awt_event_KeyEvent_VK_AMPERSAND : macKey = '&'; break; |
|
298 |
case java_awt_event_KeyEvent_VK_ASTERISK : macKey = '*'; break; |
|
299 |
case java_awt_event_KeyEvent_VK_QUOTEDBL : macKey = '\"'; break; |
|
300 |
case java_awt_event_KeyEvent_VK_LESS : macKey = '<'; break; |
|
301 |
case java_awt_event_KeyEvent_VK_GREATER : macKey = '>'; break; |
|
302 |
case java_awt_event_KeyEvent_VK_BRACELEFT : macKey = '{'; break; |
|
303 |
case java_awt_event_KeyEvent_VK_BRACERIGHT : macKey = '}'; break; |
|
304 |
case java_awt_event_KeyEvent_VK_AT : macKey = '@'; break; |
|
305 |
case java_awt_event_KeyEvent_VK_COLON : macKey = ':'; break; |
|
306 |
case java_awt_event_KeyEvent_VK_CIRCUMFLEX : macKey = '^'; break; |
|
307 |
case java_awt_event_KeyEvent_VK_DOLLAR : macKey = '$'; break; |
|
308 |
case java_awt_event_KeyEvent_VK_EXCLAMATION_MARK : macKey = '!'; break; |
|
309 |
case java_awt_event_KeyEvent_VK_LEFT_PARENTHESIS : macKey = '('; break; |
|
310 |
case java_awt_event_KeyEvent_VK_NUMBER_SIGN : macKey = '#'; break; |
|
311 |
case java_awt_event_KeyEvent_VK_PLUS : macKey = '+'; break; |
|
312 |
case java_awt_event_KeyEvent_VK_RIGHT_PARENTHESIS: macKey = ')'; break; |
|
313 |
case java_awt_event_KeyEvent_VK_UNDERSCORE : macKey = '_'; break; |
|
314 |
} |
|
315 |
} |
|
316 |
return macKey; |
|
317 |
} |
|
318 |
||
319 |
/* |
|
320 |
* Class: sun_lwawt_macosx_CMenuItem |
|
321 |
* Method: nativeSetLabel |
|
322 |
* Signature: (JLjava/lang/String;CII)V |
|
323 |
*/ |
|
324 |
JNIEXPORT void JNICALL |
|
325 |
Java_sun_lwawt_macosx_CMenuItem_nativeSetLabel |
|
326 |
(JNIEnv *env, jobject peer, |
|
327 |
jlong menuItemObj, jstring label, |
|
328 |
jchar shortcutKey, jint shortcutKeyCode, jint mods) |
|
329 |
{ |
|
330 |
JNF_COCOA_ENTER(env); |
|
331 |
NSString *theLabel = JNFJavaToNSString(env, label); |
|
332 |
NSString *theKeyEquivalent = nil; |
|
333 |
unichar macKey = shortcutKey; |
|
334 |
||
335 |
if (macKey == 0) { |
|
336 |
macKey = AWTKeyToMacShortcut(shortcutKeyCode, (mods & java_awt_event_KeyEvent_SHIFT_MASK) != 0); |
|
337 |
} |
|
338 |
||
339 |
if (macKey != 0) { |
|
340 |
unichar equivalent[1] = {macKey}; |
|
341 |
theKeyEquivalent = [NSString stringWithCharacters:equivalent length:1]; |
|
342 |
} else { |
|
343 |
theKeyEquivalent = @""; |
|
344 |
} |
|
345 |
||
346 |
[((CMenuItem *)jlong_to_ptr(menuItemObj)) setJavaLabel:theLabel shortcut:theKeyEquivalent modifierMask:mods]; |
|
347 |
JNF_COCOA_EXIT(env); |
|
348 |
} |
|
349 |
||
350 |
/* |
|
351 |
* Class: sun_lwawt_macosx_CMenuItem |
|
352 |
* Method: nativeSetTooltip |
|
353 |
* Signature: (JLjava/lang/String;)V |
|
354 |
*/ |
|
355 |
JNIEXPORT void JNICALL |
|
356 |
Java_sun_lwawt_macosx_CMenuItem_nativeSetTooltip |
|
357 |
(JNIEnv *env, jobject peer, jlong menuItemObj, jstring tooltip) |
|
358 |
{ |
|
359 |
JNF_COCOA_ENTER(env); |
|
360 |
NSString *theTooltip = JNFJavaToNSString(env, tooltip); |
|
361 |
[((CMenuItem *)jlong_to_ptr(menuItemObj)) setJavaToolTipText:theTooltip]; |
|
362 |
JNF_COCOA_EXIT(env); |
|
363 |
} |
|
364 |
||
365 |
/* |
|
366 |
* Class: sun_lwawt_macosx_CMenuItem |
|
367 |
* Method: nativeSetImage |
|
368 |
* Signature: (JJ)V |
|
369 |
*/ |
|
370 |
JNIEXPORT void JNICALL |
|
371 |
Java_sun_lwawt_macosx_CMenuItem_nativeSetImage |
|
372 |
(JNIEnv *env, jobject peer, jlong menuItemObj, jlong image) |
|
373 |
{ |
|
374 |
JNF_COCOA_ENTER(env); |
|
375 |
[((CMenuItem *)jlong_to_ptr(menuItemObj)) setJavaImage:(NSImage*)jlong_to_ptr(image)]; |
|
376 |
JNF_COCOA_EXIT(env); |
|
377 |
} |
|
378 |
||
379 |
/* |
|
380 |
* Class: sun_lwawt_macosx_CMenuItem |
|
381 |
* Method: nativeCreate |
|
382 |
* Signature: (JZ)J |
|
383 |
*/ |
|
384 |
JNIEXPORT jlong JNICALL |
|
385 |
Java_sun_lwawt_macosx_CMenuItem_nativeCreate |
|
386 |
(JNIEnv *env, jobject peer, jlong parentCMenuObj, jboolean isSeparator) |
|
387 |
{ |
|
388 |
||
389 |
CMenuItem *aCMenuItem = nil; |
|
390 |
CMenu *parentCMenu = (CMenu *)jlong_to_ptr(parentCMenuObj); |
|
391 |
JNF_COCOA_ENTER(env); |
|
392 |
||
393 |
jobject cPeerObjGlobal = (*env)->NewGlobalRef(env, peer); |
|
394 |
||
395 |
NSMutableArray *args = nil; |
|
396 |
||
397 |
// Create a new item.... |
|
398 |
if (isSeparator == JNI_TRUE) { |
|
399 |
args = [[NSMutableArray alloc] initWithObjects:[NSValue valueWithBytes:&cPeerObjGlobal objCType:@encode(jobject)], [NSNumber numberWithBool:YES], nil]; |
|
400 |
} else { |
|
401 |
args = [[NSMutableArray alloc] initWithObjects:[NSValue valueWithBytes:&cPeerObjGlobal objCType:@encode(jobject)], [NSNumber numberWithBool:NO], nil]; |
|
402 |
} |
|
403 |
||
404 |
[ThreadUtilities performOnMainThread:@selector(_createMenuItem_OnAppKitThread:) onObject:[CMenuItem alloc] withObject:args waitUntilDone:YES awtMode:YES]; |
|
405 |
||
406 |
aCMenuItem = (CMenuItem *)[args objectAtIndex: 0]; |
|
407 |
||
408 |
if (aCMenuItem == nil) { |
|
409 |
return 0L; |
|
410 |
} |
|
411 |
||
412 |
// and add it to the parent item. |
|
413 |
[parentCMenu addJavaMenuItem: aCMenuItem]; |
|
414 |
||
415 |
// setLabel will be called after creation completes. |
|
416 |
||
417 |
if (aCMenuItem) { |
|
418 |
CFRetain(aCMenuItem); // GC |
|
419 |
[aCMenuItem release]; |
|
420 |
} |
|
421 |
||
422 |
JNF_COCOA_EXIT(env); |
|
423 |
return ptr_to_jlong(aCMenuItem); |
|
424 |
} |
|
425 |
||
426 |
/* |
|
427 |
* Class: sun_lwawt_macosx_CMenuItem |
|
428 |
* Method: nativeSetEnabled |
|
429 |
* Signature: (JZ)V |
|
430 |
*/ |
|
431 |
JNIEXPORT void JNICALL |
|
432 |
Java_sun_lwawt_macosx_CMenuItem_nativeSetEnabled |
|
433 |
(JNIEnv *env, jobject peer, jlong menuItemObj, jboolean enable) |
|
434 |
{ |
|
435 |
JNF_COCOA_ENTER(env); |
|
436 |
CMenuItem *item = (CMenuItem *)jlong_to_ptr(menuItemObj); |
|
437 |
[item setJavaEnabled: (enable == JNI_TRUE)]; |
|
438 |
JNF_COCOA_EXIT(env); |
|
439 |
} |
|
440 |
||
441 |
/* |
|
442 |
* Class: sun_lwawt_macosx_CCheckboxMenuItem |
|
443 |
* Method: nativeSetState |
|
444 |
* Signature: (IZ)V |
|
445 |
*/ |
|
446 |
JNIEXPORT void JNICALL |
|
447 |
Java_sun_lwawt_macosx_CCheckboxMenuItem_nativeSetState |
|
448 |
(JNIEnv *env, jobject peer, jlong menuItemObj, jboolean state) |
|
449 |
{ |
|
450 |
JNF_COCOA_ENTER(env); |
|
451 |
CMenuItem *item = (CMenuItem *)jlong_to_ptr(menuItemObj); |
|
452 |
[item setJavaState: (state == JNI_TRUE)]; |
|
453 |
JNF_COCOA_EXIT(env); |
|
454 |
} |
|
455 |
||
456 |
/* |
|
457 |
* Class: sun_lwawt_macosx_CCheckboxMenuItem |
|
458 |
* Method: nativeSetState |
|
459 |
* Signature: (IZ)V |
|
460 |
*/ |
|
461 |
JNIEXPORT void JNICALL |
|
462 |
Java_sun_lwawt_macosx_CCheckboxMenuItem_nativeSetIsCheckbox |
|
463 |
(JNIEnv *env, jobject peer, jlong menuItemObj) |
|
464 |
{ |
|
465 |
JNF_COCOA_ENTER(env); |
|
466 |
CMenuItem *item = (CMenuItem *)jlong_to_ptr(menuItemObj); |
|
467 |
[item setIsCheckbox]; |
|
468 |
JNF_COCOA_EXIT(env); |
|
469 |
} |