jdk/src/solaris/classes/sun/awt/X11/XDialogPeer.java
author yan
Mon, 06 Oct 2008 16:45:00 +0400
changeset 1966 12a51fb0db0d
parent 449 7820f232278d
child 4371 dc9dcb8b0ae7
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
/*
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 129
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.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.peer.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import sun.awt.ComponentAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
class XDialogPeer extends XDecoratedPeer implements DialogPeer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    private Boolean undecorated;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    XDialogPeer(Dialog target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        super(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    public void preInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        super.preInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        Dialog target = (Dialog)(this.target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        undecorated = Boolean.valueOf(target.isUndecorated());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        winAttr.nativeDecor = !target.isUndecorated();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        if (winAttr.nativeDecor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
            winAttr.decorations = winAttr.AWT_DECOR_ALL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            winAttr.decorations = winAttr.AWT_DECOR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        }
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 129
diff changeset
    54
        winAttr.functions = MWMConstants.MWM_FUNC_ALL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        winAttr.isResizable =  true; //target.isResizable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        winAttr.initialResizability =  target.isResizable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        winAttr.title = target.getTitle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        winAttr.initialState = XWindowAttributesData.NORMAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public void setVisible(boolean vis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            Dialog target = (Dialog)this.target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            if (vis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                if (target.getModalityType() != Dialog.ModalityType.MODELESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                    if (!isModalBlocked()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                        XBaseWindow.ungrabInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                restoreTransientFor(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                prevTransientFor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                nextTransientFor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        super.setVisible(vis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
    83
    @Override
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
    84
    boolean isTargetUndecorated() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        if (undecorated != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            return undecorated.booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            return ((Dialog)target).isUndecorated();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    int getDecorations() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        int d = super.getDecorations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        // remove minimize and maximize buttons for dialogs
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 129
diff changeset
    95
        if ((d & MWMConstants.MWM_DECOR_ALL) != 0) {
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 129
diff changeset
    96
            d |= (MWMConstants.MWM_DECOR_MINIMIZE | MWMConstants.MWM_DECOR_MAXIMIZE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        } else {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 129
diff changeset
    98
            d &= ~(MWMConstants.MWM_DECOR_MINIMIZE | MWMConstants.MWM_DECOR_MAXIMIZE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    int getFunctions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        int f = super.getFunctions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        // remove minimize and maximize functions for dialogs
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 129
diff changeset
   106
        if ((f & MWMConstants.MWM_FUNC_ALL) != 0) {
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 129
diff changeset
   107
            f |= (MWMConstants.MWM_FUNC_MINIMIZE | MWMConstants.MWM_FUNC_MAXIMIZE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        } else {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 129
diff changeset
   109
            f &= ~(MWMConstants.MWM_FUNC_MINIMIZE | MWMConstants.MWM_FUNC_MAXIMIZE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        return f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public void blockWindows(java.util.List<Window> toBlock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        Vector<XWindowPeer> javaToplevels = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            javaToplevels = XWindowPeer.collectJavaToplevels();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            for (Window w : toBlock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                XWindowPeer wp = (XWindowPeer)ComponentAccessor.getPeer(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                if (wp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                    wp.setModalBlocked((Dialog)target, true, javaToplevels);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * WARNING: don't call client code in this method!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * The check is performed before the dialog is shown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * The focused window can't be blocked at the time it's focused.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Thus we don't have to perform any transitive (a blocker of a blocker) checks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    boolean isFocusedWindowModalBlocker() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        Window focusedWindow = XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        XWindowPeer focusedWindowPeer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        if (focusedWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            focusedWindowPeer = (XWindowPeer)ComponentAccessor.getPeer(focusedWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
             * For the case when a potential blocked window is not yet focused
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
             * on the Java level (e.g. it's just been mapped) we're asking for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
             * focused window on the native level.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            focusedWindowPeer = getNativeFocusedWindowPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        synchronized (getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            if (focusedWindowPeer != null && focusedWindowPeer.modalBlocker == target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        return super.isFocusedWindowModalBlocker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
}