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