src/macosx/native/sun/awt/CMenuItem.m

Print this page




  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];
  99         jint javaModifiers = NsKeyModifiersToJavaModifiers(modifiers, NO);
 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 
 126         modifierMask = JavaModifiersToNsKeyModifiers(modifiers, NO);
 127     }
 128 
 129     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 130         AWT_ASSERT_APPKIT_THREAD;
 131         [fMenuItem setKeyEquivalent:theKeyEquivalent];
 132         [fMenuItem setKeyEquivalentModifierMask:modifierMask];
 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 




  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];
  99         jint javaModifiers = NsKeyModifiersToJavaModifiers(modifiers, NO);
 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 
 108     NSUInteger modifierMask = 0;
 109 
 110     if (![theKeyEquivalent isEqualToString:@""]) {
 111         // Force the key equivalent to lower case if not using the shift key.
 112         // Otherwise AppKit will draw a Shift glyph in the menu.
 113         if ((modifiers & java_awt_event_KeyEvent_SHIFT_MASK) == 0) {
 114             theKeyEquivalent = [theKeyEquivalent lowercaseString];
 115         }
 116 
 117         // Hack for the question mark -- SHIFT and / means use the question mark.
 118         if ((modifiers & java_awt_event_KeyEvent_SHIFT_MASK) != 0 &&
 119             [theKeyEquivalent isEqualToString:@"/"])
 120         {
 121             theKeyEquivalent = @"?";
 122             modifiers &= ~java_awt_event_KeyEvent_SHIFT_MASK;
 123         }
 124 
 125         modifierMask = JavaModifiersToNsKeyModifiers(modifiers, NO);
 126     }
 127 
 128     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){

 129         [fMenuItem setKeyEquivalent:theKeyEquivalent];
 130         [fMenuItem setKeyEquivalentModifierMask:modifierMask];
 131         [fMenuItem setTitle:theLabel];
 132     }];
 133 }
 134 
 135 - (void) setJavaImage:(NSImage *)theImage {




 136 
 137     [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
 138         [fMenuItem setImage:theImage];
 139     }];
 140 }
 141 
 142 - (void) setJavaToolTipText:(NSString *)theText {




 143 
 144     [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
 145         [fMenuItem setToolTip:theText];
 146     }];
 147 }
 148 
 149 
 150 - (void)setJavaEnabled:(BOOL) enabled {




 151 
 152     [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
 153         @synchronized(self) {
 154             fIsEnabled = enabled;
 155 
 156             // Warning:  This won't work if the parent menu is disabled.
 157             // See [CMenu syncFromJava]. We still need to call it here so
 158             // the NSMenuItem itself gets properly updated.
 159             [fMenuItem setEnabled:fIsEnabled];
 160         }
 161     }];
 162 }
 163 
 164 - (BOOL)isEnabled {

 165 
 166     BOOL enabled = NO;
 167     @synchronized(self) {
 168         enabled = fIsEnabled;
 169     }
 170     return enabled;
 171 }
 172 
 173 
 174 - (void)setJavaState:(BOOL)newState {




 175 
 176     [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
 177         [fMenuItem setState:(newState ? NSOnState : NSOffState)];
 178     }];
 179 }
 180 
 181 - (void)cleanup {
 182     [fMenuItem setAction:NULL];
 183     [fMenuItem setTarget:nil];
 184 }
 185 
 186 - (void)dealloc {
 187     [fMenuItem release];
 188     fMenuItem = nil;
 189 
 190     [super dealloc];
 191 }
 192 
 193 - (void)addNSMenuItemToMenu:(NSMenu *)inMenu {
 194     [inMenu addItem:fMenuItem];
 195 }
 196