1 /* 2 * Copyright (c) 2011, 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 package sun.lwawt.macosx; 27 28 import sun.lwawt.PlatformWindow; 29 import sun.lwawt.LWWindowPeer; 30 31 import sun.java2d.opengl.CGLLayer; 32 import sun.java2d.SurfaceData; 33 34 import sun.awt.CausedFocusEvent; 35 36 import java.awt.*; 37 38 import sun.util.logging.PlatformLogger; 39 40 /* 41 * Provides a lightweight implementation of the EmbeddedFrame. 42 */ 43 public class CPlatformEmbeddedFrame implements PlatformWindow { 44 45 private static final PlatformLogger focusLogger = PlatformLogger.getLogger("sun.lwawt.macosx.focus.CPlatformEmbeddedFrame"); 46 47 private CGLLayer windowLayer; 48 private LWWindowPeer peer; 49 private CEmbeddedFrame target; 50 51 private volatile int screenX = 0; 52 private volatile int screenY = 0; 53 54 @Override // PlatformWindow 55 public void initialize(Window target, final LWWindowPeer peer, PlatformWindow owner) { 56 this.peer = peer; 57 this.windowLayer = new CGLLayer(peer); 58 this.target = (CEmbeddedFrame)target; 59 } 60 61 @Override 62 public LWWindowPeer getPeer() { 63 return peer; 64 } 65 66 @Override 67 public long getLayerPtr() { 68 return windowLayer.getPointer(); 69 } 70 71 @Override 72 public void dispose() { 73 windowLayer.dispose(); 74 } 75 76 @Override 77 public void setBounds(int x, int y, int w, int h) { 78 // This is a lightweight implementation of the EmbeddedFrame 79 // and we simply synthesize a reshape request. 80 screenX = x; 81 screenY = y; 82 peer.notifyReshape(x, y, w, h); 83 } 84 85 @Override 86 public GraphicsDevice getGraphicsDevice() { 87 // REMIND: return the main screen for the initial implementation 88 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); 89 return ge.getDefaultScreenDevice(); 90 } 91 92 @Override 93 public Point getLocationOnScreen() { 94 return new Point(screenX, screenY); 95 } 96 97 @Override 98 public FontMetrics getFontMetrics(Font f) { 99 throw new RuntimeException("Not implemented"); 100 } 101 102 @Override 103 public SurfaceData getScreenSurface() { 104 return windowLayer.getSurfaceData(); 105 } 106 107 @Override 108 public SurfaceData replaceSurfaceData() { 109 return windowLayer.replaceSurfaceData(); 110 } 111 112 @Override 113 public void setVisible(boolean visible) {} 114 115 @Override 116 public void setTitle(String title) {} 117 118 @Override 119 public Insets getInsets() { 120 return new Insets(0, 0, 0, 0); 121 } 122 123 @Override 124 public void toFront() {} 125 126 @Override 127 public void toBack() {} 128 129 @Override 130 public void setMenuBar(MenuBar mb) {} 131 132 @Override 133 public void setAlwaysOnTop(boolean value) {} 134 135 // This method should be properly implemented for applets. 136 // It returns null just as a stub. 137 public PlatformWindow getTopmostPlatformWindowUnderMouse() { return null; } 138 139 @Override 140 public void updateFocusableWindowState() {} 141 142 @Override 143 public boolean rejectFocusRequest(CausedFocusEvent.Cause cause) { 144 // Cross-app activation requests are not allowed. 145 if (cause != CausedFocusEvent.Cause.MOUSE_EVENT && 146 !target.isParentWindowActive()) 147 { 148 focusLogger.fine("the embedder is inactive, so the request is rejected"); 149 return true; 150 } 151 return false; 152 } 153 154 @Override 155 public boolean requestWindowFocus() { 156 return true; 157 } 158 159 @Override 160 public boolean isActive() { 161 return true; 162 } 163 164 @Override 165 public void setResizable(boolean resizable) {} 166 167 @Override 168 public void setSizeConstraints(int minW, int minH, int maxW, int maxH) {} 169 170 @Override 171 public Graphics transformGraphics(Graphics g) { 172 return g; 173 } 174 175 @Override 176 public void updateIconImages() {} 177 178 @Override 179 public void setOpacity(float opacity) {} 180 181 @Override 182 public void setOpaque(boolean isOpaque) {} 183 184 @Override 185 public void enterFullScreenMode() {} 186 187 @Override 188 public void exitFullScreenMode() {} 189 190 @Override 191 public void setWindowState(int windowState) {} 192 193 @Override 194 public void setModalBlocked(boolean blocked) {} 195 }