Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-aarch32-jdk8u
Path: blob/jdk8u272-b10-aarch32-20201026/jdk/src/macosx/native/sun/awt/AWTWindow.m
83406 views
1
/*
2
* Copyright (c) 2011, 2014, 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 <Cocoa/Cocoa.h>
27
#import <JavaNativeFoundation/JavaNativeFoundation.h>
28
#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
29
30
#import "sun_lwawt_macosx_CPlatformWindow.h"
31
#import "com_apple_eawt_event_GestureHandler.h"
32
#import "com_apple_eawt_FullScreenHandler.h"
33
#import "ApplicationDelegate.h"
34
35
#import "AWTWindow.h"
36
#import "AWTView.h"
37
#import "CMenu.h"
38
#import "CMenuBar.h"
39
#import "LWCToolkit.h"
40
#import "GeomUtilities.h"
41
#import "ThreadUtilities.h"
42
#import "OSVersion.h"
43
44
#define MASK(KEY) \
45
(sun_lwawt_macosx_CPlatformWindow_ ## KEY)
46
47
#define IS(BITS, KEY) \
48
((BITS & MASK(KEY)) != 0)
49
50
#define SET(BITS, KEY, VALUE) \
51
BITS = VALUE ? BITS | MASK(KEY) : BITS & ~MASK(KEY)
52
53
static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow");
54
55
// Cocoa windowDidBecomeKey/windowDidResignKey notifications
56
// doesn't provide information about "opposite" window, so we
57
// have to do a bit of tracking. This variable points to a window
58
// which had been the key window just before a new key window
59
// was set. It would be nil if the new key window isn't an AWT
60
// window or the app currently has no key window.
61
static AWTWindow* lastKeyWindow = nil;
62
63
// --------------------------------------------------------------
64
// NSWindow/NSPanel descendants implementation
65
#define AWT_NS_WINDOW_IMPLEMENTATION \
66
- (id) initWithDelegate:(AWTWindow *)delegate \
67
frameRect:(NSRect)contectRect \
68
styleMask:(NSUInteger)styleMask \
69
contentView:(NSView *)view \
70
{ \
71
self = [super initWithContentRect:contectRect \
72
styleMask:styleMask \
73
backing:NSBackingStoreBuffered \
74
defer:NO]; \
75
\
76
if (self == nil) return nil; \
77
\
78
[self setDelegate:delegate]; \
79
[self setContentView:view]; \
80
[self setInitialFirstResponder:view]; \
81
[self setReleasedWhenClosed:NO]; \
82
[self setPreservesContentDuringLiveResize:YES]; \
83
\
84
return self; \
85
} \
86
\
87
/* NSWindow overrides */ \
88
- (BOOL) canBecomeKeyWindow { \
89
return [(AWTWindow*)[self delegate] canBecomeKeyWindow]; \
90
} \
91
\
92
- (BOOL) canBecomeMainWindow { \
93
return [(AWTWindow*)[self delegate] canBecomeMainWindow]; \
94
} \
95
\
96
- (BOOL) worksWhenModal { \
97
return [(AWTWindow*)[self delegate] worksWhenModal]; \
98
} \
99
\
100
- (void)sendEvent:(NSEvent *)event { \
101
[(AWTWindow*)[self delegate] sendEvent:event]; \
102
[super sendEvent:event]; \
103
}
104
105
@implementation AWTWindow_Normal
106
AWT_NS_WINDOW_IMPLEMENTATION
107
108
// Gesture support
109
- (void)postGesture:(NSEvent *)event as:(jint)type a:(jdouble)a b:(jdouble)b {
110
AWT_ASSERT_APPKIT_THREAD;
111
112
JNIEnv *env = [ThreadUtilities getJNIEnv];
113
jobject platformWindow = [((AWTWindow *)self.delegate).javaPlatformWindow jObjectWithEnv:env];
114
if (platformWindow != NULL) {
115
// extract the target AWT Window object out of the CPlatformWindow
116
static JNF_MEMBER_CACHE(jf_target, jc_CPlatformWindow, "target", "Ljava/awt/Window;");
117
jobject awtWindow = JNFGetObjectField(env, platformWindow, jf_target);
118
if (awtWindow != NULL) {
119
// translate the point into Java coordinates
120
NSPoint loc = [event locationInWindow];
121
loc.y = [self frame].size.height - loc.y;
122
123
// send up to the GestureHandler to recursively dispatch on the AWT event thread
124
static JNF_CLASS_CACHE(jc_GestureHandler, "com/apple/eawt/event/GestureHandler");
125
static JNF_STATIC_MEMBER_CACHE(sjm_handleGestureFromNative, jc_GestureHandler, "handleGestureFromNative", "(Ljava/awt/Window;IDDDD)V");
126
JNFCallStaticVoidMethod(env, sjm_handleGestureFromNative, awtWindow, type, (jdouble)loc.x, (jdouble)loc.y, (jdouble)a, (jdouble)b);
127
(*env)->DeleteLocalRef(env, awtWindow);
128
}
129
(*env)->DeleteLocalRef(env, platformWindow);
130
}
131
}
132
133
- (void)beginGestureWithEvent:(NSEvent *)event {
134
[self postGesture:event
135
as:com_apple_eawt_event_GestureHandler_PHASE
136
a:-1.0
137
b:0.0];
138
}
139
140
- (void)endGestureWithEvent:(NSEvent *)event {
141
[self postGesture:event
142
as:com_apple_eawt_event_GestureHandler_PHASE
143
a:1.0
144
b:0.0];
145
}
146
147
- (void)magnifyWithEvent:(NSEvent *)event {
148
[self postGesture:event
149
as:com_apple_eawt_event_GestureHandler_MAGNIFY
150
a:[event magnification]
151
b:0.0];
152
}
153
154
- (void)rotateWithEvent:(NSEvent *)event {
155
[self postGesture:event
156
as:com_apple_eawt_event_GestureHandler_ROTATE
157
a:[event rotation]
158
b:0.0];
159
}
160
161
- (void)swipeWithEvent:(NSEvent *)event {
162
[self postGesture:event
163
as:com_apple_eawt_event_GestureHandler_SWIPE
164
a:[event deltaX]
165
b:[event deltaY]];
166
}
167
168
@end
169
@implementation AWTWindow_Panel
170
AWT_NS_WINDOW_IMPLEMENTATION
171
@end
172
// END of NSWindow/NSPanel descendants implementation
173
// --------------------------------------------------------------
174
175
176
@implementation AWTWindow
177
178
@synthesize nsWindow;
179
@synthesize javaPlatformWindow;
180
@synthesize javaMenuBar;
181
@synthesize javaMinSize;
182
@synthesize javaMaxSize;
183
@synthesize styleBits;
184
@synthesize isEnabled;
185
@synthesize ownerWindow;
186
@synthesize preFullScreenLevel;
187
@synthesize isMinimizing;
188
189
- (void) updateMinMaxSize:(BOOL)resizable {
190
if (resizable) {
191
[self.nsWindow setMinSize:self.javaMinSize];
192
[self.nsWindow setMaxSize:self.javaMaxSize];
193
} else {
194
NSRect currentFrame = [self.nsWindow frame];
195
[self.nsWindow setMinSize:currentFrame.size];
196
[self.nsWindow setMaxSize:currentFrame.size];
197
}
198
}
199
200
// creates a new NSWindow style mask based on the _STYLE_PROP_BITMASK bits
201
+ (NSUInteger) styleMaskForStyleBits:(jint)styleBits {
202
NSUInteger type = 0;
203
if (IS(styleBits, DECORATED)) {
204
type |= NSTitledWindowMask;
205
if (IS(styleBits, CLOSEABLE)) type |= NSClosableWindowMask;
206
if (IS(styleBits, MINIMIZABLE)) type |= NSMiniaturizableWindowMask;
207
if (IS(styleBits, RESIZABLE)) type |= NSResizableWindowMask;
208
if (IS(styleBits, FULL_WINDOW_CONTENT)) type |= NSFullSizeContentViewWindowMask;
209
} else {
210
type |= NSBorderlessWindowMask;
211
}
212
213
if (IS(styleBits, TEXTURED)) type |= NSTexturedBackgroundWindowMask;
214
if (IS(styleBits, UNIFIED)) type |= NSUnifiedTitleAndToolbarWindowMask;
215
if (IS(styleBits, UTILITY)) type |= NSUtilityWindowMask;
216
if (IS(styleBits, HUD)) type |= NSHUDWindowMask;
217
if (IS(styleBits, SHEET)) type |= NSDocModalWindowMask;
218
if (IS(styleBits, NONACTIVATING)) type |= NSNonactivatingPanelMask;
219
220
return type;
221
}
222
223
// updates _METHOD_PROP_BITMASK based properties on the window
224
- (void) setPropertiesForStyleBits:(jint)bits mask:(jint)mask {
225
if (IS(mask, RESIZABLE)) {
226
BOOL resizable = IS(bits, RESIZABLE);
227
[self updateMinMaxSize:resizable];
228
[self.nsWindow setShowsResizeIndicator:resizable];
229
// Zoom button should be disabled, if the window is not resizable,
230
// otherwise button should be restored to initial state.
231
BOOL zoom = resizable && IS(bits, ZOOMABLE);
232
[[self.nsWindow standardWindowButton:NSWindowZoomButton] setEnabled:zoom];
233
}
234
235
if (IS(mask, HAS_SHADOW)) {
236
[self.nsWindow setHasShadow:IS(bits, HAS_SHADOW)];
237
}
238
239
if (IS(mask, ZOOMABLE)) {
240
[[self.nsWindow standardWindowButton:NSWindowZoomButton] setEnabled:IS(bits, ZOOMABLE)];
241
}
242
243
if (IS(mask, ALWAYS_ON_TOP)) {
244
[self.nsWindow setLevel:IS(bits, ALWAYS_ON_TOP) ? NSFloatingWindowLevel : NSNormalWindowLevel];
245
}
246
247
if (IS(mask, HIDES_ON_DEACTIVATE)) {
248
[self.nsWindow setHidesOnDeactivate:IS(bits, HIDES_ON_DEACTIVATE)];
249
}
250
251
if (IS(mask, DRAGGABLE_BACKGROUND)) {
252
[self.nsWindow setMovableByWindowBackground:IS(bits, DRAGGABLE_BACKGROUND)];
253
}
254
255
if (IS(mask, DOCUMENT_MODIFIED)) {
256
[self.nsWindow setDocumentEdited:IS(bits, DOCUMENT_MODIFIED)];
257
}
258
259
if (IS(mask, FULLSCREENABLE) && [self.nsWindow respondsToSelector:@selector(toggleFullScreen:)]) {
260
if (IS(bits, FULLSCREENABLE)) {
261
[self.nsWindow setCollectionBehavior:(1 << 7) /*NSWindowCollectionBehaviorFullScreenPrimary*/];
262
} else {
263
[self.nsWindow setCollectionBehavior:NSWindowCollectionBehaviorDefault];
264
}
265
}
266
267
if (IS(mask, TRANSPARENT_TITLE_BAR) && [self.nsWindow respondsToSelector:@selector(setTitlebarAppearsTransparent:)]) {
268
[self.nsWindow setTitlebarAppearsTransparent:IS(bits, TRANSPARENT_TITLE_BAR)];
269
}
270
}
271
272
- (id) initWithPlatformWindow:(JNFWeakJObjectWrapper *)platformWindow
273
ownerWindow:owner
274
styleBits:(jint)bits
275
frameRect:(NSRect)rect
276
contentView:(NSView *)view
277
{
278
AWT_ASSERT_APPKIT_THREAD;
279
280
NSUInteger styleMask = [AWTWindow styleMaskForStyleBits:bits];
281
NSRect contentRect = rect; //[NSWindow contentRectForFrameRect:rect styleMask:styleMask];
282
if (contentRect.size.width <= 0.0) {
283
contentRect.size.width = 1.0;
284
}
285
if (contentRect.size.height <= 0.0) {
286
contentRect.size.height = 1.0;
287
}
288
289
self = [super init];
290
291
if (self == nil) return nil; // no hope
292
293
if (IS(bits, UTILITY) ||
294
IS(bits, NONACTIVATING) ||
295
IS(bits, HUD) ||
296
IS(bits, HIDES_ON_DEACTIVATE))
297
{
298
self.nsWindow = [[AWTWindow_Panel alloc] initWithDelegate:self
299
frameRect:contentRect
300
styleMask:styleMask
301
contentView:view];
302
}
303
else
304
{
305
// These windows will appear in the window list in the dock icon menu
306
self.nsWindow = [[AWTWindow_Normal alloc] initWithDelegate:self
307
frameRect:contentRect
308
styleMask:styleMask
309
contentView:view];
310
}
311
312
if (self.nsWindow == nil) return nil; // no hope either
313
[self.nsWindow release]; // the property retains the object already
314
315
self.isEnabled = YES;
316
self.isMinimizing = NO;
317
self.javaPlatformWindow = platformWindow;
318
self.styleBits = bits;
319
self.ownerWindow = owner;
320
[self setPropertiesForStyleBits:styleBits mask:MASK(_METHOD_PROP_BITMASK)];
321
322
if (IS(self.styleBits, IS_POPUP)) {
323
[self.nsWindow setCollectionBehavior:(1 << 8) /*NSWindowCollectionBehaviorFullScreenAuxiliary*/];
324
}
325
326
return self;
327
}
328
329
+ (BOOL) isAWTWindow:(NSWindow *)window {
330
return [window isKindOfClass: [AWTWindow_Panel class]] || [window isKindOfClass: [AWTWindow_Normal class]];
331
}
332
333
// Retrieves the list of possible window layers (levels)
334
+ (NSArray*) getWindowLayers {
335
static NSArray *windowLayers;
336
static dispatch_once_t token;
337
338
// Initialize the list of possible window layers
339
dispatch_once(&token, ^{
340
// The layers are ordered from front to back, (i.e. the toppest one is the first)
341
windowLayers = [NSArray arrayWithObjects:
342
[NSNumber numberWithInt:CGWindowLevelForKey(kCGPopUpMenuWindowLevelKey)],
343
[NSNumber numberWithInt:CGWindowLevelForKey(kCGFloatingWindowLevelKey)],
344
[NSNumber numberWithInt:CGWindowLevelForKey(kCGNormalWindowLevelKey)],
345
nil
346
];
347
[windowLayers retain];
348
});
349
return windowLayers;
350
}
351
352
// returns id for the topmost window under mouse
353
+ (NSInteger) getTopmostWindowUnderMouseID {
354
NSInteger result = -1;
355
356
NSArray *windowLayers = [AWTWindow getWindowLayers];
357
// Looking for the window under mouse starting from the toppest layer
358
for (NSNumber *layer in windowLayers) {
359
result = [AWTWindow getTopmostWindowUnderMouseIDImpl:[layer integerValue]];
360
if (result != -1) {
361
break;
362
}
363
}
364
return result;
365
}
366
367
+ (NSInteger) getTopmostWindowUnderMouseIDImpl:(NSInteger)windowLayer {
368
NSInteger result = -1;
369
370
NSRect screenRect = [[NSScreen mainScreen] frame];
371
NSPoint nsMouseLocation = [NSEvent mouseLocation];
372
CGPoint cgMouseLocation = CGPointMake(nsMouseLocation.x, screenRect.size.height - nsMouseLocation.y);
373
374
NSMutableArray *windows = (NSMutableArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
375
376
for (NSDictionary *window in windows) {
377
NSInteger layer = [[window objectForKey:(id)kCGWindowLayer] integerValue];
378
if (layer == windowLayer) {
379
CGRect rect;
380
CGRectMakeWithDictionaryRepresentation((CFDictionaryRef)[window objectForKey:(id)kCGWindowBounds], &rect);
381
if (CGRectContainsPoint(rect, cgMouseLocation)) {
382
result = [[window objectForKey:(id)kCGWindowNumber] integerValue];
383
break;
384
}
385
}
386
}
387
[windows release];
388
return result;
389
}
390
391
// checks that this window is under the mouse cursor and this point is not overlapped by others windows
392
- (BOOL) isTopmostWindowUnderMouse {
393
return [self.nsWindow windowNumber] == [AWTWindow getTopmostWindowUnderMouseID];
394
}
395
396
+ (AWTWindow *) getTopmostWindowUnderMouse {
397
NSEnumerator *windowEnumerator = [[NSApp windows] objectEnumerator];
398
NSWindow *window;
399
400
NSInteger topmostWindowUnderMouseID = [AWTWindow getTopmostWindowUnderMouseID];
401
402
while ((window = [windowEnumerator nextObject]) != nil) {
403
if ([window windowNumber] == topmostWindowUnderMouseID) {
404
BOOL isAWTWindow = [AWTWindow isAWTWindow: window];
405
return isAWTWindow ? (AWTWindow *) [window delegate] : nil;
406
}
407
}
408
return nil;
409
}
410
411
+ (void) synthesizeMouseEnteredExitedEvents:(NSWindow*)window withType:(NSEventType)eventType {
412
413
NSPoint screenLocation = [NSEvent mouseLocation];
414
NSPoint windowLocation = [window convertScreenToBase: screenLocation];
415
int modifierFlags = (eventType == NSMouseEntered) ? NSMouseEnteredMask : NSMouseExitedMask;
416
417
NSEvent *mouseEvent = [NSEvent enterExitEventWithType: eventType
418
location: windowLocation
419
modifierFlags: modifierFlags
420
timestamp: 0
421
windowNumber: [window windowNumber]
422
context: nil
423
eventNumber: 0
424
trackingNumber: 0
425
userData: nil
426
];
427
428
[[window contentView] deliverJavaMouseEvent: mouseEvent];
429
}
430
431
+ (void) synthesizeMouseEnteredExitedEventsForAllWindows {
432
433
NSInteger topmostWindowUnderMouseID = [AWTWindow getTopmostWindowUnderMouseID];
434
NSArray *windows = [NSApp windows];
435
NSWindow *window;
436
437
NSEnumerator *windowEnumerator = [windows objectEnumerator];
438
while ((window = [windowEnumerator nextObject]) != nil) {
439
if ([AWTWindow isAWTWindow: window]) {
440
BOOL isUnderMouse = ([window windowNumber] == topmostWindowUnderMouseID);
441
BOOL mouseIsOver = [[window contentView] mouseIsOver];
442
if (isUnderMouse && !mouseIsOver) {
443
[AWTWindow synthesizeMouseEnteredExitedEvents:window withType:NSMouseEntered];
444
} else if (!isUnderMouse && mouseIsOver) {
445
[AWTWindow synthesizeMouseEnteredExitedEvents:window withType:NSMouseExited];
446
}
447
}
448
}
449
}
450
451
+ (NSNumber *) getNSWindowDisplayID_AppKitThread:(NSWindow *)window {
452
AWT_ASSERT_APPKIT_THREAD;
453
NSScreen *screen = [window screen];
454
NSDictionary *deviceDescription = [screen deviceDescription];
455
return [deviceDescription objectForKey:@"NSScreenNumber"];
456
}
457
458
- (void) dealloc {
459
AWT_ASSERT_APPKIT_THREAD;
460
461
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
462
[self.javaPlatformWindow setJObject:nil withEnv:env];
463
self.javaPlatformWindow = nil;
464
self.nsWindow = nil;
465
self.ownerWindow = nil;
466
[super dealloc];
467
}
468
469
// Tests whether window is blocked by modal dialog/window
470
- (BOOL) isBlocked {
471
BOOL isBlocked = NO;
472
473
JNIEnv *env = [ThreadUtilities getJNIEnv];
474
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
475
if (platformWindow != NULL) {
476
static JNF_MEMBER_CACHE(jm_isBlocked, jc_CPlatformWindow, "isBlocked", "()Z");
477
isBlocked = JNFCallBooleanMethod(env, platformWindow, jm_isBlocked) == JNI_TRUE ? YES : NO;
478
(*env)->DeleteLocalRef(env, platformWindow);
479
}
480
481
return isBlocked;
482
}
483
484
- (BOOL) isSimpleWindowOwnedByEmbeddedFrame {
485
BOOL isSimpleWindowOwnedByEmbeddedFrame = NO;
486
487
JNIEnv *env = [ThreadUtilities getJNIEnv];
488
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
489
if (platformWindow != NULL) {
490
static JNF_MEMBER_CACHE(jm_isBlocked, jc_CPlatformWindow, "isSimpleWindowOwnedByEmbeddedFrame", "()Z");
491
isSimpleWindowOwnedByEmbeddedFrame = JNFCallBooleanMethod(env, platformWindow, jm_isBlocked) == JNI_TRUE ? YES : NO;
492
(*env)->DeleteLocalRef(env, platformWindow);
493
}
494
495
return isSimpleWindowOwnedByEmbeddedFrame;
496
}
497
498
// Tests whether the corresponding Java platform window is visible or not
499
+ (BOOL) isJavaPlatformWindowVisible:(NSWindow *)window {
500
BOOL isVisible = NO;
501
502
if ([AWTWindow isAWTWindow:window] && [window delegate] != nil) {
503
AWTWindow *awtWindow = (AWTWindow *)[window delegate];
504
[AWTToolkit eventCountPlusPlus];
505
506
JNIEnv *env = [ThreadUtilities getJNIEnv];
507
jobject platformWindow = [awtWindow.javaPlatformWindow jObjectWithEnv:env];
508
if (platformWindow != NULL) {
509
static JNF_MEMBER_CACHE(jm_isVisible, jc_CPlatformWindow, "isVisible", "()Z");
510
isVisible = JNFCallBooleanMethod(env, platformWindow, jm_isVisible) == JNI_TRUE ? YES : NO;
511
(*env)->DeleteLocalRef(env, platformWindow);
512
513
}
514
}
515
return isVisible;
516
}
517
518
// Orders window's childs based on the current focus state
519
- (void) orderChildWindows:(BOOL)focus {
520
AWT_ASSERT_APPKIT_THREAD;
521
522
if (self.isMinimizing || [self isBlocked]) {
523
// Do not perform any ordering, if iconify is in progress
524
// or the window is blocked by a modal window
525
return;
526
}
527
528
NSEnumerator *windowEnumerator = [[NSApp windows]objectEnumerator];
529
NSWindow *window;
530
while ((window = [windowEnumerator nextObject]) != nil) {
531
if ([AWTWindow isJavaPlatformWindowVisible:window]) {
532
AWTWindow *awtWindow = (AWTWindow *)[window delegate];
533
AWTWindow *owner = awtWindow.ownerWindow;
534
if (IS(awtWindow.styleBits, ALWAYS_ON_TOP)) {
535
// Do not order 'always on top' windows
536
continue;
537
}
538
while (awtWindow.ownerWindow != nil) {
539
if (awtWindow.ownerWindow == self) {
540
if (focus) {
541
// Move the childWindow to floating level
542
// so it will appear in front of its
543
// parent which owns the focus
544
[window setLevel:NSFloatingWindowLevel];
545
} else {
546
// Focus owner has changed, move the childWindow
547
// back to normal window level
548
[window setLevel:NSNormalWindowLevel];
549
}
550
// The childWindow should be displayed in front of
551
// its nearest parentWindow
552
[window orderWindow:NSWindowAbove relativeTo:[owner.nsWindow windowNumber]];
553
break;
554
}
555
awtWindow = awtWindow.ownerWindow;
556
}
557
}
558
}
559
}
560
561
// NSWindow overrides
562
- (BOOL) canBecomeKeyWindow {
563
AWT_ASSERT_APPKIT_THREAD;
564
return self.isEnabled && (IS(self.styleBits, SHOULD_BECOME_KEY) || [self isSimpleWindowOwnedByEmbeddedFrame]);
565
}
566
567
- (BOOL) canBecomeMainWindow {
568
AWT_ASSERT_APPKIT_THREAD;
569
if (!self.isEnabled) {
570
// Native system can bring up the NSWindow to
571
// the top even if the window is not main.
572
// We should bring up the modal dialog manually
573
[AWTToolkit eventCountPlusPlus];
574
575
JNIEnv *env = [ThreadUtilities getJNIEnv];
576
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
577
if (platformWindow != NULL) {
578
static JNF_MEMBER_CACHE(jm_checkBlockingAndOrder, jc_CPlatformWindow,
579
"checkBlockingAndOrder", "()Z");
580
JNFCallBooleanMethod(env, platformWindow, jm_checkBlockingAndOrder);
581
(*env)->DeleteLocalRef(env, platformWindow);
582
}
583
}
584
585
return self.isEnabled && IS(self.styleBits, SHOULD_BECOME_MAIN);
586
}
587
588
- (BOOL) worksWhenModal {
589
AWT_ASSERT_APPKIT_THREAD;
590
return IS(self.styleBits, MODAL_EXCLUDED);
591
}
592
593
594
// NSWindowDelegate methods
595
596
- (void) _deliverMoveResizeEvent {
597
AWT_ASSERT_APPKIT_THREAD;
598
599
// deliver the event if this is a user-initiated live resize or as a side-effect
600
// of a Java initiated resize, because AppKit can override the bounds and force
601
// the bounds of the window to avoid the Dock or remain on screen.
602
[AWTToolkit eventCountPlusPlus];
603
JNIEnv *env = [ThreadUtilities getJNIEnv];
604
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
605
if (platformWindow == NULL) {
606
// TODO: create generic AWT assert
607
}
608
609
NSRect frame = ConvertNSScreenRect(env, [self.nsWindow frame]);
610
611
static JNF_MEMBER_CACHE(jm_deliverMoveResizeEvent, jc_CPlatformWindow, "deliverMoveResizeEvent", "(IIIIZ)V");
612
JNFCallVoidMethod(env, platformWindow, jm_deliverMoveResizeEvent,
613
(jint)frame.origin.x,
614
(jint)frame.origin.y,
615
(jint)frame.size.width,
616
(jint)frame.size.height,
617
(jboolean)[self.nsWindow inLiveResize]);
618
(*env)->DeleteLocalRef(env, platformWindow);
619
620
[AWTWindow synthesizeMouseEnteredExitedEventsForAllWindows];
621
}
622
623
- (void)windowDidMove:(NSNotification *)notification {
624
AWT_ASSERT_APPKIT_THREAD;
625
626
[self _deliverMoveResizeEvent];
627
}
628
629
- (void)windowDidResize:(NSNotification *)notification {
630
AWT_ASSERT_APPKIT_THREAD;
631
632
[self _deliverMoveResizeEvent];
633
}
634
635
- (void)windowDidExpose:(NSNotification *)notification {
636
AWT_ASSERT_APPKIT_THREAD;
637
638
[AWTToolkit eventCountPlusPlus];
639
// TODO: don't see this callback invoked anytime so we track
640
// window exposing in _setVisible:(BOOL)
641
}
642
643
// Hides/shows window's childs during iconify/de-iconify operation
644
- (void) iconifyChildWindows:(BOOL)iconify {
645
AWT_ASSERT_APPKIT_THREAD;
646
647
NSEnumerator *windowEnumerator = [[NSApp windows]objectEnumerator];
648
NSWindow *window;
649
while ((window = [windowEnumerator nextObject]) != nil) {
650
if ([AWTWindow isJavaPlatformWindowVisible:window]) {
651
AWTWindow *awtWindow = (AWTWindow *)[window delegate];
652
while (awtWindow.ownerWindow != nil) {
653
if (awtWindow.ownerWindow == self) {
654
if (iconify) {
655
[window orderOut:window];
656
} else {
657
[window orderFront:window];
658
}
659
break;
660
}
661
awtWindow = awtWindow.ownerWindow;
662
}
663
}
664
}
665
}
666
667
- (void) _deliverIconify:(BOOL)iconify {
668
AWT_ASSERT_APPKIT_THREAD;
669
670
[AWTToolkit eventCountPlusPlus];
671
JNIEnv *env = [ThreadUtilities getJNIEnv];
672
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
673
if (platformWindow != NULL) {
674
static JNF_MEMBER_CACHE(jm_deliverIconify, jc_CPlatformWindow, "deliverIconify", "(Z)V");
675
JNFCallVoidMethod(env, platformWindow, jm_deliverIconify, iconify);
676
(*env)->DeleteLocalRef(env, platformWindow);
677
}
678
}
679
680
- (void)windowWillMiniaturize:(NSNotification *)notification {
681
AWT_ASSERT_APPKIT_THREAD;
682
683
self.isMinimizing = YES;
684
685
JNIEnv *env = [ThreadUtilities getJNIEnv];
686
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
687
if (platformWindow != NULL) {
688
static JNF_MEMBER_CACHE(jm_windowWillMiniaturize, jc_CPlatformWindow, "windowWillMiniaturize", "()V");
689
JNFCallVoidMethod(env, platformWindow, jm_windowWillMiniaturize);
690
(*env)->DeleteLocalRef(env, platformWindow);
691
}
692
// Excplicitly make myself a key window to avoid possible
693
// negative visual effects during iconify operation
694
[self.nsWindow makeKeyAndOrderFront:self.nsWindow];
695
[self iconifyChildWindows:YES];
696
}
697
698
- (void)windowDidMiniaturize:(NSNotification *)notification {
699
AWT_ASSERT_APPKIT_THREAD;
700
701
[self _deliverIconify:JNI_TRUE];
702
self.isMinimizing = NO;
703
}
704
705
- (void)windowDidDeminiaturize:(NSNotification *)notification {
706
AWT_ASSERT_APPKIT_THREAD;
707
708
[self _deliverIconify:JNI_FALSE];
709
[self iconifyChildWindows:NO];
710
}
711
712
- (void) _deliverWindowFocusEvent:(BOOL)focused oppositeWindow:(AWTWindow *)opposite {
713
//AWT_ASSERT_APPKIT_THREAD;
714
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
715
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
716
if (platformWindow != NULL) {
717
jobject oppositeWindow = [opposite.javaPlatformWindow jObjectWithEnv:env];
718
719
static JNF_MEMBER_CACHE(jm_deliverWindowFocusEvent, jc_CPlatformWindow, "deliverWindowFocusEvent", "(ZLsun/lwawt/macosx/CPlatformWindow;)V");
720
JNFCallVoidMethod(env, platformWindow, jm_deliverWindowFocusEvent, (jboolean)focused, oppositeWindow);
721
(*env)->DeleteLocalRef(env, platformWindow);
722
(*env)->DeleteLocalRef(env, oppositeWindow);
723
}
724
}
725
726
727
- (void) windowDidBecomeKey: (NSNotification *) notification {
728
AWT_ASSERT_APPKIT_THREAD;
729
[AWTToolkit eventCountPlusPlus];
730
AWTWindow *opposite = [AWTWindow lastKeyWindow];
731
732
// Finds appropriate menubar in our hierarchy,
733
AWTWindow *awtWindow = self;
734
while (awtWindow.ownerWindow != nil) {
735
awtWindow = awtWindow.ownerWindow;
736
}
737
738
CMenuBar *menuBar = nil;
739
BOOL isDisabled = NO;
740
if ([awtWindow.nsWindow isVisible]){
741
menuBar = awtWindow.javaMenuBar;
742
isDisabled = !awtWindow.isEnabled;
743
}
744
745
if (menuBar == nil) {
746
menuBar = [[ApplicationDelegate sharedDelegate] defaultMenuBar];
747
isDisabled = NO;
748
}
749
750
[CMenuBar activate:menuBar modallyDisabled:isDisabled];
751
752
[AWTWindow setLastKeyWindow:nil];
753
754
[self _deliverWindowFocusEvent:YES oppositeWindow: opposite];
755
[self orderChildWindows:YES];
756
}
757
758
- (void) windowDidResignKey: (NSNotification *) notification {
759
// TODO: check why sometimes at start is invoked *not* on AppKit main thread.
760
AWT_ASSERT_APPKIT_THREAD;
761
[AWTToolkit eventCountPlusPlus];
762
[self.javaMenuBar deactivate];
763
764
// In theory, this might cause flickering if the window gaining focus
765
// has its own menu. However, I couldn't reproduce it on practice, so
766
// perhaps this is a non issue.
767
CMenuBar* defaultMenu = [[ApplicationDelegate sharedDelegate] defaultMenuBar];
768
if (defaultMenu != nil) {
769
[CMenuBar activate:defaultMenu modallyDisabled:NO];
770
}
771
772
// the new key window
773
NSWindow *keyWindow = [NSApp keyWindow];
774
AWTWindow *opposite = nil;
775
if ([AWTWindow isAWTWindow: keyWindow]) {
776
opposite = (AWTWindow *)[keyWindow delegate];
777
[AWTWindow setLastKeyWindow: self];
778
} else {
779
[AWTWindow setLastKeyWindow: nil];
780
}
781
782
[self _deliverWindowFocusEvent:NO oppositeWindow: opposite];
783
[self orderChildWindows:NO];
784
}
785
786
- (void) windowDidBecomeMain: (NSNotification *) notification {
787
AWT_ASSERT_APPKIT_THREAD;
788
[AWTToolkit eventCountPlusPlus];
789
790
JNIEnv *env = [ThreadUtilities getJNIEnv];
791
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
792
if (platformWindow != NULL) {
793
static JNF_MEMBER_CACHE(jm_windowDidBecomeMain, jc_CPlatformWindow, "windowDidBecomeMain", "()V");
794
JNFCallVoidMethod(env, platformWindow, jm_windowDidBecomeMain);
795
(*env)->DeleteLocalRef(env, platformWindow);
796
}
797
}
798
799
- (BOOL)windowShouldClose:(id)sender {
800
AWT_ASSERT_APPKIT_THREAD;
801
[AWTToolkit eventCountPlusPlus];
802
JNIEnv *env = [ThreadUtilities getJNIEnv];
803
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
804
if (platformWindow != NULL) {
805
static JNF_MEMBER_CACHE(jm_deliverWindowClosingEvent, jc_CPlatformWindow, "deliverWindowClosingEvent", "()V");
806
JNFCallVoidMethod(env, platformWindow, jm_deliverWindowClosingEvent);
807
(*env)->DeleteLocalRef(env, platformWindow);
808
}
809
// The window will be closed (if allowed) as result of sending Java event
810
return NO;
811
}
812
813
814
- (void)_notifyFullScreenOp:(jint)op withEnv:(JNIEnv *)env {
815
static JNF_CLASS_CACHE(jc_FullScreenHandler, "com/apple/eawt/FullScreenHandler");
816
static JNF_STATIC_MEMBER_CACHE(jm_notifyFullScreenOperation, jc_FullScreenHandler, "handleFullScreenEventFromNative", "(Ljava/awt/Window;I)V");
817
static JNF_MEMBER_CACHE(jf_target, jc_CPlatformWindow, "target", "Ljava/awt/Window;");
818
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
819
if (platformWindow != NULL) {
820
jobject awtWindow = JNFGetObjectField(env, platformWindow, jf_target);
821
if (awtWindow != NULL) {
822
JNFCallStaticVoidMethod(env, jm_notifyFullScreenOperation, awtWindow, op);
823
(*env)->DeleteLocalRef(env, awtWindow);
824
}
825
(*env)->DeleteLocalRef(env, platformWindow);
826
}
827
}
828
829
830
- (void)windowWillEnterFullScreen:(NSNotification *)notification {
831
static JNF_MEMBER_CACHE(jm_windowWillEnterFullScreen, jc_CPlatformWindow, "windowWillEnterFullScreen", "()V");
832
JNIEnv *env = [ThreadUtilities getJNIEnv];
833
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
834
if (platformWindow != NULL) {
835
JNFCallVoidMethod(env, platformWindow, jm_windowWillEnterFullScreen);
836
[self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_WILL_ENTER withEnv:env];
837
(*env)->DeleteLocalRef(env, platformWindow);
838
}
839
}
840
841
- (void)windowDidEnterFullScreen:(NSNotification *)notification {
842
static JNF_MEMBER_CACHE(jm_windowDidEnterFullScreen, jc_CPlatformWindow, "windowDidEnterFullScreen", "()V");
843
JNIEnv *env = [ThreadUtilities getJNIEnv];
844
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
845
if (platformWindow != NULL) {
846
JNFCallVoidMethod(env, platformWindow, jm_windowDidEnterFullScreen);
847
[self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_DID_ENTER withEnv:env];
848
(*env)->DeleteLocalRef(env, platformWindow);
849
}
850
[AWTWindow synthesizeMouseEnteredExitedEventsForAllWindows];
851
}
852
853
- (void)windowWillExitFullScreen:(NSNotification *)notification {
854
static JNF_MEMBER_CACHE(jm_windowWillExitFullScreen, jc_CPlatformWindow, "windowWillExitFullScreen", "()V");
855
JNIEnv *env = [ThreadUtilities getJNIEnv];
856
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
857
if (platformWindow != NULL) {
858
JNFCallVoidMethod(env, platformWindow, jm_windowWillExitFullScreen);
859
[self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_WILL_EXIT withEnv:env];
860
(*env)->DeleteLocalRef(env, platformWindow);
861
}
862
}
863
864
- (void)windowDidExitFullScreen:(NSNotification *)notification {
865
static JNF_MEMBER_CACHE(jm_windowDidExitFullScreen, jc_CPlatformWindow, "windowDidExitFullScreen", "()V");
866
JNIEnv *env = [ThreadUtilities getJNIEnv];
867
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
868
if (platformWindow != NULL) {
869
JNFCallVoidMethod(env, platformWindow, jm_windowDidExitFullScreen);
870
[self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_DID_EXIT withEnv:env];
871
(*env)->DeleteLocalRef(env, platformWindow);
872
}
873
[AWTWindow synthesizeMouseEnteredExitedEventsForAllWindows];
874
}
875
876
- (void)sendEvent:(NSEvent *)event {
877
if ([event type] == NSLeftMouseDown || [event type] == NSRightMouseDown || [event type] == NSOtherMouseDown) {
878
if ([self isBlocked]) {
879
// Move parent windows to front and make sure that a child window is displayed
880
// in front of its nearest parent.
881
if (self.ownerWindow != nil) {
882
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
883
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
884
if (platformWindow != NULL) {
885
static JNF_MEMBER_CACHE(jm_orderAboveSiblings, jc_CPlatformWindow, "orderAboveSiblings", "()V");
886
JNFCallVoidMethod(env,platformWindow, jm_orderAboveSiblings);
887
(*env)->DeleteLocalRef(env, platformWindow);
888
}
889
}
890
[self orderChildWindows:YES];
891
}
892
893
NSPoint p = [NSEvent mouseLocation];
894
NSRect frame = [self.nsWindow frame];
895
NSRect contentRect = [self.nsWindow contentRectForFrameRect:frame];
896
897
// Check if the click happened in the non-client area (title bar)
898
if (p.y >= (frame.origin.y + contentRect.size.height)) {
899
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
900
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
901
if (platformWindow != NULL) {
902
// Currently, no need to deliver the whole NSEvent.
903
static JNF_MEMBER_CACHE(jm_deliverNCMouseDown, jc_CPlatformWindow, "deliverNCMouseDown", "()V");
904
JNFCallVoidMethod(env, platformWindow, jm_deliverNCMouseDown);
905
(*env)->DeleteLocalRef(env, platformWindow);
906
}
907
}
908
}
909
}
910
911
- (void)constrainSize:(NSSize*)size {
912
float minWidth = 0.f, minHeight = 0.f;
913
914
if (IS(self.styleBits, DECORATED)) {
915
NSRect frame = [self.nsWindow frame];
916
NSRect contentRect = [NSWindow contentRectForFrameRect:frame styleMask:[self.nsWindow styleMask]];
917
918
float top = frame.size.height - contentRect.size.height;
919
float left = contentRect.origin.x - frame.origin.x;
920
float bottom = contentRect.origin.y - frame.origin.y;
921
float right = frame.size.width - (contentRect.size.width + left);
922
923
// Speculative estimation: 80 - enough for window decorations controls
924
minWidth += left + right + 80;
925
minHeight += top + bottom;
926
}
927
928
minWidth = MAX(1.f, minWidth);
929
minHeight = MAX(1.f, minHeight);
930
931
size->width = MAX(size->width, minWidth);
932
size->height = MAX(size->height, minHeight);
933
}
934
935
- (void) setEnabled: (BOOL)flag {
936
self.isEnabled = flag;
937
938
if (IS(self.styleBits, CLOSEABLE)) {
939
[[self.nsWindow standardWindowButton:NSWindowCloseButton] setEnabled: flag];
940
}
941
942
if (IS(self.styleBits, MINIMIZABLE)) {
943
[[self.nsWindow standardWindowButton:NSWindowMiniaturizeButton] setEnabled: flag];
944
}
945
946
if (IS(self.styleBits, ZOOMABLE)) {
947
[[self.nsWindow standardWindowButton:NSWindowZoomButton] setEnabled: flag];
948
}
949
950
if (IS(self.styleBits, RESIZABLE)) {
951
[self updateMinMaxSize:flag];
952
[self.nsWindow setShowsResizeIndicator:flag];
953
}
954
}
955
956
+ (void) setLastKeyWindow:(AWTWindow *)window {
957
[window retain];
958
[lastKeyWindow release];
959
lastKeyWindow = window;
960
}
961
962
+ (AWTWindow *) lastKeyWindow {
963
return lastKeyWindow;
964
}
965
966
- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame {
967
return !NSEqualSizes(self.nsWindow.frame.size, newFrame.size);
968
}
969
970
971
@end // AWTWindow
972
973
974
/*
975
* Class: sun_lwawt_macosx_CPlatformWindow
976
* Method: nativeCreateNSWindow
977
* Signature: (JJIIII)J
978
*/
979
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeCreateNSWindow
980
(JNIEnv *env, jobject obj, jlong contentViewPtr, jlong ownerPtr, jlong styleBits, jdouble x, jdouble y, jdouble w, jdouble h)
981
{
982
__block AWTWindow *window = nil;
983
984
JNF_COCOA_ENTER(env);
985
986
JNFWeakJObjectWrapper *platformWindow = [JNFWeakJObjectWrapper wrapperWithJObject:obj withEnv:env];
987
NSView *contentView = OBJC(contentViewPtr);
988
NSRect frameRect = NSMakeRect(x, y, w, h);
989
AWTWindow *owner = [OBJC(ownerPtr) delegate];
990
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
991
992
window = [[AWTWindow alloc] initWithPlatformWindow:platformWindow
993
ownerWindow:owner
994
styleBits:styleBits
995
frameRect:frameRect
996
contentView:contentView];
997
// the window is released is CPlatformWindow.nativeDispose()
998
999
if (window) [window.nsWindow retain];
1000
}];
1001
1002
JNF_COCOA_EXIT(env);
1003
1004
return ptr_to_jlong(window ? window.nsWindow : nil);
1005
}
1006
1007
/*
1008
* Class: sun_lwawt_macosx_CPlatformWindow
1009
* Method: nativeSetNSWindowStyleBits
1010
* Signature: (JII)V
1011
*/
1012
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowStyleBits
1013
(JNIEnv *env, jclass clazz, jlong windowPtr, jint mask, jint bits)
1014
{
1015
JNF_COCOA_ENTER(env);
1016
1017
NSWindow *nsWindow = OBJC(windowPtr);
1018
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1019
1020
AWTWindow *window = (AWTWindow*)[nsWindow delegate];
1021
1022
// scans the bit field, and only updates the values requested by the mask
1023
// (this implicitly handles the _CALLBACK_PROP_BITMASK case, since those are passive reads)
1024
jint newBits = window.styleBits & ~mask | bits & mask;
1025
1026
BOOL resized = NO;
1027
1028
// Check for a change to the full window content view option.
1029
// The content view must be resized first, otherwise the window will be resized to fit the existing
1030
// content view.
1031
if (IS(mask, FULL_WINDOW_CONTENT)) {
1032
if (IS(newBits, FULL_WINDOW_CONTENT) != IS(window.styleBits, FULL_WINDOW_CONTENT)) {
1033
NSRect frame = [nsWindow frame];
1034
NSUInteger styleMask = [AWTWindow styleMaskForStyleBits:newBits];
1035
NSRect screenContentRect = [NSWindow contentRectForFrameRect:frame styleMask:styleMask];
1036
NSRect contentFrame = NSMakeRect(screenContentRect.origin.x - frame.origin.x,
1037
screenContentRect.origin.y - frame.origin.y,
1038
screenContentRect.size.width,
1039
screenContentRect.size.height);
1040
nsWindow.contentView.frame = contentFrame;
1041
resized = YES;
1042
}
1043
}
1044
1045
// resets the NSWindow's style mask if the mask intersects any of those bits
1046
if (mask & MASK(_STYLE_PROP_BITMASK)) {
1047
[nsWindow setStyleMask:[AWTWindow styleMaskForStyleBits:newBits]];
1048
}
1049
1050
// calls methods on NSWindow to change other properties, based on the mask
1051
if (mask & MASK(_METHOD_PROP_BITMASK)) {
1052
[window setPropertiesForStyleBits:newBits mask:mask];
1053
}
1054
1055
window.styleBits = newBits;
1056
1057
if (resized) {
1058
[window _deliverMoveResizeEvent];
1059
}
1060
}];
1061
1062
JNF_COCOA_EXIT(env);
1063
}
1064
1065
/*
1066
* Class: sun_lwawt_macosx_CPlatformWindow
1067
* Method: nativeSetNSWindowMenuBar
1068
* Signature: (JJ)V
1069
*/
1070
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMenuBar
1071
(JNIEnv *env, jclass clazz, jlong windowPtr, jlong menuBarPtr)
1072
{
1073
JNF_COCOA_ENTER(env);
1074
1075
NSWindow *nsWindow = OBJC(windowPtr);
1076
CMenuBar *menuBar = OBJC(menuBarPtr);
1077
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1078
1079
AWTWindow *window = (AWTWindow*)[nsWindow delegate];
1080
1081
if ([nsWindow isKeyWindow]) {
1082
[window.javaMenuBar deactivate];
1083
}
1084
1085
window.javaMenuBar = menuBar;
1086
1087
CMenuBar* actualMenuBar = menuBar;
1088
if (actualMenuBar == nil) {
1089
actualMenuBar = [[ApplicationDelegate sharedDelegate] defaultMenuBar];
1090
}
1091
1092
if ([nsWindow isKeyWindow]) {
1093
[CMenuBar activate:actualMenuBar modallyDisabled:NO];
1094
}
1095
}];
1096
1097
JNF_COCOA_EXIT(env);
1098
}
1099
1100
/*
1101
* Class: sun_lwawt_macosx_CPlatformWindow
1102
* Method: nativeGetNSWindowInsets
1103
* Signature: (J)Ljava/awt/Insets;
1104
*/
1105
JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeGetNSWindowInsets
1106
(JNIEnv *env, jclass clazz, jlong windowPtr)
1107
{
1108
jobject ret = NULL;
1109
1110
JNF_COCOA_ENTER(env);
1111
1112
NSWindow *nsWindow = OBJC(windowPtr);
1113
__block NSRect contentRect = NSZeroRect;
1114
__block NSRect frame = NSZeroRect;
1115
1116
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
1117
1118
frame = [nsWindow frame];
1119
contentRect = [NSWindow contentRectForFrameRect:frame styleMask:[nsWindow styleMask]];
1120
}];
1121
1122
jint top = (jint)(frame.size.height - contentRect.size.height);
1123
jint left = (jint)(contentRect.origin.x - frame.origin.x);
1124
jint bottom = (jint)(contentRect.origin.y - frame.origin.y);
1125
jint right = (jint)(frame.size.width - (contentRect.size.width + left));
1126
1127
static JNF_CLASS_CACHE(jc_Insets, "java/awt/Insets");
1128
static JNF_CTOR_CACHE(jc_Insets_ctor, jc_Insets, "(IIII)V");
1129
ret = JNFNewObject(env, jc_Insets_ctor, top, left, bottom, right);
1130
1131
JNF_COCOA_EXIT(env);
1132
return ret;
1133
}
1134
1135
/*
1136
* Class: sun_lwawt_macosx_CPlatformWindow
1137
* Method: nativeSetNSWindowBounds
1138
* Signature: (JDDDD)V
1139
*/
1140
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowBounds
1141
(JNIEnv *env, jclass clazz, jlong windowPtr, jdouble originX, jdouble originY, jdouble width, jdouble height)
1142
{
1143
JNF_COCOA_ENTER(env);
1144
1145
NSRect jrect = NSMakeRect(originX, originY, width, height);
1146
1147
// TODO: not sure we need displayIfNeeded message in our view
1148
NSWindow *nsWindow = OBJC(windowPtr);
1149
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1150
1151
AWTWindow *window = (AWTWindow*)[nsWindow delegate];
1152
1153
NSRect rect = ConvertNSScreenRect(NULL, jrect);
1154
[window constrainSize:&rect.size];
1155
1156
[nsWindow setFrame:rect display:YES];
1157
1158
// only start tracking events if pointer is above the toplevel
1159
// TODO: should post an Entered event if YES.
1160
NSPoint mLocation = [NSEvent mouseLocation];
1161
[nsWindow setAcceptsMouseMovedEvents:NSPointInRect(mLocation, rect)];
1162
1163
// ensure we repaint the whole window after the resize operation
1164
// (this will also re-enable screen updates, which were disabled above)
1165
// TODO: send PaintEvent
1166
}];
1167
1168
JNF_COCOA_EXIT(env);
1169
}
1170
1171
/*
1172
* Class: sun_lwawt_macosx_CPlatformWindow
1173
* Method: nativeSetNSWindowMinMax
1174
* Signature: (JDDDD)V
1175
*/
1176
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinMax
1177
(JNIEnv *env, jclass clazz, jlong windowPtr, jdouble minW, jdouble minH, jdouble maxW, jdouble maxH)
1178
{
1179
JNF_COCOA_ENTER(env);
1180
1181
if (minW < 1) minW = 1;
1182
if (minH < 1) minH = 1;
1183
if (maxW < 1) maxW = 1;
1184
if (maxH < 1) maxH = 1;
1185
1186
NSWindow *nsWindow = OBJC(windowPtr);
1187
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1188
1189
AWTWindow *window = (AWTWindow*)[nsWindow delegate];
1190
1191
NSSize min = { minW, minH };
1192
NSSize max = { maxW, maxH };
1193
1194
[window constrainSize:&min];
1195
[window constrainSize:&max];
1196
1197
window.javaMinSize = min;
1198
window.javaMaxSize = max;
1199
[window updateMinMaxSize:IS(window.styleBits, RESIZABLE)];
1200
}];
1201
1202
JNF_COCOA_EXIT(env);
1203
}
1204
1205
/*
1206
* Class: sun_lwawt_macosx_CPlatformWindow
1207
* Method: nativePushNSWindowToBack
1208
* Signature: (J)V
1209
*/
1210
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativePushNSWindowToBack
1211
(JNIEnv *env, jclass clazz, jlong windowPtr)
1212
{
1213
JNF_COCOA_ENTER(env);
1214
1215
NSWindow *nsWindow = OBJC(windowPtr);
1216
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1217
[nsWindow orderBack:nil];
1218
// Order parent windows
1219
AWTWindow *awtWindow = (AWTWindow*)[nsWindow delegate];
1220
while (awtWindow.ownerWindow != nil) {
1221
awtWindow = awtWindow.ownerWindow;
1222
if ([AWTWindow isJavaPlatformWindowVisible:awtWindow.nsWindow]) {
1223
[awtWindow.nsWindow orderBack:nil];
1224
}
1225
}
1226
// Order child windows
1227
[(AWTWindow*)[nsWindow delegate] orderChildWindows:NO];
1228
}];
1229
1230
JNF_COCOA_EXIT(env);
1231
}
1232
1233
/*
1234
* Class: sun_lwawt_macosx_CPlatformWindow
1235
* Method: nativePushNSWindowToFront
1236
* Signature: (J)V
1237
*/
1238
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativePushNSWindowToFront
1239
(JNIEnv *env, jclass clazz, jlong windowPtr)
1240
{
1241
JNF_COCOA_ENTER(env);
1242
1243
NSWindow *nsWindow = OBJC(windowPtr);
1244
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1245
1246
if (![nsWindow isKeyWindow]) {
1247
[nsWindow makeKeyAndOrderFront:nsWindow];
1248
} else {
1249
[nsWindow orderFront:nsWindow];
1250
}
1251
}];
1252
1253
JNF_COCOA_EXIT(env);
1254
}
1255
1256
/*
1257
* Class: sun_lwawt_macosx_CPlatformWindow
1258
* Method: nativeSetNSWindowTitle
1259
* Signature: (JLjava/lang/String;)V
1260
*/
1261
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowTitle
1262
(JNIEnv *env, jclass clazz, jlong windowPtr, jstring jtitle)
1263
{
1264
JNF_COCOA_ENTER(env);
1265
1266
NSWindow *nsWindow = OBJC(windowPtr);
1267
[nsWindow performSelectorOnMainThread:@selector(setTitle:)
1268
withObject:JNFJavaToNSString(env, jtitle)
1269
waitUntilDone:NO];
1270
1271
JNF_COCOA_EXIT(env);
1272
}
1273
1274
/*
1275
* Class: sun_lwawt_macosx_CPlatformWindow
1276
* Method: nativeRevalidateNSWindowShadow
1277
* Signature: (J)V
1278
*/
1279
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeRevalidateNSWindowShadow
1280
(JNIEnv *env, jclass clazz, jlong windowPtr)
1281
{
1282
JNF_COCOA_ENTER(env);
1283
1284
NSWindow *nsWindow = OBJC(windowPtr);
1285
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1286
[nsWindow invalidateShadow];
1287
}];
1288
1289
JNF_COCOA_EXIT(env);
1290
}
1291
1292
/*
1293
* Class: sun_lwawt_macosx_CPlatformWindow
1294
* Method: nativeScreenOn_AppKitThread
1295
* Signature: (J)I
1296
*/
1297
JNIEXPORT jint JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeScreenOn_1AppKitThread
1298
(JNIEnv *env, jclass clazz, jlong windowPtr)
1299
{
1300
jint ret = 0;
1301
1302
JNF_COCOA_ENTER(env);
1303
AWT_ASSERT_APPKIT_THREAD;
1304
1305
NSWindow *nsWindow = OBJC(windowPtr);
1306
NSDictionary *props = [[nsWindow screen] deviceDescription];
1307
ret = [[props objectForKey:@"NSScreenNumber"] intValue];
1308
1309
JNF_COCOA_EXIT(env);
1310
1311
return ret;
1312
}
1313
1314
/*
1315
* Class: sun_lwawt_macosx_CPlatformWindow
1316
* Method: nativeSetNSWindowMinimizedIcon
1317
* Signature: (JJ)V
1318
*/
1319
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinimizedIcon
1320
(JNIEnv *env, jclass clazz, jlong windowPtr, jlong nsImagePtr)
1321
{
1322
JNF_COCOA_ENTER(env);
1323
1324
NSWindow *nsWindow = OBJC(windowPtr);
1325
NSImage *image = OBJC(nsImagePtr);
1326
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1327
[nsWindow setMiniwindowImage:image];
1328
}];
1329
1330
JNF_COCOA_EXIT(env);
1331
}
1332
1333
/*
1334
* Class: sun_lwawt_macosx_CPlatformWindow
1335
* Method: nativeSetNSWindowRepresentedFilename
1336
* Signature: (JLjava/lang/String;)V
1337
*/
1338
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowRepresentedFilename
1339
(JNIEnv *env, jclass clazz, jlong windowPtr, jstring filename)
1340
{
1341
JNF_COCOA_ENTER(env);
1342
1343
NSWindow *nsWindow = OBJC(windowPtr);
1344
NSURL *url = (filename == NULL) ? nil : [NSURL fileURLWithPath:JNFNormalizedNSStringForPath(env, filename)];
1345
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1346
[nsWindow setRepresentedURL:url];
1347
}];
1348
1349
JNF_COCOA_EXIT(env);
1350
}
1351
1352
/*
1353
* Class: sun_lwawt_macosx_CPlatformWindow
1354
* Method: nativeGetTopmostPlatformWindowUnderMouse
1355
* Signature: (J)V
1356
*/
1357
JNIEXPORT jobject
1358
JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeGetTopmostPlatformWindowUnderMouse
1359
(JNIEnv *env, jclass clazz)
1360
{
1361
__block jobject topmostWindowUnderMouse = nil;
1362
1363
JNF_COCOA_ENTER(env);
1364
1365
[ThreadUtilities performOnMainThreadWaiting:YES block:^{
1366
AWTWindow *awtWindow = [AWTWindow getTopmostWindowUnderMouse];
1367
if (awtWindow != nil) {
1368
topmostWindowUnderMouse = [awtWindow.javaPlatformWindow jObject];
1369
}
1370
}];
1371
1372
JNF_COCOA_EXIT(env);
1373
1374
return topmostWindowUnderMouse;
1375
}
1376
1377
/*
1378
* Class: sun_lwawt_macosx_CPlatformWindow
1379
* Method: nativeSynthesizeMouseEnteredExitedEvents
1380
* Signature: ()V
1381
*/
1382
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSynthesizeMouseEnteredExitedEvents__
1383
(JNIEnv *env, jclass clazz)
1384
{
1385
JNF_COCOA_ENTER(env);
1386
1387
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1388
[AWTWindow synthesizeMouseEnteredExitedEventsForAllWindows];
1389
}];
1390
1391
JNF_COCOA_EXIT(env);
1392
}
1393
1394
/*
1395
* Class: sun_lwawt_macosx_CPlatformWindow
1396
* Method: nativeSynthesizeMouseEnteredExitedEvents
1397
* Signature: (JI)V
1398
*/
1399
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSynthesizeMouseEnteredExitedEvents__JI
1400
(JNIEnv *env, jclass clazz, jlong windowPtr, jint eventType)
1401
{
1402
JNF_COCOA_ENTER(env);
1403
1404
if (eventType == NSMouseEntered || eventType == NSMouseExited) {
1405
NSWindow *nsWindow = OBJC(windowPtr);
1406
1407
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1408
[AWTWindow synthesizeMouseEnteredExitedEvents:nsWindow withType:eventType];
1409
}];
1410
} else {
1411
[JNFException raise:env as:kIllegalArgumentException reason:"unknown event type"];
1412
}
1413
1414
JNF_COCOA_EXIT(env);
1415
}
1416
1417
/*
1418
* Class: sun_lwawt_macosx_CPlatformWindow
1419
* Method: _toggleFullScreenMode
1420
* Signature: (J)V
1421
*/
1422
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow__1toggleFullScreenMode
1423
(JNIEnv *env, jobject peer, jlong windowPtr)
1424
{
1425
JNF_COCOA_ENTER(env);
1426
1427
NSWindow *nsWindow = OBJC(windowPtr);
1428
SEL toggleFullScreenSelector = @selector(toggleFullScreen:);
1429
if (![nsWindow respondsToSelector:toggleFullScreenSelector]) return;
1430
1431
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1432
[nsWindow performSelector:toggleFullScreenSelector withObject:nil];
1433
}];
1434
1435
JNF_COCOA_EXIT(env);
1436
}
1437
1438
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetEnabled
1439
(JNIEnv *env, jclass clazz, jlong windowPtr, jboolean isEnabled)
1440
{
1441
JNF_COCOA_ENTER(env);
1442
1443
NSWindow *nsWindow = OBJC(windowPtr);
1444
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1445
AWTWindow *window = (AWTWindow*)[nsWindow delegate];
1446
1447
[window setEnabled: isEnabled];
1448
}];
1449
1450
JNF_COCOA_EXIT(env);
1451
}
1452
1453
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeDispose
1454
(JNIEnv *env, jclass clazz, jlong windowPtr)
1455
{
1456
JNF_COCOA_ENTER(env);
1457
1458
NSWindow *nsWindow = OBJC(windowPtr);
1459
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1460
AWTWindow *window = (AWTWindow*)[nsWindow delegate];
1461
1462
if ([AWTWindow lastKeyWindow] == window) {
1463
[AWTWindow setLastKeyWindow: nil];
1464
}
1465
1466
// AWTWindow holds a reference to the NSWindow in its nsWindow
1467
// property. Unsetting the delegate allows it to be deallocated
1468
// which releases the reference. This, in turn, allows the window
1469
// itself be deallocated.
1470
[nsWindow setDelegate: nil];
1471
1472
[window release];
1473
}];
1474
1475
JNF_COCOA_EXIT(env);
1476
}
1477
1478
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeEnterFullScreenMode
1479
(JNIEnv *env, jclass clazz, jlong windowPtr)
1480
{
1481
JNF_COCOA_ENTER(env);
1482
1483
NSWindow *nsWindow = OBJC(windowPtr);
1484
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1485
AWTWindow *window = (AWTWindow*)[nsWindow delegate];
1486
NSNumber* screenID = [AWTWindow getNSWindowDisplayID_AppKitThread: nsWindow];
1487
CGDirectDisplayID aID = [screenID intValue];
1488
1489
if (CGDisplayCapture(aID) == kCGErrorSuccess) {
1490
// remove window decoration
1491
NSUInteger styleMask = [AWTWindow styleMaskForStyleBits:window.styleBits];
1492
[nsWindow setStyleMask:(styleMask & ~NSTitledWindowMask) | NSBorderlessWindowMask];
1493
1494
int shieldLevel = CGShieldingWindowLevel();
1495
window.preFullScreenLevel = [nsWindow level];
1496
[nsWindow setLevel: shieldLevel];
1497
1498
NSRect screenRect = [[nsWindow screen] frame];
1499
[nsWindow setFrame:screenRect display:YES];
1500
} else {
1501
[JNFException raise:[ThreadUtilities getJNIEnv]
1502
as:kRuntimeException
1503
reason:"Failed to enter full screen."];
1504
}
1505
}];
1506
1507
JNF_COCOA_EXIT(env);
1508
}
1509
1510
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeExitFullScreenMode
1511
(JNIEnv *env, jclass clazz, jlong windowPtr)
1512
{
1513
JNF_COCOA_ENTER(env);
1514
1515
NSWindow *nsWindow = OBJC(windowPtr);
1516
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1517
AWTWindow *window = (AWTWindow*)[nsWindow delegate];
1518
NSNumber* screenID = [AWTWindow getNSWindowDisplayID_AppKitThread: nsWindow];
1519
CGDirectDisplayID aID = [screenID intValue];
1520
1521
if (CGDisplayRelease(aID) == kCGErrorSuccess) {
1522
NSUInteger styleMask = [AWTWindow styleMaskForStyleBits:window.styleBits];
1523
[nsWindow setStyleMask:styleMask];
1524
[nsWindow setLevel: window.preFullScreenLevel];
1525
1526
// GraphicsDevice takes care of restoring pre full screen bounds
1527
} else {
1528
[JNFException raise:[ThreadUtilities getJNIEnv]
1529
as:kRuntimeException
1530
reason:"Failed to exit full screen."];
1531
}
1532
}];
1533
1534
JNF_COCOA_EXIT(env);
1535
}
1536
1537
1538