author | prr |
Thu, 27 Feb 2014 10:43:53 -0800 | |
changeset 23328 | 4c53a6ebc779 |
parent 23268 | 2cdb715ff32d |
parent 23010 | 6dadb192ad81 |
child 24555 | 42926c558bc8 |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
23268 | 2 |
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. |
12047 | 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 <AppKit/AppKit.h> |
|
27 |
#import <JavaNativeFoundation/JavaNativeFoundation.h> |
|
28 |
||
29 |
#import "CTrayIcon.h" |
|
30 |
#import "ThreadUtilities.h" |
|
31 |
#include "GeomUtilities.h" |
|
14157
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
32 |
#import "LWCToolkit.h" |
12047 | 33 |
|
34 |
#define kImageInset 4.0 |
|
35 |
||
36 |
/** |
|
37 |
* If the image of the specified size won't fit into the status bar, |
|
38 |
* then scale it down proprtionally. Otherwise, leave it as is. |
|
39 |
*/ |
|
40 |
static NSSize ScaledImageSizeForStatusBar(NSSize imageSize) { |
|
41 |
NSRect imageRect = NSMakeRect(0.0, 0.0, imageSize.width, imageSize.height); |
|
42 |
||
43 |
// There is a black line at the bottom of the status bar |
|
44 |
// that we don't want to cover with image pixels. |
|
45 |
CGFloat desiredHeight = [[NSStatusBar systemStatusBar] thickness] - 1.0; |
|
46 |
CGFloat scaleFactor = MIN(1.0, desiredHeight/imageSize.height); |
|
47 |
||
48 |
imageRect.size.width *= scaleFactor; |
|
49 |
imageRect.size.height *= scaleFactor; |
|
50 |
imageRect = NSIntegralRect(imageRect); |
|
51 |
||
52 |
return imageRect.size; |
|
53 |
} |
|
54 |
||
55 |
@implementation AWTTrayIcon |
|
56 |
||
57 |
- (id) initWithPeer:(jobject)thePeer { |
|
58 |
if (!(self = [super init])) return nil; |
|
59 |
||
60 |
peer = thePeer; |
|
61 |
||
62 |
theItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength]; |
|
63 |
[theItem retain]; |
|
64 |
||
65 |
view = [[AWTTrayIconView alloc] initWithTrayIcon:self]; |
|
66 |
[theItem setView:view]; |
|
67 |
||
68 |
return self; |
|
69 |
} |
|
70 |
||
71 |
-(void) dealloc { |
|
72 |
JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; |
|
73 |
JNFDeleteGlobalRef(env, peer); |
|
74 |
||
75 |
[[NSStatusBar systemStatusBar] removeStatusItem: theItem]; |
|
76 |
||
77 |
// Its a bad idea to force the item to release our view by setting |
|
78 |
// the item's view to nil: it can lead to a crash in some scenarios. |
|
79 |
// The item will release the view later on, so just set the view's image |
|
14157
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
80 |
// and tray icon to nil since we are done with it. |
12047 | 81 |
[view setImage: nil]; |
14157
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
82 |
[view setTrayIcon: nil]; |
12047 | 83 |
[view release]; |
84 |
||
85 |
[theItem release]; |
|
86 |
||
87 |
[super dealloc]; |
|
88 |
} |
|
89 |
||
90 |
- (void) setTooltip:(NSString *) tooltip{ |
|
91 |
[view setToolTip:tooltip]; |
|
92 |
} |
|
93 |
||
94 |
-(NSStatusItem *) theItem{ |
|
95 |
return theItem; |
|
96 |
} |
|
97 |
||
98 |
- (jobject) peer{ |
|
99 |
return peer; |
|
100 |
} |
|
101 |
||
102 |
- (void) setImage:(NSImage *) imagePtr sizing:(BOOL)autosize{ |
|
103 |
NSSize imageSize = [imagePtr size]; |
|
104 |
NSSize scaledSize = ScaledImageSizeForStatusBar(imageSize); |
|
105 |
if (imageSize.width != scaledSize.width || |
|
106 |
imageSize.height != scaledSize.height) { |
|
107 |
[imagePtr setSize: scaledSize]; |
|
108 |
} |
|
109 |
||
110 |
CGFloat itemLength = scaledSize.width + 2.0*kImageInset; |
|
111 |
[theItem setLength:itemLength]; |
|
112 |
||
113 |
[view setImage:imagePtr]; |
|
114 |
} |
|
115 |
||
116 |
- (NSPoint) getLocationOnScreen { |
|
117 |
return [[view window] convertBaseToScreen: NSZeroPoint]; |
|
118 |
} |
|
119 |
||
14157
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
120 |
-(void) deliverJavaMouseEvent: (NSEvent *) event { |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
121 |
[AWTToolkit eventCountPlusPlus]; |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
122 |
|
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
123 |
JNIEnv *env = [ThreadUtilities getJNIEnv]; |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
124 |
|
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
125 |
NSPoint eventLocation = [event locationInWindow]; |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
126 |
NSPoint localPoint = [view convertPoint: eventLocation fromView: nil]; |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
127 |
localPoint.y = [view bounds].size.height - localPoint.y; |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
128 |
|
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
129 |
NSPoint absP = [NSEvent mouseLocation]; |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
130 |
NSEventType type = [event type]; |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
131 |
|
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
132 |
NSRect screenRect = [[NSScreen mainScreen] frame]; |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
133 |
absP.y = screenRect.size.height - absP.y; |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
134 |
jint clickCount; |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
135 |
|
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
136 |
clickCount = [event clickCount]; |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
137 |
|
23268 | 138 |
static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/NSEvent"); |
14157
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
139 |
static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IIIIIIIIDD)V"); |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
140 |
jobject jEvent = JNFNewObject(env, jctor_NSEvent, |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
141 |
[event type], |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
142 |
[event modifierFlags], |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
143 |
clickCount, |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
144 |
[event buttonNumber], |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
145 |
(jint)localPoint.x, (jint)localPoint.y, |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
146 |
(jint)absP.x, (jint)absP.y, |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
147 |
[event deltaY], |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
148 |
[event deltaX]); |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
149 |
if (jEvent == nil) { |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
150 |
// Unable to create event by some reason. |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
151 |
return; |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
152 |
} |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
153 |
|
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
154 |
static JNF_CLASS_CACHE(jc_TrayIcon, "sun/lwawt/macosx/CTrayIcon"); |
23268 | 155 |
static JNF_MEMBER_CACHE(jm_handleMouseEvent, jc_TrayIcon, "handleMouseEvent", "(Lsun/lwawt/macosx/NSEvent;)V"); |
14157
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
156 |
JNFCallVoidMethod(env, peer, jm_handleMouseEvent, jEvent); |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
157 |
} |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
158 |
|
12047 | 159 |
@end //AWTTrayIcon |
160 |
//================================================ |
|
161 |
||
162 |
@implementation AWTTrayIconView |
|
163 |
||
164 |
-(id)initWithTrayIcon:(AWTTrayIcon *)theTrayIcon { |
|
165 |
self = [super initWithFrame:NSMakeRect(0, 0, 1, 1)]; |
|
166 |
||
14157
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
167 |
[self setTrayIcon: theTrayIcon]; |
12047 | 168 |
isHighlighted = NO; |
169 |
image = nil; |
|
170 |
||
171 |
return self; |
|
172 |
} |
|
173 |
||
174 |
-(void) dealloc { |
|
175 |
[image release]; |
|
176 |
[super dealloc]; |
|
177 |
} |
|
178 |
||
179 |
- (void)setHighlighted:(BOOL)aFlag |
|
180 |
{ |
|
181 |
if (isHighlighted != aFlag) { |
|
182 |
isHighlighted = aFlag; |
|
183 |
[self setNeedsDisplay:YES]; |
|
184 |
} |
|
185 |
} |
|
186 |
||
187 |
- (void)setImage:(NSImage*)anImage { |
|
188 |
[anImage retain]; |
|
189 |
[image release]; |
|
190 |
image = anImage; |
|
191 |
||
192 |
if (image != nil) { |
|
193 |
[self setNeedsDisplay:YES]; |
|
194 |
} |
|
195 |
} |
|
196 |
||
14157
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
197 |
-(void)setTrayIcon:(AWTTrayIcon*)theTrayIcon { |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
198 |
trayIcon = theTrayIcon; |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
199 |
} |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
200 |
|
12047 | 201 |
- (void)menuWillOpen:(NSMenu *)menu |
202 |
{ |
|
203 |
[self setHighlighted:YES]; |
|
204 |
} |
|
205 |
||
206 |
- (void)menuDidClose:(NSMenu *)menu |
|
207 |
{ |
|
208 |
[menu setDelegate:nil]; |
|
209 |
[self setHighlighted:NO]; |
|
210 |
} |
|
211 |
||
212 |
- (void)drawRect:(NSRect)dirtyRect |
|
213 |
{ |
|
214 |
if (image == nil) { |
|
215 |
return; |
|
216 |
} |
|
217 |
||
218 |
NSRect bounds = [self bounds]; |
|
219 |
NSSize imageSize = [image size]; |
|
220 |
||
221 |
NSRect drawRect = {{ (bounds.size.width - imageSize.width) / 2.0, |
|
222 |
(bounds.size.height - imageSize.height) / 2.0 }, imageSize}; |
|
223 |
||
224 |
// don't cover bottom pixels of the status bar with the image |
|
225 |
if (drawRect.origin.y < 1.0) { |
|
226 |
drawRect.origin.y = 1.0; |
|
227 |
} |
|
228 |
drawRect = NSIntegralRect(drawRect); |
|
229 |
||
230 |
[trayIcon.theItem drawStatusBarBackgroundInRect:bounds |
|
231 |
withHighlight:isHighlighted]; |
|
232 |
[image drawInRect:drawRect |
|
233 |
fromRect:NSZeroRect |
|
234 |
operation:NSCompositeSourceOver |
|
235 |
fraction:1.0 |
|
236 |
]; |
|
237 |
} |
|
238 |
||
14157
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
239 |
- (void)mouseDown:(NSEvent *)event { |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
240 |
[trayIcon deliverJavaMouseEvent: event]; |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
241 |
|
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
242 |
// don't show the menu on ctrl+click: it triggers ACTION event, like right click |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
243 |
if (([event modifierFlags] & NSControlKeyMask) == 0) { |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
244 |
//find CTrayIcon.getPopupMenuModel method and call it to get popup menu ptr. |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
245 |
JNIEnv *env = [ThreadUtilities getJNIEnv]; |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
246 |
static JNF_CLASS_CACHE(jc_CTrayIcon, "sun/lwawt/macosx/CTrayIcon"); |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
247 |
static JNF_MEMBER_CACHE(jm_getPopupMenuModel, jc_CTrayIcon, "getPopupMenuModel", "()J"); |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
248 |
jlong res = JNFCallLongMethod(env, trayIcon.peer, jm_getPopupMenuModel); |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
249 |
|
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
250 |
if (res != 0) { |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
251 |
CPopupMenu *cmenu = jlong_to_ptr(res); |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
252 |
NSMenu* menu = [cmenu menu]; |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
253 |
[menu setDelegate:self]; |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
254 |
[trayIcon.theItem popUpStatusItemMenu:menu]; |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
255 |
[self setNeedsDisplay:YES]; |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
256 |
} |
12047 | 257 |
} |
258 |
} |
|
259 |
||
14157
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
260 |
- (void) mouseUp:(NSEvent *)event { |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
261 |
[trayIcon deliverJavaMouseEvent: event]; |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
262 |
} |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
263 |
|
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
264 |
- (void) mouseDragged:(NSEvent *)event { |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
265 |
[trayIcon deliverJavaMouseEvent: event]; |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
266 |
} |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
267 |
|
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
268 |
- (void) rightMouseDown:(NSEvent *)event { |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
269 |
[trayIcon deliverJavaMouseEvent: event]; |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
270 |
} |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
271 |
|
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
272 |
- (void) rightMouseUp:(NSEvent *)event { |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
273 |
[trayIcon deliverJavaMouseEvent: event]; |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
274 |
} |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
275 |
|
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
276 |
- (void) rightMouseDragged:(NSEvent *)event { |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
277 |
[trayIcon deliverJavaMouseEvent: event]; |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
278 |
} |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
279 |
|
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
280 |
- (void) otherMouseDown:(NSEvent *)event { |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
281 |
[trayIcon deliverJavaMouseEvent: event]; |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
282 |
} |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
283 |
|
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
284 |
- (void) otherMouseUp:(NSEvent *)event { |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
285 |
[trayIcon deliverJavaMouseEvent: event]; |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
286 |
} |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
287 |
|
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
288 |
- (void) otherMouseDragged:(NSEvent *)event { |
5d50d32dd770
7124321: [macosx] TrayIcon MouseListener is never triggered
leonidr
parents:
12047
diff
changeset
|
289 |
[trayIcon deliverJavaMouseEvent: event]; |
12047 | 290 |
} |
291 |
||
292 |
||
293 |
@end //AWTTrayIconView |
|
294 |
//================================================ |
|
295 |
||
296 |
/* |
|
297 |
* Class: sun_lwawt_macosx_CTrayIcon |
|
298 |
* Method: nativeCreate |
|
299 |
* Signature: ()J |
|
300 |
*/ |
|
301 |
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CTrayIcon_nativeCreate |
|
302 |
(JNIEnv *env, jobject peer) { |
|
303 |
__block AWTTrayIcon *trayIcon = nil; |
|
304 |
||
305 |
JNF_COCOA_ENTER(env); |
|
306 |
||
307 |
jobject thePeer = JNFNewGlobalRef(env, peer); |
|
15322
3638f33225ec
7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents:
14157
diff
changeset
|
308 |
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){ |
12047 | 309 |
trayIcon = [[AWTTrayIcon alloc] initWithPeer:thePeer]; |
310 |
}]; |
|
311 |
||
312 |
JNF_COCOA_EXIT(env); |
|
313 |
||
314 |
return ptr_to_jlong(trayIcon); |
|
315 |
} |
|
316 |
||
317 |
||
318 |
/* |
|
319 |
* Class: java_awt_TrayIcon |
|
320 |
* Method: initIDs |
|
321 |
* Signature: ()V |
|
322 |
*/ |
|
323 |
JNIEXPORT void JNICALL Java_java_awt_TrayIcon_initIDs |
|
324 |
(JNIEnv *env, jclass cls) { |
|
325 |
//Do nothing. |
|
326 |
} |
|
327 |
||
328 |
/* |
|
329 |
* Class: sun_lwawt_macosx_CTrayIcon |
|
330 |
* Method: nativeSetToolTip |
|
331 |
* Signature: (JLjava/lang/String;)V |
|
332 |
*/ |
|
333 |
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CTrayIcon_nativeSetToolTip |
|
334 |
(JNIEnv *env, jobject self, jlong model, jstring jtooltip) { |
|
335 |
JNF_COCOA_ENTER(env); |
|
336 |
||
337 |
AWTTrayIcon *icon = jlong_to_ptr(model); |
|
338 |
NSString *tooltip = JNFJavaToNSString(env, jtooltip); |
|
15322
3638f33225ec
7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents:
14157
diff
changeset
|
339 |
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){ |
12047 | 340 |
[icon setTooltip:tooltip]; |
341 |
}]; |
|
342 |
||
343 |
JNF_COCOA_EXIT(env); |
|
344 |
} |
|
345 |
||
346 |
/* |
|
347 |
* Class: sun_lwawt_macosx_CTrayIcon |
|
348 |
* Method: setNativeImage |
|
349 |
* Signature: (JJZ)V |
|
350 |
*/ |
|
351 |
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CTrayIcon_setNativeImage |
|
352 |
(JNIEnv *env, jobject self, jlong model, jlong imagePtr, jboolean autosize) { |
|
353 |
JNF_COCOA_ENTER(env); |
|
354 |
||
355 |
AWTTrayIcon *icon = jlong_to_ptr(model); |
|
15322
3638f33225ec
7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents:
14157
diff
changeset
|
356 |
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){ |
12047 | 357 |
[icon setImage:jlong_to_ptr(imagePtr) sizing:autosize]; |
358 |
}]; |
|
359 |
||
360 |
JNF_COCOA_EXIT(env); |
|
361 |
} |
|
362 |
||
363 |
JNIEXPORT jobject JNICALL |
|
364 |
Java_sun_lwawt_macosx_CTrayIcon_nativeGetIconLocation |
|
365 |
(JNIEnv *env, jobject self, jlong model) { |
|
366 |
jobject jpt = NULL; |
|
367 |
||
368 |
JNF_COCOA_ENTER(env); |
|
369 |
||
370 |
__block NSPoint pt = NSZeroPoint; |
|
371 |
AWTTrayIcon *icon = jlong_to_ptr(model); |
|
15322
3638f33225ec
7179050: [macosx] Make LWAWT be able to run on AppKit thread
serb
parents:
14157
diff
changeset
|
372 |
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){ |
12047 | 373 |
NSPoint loc = [icon getLocationOnScreen]; |
374 |
pt = ConvertNSScreenPoint(env, loc); |
|
375 |
}]; |
|
376 |
||
377 |
jpt = NSToJavaPoint(env, pt); |
|
378 |
||
379 |
JNF_COCOA_EXIT(env); |
|
380 |
||
381 |
return jpt; |
|
382 |
} |