jdk/src/java.desktop/windows/classes/sun/awt/windows/WDialogPeer.java
author serb
Fri, 17 Apr 2015 16:54:13 +0300
changeset 30469 bac0a7ff7e1e
parent 25859 3317bb8137f4
child 32865 f9cb6e427f9e
permissions -rw-r--r--
8074028: Remove API references to java.awt.peer Reviewed-by: alanb, ant, yan, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23272
0e0103e73d3c 8032435: Cleanup of sun.awt.windows package
serb
parents: 11271
diff changeset
     2
 * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4371
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4371
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4371
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4371
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4371
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.awt.windows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.peer.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import sun.awt.im.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
23272
0e0103e73d3c 8032435: Cleanup of sun.awt.windows package
serb
parents: 11271
diff changeset
    33
final class WDialogPeer extends WWindowPeer implements DialogPeer {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    // Toolkit & peer internals
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    // Platform default background for dialogs.  Gets set on target if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    // target has none explicitly specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    final static Color defaultBackground =  SystemColor.control;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    // If target doesn't have its background color set, we set its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    // background to platform default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    boolean needDefaultBackground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    WDialogPeer(Dialog target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        super(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        InputMethodManager imm = InputMethodManager.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        String menuString = imm.getTriggerMenuString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        if (menuString != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
            pSetIMMOption(menuString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
4366
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 2643
diff changeset
    55
    native void createAwtDialog(WComponentPeer parent);
23272
0e0103e73d3c 8032435: Cleanup of sun.awt.windows package
serb
parents: 11271
diff changeset
    56
    @Override
4366
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 2643
diff changeset
    57
    void create(WComponentPeer parent) {
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 2643
diff changeset
    58
        preCreate(parent);
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 2643
diff changeset
    59
        createAwtDialog(parent);
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 2643
diff changeset
    60
    }
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 2643
diff changeset
    61
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    native void showModal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    native void endModal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
23272
0e0103e73d3c 8032435: Cleanup of sun.awt.windows package
serb
parents: 11271
diff changeset
    65
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    void initialize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        Dialog target = (Dialog)this.target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        // Need to set target's background to default _before_ a call
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        // to super.initialize.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        if (needDefaultBackground) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            target.setBackground(defaultBackground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        super.initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        if (target.getTitle() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            setTitle(target.getTitle());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        setResizable(target.isResizable());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
23272
0e0103e73d3c 8032435: Cleanup of sun.awt.windows package
serb
parents: 11271
diff changeset
    82
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    protected void realShow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        Dialog dlg = (Dialog)target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        if (dlg.getModalityType() != Dialog.ModalityType.MODELESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            showModal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            super.realShow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
23272
0e0103e73d3c 8032435: Cleanup of sun.awt.windows package
serb
parents: 11271
diff changeset
    92
    @Override
11271
f10f98b24801 7117011: Reduce number of warnings in sun/awt/windows and sun/awt/datatransfer
denis
parents: 5506
diff changeset
    93
    @SuppressWarnings("deprecation")
23272
0e0103e73d3c 8032435: Cleanup of sun.awt.windows package
serb
parents: 11271
diff changeset
    94
    void hide() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        Dialog dlg = (Dialog)target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        if (dlg.getModalityType() != Dialog.ModalityType.MODELESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            endModal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            super.hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
23272
0e0103e73d3c 8032435: Cleanup of sun.awt.windows package
serb
parents: 11271
diff changeset
   103
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public void blockWindows(java.util.List<Window> toBlock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        for (Window w : toBlock) {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 25859
diff changeset
   106
            WWindowPeer wp = AWTAccessor.getComponentAccessor().getPeer(w);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            if (wp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                wp.setModalBlocked((Dialog)target, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
23272
0e0103e73d3c 8032435: Cleanup of sun.awt.windows package
serb
parents: 11271
diff changeset
   113
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (((Dialog)target).isUndecorated()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            return super.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            return new Dimension(getSysMinWidth(), getSysMinHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   122
    @Override
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   123
    boolean isTargetUndecorated() {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   124
        return ((Dialog)target).isUndecorated();
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   125
    }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   126
23272
0e0103e73d3c 8032435: Cleanup of sun.awt.windows package
serb
parents: 11271
diff changeset
   127
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public void reshape(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        if (((Dialog)target).isUndecorated()) {
2643
ea218b1a2000 6821948: Consider removing the constraints for bounds of untrusted top-level windows
anthony
parents: 715
diff changeset
   130
            super.reshape(x, y, width, height);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        } else {
2643
ea218b1a2000 6821948: Consider removing the constraints for bounds of untrusted top-level windows
anthony
parents: 715
diff changeset
   132
            reshapeFrame(x, y, width, height);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /* Native create() peeks at target's background and if it's null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * calls this method to arrage for default background to be set on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * target.  Can't make the check in Java, since getBackground will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * return owner's background if target has none set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private void setDefaultColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        // Can't call target.setBackground directly, since we are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        // called on toolkit thread.  Can't schedule a Runnable on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        // EventHandlerThread because of the race condition.  So just
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        // set a flag and call target.setBackground in initialize.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        needDefaultBackground = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    native void pSetIMMOption(String option);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    void notifyIMMOptionChange(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
      InputMethodManager.getInstance().notifyChangeRequest((Component)target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
}