1 /* 2 * Copyright (c) 2012, 2014, 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 27 package sun.lwawt.macosx; 28 29 import java.awt.AWTKeyStroke; 30 import java.awt.Toolkit; 31 import java.lang.reflect.InvocationTargetException; 32 33 import sun.awt.EmbeddedFrame; 34 import sun.lwawt.LWWindowPeer; 35 36 /* 37 * The CViewEmbeddedFrame class is used in the SWT_AWT bridge. 38 * This is a part of public API and should not be renamed or moved 39 */ 40 @SuppressWarnings("serial") // JDK implementation class 41 public class CViewEmbeddedFrame extends EmbeddedFrame { 42 43 private final long nsViewPtr; 44 45 private boolean isActive = false; 46 47 public CViewEmbeddedFrame(long nsViewPtr) { 48 this.nsViewPtr = nsViewPtr; 49 } 50 51 @SuppressWarnings("deprecation") 52 @Override 53 public void addNotify() { 54 if (getPeer() == null) { 55 LWCToolkit toolkit = (LWCToolkit) Toolkit.getDefaultToolkit(); 56 setPeer(toolkit.createEmbeddedFrame(this)); 57 } 58 super.addNotify(); 59 } 60 61 public long getEmbedderHandle() { 62 return nsViewPtr; 63 } 64 65 @Override 66 public void registerAccelerator(AWTKeyStroke awtks) { 67 } 68 69 @Override 70 public void unregisterAccelerator(AWTKeyStroke awtks) { 71 } 72 73 public boolean isParentWindowActive() { 74 return isActive; 75 } 76 77 /* 78 * Synthetic event delivery for focus management 79 */ 80 @Override 81 public void synthesizeWindowActivation(boolean activated) { 82 if (isActive != activated) { 83 isActive = activated; 84 ((LWWindowPeer)getPeer()).notifyActivation(activated, null); 85 } 86 } 87 88 /* 89 * Initializes the embedded frame bounds and validates a component. 90 * Designed to be called from the main thread 91 * This method should be called once from the initialization of the SWT_AWT Bridge 92 */ 93 @SuppressWarnings("deprecation") 94 public void validateWithBounds(final int x, final int y, final int width, final int height) { 95 try { 96 LWCToolkit.invokeAndWait(new Runnable() { 97 @Override 98 public void run() { 99 ((LWWindowPeer) getPeer()).setBoundsPrivate(0, 0, width, height); 100 validate(); 101 setVisible(true); 102 } 103 }, this); 104 } catch (InvocationTargetException ex) {} 105 } 106 }