1 /* 2 * Copyright (c) 1999, 2015, 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.*; 29 import java.awt.peer.DialogPeer; 30 import java.awt.peer.ComponentPeer; 31 import java.awt.dnd.DropTarget; 32 import java.util.Vector; 33 import sun.awt.CausedFocusEvent; 34 import sun.awt.AWTAccessor; 35 36 class WPrintDialogPeer extends WWindowPeer implements DialogPeer { 37 38 static { 39 initIDs(); 40 } 41 42 private WComponentPeer parent; 43 44 private Vector<WWindowPeer> blockedWindows = new Vector<>(); 45 46 WPrintDialogPeer(WPrintDialog target) { 47 super(target); 48 } 49 50 @Override 51 void create(WComponentPeer parent) { 52 this.parent = parent; 53 } 54 55 // fix for CR 6178323: 56 // don't use checkCreation() from WComponentPeer to avoid hwnd check 57 @Override 58 protected void checkCreation() { 59 } 60 61 @Override 62 protected void disposeImpl() { 63 WToolkit.targetDisposedPeer(target, this); 64 } 65 66 private native boolean _show(); 67 68 @Override 69 public void show() { 70 Runnable runnable = () -> { 71 try { 72 ((WPrintDialog)target).setRetVal(_show()); 73 } catch (Exception e) { 74 // No exception should be thrown by native dialog code, 75 // but if it is we need to trap it so the thread does 76 // not hide is called and the thread doesn't hang. 77 } 78 ((WPrintDialog)target).setVisible(false); 79 }; 80 new Thread(null, runnable, "PrintDialog", 0, false).start(); 81 } 82 83 synchronized void setHWnd(long hwnd) { 84 this.hwnd = hwnd; 85 for (WWindowPeer window : blockedWindows) { 86 if (hwnd != 0) { 87 window.modalDisable((Dialog)target, hwnd); 88 } else { 89 window.modalEnable((Dialog)target); 90 } 91 } 92 } 93 94 synchronized void blockWindow(WWindowPeer window) { 95 blockedWindows.add(window); 96 if (hwnd != 0) { 97 window.modalDisable((Dialog)target, hwnd); 98 } 99 } 100 synchronized void unblockWindow(WWindowPeer window) { 101 blockedWindows.remove(window); 102 if (hwnd != 0) { 103 window.modalEnable((Dialog)target); 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 blockWindow(wp); 113 } 114 } 115 } 116 117 @Override 118 public native void toFront(); 119 @Override 120 public native void toBack(); 121 122 // unused methods. Overridden to disable this functionality as 123 // it requires HWND which is not available for FileDialog 124 @Override 125 void initialize() {} 126 @Override 127 public void updateAlwaysOnTopState() {} 128 @Override 129 public void setResizable(boolean resizable) {} 130 @Override 131 void hide() {} 132 @Override 133 void enable() {} 134 @Override 135 void disable() {} 136 @Override 137 public void reshape(int x, int y, int width, int height) {} 138 public boolean handleEvent(Event e) { return false; } 139 @Override 140 public void setForeground(Color c) {} 141 @Override 142 public void setBackground(Color c) {} 143 @Override 144 public void setFont(Font f) {} 145 @Override 146 public void updateMinimumSize() {} 147 @Override 148 public void updateIconImages() {} 149 public boolean requestFocus(boolean temporary, boolean focusedWindowChangeAllowed) { 150 return false; 151 } 152 153 @Override 154 public boolean requestFocus 155 (Component lightweightChild, boolean temporary, 156 boolean focusedWindowChangeAllowed, long time, CausedFocusEvent.Cause cause) 157 { 158 159 return false; 160 } 161 162 @Override 163 public void updateFocusableWindowState() {} 164 @Override 165 void start() {} 166 @Override 167 public void beginValidate() {} 168 @Override 169 public void endValidate() {} 170 void invalidate(int x, int y, int width, int height) {} 171 @Override 172 public void addDropTarget(DropTarget dt) {} 173 @Override 174 public void removeDropTarget(DropTarget dt) {} 175 @Override 176 public void setZOrder(ComponentPeer above) {} 177 178 /** 179 * Initialize JNI field and method ids 180 */ 181 private static native void initIDs(); 182 183 // The effects are not supported for system dialogs. 184 @Override 185 public void applyShape(sun.java2d.pipe.Region shape) {} 186 @Override 187 public void setOpacity(float opacity) {} 188 @Override 189 public void setOpaque(boolean isOpaque) {} 190 public void updateWindow(java.awt.image.BufferedImage backBuffer) {} 191 192 // the file/print dialogs are native dialogs and 193 // the native system does their own rendering 194 @Override 195 public void createScreenSurface(boolean isResize) {} 196 @Override 197 public void replaceSurfaceData() {} 198 }