jdk/src/solaris/classes/sun/awt/X11/XEmbeddedFramePeer.java
author dcherepanov
Thu, 12 Feb 2009 18:24:35 +0300
changeset 2453 35e5fab82613
parent 1974 1e1487c04864
child 2643 ea218b1a2000
permissions -rw-r--r--
6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start Reviewed-by: art, ant
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) {
1974
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    66
            // install X11 event dispatcher
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    67
            embedder.setClient(this);
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    68
            // reparent to XEmbed server
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    69
            embedder.install();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        } else if (getParentWindowHandle() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                XlibWrapper.XReparentWindow(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                                            getWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                                            getParentWindowHandle(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                                            0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
1974
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    83
    @Override
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    84
    public void dispose() {
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    85
        if (embedder != null) {
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    86
            // uninstall X11 event dispatcher
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    87
            embedder.setClient(null);
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    88
        }
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    89
        super.dispose();
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    90
    }
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    91
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public void updateMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    protected String getWMName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        return "JavaEmbeddedFrame";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    final long getParentWindowHandle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        return ((XEmbeddedFrame)target).handle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    boolean supportsXEmbed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        return ((EmbeddedFrame)target).supportsXEmbed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public boolean requestWindowFocus(long time, boolean timeProvided) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        // Should check for active state of host application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        if (embedder != null && embedder.isActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            xembedLog.fine("Requesting focus from embedding host");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            return embedder.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            xembedLog.fine("Requesting focus from X");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            return super.requestWindowFocus(time, timeProvided);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    protected void requestInitialFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        if (embedder != null && supportsXEmbed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            embedder.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            super.requestInitialFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    protected boolean isEventDisabled(XEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if (embedder != null && embedder.isActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            switch (e.get_type()) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 129
diff changeset
   129
              case XConstants.FocusIn:
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 129
diff changeset
   130
              case XConstants.FocusOut:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        return super.isEventDisabled(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public void handleConfigureNotifyEvent(XEvent xev)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        assert (SunToolkit.isAWTLockHeldByCurrentThread());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        XConfigureEvent xe = xev.get_xconfigure();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        if (xembedLog.isLoggable(Level.FINE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            xembedLog.fine(xe.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        // fix for 5063031
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        // if we use super.handleConfigureNotifyEvent() we would get wrong
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        // size and position because embedded frame really is NOT a decorated one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        checkIfOnNewScreen(toGlobal(new Rectangle(xe.get_x(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                xe.get_y(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                xe.get_width(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                xe.get_height())));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        Rectangle oldBounds = getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        synchronized (getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            x = xe.get_x();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            y = xe.get_y();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            width = xe.get_width();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            height = xe.get_height();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            dimensions.setClientSize(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            dimensions.setLocation(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        if (!getLocation().equals(oldBounds.getLocation())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            handleMoved(dimensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        reconfigureContentWindow(dimensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    protected void traverseOutForward() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        if (embedder != null && embedder.isActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            if (embedder.isApplicationActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                xembedLog.fine("Traversing out Forward");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                embedder.traverseOutForward();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    protected void traverseOutBackward() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if (embedder != null && embedder.isActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            if (embedder.isApplicationActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                xembedLog.fine("Traversing out Backward");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                embedder.traverseOutBackward();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    // don't use getLocationOnScreen() inherited from XDecoratedPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public Point getLocationOnScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            return toGlobal(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   199
    @Override
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   200
    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
   201
        // 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
   202
        return new Rectangle(x, y, width, height);
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   203
    }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   204
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    // don't use getBounds() inherited from XDecoratedPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return new Rectangle(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public void setBoundsPrivate(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        setBounds(x, y, width, height, SET_BOUNDS | NO_EMBEDDED_CHECK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public Rectangle getBoundsPrivate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        int x = 0, y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        int w = 0, h = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        XWindowAttributes attr = new XWindowAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                getWindow(), attr.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            x = attr.get_x();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            y = attr.get_y();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            w = attr.get_width();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            h = attr.get_height();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        attr.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return new Rectangle(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    void registerAccelerator(AWTKeyStroke stroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        if (stroke == null) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        strokes.add(stroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        if (embedder != null && embedder.isActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            embedder.registerAccelerator(stroke, strokes.size()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    void unregisterAccelerator(AWTKeyStroke stroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (stroke == null) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        if (embedder != null && embedder.isActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            int index = strokes.indexOf(stroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            embedder.unregisterAccelerator(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    void notifyStarted() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        // Register accelerators
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if (embedder != null && embedder.isActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            Iterator<AWTKeyStroke> iter = strokes.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                embedder.registerAccelerator(iter.next(), i++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        // Now we know that the the embedder is an XEmbed server, so we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        // reregister the drop target to enable XDnD protocol support via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        // XEmbed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        updateDropTarget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
1974
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   264
    void notifyStopped() {
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   265
        if (embedder != null && embedder.isActive()) {
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   266
            for (int i = strokes.size() - 1; i >= 0; i--) {
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   267
                embedder.unregisterAccelerator(i);
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   268
            }
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   269
        }
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   270
    }
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   271
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    long getFocusTargetWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        return getWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    boolean isXEmbedActive() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        return embedder != null && embedder.isActive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public int getAbsoluteX()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        Point absoluteLoc = XlibUtil.translateCoordinates(getWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                                                          XToolkit.getDefaultRootWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                                                          new Point(0, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        return absoluteLoc.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public int getAbsoluteY()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        Point absoluteLoc = XlibUtil.translateCoordinates(getWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                                                          XToolkit.getDefaultRootWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                                                          new Point(0, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        return absoluteLoc.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    public int getWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        return width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    public int getHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        return height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    public Dimension getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        return new Dimension(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    // override XWindowPeer's method to let the embedded frame to block
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    // the containing window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    public void setModalBlocked(Dialog blocker, boolean blocked) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        super.setModalBlocked(blocker, blocked);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        EmbeddedFrame frame = (EmbeddedFrame)target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        frame.notifyModalBlocked(blocker, blocked);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
}