jdk/src/solaris/classes/sun/awt/X11/XWindowPeer.java
author yan
Mon, 06 Oct 2008 16:45:00 +0400
changeset 1966 12a51fb0db0d
parent 1962 6c293d33645b
child 2451 597df8e1d786
permissions -rw-r--r--
5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif Summary: Does not work on Motif but works on XToolkit now; implemented using XQueryPointer. Reviewed-by: anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
116
9c43d9eb1029 6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents: 2
diff changeset
     2
 * Copyright 2002-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.awt.X11;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.ComponentEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.event.FocusEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.event.WindowEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.peer.ComponentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.peer.WindowPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.logging.Level;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.util.logging.Logger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import sun.awt.ComponentAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import sun.awt.WindowAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import sun.awt.DisplayChangedListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import sun.awt.X11GraphicsDevice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import sun.awt.X11GraphicsEnvironment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
class XWindowPeer extends XPanelPeer implements WindowPeer,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
    53
                                                DisplayChangedListener {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private static final Logger log = Logger.getLogger("sun.awt.X11.XWindowPeer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static final Logger focusLog = Logger.getLogger("sun.awt.X11.focus.XWindowPeer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private static final Logger insLog = Logger.getLogger("sun.awt.X11.insets.XWindowPeer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private static final Logger grabLog = Logger.getLogger("sun.awt.X11.grab.XWindowPeer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static final Logger iconLog = Logger.getLogger("sun.awt.X11.icon.XWindowPeer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    // should be synchronized on awtLock
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private static Set<XWindowPeer> windows = new HashSet<XWindowPeer>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    static XAtom wm_protocols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    static XAtom wm_delete_window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    static XAtom wm_take_focus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    XWindowAttributesData winAttr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private boolean cachedFocusableWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    XWarningWindow warningWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private boolean alwaysOnTop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    PropMwmHints mwm_hints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private boolean locationByPlatform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    Dialog modalBlocker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    boolean delayedModalBlocking = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    Dimension targetMinimumSize = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private XWindowPeer ownerPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    // used for modal blocking to keep existing z-order
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    protected XWindowPeer prevTransientFor, nextTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    // value of WM_TRANSIENT_FOR hint set on this window
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private XWindowPeer curRealTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private boolean grab = false; // Whether to do a grab during showing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private boolean isMapped = false; // Is this window mapped or not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private boolean stateChanged; // Indicates whether the value on savedState is valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private int savedState; // Holds last known state of the top-level window
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private boolean mustControlStackPosition = false; // Am override-redirect not on top
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private XEventDispatcher rootPropertyEventDispatcher = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Focus related flags
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private boolean isUnhiding = false;             // Is the window unhiding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private boolean isBeforeFirstMapNotify = false; // Is the window (being shown) between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                                                    //    setVisible(true) & handleMapNotify().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    // It need to be accessed from XFramePeer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    protected Vector <ToplevelStateListener> toplevelStateListeners = new Vector<ToplevelStateListener>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    XWindowPeer(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        super(params.putIfNull(PARENT_WINDOW, Long.valueOf(0)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    XWindowPeer(Window target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        super(new XCreateWindowParams(new Object[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            TARGET, target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            PARENT_WINDOW, Long.valueOf(0)}));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * This constant defines icon size recommended for using.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Apparently, we should use XGetIconSizes which should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * return icon sizes would be most appreciated by the WM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * However, XGetIconSizes always returns 0 for some reason.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * So the constant has been introduced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private static final int PREFERRED_SIZE_FOR_ICON = 128;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * Sometimes XChangeProperty(_NET_WM_ICON) doesn't work if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * image buffer is too large. This constant holds maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * length of buffer which can be used with _NET_WM_ICON hint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * It holds int's value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private static final int MAXIMUM_BUFFER_LENGTH_NET_WM_ICON = (2<<15) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    void preInit(XCreateWindowParams params) {
1190
f27065d0d9f0 6708392: Provide internal API to create OverrideRedirect windows, XToolkit
art
parents: 449
diff changeset
   132
        target = (Component)params.get(TARGET);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        params.put(REPARENTED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                   Boolean.valueOf(isOverrideRedirect() || isSimpleWindow()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        super.preInit(params);
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
   136
        params.putIfNull(BIT_GRAVITY, Integer.valueOf(XConstants.NorthWestGravity));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
   138
        savedState = XUtilConstants.WithdrawnState;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        XA_NET_WM_STATE = XAtom.get("_NET_WM_STATE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        winAttr = new XWindowAttributesData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        params.put(OVERRIDE_REDIRECT, Boolean.valueOf(isOverrideRedirect()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        SunToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            windows.add(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            if (wm_protocols == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                wm_protocols = XAtom.get("WM_PROTOCOLS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                wm_delete_window = XAtom.get("WM_DELETE_WINDOW");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                wm_take_focus = XAtom.get("WM_TAKE_FOCUS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            SunToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        cachedFocusableWindow = isFocusableWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        Font f = target.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (f == null) {
116
9c43d9eb1029 6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents: 2
diff changeset
   161
            f = XWindow.getDefaultFont();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            target.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            // we should not call setFont because it will call a repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            // which the peer may not be ready to do yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        Color c = target.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            Color background = SystemColor.window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            target.setBackground(background);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            // we should not call setBackGround because it will call a repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            // which the peer may not be ready to do yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        c = target.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            target.setForeground(SystemColor.windowText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            // we should not call setForeGround because it will call a repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            // which the peer may not be ready to do yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        alwaysOnTop = ((Window)target).isAlwaysOnTop() && ((Window)target).isAlwaysOnTopSupported();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        GraphicsConfiguration gc = getGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        ((X11GraphicsDevice)gc.getDevice()).addDisplayChangedListener(this);
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   184
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   185
        Rectangle bounds = (Rectangle)(params.get(BOUNDS));
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   186
        params.put(BOUNDS, constrainBounds(bounds.x, bounds.y, bounds.width, bounds.height));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    private void initWMProtocols() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        wm_protocols.setAtomListProperty(this, getWMProtocols());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * Returns list of protocols which should be installed on this window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Descendants can override this method to add class-specific protocols
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    protected XAtomList getWMProtocols() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        // No protocols on simple window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        return new XAtomList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    protected String getWMName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        String name = target.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (name == null || name.trim().equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            name = " ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    void postInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        super.postInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        // Init WM_PROTOCOLS atom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        initWMProtocols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        // Set WM_TRANSIENT_FOR and group_leader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        Window t_window = (Window)target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        Window owner = t_window.getOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        if (owner != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            ownerPeer = (XWindowPeer)owner.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            if (focusLog.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                focusLog.fine("Owner is " + owner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                focusLog.fine("Owner peer is " + ownerPeer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                focusLog.fine("Owner X window " + Long.toHexString(ownerPeer.getWindow()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                focusLog.fine("Owner content X window " + Long.toHexString(ownerPeer.getContentWindow()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            // as owner window may be an embedded window, we must get a toplevel window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            // to set as TRANSIENT_FOR hint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            long ownerWindow = ownerPeer.getWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            if (ownerWindow != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                    // Set WM_TRANSIENT_FOR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                    if (focusLog.isLoggable(Level.FINE)) focusLog.fine("Setting transient on " + Long.toHexString(getWindow())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                                                                       + " for " + Long.toHexString(ownerWindow));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    setToplevelTransientFor(this, ownerPeer, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    // Set group leader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                    XWMHints hints = getWMHints();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
   241
                    hints.set_flags(hints.get_flags() | (int)XUtilConstants.WindowGroupHint);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    hints.set_window_group(ownerWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                    XlibWrapper.XSetWMHints(XToolkit.getDisplay(), getWindow(), hints.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                    XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
         // Init warning window(for applets)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if (((Window)target).getWarningString() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            // accessSystemTray permission allows to display TrayIcon, TrayIcon tooltip
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            // and TrayIcon balloon windows without a warning window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            if (!WindowAccessor.isTrayIconWindow((Window)target)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                warningWindow = new XWarningWindow((Window)target, getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        setSaveUnder(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        updateIconImages();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public void updateIconImages() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        Window target = (Window)this.target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        java.util.List<Image> iconImages = ((Window)target).getIconImages();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        XWindowPeer ownerPeer = getOwnerPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        winAttr.icons = new ArrayList<XIconInfo>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        if (iconImages.size() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            //read icon images from target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            winAttr.iconsInherited = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            for (Iterator<Image> i = iconImages.iterator(); i.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                Image image = i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                if (image == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                    if (log.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                        log.finest("XWindowPeer.updateIconImages: Skipping the image passed into Java because it's null.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                XIconInfo iconInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                    iconInfo = new XIconInfo(image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                } catch (Exception e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                    if (log.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                        log.finest("XWindowPeer.updateIconImages: Perhaps the image passed into Java is broken. Skipping this icon.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                if (iconInfo.isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                    winAttr.icons.add(iconInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        // Fix for CR#6425089
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        winAttr.icons = normalizeIconImages(winAttr.icons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        if (winAttr.icons.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            //target.icons is empty or all icon images are broken
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            if (ownerPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                //icon is inherited from parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                winAttr.iconsInherited = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                winAttr.icons = ownerPeer.getIconInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                //default icon is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                winAttr.iconsInherited = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                winAttr.icons = getDefaultIconInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        recursivelySetIcon(winAttr.icons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * Sometimes XChangeProperty(_NET_WM_ICON) doesn't work if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * image buffer is too large. This function help us accommodate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * initial list of the icon images to certainly-acceptable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * It does scale some of these icons to appropriate size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * if it's necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    static java.util.List<XIconInfo> normalizeIconImages(java.util.List<XIconInfo> icons) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        java.util.List<XIconInfo> result = new ArrayList<XIconInfo>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        int totalLength = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        boolean haveLargeIcon = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        for (XIconInfo icon : icons) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            int width = icon.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            int height = icon.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            int length = icon.getRawLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            if (width > PREFERRED_SIZE_FOR_ICON || height > PREFERRED_SIZE_FOR_ICON) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                if (haveLargeIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                int scaledWidth = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                int scaledHeight = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                while (scaledWidth > PREFERRED_SIZE_FOR_ICON ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                       scaledHeight > PREFERRED_SIZE_FOR_ICON) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                    scaledWidth = scaledWidth / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                    scaledHeight = scaledHeight / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                icon.setScaledSize(scaledWidth, scaledHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                length = icon.getRawLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            if (totalLength + length <= MAXIMUM_BUFFER_LENGTH_NET_WM_ICON) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                totalLength += length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                result.add(icon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                if (width > PREFERRED_SIZE_FOR_ICON || height > PREFERRED_SIZE_FOR_ICON) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                    haveLargeIcon = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        if (iconLog.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            iconLog.log(Level.FINEST, ">>> Length_ of buffer of icons data: " + totalLength +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                                      ", maximum length: " + MAXIMUM_BUFFER_LENGTH_NET_WM_ICON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        return result;
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
     * Dumps each icon from the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    static void dumpIcons(java.util.List<XIconInfo> icons) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        if (iconLog.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            iconLog.log(Level.FINEST, ">>> Sizes of icon images:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            for (Iterator<XIconInfo> i = icons.iterator(); i.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                iconLog.log(Level.FINEST, "    {0}", i.next());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    public void recursivelySetIcon(java.util.List<XIconInfo> icons) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        dumpIcons(winAttr.icons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        setIconHints(icons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        Window target = (Window)this.target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        Window[] children = target.getOwnedWindows();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        int cnt = children.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        for (int i = 0; i < cnt; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            ComponentPeer childPeer = children[i].getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            if (childPeer != null && childPeer instanceof XWindowPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                if (((XWindowPeer)childPeer).winAttr.iconsInherited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                    ((XWindowPeer)childPeer).winAttr.icons = icons;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                    ((XWindowPeer)childPeer).recursivelySetIcon(icons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    java.util.List<XIconInfo> getIconInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        return winAttr.icons;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    void setIconHints(java.util.List<XIconInfo> icons) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        //This does nothing for XWindowPeer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        //It's overriden in XDecoratedPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    private static ArrayList<XIconInfo> defaultIconInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    protected synchronized static java.util.List<XIconInfo> getDefaultIconInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        if (defaultIconInfo == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            defaultIconInfo = new ArrayList<XIconInfo>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            if (XlibWrapper.dataModel == 32) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                defaultIconInfo.add(new XIconInfo(XAWTIcon32_java_icon16_png.java_icon16_png));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                defaultIconInfo.add(new XIconInfo(XAWTIcon32_java_icon24_png.java_icon24_png));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                defaultIconInfo.add(new XIconInfo(XAWTIcon32_java_icon32_png.java_icon32_png));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                defaultIconInfo.add(new XIconInfo(XAWTIcon32_java_icon48_png.java_icon48_png));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                defaultIconInfo.add(new XIconInfo(XAWTIcon64_java_icon16_png.java_icon16_png));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                defaultIconInfo.add(new XIconInfo(XAWTIcon64_java_icon24_png.java_icon24_png));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                defaultIconInfo.add(new XIconInfo(XAWTIcon64_java_icon32_png.java_icon32_png));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                defaultIconInfo.add(new XIconInfo(XAWTIcon64_java_icon48_png.java_icon48_png));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        return defaultIconInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    public void updateMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        //This function only saves minimumSize value in XWindowPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        //Setting WMSizeHints is implemented in XDecoratedPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        targetMinimumSize = (((Component)target).isMinimumSizeSet()) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            ((Component)target).getMinimumSize() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    public Dimension getTargetMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        return (targetMinimumSize == null) ? null : new Dimension(targetMinimumSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    public XWindowPeer getOwnerPeer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        return ownerPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   435
    // This method is overriden at the XDecoratedPeer to handle
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   436
    // decorated windows a bit differently.
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   437
    Rectangle constrainBounds(int x, int y, int width, int height) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   438
        // We don't restrict the setBounds() operation if the code is trusted.
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   439
        if (!hasWarningWindow()) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   440
            return new Rectangle(x, y, width, height);
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   441
        }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   442
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   443
        // The window bounds should be within the visible part of the screen
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   444
        int newX = x;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   445
        int newY = y;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   446
        int newW = width;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   447
        int newH = height;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   448
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   449
        // Now check each point is within the visible part of the screen
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   450
        GraphicsConfiguration gc = ((Window)target).getGraphicsConfiguration();
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   451
        Rectangle sB = gc.getBounds();
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   452
        Insets sIn = ((Window)target).getToolkit().getScreenInsets(gc);
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   453
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   454
        int screenX = sB.x + sIn.left;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   455
        int screenY = sB.y + sIn.top;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   456
        int screenW = sB.width - sIn.left - sIn.right;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   457
        int screenH = sB.height - sIn.top - sIn.bottom;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   458
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   459
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   460
        // First make sure the size is withing the visible part of the screen
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   461
        if (newW > screenW) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   462
            newW = screenW;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   463
        }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   464
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   465
        if (newH > screenH) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   466
            newH = screenH;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   467
        }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   468
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   469
        // Tweak the location if needed
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   470
        if (newX < screenX) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   471
            newX = screenX;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   472
        } else if (newX + newW > screenX + screenW) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   473
            newX = screenX + screenW - newW;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   474
        }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   475
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   476
        if (newY < screenY) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   477
            newY = screenY;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   478
        } else if (newY + newH > screenY + screenH) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   479
            newY = screenY + screenH - newH;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   480
        }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   481
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   482
        return new Rectangle(newX, newY, newW, newH);
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   483
    }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   484
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    //Fix for 6318144: PIT:Setting Min Size bigger than current size enlarges
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    //the window but fails to revalidate, Sol-CDE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    //This bug is regression for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    //5025858: Resizing a decorated frame triggers componentResized event twice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    //Since events are not posted from Component.setBounds we need to send them here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    //Note that this function is overriden in XDecoratedPeer so event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    //posting is not changing for decorated peers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    public void setBounds(int x, int y, int width, int height, int op) {
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   493
        Rectangle newBounds = constrainBounds(x, y, width, height);
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   494
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            Rectangle oldBounds = getBounds();
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   498
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   499
            super.setBounds(newBounds.x, newBounds.y, newBounds.width, newBounds.height, op);
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
   500
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            Rectangle bounds = getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            XSizeHints hints = getHints();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
   504
            setSizeHints(hints.get_flags() | XUtilConstants.PPosition | XUtilConstants.PSize,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                             bounds.x, bounds.y, bounds.width, bounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            XWM.setMotifDecor(this, false, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            XNETProtocol protocol = XWM.getWM().getNETProtocol();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            if (protocol != null && protocol.active()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                XAtomList net_wm_state = getNETWMState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                net_wm_state.add(protocol.XA_NET_WM_STATE_SKIP_TASKBAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                setNETWMState(net_wm_state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            if (!bounds.getSize().equals(oldBounds.getSize())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                postEventToEventQueue(new ComponentEvent(getEventSource(), ComponentEvent.COMPONENT_RESIZED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            if (!bounds.getLocation().equals(oldBounds.getLocation())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                postEventToEventQueue(new ComponentEvent(getEventSource(), ComponentEvent.COMPONENT_MOVED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    void updateFocusability() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        updateFocusableWindowState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            XWMHints hints = getWMHints();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
   532
            hints.set_flags(hints.get_flags() | (int)XUtilConstants.InputHint);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            hints.set_input(false/*isNativelyNonFocusableWindow() ? (0):(1)*/);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            XlibWrapper.XSetWMHints(XToolkit.getDisplay(), getWindow(), hints.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    public Insets getInsets() {
449
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
   542
        return new Insets(getWarningWindowHeight(), 0, 0, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    public void handleIconify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        postEvent(new WindowEvent((Window)target, WindowEvent.WINDOW_ICONIFIED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    public void handleDeiconify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        postEvent(new WindowEvent((Window)target, WindowEvent.WINDOW_DEICONIFIED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    public void handleStateChange(int oldState, int newState) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        postEvent(new WindowEvent((Window)target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                                  WindowEvent.WINDOW_STATE_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                                  oldState, newState));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * DEPRECATED:  Replaced by getInsets().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    public Insets insets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        return getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    boolean isAutoRequestFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        if (XToolkit.isToolkitThread()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            return WindowAccessor.isAutoRequestFocus((Window)target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            return ((Window)target).isAutoRequestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    /*
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   581
     * Retrives real native focused window and converts it into Java peer.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    static XWindowPeer getNativeFocusedWindowPeer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        XBaseWindow baseWindow = XToolkit.windowToXWindow(xGetInputFocus());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        return (baseWindow instanceof XWindowPeer) ? (XWindowPeer)baseWindow :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
               (baseWindow instanceof XFocusProxyWindow) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
               ((XFocusProxyWindow)baseWindow).getOwner() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   590
    /*
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   591
     * Retrives real native focused window and converts it into Java window.
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   592
     */
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   593
    static Window getNativeFocusedWindow() {
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   594
        XWindowPeer peer = getNativeFocusedWindowPeer();
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   595
        return peer != null ? (Window)peer.target : null;
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   596
    }
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   597
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    boolean isFocusableWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        if (XToolkit.isToolkitThread() || SunToolkit.isAWTLockHeldByCurrentThread())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            return cachedFocusableWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            return ((Window)target).isFocusableWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    /* WARNING: don't call client code in this method! */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    boolean isFocusedWindowModalBlocker() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    long getFocusTargetWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        return getContentWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * Returns whether or not this window peer has native X window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * configured as non-focusable window. It might happen if:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * - Java window is non-focusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * - Java window is simple Window(not Frame or Dialog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    boolean isNativelyNonFocusableWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        if (XToolkit.isToolkitThread() || SunToolkit.isAWTLockHeldByCurrentThread())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            return isSimpleWindow() || !cachedFocusableWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            return isSimpleWindow() || !(((Window)target).isFocusableWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    public void handleWindowFocusIn_Dispatch() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        if (EventQueue.isDispatchThread()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            XKeyboardFocusManagerPeer.setCurrentNativeFocusedWindow((Window) target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            target.dispatchEvent(new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    public void handleWindowFocusInSync(long serial) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        XKeyboardFocusManagerPeer.setCurrentNativeFocusedWindow((Window) target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        sendEvent(we);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    public void handleWindowFocusIn(long serial) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        /* wrap in Sequenced, then post*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        XKeyboardFocusManagerPeer.setCurrentNativeFocusedWindow((Window) target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        postEvent(wrapInSequenced((AWTEvent) we));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    public void handleWindowFocusOut(Window oppositeWindow, long serial) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_LOST_FOCUS, oppositeWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        XKeyboardFocusManagerPeer.setCurrentNativeFocusedWindow(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        XKeyboardFocusManagerPeer.setCurrentNativeFocusOwner(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        /* wrap in Sequenced, then post*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        postEvent(wrapInSequenced((AWTEvent) we));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    public void handleWindowFocusOutSync(Window oppositeWindow, long serial) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_LOST_FOCUS, oppositeWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        XKeyboardFocusManagerPeer.setCurrentNativeFocusedWindow(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        XKeyboardFocusManagerPeer.setCurrentNativeFocusOwner(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        sendEvent(we);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
/* --- DisplayChangedListener Stuff --- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    /* Xinerama
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * called to check if we've been moved onto a different screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * Based on checkNewXineramaScreen() in awt_GraphicsEnv.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    public void checkIfOnNewScreen(Rectangle newBounds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        if (!XToolkit.localEnv.runningXinerama()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        if (log.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            log.finest("XWindowPeer: Check if we've been moved to a new screen since we're running in Xinerama mode");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        int area = newBounds.width * newBounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        int intAmt, vertAmt, horizAmt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        int largestAmt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        int curScreenNum = ((X11GraphicsDevice)getGraphicsConfiguration().getDevice()).getScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        int newScreenNum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        GraphicsDevice gds[] = XToolkit.localEnv.getScreenDevices();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        Rectangle screenBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        for (int i = 0; i < gds.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            screenBounds = gds[i].getDefaultConfiguration().getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            if (newBounds.intersects(screenBounds)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                horizAmt = Math.min(newBounds.x + newBounds.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                                    screenBounds.x + screenBounds.width) -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                           Math.max(newBounds.x, screenBounds.x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                vertAmt = Math.min(newBounds.y + newBounds.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                                   screenBounds.y + screenBounds.height)-
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                          Math.max(newBounds.y, screenBounds.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                intAmt = horizAmt * vertAmt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                if (intAmt == area) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                    // Completely on this screen - done!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                    newScreenNum = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                if (intAmt > largestAmt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                    largestAmt = intAmt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                    newScreenNum = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        if (newScreenNum != curScreenNum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            if (log.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                log.finest("XWindowPeer: Moved to a new screen");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            draggedToNewScreen(newScreenNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    /* Xinerama
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * called to update our GC when dragged onto another screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    public void draggedToNewScreen(int screenNum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        executeDisplayChangedOnEDT(screenNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * Helper method that executes the displayChanged(screen) method on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * the event dispatch thread.  This method is used in the Xinerama case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * and after display mode change events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    private void executeDisplayChangedOnEDT(final int screenNum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        Runnable dc = new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                // Updates this window's GC and notifies all the children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                // See XPanelPeer/XCanvasPeer.displayChanged(int) for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                displayChanged(screenNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        SunToolkit.executeOnEventHandlerThread((Component)target, dc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * From the DisplayChangedListener interface; called from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * X11GraphicsDevice when the display mode has been changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    public void displayChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        GraphicsConfiguration gc = getGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        int curScreenNum = ((X11GraphicsDevice)gc.getDevice()).getScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        executeDisplayChangedOnEDT(curScreenNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * From the DisplayChangedListener interface; top-levels do not need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * to react to this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    public void paletteChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * Overridden to check if we need to update our GraphicsDevice/Config
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * Added for 4934052.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    public void handleConfigureNotifyEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        // TODO: We create an XConfigureEvent every time we override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        // handleConfigureNotify() - too many!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        XConfigureEvent xe = xev.get_xconfigure();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        checkIfOnNewScreen(new Rectangle(xe.get_x(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                                         xe.get_y(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                                         xe.get_width(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                                         xe.get_height()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        // Don't call super until we've handled a screen change.  Otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        // there could be a race condition in which a ComponentListener could
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        // see the old screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        super.handleConfigureNotifyEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        // for 5085647: no applet warning window visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        updateChildrenSizes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    final void requestXFocus(long time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        requestXFocus(time, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    final void requestXFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        requestXFocus(0, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * Requests focus to this top-level. Descendants should override to provide
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * implementations based on a class of top-level.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    protected void requestXFocus(long time, boolean timeProvided) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        // Since in XAWT focus is synthetic and all basic Windows are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        // override_redirect all we can do is check whether our parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        // is active. If it is - we can freely synthesize focus transfer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        // Luckily, this logic is already implemented in requestWindowFocus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        if (focusLog.isLoggable(Level.FINE)) focusLog.fine("Requesting window focus");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        requestWindowFocus(time, timeProvided);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    public final boolean focusAllowedFor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        if (isNativelyNonFocusableWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        Window target = (Window)this.target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        if (!target.isVisible() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            !target.isEnabled() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            !target.isFocusable())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        if (isModalBlocked()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    public void handleFocusEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        XFocusChangeEvent xfe = xev.get_xfocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        FocusEvent fe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        focusLog.log(Level.FINE, "{0}", new Object[] {xfe});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        if (isEventDisabled(xev)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        }
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
   828
        if (xev.get_type() == XConstants.FocusIn)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            // If this window is non-focusable don't post any java focus event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            if (focusAllowedFor()) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
   832
                if (xfe.get_mode() == XConstants.NotifyNormal // Normal notify
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
   833
                    || xfe.get_mode() == XConstants.NotifyWhileGrabbed) // Alt-Tab notify
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                    handleWindowFocusIn(xfe.get_serial());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
   841
            if (xfe.get_mode() == XConstants.NotifyNormal // Normal notify
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
   842
                || xfe.get_mode() == XConstants.NotifyWhileGrabbed) // Alt-Tab notify
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                // If this window is non-focusable don't post any java focus event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                if (!isNativelyNonFocusableWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                    XWindowPeer oppositeXWindow = getNativeFocusedWindowPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                    Object oppositeTarget = (oppositeXWindow!=null)? oppositeXWindow.getTarget() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                    Window oppositeWindow = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                    if (oppositeTarget instanceof Window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                        oppositeWindow = (Window) oppositeTarget;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                    // Check if opposite window is non-focusable. In that case we don't want to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                    // post any event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                    if (oppositeXWindow != null && oppositeXWindow.isNativelyNonFocusableWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                    if (this == oppositeXWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                        oppositeWindow = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                    } else if (oppositeXWindow instanceof XDecoratedPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                        if (((XDecoratedPeer) oppositeXWindow).actualFocusedWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                            oppositeXWindow = ((XDecoratedPeer) oppositeXWindow).actualFocusedWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                            oppositeTarget = oppositeXWindow.getTarget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                            if (oppositeTarget instanceof Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                                && oppositeXWindow.isVisible()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                                && oppositeXWindow.isNativelyNonFocusableWindow())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                                oppositeWindow = ((Window) oppositeTarget);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                    handleWindowFocusOut(oppositeWindow, xfe.get_serial());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    void setSaveUnder(boolean state) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    public void toFront() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        if (isOverrideRedirect() && mustControlStackPosition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
            mustControlStackPosition = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            removeRootPropertyEventDispatcher();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        if (isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            super.toFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            if (isFocusableWindow() && isAutoRequestFocus() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                !isModalBlocked() && !isWithdrawn())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                requestInitialFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    public void toBack() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            if(!isOverrideRedirect()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                XlibWrapper.XLowerWindow(XToolkit.getDisplay(), getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            }else{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                lowerOverrideRedirect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    private void lowerOverrideRedirect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        // make new hash of toplevels of all windows from 'windows' hash.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        // FIXME: do not call them "toplevel" as it is misleading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        HashSet toplevels = new HashSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        long topl = 0, mytopl = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        for (XWindowPeer xp : windows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            topl = getToplevelWindow( xp.getWindow() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            if( xp.equals( this ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                mytopl = topl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            if( topl > 0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                toplevels.add( Long.valueOf( topl ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        // find in the root's tree:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        // (1) my toplevel, (2) lowest java toplevel, (3) desktop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        // We must enforce (3), (1), (2) order, upward;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        // note that nautilus on the next restacking will do (1),(3),(2).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        long laux,     wDesktop = -1, wBottom = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        int  iMy = -1, iDesktop = -1, iBottom = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        XQueryTree xqt = new XQueryTree(XToolkit.getDefaultRootWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            if( xqt.execute() > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                int nchildren = xqt.get_nchildren();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                long children = xqt.get_children();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                for(i = 0; i < nchildren; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                    laux = Native.getWindow(children, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                    if( laux == mytopl ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                        iMy = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                    }else if( isDesktopWindow( laux ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                        // we need topmost desktop of them all.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                        iDesktop = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                        wDesktop = laux;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                    }else if(iBottom < 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                             toplevels.contains( Long.valueOf(laux) ) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                             laux != mytopl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                        iBottom = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                        wBottom = laux;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            if( (iMy < iBottom || iBottom < 0 )&& iDesktop < iMy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                return; // no action necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            long to_restack = Native.allocateLongArray(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            Native.putLong(to_restack, 0, wBottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            Native.putLong(to_restack, 1,  mytopl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            XlibWrapper.XRestackWindows(XToolkit.getDisplay(), to_restack, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            XlibWrapper.unsafe.freeMemory(to_restack);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
            if( !mustControlStackPosition ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                mustControlStackPosition = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                // add root window property listener:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                // somebody (eg nautilus desktop) may obscure us
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                addRootPropertyEventDispatcher();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
            xqt.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        Get XID of closest to root window in a given window hierarchy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        FIXME: do not call it "toplevel" as it is misleading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        On error return 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
    private long getToplevelWindow( long w ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        long wi = w, ret, root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            ret = wi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
            XQueryTree qt = new XQueryTree(wi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                if (qt.execute() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                root = qt.get_root();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                wi = qt.get_parent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                qt.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        } while (wi != root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
    }
449
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
  1001
7820f232278d 6690036: some code cleanup for insets-related code
son
parents: 442
diff changeset
  1002
    private static boolean isDesktopWindow( long wi ) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        return XWM.getWM().isDesktopWindow( wi );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    private void updateAlwaysOnTop() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        log.log(Level.FINE, "Promoting always-on-top state {0}", Boolean.valueOf(alwaysOnTop));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        XWM.getWM().setLayer(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                             alwaysOnTop ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                             XLayerProtocol.LAYER_ALWAYS_ON_TOP :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                             XLayerProtocol.LAYER_NORMAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    public void setAlwaysOnTop(boolean alwaysOnTop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        this.alwaysOnTop = alwaysOnTop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        updateAlwaysOnTop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    boolean isLocationByPlatform() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        return locationByPlatform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    private void promoteDefaultPosition() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        this.locationByPlatform = ((Window)target).isLocationByPlatform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        if (locationByPlatform) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                Rectangle bounds = getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                XSizeHints hints = getHints();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
  1030
                setSizeHints(hints.get_flags() & ~(XUtilConstants.USPosition | XUtilConstants.PPosition),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                             bounds.x, bounds.y, bounds.width, bounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
    public void setVisible(boolean vis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        if (!isVisible() && vis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            isBeforeFirstMapNotify = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            winAttr.initialFocus = isAutoRequestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
            if (!winAttr.initialFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                 * It's easier and safer to temporary suppress WM_TAKE_FOCUS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                 * protocol itself than to ignore WM_TAKE_FOCUS client message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                 * Because we will have to make the difference between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                 * the message come after showing and the message come after
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                 * activation. Also, on Metacity, for some reason, we have _two_
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                 * WM_TAKE_FOCUS client messages when showing a frame/dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                suppressWmTakeFocus(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        updateFocusability();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        promoteDefaultPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        super.setVisible(vis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        if (!vis && !isWithdrawn()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            // ICCCM, 4.1.4. Changing Window State:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            // "Iconic -> Withdrawn - The client should unmap the window and follow it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            // with a synthetic UnmapNotify event as described later in this section."
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            // The same is true for Normal -> Withdrawn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                XUnmapEvent unmap = new XUnmapEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                unmap.set_window(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                unmap.set_event(XToolkit.getDefaultRootWindow());
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
  1067
                unmap.set_type((int)XConstants.UnmapNotify);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                unmap.set_from_configure(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                XlibWrapper.XSendEvent(XToolkit.getDisplay(), XToolkit.getDefaultRootWindow(),
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
  1070
                        false, XConstants.SubstructureNotifyMask | XConstants.SubstructureRedirectMask,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                        unmap.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                unmap.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
            finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        // method called somewhere in parent does not generate configure-notify
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        // event for override-redirect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        // Ergo, no reshape and bugs like 5085647 in case setBounds was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        // called before setVisible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        if (isOverrideRedirect() && vis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            updateChildrenSizes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
    protected void suppressWmTakeFocus(boolean doSuppress) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
    final boolean isSimpleWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        return !(target instanceof Frame || target instanceof Dialog);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
    boolean hasWarningWindow() {
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 116
diff changeset
  1094
        return ((Window)target).getWarningString() != null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
    // The height of menu bar window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
    int getMenuBarHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
    // The height of area used to display Applet's warning about securit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
    int getWarningWindowHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        if (warningWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
            return warningWindow.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    // Called when shell changes its size and requires children windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
    // to update their sizes appropriately
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
    void updateChildrenSizes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        if (warningWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
            warningWindow.reshape(0, getMenuBarHeight(), getSize().width, warningWindow.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    boolean isOverrideRedirect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        return (XWM.getWMID() == XWM.OPENLOOK_WM ? true : false) ||
1190
f27065d0d9f0 6708392: Provide internal API to create OverrideRedirect windows, XToolkit
art
parents: 449
diff changeset
  1121
            ((XToolkit)Toolkit.getDefaultToolkit()).isOverrideRedirect((Window)target) ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
            XTrayIconPeer.isTrayIconStuffWindow((Window)target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
    final boolean isOLWMDecorBug() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        return XWM.getWMID() == XWM.OPENLOOK_WM &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            winAttr.nativeDecor == false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
    public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
        SunToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
            windows.remove(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
            SunToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        if (warningWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
            warningWindow.destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        removeRootPropertyEventDispatcher();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        mustControlStackPosition = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        super.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
         * Fix for 6457980.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
         * When disposing an owned Window we should implicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
         * return focus to its decorated owner because it won't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
         * receive WM_TAKE_FOCUS.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        if (isSimpleWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
            if (target == XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                Window owner = getDecoratedOwner((Window)target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                ((XWindowPeer)ComponentAccessor.getPeer(owner)).requestWindowFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
    boolean isResizable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        return winAttr.isResizable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
    public void handleVisibilityEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        super.handleVisibilityEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        XVisibilityEvent ve = xev.get_xvisibility();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        winAttr.visibilityState = ve.get_state();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
//         if (ve.get_state() == XlibWrapper.VisibilityUnobscured) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
//             // raiseInputMethodWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
//         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
    public void handlePropertyNotify(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        super.handlePropertyNotify(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        XPropertyEvent ev = xev.get_xproperty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        if (ev.get_atom() == XWM.XA_WM_STATE.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            // State has changed, invalidate saved value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            stateChanged = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
            stateChanged(ev.get_time(), savedState, getWMState());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
    void handleRootPropertyNotify(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        XPropertyEvent ev = xev.get_xproperty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        if( mustControlStackPosition &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
            ev.get_atom() == XAtom.get("_NET_CLIENT_LIST_STACKING").getAtom()){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
            // Restore stack order unhadled/spoiled by WM or some app (nautilus).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
            // As of now, don't use any generic machinery: just
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
            // do toBack() again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
            if(isOverrideRedirect()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                toBack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
    public void handleMapNotifyEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        // See 6480534.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        isUnhiding |= isWMStateNetHidden();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        super.handleMapNotifyEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        if (!winAttr.initialFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
            suppressWmTakeFocus(false); // restore the protocol.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
             * For some reason, on Metacity, a frame/dialog being shown
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
             * without WM_TAKE_FOCUS protocol doesn't get moved to the front.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
             * So, we do it evidently.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                XlibWrapper.XRaiseWindow(XToolkit.getDisplay(), getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        if (shouldFocusOnMapNotify()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
            focusLog.fine("Automatically request focus on window");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            requestInitialFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        isUnhiding = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        isBeforeFirstMapNotify = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        updateAlwaysOnTop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        synchronized (getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
            if (!isMapped) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
                isMapped = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    public void handleUnmapNotifyEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        super.handleUnmapNotifyEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        // On Metacity UnmapNotify comes before PropertyNotify (for _NET_WM_STATE_HIDDEN).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        // So we also check for the property later in MapNotify. See 6480534.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
        isUnhiding |= isWMStateNetHidden();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        synchronized (getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
            if (isMapped) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
                isMapped = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
    private boolean shouldFocusOnMapNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        boolean res = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
        if (isBeforeFirstMapNotify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
            res = (winAttr.initialFocus ||          // Window.autoRequestFocus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
                   isFocusedWindowModalBlocker());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
            res = isUnhiding;                       // Unhiding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
        res = res &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
            isFocusableWindow() &&                  // General focusability
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
            !isModalBlocked();                      // Modality
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1257
    protected boolean isWMStateNetHidden() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
        XNETProtocol protocol = XWM.getWM().getNETProtocol();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        return (protocol != null && protocol.isWMStateNetHidden(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
    protected void requestInitialFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
        requestXFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    public void addToplevelStateListener(ToplevelStateListener l){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
        toplevelStateListeners.add(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    public void removeToplevelStateListener(ToplevelStateListener l){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        toplevelStateListeners.remove(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
     * Override this methods to get notifications when top-level window state changes. The state is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     * meant in terms of ICCCM: WithdrawnState, IconicState, NormalState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
    protected void stateChanged(long time, int oldState, int newState) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
        // Fix for 6401700, 6412803
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
        // If this window is modal blocked, it is put into the transient_for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        // chain using prevTransientFor and nextTransientFor hints. However,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        // the real WM_TRANSIENT_FOR hint shouldn't be set for windows in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        // different WM states (except for owner-window relationship), so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
        // if the window changes its state, its real WM_TRANSIENT_FOR hint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        // should be updated accordingly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
        updateTransientFor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
        for (ToplevelStateListener topLevelListenerTmp : toplevelStateListeners) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
            topLevelListenerTmp.stateChangedICCCM(oldState, newState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
     * XmNiconic and Map/UnmapNotify (that XmNiconic relies on) are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
     * unreliable, since mapping changes can happen for a virtual desktop
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
     * switch or MacOS style shading that became quite popular under X as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
     * well.  Yes, it probably should not be this way, as it violates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     * ICCCM, but reality is that quite a lot of window managers abuse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * mapping state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
    int getWMState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
        if (stateChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
            stateChanged = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
            WindowPropertyGetter getter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
                new WindowPropertyGetter(window, XWM.XA_WM_STATE, 0, 1, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
                                         XWM.XA_WM_STATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
                int status = getter.execute();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
  1310
                if (status != XConstants.Success || getter.getData() == 0) {
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
  1311
                    return savedState = XUtilConstants.WithdrawnState;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                if (getter.getActualType() != XWM.XA_WM_STATE.getAtom() && getter.getActualFormat() != 32) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
  1315
                    return savedState = XUtilConstants.WithdrawnState;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
                savedState = (int)Native.getCard32(getter.getData());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
                getter.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
        return savedState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
    boolean isWithdrawn() {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
  1326
        return getWMState() == XUtilConstants.WithdrawnState;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
    boolean hasDecorations(int decor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        if (!winAttr.nativeDecor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
            int myDecor = winAttr.decorations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
            boolean hasBits = ((myDecor & decor) == decor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
            if ((myDecor & XWindowAttributesData.AWT_DECOR_ALL) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                return !hasBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
                return hasBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
    void setReparented(boolean newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
        super.setReparented(newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
            if (isReparented() && delayedModalBlocking) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
                addToTransientFors((XDialogPeer) ComponentAccessor.getPeer(modalBlocker));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
                delayedModalBlocking = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
     * Returns a Vector of all Java top-level windows,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
     * sorted by their current Z-order
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
    static Vector<XWindowPeer> collectJavaToplevels() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
        Vector<XWindowPeer> javaToplevels = new Vector<XWindowPeer>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
        Vector<Long> v = new Vector<Long>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        X11GraphicsEnvironment ge =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
            (X11GraphicsEnvironment)GraphicsEnvironment.getLocalGraphicsEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
        GraphicsDevice[] gds = ge.getScreenDevices();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
        if (!ge.runningXinerama() && (gds.length > 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
            for (GraphicsDevice gd : gds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
                int screen = ((X11GraphicsDevice)gd).getScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
                long rootWindow = XlibWrapper.RootWindow(XToolkit.getDisplay(), screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
                v.add(rootWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
            v.add(XToolkit.getDefaultRootWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
        final int windowsCount = windows.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        while ((v.size() > 0) && (javaToplevels.size() < windowsCount)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
            long win = v.remove(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
            XQueryTree qt = new XQueryTree(win);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
                if (qt.execute() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
                    int nchildren = qt.get_nchildren();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
                    long children = qt.get_children();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                    // XQueryTree returns window children ordered by z-order
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                    for (int i = 0; i < nchildren; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
                        long child = Native.getWindow(children, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
                        XBaseWindow childWindow = XToolkit.windowToXWindow(child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
                        // filter out Java non-toplevels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
                        if ((childWindow != null) && !(childWindow instanceof XWindowPeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
                            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
                            v.add(child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
                        if (childWindow instanceof XWindowPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
                            XWindowPeer np = (XWindowPeer)childWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
                            javaToplevels.add(np);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
                            // XQueryTree returns windows sorted by their z-order. However,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
                            // if WM has not handled transient for hint for a child window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
                            // it may appear in javaToplevels before its owner. Move such
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
                            // children after their owners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                            int k = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
                            XWindowPeer toCheck = javaToplevels.get(k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
                            while (toCheck != np) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
                                XWindowPeer toCheckOwnerPeer = toCheck.getOwnerPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
                                if (toCheckOwnerPeer == np) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
                                    javaToplevels.remove(k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
                                    javaToplevels.add(toCheck);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
                                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
                                    k++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
                                toCheck = javaToplevels.get(k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
                qt.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
        return javaToplevels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
    public void setModalBlocked(Dialog d, boolean blocked) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
        setModalBlocked(d, blocked, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
    public void setModalBlocked(Dialog d, boolean blocked,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
                                Vector<XWindowPeer> javaToplevels)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
            // State lock should always be after awtLock
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
            synchronized(getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
                XDialogPeer blockerPeer = (XDialogPeer) ComponentAccessor.getPeer(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
                if (blocked) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
                    log.log(Level.FINE, "{0} is blocked by {1}", new Object[] { this, blockerPeer});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
                    modalBlocker = d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
                    if (isReparented() || XWM.isNonReparentingWM()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
                        addToTransientFors(blockerPeer, javaToplevels);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
                        delayedModalBlocking = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
                    if (d != modalBlocker) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
                        throw new IllegalStateException("Trying to unblock window blocked by another dialog");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
                    modalBlocker = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
                    if (isReparented() || XWM.isNonReparentingWM()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
                        removeFromTransientFors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
                        delayedModalBlocking = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
                updateTransientFor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
     * Sets the TRANSIENT_FOR hint to the given top-level window. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
     *  method is used when a window is modal blocked/unblocked or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
     *  changed its state from/to NormalState to/from other states.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
     * If window or transientForWindow are embedded frames, the containing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
     *  top-level windows are used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
     * @param window specifies the top-level window that the hint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
     *  is to be set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
     * @param transientForWindow the top-level window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
     * @param updateChain specifies if next/prevTransientFor fields are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
     *  to be updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
     * @param allStates if set to <code>true</code> then TRANSIENT_FOR hint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
     *  is set regardless of the state of window and transientForWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
     *  otherwise it is set only if both are in the same state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
    static void setToplevelTransientFor(XWindowPeer window, XWindowPeer transientForWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
                                                boolean updateChain, boolean allStates)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
        if ((window == null) || (transientForWindow == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
        if (updateChain) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
            window.prevTransientFor = transientForWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
            transientForWindow.nextTransientFor = window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
        if (window.curRealTransientFor == transientForWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
        if (!allStates && (window.getWMState() != transientForWindow.getWMState())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
        if (window.getScreenNumber() != transientForWindow.getScreenNumber()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
        long bpw = window.getWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
        while (!XlibUtil.isToplevelWindow(bpw) && !XlibUtil.isXAWTToplevelWindow(bpw)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
            bpw = XlibUtil.getParentWindow(bpw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
        long tpw = transientForWindow.getWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
        while (!XlibUtil.isToplevelWindow(tpw) && !XlibUtil.isXAWTToplevelWindow(tpw)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
            tpw = XlibUtil.getParentWindow(tpw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
        XlibWrapper.XSetTransientFor(XToolkit.getDisplay(), bpw, tpw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
        window.curRealTransientFor = transientForWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
     * This method does nothing if this window is not blocked by any modal dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
     * For modal blocked windows this method looks up for the nearest
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
     *  prevTransiendFor window that is in the same state (Normal/Iconified/Withdrawn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
     *  as this one and makes this window transient for it. The same operation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
     *  performed for nextTransientFor window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
     * Values of prevTransientFor and nextTransientFor fields are not changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
    void updateTransientFor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
        int state = getWMState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
        XWindowPeer p = prevTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
        while ((p != null) && ((p.getWMState() != state) || (p.getScreenNumber() != getScreenNumber()))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
            p = p.prevTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
        if (p != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
            setToplevelTransientFor(this, p, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
            restoreTransientFor(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
        XWindowPeer n = nextTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
        while ((n != null) && ((n.getWMState() != state) || (n.getScreenNumber() != getScreenNumber()))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
            n = n.nextTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
        if (n != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
            setToplevelTransientFor(n, this, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
     * Removes the TRANSIENT_FOR hint from the given top-level window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
     * If window or transientForWindow are embedded frames, the containing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
     *  top-level windows are used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
     * @param window specifies the top-level window that the hint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
     *  is to be removed from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
    private static void removeTransientForHint(XWindowPeer window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
        XAtom XA_WM_TRANSIENT_FOR = XAtom.get(XAtom.XA_WM_TRANSIENT_FOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
        long bpw = window.getWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
        while (!XlibUtil.isToplevelWindow(bpw) && !XlibUtil.isXAWTToplevelWindow(bpw)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
            bpw = XlibUtil.getParentWindow(bpw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
        XlibWrapper.XDeleteProperty(XToolkit.getDisplay(), bpw, XA_WM_TRANSIENT_FOR.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
        window.curRealTransientFor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
     * When a modal dialog is shown, all its blocked windows are lined up into
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
     *  a chain in such a way that each window is a transient_for window for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
     *  the next one. That allows us to keep the modal dialog above all its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
     *  blocked windows (even if there are some another modal dialogs between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
     *  them).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
     * This method adds this top-level window to the chain of the given modal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
     *  dialog. To keep the current relative z-order, we should use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
     *  XQueryTree to find the place to insert this window to. As each window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
     *  can be blocked by only one modal dialog (such checks are performed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
     *  shared code), both this and blockerPeer are on the top of their chains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
     *  (chains may be empty).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
     * If this window is a modal dialog and has its own chain, these chains are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
     *  merged according to the current z-order (XQueryTree is used again).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
     *  Below are some simple examples (z-order is from left to right, -- is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
     *  modal blocking).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
     * Example 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
     *     T (current chain of this, no windows are blocked by this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
     *  W1---B (current chain of blockerPeer, W2 is blocked by blockerPeer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
     *  Result is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
     *  W1-T-B (merged chain, all the windows are blocked by blockerPeer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
     * Example 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
     *  W1-T (current chain of this, W1 is blocked by this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
     *       W2-B (current chain of blockerPeer, W2 is blocked by blockerPeer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
     *  Result is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
     *  W1-T-W2-B (merged chain, all the windows are blocked by blockerPeer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
     * Example 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
     *  W1----T (current chain of this, W1 is blocked by this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
     *     W2---B (current chain of blockerPeer, W2 is blocked by blockerPeer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
     *  Result is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
     *  W1-W2-T-B (merged chain, all the windows are blocked by blockerPeer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
     * This method should be called under the AWT lock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
     * @see #removeFromTransientFors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
     * @see #setModalBlocked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
    private void addToTransientFors(XDialogPeer blockerPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
        addToTransientFors(blockerPeer, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
    private void addToTransientFors(XDialogPeer blockerPeer, Vector<XWindowPeer> javaToplevels)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
        // blockerPeer chain iterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
        XWindowPeer blockerChain = blockerPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
        while (blockerChain.prevTransientFor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
            blockerChain = blockerChain.prevTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
        // this window chain iterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
        // each window can be blocked no more than once, so this window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
        //   is on top of its chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
        XWindowPeer thisChain = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
        while (thisChain.prevTransientFor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
            thisChain = thisChain.prevTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
        // if there are no windows blocked by modalBlocker, simply add this window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
        //  and its chain to blocker's chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
        if (blockerChain == blockerPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
            setToplevelTransientFor(blockerPeer, this, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
            // Collect all the Java top-levels, if required
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
            if (javaToplevels == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
                javaToplevels = collectJavaToplevels();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
            // merged chain tail
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
            XWindowPeer mergedChain = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
            for (XWindowPeer w : javaToplevels) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
                XWindowPeer prevMergedChain = mergedChain;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
                if (w == thisChain) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
                    if (thisChain == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
                        if (prevMergedChain != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
                            setToplevelTransientFor(this, prevMergedChain, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
                        setToplevelTransientFor(blockerChain, this, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
                        mergedChain = thisChain;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
                        thisChain = thisChain.nextTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
                } else if (w == blockerChain) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
                    mergedChain = blockerChain;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
                    blockerChain = blockerChain.nextTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
                if (prevMergedChain == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
                    mergedChain.prevTransientFor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
                    setToplevelTransientFor(mergedChain, prevMergedChain, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
                    mergedChain.updateTransientFor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
                if (blockerChain == blockerPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
                    setToplevelTransientFor(thisChain, mergedChain, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
                    setToplevelTransientFor(blockerChain, this, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
        XToolkit.XSync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
    static void restoreTransientFor(XWindowPeer window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
        XWindowPeer ownerPeer = window.getOwnerPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
        if (ownerPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
            setToplevelTransientFor(window, ownerPeer, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
            removeTransientForHint(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
     * When a window is modally unblocked, it should be removed from its blocker
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
     *  chain, see {@link #addToTransientFor addToTransientFors} method for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
     *  chain definition.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
     * The problem is that we cannot simply restore window's original
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
     *  TRANSIENT_FOR hint (if any) and link prevTransientFor and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
     *  nextTransientFor together as the whole chain could be created as a merge
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
     *  of two other chains in addToTransientFors. In that case, if this window is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
     *  a modal dialog, it would lost all its own chain, if we simply exclude it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
     *  from the chain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
     * The correct behaviour of this method should be to split the chain, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
     *  window is currently in, into two chains. First chain is this window own
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
     *  chain (i. e. all the windows blocked by this one, directly or indirectly),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
     *  if any, and the rest windows from the current chain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
     * Example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
     *  Original state:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
     *   W1-B1 (window W1 is blocked by B1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
     *   W2-B2 (window W2 is blocked by B2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
     *  B3 is shown and blocks B1 and B2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
     *   W1-W2-B1-B2-B3 (a single chain after B1.addToTransientFors() and B2.addToTransientFors())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
     *  If we then unblock B1, the state should be:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
     *   W1-B1 (window W1 is blocked by B1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
     *   W2-B2-B3 (window W2 is blocked by B2 and B2 is blocked by B3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
     * This method should be called under the AWT lock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
     * @see #addToTransientFors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
     * @see #setModalBlocked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
    private void removeFromTransientFors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
        // the head of the chain of this window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
        XWindowPeer thisChain = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
        // the head of the current chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
        // nextTransientFor is always not null as this window is in the chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
        XWindowPeer otherChain = nextTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
        // the set of blockers in this chain: if this dialog blocks some other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
        // modal dialogs, their blocked windows should stay in this dialog's chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
        Set<XWindowPeer> thisChainBlockers = new HashSet<XWindowPeer>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
        thisChainBlockers.add(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
        // current chain iterator in the order from next to prev
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
        XWindowPeer chainToSplit = prevTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
        while (chainToSplit != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
            XWindowPeer blocker = (XWindowPeer) ComponentAccessor.getPeer(chainToSplit.modalBlocker);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
            if (thisChainBlockers.contains(blocker)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
                // add to this dialog's chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
                setToplevelTransientFor(thisChain, chainToSplit, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
                thisChain = chainToSplit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
                thisChainBlockers.add(chainToSplit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
                // leave in the current chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
                setToplevelTransientFor(otherChain, chainToSplit, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
                otherChain = chainToSplit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
            chainToSplit = chainToSplit.prevTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
        restoreTransientFor(thisChain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
        thisChain.prevTransientFor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
        restoreTransientFor(otherChain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
        otherChain.prevTransientFor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
        nextTransientFor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
        XToolkit.XSync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
    boolean isModalBlocked() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
        return modalBlocker != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
    static Window getDecoratedOwner(Window window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
        while ((null != window) && !(window instanceof Frame || window instanceof Dialog)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
            window = (Window) ComponentAccessor.getParent_NoClientCode(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
        return window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1745
    public boolean requestWindowFocus(XWindowPeer actualFocusedWindow) {
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1746
        setActualFocusedWindow(actualFocusedWindow);
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1747
        return requestWindowFocus();
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1748
    }
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1749
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
    public boolean requestWindowFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
        return requestWindowFocus(0, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
    public boolean requestWindowFocus(long time, boolean timeProvided) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
        focusLog.fine("Request for window focus");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
        // If this is Frame or Dialog we can't assure focus request success - but we still can try
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
        // If this is Window and its owner Frame is active we can be sure request succedded.
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1758
        Window ownerWindow  = XWindowPeer.getDecoratedOwner((Window)target);
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1759
        Window focusedWindow = XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow();
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1760
        Window activeWindow = XWindowPeer.getDecoratedOwner(focusedWindow);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1762
        if (isWMStateNetHidden()) {
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1763
            focusLog.fine("The window is unmapped, so rejecting the request");
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1764
            return false;
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1765
        }
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1766
        if (activeWindow == ownerWindow) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
            focusLog.fine("Parent window is active - generating focus for this window");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
            handleWindowFocusInSync(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
        }
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1771
        focusLog.fine("Parent window is not active");
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1772
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1773
        XDecoratedPeer wpeer = (XDecoratedPeer)ComponentAccessor.getPeer(ownerWindow);
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1774
        if (wpeer != null && wpeer.requestWindowFocus(this, time, timeProvided)) {
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1775
            focusLog.fine("Parent window accepted focus request - generating focus for this window");
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1776
            return true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
        focusLog.fine("Denied - parent window is not active and didn't accept focus request");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
    // This method is to be overriden in XDecoratedPeer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
    void setActualFocusedWindow(XWindowPeer actualFocusedWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
    public void xSetVisible(boolean visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
        if (log.isLoggable(Level.FINE)) log.fine("Setting visible on " + this + " to " + visible);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
            this.visible = visible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
            if (visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
                XlibWrapper.XMapRaised(XToolkit.getDisplay(), getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
                XlibWrapper.XUnmapWindow(XToolkit.getDisplay(), getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
            XlibWrapper.XFlush(XToolkit.getDisplay());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
        finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
    private int dropTargetCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
    public synchronized void addDropTarget() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
        if (dropTargetCount == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
            long window = getWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
            if (window != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
                XDropTargetRegistry.getRegistry().registerDropSite(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
        dropTargetCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
    public synchronized void removeDropTarget() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
        dropTargetCount--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
        if (dropTargetCount == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
            long window = getWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
            if (window != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
                XDropTargetRegistry.getRegistry().unregisterDropSite(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
    void addRootPropertyEventDispatcher() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
        if( rootPropertyEventDispatcher == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
            rootPropertyEventDispatcher = new XEventDispatcher() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
                public void dispatchEvent(XEvent ev) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
  1828
                    if( ev.get_type() == XConstants.PropertyNotify ) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
                        handleRootPropertyNotify( ev );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
            XlibWrapper.XSelectInput( XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
                                      XToolkit.getDefaultRootWindow(),
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
  1835
                                      XConstants.PropertyChangeMask);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
            XToolkit.addEventDispatcher(XToolkit.getDefaultRootWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
                                                rootPropertyEventDispatcher);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
    void removeRootPropertyEventDispatcher() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
        if( rootPropertyEventDispatcher != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
            XToolkit.removeEventDispatcher(XToolkit.getDefaultRootWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
                                                rootPropertyEventDispatcher);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
            rootPropertyEventDispatcher = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
    public void updateFocusableWindowState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
        cachedFocusableWindow = isFocusableWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
    XAtom XA_NET_WM_STATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
    XAtomList net_wm_state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
    public XAtomList getNETWMState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
        if (net_wm_state == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
            net_wm_state = XA_NET_WM_STATE.getAtomListPropertyList(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
        return net_wm_state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
    public void setNETWMState(XAtomList state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
        net_wm_state = state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
        if (state != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
            XA_NET_WM_STATE.setAtomListProperty(this, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
    public PropMwmHints getMWMHints() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
        if (mwm_hints == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
            mwm_hints = new PropMwmHints();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
  1870
            if (!XWM.XA_MWM_HINTS.getAtomData(getWindow(), mwm_hints.pData, MWMConstants.PROP_MWM_HINTS_ELEMENTS)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
                mwm_hints.zero();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
        return mwm_hints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
    public void setMWMHints(PropMwmHints hints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
        mwm_hints = hints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
        if (hints != null) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 430
diff changeset
  1880
            XWM.XA_MWM_HINTS.setAtomData(getWindow(), mwm_hints.pData, MWMConstants.PROP_MWM_HINTS_ELEMENTS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
    protected synchronized void updateDropTarget() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
        if (dropTargetCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
            long window = getWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
            if (window != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
                XDropTargetRegistry.getRegistry().unregisterDropSite(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
                XDropTargetRegistry.getRegistry().registerDropSite(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
    public void setGrab(boolean grab) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
        this.grab = grab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
        if (grab) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
            pressTarget = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
            grabInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
            ungrabInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
    public boolean isGrabbed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
        return grab && XAwtState.getGrabWindow() == this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
    public void handleXCrossingEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
        XCrossingEvent xce = xev.get_xcrossing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
        if (grabLog.isLoggable(Level.FINE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
            grabLog.log(Level.FINE, "{0}, when grabbed {1}, contains {2}",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
                        new Object[] {xce, isGrabbed(), containsGlobal(xce.get_x_root(), xce.get_y_root())});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
        if (isGrabbed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
            // When window is grabbed, all events are dispatched to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
            // it.  Retarget them to the corresponding windows (notice
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
            // that XBaseWindow.dispatchEvent does the opposite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
            // translation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
            // Note that we need to retarget XCrossingEvents to content window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
            // since it generates MOUSE_ENTERED/MOUSE_EXITED for frame and dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
            // (fix for 6390326)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
            XBaseWindow target = XToolkit.windowToXWindow(xce.get_window());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
            grabLog.log(Level.FINER, "  -  Grab event target {0}", new Object[] {target});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
            if (target != null && target != this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
                target.dispatchEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
        super.handleXCrossingEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
    public void handleMotionNotify(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
        XMotionEvent xme = xev.get_xmotion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
        if (grabLog.isLoggable(Level.FINE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
            grabLog.log(Level.FINER, "{0}, when grabbed {1}, contains {2}",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
                        new Object[] {xme, isGrabbed(), containsGlobal(xme.get_x_root(), xme.get_y_root())});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
        if (isGrabbed()) {
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1190
diff changeset
  1939
            boolean dragging = false;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1190
diff changeset
  1940
            for (int i = 0; i<XToolkit.getNumMouseButtons(); i++){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1190
diff changeset
  1941
                // here is the bug in WM: extra buttons doesn't have state!=0 as they should.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1190
diff changeset
  1942
                if ((i != 4) && (i != 5)){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1190
diff changeset
  1943
                    dragging = dragging || ((xme.get_state() & XConstants.buttonsMask[i]) != 0);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1190
diff changeset
  1944
                }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1190
diff changeset
  1945
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
            // When window is grabbed, all events are dispatched to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
            // it.  Retarget them to the corresponding windows (notice
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
            // that XBaseWindow.dispatchEvent does the opposite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
            // translation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
            XBaseWindow target = XToolkit.windowToXWindow(xme.get_window());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
            if (dragging && pressTarget != target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
                // for some reasons if we grab input MotionNotify for drag is reported with target
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
                // to underlying window, not to window on which we have initiated drag
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
                // so we need to retarget them.  Here I use simplified logic which retarget all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
                // such events to source of mouse press (or the grabber).  It helps with fix for 6390326.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
                // So, I do not want to implement complicated logic for better retargeting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
                target = pressTarget.isVisible() ? pressTarget : this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
                xme.set_window(target.getWindow());
430
ff8a4a3ad82f 6508505: JComboBox collapses immediately if it is placed to embedded frame
dcherepanov
parents: 129
diff changeset
  1959
                Point localCoord = target.toLocal(xme.get_x_root(), xme.get_y_root());
ff8a4a3ad82f 6508505: JComboBox collapses immediately if it is placed to embedded frame
dcherepanov
parents: 129
diff changeset
  1960
                xme.set_x(localCoord.x);
ff8a4a3ad82f 6508505: JComboBox collapses immediately if it is placed to embedded frame
dcherepanov
parents: 129
diff changeset
  1961
                xme.set_y(localCoord.y);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
            grabLog.log(Level.FINER, "  -  Grab event target {0}", new Object[] {target});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
                if (target != getContentXWindow() && target != this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
                    target.dispatchEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
            // note that we need to pass dragging events to the grabber (6390326)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
            // see comment above for more inforamtion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
            if (!containsGlobal(xme.get_x_root(), xme.get_y_root()) && !dragging) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
                // Outside of Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
        super.handleMotionNotify(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
    // we use it to retarget mouse drag and mouse release during grab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
    private XBaseWindow pressTarget = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
    public void handleButtonPressRelease(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
        XButtonEvent xbe = xev.get_xbutton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
        if (grabLog.isLoggable(Level.FINE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
            grabLog.log(Level.FINE, "{0}, when grabbed {1}, contains {2} ({3}, {4}, {5}x{6})",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
                        new Object[] {xbe, isGrabbed(), containsGlobal(xbe.get_x_root(), xbe.get_y_root()), getAbsoluteX(), getAbsoluteY(), getWidth(), getHeight()});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
        if (isGrabbed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
            // When window is grabbed, all events are dispatched to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
            // it.  Retarget them to the corresponding windows (notice
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
            // that XBaseWindow.dispatchEvent does the opposite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
            // translation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
            XBaseWindow target = XToolkit.windowToXWindow(xbe.get_window());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
                grabLog.log(Level.FINER, "  -  Grab event target {0} (press target {1})", new Object[] {target, pressTarget});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
                if (xbe.get_type() == XConstants.ButtonPress
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1190
diff changeset
  1999
                    && xbe.get_button() == XConstants.buttons[0])
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
                    // need to keep it to retarget mouse release
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
                    pressTarget = target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
                } else if (xbe.get_type() == XConstants.ButtonRelease
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents: 1190
diff changeset
  2004
                           && xbe.get_button() == XConstants.buttons[0]
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
                           && pressTarget != target)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
                    // during grab we do receive mouse release on different component (not on the source
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
                    // of mouse press).  So we need to retarget it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
                    // see 6390326 for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
                    target = pressTarget.isVisible() ? pressTarget : this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
                    xbe.set_window(target.getWindow());
430
ff8a4a3ad82f 6508505: JComboBox collapses immediately if it is placed to embedded frame
dcherepanov
parents: 129
diff changeset
  2012
                    Point localCoord = target.toLocal(xbe.get_x_root(), xbe.get_y_root());
ff8a4a3ad82f 6508505: JComboBox collapses immediately if it is placed to embedded frame
dcherepanov
parents: 129
diff changeset
  2013
                    xbe.set_x(localCoord.x);
ff8a4a3ad82f 6508505: JComboBox collapses immediately if it is placed to embedded frame
dcherepanov
parents: 129
diff changeset
  2014
                    xbe.set_y(localCoord.y);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
                    pressTarget = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
                if (target != null && target != getContentXWindow() && target != this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
                    target.dispatchEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
                if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
                    // Target is either us or our content window -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
                    // check that event is inside.  'Us' in case of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
                    // shell will mean that this will also filter out press on title
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
                    if ((target == this || target == getContentXWindow()) && !containsGlobal(xbe.get_x_root(), xbe.get_y_root())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
                        // Outside this toplevel hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
                        // According to the specification of UngrabEvent, post it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
                        // when press occurs outside of the window and not on its owned windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
                        grabLog.log(Level.FINE, "Generating UngrabEvent on {0} because not inside of shell", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
                        postEventToEventQueue(new sun.awt.UngrabEvent(getEventSource()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
                    // First, get the toplevel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
                    XWindowPeer toplevel = target.getToplevelXWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
                    if (toplevel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
                        Window w = (Window)toplevel.target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
                        while (w != null && toplevel != this && !(toplevel instanceof XDialogPeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
                            w = (Window) ComponentAccessor.getParent_NoClientCode(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
                            if (w != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
                                toplevel = (XWindowPeer) ComponentAccessor.getPeer(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
                        if (w == null || (w != this.target && w instanceof Dialog)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
                            // toplevel == null - outside of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
                            // hierarchy, toplevel is Dialog - should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
                            // send ungrab (but shouldn't for Window)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
                            grabLog.log(Level.FINE, "Generating UngrabEvent on {0} because hierarchy ended", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
                            postEventToEventQueue(new sun.awt.UngrabEvent(getEventSource()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
                        // toplevel is null - outside of hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
                        grabLog.log(Level.FINE, "Generating UngrabEvent on {0} because toplevel is null", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
                        postEventToEventQueue(new sun.awt.UngrabEvent(getEventSource()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
                    // target doesn't map to XAWT window - outside of hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
                    grabLog.log(Level.FINE, "Generating UngrabEvent on because target is null {0}", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
                    postEventToEventQueue(new sun.awt.UngrabEvent(getEventSource()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
        super.handleButtonPressRelease(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
}