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