src/macosx/native/sun/awt/CTrayIcon.m
Print this page
*** 27,36 ****
--- 27,37 ----
#import <JavaNativeFoundation/JavaNativeFoundation.h>
#import "CTrayIcon.h"
#import "ThreadUtilities.h"
#include "GeomUtilities.h"
+ #import "LWCToolkit.h"
#define kImageInset 4.0
/**
* If the image of the specified size won't fit into the status bar,
*** 74,85 ****
[[NSStatusBar systemStatusBar] removeStatusItem: theItem];
// Its a bad idea to force the item to release our view by setting
// the item's view to nil: it can lead to a crash in some scenarios.
// The item will release the view later on, so just set the view's image
! // to nil since we are done with it.
[view setImage: nil];
[view release];
[theItem release];
[super dealloc];
--- 75,87 ----
[[NSStatusBar systemStatusBar] removeStatusItem: theItem];
// Its a bad idea to force the item to release our view by setting
// the item's view to nil: it can lead to a crash in some scenarios.
// The item will release the view later on, so just set the view's image
! // and tray icon to nil since we are done with it.
[view setImage: nil];
+ [view setTrayIcon: nil];
[view release];
[theItem release];
[super dealloc];
*** 113,131 ****
- (NSPoint) getLocationOnScreen {
return [[view window] convertBaseToScreen: NSZeroPoint];
}
@end //AWTTrayIcon
//================================================
@implementation AWTTrayIconView
-(id)initWithTrayIcon:(AWTTrayIcon *)theTrayIcon {
self = [super initWithFrame:NSMakeRect(0, 0, 1, 1)];
! trayIcon = theTrayIcon;
isHighlighted = NO;
image = nil;
return self;
}
--- 115,172 ----
- (NSPoint) getLocationOnScreen {
return [[view window] convertBaseToScreen: NSZeroPoint];
}
+ -(void) deliverJavaMouseEvent: (NSEvent *) event {
+ [AWTToolkit eventCountPlusPlus];
+
+ JNIEnv *env = [ThreadUtilities getJNIEnv];
+
+ NSPoint eventLocation = [event locationInWindow];
+ NSPoint localPoint = [view convertPoint: eventLocation fromView: nil];
+ localPoint.y = [view bounds].size.height - localPoint.y;
+
+ NSPoint absP = [NSEvent mouseLocation];
+ NSEventType type = [event type];
+
+ NSRect screenRect = [[NSScreen mainScreen] frame];
+ absP.y = screenRect.size.height - absP.y;
+ jint clickCount;
+
+ clickCount = [event clickCount];
+
+ static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/event/NSEvent");
+ static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IIIIIIIIDD)V");
+ jobject jEvent = JNFNewObject(env, jctor_NSEvent,
+ [event type],
+ [event modifierFlags],
+ clickCount,
+ [event buttonNumber],
+ (jint)localPoint.x, (jint)localPoint.y,
+ (jint)absP.x, (jint)absP.y,
+ [event deltaY],
+ [event deltaX]);
+ if (jEvent == nil) {
+ // Unable to create event by some reason.
+ return;
+ }
+
+ static JNF_CLASS_CACHE(jc_TrayIcon, "sun/lwawt/macosx/CTrayIcon");
+ static JNF_MEMBER_CACHE(jm_handleMouseEvent, jc_TrayIcon, "handleMouseEvent", "(Lsun/lwawt/macosx/event/NSEvent;)V");
+ JNFCallVoidMethod(env, peer, jm_handleMouseEvent, jEvent);
+ }
+
@end //AWTTrayIcon
//================================================
@implementation AWTTrayIconView
-(id)initWithTrayIcon:(AWTTrayIcon *)theTrayIcon {
self = [super initWithFrame:NSMakeRect(0, 0, 1, 1)];
! [self setTrayIcon: theTrayIcon];
isHighlighted = NO;
image = nil;
return self;
}
*** 151,160 ****
--- 192,205 ----
if (image != nil) {
[self setNeedsDisplay:YES];
}
}
+ -(void)setTrayIcon:(AWTTrayIcon*)theTrayIcon {
+ trayIcon = theTrayIcon;
+ }
+
- (void)menuWillOpen:(NSMenu *)menu
{
[self setHighlighted:YES];
}
*** 189,222 ****
operation:NSCompositeSourceOver
fraction:1.0
];
}
! - (void) mouseDown:(NSEvent *)e {
//find CTrayIcon.getPopupMenuModel method and call it to get popup menu ptr.
JNIEnv *env = [ThreadUtilities getJNIEnv];
static JNF_CLASS_CACHE(jc_CTrayIcon, "sun/lwawt/macosx/CTrayIcon");
static JNF_MEMBER_CACHE(jm_getPopupMenuModel, jc_CTrayIcon, "getPopupMenuModel", "()J");
- static JNF_MEMBER_CACHE(jm_performAction, jc_CTrayIcon, "performAction", "()V");
jlong res = JNFCallLongMethod(env, trayIcon.peer, jm_getPopupMenuModel);
if (res != 0) {
CPopupMenu *cmenu = jlong_to_ptr(res);
NSMenu* menu = [cmenu menu];
[menu setDelegate:self];
[trayIcon.theItem popUpStatusItemMenu:menu];
[self setNeedsDisplay:YES];
! } else {
! JNFCallVoidMethod(env, trayIcon.peer, jm_performAction);
}
}
! - (void) rightMouseDown:(NSEvent *)e {
! // Call CTrayIcon.performAction() method on right mouse press
! JNIEnv *env = [ThreadUtilities getJNIEnv];
! static JNF_CLASS_CACHE(jc_CTrayIcon, "sun/lwawt/macosx/CTrayIcon");
! static JNF_MEMBER_CACHE(jm_performAction, jc_CTrayIcon, "performAction", "()V");
! JNFCallVoidMethod(env, trayIcon.peer, jm_performAction);
}
@end //AWTTrayIconView
//================================================
--- 234,294 ----
operation:NSCompositeSourceOver
fraction:1.0
];
}
! - (void)mouseDown:(NSEvent *)event {
! [trayIcon deliverJavaMouseEvent: event];
!
! // don't show the menu on ctrl+click: it triggers ACTION event, like right click
! if (([event modifierFlags] & NSControlKeyMask) == 0) {
//find CTrayIcon.getPopupMenuModel method and call it to get popup menu ptr.
JNIEnv *env = [ThreadUtilities getJNIEnv];
static JNF_CLASS_CACHE(jc_CTrayIcon, "sun/lwawt/macosx/CTrayIcon");
static JNF_MEMBER_CACHE(jm_getPopupMenuModel, jc_CTrayIcon, "getPopupMenuModel", "()J");
jlong res = JNFCallLongMethod(env, trayIcon.peer, jm_getPopupMenuModel);
+
if (res != 0) {
CPopupMenu *cmenu = jlong_to_ptr(res);
NSMenu* menu = [cmenu menu];
[menu setDelegate:self];
[trayIcon.theItem popUpStatusItemMenu:menu];
[self setNeedsDisplay:YES];
! }
}
}
! - (void) mouseUp:(NSEvent *)event {
! [trayIcon deliverJavaMouseEvent: event];
! }
!
! - (void) mouseDragged:(NSEvent *)event {
! [trayIcon deliverJavaMouseEvent: event];
! }
!
! - (void) rightMouseDown:(NSEvent *)event {
! [trayIcon deliverJavaMouseEvent: event];
! }
!
! - (void) rightMouseUp:(NSEvent *)event {
! [trayIcon deliverJavaMouseEvent: event];
! }
!
! - (void) rightMouseDragged:(NSEvent *)event {
! [trayIcon deliverJavaMouseEvent: event];
! }
!
! - (void) otherMouseDown:(NSEvent *)event {
! [trayIcon deliverJavaMouseEvent: event];
! }
!
! - (void) otherMouseUp:(NSEvent *)event {
! [trayIcon deliverJavaMouseEvent: event];
! }
!
! - (void) otherMouseDragged:(NSEvent *)event {
! [trayIcon deliverJavaMouseEvent: event];
}
@end //AWTTrayIconView
//================================================