1/*
2 * Copyright (c) 2002, 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
26package sun.awt.X11;
27
28import java.awt.AWTKeyStroke;
29import java.awt.Component;
30import java.awt.Toolkit;
31import java.awt.peer.ComponentPeer;
32
33import sun.awt.AWTAccessor;
34import sun.awt.EmbeddedFrame;
35import sun.util.logging.PlatformLogger;
36
37@SuppressWarnings("serial") // JDK-implementation class
38public class XEmbeddedFrame extends EmbeddedFrame {
39
40    private static final PlatformLogger log =
41            PlatformLogger.getLogger(XEmbeddedFrame.class.getName());
42
43    long handle;
44    public XEmbeddedFrame() {
45    }
46
47    // handle should be a valid X Window.
48    public XEmbeddedFrame(long handle) {
49        this(handle, false);
50    }
51
52    // Handle is the valid X window
53    public XEmbeddedFrame(long handle, boolean supportsXEmbed, boolean isTrayIconWindow) {
54        super(handle, supportsXEmbed);
55
56        if (isTrayIconWindow) {
57            XTrayIconPeer.suppressWarningString(this);
58        }
59
60        this.handle = handle;
61        if (handle != 0) { // Has actual parent
62            addNotify();
63            if (!isTrayIconWindow) {
64                show();
65            }
66        }
67    }
68
69    public void addNotify()
70    {
71        if (!isDisplayable()) {
72            XToolkit toolkit = (XToolkit)Toolkit.getDefaultToolkit();
73            setPeer(toolkit.createEmbeddedFrame(this));
74        }
75        super.addNotify();
76    }
77
78    public XEmbeddedFrame(long handle, boolean supportsXEmbed) {
79        this(handle, supportsXEmbed, false);
80    }
81
82    /*
83     * The method shouldn't be called in case of active XEmbed.
84     */
85    public boolean traverseIn(boolean direction) {
86        XEmbeddedFramePeer peer = AWTAccessor.getComponentAccessor()
87                                             .getPeer(this);
88        if (peer != null) {
89            if (peer.supportsXEmbed() && peer.isXEmbedActive()) {
90                log.fine("The method shouldn't be called when XEmbed is active!");
91            } else {
92                return super.traverseIn(direction);
93            }
94        }
95        return false;
96    }
97
98    protected boolean traverseOut(boolean direction) {
99        XEmbeddedFramePeer xefp = AWTAccessor.getComponentAccessor()
100                                             .getPeer(this);
101        if (direction == FORWARD) {
102            xefp.traverseOutForward();
103        }
104        else {
105            xefp.traverseOutBackward();
106        }
107        return true;
108    }
109
110    /*
111     * The method shouldn't be called in case of active XEmbed.
112     */
113    public void synthesizeWindowActivation(boolean doActivate) {
114        XEmbeddedFramePeer peer = AWTAccessor.getComponentAccessor()
115                                             .getPeer(this);
116        if (peer != null) {
117            if (peer.supportsXEmbed() && peer.isXEmbedActive()) {
118                log.fine("The method shouldn't be called when XEmbed is active!");
119            } else {
120                peer.synthesizeFocusInOut(doActivate);
121            }
122        }
123    }
124
125    public void registerAccelerator(AWTKeyStroke stroke) {
126        XEmbeddedFramePeer xefp = AWTAccessor.getComponentAccessor()
127                                             .getPeer(this);
128        if (xefp != null) {
129            xefp.registerAccelerator(stroke);
130        }
131    }
132
133    public void unregisterAccelerator(AWTKeyStroke stroke) {
134        XEmbeddedFramePeer xefp = AWTAccessor.getComponentAccessor()
135                                             .getPeer(this);
136        if (xefp != null) {
137            xefp.unregisterAccelerator(stroke);
138        }
139    }
140}
141