jdk/src/solaris/classes/sun/awt/X11/XEmbedCanvasPeer.java
author anthony
Fri, 12 Apr 2013 14:33:38 +0400
changeset 16839 d0f2e97b7359
parent 13604 31089af1a447
child 17679 a81555868357
permissions -rw-r--r--
8010297: Missing isLoggable() checks in logging code Summary: Add isLoggable() checks Reviewed-by: anthony, mchung, serb Contributed-by: Laurent Bourges <bourges.laurent@gmail.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     2
 * Copyright (c) 2003, 2008, Oracle and/or its affiliates. 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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    23
 * questions.
2
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
import java.awt.dnd.DropTarget;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.dnd.DropTargetListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.awt.*;
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 11093
diff changeset
    33
import sun.awt.AWTAccessor;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
    34
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import static sun.awt.X11.XEmbedHelper.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.security.action.GetBooleanAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
public class XEmbedCanvasPeer extends XCanvasPeer implements WindowFocusListener, KeyEventPostProcessor, ModalityListener, WindowIDProvider {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
    42
    private static final PlatformLogger xembedLog = PlatformLogger.getLogger("sun.awt.X11.xembed.XEmbedCanvasPeer");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    boolean applicationActive; // Whether the application is active(has focus)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    XEmbedServer xembed = new XEmbedServer(); // Helper object, contains XEmbed intrinsics
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    Map<Long, AWTKeyStroke> accelerators = new HashMap<Long, AWTKeyStroke>(); // Maps accelerator ID into AWTKeyStroke
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    Map<AWTKeyStroke, Long> accel_lookup = new HashMap<AWTKeyStroke, Long>(); // Maps AWTKeyStroke into accelerator ID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    Set<GrabbedKey> grabbed_keys = new HashSet<GrabbedKey>(); // A set of keys grabbed by client
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    Object ACCEL_LOCK = accelerators; // Lock object for working with accelerators;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    Object GRAB_LOCK = grabbed_keys; // Lock object for working with keys grabbed by client
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    XEmbedCanvasPeer() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    XEmbedCanvasPeer(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        super(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    XEmbedCanvasPeer(Component target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        super(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    protected void postInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        super.postInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        installActivateListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        installAcceleratorListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        installModalityListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        // XEmbed canvas should be non-traversable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        // FIXME: Probably should be removed and enforced setting of it by the users
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        target.setFocusTraversalKeysEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    protected void preInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        super.preInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        params.put(EVENT_MASK,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 120
diff changeset
    78
                   XConstants.KeyPressMask       | XConstants.KeyReleaseMask
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 120
diff changeset
    79
                   | XConstants.FocusChangeMask  | XConstants.ButtonPressMask | XConstants.ButtonReleaseMask
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 120
diff changeset
    80
                   | XConstants.EnterWindowMask  | XConstants.LeaveWindowMask | XConstants.PointerMotionMask
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 120
diff changeset
    81
                   | XConstants.ButtonMotionMask | XConstants.ExposureMask    | XConstants.StructureNotifyMask | XConstants.SubstructureNotifyMask);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    void installModalityListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        ((SunToolkit)Toolkit.getDefaultToolkit()).addModalityListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    void deinstallModalityListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        ((SunToolkit)Toolkit.getDefaultToolkit()).removeModalityListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    void installAcceleratorListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventPostProcessor(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    void deinstallAcceleratorListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventPostProcessor(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    void installActivateListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        // FIXME: should watch for hierarchy changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        Window toplevel = getTopLevel(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        if (toplevel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            toplevel.addWindowFocusListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            applicationActive = toplevel.isFocused();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    void deinstallActivateListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        Window toplevel = getTopLevel(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        if (toplevel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            toplevel.removeWindowFocusListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    boolean isXEmbedActive() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        return xembed.handle != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    boolean isApplicationActive() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        return applicationActive;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    void initDispatching() {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   126
        if (xembedLog.isLoggable(PlatformLogger.FINE)) {
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   127
            xembedLog.fine("Init embedding for " + Long.toHexString(xembed.handle));
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   128
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            XToolkit.addEventDispatcher(xembed.handle, xembed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            XlibWrapper.XSelectInput(XToolkit.getDisplay(), xembed.handle,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 120
diff changeset
   133
                                     XConstants.StructureNotifyMask | XConstants.PropertyChangeMask);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            XDropTargetRegistry.getRegistry().registerXEmbedClient(getWindow(), xembed.handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        xembed.processXEmbedInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        notifyChildEmbedded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    void endDispatching() {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   145
        if (xembedLog.isLoggable(PlatformLogger.FINE)) {
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   146
            xembedLog.fine("End dispatching for " + Long.toHexString(xembed.handle));
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   147
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            XDropTargetRegistry.getRegistry().unregisterXEmbedClient(getWindow(), xembed.handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            // We can't deselect input since someone else might be interested in it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            XToolkit.removeEventDispatcher(xembed.handle, xembed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    void embedChild(long child) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        if (xembed.handle != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            detachChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        xembed.handle = child;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        initDispatching();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    void childDestroyed() {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   167
        if (xembedLog.isLoggable(PlatformLogger.FINE)) {
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   168
            xembedLog.fine("Child " + Long.toHexString(xembed.handle) + " has self-destroyed.");
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   169
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        endDispatching();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        xembed.handle = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public void handleEvent(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        super.handleEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if (isXEmbedActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            switch (e.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
              case FocusEvent.FOCUS_GAINED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                  canvasFocusGained((FocusEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
              case FocusEvent.FOCUS_LOST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                  canvasFocusLost((FocusEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
              case KeyEvent.KEY_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
              case KeyEvent.KEY_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                  if (!((InputEvent)e).isConsumed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                      forwardKeyEvent((KeyEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public void dispatchEvent(XEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        super.dispatchEvent(ev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        switch (ev.get_type()) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 120
diff changeset
   197
          case XConstants.CreateNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
              XCreateWindowEvent cr = ev.get_xcreatewindow();
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
   199
              if (xembedLog.isLoggable(PlatformLogger.FINEST)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                  xembedLog.finest("Message on embedder: " + cr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
              }
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
   202
              if (xembedLog.isLoggable(PlatformLogger.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                  xembedLog.finer("Create notify for parent " + Long.toHexString(cr.get_parent()) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                                  ", window " + Long.toHexString(cr.get_window()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
              embedChild(cr.get_window());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
              break;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 120
diff changeset
   208
          case XConstants.DestroyNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
              XDestroyWindowEvent dn = ev.get_xdestroywindow();
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
   210
              if (xembedLog.isLoggable(PlatformLogger.FINEST)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                  xembedLog.finest("Message on embedder: " + dn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
              }
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
   213
              if (xembedLog.isLoggable(PlatformLogger.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                  xembedLog.finer("Destroy notify for parent: " + dn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
              childDestroyed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
              break;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 120
diff changeset
   218
          case XConstants.ReparentNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
              XReparentEvent rep = ev.get_xreparent();
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
   220
              if (xembedLog.isLoggable(PlatformLogger.FINEST)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                  xembedLog.finest("Message on embedder: " + rep);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
              }
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
   223
              if (xembedLog.isLoggable(PlatformLogger.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                  xembedLog.finer("Reparent notify for parent " + Long.toHexString(rep.get_parent()) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                                  ", window " + Long.toHexString(rep.get_window()) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                                  ", event " + Long.toHexString(rep.get_event()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
              if (rep.get_parent() == getWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                  // Reparented into us - embed it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                  embedChild(rep.get_window());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
              } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                  // Reparented out of us - detach it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                  childDestroyed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (isXEmbedActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                long p_hints = XlibWrapper.XAllocSizeHints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                XSizeHints hints = new XSizeHints(p_hints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                XlibWrapper.XGetWMNormalHints(XToolkit.getDisplay(), xembed.handle, p_hints, XlibWrapper.larg1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                Dimension res = new Dimension(hints.get_width(), hints.get_height());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                XlibWrapper.XFree(p_hints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            return super.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        if (isXEmbedActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                long p_hints = XlibWrapper.XAllocSizeHints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                XSizeHints hints = new XSizeHints(p_hints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                XlibWrapper.XGetWMNormalHints(XToolkit.getDisplay(), xembed.handle, p_hints, XlibWrapper.larg1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                Dimension res = new Dimension(hints.get_min_width(), hints.get_min_height());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                XlibWrapper.XFree(p_hints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            return super.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        if (isXEmbedActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            detachChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        deinstallActivateListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        deinstallModalityListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        deinstallAcceleratorListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        // BUG: Focus traversal doesn't become enabled after the one round of embedding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        //target.setFocusTraversalKeysEnabled(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        super.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    // Focusable is true in order to enable focus traversal through this Canvas
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public boolean isFocusable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    Window getTopLevel(Component comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        while (comp != null && !(comp instanceof Window)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            comp = comp.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return (Window)comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    Rectangle getClientBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            XWindowAttributes wattr = new XWindowAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            try {
2802
d05a9dcc8296 6678385: Random java.lang.StackOverflowError from various JDKs
art
parents: 439
diff changeset
   304
                XToolkit.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                int status = XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                                                              xembed.handle, wattr.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                XToolkit.RESTORE_XERROR_HANDLER();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                if (status == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                    (XToolkit.saved_error != null &&
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 120
diff changeset
   312
                     XToolkit.saved_error.get_error_code() != XConstants.Success)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                return new Rectangle(wattr.get_x(), wattr.get_y(), wattr.get_width(), wattr.get_height());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                wattr.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    void childResized() {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
   326
        if (xembedLog.isLoggable(PlatformLogger.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            Rectangle bounds = getClientBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            xembedLog.finer("Child resized: " + bounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            // It is not required to update embedder's size when client size changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            // However, since there is no any means to get client size it seems to be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            // only way to provide it. However, it contradicts with Java layout concept -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            // so it is disabled for now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
//             Rectangle my_bounds = getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
//             setBounds(my_bounds.x, my_bounds.y, bounds.width, bounds.height, SET_BOUNDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        XToolkit.postEvent(XToolkit.targetToAppContext(target), new ComponentEvent(target, ComponentEvent.COMPONENT_RESIZED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    void focusNext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        if (isXEmbedActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            xembedLog.fine("Requesting focus for the next component after embedder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            postEvent(new InvocationEvent(target, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                        KeyboardFocusManager.getCurrentKeyboardFocusManager().focusNextComponent(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                }));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            xembedLog.fine("XEmbed is not active - denying focus next");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    void focusPrev() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        if (isXEmbedActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            xembedLog.fine("Requesting focus for the next component after embedder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            postEvent(new InvocationEvent(target, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                        KeyboardFocusManager.getCurrentKeyboardFocusManager().focusPreviousComponent(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                }));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            xembedLog.fine("XEmbed is not active - denying focus prev");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    void requestXEmbedFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        if (isXEmbedActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            xembedLog.fine("Requesting focus for client");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            postEvent(new InvocationEvent(target, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                        target.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                }));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            xembedLog.fine("XEmbed is not active - denying request focus");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    void notifyChildEmbedded() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        xembed.sendMessage(xembed.handle, XEMBED_EMBEDDED_NOTIFY, getWindow(), Math.min(xembed.version, XEMBED_VERSION), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        if (isApplicationActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            xembedLog.fine("Sending WINDOW_ACTIVATE during initialization");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            xembed.sendMessage(xembed.handle, XEMBED_WINDOW_ACTIVATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            if (hasFocus()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                xembedLog.fine("Sending FOCUS_GAINED during initialization");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                xembed.sendMessage(xembed.handle, XEMBED_FOCUS_IN, XEMBED_FOCUS_CURRENT, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    void detachChild() {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   391
        if (xembedLog.isLoggable(PlatformLogger.FINE)) {
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   392
            xembedLog.fine("Detaching child " + Long.toHexString(xembed.handle));
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   393
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
         *  XEmbed specification:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
         *  "The embedder can unmap the client and reparent the client window to the root window. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
         *  client receives an ReparentNotify event, it should check the parent field of the XReparentEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
         *  structure. If this is the root window of the window's screen, then the protocol is finished and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
         *  there is no further interaction. If it is a window other than the root window, then the protocol
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
         *  continues with the new parent acting as the embedder window."
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            XlibWrapper.XUnmapWindow(XToolkit.getDisplay(), xembed.handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            XlibWrapper.XReparentWindow(XToolkit.getDisplay(), xembed.handle, XToolkit.getDefaultRootWindow(), 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        endDispatching();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        xembed.handle = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    public void windowGainedFocus(WindowEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        applicationActive = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        if (isXEmbedActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            xembedLog.fine("Sending WINDOW_ACTIVATE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            xembed.sendMessage(xembed.handle, XEMBED_WINDOW_ACTIVATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    public void windowLostFocus(WindowEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        applicationActive = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        if (isXEmbedActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            xembedLog.fine("Sending WINDOW_DEACTIVATE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            xembed.sendMessage(xembed.handle, XEMBED_WINDOW_DEACTIVATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    void canvasFocusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        if (isXEmbedActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            xembedLog.fine("Forwarding FOCUS_GAINED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            int flavor = XEMBED_FOCUS_CURRENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            if (e instanceof CausedFocusEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                CausedFocusEvent ce = (CausedFocusEvent)e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                if (ce.getCause() == CausedFocusEvent.Cause.TRAVERSAL_FORWARD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                    flavor = XEMBED_FOCUS_FIRST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                } else if (ce.getCause() == CausedFocusEvent.Cause.TRAVERSAL_BACKWARD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                    flavor = XEMBED_FOCUS_LAST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            xembed.sendMessage(xembed.handle, XEMBED_FOCUS_IN, flavor, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    void canvasFocusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        if (isXEmbedActive() && !e.isTemporary()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            xembedLog.fine("Forwarding FOCUS_LOST");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            int num = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            if (AccessController.doPrivileged(new GetBooleanAction("sun.awt.xembed.testing"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                Component opp = e.getOppositeComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                    num = Integer.parseInt(opp.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                } catch (NumberFormatException nfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            xembed.sendMessage(xembed.handle, XEMBED_FOCUS_OUT, num, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    static byte[] getBData(KeyEvent e) {
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 11093
diff changeset
   461
        return AWTAccessor.getAWTEventAccessor().getBData(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    void forwardKeyEvent(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        xembedLog.fine("Try to forward key event");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        byte[] bdata = getBData(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        long data = Native.toData(bdata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        if (data == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            XKeyEvent ke = new XKeyEvent(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            ke.set_window(xembed.handle);
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   474
            if (xembedLog.isLoggable(PlatformLogger.FINE)) {
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   475
                xembedLog.fine("Forwarding native key event: " + ke);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   476
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            try {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 120
diff changeset
   479
                XlibWrapper.XSendEvent(XToolkit.getDisplay(), xembed.handle, false, XConstants.NoEventMask, data);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            XlibWrapper.unsafe.freeMemory(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * Grab/ungrab key functionality is an unofficial API supported by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * GTK.  Unfortunately, it doesn't support accelerator API, so,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * since this is the ONLY shortcut-processing API available, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * must support it.  See XEmbed.NON_STANDARD_XEMBED_GTK_*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * messages.  The format of these messages is as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * - request from client:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * data[1] = NON_STANDARD_XEMBED_GTK_GRAB_KEY or NON_STANDARD_XEMBED_GTK_UNGRAB_KEY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * data[3] = X keysym
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * data[4] = X modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * - response from server (in case the grabbed key has been pressed):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * forwarded XKeyEvent that matches keysym/modifiers pair
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    void grabKey(final long keysym, final long modifiers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        postEvent(new InvocationEvent(target, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                    GrabbedKey grab = new GrabbedKey(keysym, modifiers);
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   507
                    if (xembedLog.isLoggable(PlatformLogger.FINE)) {
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   508
                        xembedLog.fine("Grabbing key: " + grab);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   509
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                    synchronized(GRAB_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                        grabbed_keys.add(grab);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            }));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    void ungrabKey(final long keysym, final long modifiers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        postEvent(new InvocationEvent(target, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                    GrabbedKey grab = new GrabbedKey(keysym, modifiers);
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   521
                    if (xembedLog.isLoggable(PlatformLogger.FINE)) {
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   522
                        xembedLog.fine("UnGrabbing key: " + grab);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   523
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                    synchronized(GRAB_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                        grabbed_keys.remove(grab);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            }));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    void registerAccelerator(final long accel_id, final long keysym, final long modifiers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        postEvent(new InvocationEvent(target, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                    AWTKeyStroke stroke = xembed.getKeyStrokeForKeySym(keysym, modifiers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                    if (stroke != null) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   536
                        if (xembedLog.isLoggable(PlatformLogger.FINE)) {
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   537
                            xembedLog.fine("Registering accelerator " + accel_id + " for " + stroke);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   538
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                        synchronized(ACCEL_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                            accelerators.put(accel_id, stroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                            accel_lookup.put(stroke, accel_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                    propogateRegisterAccelerator(stroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            }));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    void unregisterAccelerator(final long accel_id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        postEvent(new InvocationEvent(target, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                    AWTKeyStroke stroke = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                    synchronized(ACCEL_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                        stroke = accelerators.get(accel_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                        if (stroke != null) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   556
                            if (xembedLog.isLoggable(PlatformLogger.FINE)) {
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   557
                                xembedLog.fine("Unregistering accelerator: " + accel_id);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   558
                            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                            accelerators.remove(accel_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                            accel_lookup.remove(stroke); // FIXME: How about several accelerators with the same stroke?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                    propogateUnRegisterAccelerator(stroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            }));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    void propogateRegisterAccelerator(AWTKeyStroke stroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        // Find the top-level and see if it is XEmbed client. If so, ask him to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        // register the accelerator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        XWindowPeer parent = getToplevelXWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        if (parent != null && parent instanceof XEmbeddedFramePeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            XEmbeddedFramePeer embedded = (XEmbeddedFramePeer)parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            embedded.registerAccelerator(stroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    void propogateUnRegisterAccelerator(AWTKeyStroke stroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        // Find the top-level and see if it is XEmbed client. If so, ask him to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        // register the accelerator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        XWindowPeer parent = getToplevelXWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        if (parent != null && parent instanceof XEmbeddedFramePeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            XEmbeddedFramePeer embedded = (XEmbeddedFramePeer)parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            embedded.unregisterAccelerator(stroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    public boolean postProcessKeyEvent(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        // Processing events only if we are in the focused window but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        // we are not focus owner since otherwise we will get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        // duplicate shortcut events in the client - one is from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        // activate_accelerator, another from forwarded event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        // FIXME: This is probably an incompatibility, protocol
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        // doesn't say anything about disable accelerators when client
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        // is focused.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        XWindowPeer parent = getToplevelXWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        if (parent == null || !((Window)parent.getTarget()).isFocused() || target.isFocusOwner()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        boolean result = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   604
        if (xembedLog.isLoggable(PlatformLogger.FINER)) {
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   605
            xembedLog.finer("Post-processing event " + e);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   606
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        // Process ACCELERATORS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        AWTKeyStroke stroke = AWTKeyStroke.getAWTKeyStrokeForEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        long accel_id = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        boolean exists = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        synchronized(ACCEL_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            exists = accel_lookup.containsKey(stroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            if (exists) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                accel_id = accel_lookup.get(stroke).longValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        if (exists) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   619
            if (xembedLog.isLoggable(PlatformLogger.FINE)) {
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   620
                xembedLog.fine("Activating accelerator " + accel_id);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   621
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            xembed.sendMessage(xembed.handle, XEMBED_ACTIVATE_ACCELERATOR, accel_id, 0, 0); // FIXME: How about overloaded?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            result = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        // Process Grabs, unofficial GTK feature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        exists = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        GrabbedKey key = new GrabbedKey(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        synchronized(GRAB_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            exists = grabbed_keys.contains(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        if (exists) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   633
            if (xembedLog.isLoggable(PlatformLogger.FINE)) {
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   634
                xembedLog.fine("Forwarding grabbed key " + e);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   635
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            forwardKeyEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            result = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    public void modalityPushed(ModalityEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        xembed.sendMessage(xembed.handle, XEMBED_MODALITY_ON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    public void modalityPopped(ModalityEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        xembed.sendMessage(xembed.handle, XEMBED_MODALITY_OFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    public void handleClientMessage(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        super.handleClientMessage(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        XClientMessageEvent msg = xev.get_xclient();
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   654
        if (xembedLog.isLoggable(PlatformLogger.FINER)) {
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   655
            xembedLog.finer("Client message to embedder: " + msg);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   656
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        if (msg.get_message_type() == xembed.XEmbed.getAtom()) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   658
            if (xembedLog.isLoggable(PlatformLogger.FINE)) {
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   659
                xembedLog.fine(xembed.XEmbedMessageToString(msg));
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   660
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        if (isXEmbedActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            switch ((int)msg.get_data(1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
              case XEMBED_REQUEST_FOCUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                  requestXEmbedFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
              case XEMBED_FOCUS_NEXT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                  focusNext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
              case XEMBED_FOCUS_PREV:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                  focusPrev();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
              case XEMBED_REGISTER_ACCELERATOR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                  registerAccelerator(msg.get_data(2), msg.get_data(3), msg.get_data(4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
              case XEMBED_UNREGISTER_ACCELERATOR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                  unregisterAccelerator(msg.get_data(2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
              case NON_STANDARD_XEMBED_GTK_GRAB_KEY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                  grabKey(msg.get_data(3), msg.get_data(4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
              case NON_STANDARD_XEMBED_GTK_UNGRAB_KEY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                  ungrabKey(msg.get_data(3), msg.get_data(4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            xembedLog.finer("But XEmbed is not Active!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    private static class XEmbedDropTarget extends DropTarget {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        public void addDropTargetListener(DropTargetListener dtl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
          throws TooManyListenersException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            // Drop target listeners registered with this target will never be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            // notified, since all drag notifications are routed to the XEmbed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            // client. To avoid confusion we prohibit listeners registration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            // by throwing TooManyListenersException as if there is a listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            // registered with this target already.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            throw new TooManyListenersException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    public void setXEmbedDropTarget() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        // Register a drop site on the top level.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        Runnable r = new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                    target.setDropTarget(new XEmbedDropTarget());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        SunToolkit.executeOnEventHandlerThread(target, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    public void removeXEmbedDropTarget() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        // Unregister a drop site on the top level.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        Runnable r = new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                    if (target.getDropTarget() instanceof XEmbedDropTarget) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                        target.setDropTarget(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        SunToolkit.executeOnEventHandlerThread(target, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    public boolean processXEmbedDnDEvent(long ctxt, int eventID) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
   726
        if (xembedLog.isLoggable(PlatformLogger.FINEST)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            xembedLog.finest("     Drop target=" + target.getDropTarget());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        if (target.getDropTarget() instanceof XEmbedDropTarget) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            AppContext appContext = XToolkit.targetToAppContext(getTarget());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            XDropTargetContextPeer peer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                XDropTargetContextPeer.getPeer(appContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            peer.forwardEventToEmbedded(xembed.handle, ctxt, eventID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    class XEmbedServer extends XEmbedHelper implements XEventDispatcher {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        long handle; // Handle to XEmbed client
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        long version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        long flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        boolean processXEmbedInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            long xembed_info_data = Native.allocateLongArray(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                if (!XEmbedInfo.getAtomData(handle, xembed_info_data, 2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                    // No more XEMBED_INFO? This is not XEmbed client!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                    // Unfortunately this is the initial state of the most clients
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                    // FIXME: add 5-state processing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                    //childDestroyed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                    xembedLog.finer("Unable to get XEMBED_INFO atom data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                version = Native.getCard32(xembed_info_data, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                flags = Native.getCard32(xembed_info_data, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                boolean new_mapped = (flags & XEMBED_MAPPED) != 0;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 120
diff changeset
   759
                boolean currently_mapped = XlibUtil.getWindowMapState(handle) != XConstants.IsUnmapped;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                if (new_mapped != currently_mapped) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   761
                    if (xembedLog.isLoggable(PlatformLogger.FINER)) {
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   762
                        xembedLog.finer("Mapping state of the client has changed, old state: " + currently_mapped + ", new state: " + new_mapped);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   763
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                    if (new_mapped) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                            XlibWrapper.XMapWindow(XToolkit.getDisplay(), handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                            XlibWrapper.XUnmapWindow(XToolkit.getDisplay(), handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                } else {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   780
                    if (xembedLog.isLoggable(PlatformLogger.FINER)) {
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   781
                        xembedLog.finer("Mapping state didn't change, mapped: " + currently_mapped);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   782
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                XlibWrapper.unsafe.freeMemory(xembed_info_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        public void handlePropertyNotify(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            if (isXEmbedActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                XPropertyEvent ev = xev.get_xproperty();
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   793
                if (xembedLog.isLoggable(PlatformLogger.FINER)) {
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   794
                    xembedLog.finer("Property change on client: " + ev);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   795
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                if (ev.get_atom() == XAtom.XA_WM_NORMAL_HINTS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                    childResized();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                } else if (ev.get_atom() == XEmbedInfo.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                    processXEmbedInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                } else if (ev.get_atom() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                           XDnDConstants.XA_XdndAware.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                    XDropTargetRegistry.getRegistry().unregisterXEmbedClient(getWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                                                                             xembed.handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                    if (ev.get_state() == XConstants.PropertyNewValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                        XDropTargetRegistry.getRegistry().registerXEmbedClient(getWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                                                                                xembed.handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                xembedLog.finer("XEmbed is not active");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        void handleConfigureNotify(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
            if (isXEmbedActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                XConfigureEvent ev = xev.get_xconfigure();
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   816
                if (xembedLog.isLoggable(PlatformLogger.FINER)) {
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   817
                    xembedLog.finer("Bounds change on client: " + ev);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   818
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                if (xev.get_xany().get_window() == handle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                    childResized();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        public void dispatchEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            int type = xev.get_type();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            switch (type) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 120
diff changeset
   827
              case XConstants.PropertyNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                  handlePropertyNotify(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                  break;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 120
diff changeset
   830
              case XConstants.ConfigureNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                  handleConfigureNotify(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                  break;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 120
diff changeset
   833
              case XConstants.ClientMessage:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                  handleClientMessage(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    static class GrabbedKey {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        long keysym;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        long modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        GrabbedKey(long keysym, long modifiers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            this.keysym = keysym;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            this.modifiers = modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        GrabbedKey(KeyEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            init(ev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        private void init(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            byte[] bdata = getBData(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            long data = Native.toData(bdata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
            if (data == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                    keysym = XWindow.getKeySymForAWTKeyCode(e.getKeyCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                    XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                XKeyEvent ke = new XKeyEvent(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                // We recognize only these masks
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 120
diff changeset
   868
                modifiers = ke.get_state() & (XConstants.ShiftMask | XConstants.ControlMask | XConstants.LockMask);
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   869
                if (xembedLog.isLoggable(PlatformLogger.FINEST)) {
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   870
                    xembedLog.finest("Mapped " + e + " to " + this);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   871
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                XlibWrapper.unsafe.freeMemory(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
            return (int)keysym & 0xFFFFFFFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            if (!(o instanceof GrabbedKey)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            GrabbedKey key = (GrabbedKey)o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            return (keysym == key.keysym && modifiers == key.modifiers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            return "Key combination[keysym=" + keysym + ", mods=" + modifiers + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
}