jdk/src/windows/classes/sun/awt/windows/WWindowPeer.java
author lana
Tue, 02 Nov 2010 22:15:35 -0700
changeset 7146 d0163a4e4e75
parent 6828 3999af3d33de
parent 6996 5122ee0dcc92
child 7668 d4a77089c587
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4366
diff changeset
     2
 * Copyright (c) 1996, 2009, 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: 4366
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: 4366
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: 4366
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4366
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4366
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.awt.windows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.image.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.peer.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.List;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3237
diff changeset
    38
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.awt.*;
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
    41
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
    42
import sun.java2d.pipe.Region;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
    44
public class WWindowPeer extends WPanelPeer implements WindowPeer,
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
    45
       DisplayChangedListener
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
    46
{
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3237
diff changeset
    48
    private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.windows.WWindowPeer");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3237
diff changeset
    49
    private static final PlatformLogger screenLog = PlatformLogger.getLogger("sun.awt.windows.screen.WWindowPeer");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    // we can't use WDialogPeer as blocker may be an instance of WPrintDialogPeer that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    // extends WWindowPeer, not WDialogPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private WWindowPeer modalBlocker = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
    55
    private boolean isOpaque;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
    56
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
    57
    private TranslucentWindowPainter painter;
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
    58
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * A key used for storing a list of active windows in AppContext. The value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * is a list of windows, sorted by the time of activation: later a window is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * activated, greater its index is in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private final static StringBuffer ACTIVE_WINDOWS_KEY =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        new StringBuffer("active_windows_list");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * Listener for 'activeWindow' KFM property changes. It is added to each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * AppContext KFM. See ActiveWindowListener inner class below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private static PropertyChangeListener activeWindowListener =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        new ActiveWindowListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * The object is a listener for the AppContext.GUI_DISPOSED property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private final static PropertyChangeListener guiDisposedListener =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        new GuiDisposedListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
    80
    /*
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
    81
     * Called (on the Toolkit thread) before the appropriate
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
    82
     * WindowStateEvent is posted to the EventQueue.
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
    83
     */
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
    84
    private WindowListener windowListener;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
    85
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Initialize JNI field IDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    // WComponentPeer overrides
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    protected void disposeImpl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        AppContext appContext = SunToolkit.targetToAppContext(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        synchronized (appContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            List<WWindowPeer> l = (List<WWindowPeer>)appContext.get(ACTIVE_WINDOWS_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            if (l != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                l.remove(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   104
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        // Remove ourself from the Map of DisplayChangeListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        GraphicsConfiguration gc = getGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        ((Win32GraphicsDevice)gc.getDevice()).removeDisplayChangedListener(this);
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   108
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   109
        synchronized (getStateLock()) {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   110
            TranslucentWindowPainter currentPainter = painter;
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   111
            if (currentPainter != null) {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   112
                currentPainter.flush();
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   113
                // don't set the current one to null here; reduces the chances of
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   114
                // MT issues (like NPEs)
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   115
            }
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   116
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   117
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        super.disposeImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    // WindowPeer implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public void toFront() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        updateFocusableWindowState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        _toFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    native void _toFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public native void toBack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public native void setAlwaysOnTopNative(boolean value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public void setAlwaysOnTop(boolean value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        if ((value && ((Window)target).isVisible()) || !value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            setAlwaysOnTopNative(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public void updateFocusableWindowState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        setFocusableWindow(((Window)target).isFocusableWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    native void setFocusableWindow(boolean value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    // FramePeer & DialogPeer partial shared implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public void setTitle(String title) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        // allow a null title to pass as an empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if (title == null) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 129
diff changeset
   147
            title = "";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        _setTitle(title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    native void _setTitle(String title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public void setResizable(boolean resizable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        _setResizable(resizable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public native void _setResizable(boolean resizable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    // Toolkit & peer internals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    WWindowPeer(Window target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        super(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    void initialize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        super.initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        updateInsets(insets_);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        Font f = ((Window)target).getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (f == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            f = defaultFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            ((Window)target).setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        // Express our interest in display changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        GraphicsConfiguration gc = getGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        ((Win32GraphicsDevice)gc.getDevice()).addDisplayChangedListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        initActiveWindowsTracking((Window)target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        updateIconImages();
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   182
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   183
        Shape shape = ((Window)target).getShape();
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   184
        if (shape != null) {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   185
            applyShape(Region.getInstance(shape, null));
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   186
        }
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   187
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   188
        float opacity = ((Window)target).getOpacity();
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   189
        if (opacity < 1.0f) {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   190
            setOpacity(opacity);
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   191
        }
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   192
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   193
        synchronized (getStateLock()) {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   194
            // default value of a boolean field is 'false', so set isOpaque to
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   195
            // true here explicitly
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   196
            this.isOpaque = true;
3237
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 2808
diff changeset
   197
            setOpaque(((Window)target).isOpaque());
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   198
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    native void createAwtWindow(WComponentPeer parent);
4366
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4259
diff changeset
   202
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4259
diff changeset
   203
    private volatile Window.Type windowType = Window.Type.NORMAL;
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4259
diff changeset
   204
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4259
diff changeset
   205
    // This method must be called for Window, Dialog, and Frame before creating
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4259
diff changeset
   206
    // the hwnd
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4259
diff changeset
   207
    void preCreate(WComponentPeer parent) {
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4259
diff changeset
   208
        windowType = ((Window)target).getType();
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4259
diff changeset
   209
    }
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4259
diff changeset
   210
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    void create(WComponentPeer parent) {
4366
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4259
diff changeset
   212
        preCreate(parent);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        createAwtWindow(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    // should be overriden in WDialogPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    protected void realShow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        super.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public void show() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        updateFocusableWindowState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        boolean alwaysOnTop = ((Window)target).isAlwaysOnTop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        // Fix for 4868278.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        // If we create a window with a specific GraphicsConfig, and then move it with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        // setLocation() or setBounds() to another one before its peer has been created,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        // then calling Window.getGraphicsConfig() returns wrong config. That may lead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        // to some problems like wrong-placed tooltips. It is caused by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        // super.displayChanged() in WWindowPeer.displayChanged() regardless of whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        // GraphicsDevice was really changed, or not. So we need to track it here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        updateGC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        realShow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        updateMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        if (((Window)target).isAlwaysOnTopSupported() && alwaysOnTop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            setAlwaysOnTop(alwaysOnTop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   241
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   242
        synchronized (getStateLock()) {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   243
            if (!isOpaque) {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   244
                updateWindow(true);
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   245
            }
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   246
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    // Synchronize the insets members (here & in helper) with actual window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    // state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    native void updateInsets(Insets i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    static native int getSysMinWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    static native int getSysMinHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    static native int getSysIconWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    static native int getSysIconHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    static native int getSysSmIconWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    static native int getSysSmIconHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /**windows/classes/sun/awt/windows/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * Creates native icon from specified raster data and updates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * icon for window and all descendant windows that inherit icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * Raster data should be passed in the ARGB form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * Note that raster data format was changed to provide support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * for XP icons with alpha-channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    native void setIconImagesData(int[] iconRaster, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                                  int[] smallIconRaster, int smw, int smh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    synchronized native void reshapeFrame(int x, int y, int width, int height);
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   270
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   271
    public boolean requestWindowFocus(CausedFocusEvent.Cause cause) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   272
        if (!focusAllowedFor()) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   273
            return false;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   274
        }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   275
        return requestWindowFocus(cause == CausedFocusEvent.Cause.MOUSE_EVENT);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   277
    public native boolean requestWindowFocus(boolean isMouseEventCause);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public boolean focusAllowedFor() {
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   280
        Window window = (Window)this.target;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   281
        if (!window.isVisible() ||
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   282
            !window.isEnabled() ||
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   283
            !window.isFocusableWindow())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        if (isModalBlocked()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   290
        return true;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   291
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   293
    public void hide() {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   294
        WindowListener listener = windowListener;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   295
        if (listener != null) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   296
            // We're not getting WINDOW_CLOSING from the native code when hiding
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   297
            // the window programmatically. So, create it and notify the listener.
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   298
            listener.windowClosing(new WindowEvent((Window)target, WindowEvent.WINDOW_CLOSING));
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   299
        }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   300
        super.hide();
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   301
    }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   302
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   303
    // WARNING: it's called on the Toolkit thread!
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   304
    void preprocessPostEvent(AWTEvent event) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   305
        if (event instanceof WindowEvent) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   306
            WindowListener listener = windowListener;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   307
            if (listener != null) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   308
                switch(event.getID()) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   309
                    case WindowEvent.WINDOW_CLOSING:
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   310
                        listener.windowClosing((WindowEvent)event);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   311
                        break;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   312
                    case WindowEvent.WINDOW_ICONIFIED:
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   313
                        listener.windowIconified((WindowEvent)event);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   314
                        break;
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   315
                }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   316
            }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   317
        }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   318
    }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   319
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   320
    synchronized void addWindowListener(WindowListener l) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   321
        windowListener = AWTEventMulticaster.add(windowListener, l);
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   322
    }
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   323
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   324
    synchronized void removeWindowListener(WindowListener l) {
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2459
diff changeset
   325
        windowListener = AWTEventMulticaster.remove(windowListener, l);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    public void updateMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        Dimension minimumSize = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        if (((Component)target).isMinimumSizeSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            minimumSize = ((Component)target).getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        if (minimumSize != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            int msw = getSysMinWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            int msh = getSysMinHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            int w = (minimumSize.width >= msw) ? minimumSize.width : msw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            int h = (minimumSize.height >= msh) ? minimumSize.height : msh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            setMinSize(w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            setMinSize(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    public void updateIconImages() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        java.util.List<Image> imageList = ((Window)target).getIconImages();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        if (imageList == null || imageList.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            setIconImagesData(null, 0, 0, null, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            int w = getSysIconWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            int h = getSysIconHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            int smw = getSysSmIconWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            int smh = getSysSmIconHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            DataBufferInt iconData = SunToolkit.getScaledIconData(imageList,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                                                                  w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            DataBufferInt iconSmData = SunToolkit.getScaledIconData(imageList,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                                                                    smw, smh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            if (iconData != null && iconSmData != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                setIconImagesData(iconData.getData(), w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                                  iconSmData.getData(), smw, smh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                setIconImagesData(null, 0, 0, null, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    native void setMinSize(int width, int height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
 * ---- MODALITY SUPPORT ----
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * Some modality-related code here because WFileDialogPeer, WPrintDialogPeer and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *   WPageDialogPeer are descendants of WWindowPeer, not WDialogPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    public boolean isModalBlocked() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        return modalBlocker != null;
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 void setModalBlocked(Dialog dialog, boolean blocked) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        synchronized (((Component)getTarget()).getTreeLock()) // State lock should always be after awtLock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            // use WWindowPeer instead of WDialogPeer because of FileDialogs and PrintDialogs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            WWindowPeer blockerPeer = (WWindowPeer)dialog.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            if (blocked)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                modalBlocker = blockerPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                // handle native dialogs separately, as they may have not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                // got HWND yet; modalEnable/modalDisable is called from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                // their setHWnd() methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                if (blockerPeer instanceof WFileDialogPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                    ((WFileDialogPeer)blockerPeer).blockWindow(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                } else if (blockerPeer instanceof WPrintDialogPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                    ((WPrintDialogPeer)blockerPeer).blockWindow(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                    modalDisable(dialog, blockerPeer.getHWnd());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                modalBlocker = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                if (blockerPeer instanceof WFileDialogPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                    ((WFileDialogPeer)blockerPeer).unblockWindow(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                } else if (blockerPeer instanceof WPrintDialogPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                    ((WPrintDialogPeer)blockerPeer).unblockWindow(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                    modalEnable(dialog);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    native void modalDisable(Dialog blocker, long blockerHWnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    native void modalEnable(Dialog blocker);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * Returns all the ever active windows from the current AppContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * The list is sorted by the time of activation, so the latest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * active window is always at the end.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    public static long[] getActiveWindowHandles() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        AppContext appContext = AppContext.getAppContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        synchronized (appContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            List<WWindowPeer> l = (List<WWindowPeer>)appContext.get(ACTIVE_WINDOWS_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            long[] result = new long[l.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            for (int j = 0; j < l.size(); j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                result[j] = l.get(j).getHWnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
 * ----DISPLAY CHANGE SUPPORT----
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * Called from native code when we have been dragged onto another screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    void draggedToNewScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        SunToolkit.executeOnEventHandlerThread((Component)target,new Runnable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                displayChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    public void updateGC() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        int scrn = getScreenImOn();
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3237
diff changeset
   453
        if (screenLog.isLoggable(PlatformLogger.FINER)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3237
diff changeset
   454
            log.finer("Screen number: " + scrn);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        // get current GD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        Win32GraphicsDevice oldDev = (Win32GraphicsDevice)winGraphicsConfig
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                                     .getDevice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        Win32GraphicsDevice newDev;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        GraphicsDevice devs[] = GraphicsEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            .getLocalGraphicsEnvironment()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            .getScreenDevices();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        // Occasionally during device addition/removal getScreenImOn can return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        // a non-existing screen number. Use the default device in this case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        if (scrn >= devs.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            newDev = (Win32GraphicsDevice)GraphicsEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                .getLocalGraphicsEnvironment().getDefaultScreenDevice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            newDev = (Win32GraphicsDevice)devs[scrn];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        // Set winGraphicsConfig to the default GC for the monitor this Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        // is now mostly on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        winGraphicsConfig = (Win32GraphicsConfig)newDev
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                            .getDefaultConfiguration();
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3237
diff changeset
   478
        if (screenLog.isLoggable(PlatformLogger.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            if (winGraphicsConfig == null) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3237
diff changeset
   480
                screenLog.fine("Assertion (winGraphicsConfig != null) failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        // if on a different display, take off old GD and put on new GD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        if (oldDev != newDev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            oldDev.removeDisplayChangedListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            newDev.addDisplayChangedListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        }
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   489
6828
3999af3d33de 6838089: java.awt.Window.setOpacity() doesn't throw IllegalComponentStateException for two-display conf
dcherepanov
parents: 6645
diff changeset
   490
        AWTAccessor.getComponentAccessor().
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   491
            setGraphicsConfiguration((Component)target, winGraphicsConfig);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   494
    /**
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   495
     * From the DisplayChangedListener interface.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * This method handles a display change - either when the display settings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * are changed, or when the window has been dragged onto a different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * display.
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   500
     * Called after a change in the display mode.  This event
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   501
     * triggers replacing the surfaceData object (since that object
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   502
     * reflects the current display depth information, which has
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   503
     * just changed).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    public void displayChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        updateGC();
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   507
    }
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   508
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   509
    /**
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   510
     * Part of the DisplayChangedListener interface: components
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   511
     * do not need to react to this event
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   512
     */
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2451
diff changeset
   513
    public void paletteChanged() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    private native int getScreenImOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
4256
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 3237
diff changeset
   518
    // Used in Win32GraphicsDevice.
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 3237
diff changeset
   519
    public final native void setFullScreenExclusiveModeState(boolean state);
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 3237
diff changeset
   520
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
 * ----END DISPLAY CHANGE SUPPORT----
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     public void grab() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
         nativeGrab();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     public void ungrab() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
         nativeUngrab();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     private native void nativeGrab();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     private native void nativeUngrab();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   535
     private final boolean hasWarningWindow() {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   536
         return ((Window)target).getWarningString() != null;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   537
     }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   538
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   539
     boolean isTargetUndecorated() {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   540
         return true;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   541
     }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   542
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   543
     // These are the peer bounds. They get updated at:
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   544
     //    1. the WWindowPeer.setBounds() method.
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   545
     //    2. the native code (on WM_SIZE/WM_MOVE)
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   546
     private volatile int sysX = 0;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   547
     private volatile int sysY = 0;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   548
     private volatile int sysW = 0;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   549
     private volatile int sysH = 0;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   550
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
   551
     public native void repositionSecurityWarning();
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2464
diff changeset
   552
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   553
     @Override
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   554
     public void setBounds(int x, int y, int width, int height, int op) {
2643
ea218b1a2000 6821948: Consider removing the constraints for bounds of untrusted top-level windows
anthony
parents: 2472
diff changeset
   555
         sysX = x;
ea218b1a2000 6821948: Consider removing the constraints for bounds of untrusted top-level windows
anthony
parents: 2472
diff changeset
   556
         sysY = y;
ea218b1a2000 6821948: Consider removing the constraints for bounds of untrusted top-level windows
anthony
parents: 2472
diff changeset
   557
         sysW = width;
ea218b1a2000 6821948: Consider removing the constraints for bounds of untrusted top-level windows
anthony
parents: 2472
diff changeset
   558
         sysH = height;
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   559
2643
ea218b1a2000 6821948: Consider removing the constraints for bounds of untrusted top-level windows
anthony
parents: 2472
diff changeset
   560
         super.setBounds(x, y, width, height, op);
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   561
     }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   562
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   563
    @Override
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   564
    public void print(Graphics g) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   565
        // We assume we print the whole frame,
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   566
        // so we expect no clip was set previously
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   567
        Shape shape = AWTAccessor.getWindowAccessor().getShape((Window)target);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   568
        if (shape != null) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   569
            g.setClip(shape);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   570
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   571
        super.print(g);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   572
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   573
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   574
    private void replaceSurfaceDataRecursively(Component c) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   575
        if (c instanceof Container) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   576
            for (Component child : ((Container)c).getComponents()) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   577
                replaceSurfaceDataRecursively(child);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   578
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   579
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   580
        ComponentPeer cp = c.getPeer();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   581
        if (cp instanceof WComponentPeer) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   582
            ((WComponentPeer)cp).replaceSurfaceDataLater();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   583
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   584
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   585
4258
50b23b28d857 6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents: 4256
diff changeset
   586
    public final Graphics getTranslucentGraphics() {
50b23b28d857 6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents: 4256
diff changeset
   587
        synchronized (getStateLock()) {
50b23b28d857 6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents: 4256
diff changeset
   588
            return isOpaque ? null : painter.getBackBuffer(false).getGraphics();
50b23b28d857 6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents: 4256
diff changeset
   589
        }
50b23b28d857 6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents: 4256
diff changeset
   590
    }
50b23b28d857 6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents: 4256
diff changeset
   591
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   592
    @Override
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   593
    public void setBackground(Color c) {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   594
        super.setBackground(c);
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   595
        synchronized (getStateLock()) {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   596
            if (!isOpaque && ((Window)target).isVisible()) {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   597
                updateWindow(true);
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   598
            }
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   599
        }
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   600
    }
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   601
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   602
    private native void setOpacity(int iOpacity);
6996
5122ee0dcc92 6663447: D3D: excessive surface data replacements
bae
parents: 6645
diff changeset
   603
    private float opacity = 1.0f;
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   604
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   605
    public void setOpacity(float opacity) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   606
        if (!((SunToolkit)((Window)target).getToolkit()).
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   607
            isWindowOpacitySupported())
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   608
        {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   609
            return;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   610
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   611
6996
5122ee0dcc92 6663447: D3D: excessive surface data replacements
bae
parents: 6645
diff changeset
   612
        if (opacity < 0.0f || opacity > 1.0f) {
5122ee0dcc92 6663447: D3D: excessive surface data replacements
bae
parents: 6645
diff changeset
   613
            throw new IllegalArgumentException(
5122ee0dcc92 6663447: D3D: excessive surface data replacements
bae
parents: 6645
diff changeset
   614
                "The value of opacity should be in the range [0.0f .. 1.0f].");
5122ee0dcc92 6663447: D3D: excessive surface data replacements
bae
parents: 6645
diff changeset
   615
        }
5122ee0dcc92 6663447: D3D: excessive surface data replacements
bae
parents: 6645
diff changeset
   616
5122ee0dcc92 6663447: D3D: excessive surface data replacements
bae
parents: 6645
diff changeset
   617
        if (((this.opacity == 1.0f && opacity <  1.0f) ||
5122ee0dcc92 6663447: D3D: excessive surface data replacements
bae
parents: 6645
diff changeset
   618
             (this.opacity <  1.0f && opacity == 1.0f)) &&
5122ee0dcc92 6663447: D3D: excessive surface data replacements
bae
parents: 6645
diff changeset
   619
            !Win32GraphicsEnvironment.isVistaOS())
5122ee0dcc92 6663447: D3D: excessive surface data replacements
bae
parents: 6645
diff changeset
   620
        {
5122ee0dcc92 6663447: D3D: excessive surface data replacements
bae
parents: 6645
diff changeset
   621
            // non-Vista OS: only replace the surface data if opacity status
5122ee0dcc92 6663447: D3D: excessive surface data replacements
bae
parents: 6645
diff changeset
   622
            // changed (see WComponentPeer.isAccelCapable() for more)
5122ee0dcc92 6663447: D3D: excessive surface data replacements
bae
parents: 6645
diff changeset
   623
            replaceSurfaceDataRecursively((Component)getTarget());
5122ee0dcc92 6663447: D3D: excessive surface data replacements
bae
parents: 6645
diff changeset
   624
        }
5122ee0dcc92 6663447: D3D: excessive surface data replacements
bae
parents: 6645
diff changeset
   625
5122ee0dcc92 6663447: D3D: excessive surface data replacements
bae
parents: 6645
diff changeset
   626
        this.opacity = opacity;
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   627
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   628
        final int maxOpacity = 0xff;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   629
        int iOpacity = (int)(opacity * maxOpacity);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   630
        if (iOpacity < 0) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   631
            iOpacity = 0;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   632
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   633
        if (iOpacity > maxOpacity) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   634
            iOpacity = maxOpacity;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   635
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   636
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   637
        setOpacity(iOpacity);
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   638
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   639
        synchronized (getStateLock()) {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   640
            if (!isOpaque && ((Window)target).isVisible()) {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   641
                updateWindow(true);
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   642
            }
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   643
        }
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   644
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   645
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   646
    private native void setOpaqueImpl(boolean isOpaque);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   647
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   648
    public void setOpaque(boolean isOpaque) {
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   649
        synchronized (getStateLock()) {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   650
            if (this.isOpaque == isOpaque) {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   651
                return;
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   652
            }
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   653
        }
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   654
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   655
        Window target = (Window)getTarget();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   656
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2643
diff changeset
   657
        if (!isOpaque) {
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2643
diff changeset
   658
            SunToolkit sunToolkit = (SunToolkit)target.getToolkit();
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2643
diff changeset
   659
            if (!sunToolkit.isWindowTranslucencySupported() ||
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2643
diff changeset
   660
                !sunToolkit.isTranslucencyCapable(target.getGraphicsConfiguration()))
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2643
diff changeset
   661
            {
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2643
diff changeset
   662
                return;
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2643
diff changeset
   663
            }
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   664
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   665
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   666
        boolean isVistaOS = Win32GraphicsEnvironment.isVistaOS();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   667
6996
5122ee0dcc92 6663447: D3D: excessive surface data replacements
bae
parents: 6645
diff changeset
   668
        if (this.isOpaque != isOpaque && !isVistaOS) {
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   669
            // non-Vista OS: only replace the surface data if the opacity
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   670
            // status changed (see WComponentPeer.isAccelCapable() for more)
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   671
            replaceSurfaceDataRecursively(target);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   672
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   673
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   674
        synchronized (getStateLock()) {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   675
            this.isOpaque = isOpaque;
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   676
            setOpaqueImpl(isOpaque);
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   677
            if (isOpaque) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   678
                TranslucentWindowPainter currentPainter = painter;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   679
                if (currentPainter != null) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   680
                    currentPainter.flush();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   681
                    painter = null;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   682
                }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   683
            } else {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   684
                painter = TranslucentWindowPainter.createInstance(this);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   685
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   686
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   687
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   688
        if (isVistaOS) {
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   689
            // On Vista: setting the window non-opaque makes the window look
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   690
            // rectangular, though still catching the mouse clicks within
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   691
            // its shape only. To restore the correct visual appearance
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   692
            // of the window (i.e. w/ the correct shape) we have to reset
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   693
            // the shape.
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2643
diff changeset
   694
            Shape shape = ((Window)target).getShape();
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   695
            if (shape != null) {
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2643
diff changeset
   696
                ((Window)target).setShape(shape);
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   697
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   698
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   699
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   700
        if (((Window)target).isVisible()) {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   701
            updateWindow(true);
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   702
        }
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   703
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   704
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   705
    public native void updateWindowImpl(int[] data, int width, int height);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   706
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   707
    public void updateWindow() {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   708
        updateWindow(false);
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   709
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   710
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   711
    private void updateWindow(boolean repaint) {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   712
        Window w = (Window)target;
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   713
        synchronized (getStateLock()) {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   714
            if (isOpaque || !w.isVisible() ||
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   715
                (w.getWidth() <= 0) || (w.getHeight() <= 0))
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   716
            {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   717
                return;
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   718
            }
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   719
            TranslucentWindowPainter currentPainter = painter;
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   720
            if (currentPainter != null) {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   721
                currentPainter.updateWindow(repaint);
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3237
diff changeset
   722
            } else if (log.isLoggable(PlatformLogger.FINER)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3237
diff changeset
   723
                log.finer("Translucent window painter is null in updateWindow");
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   724
            }
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   725
        }
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   726
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 715
diff changeset
   727
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * The method maps the list of the active windows to the window's AppContext,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * then the method registers ActiveWindowListener, GuiDisposedListener listeners;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * it executes the initilialization only once per AppContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    private static void initActiveWindowsTracking(Window w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        AppContext appContext = AppContext.getAppContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        synchronized (appContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            List<WWindowPeer> l = (List<WWindowPeer>)appContext.get(ACTIVE_WINDOWS_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                l = new LinkedList<WWindowPeer>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                appContext.put(ACTIVE_WINDOWS_KEY, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                appContext.addPropertyChangeListener(AppContext.GUI_DISPOSED, guiDisposedListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                kfm.addPropertyChangeListener("activeWindow", activeWindowListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * The GuiDisposedListener class listens for the AppContext.GUI_DISPOSED property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * it removes the list of the active windows from the disposed AppContext and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * unregisters ActiveWindowListener listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    private static class GuiDisposedListener implements PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            boolean isDisposed = (Boolean)e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            if (isDisposed != true) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3237
diff changeset
   757
                if (log.isLoggable(PlatformLogger.FINE)) {
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3237
diff changeset
   758
                    log.fine(" Assertion (newValue != true) failed for AppContext.GUI_DISPOSED ");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            AppContext appContext = AppContext.getAppContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            synchronized (appContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                appContext.remove(ACTIVE_WINDOWS_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                appContext.removePropertyChangeListener(AppContext.GUI_DISPOSED, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                kfm.removePropertyChangeListener("activeWindow", activeWindowListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * Static inner class, listens for 'activeWindow' KFM property changes and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * updates the list of active windows per AppContext, so the latest active
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * window is always at the end of the list. The list is stored in AppContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    private static class ActiveWindowListener implements PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            Window w = (Window)e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            if (w == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            AppContext appContext = SunToolkit.targetToAppContext(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            synchronized (appContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                WWindowPeer wp = (WWindowPeer)w.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                // add/move wp to the end of the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                List<WWindowPeer> l = (List<WWindowPeer>)appContext.get(ACTIVE_WINDOWS_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                if (l != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                    l.remove(wp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                    l.add(wp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
}