1 /*
   2  * Copyright (c) 2011, 2015, 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.LWWindowPeer.PeerType;
  35 import sun.lwawt.PlatformWindow;
  36 import sun.util.logging.PlatformLogger;
  37 
  38 /*
  39  * Provides a lightweight implementation of the EmbeddedFrame.
  40  */
  41 public class CPlatformEmbeddedFrame implements PlatformWindow {
  42 
  43     private static final PlatformLogger focusLogger = PlatformLogger.getLogger("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
  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
  60     public LWWindowPeer getPeer() {
  61         return peer;
  62     }
  63 
  64     @Override
  65     public long getLayerPtr() {
  66         return windowLayer.getPointer();
  67     }
  68 
  69     @Override
  70     public void dispose() {
  71         windowLayer.dispose();
  72     }
  73 
  74     @Override
  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
  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
  91     public Point getLocationOnScreen() {
  92         return new Point(screenX, screenY);
  93     }
  94 
  95     @Override
  96     public FontMetrics getFontMetrics(Font f) {
  97         throw new RuntimeException("Not implemented");
  98     }
  99 
 100     @Override
 101     public SurfaceData getScreenSurface() {
 102         return windowLayer.getSurfaceData();
 103     }
 104 
 105     @Override
 106     public SurfaceData replaceSurfaceData() {
 107         return windowLayer.replaceSurfaceData();
 108     }
 109 
 110     @Override
 111     public void setVisible(boolean visible) {}
 112 
 113     @Override
 114     public void setTitle(String title) {}
 115 
 116     @Override
 117     public Insets getInsets() {
 118         return new Insets(0, 0, 0, 0);
 119     }
 120 
 121     @Override
 122     public void toFront() {}
 123 
 124     @Override
 125     public void toBack() {}
 126 
 127     @Override
 128     public void setMenuBar(MenuBar mb) {}
 129 
 130     @Override
 131     public void setAlwaysOnTop(boolean value) {}
 132 
 133     @Override
 134     public void updateFocusableWindowState() {}
 135 
 136     @Override
 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
 149     public boolean requestWindowFocus() {
 150         return true;
 151     }
 152 
 153     @Override
 154     public boolean isActive() {
 155         return true;
 156     }
 157 
 158     @Override
 159     public void setResizable(boolean resizable) {}
 160 
 161     @Override
 162     public void setSizeConstraints(int minW, int minH, int maxW, int maxH) {}
 163 
 164     @Override
 165     public Graphics transformGraphics(Graphics g) {
 166         return g;
 167     }
 168 
 169     @Override
 170     public void updateIconImages() {}
 171 
 172     @Override
 173     public void setOpacity(float opacity) {}
 174 
 175     @Override
 176     public void setOpaque(boolean isOpaque) {}
 177 
 178     @Override
 179     public void enterFullScreenMode() {}
 180 
 181     @Override
 182     public void exitFullScreenMode() {}
 183 
 184     @Override
 185     public boolean isFullScreenMode() {
 186         return false;
 187     }
 188 
 189     @Override
 190     public void setWindowState(int windowState) {}
 191 
 192     @Override
 193     public void setModalBlocked(boolean blocked) {}
 194 
 195     /*
 196      * The method could not be implemented due to CALayer restrictions.
 197      * The exeption enforce clients not to use it.
 198      */
 199     @Override
 200     public boolean isUnderMouse() {
 201         throw new RuntimeException("Not implemented");
 202     }
 203 }