1 /* 2 * Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.awt.windows; 27 28 import java.awt.Color; 29 import java.awt.Component; 30 import java.awt.Dialog; 31 import java.awt.Dimension; 32 import java.awt.SystemColor; 33 import java.awt.Window; 34 import java.awt.peer.DialogPeer; 35 36 import sun.awt.AWTAccessor; 37 import sun.awt.im.InputMethodManager; 38 39 import static sun.java2d.SunGraphicsEnvironment.toUserSpace; 40 41 final class WDialogPeer extends WWindowPeer implements DialogPeer { 42 // Toolkit & peer internals 43 44 // Platform default background for dialogs. Gets set on target if 45 // target has none explicitly specified. 46 static final Color defaultBackground = SystemColor.control; 47 48 WDialogPeer(Dialog target) { 49 super(target); 50 51 InputMethodManager imm = InputMethodManager.getInstance(); 52 String menuString = imm.getTriggerMenuString(); 53 if (menuString != null) 54 { 55 pSetIMMOption(menuString); 56 } 57 } 58 59 native void createAwtDialog(WComponentPeer parent); 60 @Override 61 void create(WComponentPeer parent) { 62 preCreate(parent); 63 createAwtDialog(parent); 64 } 65 66 native void showModal(); 67 native void endModal(); 68 69 @Override 70 void initialize() { 71 Dialog target = (Dialog)this.target; 72 // Need to set target's background to default _before_ a call 73 // to super.initialize. 74 if (!target.isBackgroundSet()) { 75 target.setBackground(defaultBackground); 76 } 77 78 super.initialize(); 79 80 if (target.getTitle() != null) { 81 setTitle(target.getTitle()); 82 } 83 setResizable(target.isResizable()); 84 } 85 86 @Override 87 protected void realShow() { 88 Dialog dlg = (Dialog)target; 89 if (dlg.getModalityType() != Dialog.ModalityType.MODELESS) { 90 showModal(); 91 } else { 92 super.realShow(); 93 } 94 } 95 96 @Override 97 @SuppressWarnings("deprecation") 98 void hide() { 99 Dialog dlg = (Dialog)target; 100 if (dlg.getModalityType() != Dialog.ModalityType.MODELESS) { 101 endModal(); 102 } else { 103 super.hide(); 104 } 105 } 106 107 @Override 108 public void blockWindows(java.util.List<Window> toBlock) { 109 for (Window w : toBlock) { 110 WWindowPeer wp = AWTAccessor.getComponentAccessor().getPeer(w); 111 if (wp != null) { 112 wp.setModalBlocked((Dialog)target, true); 113 } 114 } 115 } 116 117 @Override 118 public Dimension getMinimumSize() { 119 if (((Dialog)target).isUndecorated()) { 120 return super.getMinimumSize(); 121 } 122 return toUserSpace(getGraphicsConfiguration(), 123 getSysMinWidth(), getSysMinHeight()); 124 } 125 126 @Override 127 boolean isTargetUndecorated() { 128 return ((Dialog)target).isUndecorated(); 129 } 130 131 @Override 132 public void reshape(int x, int y, int width, int height) { 133 if (((Dialog)target).isUndecorated()) { 134 super.reshape(x, y, width, height); 135 } else { 136 reshapeFrame(x, y, width, height); 137 } 138 } 139 140 native void pSetIMMOption(String option); 141 void notifyIMMOptionChange(){ 142 InputMethodManager.getInstance().notifyChangeRequest((Component)target); 143 } 144 }