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