jdk/src/windows/classes/sun/awt/windows/WToolkit.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 7954 13aa14c7723e
child 9050 26c2c1de1631
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 7954
diff changeset
     2
 * Copyright (c) 1996, 2011, 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: 5275
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: 5275
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: 5275
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5275
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5275
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.windows;
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.im.InputMethodHighlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.im.spi.InputMethodDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.image.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.peer.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.event.KeyEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.datatransfer.Clipboard;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.TrayIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.awt.AWTAutoShutdown;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.awt.Win32GraphicsDevice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.awt.Win32GraphicsEnvironment;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    43
import sun.java2d.d3d.D3DRenderQueue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import sun.java2d.opengl.OGLRenderQueue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import sun.print.PrintJob2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.awt.dnd.DragSource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.awt.dnd.DragGestureListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.awt.dnd.DragGestureEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.awt.dnd.DragGestureRecognizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.awt.dnd.MouseDragGestureRecognizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.awt.dnd.InvalidDnDOperationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.awt.dnd.peer.DragSourceContextPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import java.util.Properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3246
diff changeset
    61
import sun.font.FontManager;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3246
diff changeset
    62
import sun.font.FontManagerFactory;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3246
diff changeset
    63
import sun.font.SunFontManager;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
import sun.misc.PerformanceLogger;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
    65
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
public class WToolkit extends SunToolkit implements Runnable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
    69
    private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.windows.WToolkit");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    static GraphicsConfiguration config;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    // System clipboard.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    WClipboard clipboard;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    // cache of font peers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private Hashtable cacheFontPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    // Windows properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private WDesktopProperties  wprops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    // Dynamic Layout Resize client code setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    protected boolean dynamicLayoutSetting = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
    85
    //Is it allowed to generate events assigned to extra mouse buttons.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
    86
    //Set to true by default.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
    87
    private static boolean areExtraMouseButtonsEnabled = true;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
    88
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Initialize JNI field and method IDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private static boolean loaded = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public static void loadLibraries() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        if (!loaded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                          new sun.security.action.LoadLibraryAction("awt"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            loaded = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private static native String getWindowsVersion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        loadLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        // Force Win32GE to load if it is not already loaded; this loads
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        // various other classes that are required for basic awt functionality
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        Win32GraphicsEnvironment.init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        // Print out which version of Windows is running
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
   112
        if (log.isLoggable(PlatformLogger.FINE)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
   113
            log.fine("Win version: " + getWindowsVersion());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            new java.security.PrivilegedAction()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                String browserProp = System.getProperty("browser");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                if (browserProp != null && browserProp.equals("sun.plugin")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                    disableCustomPalette();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private static native void disableCustomPalette();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Reset the static GraphicsConfiguration to the default.  Called on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * startup and when display settings have changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public static void resetGC() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        if (GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            config = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
          config = (GraphicsEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                  .getLocalGraphicsEnvironment()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
          .getDefaultScreenDevice()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
          .getDefaultConfiguration());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * NOTE: The following embedded*() methods are non-public API intended
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * for internal use only.  The methods are unsupported and could go
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * away in future releases.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * New hook functions for using the AWT as an embedded service. These
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * functions replace the global C function AwtInit() which was previously
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * exported by awt.dll.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * When used as an embedded service, the AWT does NOT have its own
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * message pump. It instead relies on the parent application to provide
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * this functionality. embeddedInit() assumes that the thread on which it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * is called is the message pumping thread. Violating this assumption
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * will lead to undefined behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * embeddedInit must be called before the WToolkit() constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * embeddedDispose should be called before the applicaton terminates the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Java VM. It is currently unsafe to reinitialize the toolkit again
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * after it has been disposed. Instead, awt.dll must be reloaded and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * class loader which loaded WToolkit must be finalized before it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * safe to reuse AWT. Dynamic reusability may be added to the toolkit in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * Initializes the Toolkit for use in an embedded environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @return true if the the initialization succeeded; false if it failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *         The function will fail if the Toolkit was already initialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public static native boolean embeddedInit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * Disposes the Toolkit in an embedded environment. This method should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * not be called on exit unless the Toolkit was constructed with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * embeddedInit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @return true if the disposal succeeded; false if it failed. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *         function will fail if the calling thread is not the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *         thread which called embeddedInit(), or if the Toolkit was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *         already disposed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public static native boolean embeddedDispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * To be called after processing the event queue by users of the above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * embeddedInit() function.  The reason for this additional call is that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * there are some operations performed during idle time in the AwtToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * event loop which should also be performed during idle time in any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * other native event loop.  Failure to do so could result in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * deadlocks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * This method was added at the last minute of the jdk1.4 release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * to work around a specific customer problem.  As with the above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * embedded*() class, this method is non-public and should not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * used by external applications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * See bug #4526587 for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public native void embeddedEventLoopIdleProcessing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public static final String DATA_TRANSFERER_CLASS_NAME = "sun.awt.windows.WDataTransferer";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    static class ToolkitDisposer implements sun.java2d.DisposerRecord {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            WToolkit.postDispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    private final Object anchor = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    private static native void postDispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
7004
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 5506
diff changeset
   221
    private static native boolean startToolkitThread(Runnable thread);
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 5506
diff changeset
   222
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public WToolkit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        // Startup toolkit threads
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        if (PerformanceLogger.loggingEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            PerformanceLogger.setTime("WToolkit construction");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        sun.java2d.Disposer.addRecord(anchor, new ToolkitDisposer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
7954
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   231
        /*
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   232
         * Fix for 4701990.
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   233
         * AWTAutoShutdown state must be changed before the toolkit thread
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   234
         * starts to avoid race condition.
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   235
         */
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   236
        AWTAutoShutdown.notifyToolkitThreadBusy();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
7954
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   238
        if (!startToolkitThread(this)) {
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   239
            Thread toolkitThread = new Thread(this, "AWT-Windows");
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   240
            toolkitThread.setDaemon(true);
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   241
            toolkitThread.start();
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   242
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
7954
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   244
        try {
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   245
            synchronized(this) {
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   246
                while(!inited) {
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   247
                    wait();
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   248
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            }
7954
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   250
        } catch (InterruptedException x) {
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   251
            // swallow the exception
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        }
7954
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   253
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        SunToolkit.setDataTransfererClassName(DATA_TRANSFERER_CLASS_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        // Enabled "live resizing" by default.  It remains controlled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        // by the native system though.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        setDynamicLayout(true);
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   259
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   260
        areExtraMouseButtonsEnabled = Boolean.parseBoolean(System.getProperty("sun.awt.enableExtraMouseButtons", "true"));
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   261
        //set system property if not yet assigned
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   262
        System.setProperty("sun.awt.enableExtraMouseButtons", ""+areExtraMouseButtonsEnabled);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   263
        setExtraMouseButtonsEnabledNative(areExtraMouseButtonsEnabled);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
7954
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   266
    private final void registerShutdownHook() {
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   267
        AccessController.doPrivileged(new PrivilegedAction() {
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   268
            public Object run() {
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   269
                ThreadGroup currentTG =
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   270
                    Thread.currentThread().getThreadGroup();
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   271
                ThreadGroup parentTG = currentTG.getParent();
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   272
                while (parentTG != null) {
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   273
                    currentTG = parentTG;
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   274
                    parentTG = currentTG.getParent();
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   275
                }
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   276
                Thread shutdown = new Thread(currentTG, new Runnable() {
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   277
                    public void run() {
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   278
                        shutdown();
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   279
                    }
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   280
                });
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   281
                shutdown.setContextClassLoader(null);
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   282
                Runtime.getRuntime().addShutdownHook(shutdown);
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   283
                return null;
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   284
            }
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   285
        });
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   286
     }
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   287
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public void run() {
7004
3f92ea1ffcac 6867515: Reduce impact of D3D initializion on startup time
amenkov
parents: 5506
diff changeset
   289
        Thread.currentThread().setPriority(Thread.NORM_PRIORITY+1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        boolean startPump = init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        if (startPump) {
7954
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   293
            registerShutdownHook();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        synchronized(this) {
7954
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   297
            inited = true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        if (startPump) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            eventLoop(); // will Dispose Toolkit when shutdown hook executes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * eventLoop() begins the native message pump which retrieves and processes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * native events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * When shutdown() is called by the ShutdownHook added in run(), a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * WM_QUIT message is posted to the Toolkit thread indicating that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * eventLoop() should Dispose the toolkit and exit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    private native boolean init();
7954
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   315
    private boolean inited = false;
13aa14c7723e 7011446: ./windows/classes/sun/awt/windows/WToolkit.java needs to avoid spurious wakeup
dcherepanov
parents: 7668
diff changeset
   316
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    private native void eventLoop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    private native void shutdown();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * Instead of blocking the "AWT-Windows" thread uselessly on a semaphore,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * use these functions. startSecondaryEventLoop() corresponds to wait()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * and quitSecondaryEventLoop() corresponds to notify.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * These functions simulate blocking while allowing the AWT to continue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * processing native events, eliminating a potential deadlock situation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * with SendMessage.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * WARNING: startSecondaryEventLoop must only be called from the "AWT-
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * Windows" thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    public static native void startSecondaryEventLoop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    public static native void quitSecondaryEventLoop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * Create peer objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    public ButtonPeer createButton(Button target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        ButtonPeer peer = new WButtonPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    public TextFieldPeer createTextField(TextField target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        TextFieldPeer peer = new WTextFieldPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    public LabelPeer createLabel(Label target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        LabelPeer peer = new WLabelPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    public ListPeer createList(List target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        ListPeer peer = new WListPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    public CheckboxPeer createCheckbox(Checkbox target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        CheckboxPeer peer = new WCheckboxPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    public ScrollbarPeer createScrollbar(Scrollbar target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        ScrollbarPeer peer = new WScrollbarPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    public ScrollPanePeer createScrollPane(ScrollPane target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        ScrollPanePeer peer = new WScrollPanePeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    public TextAreaPeer createTextArea(TextArea target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        TextAreaPeer peer = new WTextAreaPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    public ChoicePeer createChoice(Choice target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        ChoicePeer peer = new WChoicePeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    public FramePeer  createFrame(Frame target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        FramePeer peer = new WFramePeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    public CanvasPeer createCanvas(Canvas target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        CanvasPeer peer = new WCanvasPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    public void disableBackgroundErase(Canvas canvas) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        WCanvasPeer peer = (WCanvasPeer)canvas.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        if (peer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            throw new IllegalStateException("Canvas must have a valid peer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        peer.disableBackgroundErase();
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 PanelPeer createPanel(Panel target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        PanelPeer peer = new WPanelPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    public WindowPeer createWindow(Window target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        WindowPeer peer = new WWindowPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    public DialogPeer createDialog(Dialog target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        DialogPeer peer = new WDialogPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    public FileDialogPeer createFileDialog(FileDialog target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        FileDialogPeer peer = new WFileDialogPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    public MenuBarPeer createMenuBar(MenuBar target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        MenuBarPeer peer = new WMenuBarPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    public MenuPeer createMenu(Menu target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        MenuPeer peer = new WMenuPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    public PopupMenuPeer createPopupMenu(PopupMenu target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        PopupMenuPeer peer = new WPopupMenuPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    public MenuItemPeer createMenuItem(MenuItem target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        MenuItemPeer peer = new WMenuItemPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    public CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        CheckboxMenuItemPeer peer = new WCheckboxMenuItemPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    public RobotPeer createRobot(Robot target, GraphicsDevice screen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        // (target is unused for now)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        // Robot's don't need to go in the peer map since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        // they're not Component's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        return new WRobotPeer(screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    public WEmbeddedFramePeer createEmbeddedFrame(WEmbeddedFrame target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        WEmbeddedFramePeer peer = new WEmbeddedFramePeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    WPrintDialogPeer createWPrintDialog(WPrintDialog target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        WPrintDialogPeer peer = new WPrintDialogPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    WPageDialogPeer createWPageDialog(WPageDialog target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        WPageDialogPeer peer = new WPageDialogPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    public TrayIconPeer createTrayIcon(TrayIcon target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        WTrayIconPeer peer = new WTrayIconPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        targetCreatedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    public SystemTrayPeer createSystemTray(SystemTray target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        return new WSystemTrayPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    public boolean isTraySupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   506
    public KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(KeyboardFocusManager manager)
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   507
      throws HeadlessException
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   508
    {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   509
        return new WKeyboardFocusManagerPeer(manager);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   510
    }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2451
diff changeset
   511
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    protected native void setDynamicLayoutNative(boolean b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    public void setDynamicLayout(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        if (b == dynamicLayoutSetting) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        dynamicLayoutSetting = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        setDynamicLayoutNative(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    protected boolean isDynamicLayoutSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        return dynamicLayoutSetting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * Called from lazilyLoadDynamicLayoutSupportedProperty because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * Windows doesn't always send WM_SETTINGCHANGE when it should.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    protected native boolean isDynamicLayoutSupportedNative();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    public boolean isDynamicLayoutActive() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        return (isDynamicLayoutSet() && isDynamicLayoutSupported());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * Returns <code>true</code> if this frame state is supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    public boolean isFrameStateSupported(int state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        switch (state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
          case Frame.NORMAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
          case Frame.ICONIFIED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
          case Frame.MAXIMIZED_BOTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
              return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
              return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    static native ColorModel makeColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    static ColorModel screenmodel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    static ColorModel getStaticColorModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        if (GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        if (config == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            resetGC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        return config.getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    public ColorModel getColorModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        return getStaticColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    public Insets getScreenInsets(GraphicsConfiguration gc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        return getScreenInsets(((Win32GraphicsDevice) gc.getDevice()).getScreen());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    public int getScreenResolution() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        Win32GraphicsEnvironment ge = (Win32GraphicsEnvironment)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            GraphicsEnvironment.getLocalGraphicsEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        return ge.getXResolution();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    protected native int getScreenWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    protected native int getScreenHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    protected native Insets getScreenInsets(int screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    public FontMetrics getFontMetrics(Font font) {
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3246
diff changeset
   584
        // This is an unsupported hack, but left in for a customer.
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3246
diff changeset
   585
        // Do not remove.
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3246
diff changeset
   586
        FontManager fm = FontManagerFactory.getInstance();
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3246
diff changeset
   587
        if (fm instanceof SunFontManager
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 3246
diff changeset
   588
            && ((SunFontManager) fm).usePlatformFontMetrics()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            return WFontMetrics.getFontMetrics(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        return super.getFontMetrics(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    public FontPeer getFontPeer(String name, int style) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        FontPeer retval = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        String lcName = name.toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        if (null != cacheFontPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            retval = (FontPeer)cacheFontPeer.get(lcName + style);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            if (null != retval) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                return retval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        retval = new WFontPeer(name, style);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        if (retval != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            if (null == cacheFontPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                cacheFontPeer = new Hashtable(5, (float)0.9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            if (null != cacheFontPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                cacheFontPeer.put(lcName + style, retval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        return retval;
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 native void nativeSync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    public void sync() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        // flush the GDI/DD buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        nativeSync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        // now flush the OGL pipeline (this is a no-op if OGL is not enabled)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        OGLRenderQueue.sync();
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   622
        // now flush the D3D pipeline (this is a no-op if D3D is not enabled)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   623
        D3DRenderQueue.sync();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    public PrintJob getPrintJob(Frame frame, String doctitle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                                Properties props) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        return getPrintJob(frame, doctitle, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    public PrintJob getPrintJob(Frame frame, String doctitle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                                JobAttributes jobAttributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                                PageAttributes pageAttributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        if (GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        PrintJob2D printJob = new PrintJob2D(frame, doctitle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                                             jobAttributes, pageAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        if (printJob.printDialog() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            printJob = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        return printJob;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    public native void beep();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    public boolean getLockingKeyState(int key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        if (! (key == KeyEvent.VK_CAPS_LOCK || key == KeyEvent.VK_NUM_LOCK ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
               key == KeyEvent.VK_SCROLL_LOCK || key == KeyEvent.VK_KANA_LOCK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            throw new IllegalArgumentException("invalid key for Toolkit.getLockingKeyState");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        return getLockingKeyStateNative(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    public native boolean getLockingKeyStateNative(int key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    public void setLockingKeyState(int key, boolean on) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        if (! (key == KeyEvent.VK_CAPS_LOCK || key == KeyEvent.VK_NUM_LOCK ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
               key == KeyEvent.VK_SCROLL_LOCK || key == KeyEvent.VK_KANA_LOCK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            throw new IllegalArgumentException("invalid key for Toolkit.setLockingKeyState");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        setLockingKeyStateNative(key, on);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    public native void setLockingKeyStateNative(int key, boolean on);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    public Clipboard getSystemClipboard() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
          security.checkSystemClipboardAccess();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            if (clipboard == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                clipboard = new WClipboard();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        return clipboard;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    protected native void loadSystemColors(int[] systemColors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    public static final Object targetToPeer(Object target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        return SunToolkit.targetToPeer(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    public static final void targetDisposedPeer(Object target, Object peer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        SunToolkit.targetDisposedPeer(target, peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * Returns a new input method adapter descriptor for native input methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    public InputMethodDescriptor getInputMethodAdapterDescriptor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        return new WInputMethodDescriptor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * Returns a style map for the input method highlight.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    public Map mapInputMethodHighlight(InputMethodHighlight highlight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        return WInputMethod.mapInputMethodHighlight(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * Returns whether enableInputMethods should be set to true for peered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * TextComponent instances on this platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    public boolean enableInputMethodsForTextComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * Returns the default keyboard locale of the underlying operating system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    public Locale getDefaultKeyboardLocale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        Locale locale = WInputMethod.getNativeLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        if (locale == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            return super.getDefaultKeyboardLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            return locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * Returns a new custom cursor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    public Cursor createCustomCursor(Image cursor, Point hotSpot, String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        throws IndexOutOfBoundsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        return new WCustomCursor(cursor, hotSpot, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * Returns the supported cursor size (Win32 only has one).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    public Dimension getBestCursorSize(int preferredWidth, int preferredHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        return new Dimension(WCustomCursor.getCursorWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                             WCustomCursor.getCursorHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    public native int getMaximumCursorColors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    static void paletteChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        ((Win32GraphicsEnvironment)GraphicsEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        .getLocalGraphicsEnvironment())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        .paletteChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * Called from Toolkit native code when a WM_DISPLAYCHANGE occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * Have Win32GraphicsEnvironment execute the display change code on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * Event thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    static public void displayChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        EventQueue.invokeLater(new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                ((Win32GraphicsEnvironment)GraphicsEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                .getLocalGraphicsEnvironment())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                .displayChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * create the peer for a DragSourceContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        return WDragSourceContextPeer.createDragSourceContextPeer(dge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    public <T extends DragGestureRecognizer> T
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        createDragGestureRecognizer(Class<T> abstractRecognizerClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                                    DragSource ds, Component c, int srcActions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                                    DragGestureListener dgl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        if (MouseDragGestureRecognizer.class.equals(abstractRecognizerClass))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            return (T)new WMouseDragGestureRecognizer(ds, c, srcActions, dgl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    private static final String prefix  = "DnD.Cursor.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    private static final String postfix = ".32x32";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    private static final String awtPrefix  = "awt.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    private static final String dndPrefix  = "DnD.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    protected Object lazilyLoadDesktopProperty(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        if (name.startsWith(prefix)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            String cursorName = name.substring(prefix.length(), name.length()) + postfix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                return Cursor.getSystemCustomCursor(cursorName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            } catch (AWTException awte) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                throw new RuntimeException("cannot load system cursor: " + cursorName, awte);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        if (name.equals("awt.dynamicLayoutSupported")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            return  Boolean.valueOf(isDynamicLayoutSupported());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        if (WDesktopProperties.isWindowsProperty(name) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            name.startsWith(awtPrefix) || name.startsWith(dndPrefix))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
            synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                lazilyInitWProps();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                return desktopProperties.get(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        return super.lazilyLoadDesktopProperty(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    private synchronized void lazilyInitWProps() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        if (wprops == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            wprops = new WDesktopProperties(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            updateProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * Called from lazilyLoadDesktopProperty because Windows doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * always send WM_SETTINGCHANGE when it should.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    private synchronized boolean isDynamicLayoutSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        boolean nativeDynamic = isDynamicLayoutSupportedNative();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        lazilyInitWProps();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        Boolean prop = (Boolean) desktopProperties.get("awt.dynamicLayoutSupported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
   839
        if (log.isLoggable(PlatformLogger.FINER)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
   840
            log.finer("In WTK.isDynamicLayoutSupported()" +
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
   841
                      "   nativeDynamic == " + nativeDynamic +
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
   842
                      "   wprops.dynamic == " + prop);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        if ((prop == null) || (nativeDynamic != prop.booleanValue())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            // We missed the WM_SETTINGCHANGE, so we pretend
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            // we just got one - fire the propertyChange, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            windowsSettingChange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            return nativeDynamic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        return prop.booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * Called from native toolkit code when WM_SETTINGCHANGE message received
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * Also called from lazilyLoadDynamicLayoutSupportedProperty because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * Windows doesn't always send WM_SETTINGCHANGE when it should.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    private void windowsSettingChange() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        EventQueue.invokeLater(new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                updateProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    private synchronized void updateProperties() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        if (null == wprops) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            // wprops has not been initialized, so we have nothing to update
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        Map<String, Object> props = wprops.getProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        for (String propName : props.keySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
            Object val = props.get(propName);
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
   877
            if (log.isLoggable(PlatformLogger.FINER)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3928
diff changeset
   878
                log.finer("changed " + propName + " to " + val);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            setDesktopProperty(propName, val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    public synchronized void addPropertyChangeListener(String name, PropertyChangeListener pcl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        if ( WDesktopProperties.isWindowsProperty(name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
             || name.startsWith(awtPrefix)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
             || name.startsWith(dndPrefix))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            // someone is interested in Windows-specific desktop properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            // we should initialize wprops
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            lazilyInitWProps();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        super.addPropertyChangeListener(name, pcl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * initialize only static props here and do not try to initialize props which depends on wprops,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * this should be done in lazilyLoadDesktopProperty() only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    protected synchronized void initializeDesktopProperties() {
3246
7441718ff264 6857870: Regression tests are failing with ExceptionInInitializerError
dcherepanov
parents: 2810
diff changeset
   901
        desktopProperties.put("DnD.Autoscroll.initialDelay",
7441718ff264 6857870: Regression tests are failing with ExceptionInInitializerError
dcherepanov
parents: 2810
diff changeset
   902
                              Integer.valueOf(50));
7441718ff264 6857870: Regression tests are failing with ExceptionInInitializerError
dcherepanov
parents: 2810
diff changeset
   903
        desktopProperties.put("DnD.Autoscroll.interval",
7441718ff264 6857870: Regression tests are failing with ExceptionInInitializerError
dcherepanov
parents: 2810
diff changeset
   904
                              Integer.valueOf(50));
4831
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 3938
diff changeset
   905
        desktopProperties.put("DnD.isDragImageSupported",
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents: 3938
diff changeset
   906
                              Boolean.TRUE);
3246
7441718ff264 6857870: Regression tests are failing with ExceptionInInitializerError
dcherepanov
parents: 2810
diff changeset
   907
        desktopProperties.put("Shell.shellFolderManager",
7441718ff264 6857870: Regression tests are failing with ExceptionInInitializerError
dcherepanov
parents: 2810
diff changeset
   908
                              "sun.awt.shell.Win32ShellFolderManager2");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * This returns the value for the desktop property "awt.font.desktophints"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * This requires that the Windows properties have already been gathered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
    protected synchronized RenderingHints getDesktopAAHints() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        if (wprops == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            return wprops.getDesktopAAHints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    public boolean isModalityTypeSupported(Dialog.ModalityType modalityType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        return (modalityType == null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
               (modalityType == Dialog.ModalityType.MODELESS) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
               (modalityType == Dialog.ModalityType.DOCUMENT_MODAL) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
               (modalityType == Dialog.ModalityType.APPLICATION_MODAL) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
               (modalityType == Dialog.ModalityType.TOOLKIT_MODAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    public boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType exclusionType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        return (exclusionType == null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
               (exclusionType == Dialog.ModalExclusionType.NO_EXCLUDE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
               (exclusionType == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
               (exclusionType == Dialog.ModalExclusionType.TOOLKIT_EXCLUDE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    public static WToolkit getWToolkit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        WToolkit toolkit = (WToolkit)Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        return toolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   943
    /**
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   944
     * There are two reasons why we don't use buffer per window when
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   945
     * Vista's DWM (aka Aero) is enabled:
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   946
     * - since with DWM all windows are already double-buffered, the application
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   947
     *   doesn't get expose events so we don't get to use our true back-buffer,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   948
     *   wasting memory and performance (this is valid for both d3d and gdi
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   949
     *   pipelines)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   950
     * - in some cases with buffer per window enabled it is possible for the
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   951
     *   paint manager to redirect rendering to the screen for some operations
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   952
     *   (like copyArea), and since bpw uses its own BufferStrategy the
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   953
     *   d3d onscreen rendering support is disabled and rendering goes through
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   954
     *   GDI. This doesn't work well with Vista's DWM since one
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   955
     *   can not perform GDI and D3D operations on the same surface
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   956
     *   (see 6630702 for more info)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   957
     *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   958
     * Note: even though DWM composition state can change during the lifetime
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   959
     * of the application it is a rare event, and it is more often that it
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   960
     * is temporarily disabled (because of some app) than it is getting
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   961
     * permanently enabled so we can live with this approach without the
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   962
     * complexity of dwm state listeners and such. This can be revisited if
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   963
     * proved otherwise.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   964
     */
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   965
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    public boolean useBufferPerWindow() {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   967
        return !Win32GraphicsEnvironment.isDWMCompositionEnabled();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
    public void grab(Window w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        if (w.getPeer() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
            ((WWindowPeer)w.getPeer()).grab();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    public void ungrab(Window w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        if (w.getPeer() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
           ((WWindowPeer)w.getPeer()).ungrab();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
    public native boolean syncNativeQueue(final long timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    public boolean isDesktopSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    public DesktopPeer createDesktopPeer(Desktop target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        return new WDesktopPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   991
    public static native void setExtraMouseButtonsEnabledNative(boolean enable);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   992
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   993
    public boolean areExtraMouseButtonsEnabled() throws HeadlessException {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   994
        return areExtraMouseButtonsEnabled;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 888
diff changeset
   995
    }
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
   996
2810
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2464
diff changeset
   997
    private native synchronized int getNumberOfButtonsImpl();
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2464
diff changeset
   998
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2464
diff changeset
   999
    @Override
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2464
diff changeset
  1000
    public int getNumberOfButtons(){
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2464
diff changeset
  1001
        if (numberOfButtons == 0) {
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2464
diff changeset
  1002
            numberOfButtons = getNumberOfButtonsImpl();
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2464
diff changeset
  1003
        }
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2464
diff changeset
  1004
        return (numberOfButtons > MAX_BUTTONS_SUPPORTED)? MAX_BUTTONS_SUPPORTED : numberOfButtons;
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2464
diff changeset
  1005
    }
fa49c6a06baf 6799099: All automatic regression tests that create Robot fail on X11
dav
parents: 2464
diff changeset
  1006
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1007
    @Override
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1008
    public boolean isWindowOpacitySupported() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1009
        // supported in Win2K and later
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1010
        return true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1011
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1012
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1013
    @Override
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1014
    public boolean isWindowShapingSupported() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1015
        return true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1016
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1017
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1018
    @Override
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1019
    public boolean isWindowTranslucencySupported() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1020
        // supported in Win2K and later
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1021
        return true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1022
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1023
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1024
    @Override
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1025
    public boolean isTranslucencyCapable(GraphicsConfiguration gc) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1026
        //XXX: worth checking if 8-bit? Anyway, it doesn't hurt.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1027
        return true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1028
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1029
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1030
    // On MS Windows one must use the peer.updateWindow() to implement
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1031
    // non-opaque windows.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1032
    @Override
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1033
    public boolean needUpdateWindow() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1034
        return true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1962
diff changeset
  1035
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
}