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