1 /*
2  * Copyright (c) 2013, 2019, 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.GraphicsEnvironment;
32 import java.awt.Insets;
33 import java.awt.MenuBar;
34 import java.awt.Point;
35 import java.awt.Rectangle;
36 import java.awt.Window;
37 import java.awt.event.FocusEvent;
38 
39 import sun.awt.CGraphicsDevice;
40 import sun.awt.CGraphicsEnvironment;
41 import sun.awt.LightweightFrame;
42 import sun.java2d.SurfaceData;
43 import sun.lwawt.LWLightweightFramePeer;
44 import sun.lwawt.LWWindowPeer;
45 import sun.lwawt.PlatformWindow;
46 
47 public class CPlatformLWWindow extends CPlatformWindow {
48 
49     @Override
initialize(Window target, LWWindowPeer peer, PlatformWindow owner)50     public void initialize(Window target, LWWindowPeer peer, PlatformWindow owner) {
51         initializeBase(target, peer, owner);
52     }
53 
54     @Override
createContentView()55     CPlatformView createContentView() {
56         return new CPlatformLWView();
57     }
58 
59     @Override
toggleFullScreen()60     public void toggleFullScreen() {
61     }
62 
63     @Override
setMenuBar(MenuBar mb)64     public void setMenuBar(MenuBar mb) {
65     }
66 
67     @Override
dispose()68     public void dispose() {
69     }
70 
71     @Override
getFontMetrics(Font f)72     public FontMetrics getFontMetrics(Font f) {
73         return null;
74     }
75 
76     @Override
getInsets()77     public Insets getInsets() {
78         return new Insets(0, 0, 0, 0);
79     }
80 
81     @Override
getLocationOnScreen()82     public Point getLocationOnScreen() {
83         return null;
84     }
85 
86     @Override
getScreenSurface()87     public SurfaceData getScreenSurface() {
88         return null;
89     }
90 
91     @Override
replaceSurfaceData()92     public SurfaceData replaceSurfaceData() {
93         return null;
94     }
95 
96     @Override
setBounds(int x, int y, int w, int h)97     public void setBounds(int x, int y, int w, int h) {
98         if (getPeer() != null) {
99             getPeer().notifyReshape(x, y, w, h);
100         }
101     }
102 
103     @Override
setVisible(boolean visible)104     public void setVisible(boolean visible) {
105     }
106 
107     @Override
setTitle(String title)108     public void setTitle(String title) {
109     }
110 
111     @Override
updateIconImages()112     public void updateIconImages() {
113     }
114 
115     @Override
getSurfaceData()116     public SurfaceData getSurfaceData() {
117         return null;
118     }
119 
120     @Override
toBack()121     public void toBack() {
122     }
123 
124     @Override
toFront()125     public void toFront() {
126     }
127 
128     @Override
setResizable(final boolean resizable)129     public void setResizable(final boolean resizable) {
130     }
131 
132     @Override
setSizeConstraints(int minW, int minH, int maxW, int maxH)133     public void setSizeConstraints(int minW, int minH, int maxW, int maxH) {
134     }
135 
136     @Override
rejectFocusRequest(FocusEvent.Cause cause)137     public boolean rejectFocusRequest(FocusEvent.Cause cause) {
138         return false;
139     }
140 
141     @Override
requestWindowFocus()142     public boolean requestWindowFocus() {
143         return true;
144     }
145 
146     @Override
isActive()147     public boolean isActive() {
148         return true;
149     }
150 
151     @Override
updateFocusableWindowState()152     public void updateFocusableWindowState() {
153     }
154 
155     @Override
setAlwaysOnTop(boolean isAlwaysOnTop)156     public void setAlwaysOnTop(boolean isAlwaysOnTop) {
157     }
158 
159     @Override
setOpacity(float opacity)160     public void setOpacity(float opacity) {
161     }
162 
163     @Override
setOpaque(boolean isOpaque)164     public void setOpaque(boolean isOpaque) {
165     }
166 
167     @Override
enterFullScreenMode()168     public void enterFullScreenMode() {
169     }
170 
171     @Override
exitFullScreenMode()172     public void exitFullScreenMode() {
173     }
174 
175     @Override
setWindowState(int windowState)176     public void setWindowState(int windowState) {
177     }
178 
179     @Override
getPeer()180     public LWWindowPeer getPeer() {
181         return super.getPeer();
182     }
183 
184     @Override
getContentView()185     public CPlatformView getContentView() {
186         return super.getContentView();
187     }
188 
189     @Override
getLayerPtr()190     public long getLayerPtr() {
191         return 0;
192     }
193 
194     @Override
getGraphicsDevice()195     public GraphicsDevice getGraphicsDevice() {
196         CGraphicsEnvironment ge = (CGraphicsEnvironment)GraphicsEnvironment.
197                                   getLocalGraphicsEnvironment();
198 
199         LWLightweightFramePeer peer = (LWLightweightFramePeer)getPeer();
200         int scale =(int) Math.round(((LightweightFrame)peer.getTarget())
201                                                             .getScaleFactorX());
202 
203         Rectangle bounds = ((LightweightFrame)peer.getTarget()).getHostBounds();
204         for (GraphicsDevice d : ge.getScreenDevices()) {
205             if (d.getDefaultConfiguration().getBounds().intersects(bounds) &&
206                 ((CGraphicsDevice)d).getScaleFactor() == scale)
207             {
208                 return d;
209             }
210         }
211         // We shouldn't be here...
212         return ge.getDefaultScreenDevice();
213     }
214 }
215