Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m
66646 views
1
/*
2
* Copyright (c) 2011, 2021, 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_STATIC_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
* Class: sun_lwawt_macosx_CPlatformWindow
1099
* Method: nativeSetAllAllowAutomaticTabbingProperty
1100
* Signature: (Z)V
1101
*/
1102
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetAllowAutomaticTabbingProperty
1103
(JNIEnv *env, jclass clazz, jboolean allowAutomaticTabbing)
1104
{
1105
JNI_COCOA_ENTER(env);
1106
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1107
if (allowAutomaticTabbing) {
1108
[NSWindow setAllowsAutomaticWindowTabbing:YES];
1109
} else {
1110
[NSWindow setAllowsAutomaticWindowTabbing:NO];
1111
}
1112
}];
1113
JNI_COCOA_EXIT(env);
1114
}
1115
1116
/*
1117
* Class: sun_lwawt_macosx_CPlatformWindow
1118
* Method: nativeCreateNSWindow
1119
* Signature: (JJIIII)J
1120
*/
1121
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeCreateNSWindow
1122
(JNIEnv *env, jobject obj, jlong contentViewPtr, jlong ownerPtr, jlong styleBits, jdouble x, jdouble y, jdouble w, jdouble h)
1123
{
1124
__block AWTWindow *window = nil;
1125
1126
JNI_COCOA_ENTER(env);
1127
1128
jobject platformWindow = (*env)->NewWeakGlobalRef(env, obj);
1129
NSView *contentView = OBJC(contentViewPtr);
1130
NSRect frameRect = NSMakeRect(x, y, w, h);
1131
AWTWindow *owner = [OBJC(ownerPtr) delegate];
1132
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
1133
1134
window = [[AWTWindow alloc] initWithPlatformWindow:platformWindow
1135
ownerWindow:owner
1136
styleBits:styleBits
1137
frameRect:frameRect
1138
contentView:contentView];
1139
// the window is released is CPlatformWindow.nativeDispose()
1140
1141
if (window) [window.nsWindow retain];
1142
}];
1143
1144
JNI_COCOA_EXIT(env);
1145
1146
return ptr_to_jlong(window ? window.nsWindow : nil);
1147
}
1148
1149
/*
1150
* Class: sun_lwawt_macosx_CPlatformWindow
1151
* Method: nativeSetNSWindowStyleBits
1152
* Signature: (JII)V
1153
*/
1154
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowStyleBits
1155
(JNIEnv *env, jclass clazz, jlong windowPtr, jint mask, jint bits)
1156
{
1157
JNI_COCOA_ENTER(env);
1158
1159
NSWindow *nsWindow = OBJC(windowPtr);
1160
1161
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1162
1163
AWTWindow *window = (AWTWindow*)[nsWindow delegate];
1164
1165
// scans the bit field, and only updates the values requested by the mask
1166
// (this implicitly handles the _CALLBACK_PROP_BITMASK case, since those are passive reads)
1167
jint newBits = window.styleBits & ~mask | bits & mask;
1168
1169
BOOL resized = NO;
1170
1171
// Check for a change to the full window content view option.
1172
// The content view must be resized first, otherwise the window will be resized to fit the existing
1173
// content view.
1174
if (IS(mask, FULL_WINDOW_CONTENT)) {
1175
if (IS(newBits, FULL_WINDOW_CONTENT) != IS(window.styleBits, FULL_WINDOW_CONTENT)) {
1176
NSRect frame = [nsWindow frame];
1177
NSUInteger styleMask = [AWTWindow styleMaskForStyleBits:newBits];
1178
NSRect screenContentRect = [NSWindow contentRectForFrameRect:frame styleMask:styleMask];
1179
NSRect contentFrame = NSMakeRect(screenContentRect.origin.x - frame.origin.x,
1180
screenContentRect.origin.y - frame.origin.y,
1181
screenContentRect.size.width,
1182
screenContentRect.size.height);
1183
nsWindow.contentView.frame = contentFrame;
1184
resized = YES;
1185
}
1186
}
1187
1188
// resets the NSWindow's style mask if the mask intersects any of those bits
1189
if (mask & MASK(_STYLE_PROP_BITMASK)) {
1190
[nsWindow setStyleMask:[AWTWindow styleMaskForStyleBits:newBits]];
1191
}
1192
1193
// calls methods on NSWindow to change other properties, based on the mask
1194
if (mask & MASK(_METHOD_PROP_BITMASK)) {
1195
[window setPropertiesForStyleBits:newBits mask:mask];
1196
}
1197
1198
window.styleBits = newBits;
1199
1200
if (resized) {
1201
[window _deliverMoveResizeEvent];
1202
}
1203
}];
1204
1205
JNI_COCOA_EXIT(env);
1206
}
1207
1208
/*
1209
* Class: sun_lwawt_macosx_CPlatformWindow
1210
* Method: nativeSetNSWindowMenuBar
1211
* Signature: (JJ)V
1212
*/
1213
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMenuBar
1214
(JNIEnv *env, jclass clazz, jlong windowPtr, jlong menuBarPtr)
1215
{
1216
JNI_COCOA_ENTER(env);
1217
1218
NSWindow *nsWindow = OBJC(windowPtr);
1219
CMenuBar *menuBar = OBJC(menuBarPtr);
1220
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1221
1222
AWTWindow *window = (AWTWindow*)[nsWindow delegate];
1223
1224
if ([nsWindow isKeyWindow] || [nsWindow isMainWindow]) {
1225
[window.javaMenuBar deactivate];
1226
}
1227
1228
window.javaMenuBar = menuBar;
1229
1230
CMenuBar* actualMenuBar = menuBar;
1231
if (actualMenuBar == nil) {
1232
actualMenuBar = [[ApplicationDelegate sharedDelegate] defaultMenuBar];
1233
}
1234
1235
if ([nsWindow isKeyWindow] || [nsWindow isMainWindow]) {
1236
[CMenuBar activate:actualMenuBar modallyDisabled:NO];
1237
}
1238
}];
1239
1240
JNI_COCOA_EXIT(env);
1241
}
1242
1243
/*
1244
* Class: sun_lwawt_macosx_CPlatformWindow
1245
* Method: nativeGetNSWindowInsets
1246
* Signature: (J)Ljava/awt/Insets;
1247
*/
1248
JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeGetNSWindowInsets
1249
(JNIEnv *env, jclass clazz, jlong windowPtr)
1250
{
1251
jobject ret = NULL;
1252
1253
JNI_COCOA_ENTER(env);
1254
1255
NSWindow *nsWindow = OBJC(windowPtr);
1256
__block NSRect contentRect = NSZeroRect;
1257
__block NSRect frame = NSZeroRect;
1258
1259
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
1260
1261
frame = [nsWindow frame];
1262
contentRect = [NSWindow contentRectForFrameRect:frame styleMask:[nsWindow styleMask]];
1263
}];
1264
1265
jint top = (jint)(frame.size.height - contentRect.size.height);
1266
jint left = (jint)(contentRect.origin.x - frame.origin.x);
1267
jint bottom = (jint)(contentRect.origin.y - frame.origin.y);
1268
jint right = (jint)(frame.size.width - (contentRect.size.width + left));
1269
1270
DECLARE_CLASS_RETURN(jc_Insets, "java/awt/Insets", NULL);
1271
DECLARE_METHOD_RETURN(jc_Insets_ctor, jc_Insets, "<init>", "(IIII)V", NULL);
1272
ret = (*env)->NewObject(env, jc_Insets, jc_Insets_ctor, top, left, bottom, right);
1273
1274
JNI_COCOA_EXIT(env);
1275
return ret;
1276
}
1277
1278
/*
1279
* Class: sun_lwawt_macosx_CPlatformWindow
1280
* Method: nativeSetNSWindowBounds
1281
* Signature: (JDDDD)V
1282
*/
1283
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowBounds
1284
(JNIEnv *env, jclass clazz, jlong windowPtr, jdouble originX, jdouble originY, jdouble width, jdouble height)
1285
{
1286
JNI_COCOA_ENTER(env);
1287
1288
NSRect jrect = NSMakeRect(originX, originY, width, height);
1289
1290
// TODO: not sure we need displayIfNeeded message in our view
1291
NSWindow *nsWindow = OBJC(windowPtr);
1292
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1293
1294
AWTWindow *window = (AWTWindow*)[nsWindow delegate];
1295
1296
NSRect rect = ConvertNSScreenRect(NULL, jrect);
1297
[window constrainSize:&rect.size];
1298
1299
[nsWindow setFrame:rect display:YES];
1300
1301
// only start tracking events if pointer is above the toplevel
1302
// TODO: should post an Entered event if YES.
1303
NSPoint mLocation = [NSEvent mouseLocation];
1304
[nsWindow setAcceptsMouseMovedEvents:NSPointInRect(mLocation, rect)];
1305
1306
// ensure we repaint the whole window after the resize operation
1307
// (this will also re-enable screen updates, which were disabled above)
1308
// TODO: send PaintEvent
1309
1310
// the macOS may ignore our "setFrame" request, in this, case the
1311
// windowDidMove() will not come and we need to manually resync the
1312
// "java.awt.Window" and NSWindow locations, because "java.awt.Window"
1313
// already uses location ignored by the macOS.
1314
// see sun.lwawt.LWWindowPeer#notifyReshape()
1315
if (!NSEqualRects(rect, [nsWindow frame])) {
1316
[window _deliverMoveResizeEvent];
1317
}
1318
}];
1319
1320
JNI_COCOA_EXIT(env);
1321
}
1322
1323
/*
1324
* Class: sun_lwawt_macosx_CPlatformWindow
1325
* Method: nativeSetNSWindowStandardFrame
1326
* Signature: (JDDDD)V
1327
*/
1328
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowStandardFrame
1329
(JNIEnv *env, jclass clazz, jlong windowPtr, jdouble originX, jdouble originY,
1330
jdouble width, jdouble height)
1331
{
1332
JNI_COCOA_ENTER(env);
1333
1334
NSRect jrect = NSMakeRect(originX, originY, width, height);
1335
1336
NSWindow *nsWindow = OBJC(windowPtr);
1337
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1338
1339
NSRect rect = ConvertNSScreenRect(NULL, jrect);
1340
AWTWindow *window = (AWTWindow*)[nsWindow delegate];
1341
window.standardFrame = rect;
1342
}];
1343
1344
JNI_COCOA_EXIT(env);
1345
}
1346
1347
/*
1348
* Class: sun_lwawt_macosx_CPlatformWindow
1349
* Method: nativeSetNSWindowLocationByPlatform
1350
* Signature: (J)V
1351
*/
1352
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowLocationByPlatform
1353
(JNIEnv *env, jclass clazz, jlong windowPtr)
1354
{
1355
JNI_COCOA_ENTER(env);
1356
1357
NSWindow *nsWindow = OBJC(windowPtr);
1358
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1359
1360
if (NSEqualPoints(lastTopLeftPoint, NSZeroPoint)) {
1361
// This is the first usage of lastTopLeftPoint. So invoke cascadeTopLeftFromPoint
1362
// twice to avoid positioning the window's top left to zero-point, since it may
1363
// cause negative user experience.
1364
lastTopLeftPoint = [nsWindow cascadeTopLeftFromPoint:lastTopLeftPoint];
1365
}
1366
lastTopLeftPoint = [nsWindow cascadeTopLeftFromPoint:lastTopLeftPoint];
1367
}];
1368
1369
JNI_COCOA_EXIT(env);
1370
}
1371
1372
/*
1373
* Class: sun_lwawt_macosx_CPlatformWindow
1374
* Method: nativeSetNSWindowMinMax
1375
* Signature: (JDDDD)V
1376
*/
1377
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinMax
1378
(JNIEnv *env, jclass clazz, jlong windowPtr, jdouble minW, jdouble minH, jdouble maxW, jdouble maxH)
1379
{
1380
JNI_COCOA_ENTER(env);
1381
1382
if (minW < 1) minW = 1;
1383
if (minH < 1) minH = 1;
1384
if (maxW < 1) maxW = 1;
1385
if (maxH < 1) maxH = 1;
1386
1387
NSWindow *nsWindow = OBJC(windowPtr);
1388
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1389
1390
AWTWindow *window = (AWTWindow*)[nsWindow delegate];
1391
1392
NSSize min = { minW, minH };
1393
NSSize max = { maxW, maxH };
1394
1395
[window constrainSize:&min];
1396
[window constrainSize:&max];
1397
1398
window.javaMinSize = min;
1399
window.javaMaxSize = max;
1400
[window updateMinMaxSize:IS(window.styleBits, RESIZABLE)];
1401
}];
1402
1403
JNI_COCOA_EXIT(env);
1404
}
1405
1406
/*
1407
* Class: sun_lwawt_macosx_CPlatformWindow
1408
* Method: nativePushNSWindowToBack
1409
* Signature: (J)V
1410
*/
1411
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativePushNSWindowToBack
1412
(JNIEnv *env, jclass clazz, jlong windowPtr)
1413
{
1414
JNI_COCOA_ENTER(env);
1415
1416
NSWindow *nsWindow = OBJC(windowPtr);
1417
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1418
[nsWindow orderBack:nil];
1419
// Order parent windows
1420
AWTWindow *awtWindow = (AWTWindow*)[nsWindow delegate];
1421
while (awtWindow.ownerWindow != nil) {
1422
awtWindow = awtWindow.ownerWindow;
1423
if ([AWTWindow isJavaPlatformWindowVisible:awtWindow.nsWindow]) {
1424
[awtWindow.nsWindow orderBack:nil];
1425
}
1426
}
1427
// Order child windows
1428
[(AWTWindow*)[nsWindow delegate] orderChildWindows:NO];
1429
}];
1430
1431
JNI_COCOA_EXIT(env);
1432
}
1433
1434
/*
1435
* Class: sun_lwawt_macosx_CPlatformWindow
1436
* Method: nativePushNSWindowToFront
1437
* Signature: (J)V
1438
*/
1439
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativePushNSWindowToFront
1440
(JNIEnv *env, jclass clazz, jlong windowPtr)
1441
{
1442
JNI_COCOA_ENTER(env);
1443
1444
NSWindow *nsWindow = OBJC(windowPtr);
1445
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1446
1447
if (![nsWindow isKeyWindow]) {
1448
[nsWindow makeKeyAndOrderFront:nsWindow];
1449
} else {
1450
[nsWindow orderFront:nsWindow];
1451
}
1452
}];
1453
1454
JNI_COCOA_EXIT(env);
1455
}
1456
1457
/*
1458
* Class: sun_lwawt_macosx_CPlatformWindow
1459
* Method: nativeSetNSWindowTitle
1460
* Signature: (JLjava/lang/String;)V
1461
*/
1462
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowTitle
1463
(JNIEnv *env, jclass clazz, jlong windowPtr, jstring jtitle)
1464
{
1465
JNI_COCOA_ENTER(env);
1466
1467
NSWindow *nsWindow = OBJC(windowPtr);
1468
[nsWindow performSelectorOnMainThread:@selector(setTitle:)
1469
withObject:JavaStringToNSString(env, jtitle)
1470
waitUntilDone:NO];
1471
1472
JNI_COCOA_EXIT(env);
1473
}
1474
1475
/*
1476
* Class: sun_lwawt_macosx_CPlatformWindow
1477
* Method: nativeRevalidateNSWindowShadow
1478
* Signature: (J)V
1479
*/
1480
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeRevalidateNSWindowShadow
1481
(JNIEnv *env, jclass clazz, jlong windowPtr)
1482
{
1483
JNI_COCOA_ENTER(env);
1484
1485
NSWindow *nsWindow = OBJC(windowPtr);
1486
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1487
[nsWindow invalidateShadow];
1488
}];
1489
1490
JNI_COCOA_EXIT(env);
1491
}
1492
1493
/*
1494
* Class: sun_lwawt_macosx_CPlatformWindow
1495
* Method: nativeScreenOn_AppKitThread
1496
* Signature: (J)I
1497
*/
1498
JNIEXPORT jint JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeScreenOn_1AppKitThread
1499
(JNIEnv *env, jclass clazz, jlong windowPtr)
1500
{
1501
jint ret = 0;
1502
1503
JNI_COCOA_ENTER(env);
1504
AWT_ASSERT_APPKIT_THREAD;
1505
1506
NSWindow *nsWindow = OBJC(windowPtr);
1507
NSDictionary *props = [[nsWindow screen] deviceDescription];
1508
ret = [[props objectForKey:@"NSScreenNumber"] intValue];
1509
1510
JNI_COCOA_EXIT(env);
1511
1512
return ret;
1513
}
1514
1515
/*
1516
* Class: sun_lwawt_macosx_CPlatformWindow
1517
* Method: nativeSetNSWindowMinimizedIcon
1518
* Signature: (JJ)V
1519
*/
1520
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinimizedIcon
1521
(JNIEnv *env, jclass clazz, jlong windowPtr, jlong nsImagePtr)
1522
{
1523
JNI_COCOA_ENTER(env);
1524
1525
NSWindow *nsWindow = OBJC(windowPtr);
1526
NSImage *image = OBJC(nsImagePtr);
1527
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1528
[nsWindow setMiniwindowImage:image];
1529
}];
1530
1531
JNI_COCOA_EXIT(env);
1532
}
1533
1534
/*
1535
* Class: sun_lwawt_macosx_CPlatformWindow
1536
* Method: nativeSetNSWindowRepresentedFilename
1537
* Signature: (JLjava/lang/String;)V
1538
*/
1539
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowRepresentedFilename
1540
(JNIEnv *env, jclass clazz, jlong windowPtr, jstring filename)
1541
{
1542
JNI_COCOA_ENTER(env);
1543
1544
NSWindow *nsWindow = OBJC(windowPtr);
1545
NSURL *url = (filename == NULL) ? nil : [NSURL fileURLWithPath:NormalizedPathNSStringFromJavaString(env, filename)];
1546
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1547
[nsWindow setRepresentedURL:url];
1548
}];
1549
1550
JNI_COCOA_EXIT(env);
1551
}
1552
1553
/*
1554
* Class: sun_lwawt_macosx_CPlatformWindow
1555
* Method: nativeGetTopmostPlatformWindowUnderMouse
1556
* Signature: (J)V
1557
*/
1558
JNIEXPORT jobject
1559
JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeGetTopmostPlatformWindowUnderMouse
1560
(JNIEnv *env, jclass clazz)
1561
{
1562
__block jobject topmostWindowUnderMouse = nil;
1563
1564
JNI_COCOA_ENTER(env);
1565
1566
[ThreadUtilities performOnMainThreadWaiting:YES block:^{
1567
AWTWindow *awtWindow = [AWTWindow getTopmostWindowUnderMouse];
1568
if (awtWindow != nil) {
1569
topmostWindowUnderMouse = awtWindow.javaPlatformWindow;
1570
}
1571
}];
1572
1573
JNI_COCOA_EXIT(env);
1574
1575
return topmostWindowUnderMouse;
1576
}
1577
1578
/*
1579
* Class: sun_lwawt_macosx_CPlatformWindow
1580
* Method: nativeSynthesizeMouseEnteredExitedEvents
1581
* Signature: ()V
1582
*/
1583
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSynthesizeMouseEnteredExitedEvents__
1584
(JNIEnv *env, jclass clazz)
1585
{
1586
JNI_COCOA_ENTER(env);
1587
1588
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1589
[AWTWindow synthesizeMouseEnteredExitedEventsForAllWindows];
1590
}];
1591
1592
JNI_COCOA_EXIT(env);
1593
}
1594
1595
/*
1596
* Class: sun_lwawt_macosx_CPlatformWindow
1597
* Method: nativeSynthesizeMouseEnteredExitedEvents
1598
* Signature: (JI)V
1599
*/
1600
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSynthesizeMouseEnteredExitedEvents__JI
1601
(JNIEnv *env, jclass clazz, jlong windowPtr, jint eventType)
1602
{
1603
JNI_COCOA_ENTER(env);
1604
1605
if (eventType == NSMouseEntered || eventType == NSMouseExited) {
1606
NSWindow *nsWindow = OBJC(windowPtr);
1607
1608
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1609
[AWTWindow synthesizeMouseEnteredExitedEvents:nsWindow withType:eventType];
1610
}];
1611
} else {
1612
JNU_ThrowIllegalArgumentException(env, "unknown event type");
1613
}
1614
1615
JNI_COCOA_EXIT(env);
1616
}
1617
1618
/*
1619
* Class: sun_lwawt_macosx_CPlatformWindow
1620
* Method: _toggleFullScreenMode
1621
* Signature: (J)V
1622
*/
1623
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow__1toggleFullScreenMode
1624
(JNIEnv *env, jobject peer, jlong windowPtr)
1625
{
1626
JNI_COCOA_ENTER(env);
1627
1628
NSWindow *nsWindow = OBJC(windowPtr);
1629
SEL toggleFullScreenSelector = @selector(toggleFullScreen:);
1630
if (![nsWindow respondsToSelector:toggleFullScreenSelector]) return;
1631
1632
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1633
[nsWindow performSelector:toggleFullScreenSelector withObject:nil];
1634
}];
1635
1636
JNI_COCOA_EXIT(env);
1637
}
1638
1639
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetEnabled
1640
(JNIEnv *env, jclass clazz, jlong windowPtr, jboolean isEnabled)
1641
{
1642
JNI_COCOA_ENTER(env);
1643
1644
NSWindow *nsWindow = OBJC(windowPtr);
1645
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1646
AWTWindow *window = (AWTWindow*)[nsWindow delegate];
1647
1648
[window setEnabled: isEnabled];
1649
}];
1650
1651
JNI_COCOA_EXIT(env);
1652
}
1653
1654
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeDispose
1655
(JNIEnv *env, jclass clazz, jlong windowPtr)
1656
{
1657
JNI_COCOA_ENTER(env);
1658
1659
NSWindow *nsWindow = OBJC(windowPtr);
1660
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1661
AWTWindow *window = (AWTWindow*)[nsWindow delegate];
1662
1663
if ([AWTWindow lastKeyWindow] == window) {
1664
[AWTWindow setLastKeyWindow: nil];
1665
}
1666
1667
// AWTWindow holds a reference to the NSWindow in its nsWindow
1668
// property. Unsetting the delegate allows it to be deallocated
1669
// which releases the reference. This, in turn, allows the window
1670
// itself be deallocated.
1671
[nsWindow setDelegate: nil];
1672
1673
[window release];
1674
}];
1675
1676
JNI_COCOA_EXIT(env);
1677
}
1678
1679
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeEnterFullScreenMode
1680
(JNIEnv *env, jclass clazz, jlong windowPtr)
1681
{
1682
JNI_COCOA_ENTER(env);
1683
1684
NSWindow *nsWindow = OBJC(windowPtr);
1685
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1686
AWTWindow *window = (AWTWindow*)[nsWindow delegate];
1687
NSNumber* screenID = [AWTWindow getNSWindowDisplayID_AppKitThread: nsWindow];
1688
CGDirectDisplayID aID = [screenID intValue];
1689
1690
if (CGDisplayCapture(aID) == kCGErrorSuccess) {
1691
// remove window decoration
1692
NSUInteger styleMask = [AWTWindow styleMaskForStyleBits:window.styleBits];
1693
[nsWindow setStyleMask:(styleMask & ~NSTitledWindowMask) | NSBorderlessWindowMask];
1694
1695
int shieldLevel = CGShieldingWindowLevel();
1696
window.preFullScreenLevel = [nsWindow level];
1697
[nsWindow setLevel: shieldLevel];
1698
1699
NSRect screenRect = [[nsWindow screen] frame];
1700
[nsWindow setFrame:screenRect display:YES];
1701
} else {
1702
[NSException raise:@"Java Exception" reason:@"Failed to enter full screen." userInfo:nil];
1703
}
1704
}];
1705
1706
JNI_COCOA_EXIT(env);
1707
}
1708
1709
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeExitFullScreenMode
1710
(JNIEnv *env, jclass clazz, jlong windowPtr)
1711
{
1712
JNI_COCOA_ENTER(env);
1713
1714
NSWindow *nsWindow = OBJC(windowPtr);
1715
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
1716
AWTWindow *window = (AWTWindow*)[nsWindow delegate];
1717
NSNumber* screenID = [AWTWindow getNSWindowDisplayID_AppKitThread: nsWindow];
1718
CGDirectDisplayID aID = [screenID intValue];
1719
1720
if (CGDisplayRelease(aID) == kCGErrorSuccess) {
1721
NSUInteger styleMask = [AWTWindow styleMaskForStyleBits:window.styleBits];
1722
[nsWindow setStyleMask:styleMask];
1723
[nsWindow setLevel: window.preFullScreenLevel];
1724
1725
// GraphicsDevice takes care of restoring pre full screen bounds
1726
} else {
1727
[NSException raise:@"Java Exception" reason:@"Failed to exit full screen." userInfo:nil];
1728
}
1729
}];
1730
1731
JNI_COCOA_EXIT(env);
1732
}
1733
1734
1735