1 /*
2  * Copyright (c) 2012, 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.Font;
29 import java.awt.FontMetrics;
30 import java.awt.GraphicsDevice;
31 import java.awt.Insets;
32 import java.awt.MenuBar;
33 import java.awt.Point;
34 import java.awt.Window;
35 import java.awt.event.FocusEvent.Cause;
36 import sun.java2d.SurfaceData;
37 import sun.lwawt.LWWindowPeer;
38 import sun.lwawt.PlatformWindow;
39 
40 public class CViewPlatformEmbeddedFrame implements PlatformWindow {
41 
42     private CPlatformView view;
43     private LWWindowPeer peer;
44     private CViewEmbeddedFrame target;
45     private CPlatformResponder responder;
46 
47     @Override // PlatformWindow
initialize(Window target, final LWWindowPeer peer, PlatformWindow owner)48     public void initialize(Window target, final LWWindowPeer peer, PlatformWindow owner) {
49         this.peer = peer;
50         this.target = (CViewEmbeddedFrame) target;
51         responder = new CPlatformResponder(peer, false);
52 
53         view = new CPlatformView();
54         view.initialize(peer, responder);
55 
56         CWrapper.NSView.addSubview(this.target.getEmbedderHandle(), view.getAWTView());
57         view.setAutoResizable(true);
58     }
59 
getNSViewPtr()60     public long getNSViewPtr() {
61         return view.getAWTView();
62     }
63 
64     @Override
getLayerPtr()65     public long getLayerPtr() {
66         return view.getWindowLayerPtr();
67     }
68 
69     @Override
getPeer()70     public LWWindowPeer getPeer() {
71         return peer;
72     }
73 
74     @Override
dispose()75     public void dispose() {
76         view.execute(CWrapper.NSView::removeFromSuperview);
77         view.dispose();
78     }
79 
80     @Override
setVisible(boolean visible)81     public void setVisible(boolean visible) {
82         view.execute(ptr -> CWrapper.NSView.setHidden(ptr, !visible));
83     }
84 
85     @Override
setTitle(String title)86     public void setTitle(String title) {
87     }
88 
89     @Override
setBounds(int x, int y, int w, int h)90     public void setBounds(int x, int y, int w, int h) {
91         view.setBounds(x, y, w, h);
92         peer.notifyReshape(x, y, w, h);
93     }
94 
95     @Override
getGraphicsDevice()96     public GraphicsDevice getGraphicsDevice() {
97         return view.getGraphicsDevice();
98     }
99 
100     @Override
getLocationOnScreen()101     public Point getLocationOnScreen() {
102         return view.getLocationOnScreen();
103     }
104 
105     @Override
getInsets()106     public Insets getInsets() {
107         return new Insets(0, 0, 0, 0);
108     }
109 
110     @Override
getFontMetrics(Font f)111     public FontMetrics getFontMetrics(Font f) {
112         throw new RuntimeException("Not implemented");
113     }
114 
115     @Override
getScreenSurface()116     public SurfaceData getScreenSurface() {
117         return view.getSurfaceData();
118     }
119 
120     @Override
replaceSurfaceData()121     public SurfaceData replaceSurfaceData() {
122         return view.replaceSurfaceData();
123     }
124 
125     @Override
setModalBlocked(boolean blocked)126     public void setModalBlocked(boolean blocked) {
127     }
128 
129     @Override
toFront()130     public void toFront() {
131     }
132 
133     @Override
toBack()134     public void toBack() {
135     }
136 
137     @Override
setMenuBar(MenuBar mb)138     public void setMenuBar(MenuBar mb) {
139     }
140 
141     @Override
setAlwaysOnTop(boolean value)142     public void setAlwaysOnTop(boolean value) {
143     }
144 
145     @Override
updateFocusableWindowState()146     public void updateFocusableWindowState() {
147     }
148 
149     @Override
rejectFocusRequest(Cause cause)150     public boolean rejectFocusRequest(Cause cause) {
151         return false;
152     }
153 
154     @Override
requestWindowFocus()155     public boolean requestWindowFocus() {
156         return true;
157     }
158 
159     @Override
isActive()160     public boolean isActive() {
161         return target.isParentWindowActive();
162     }
163 
164     @Override
setResizable(boolean resizable)165     public void setResizable(boolean resizable) {
166     }
167 
168     @Override
setSizeConstraints(int minW, int minH, int maxW, int maxH)169     public void setSizeConstraints(int minW, int minH, int maxW, int maxH) {
170     }
171 
172     @Override
updateIconImages()173     public void updateIconImages() {
174     }
175 
176     @Override
setOpacity(float opacity)177     public void setOpacity(float opacity) {
178     }
179 
180     @Override
setOpaque(boolean isOpaque)181     public void setOpaque(boolean isOpaque) {
182     }
183 
184     @Override
enterFullScreenMode()185     public void enterFullScreenMode() {
186     }
187 
188     @Override
exitFullScreenMode()189     public void exitFullScreenMode() {
190     }
191 
192     @Override
isFullScreenMode()193     public boolean isFullScreenMode() {
194         return false;
195     }
196 
197     @Override
setWindowState(int windowState)198     public void setWindowState(int windowState) {
199     }
200 
201     @Override
isUnderMouse()202     public boolean isUnderMouse() {
203         return view.isUnderMouse();
204     }
205 }
206