jdk/src/solaris/classes/sun/awt/X11/XEmbedServerTester.java
author dcherepanov
Mon, 07 Dec 2009 13:43:04 +0300
changeset 4371 dc9dcb8b0ae7
parent 3938 ef327bd847c0
child 5506 202f599c92aa
permissions -rw-r--r--
6823138: Need to replace ComponentAccessor with AWTAccessor Reviewed-by: art, anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 438
diff changeset
     2
 * Copyright 2003-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
//import static sun.awt.X11.XEmbed.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.event.*;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 439
diff changeset
    31
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import static sun.awt.X11.XConstants.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.LinkedList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Test XEmbed server implementation. See file:///home/dom/bugs/4931668/test_plan.html for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * specification and references.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class XEmbedServerTester implements XEventDispatcher {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 439
diff changeset
    40
    private static final PlatformLogger xembedLog = PlatformLogger.getLogger("sun.awt.X11.xembed.XEmbedServerTester");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private final Object EVENT_LOCK = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    static final int SYSTEM_EVENT_MASK = 0x8000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    int my_version, server_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    XEmbedHelper xembed = new XEmbedHelper();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    boolean focused;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    int focusedKind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    int focusedServerComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    boolean reparent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    long parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    boolean windowActive;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    boolean xembedActive;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    XBaseWindow window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    volatile int eventWaited = -1, eventReceived = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    int mapped;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    int accel_key, accel_keysym, accel_mods;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    static Rectangle initialBounds = new Rectangle(0, 0, 100, 100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    Robot robot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    Rectangle serverBounds[]; // first rectangle is for the server frame, second is for dummy frame, others are for its children
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static final int SERVER_BOUNDS = 0, OTHER_FRAME = 1, SERVER_FOCUS = 2, SERVER_MODAL = 3, MODAL_CLOSE = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    LinkedList<Integer> events = new LinkedList<Integer>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private XEmbedServerTester(Rectangle serverBounds[], long parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        this.parent = parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        focusedKind = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        focusedServerComponent = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        reparent = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        windowActive = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        xembedActive = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        my_version = XEmbedHelper.XEMBED_VERSION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        mapped = XEmbedHelper.XEMBED_MAPPED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        this.serverBounds = serverBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        if (serverBounds.length < 5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            throw new IllegalArgumentException("There must be at least five areas: server-activation, server-deactivation, server-focus, " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                                               "server-modal show, modal-close");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            robot = new Robot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            robot.setAutoDelay(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            throw new RuntimeException("Can't create robot");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        initAccel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        xembedLog.finer("XEmbed client(tester), embedder window: " + Long.toHexString(parent));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public static XEmbedServerTester getTester(Rectangle serverBounds[], long parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        return new XEmbedServerTester(serverBounds, parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private void dumpReceivedEvents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        xembedLog.finer("Events received so far:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        int pos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        for (Integer event : events) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            xembedLog.finer((pos++) + ":" + XEmbedHelper.msgidToString(event));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        xembedLog.finer("End of event dump");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public void test1_1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        int res = embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        waitWindowActivated(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        deactivateServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        res = activateServer(getEventPos());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        waitFocusGained(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        checkFocusGained(XEmbedHelper.XEMBED_FOCUS_CURRENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public void test1_2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        int res = embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        waitWindowActivated(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        checkFocusGained(XEmbedHelper.XEMBED_FOCUS_CURRENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public void test1_3() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        deactivateServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        requestFocusNoWait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        checkNotFocused();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public void test1_4() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        deactivateServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        requestFocusNoWait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        checkNotFocused();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        activateServer(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        waitFocusGained(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        checkFocusGained(XEmbedHelper.XEMBED_FOCUS_CURRENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public void test1_5() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        int res = embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        waitWindowActivated(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        checkWindowActivated();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public void test1_6() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        int res = embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        waitWindowActivated(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        res = deactivateServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        checkFocused();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public void test1_7() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        int res = embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        waitWindowActivated(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        focusServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        checkFocusLost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public void test2_5() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        int res = embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        waitWindowActivated(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        focusServerNext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        checkFocusedServerNext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        checkFocusLost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public void test2_6() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        int res = embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        waitWindowActivated(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        focusServerPrev();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        checkFocusedServerPrev();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        checkFocusLost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public void test3_1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        reparent = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public void test3_3() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        reparent = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public void test3_4() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        my_version = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        if (server_version != XEmbedHelper.XEMBED_VERSION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            throw new RuntimeException("Version " + server_version + " is not minimal");
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
    public void test3_5() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        window.destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        // TODO: how can we detect that XEmbed ended?  So far we are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        // just checking that XEmbed server won't end up with an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        // exception, which should end up testing, hopefully.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        // Sleep before exiting the tester application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public void test3_6() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            XlibWrapper.XUnmapWindow(XToolkit.getDisplay(), window.getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            XlibWrapper.XReparentWindow(XToolkit.getDisplay(), window.getWindow(), XToolkit.getDefaultRootWindow(), 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        activateServerNoWait(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        if (checkEventList(res, XEmbedHelper.XEMBED_WINDOW_ACTIVATE) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            throw new RuntimeException("Focus was been given to the client after XEmbed has ended");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public void test4_1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        mapped = XEmbedHelper.XEMBED_MAPPED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        checkMapped();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public void test4_2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        mapped = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        mapped = XEmbedHelper.XEMBED_MAPPED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        updateEmbedInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        checkMapped();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public void test4_3() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        mapped = XEmbedHelper.XEMBED_MAPPED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        mapped = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        updateEmbedInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        checkNotMapped();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    public void test4_4() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        mapped = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        sleep(1000);
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 438
diff changeset
   263
        if (XlibUtil.getWindowMapState(window.getWindow()) != IsUnmapped) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            throw new RuntimeException("Client has been mapped");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public void test6_1_1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        registerAccelerator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        focusServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        int res = pressAccelKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        waitForEvent(res, XEmbedHelper.XEMBED_ACTIVATE_ACCELERATOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    public void test6_1_2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        registerAccelerator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        focusServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        deactivateServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        int res = pressAccelKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        if (checkEventList(res, XEmbedHelper.XEMBED_ACTIVATE_ACCELERATOR) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            throw new RuntimeException("Accelerator has been activated in inactive embedder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public void test6_1_3() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        registerAccelerator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        focusServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        deactivateServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        unregisterAccelerator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        int res = pressAccelKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        if (checkEventList(res, XEmbedHelper.XEMBED_ACTIVATE_ACCELERATOR) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            throw new RuntimeException("Accelerator has been activated after unregistering");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    public void test6_1_4() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        registerAccelerator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        int res = pressAccelKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        if (checkEventList(res, XEmbedHelper.XEMBED_ACTIVATE_ACCELERATOR) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            throw new RuntimeException("Accelerator has been activated in focused client");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public void test6_2_1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        grabKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        focusServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        int res = pressAccelKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        waitSystemEvent(res, KeyPress);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    public void test6_2_2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        grabKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        focusServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        deactivateServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        int res = pressAccelKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        if (checkEventList(res, SYSTEM_EVENT_MASK | KeyPress) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            throw new RuntimeException("Accelerator has been activated in inactive embedder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    public void test6_2_3() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        grabKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        focusServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        deactivateServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        ungrabKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        int res = pressAccelKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        if (checkEventList(res, SYSTEM_EVENT_MASK | KeyPress) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            throw new RuntimeException("Accelerator has been activated after unregistering");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    public void test6_2_4() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        grabKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        int res = pressAccelKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        sleep(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        int pos = checkEventList(res, SYSTEM_EVENT_MASK | KeyPress);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        if (pos != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            pos = checkEventList(pos+1, SYSTEM_EVENT_MASK | KeyPress);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            if (pos != -1) { // Second event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                throw new RuntimeException("Accelerator has been activated in focused client");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    public void test7_1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        int res = showModalDialog();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        waitForEvent(res, XEmbedHelper.XEMBED_MODALITY_ON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    public void test7_2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        int res = showModalDialog();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        waitForEvent(res, XEmbedHelper.XEMBED_MODALITY_ON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        res = hideModalDialog();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        waitForEvent(res, XEmbedHelper.XEMBED_MODALITY_OFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    public void test9_1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        embedCompletely();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        int res = pressAccelKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        waitForEvent(res, SYSTEM_EVENT_MASK | KeyPress);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    private int embed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            XCreateWindowParams params =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                new XCreateWindowParams(new Object[] {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 120
diff changeset
   386
                    XBaseWindow.PARENT_WINDOW, Long.valueOf(reparent?XToolkit.getDefaultRootWindow():parent),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                    XBaseWindow.BOUNDS, initialBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                    XBaseWindow.EMBEDDED, Boolean.TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                    XBaseWindow.VISIBLE, Boolean.valueOf(mapped == XEmbedHelper.XEMBED_MAPPED),
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 120
diff changeset
   390
                    XBaseWindow.EVENT_MASK, Long.valueOf(VisibilityChangeMask | StructureNotifyMask |
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                                                     SubstructureNotifyMask | KeyPressMask)});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            window = new XBaseWindow(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            xembedLog.finer("Created tester window: " + window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            XToolkit.addEventDispatcher(window.getWindow(), this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            updateEmbedInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            if (reparent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                xembedLog.finer("Reparenting to embedder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                XlibWrapper.XReparentWindow(XToolkit.getDisplay(), window.getWindow(), parent, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    private void updateEmbedInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        long[] info = new long[] { my_version, mapped };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        long data = Native.card32ToData(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            XEmbedHelper.XEmbedInfo.setAtomData(window.getWindow(), data, info.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            XEmbedHelper.unsafe.freeMemory(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    private int getEventPos() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        synchronized(EVENT_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            return events.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    private int embedCompletely() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        xembedLog.fine("Embedding completely");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        embed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        waitEmbeddedNotify(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    private int requestFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        xembedLog.fine("Requesting focus");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        sendMessage(XEmbedHelper.XEMBED_REQUEST_FOCUS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        waitFocusGained(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    private int requestFocusNoWait() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        xembedLog.fine("Requesting focus without wait");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        sendMessage(XEmbedHelper.XEMBED_REQUEST_FOCUS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    private int activateServer(int prev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        int res = activateServerNoWait(prev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        waitWindowActivated(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    private int activateServerNoWait(int prev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        xembedLog.fine("Activating server");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        if (checkEventList(prev, XEmbedHelper.XEMBED_WINDOW_ACTIVATE) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            xembedLog.fine("Activation already received");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        Point loc = serverBounds[SERVER_BOUNDS].getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        loc.x += serverBounds[SERVER_BOUNDS].getWidth()/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        loc.y += 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        robot.mouseMove(loc.x, loc.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        robot.mousePress(InputEvent.BUTTON1_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    private int deactivateServer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        xembedLog.fine("Deactivating server");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        Point loc = serverBounds[OTHER_FRAME].getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        loc.x += serverBounds[OTHER_FRAME].getWidth()/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        loc.y += serverBounds[OTHER_FRAME].getHeight()/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        robot.mouseMove(loc.x, loc.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        robot.mousePress(InputEvent.BUTTON1_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        robot.delay(50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        waitWindowDeactivated(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    private int focusServer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        xembedLog.fine("Focusing server");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        boolean weFocused = focused;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        Point loc = serverBounds[SERVER_FOCUS].getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        loc.x += 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        loc.y += 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        robot.mouseMove(loc.x, loc.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        robot.mousePress(InputEvent.BUTTON1_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        robot.delay(50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        if (weFocused) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            waitFocusLost(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    private int focusServerNext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        xembedLog.fine("Focusing next server component");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        sendMessage(XEmbedHelper.XEMBED_FOCUS_NEXT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        waitFocusLost(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    private int focusServerPrev() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        xembedLog.fine("Focusing previous server component");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        sendMessage(XEmbedHelper.XEMBED_FOCUS_PREV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        waitFocusLost(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    private void waitEmbeddedNotify(int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        waitForEvent(pos, XEmbedHelper.XEMBED_EMBEDDED_NOTIFY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    private void waitFocusGained(int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        waitForEvent(pos, XEmbedHelper.XEMBED_FOCUS_IN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    private void waitFocusLost(int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        waitForEvent(pos, XEmbedHelper.XEMBED_FOCUS_OUT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    private void waitWindowActivated(int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        waitForEvent(pos, XEmbedHelper.XEMBED_WINDOW_ACTIVATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    private void waitWindowDeactivated(int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        waitForEvent(pos, XEmbedHelper.XEMBED_WINDOW_DEACTIVATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    private void waitSystemEvent(int position, int event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        waitForEvent(position, event | SYSTEM_EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    private void waitForEvent(int position, int event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        synchronized(EVENT_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            // Check for already received events after the request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            if (checkEventList(position, event) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                xembedLog.finer("The event " + XEmbedHelper.msgidToString(event) + " has already been received");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            if (eventReceived == event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                // Already received
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                xembedLog.finer("Already received " + XEmbedHelper.msgidToString(event));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            eventReceived = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            eventWaited = event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            xembedLog.finer("Waiting for " + XEmbedHelper.msgidToString(event) + " starting from " + position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                EVENT_LOCK.wait(3000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            } catch (InterruptedException ie) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 439
diff changeset
   547
                xembedLog.warning("Event wait interrupted", ie);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            eventWaited = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            if (checkEventList(position, event) == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                dumpReceivedEvents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                throw new RuntimeException("Didn't receive event " + XEmbedHelper.msgidToString(event) + " but recevied " + XEmbedHelper.msgidToString(eventReceived));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                xembedLog.finer("Successfully recevied " + XEmbedHelper.msgidToString(event));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * Checks if the <code>event</code> is already in a list at position >= <code>position</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    private int checkEventList(int position, int event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        if (position == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        synchronized(EVENT_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            for (int i = position; i < events.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                if (events.get(i) == event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                    return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    private void checkFocusedServerNext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        if (focusedServerComponent != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            throw new RuntimeException("Wrong focused server component, should be 0, but it is " + focusedServerComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    private void checkFocusedServerPrev() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        if (focusedServerComponent != 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            throw new RuntimeException("Wrong focused server component, should be 2, but it is " + focusedServerComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    private void checkFocusGained(int kind) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        if (!focused) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            throw new RuntimeException("Didn't receive FOCUS_GAINED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        if (focusedKind != kind) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            throw new RuntimeException("Kinds don't match, required: " + kind + ", current: " + focusedKind);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    private void checkNotFocused() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        if (focused) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            throw new RuntimeException("Focused");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    private void checkFocused() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        if (!focused) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            throw new RuntimeException("Not Focused");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    private void checkFocusLost() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        checkNotFocused();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        if (focusedKind != XEmbedHelper.XEMBED_FOCUS_OUT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            throw new RuntimeException("Didn't receive FOCUS_LOST");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    private void checkWindowActivated() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        if (!windowActive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            throw new RuntimeException("Window is not active");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    private void checkMapped() {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 438
diff changeset
   616
        if (XlibUtil.getWindowMapState(window.getWindow()) == IsUnmapped) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            throw new RuntimeException("Client is not mapped");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    private void checkNotMapped() {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 438
diff changeset
   621
        if (XlibUtil.getWindowMapState(window.getWindow()) != IsUnmapped) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            throw new RuntimeException("Client is mapped");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    private void sendMessage(int message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        xembed.sendMessage(parent, message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    private void sendMessage(int message, int detail, long data1, long data2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        xembed.sendMessage(parent, message, detail, data1, data2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    public void dispatchEvent(XEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        if (ev.get_type() == ClientMessage) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            XClientMessageEvent msg = ev.get_xclient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            if (msg.get_message_type() == xembed.XEmbed.getAtom()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 439
diff changeset
   637
                if (xembedLog.isLoggable(PlatformLogger.FINE)) xembedLog.fine("Embedded message: " + XEmbedHelper.msgidToString((int)msg.get_data(1)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                switch ((int)msg.get_data(1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                  case XEmbedHelper.XEMBED_EMBEDDED_NOTIFY: // Notification about embedding protocol start
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                      xembedActive = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                      server_version = (int)msg.get_data(3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                  case XEmbedHelper.XEMBED_WINDOW_ACTIVATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                      windowActive = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                  case XEmbedHelper.XEMBED_WINDOW_DEACTIVATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                      windowActive = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                  case XEmbedHelper.XEMBED_FOCUS_IN: // We got focus!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                      focused = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                      focusedKind = (int)msg.get_data(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                  case XEmbedHelper.XEMBED_FOCUS_OUT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                      focused = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                      focusedKind = XEmbedHelper.XEMBED_FOCUS_OUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                      focusedServerComponent = (int)msg.get_data(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                synchronized(EVENT_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                    events.add((int)msg.get_data(1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                    xembedLog.finer("Tester is waiting for " +  XEmbedHelper.msgidToString(eventWaited));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                    if ((int)msg.get_data(1) == eventWaited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                        eventReceived = (int)msg.get_data(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                        xembedLog.finer("Notifying waiting object for event " + System.identityHashCode(EVENT_LOCK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                        EVENT_LOCK.notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            synchronized(EVENT_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                int eventID = (int)ev.get_type() | SYSTEM_EVENT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                events.add(eventID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                xembedLog.finer("Tester is waiting for " + XEmbedHelper.msgidToString(eventWaited) + ", but we received " + ev + "(" + XEmbedHelper.msgidToString(eventID) + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                if (eventID == eventWaited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                    eventReceived = eventID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                    xembedLog.finer("Notifying waiting object" + System.identityHashCode(EVENT_LOCK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                    EVENT_LOCK.notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    private void sleep(int amount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            Thread.sleep(amount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    private void registerAccelerator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        sendMessage(XEmbedHelper.XEMBED_REGISTER_ACCELERATOR, 1, accel_keysym, accel_mods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    private void unregisterAccelerator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        sendMessage(XEmbedHelper.XEMBED_UNREGISTER_ACCELERATOR, 1, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    private int pressAccelKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        robot.keyPress(accel_key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        robot.keyRelease(accel_key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    private void initAccel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        accel_key = KeyEvent.VK_A;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        accel_keysym = XWindow.getKeySymForAWTKeyCode(accel_key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        accel_mods = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    private void grabKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        sendMessage(XEmbedHelper.NON_STANDARD_XEMBED_GTK_GRAB_KEY, 0, accel_keysym, accel_mods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    private void ungrabKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        sendMessage(XEmbedHelper.NON_STANDARD_XEMBED_GTK_UNGRAB_KEY, 0, accel_keysym, accel_mods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    private int showModalDialog() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        xembedLog.fine("Showing modal dialog");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        Point loc = serverBounds[SERVER_MODAL].getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        loc.x += 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        loc.y += 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        robot.mouseMove(loc.x, loc.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        robot.mousePress(InputEvent.BUTTON1_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        robot.delay(50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    private int hideModalDialog() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        xembedLog.fine("Hide modal dialog");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        int res = getEventPos();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
//         Point loc = serverBounds[MODAL_CLOSE].getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
//         loc.x += 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
//         loc.y += 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
//         robot.mouseMove(loc.x, loc.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
//         robot.mousePress(InputEvent.BUTTON1_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
//         robot.delay(50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
//         robot.mouseRelease(InputEvent.BUTTON1_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        robot.keyPress(KeyEvent.VK_SPACE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        robot.keyRelease(KeyEvent.VK_SPACE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
}