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