jdk/src/solaris/classes/sun/awt/X11/XEmbeddedFramePeer.java
author yan
Mon, 06 Oct 2008 16:45:00 +0400
changeset 1966 12a51fb0db0d
parent 439 3488710b02f8
child 1974 1e1487c04864
permissions -rw-r--r--
5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif Summary: Does not work on Motif but works on XToolkit now; implemented using XQueryPointer. Reviewed-by: anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 129
diff changeset
     2
 * Copyright 2002-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.LinkedList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.logging.Level;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.logging.Logger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.awt.EmbeddedFrame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class XEmbeddedFramePeer extends XFramePeer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private static final Logger xembedLog = Logger.getLogger("sun.awt.X11.xembed.XEmbeddedFramePeer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    LinkedList<AWTKeyStroke> strokes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    XEmbedClientHelper embedder; // Caution - can be null if XEmbed is not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    public XEmbeddedFramePeer(EmbeddedFrame target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        // Don't specify PARENT_WINDOW param here. Instead we reparent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        // this embedded frame peer to the proper parent window after
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        // an XEventDispatcher is registered to handle XEmbed events
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        super(new XCreateWindowParams(new Object[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
            TARGET, target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            VISIBLE, Boolean.TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            EMBEDDED, Boolean.TRUE}));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public void preInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        super.preInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        strokes = new LinkedList<AWTKeyStroke>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        if (supportsXEmbed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            embedder = new XEmbedClientHelper();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    void postInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        super.postInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        if (embedder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            embedder.install(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        } else if (getParentWindowHandle() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                XlibWrapper.XReparentWindow(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                                            getWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                                            getParentWindowHandle(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                                            0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public void updateMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    protected String getWMName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        return "JavaEmbeddedFrame";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    final long getParentWindowHandle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        return ((XEmbeddedFrame)target).handle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    boolean supportsXEmbed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        return ((EmbeddedFrame)target).supportsXEmbed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public boolean requestWindowFocus(long time, boolean timeProvided) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        // Should check for active state of host application
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        if (embedder != null && embedder.isActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            xembedLog.fine("Requesting focus from embedding host");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            return embedder.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            xembedLog.fine("Requesting focus from X");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            return super.requestWindowFocus(time, timeProvided);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    protected void requestInitialFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        if (embedder != null && supportsXEmbed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            embedder.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            super.requestInitialFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    protected boolean isEventDisabled(XEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (embedder != null && embedder.isActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            switch (e.get_type()) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 129
diff changeset
   117
              case XConstants.FocusIn:
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 129
diff changeset
   118
              case XConstants.FocusOut:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        return super.isEventDisabled(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public void handleConfigureNotifyEvent(XEvent xev)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        assert (SunToolkit.isAWTLockHeldByCurrentThread());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        XConfigureEvent xe = xev.get_xconfigure();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        if (xembedLog.isLoggable(Level.FINE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            xembedLog.fine(xe.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        // fix for 5063031
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        // if we use super.handleConfigureNotifyEvent() we would get wrong
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        // size and position because embedded frame really is NOT a decorated one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        checkIfOnNewScreen(toGlobal(new Rectangle(xe.get_x(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                xe.get_y(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                xe.get_width(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                xe.get_height())));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        Rectangle oldBounds = getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        synchronized (getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            x = xe.get_x();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            y = xe.get_y();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            width = xe.get_width();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            height = xe.get_height();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            dimensions.setClientSize(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            dimensions.setLocation(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if (!getLocation().equals(oldBounds.getLocation())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            handleMoved(dimensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        reconfigureContentWindow(dimensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    protected void traverseOutForward() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (embedder != null && embedder.isActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            if (embedder.isApplicationActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                xembedLog.fine("Traversing out Forward");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                embedder.traverseOutForward();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    protected void traverseOutBackward() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if (embedder != null && embedder.isActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            if (embedder.isApplicationActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                xembedLog.fine("Traversing out Backward");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                embedder.traverseOutBackward();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    // don't use getLocationOnScreen() inherited from XDecoratedPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public Point getLocationOnScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            return toGlobal(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   187
    @Override
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   188
    Rectangle constrainBounds(int x, int y, int width, int height) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   189
        // We don't constrain the bounds of the EmbeddedFrames
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   190
        return new Rectangle(x, y, width, height);
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   191
    }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   192
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    // don't use getBounds() inherited from XDecoratedPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        return new Rectangle(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public void setBoundsPrivate(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        setBounds(x, y, width, height, SET_BOUNDS | NO_EMBEDDED_CHECK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public Rectangle getBoundsPrivate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        int x = 0, y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        int w = 0, h = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        XWindowAttributes attr = new XWindowAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                getWindow(), attr.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            x = attr.get_x();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            y = attr.get_y();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            w = attr.get_width();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            h = attr.get_height();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        attr.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        return new Rectangle(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    void registerAccelerator(AWTKeyStroke stroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (stroke == null) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        strokes.add(stroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        if (embedder != null && embedder.isActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            embedder.registerAccelerator(stroke, strokes.size()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    void unregisterAccelerator(AWTKeyStroke stroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        if (stroke == null) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        if (embedder != null && embedder.isActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            int index = strokes.indexOf(stroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            embedder.unregisterAccelerator(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    void notifyStarted() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        // Register accelerators
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (embedder != null && embedder.isActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            Iterator<AWTKeyStroke> iter = strokes.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                embedder.registerAccelerator(iter.next(), i++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        // Now we know that the the embedder is an XEmbed server, so we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        // reregister the drop target to enable XDnD protocol support via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        // XEmbed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        updateDropTarget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    long getFocusTargetWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return getWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    boolean isXEmbedActive() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return embedder != null && embedder.isActive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public int getAbsoluteX()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        Point absoluteLoc = XlibUtil.translateCoordinates(getWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                                                          XToolkit.getDefaultRootWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                                                          new Point(0, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        return absoluteLoc.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public int getAbsoluteY()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        Point absoluteLoc = XlibUtil.translateCoordinates(getWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                                                          XToolkit.getDefaultRootWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                                                          new Point(0, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        return absoluteLoc.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    public int getWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        return width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public int getHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        return height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    public Dimension getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        return new Dimension(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    // override XWindowPeer's method to let the embedded frame to block
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    // the containing window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    public void setModalBlocked(Dialog blocker, boolean blocked) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        super.setModalBlocked(blocker, blocked);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        EmbeddedFrame frame = (EmbeddedFrame)target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        frame.notifyModalBlocked(blocker, blocked);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
}