Print this page
*** NO COMMENTS ***
Split |
Close |
Expand all |
Collapse all |
--- old/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java
+++ new/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java
1 1 /*
2 2 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation. Oracle designates this
8 8 * particular file as subject to the "Classpath" exception as provided
9 9 * by Oracle in the LICENSE file that accompanied this code.
10 10 *
11 11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 14 * version 2 for more details (a copy is included in the LICENSE file that
15 15 * accompanied this code).
16 16 *
17 17 * You should have received a copy of the GNU General Public License version
18 18 * 2 along with this work; if not, write to the Free Software Foundation,
19 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 20 *
21 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 22 * or visit www.oracle.com if you need additional information or have any
23 23 * questions.
24 24 */
25 25
26 26 package sun.lwawt.macosx;
27 27
28 28 import java.awt.*;
29 29 import java.awt.Dialog.ModalityType;
30 30 import java.awt.event.*;
31 31 import java.awt.peer.WindowPeer;
32 32 import java.beans.*;
33 33 import java.lang.reflect.InvocationTargetException;
34 34 import java.util.List;
35 35 import java.util.Objects;
36 36
37 37 import javax.swing.*;
38 38
39 39 import sun.awt.*;
40 40 import sun.java2d.SurfaceData;
41 41 import sun.java2d.opengl.CGLSurfaceData;
42 42 import sun.lwawt.*;
43 43 import sun.util.logging.PlatformLogger;
44 44
45 45 import com.apple.laf.*;
46 46 import com.apple.laf.ClientPropertyApplicator.Property;
47 47 import com.sun.awt.AWTUtilities;
48 48
49 49 public class CPlatformWindow extends CFRetainedResource implements PlatformWindow {
50 50 private native long nativeCreateNSWindow(long nsViewPtr,long ownerPtr, long styleBits, double x, double y, double w, double h);
51 51 private static native void nativeSetNSWindowStyleBits(long nsWindowPtr, int mask, int data);
52 52 private static native void nativeSetNSWindowMenuBar(long nsWindowPtr, long menuBarPtr);
53 53 private static native Insets nativeGetNSWindowInsets(long nsWindowPtr);
54 54 private static native void nativeSetNSWindowBounds(long nsWindowPtr, double x, double y, double w, double h);
55 55 private static native void nativeSetNSWindowMinMax(long nsWindowPtr, double minW, double minH, double maxW, double maxH);
56 56 private static native void nativePushNSWindowToBack(long nsWindowPtr);
57 57 private static native void nativePushNSWindowToFront(long nsWindowPtr);
58 58 private static native void nativeSetNSWindowTitle(long nsWindowPtr, String title);
59 59 private static native void nativeRevalidateNSWindowShadow(long nsWindowPtr);
60 60 private static native void nativeSetNSWindowMinimizedIcon(long nsWindowPtr, long nsImage);
61 61 private static native void nativeSetNSWindowRepresentedFilename(long nsWindowPtr, String representedFilename);
62 62 private static native void nativeSetEnabled(long nsWindowPtr, boolean isEnabled);
63 63 private static native void nativeSynthesizeMouseEnteredExitedEvents();
64 64 private static native void nativeDispose(long nsWindowPtr);
65 65 private static native CPlatformWindow nativeGetTopmostPlatformWindowUnderMouse();
66 66 private static native void nativeEnterFullScreenMode(long nsWindowPtr);
67 67 private static native void nativeExitFullScreenMode(long nsWindowPtr);
68 68
69 69 // Loger to report issues happened during execution but that do not affect functionality
70 70 private static final PlatformLogger logger = PlatformLogger.getLogger("sun.lwawt.macosx.CPlatformWindow");
71 71 private static final PlatformLogger focusLogger = PlatformLogger.getLogger("sun.lwawt.macosx.focus.CPlatformWindow");
72 72
73 73 // for client properties
74 74 public static final String WINDOW_BRUSH_METAL_LOOK = "apple.awt.brushMetalLook";
75 75 public static final String WINDOW_DRAGGABLE_BACKGROUND = "apple.awt.draggableWindowBackground";
76 76
77 77 public static final String WINDOW_ALPHA = "Window.alpha";
78 78 public static final String WINDOW_SHADOW = "Window.shadow";
79 79
80 80 public static final String WINDOW_STYLE = "Window.style";
81 81 public static final String WINDOW_SHADOW_REVALIDATE_NOW = "apple.awt.windowShadow.revalidateNow";
82 82
83 83 public static final String WINDOW_DOCUMENT_MODIFIED = "Window.documentModified";
84 84 public static final String WINDOW_DOCUMENT_FILE = "Window.documentFile";
85 85
86 86 public static final String WINDOW_CLOSEABLE = "Window.closeable";
87 87 public static final String WINDOW_MINIMIZABLE = "Window.minimizable";
88 88 public static final String WINDOW_ZOOMABLE = "Window.zoomable";
89 89 public static final String WINDOW_HIDES_ON_DEACTIVATE="Window.hidesOnDeactivate";
90 90
91 91 public static final String WINDOW_DOC_MODAL_SHEET = "apple.awt.documentModalSheet";
92 92 public static final String WINDOW_FADE_DELEGATE = "apple.awt._windowFadeDelegate";
93 93 public static final String WINDOW_FADE_IN = "apple.awt._windowFadeIn";
94 94 public static final String WINDOW_FADE_OUT = "apple.awt._windowFadeOut";
95 95 public static final String WINDOW_FULLSCREENABLE = "apple.awt.fullscreenable";
96 96
97 97
98 98 // Yeah, I know. But it's easier to deal with ints from JNI
99 99 static final int MODELESS = 0;
100 100 static final int DOCUMENT_MODAL = 1;
101 101 static final int APPLICATION_MODAL = 2;
102 102 static final int TOOLKIT_MODAL = 3;
103 103
104 104 // window style bits
105 105 static final int _RESERVED_FOR_DATA = 1 << 0;
106 106
107 107 // corresponds to native style mask bits
108 108 static final int DECORATED = 1 << 1;
109 109 static final int TEXTURED = 1 << 2;
110 110 static final int UNIFIED = 1 << 3;
111 111 static final int UTILITY = 1 << 4;
112 112 static final int HUD = 1 << 5;
113 113 static final int SHEET = 1 << 6;
114 114
115 115 static final int CLOSEABLE = 1 << 7;
116 116 static final int MINIMIZABLE = 1 << 8;
117 117
118 118 static final int RESIZABLE = 1 << 9; // both a style bit and prop bit
119 119 static final int NONACTIVATING = 1 << 24;
120 120 static final int IS_DIALOG = 1 << 25;
121 121 static final int IS_MODAL = 1 << 26;
122 122 static final int IS_POPUP = 1 << 27;
123 123
124 124 static final int _STYLE_PROP_BITMASK = DECORATED | TEXTURED | UNIFIED | UTILITY | HUD | SHEET | CLOSEABLE | MINIMIZABLE | RESIZABLE;
125 125
126 126 // corresponds to method-based properties
127 127 static final int HAS_SHADOW = 1 << 10;
128 128 static final int ZOOMABLE = 1 << 11;
129 129
130 130 static final int ALWAYS_ON_TOP = 1 << 15;
131 131 static final int HIDES_ON_DEACTIVATE = 1 << 17;
132 132 static final int DRAGGABLE_BACKGROUND = 1 << 19;
133 133 static final int DOCUMENT_MODIFIED = 1 << 21;
134 134 static final int FULLSCREENABLE = 1 << 23;
135 135
136 136 static final int _METHOD_PROP_BITMASK = RESIZABLE | HAS_SHADOW | ZOOMABLE | ALWAYS_ON_TOP | HIDES_ON_DEACTIVATE | DRAGGABLE_BACKGROUND | DOCUMENT_MODIFIED | FULLSCREENABLE;
137 137
138 138 // corresponds to callback-based properties
139 139 static final int SHOULD_BECOME_KEY = 1 << 12;
140 140 static final int SHOULD_BECOME_MAIN = 1 << 13;
141 141 static final int MODAL_EXCLUDED = 1 << 16;
142 142
143 143 static final int _CALLBACK_PROP_BITMASK = SHOULD_BECOME_KEY | SHOULD_BECOME_MAIN | MODAL_EXCLUDED;
144 144
145 145 static int SET(final int bits, final int mask, final boolean value) {
146 146 if (value) return (bits | mask);
147 147 return bits & ~mask;
148 148 }
149 149
150 150 static boolean IS(final int bits, final int mask) {
151 151 return (bits & mask) != 0;
152 152 }
153 153
154 154 @SuppressWarnings({"unchecked", "rawtypes"})
155 155 static ClientPropertyApplicator<JRootPane, CPlatformWindow> CLIENT_PROPERTY_APPLICATOR = new ClientPropertyApplicator<JRootPane, CPlatformWindow>(new Property[] {
156 156 new Property<CPlatformWindow>(WINDOW_DOCUMENT_MODIFIED) { public void applyProperty(final CPlatformWindow c, final Object value) {
157 157 c.setStyleBits(DOCUMENT_MODIFIED, value == null ? false : Boolean.parseBoolean(value.toString()));
158 158 }},
159 159 new Property<CPlatformWindow>(WINDOW_BRUSH_METAL_LOOK) { public void applyProperty(final CPlatformWindow c, final Object value) {
160 160 c.setStyleBits(TEXTURED, Boolean.parseBoolean(value.toString()));
161 161 }},
162 162 new Property<CPlatformWindow>(WINDOW_ALPHA) { public void applyProperty(final CPlatformWindow c, final Object value) {
163 163 AWTUtilities.setWindowOpacity(c.target, value == null ? 1.0f : Float.parseFloat(value.toString()));
164 164 }},
165 165 new Property<CPlatformWindow>(WINDOW_SHADOW) { public void applyProperty(final CPlatformWindow c, final Object value) {
166 166 c.setStyleBits(HAS_SHADOW, value == null ? true : Boolean.parseBoolean(value.toString()));
167 167 }},
168 168 new Property<CPlatformWindow>(WINDOW_MINIMIZABLE) { public void applyProperty(final CPlatformWindow c, final Object value) {
169 169 c.setStyleBits(MINIMIZABLE, Boolean.parseBoolean(value.toString()));
170 170 }},
171 171 new Property<CPlatformWindow>(WINDOW_CLOSEABLE) { public void applyProperty(final CPlatformWindow c, final Object value) {
172 172 c.setStyleBits(CLOSEABLE, Boolean.parseBoolean(value.toString()));
173 173 }},
174 174 new Property<CPlatformWindow>(WINDOW_ZOOMABLE) { public void applyProperty(final CPlatformWindow c, final Object value) {
175 175 c.setStyleBits(ZOOMABLE, Boolean.parseBoolean(value.toString()));
176 176 }},
177 177 new Property<CPlatformWindow>(WINDOW_FULLSCREENABLE) { public void applyProperty(final CPlatformWindow c, final Object value) {
178 178 c.setStyleBits(FULLSCREENABLE, Boolean.parseBoolean(value.toString()));
179 179 }},
180 180 new Property<CPlatformWindow>(WINDOW_SHADOW_REVALIDATE_NOW) { public void applyProperty(final CPlatformWindow c, final Object value) {
181 181 nativeRevalidateNSWindowShadow(c.getNSWindowPtr());
182 182 }},
183 183 new Property<CPlatformWindow>(WINDOW_DOCUMENT_FILE) { public void applyProperty(final CPlatformWindow c, final Object value) {
184 184 if (value == null || !(value instanceof java.io.File)) {
185 185 nativeSetNSWindowRepresentedFilename(c.getNSWindowPtr(), null);
186 186 return;
187 187 }
188 188
189 189 final String filename = ((java.io.File)value).getAbsolutePath();
190 190 nativeSetNSWindowRepresentedFilename(c.getNSWindowPtr(), filename);
191 191 }}
192 192 }) {
193 193 @SuppressWarnings("deprecation")
194 194 public CPlatformWindow convertJComponentToTarget(final JRootPane p) {
195 195 Component root = SwingUtilities.getRoot(p);
196 196 if (root == null || (LWWindowPeer)root.getPeer() == null) return null;
197 197 return (CPlatformWindow)((LWWindowPeer)root.getPeer()).getPlatformWindow();
198 198 }
199 199 };
200 200
201 201 // Bounds of the native widget but in the Java coordinate system.
202 202 // In order to keep it up-to-date we will update them on
203 203 // 1) setting native bounds via nativeSetBounds() call
204 204 // 2) getting notification from the native level via deliverMoveResizeEvent()
205 205 private Rectangle nativeBounds = new Rectangle(0, 0, 0, 0);
206 206 private volatile boolean isFullScreenMode;
207 207 private boolean isFullScreenAnimationOn;
208 208
209 209 private Window target;
210 210 private LWWindowPeer peer;
211 211 protected CPlatformView contentView;
212 212 protected CPlatformWindow owner;
213 213 protected boolean visible = false; // visibility status from native perspective
214 214 private boolean undecorated; // initialized in getInitialStyleBits()
215 215 private Rectangle normalBounds = null; // not-null only for undecorated maximized windows
216 216 private CPlatformResponder responder;
217 217
218 218 public CPlatformWindow() {
219 219 super(0, true);
220 220 }
221 221
222 222 /*
223 223 * Delegate initialization (create native window and all the
224 224 * related resources).
225 225 */
226 226 @Override // PlatformWindow
227 227 public void initialize(Window _target, LWWindowPeer _peer, PlatformWindow _owner) {
228 228 initializeBase(_target, _peer, _owner, new CPlatformView());
229 229
230 230 final int styleBits = getInitialStyleBits();
231 231
232 232 responder = createPlatformResponder();
233 233 contentView = createContentView();
234 234 contentView.initialize(peer, responder);
235 235
236 236 final long ownerPtr = owner != null ? owner.getNSWindowPtr() : 0L;
237 237 Rectangle bounds;
238 238 if (!IS(DECORATED, styleBits)) {
239 239 // For undecorated frames the move/resize event does not come if the frame is centered on the screen
240 240 // so we need to set a stub location to force an initial move/resize. Real bounds would be set later.
241 241 bounds = new Rectangle(0, 0, 1, 1);
242 242 } else {
243 243 bounds = _peer.constrainBounds(_target.getBounds());
244 244 }
245 245 final long nativeWindowPtr = nativeCreateNSWindow(contentView.getAWTView(),
246 246 ownerPtr, styleBits, bounds.x, bounds.y, bounds.width, bounds.height);
247 247 setPtr(nativeWindowPtr);
248 248
249 249 if (target instanceof javax.swing.RootPaneContainer) {
250 250 final javax.swing.JRootPane rootpane = ((javax.swing.RootPaneContainer)target).getRootPane();
251 251 if (rootpane != null) rootpane.addPropertyChangeListener("ancestor", new PropertyChangeListener() {
252 252 public void propertyChange(final PropertyChangeEvent evt) {
253 253 CLIENT_PROPERTY_APPLICATOR.attachAndApplyClientProperties(rootpane);
254 254 rootpane.removePropertyChangeListener("ancestor", this);
255 255 }
256 256 });
257 257 }
258 258
259 259 validateSurface();
260 260 }
261 261
262 262 protected void initializeBase(Window target, LWWindowPeer peer, PlatformWindow owner, CPlatformView view) {
263 263 this.peer = peer;
264 264 this.target = target;
265 265 if (owner instanceof CPlatformWindow) {
266 266 this.owner = (CPlatformWindow)owner;
267 267 }
268 268 this.contentView = view;
269 269 }
270 270
271 271 protected CPlatformResponder createPlatformResponder() {
272 272 return new CPlatformResponder(peer, false);
273 273 }
274 274
275 275 protected CPlatformView createContentView() {
276 276 return new CPlatformView();
277 277 }
278 278
279 279 protected int getInitialStyleBits() {
280 280 // defaults style bits
281 281 int styleBits = DECORATED | HAS_SHADOW | CLOSEABLE | MINIMIZABLE | ZOOMABLE | RESIZABLE;
282 282
283 283 if (isNativelyFocusableWindow()) {
284 284 styleBits = SET(styleBits, SHOULD_BECOME_KEY, true);
285 285 styleBits = SET(styleBits, SHOULD_BECOME_MAIN, true);
286 286 }
287 287
288 288 final boolean isFrame = (target instanceof Frame);
289 289 final boolean isDialog = (target instanceof Dialog);
290 290 final boolean isPopup = (target.getType() == Window.Type.POPUP);
291 291 if (isDialog) {
292 292 styleBits = SET(styleBits, MINIMIZABLE, false);
293 293 }
294 294
295 295 // Either java.awt.Frame or java.awt.Dialog can be undecorated, however java.awt.Window always is undecorated.
296 296 {
297 297 this.undecorated = isFrame ? ((Frame)target).isUndecorated() : (isDialog ? ((Dialog)target).isUndecorated() : true);
298 298 if (this.undecorated) styleBits = SET(styleBits, DECORATED, false);
299 299 }
300 300
301 301 // Either java.awt.Frame or java.awt.Dialog can be resizable, however java.awt.Window is never resizable
302 302 {
303 303 final boolean resizable = isFrame ? ((Frame)target).isResizable() : (isDialog ? ((Dialog)target).isResizable() : false);
304 304 styleBits = SET(styleBits, RESIZABLE, resizable);
305 305 if (!resizable) {
306 306 styleBits = SET(styleBits, ZOOMABLE, false);
307 307 }
308 308 }
309 309
310 310 if (target.isAlwaysOnTop()) {
311 311 styleBits = SET(styleBits, ALWAYS_ON_TOP, true);
312 312 }
313 313
314 314 if (target.getModalExclusionType() == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) {
315 315 styleBits = SET(styleBits, MODAL_EXCLUDED, true);
316 316 }
317 317
318 318 // If the target is a dialog, popup or tooltip we want it to ignore the brushed metal look.
319 319 if (isPopup) {
320 320 styleBits = SET(styleBits, TEXTURED, false);
321 321 // Popups in applets don't activate applet's process
322 322 styleBits = SET(styleBits, NONACTIVATING, true);
323 323 styleBits = SET(styleBits, IS_POPUP, true);
324 324 }
325 325
326 326 if (Window.Type.UTILITY.equals(target.getType())) {
327 327 styleBits = SET(styleBits, UTILITY, true);
328 328 }
329 329
330 330 if (target instanceof javax.swing.RootPaneContainer) {
331 331 javax.swing.JRootPane rootpane = ((javax.swing.RootPaneContainer)target).getRootPane();
332 332 Object prop = null;
333 333
334 334 prop = rootpane.getClientProperty(WINDOW_BRUSH_METAL_LOOK);
335 335 if (prop != null) {
336 336 styleBits = SET(styleBits, TEXTURED, Boolean.parseBoolean(prop.toString()));
337 337 }
338 338
339 339 if (isDialog && ((Dialog)target).getModalityType() == ModalityType.DOCUMENT_MODAL) {
340 340 prop = rootpane.getClientProperty(WINDOW_DOC_MODAL_SHEET);
341 341 if (prop != null) {
342 342 styleBits = SET(styleBits, SHEET, Boolean.parseBoolean(prop.toString()));
343 343 }
344 344 }
345 345
346 346 prop = rootpane.getClientProperty(WINDOW_STYLE);
347 347 if (prop != null) {
348 348 if ("small".equals(prop)) {
349 349 styleBits = SET(styleBits, UTILITY, true);
350 350 if (target.isAlwaysOnTop() && rootpane.getClientProperty(WINDOW_HIDES_ON_DEACTIVATE) == null) {
351 351 styleBits = SET(styleBits, HIDES_ON_DEACTIVATE, true);
352 352 }
353 353 }
354 354 if ("textured".equals(prop)) styleBits = SET(styleBits, TEXTURED, true);
355 355 if ("unified".equals(prop)) styleBits = SET(styleBits, UNIFIED, true);
356 356 if ("hud".equals(prop)) styleBits = SET(styleBits, HUD, true);
357 357 }
358 358
359 359 prop = rootpane.getClientProperty(WINDOW_HIDES_ON_DEACTIVATE);
360 360 if (prop != null) {
361 361 styleBits = SET(styleBits, HIDES_ON_DEACTIVATE, Boolean.parseBoolean(prop.toString()));
362 362 }
363 363
364 364 prop = rootpane.getClientProperty(WINDOW_CLOSEABLE);
365 365 if (prop != null) {
366 366 styleBits = SET(styleBits, CLOSEABLE, Boolean.parseBoolean(prop.toString()));
367 367 }
368 368
369 369 prop = rootpane.getClientProperty(WINDOW_MINIMIZABLE);
370 370 if (prop != null) {
371 371 styleBits = SET(styleBits, MINIMIZABLE, Boolean.parseBoolean(prop.toString()));
372 372 }
373 373
374 374 prop = rootpane.getClientProperty(WINDOW_ZOOMABLE);
375 375 if (prop != null) {
376 376 styleBits = SET(styleBits, ZOOMABLE, Boolean.parseBoolean(prop.toString()));
377 377 }
378 378
379 379 prop = rootpane.getClientProperty(WINDOW_FULLSCREENABLE);
380 380 if (prop != null) {
381 381 styleBits = SET(styleBits, FULLSCREENABLE, Boolean.parseBoolean(prop.toString()));
382 382 }
383 383
384 384 prop = rootpane.getClientProperty(WINDOW_SHADOW);
385 385 if (prop != null) {
386 386 styleBits = SET(styleBits, HAS_SHADOW, Boolean.parseBoolean(prop.toString()));
387 387 }
388 388
389 389 prop = rootpane.getClientProperty(WINDOW_DRAGGABLE_BACKGROUND);
390 390 if (prop != null) {
391 391 styleBits = SET(styleBits, DRAGGABLE_BACKGROUND, Boolean.parseBoolean(prop.toString()));
392 392 }
393 393 }
394 394
395 395 if (isDialog) {
396 396 styleBits = SET(styleBits, IS_DIALOG, true);
397 397 if (((Dialog) target).isModal()) {
398 398 styleBits = SET(styleBits, IS_MODAL, true);
399 399 }
400 400 }
401 401
402 402 peer.setTextured(IS(TEXTURED, styleBits));
403 403
404 404 return styleBits;
405 405 }
406 406
407 407 // this is the counter-point to -[CWindow _nativeSetStyleBit:]
408 408 private void setStyleBits(final int mask, final boolean value) {
409 409 nativeSetNSWindowStyleBits(getNSWindowPtr(), mask, value ? mask : 0);
410 410 }
411 411
412 412 private native void _toggleFullScreenMode(final long model);
413 413
414 414 public void toggleFullScreen() {
415 415 _toggleFullScreenMode(getNSWindowPtr());
416 416 }
417 417
418 418 @Override // PlatformWindow
419 419 public void setMenuBar(MenuBar mb) {
420 420 final long nsWindowPtr = getNSWindowPtr();
421 421 CMenuBar mbPeer = (CMenuBar)LWToolkit.targetToPeer(mb);
422 422 if (mbPeer != null) {
423 423 nativeSetNSWindowMenuBar(nsWindowPtr, mbPeer.getModel());
424 424 } else {
425 425 nativeSetNSWindowMenuBar(nsWindowPtr, 0);
426 426 }
427 427 }
428 428
429 429 @Override // PlatformWindow
430 430 public void dispose() {
431 431 if (owner != null) {
432 432 CWrapper.NSWindow.removeChildWindow(owner.getNSWindowPtr(), getNSWindowPtr());
433 433 }
434 434 contentView.dispose();
435 435 nativeDispose(getNSWindowPtr());
436 436 CPlatformWindow.super.dispose();
437 437 }
438 438
439 439 @Override // PlatformWindow
440 440 public FontMetrics getFontMetrics(Font f) {
441 441 // TODO: not implemented
442 442 (new RuntimeException("unimplemented")).printStackTrace();
443 443 return null;
444 444 }
445 445
446 446 @Override // PlatformWindow
447 447 public Insets getInsets() {
448 448 return nativeGetNSWindowInsets(getNSWindowPtr());
449 449 }
450 450
451 451 @Override // PlatformWindow
452 452 public Point getLocationOnScreen() {
453 453 return new Point(nativeBounds.x, nativeBounds.y);
454 454 }
455 455
456 456 @Override
457 457 public GraphicsDevice getGraphicsDevice() {
458 458 return contentView.getGraphicsDevice();
459 459 }
460 460
461 461 @Override // PlatformWindow
462 462 public SurfaceData getScreenSurface() {
463 463 // TODO: not implemented
464 464 return null;
465 465 }
466 466
467 467 @Override // PlatformWindow
468 468 public SurfaceData replaceSurfaceData() {
469 469 return contentView.replaceSurfaceData();
470 470 }
471 471
472 472 @Override // PlatformWindow
473 473 public void setBounds(int x, int y, int w, int h) {
474 474 nativeSetNSWindowBounds(getNSWindowPtr(), x, y, w, h);
475 475 }
476 476
477 477 private boolean isMaximized() {
478 478 return undecorated ? this.normalBounds != null
479 479 : CWrapper.NSWindow.isZoomed(getNSWindowPtr());
480 480 }
↓ open down ↓ |
480 lines elided |
↑ open up ↑ |
481 481
482 482 private void maximize() {
483 483 if (peer == null || isMaximized()) {
484 484 return;
485 485 }
486 486 if (!undecorated) {
487 487 CWrapper.NSWindow.zoom(getNSWindowPtr());
488 488 } else {
489 489 deliverZoom(true);
490 490
491 + // Bugfix for 8066436
492 + // setSize has an aynchronous native call to osx which in turn calls
493 + // deliverMoveResizeEvent which set the size of the peer
494 + // if that call is still in process and the peer is size is not set,
495 + // we may get bounds which are previous to setSize
496 + // To avoid this we flush all the native events before getting bounds
497 + LWCToolkit.flushNativeSelectors();
491 498 this.normalBounds = peer.getBounds();
492 499
493 500 GraphicsConfiguration config = getPeer().getGraphicsConfiguration();
494 501 Insets i = ((CGraphicsDevice)config.getDevice()).getScreenInsets();
495 502 Rectangle toBounds = config.getBounds();
496 503 setBounds(toBounds.x + i.left,
497 504 toBounds.y + i.top,
498 505 toBounds.width - i.left - i.right,
499 506 toBounds.height - i.top - i.bottom);
500 507 }
501 508 }
502 509
503 510 private void unmaximize() {
504 511 if (!isMaximized()) {
505 512 return;
506 513 }
507 514 if (!undecorated) {
508 515 CWrapper.NSWindow.zoom(getNSWindowPtr());
509 516 } else {
510 517 deliverZoom(false);
511 518
512 519 Rectangle toBounds = this.normalBounds;
513 520 this.normalBounds = null;
514 521 setBounds(toBounds.x, toBounds.y, toBounds.width, toBounds.height);
515 522 }
516 523 }
517 524
518 525 public boolean isVisible() {
519 526 return this.visible;
520 527 }
521 528
522 529 @Override // PlatformWindow
523 530 @SuppressWarnings("deprecation")
524 531 public void setVisible(boolean visible) {
525 532 final long nsWindowPtr = getNSWindowPtr();
526 533
527 534 // Process parent-child relationship when hiding
528 535 if (!visible) {
529 536 // Unparent my children
530 537 for (Window w : target.getOwnedWindows()) {
531 538 WindowPeer p = (WindowPeer)w.getPeer();
532 539 if (p instanceof LWWindowPeer) {
533 540 CPlatformWindow pw = (CPlatformWindow)((LWWindowPeer)p).getPlatformWindow();
534 541 if (pw != null && pw.isVisible()) {
535 542 CWrapper.NSWindow.removeChildWindow(nsWindowPtr, pw.getNSWindowPtr());
536 543 }
537 544 }
538 545 }
539 546
540 547 // Unparent myself
541 548 if (owner != null && owner.isVisible()) {
542 549 CWrapper.NSWindow.removeChildWindow(owner.getNSWindowPtr(), nsWindowPtr);
543 550 }
544 551 }
545 552
546 553 // Configure stuff
547 554 updateIconImages();
548 555 updateFocusabilityForAutoRequestFocus(false);
549 556
550 557 boolean wasMaximized = isMaximized();
551 558
552 559 // Actually show or hide the window
553 560 LWWindowPeer blocker = (peer == null)? null : peer.getBlocker();
554 561 if (blocker == null || !visible) {
555 562 // If it ain't blocked, or is being hidden, go regular way
556 563 if (visible) {
557 564 CWrapper.NSWindow.makeFirstResponder(nsWindowPtr, contentView.getAWTView());
558 565
559 566 boolean isPopup = (target.getType() == Window.Type.POPUP);
560 567 if (isPopup) {
561 568 // Popups in applets don't activate applet's process
562 569 CWrapper.NSWindow.orderFrontRegardless(nsWindowPtr);
563 570 } else {
564 571 CWrapper.NSWindow.orderFront(nsWindowPtr);
565 572 }
566 573
567 574 boolean isKeyWindow = CWrapper.NSWindow.isKeyWindow(nsWindowPtr);
568 575 if (!isKeyWindow) {
569 576 CWrapper.NSWindow.makeKeyWindow(nsWindowPtr);
570 577 }
571 578 } else {
572 579 // immediately hide the window
573 580 CWrapper.NSWindow.orderOut(nsWindowPtr);
574 581 // process the close
575 582 CWrapper.NSWindow.close(nsWindowPtr);
576 583 }
577 584 } else {
578 585 // otherwise, put it in a proper z-order
579 586 CWrapper.NSWindow.orderWindow(nsWindowPtr, CWrapper.NSWindow.NSWindowBelow,
580 587 ((CPlatformWindow)blocker.getPlatformWindow()).getNSWindowPtr());
581 588 }
582 589 this.visible = visible;
583 590
584 591 // Manage the extended state when showing
585 592 if (visible) {
586 593 // Apply the extended state as expected in shared code
587 594 if (target instanceof Frame) {
588 595 if (!wasMaximized && isMaximized()) {
589 596 // setVisible could have changed the native maximized state
590 597 deliverZoom(true);
591 598 } else {
592 599 int frameState = ((Frame)target).getExtendedState();
593 600 if ((frameState & Frame.ICONIFIED) != 0) {
594 601 // Treat all state bit masks with ICONIFIED bit as ICONIFIED state.
595 602 frameState = Frame.ICONIFIED;
596 603 }
597 604 switch (frameState) {
598 605 case Frame.ICONIFIED:
599 606 CWrapper.NSWindow.miniaturize(nsWindowPtr);
600 607 break;
601 608 case Frame.MAXIMIZED_BOTH:
602 609 maximize();
603 610 break;
604 611 default: // NORMAL
605 612 unmaximize(); // in case it was maximized, otherwise this is a no-op
606 613 break;
607 614 }
608 615 }
609 616 }
610 617 }
611 618
612 619 nativeSynthesizeMouseEnteredExitedEvents();
613 620
614 621 // Configure stuff #2
615 622 updateFocusabilityForAutoRequestFocus(true);
616 623
617 624 // Manage parent-child relationship when showing
618 625 if (visible) {
619 626 // Add myself as a child
620 627 if (owner != null && owner.isVisible()) {
621 628 CWrapper.NSWindow.addChildWindow(owner.getNSWindowPtr(), nsWindowPtr, CWrapper.NSWindow.NSWindowAbove);
622 629 applyWindowLevel(target);
623 630 }
624 631
625 632 // Add my own children to myself
626 633 for (Window w : target.getOwnedWindows()) {
627 634 WindowPeer p = (WindowPeer)w.getPeer();
628 635 if (p instanceof LWWindowPeer) {
629 636 CPlatformWindow pw = (CPlatformWindow)((LWWindowPeer)p).getPlatformWindow();
630 637 if (pw != null && pw.isVisible()) {
631 638 CWrapper.NSWindow.addChildWindow(nsWindowPtr, pw.getNSWindowPtr(), CWrapper.NSWindow.NSWindowAbove);
632 639 pw.applyWindowLevel(w);
633 640 }
634 641 }
635 642 }
636 643 }
637 644
638 645 // Deal with the blocker of the window being shown
639 646 if (blocker != null && visible) {
640 647 // Make sure the blocker is above its siblings
641 648 ((CPlatformWindow)blocker.getPlatformWindow()).orderAboveSiblings();
642 649 }
643 650 }
644 651
645 652 @Override // PlatformWindow
646 653 public void setTitle(String title) {
647 654 nativeSetNSWindowTitle(getNSWindowPtr(), title);
648 655 }
649 656
650 657 // Should be called on every window key property change.
651 658 @Override // PlatformWindow
652 659 public void updateIconImages() {
653 660 final long nsWindowPtr = getNSWindowPtr();
654 661 final CImage cImage = getImageForTarget();
655 662 nativeSetNSWindowMinimizedIcon(nsWindowPtr, cImage == null ? 0L : cImage.ptr);
656 663 }
657 664
658 665 public long getNSWindowPtr() {
659 666 final long nsWindowPtr = ptr;
660 667 if (nsWindowPtr == 0L) {
661 668 if(logger.isLoggable(PlatformLogger.Level.FINE)) {
662 669 logger.fine("NSWindow already disposed?", new Exception("Pointer to native NSWindow is invalid."));
663 670 }
664 671 }
665 672 return nsWindowPtr;
666 673 }
667 674
668 675 public SurfaceData getSurfaceData() {
669 676 return contentView.getSurfaceData();
670 677 }
671 678
672 679 @Override // PlatformWindow
673 680 public void toBack() {
674 681 final long nsWindowPtr = getNSWindowPtr();
675 682 nativePushNSWindowToBack(nsWindowPtr);
676 683 }
677 684
678 685 @Override // PlatformWindow
679 686 @SuppressWarnings("deprecation")
680 687 public void toFront() {
681 688 final long nsWindowPtr = getNSWindowPtr();
682 689 LWCToolkit lwcToolkit = (LWCToolkit) Toolkit.getDefaultToolkit();
683 690 Window w = DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
684 691 if( w != null && w.getPeer() != null
685 692 && ((LWWindowPeer)w.getPeer()).getPeerType() == LWWindowPeer.PeerType.EMBEDDED_FRAME
686 693 && !lwcToolkit.isApplicationActive()) {
687 694 lwcToolkit.activateApplicationIgnoringOtherApps();
688 695 }
689 696 updateFocusabilityForAutoRequestFocus(false);
690 697 nativePushNSWindowToFront(nsWindowPtr);
691 698 updateFocusabilityForAutoRequestFocus(true);
692 699 }
693 700
694 701 @Override
695 702 public void setResizable(final boolean resizable) {
696 703 setStyleBits(RESIZABLE, resizable);
697 704 }
698 705
699 706 @Override
700 707 public void setSizeConstraints(int minW, int minH, int maxW, int maxH) {
701 708 nativeSetNSWindowMinMax(getNSWindowPtr(), minW, minH, maxW, maxH);
702 709 }
703 710
704 711 @Override
705 712 public boolean rejectFocusRequest(CausedFocusEvent.Cause cause) {
706 713 // Cross-app activation requests are not allowed.
707 714 if (cause != CausedFocusEvent.Cause.MOUSE_EVENT &&
708 715 !((LWCToolkit)Toolkit.getDefaultToolkit()).isApplicationActive())
709 716 {
710 717 focusLogger.fine("the app is inactive, so the request is rejected");
711 718 return true;
712 719 }
713 720 return false;
714 721 }
715 722
716 723 @Override
717 724 public boolean requestWindowFocus() {
718 725
719 726 long ptr = getNSWindowPtr();
720 727 if (CWrapper.NSWindow.canBecomeMainWindow(ptr)) {
721 728 CWrapper.NSWindow.makeMainWindow(ptr);
722 729 }
723 730 CWrapper.NSWindow.makeKeyAndOrderFront(ptr);
724 731 return true;
725 732 }
726 733
727 734 @Override
728 735 public boolean isActive() {
729 736 long ptr = getNSWindowPtr();
730 737 return CWrapper.NSWindow.isKeyWindow(ptr);
731 738 }
732 739
733 740 @Override
734 741 public void updateFocusableWindowState() {
735 742 final boolean isFocusable = isNativelyFocusableWindow();
736 743 setStyleBits(SHOULD_BECOME_KEY | SHOULD_BECOME_MAIN, isFocusable); // set both bits at once
737 744 }
738 745
739 746 @Override
740 747 public Graphics transformGraphics(Graphics g) {
741 748 // is this where we can inject a transform for HiDPI?
742 749 return g;
743 750 }
744 751
745 752 @Override
746 753 public void setAlwaysOnTop(boolean isAlwaysOnTop) {
747 754 setStyleBits(ALWAYS_ON_TOP, isAlwaysOnTop);
748 755 }
749 756
750 757 public PlatformWindow getTopmostPlatformWindowUnderMouse(){
751 758 return CPlatformWindow.nativeGetTopmostPlatformWindowUnderMouse();
752 759 }
753 760
754 761 @Override
755 762 public void setOpacity(float opacity) {
756 763 CWrapper.NSWindow.setAlphaValue(getNSWindowPtr(), opacity);
757 764 }
758 765
759 766 @Override
760 767 public void setOpaque(boolean isOpaque) {
761 768 CWrapper.NSWindow.setOpaque(getNSWindowPtr(), isOpaque);
762 769 boolean isTextured = (peer == null) ? false : peer.isTextured();
763 770 if (!isTextured) {
764 771 if (!isOpaque) {
765 772 CWrapper.NSWindow.setBackgroundColor(getNSWindowPtr(), 0);
766 773 } else if (peer != null) {
767 774 Color color = peer.getBackground();
768 775 if (color != null) {
769 776 int rgb = color.getRGB();
770 777 CWrapper.NSWindow.setBackgroundColor(getNSWindowPtr(), rgb);
771 778 }
772 779 }
773 780 }
774 781
775 782 //This is a temporary workaround. Looks like after 7124236 will be fixed
776 783 //the correct place for invalidateShadow() is CGLayer.drawInCGLContext.
777 784 SwingUtilities.invokeLater(this::invalidateShadow);
778 785 }
779 786
780 787 @Override
781 788 public void enterFullScreenMode() {
782 789 isFullScreenMode = true;
783 790 nativeEnterFullScreenMode(getNSWindowPtr());
784 791 }
785 792
786 793 @Override
787 794 public void exitFullScreenMode() {
788 795 nativeExitFullScreenMode(getNSWindowPtr());
789 796 isFullScreenMode = false;
790 797 }
791 798
792 799 @Override
793 800 public boolean isFullScreenMode() {
794 801 return isFullScreenMode;
795 802 }
796 803
797 804 @Override
798 805 public void setWindowState(int windowState) {
799 806 if (peer == null || !peer.isVisible()) {
800 807 // setVisible() applies the state
801 808 return;
802 809 }
803 810
804 811 int prevWindowState = peer.getState();
805 812 if (prevWindowState == windowState) return;
806 813
807 814 final long nsWindowPtr = getNSWindowPtr();
808 815 if ((windowState & Frame.ICONIFIED) != 0) {
809 816 // Treat all state bit masks with ICONIFIED bit as ICONIFIED state.
810 817 windowState = Frame.ICONIFIED;
811 818 }
812 819 switch (windowState) {
813 820 case Frame.ICONIFIED:
814 821 if (prevWindowState == Frame.MAXIMIZED_BOTH) {
815 822 // let's return into the normal states first
816 823 // the zoom call toggles between the normal and the max states
817 824 unmaximize();
818 825 }
819 826 CWrapper.NSWindow.miniaturize(nsWindowPtr);
820 827 break;
821 828 case Frame.MAXIMIZED_BOTH:
822 829 if (prevWindowState == Frame.ICONIFIED) {
823 830 // let's return into the normal states first
824 831 CWrapper.NSWindow.deminiaturize(nsWindowPtr);
825 832 }
826 833 maximize();
827 834 break;
828 835 case Frame.NORMAL:
829 836 if (prevWindowState == Frame.ICONIFIED) {
830 837 CWrapper.NSWindow.deminiaturize(nsWindowPtr);
831 838 } else if (prevWindowState == Frame.MAXIMIZED_BOTH) {
832 839 // the zoom call toggles between the normal and the max states
833 840 unmaximize();
834 841 }
835 842 break;
836 843 default:
837 844 throw new RuntimeException("Unknown window state: " + windowState);
838 845 }
839 846
840 847 // NOTE: the SWP.windowState field gets updated to the newWindowState
841 848 // value when the native notification comes to us
842 849 }
843 850
844 851 @Override
845 852 public void setModalBlocked(boolean blocked) {
846 853 if (target.getModalExclusionType() == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) {
847 854 return;
848 855 }
849 856
850 857 nativeSetEnabled(getNSWindowPtr(), !blocked);
851 858 checkBlockingAndOrder();
852 859 }
853 860
854 861 public final void invalidateShadow(){
855 862 nativeRevalidateNSWindowShadow(getNSWindowPtr());
856 863 }
857 864
858 865 // ----------------------------------------------------------------------
859 866 // UTILITY METHODS
860 867 // ----------------------------------------------------------------------
861 868
862 869 /**
863 870 * Find image to install into Title or into Application icon. First try
864 871 * icons installed for toplevel. Null is returned, if there is no icon and
865 872 * default Duke image should be used.
866 873 */
867 874 private CImage getImageForTarget() {
868 875 CImage icon = null;
869 876 try {
870 877 icon = CImage.getCreator().createFromImages(target.getIconImages());
871 878 } catch (Exception ignored) {
872 879 // Perhaps the icon passed into Java is broken. Skipping this icon.
873 880 }
874 881 return icon;
875 882 }
876 883
877 884 /*
878 885 * Returns LWWindowPeer associated with this delegate.
879 886 */
880 887 @Override
881 888 public LWWindowPeer getPeer() {
882 889 return peer;
883 890 }
884 891
885 892 @Override
886 893 public boolean isUnderMouse() {
887 894 return contentView.isUnderMouse();
888 895 }
889 896
890 897 public CPlatformView getContentView() {
891 898 return contentView;
892 899 }
893 900
894 901 @Override
895 902 public long getLayerPtr() {
896 903 return contentView.getWindowLayerPtr();
897 904 }
898 905
899 906 private void validateSurface() {
900 907 SurfaceData surfaceData = getSurfaceData();
901 908 if (surfaceData instanceof CGLSurfaceData) {
902 909 ((CGLSurfaceData)surfaceData).validate();
903 910 }
904 911 }
905 912
906 913 void flushBuffers() {
907 914 if (isVisible() && !nativeBounds.isEmpty() && !isFullScreenMode) {
908 915 try {
909 916 LWCToolkit.invokeAndWait(new Runnable() {
910 917 @Override
911 918 public void run() {
912 919 //Posting an empty to flush the EventQueue without blocking the main thread
913 920 }
914 921 }, target);
915 922 } catch (InvocationTargetException e) {
916 923 e.printStackTrace();
917 924 }
918 925 }
919 926 }
920 927
921 928 /**
922 929 * Helper method to get a pointer to the native view from the PlatformWindow.
923 930 */
924 931 static long getNativeViewPtr(PlatformWindow platformWindow) {
925 932 long nativePeer = 0L;
926 933 if (platformWindow instanceof CPlatformWindow) {
927 934 nativePeer = ((CPlatformWindow) platformWindow).getContentView().getAWTView();
928 935 } else if (platformWindow instanceof CViewPlatformEmbeddedFrame){
929 936 nativePeer = ((CViewPlatformEmbeddedFrame) platformWindow).getNSViewPtr();
930 937 }
931 938 return nativePeer;
932 939 }
933 940
934 941 /*************************************************************
935 942 * Callbacks from the AWTWindow and AWTView objc classes.
936 943 *************************************************************/
937 944 private void deliverWindowFocusEvent(boolean gained, CPlatformWindow opposite){
938 945 // Fix for 7150349: ingore "gained" notifications when the app is inactive.
939 946 if (gained && !((LWCToolkit)Toolkit.getDefaultToolkit()).isApplicationActive()) {
940 947 focusLogger.fine("the app is inactive, so the notification is ignored");
941 948 return;
942 949 }
943 950
944 951 LWWindowPeer oppositePeer = (opposite == null)? null : opposite.getPeer();
945 952 responder.handleWindowFocusEvent(gained, oppositePeer);
946 953 }
947 954
948 955 protected void deliverMoveResizeEvent(int x, int y, int width, int height,
949 956 boolean byUser) {
950 957 checkZoom();
951 958
952 959 final Rectangle oldB = nativeBounds;
953 960 nativeBounds = new Rectangle(x, y, width, height);
954 961 if (peer != null) {
955 962 peer.notifyReshape(x, y, width, height);
956 963 // System-dependent appearance optimization.
957 964 if ((byUser && !oldB.getSize().equals(nativeBounds.getSize()))
958 965 || isFullScreenAnimationOn) {
959 966 flushBuffers();
960 967 }
961 968 }
962 969 }
963 970
964 971 private void deliverWindowClosingEvent() {
965 972 if (peer != null && peer.getBlocker() == null) {
966 973 peer.postEvent(new WindowEvent(target, WindowEvent.WINDOW_CLOSING));
967 974 }
968 975 }
969 976
970 977 private void deliverIconify(final boolean iconify) {
971 978 if (peer != null) {
972 979 peer.notifyIconify(iconify);
973 980 }
974 981 }
975 982
976 983 private void deliverZoom(final boolean isZoomed) {
977 984 if (peer != null) {
978 985 peer.notifyZoom(isZoomed);
979 986 }
980 987 }
981 988
982 989 private void checkZoom() {
983 990 if (target instanceof Frame && isVisible()) {
984 991 Frame targetFrame = (Frame)target;
985 992 if (targetFrame.getExtendedState() != Frame.MAXIMIZED_BOTH && isMaximized()) {
986 993 deliverZoom(true);
987 994 } else if (targetFrame.getExtendedState() == Frame.MAXIMIZED_BOTH && !isMaximized()) {
988 995 deliverZoom(false);
989 996 }
990 997 }
991 998 }
992 999
993 1000 private void deliverNCMouseDown() {
994 1001 if (peer != null) {
995 1002 peer.notifyNCMouseDown();
996 1003 }
997 1004 }
998 1005
999 1006 /*
1000 1007 * Our focus model is synthetic and only non-simple window
1001 1008 * may become natively focusable window.
1002 1009 */
1003 1010 private boolean isNativelyFocusableWindow() {
1004 1011 if (peer == null) {
1005 1012 return false;
1006 1013 }
1007 1014
1008 1015 return !peer.isSimpleWindow() && target.getFocusableWindowState();
1009 1016 }
1010 1017
1011 1018 /*
1012 1019 * An utility method for the support of the auto request focus.
1013 1020 * Updates the focusable state of the window under certain
1014 1021 * circumstances.
1015 1022 */
1016 1023 private void updateFocusabilityForAutoRequestFocus(boolean isFocusable) {
1017 1024 if (target.isAutoRequestFocus() || !isNativelyFocusableWindow()) return;
1018 1025 setStyleBits(SHOULD_BECOME_KEY | SHOULD_BECOME_MAIN, isFocusable); // set both bits at once
1019 1026 }
1020 1027
1021 1028 private boolean checkBlockingAndOrder() {
1022 1029 LWWindowPeer blocker = (peer == null)? null : peer.getBlocker();
1023 1030 if (blocker == null) {
1024 1031 return false;
1025 1032 }
1026 1033
1027 1034 if (blocker instanceof CPrinterDialogPeer) {
1028 1035 return true;
1029 1036 }
1030 1037
1031 1038 CPlatformWindow pWindow = (CPlatformWindow)blocker.getPlatformWindow();
1032 1039
1033 1040 pWindow.orderAboveSiblings();
1034 1041
1035 1042 final long nsWindowPtr = pWindow.getNSWindowPtr();
1036 1043 CWrapper.NSWindow.orderFrontRegardless(nsWindowPtr);
1037 1044 CWrapper.NSWindow.makeKeyAndOrderFront(nsWindowPtr);
1038 1045 CWrapper.NSWindow.makeMainWindow(nsWindowPtr);
1039 1046
1040 1047 return true;
1041 1048 }
1042 1049
1043 1050 private void orderAboveSiblings() {
1044 1051 if (owner == null) {
1045 1052 return;
1046 1053 }
1047 1054
1048 1055 // NOTE: the logic will fail if we have a hierarchy like:
1049 1056 // visible root owner
1050 1057 // invisible owner
1051 1058 // visible dialog
1052 1059 // However, this is an unlikely scenario for real life apps
1053 1060 if (owner.isVisible()) {
1054 1061 // Recursively pop up the windows from the very bottom so that only
1055 1062 // the very top-most one becomes the main window
1056 1063 owner.orderAboveSiblings();
1057 1064
1058 1065 // Order the window to front of the stack of child windows
1059 1066 final long nsWindowSelfPtr = getNSWindowPtr();
1060 1067 final long nsWindowOwnerPtr = owner.getNSWindowPtr();
1061 1068 CWrapper.NSWindow.removeChildWindow(nsWindowOwnerPtr, nsWindowSelfPtr);
1062 1069 CWrapper.NSWindow.addChildWindow(nsWindowOwnerPtr, nsWindowSelfPtr, CWrapper.NSWindow.NSWindowAbove);
1063 1070 }
1064 1071
1065 1072 applyWindowLevel(target);
1066 1073 }
1067 1074
1068 1075 protected void applyWindowLevel(Window target) {
1069 1076 if (target.isAlwaysOnTop() && target.getType() != Window.Type.POPUP) {
1070 1077 CWrapper.NSWindow.setLevel(getNSWindowPtr(), CWrapper.NSWindow.NSFloatingWindowLevel);
1071 1078 } else if (target.getType() == Window.Type.POPUP) {
1072 1079 CWrapper.NSWindow.setLevel(getNSWindowPtr(), CWrapper.NSWindow.NSPopUpMenuWindowLevel);
1073 1080 }
1074 1081 }
1075 1082
1076 1083 // ----------------------------------------------------------------------
1077 1084 // NATIVE CALLBACKS
1078 1085 // ----------------------------------------------------------------------
1079 1086
1080 1087 private void windowDidBecomeMain() {
1081 1088 if (checkBlockingAndOrder()) return;
1082 1089 // If it's not blocked, make sure it's above its siblings
1083 1090 orderAboveSiblings();
1084 1091 }
1085 1092
1086 1093 private void windowWillEnterFullScreen() {
1087 1094 isFullScreenAnimationOn = true;
1088 1095 }
1089 1096
1090 1097 private void windowDidEnterFullScreen() {
1091 1098 isFullScreenAnimationOn = false;
1092 1099 }
1093 1100
1094 1101 private void windowWillExitFullScreen() {
1095 1102 isFullScreenAnimationOn = true;
1096 1103 }
1097 1104
1098 1105 private void windowDidExitFullScreen() {
1099 1106 isFullScreenAnimationOn = false;
1100 1107 }
1101 1108 }
↓ open down ↓ |
601 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX