1/*
2 * Copyright (c) 2012, 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
27package sun.lwawt.macosx;
28
29import java.awt.AWTKeyStroke;
30import java.awt.Toolkit;
31import java.lang.reflect.InvocationTargetException;
32
33import sun.awt.AWTAccessor;
34import sun.awt.EmbeddedFrame;
35import sun.lwawt.LWWindowPeer;
36
37/*
38 * The CViewEmbeddedFrame class is used in the SWT_AWT bridge.
39 * This is a part of public API and should not be renamed or moved
40 */
41@SuppressWarnings("serial") // JDK implementation class
42public class CViewEmbeddedFrame extends EmbeddedFrame {
43
44    private final long nsViewPtr;
45
46    private boolean isActive = false;
47
48    public CViewEmbeddedFrame(long nsViewPtr) {
49        this.nsViewPtr = nsViewPtr;
50    }
51
52    @Override
53    public void addNotify() {
54        if (!isDisplayable()) {
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            final LWWindowPeer peer = AWTAccessor.getComponentAccessor()
85                                                 .getPeer(this);
86            peer.notifyActivation(activated, null);
87        }
88    }
89
90    /**
91     * Initializes the embedded frame bounds and validates a component.
92     * Designed to be called from the main thread. This method should be called
93     * once from the initialization of the SWT_AWT Bridge.
94     */
95    public void validateWithBounds(final int x, final int y, final int width,
96                                   final int height) {
97        try {
98            LWCToolkit.invokeAndWait(() -> {
99                final LWWindowPeer peer = AWTAccessor.getComponentAccessor()
100                                                     .getPeer(this);
101                peer.setBoundsPrivate(0, 0, width, height);
102                validate();
103                setVisible(true);
104            }, this);
105        } catch (InvocationTargetException ex) {
106        }
107    }
108}
109