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