1 /* 2 * Copyright (c) 2011, 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 sun.lwawt.LWToolkit; 29 import sun.lwawt.LWWindowPeer; 30 import sun.lwawt.macosx.CocoaConstants; 31 import sun.lwawt.macosx.event.NSEvent; 32 33 import sun.awt.EmbeddedFrame; 34 35 import java.awt.*; 36 import java.awt.event.*; 37 38 public class CEmbeddedFrame extends EmbeddedFrame { 39 40 private CPlatformResponder responder; 41 private boolean focused = true; 42 private boolean parentWindowActive = true; 43 44 public CEmbeddedFrame() { 45 show(); 46 } 47 48 public void addNotify() { 49 if (getPeer() == null) { 50 LWToolkit toolkit = (LWToolkit)Toolkit.getDefaultToolkit(); 51 LWWindowPeer peer = toolkit.createEmbeddedFrame(this); 52 setPeer(peer); 53 responder = new CPlatformResponder(peer, true); 54 } 55 super.addNotify(); 56 } 57 58 public void registerAccelerator(AWTKeyStroke stroke) {} 59 60 public void unregisterAccelerator(AWTKeyStroke stroke) {} 61 62 protected long getLayerPtr() { 63 LWWindowPeer peer = (LWWindowPeer)getPeer(); 64 return peer.getLayerPtr(); 65 } 66 67 // ----------------------------------------------------------------------- 68 // SYNTHETIC EVENT DELIVERY 69 // ----------------------------------------------------------------------- 70 71 public void handleMouseEvent(int eventType, int modifierFlags, double pluginX, 72 double pluginY, int buttonNumber, int clickCount) { 73 int x = (int)pluginX; 74 int y = (int)pluginY; 75 Point locationOnScreen = getLocationOnScreen(); 76 int screenX = locationOnScreen.x + x; 77 int screenY = locationOnScreen.y + y; 78 79 responder.handleMouseEvent(eventType, modifierFlags, buttonNumber, 80 clickCount, x, y, screenX, screenY); 81 } 82 83 public void handleScrollEvent(double pluginX, double pluginY, int modifierFlags, 84 double deltaX, double deltaY, double deltaZ) { 85 int x = (int)pluginX; 86 int y = (int)pluginY; 87 88 responder.handleScrollEvent(x, y, modifierFlags, deltaX, deltaY); 89 } 90 91 public void handleKeyEvent(int eventType, int modifierFlags, String characters, 92 String charsIgnoringMods, boolean isRepeat, short keyCode) { 93 responder.handleKeyEvent(eventType, modifierFlags, charsIgnoringMods, keyCode); 94 } 95 96 public void handleInputEvent(String text) { 97 new RuntimeException("Not implemented"); 98 } 99 100 public void handleFocusEvent(boolean focused) { 101 this.focused = focused; 102 updateOverlayWindowActiveState(); 103 } 104 105 public void handleWindowFocusEvent(boolean parentWindowActive) { 106 this.parentWindowActive = parentWindowActive; 107 updateOverlayWindowActiveState(); 108 } 109 110 public boolean isParentWindowActive() { 111 return parentWindowActive; 112 } 113 114 /* 115 * May change appearance of contents of window, and generate a 116 * WINDOW_ACTIVATED event. 117 */ 118 private void updateOverlayWindowActiveState() { 119 final boolean showAsFocused = parentWindowActive && focused; 120 dispatchEvent( 121 new FocusEvent(this, showAsFocused ? 122 FocusEvent.FOCUS_GAINED : 123 FocusEvent.FOCUS_LOST)); 124 } 125 126 }