1 /*
   2  * Copyright (c) 1999, 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 
  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         new Thread(new Runnable() {
  71             @Override
  72             public void run() {
  73                 try {
  74                     ((WPrintDialog)target).setRetVal(_show());
  75                 } catch (Exception e) {
  76                     // No exception should be thrown by native dialog code,
  77                     // but if it is we need to trap it so the thread does
  78                     // not hide is called and the thread doesn't hang.
  79                 }
  80                 ((WPrintDialog)target).setVisible(false);
  81             }
  82         }).start();
  83     }
  84 
  85     synchronized void setHWnd(long hwnd) {
  86         this.hwnd = hwnd;
  87         for (WWindowPeer window : blockedWindows) {
  88             if (hwnd != 0) {
  89                 window.modalDisable((Dialog)target, hwnd);
  90             } else {
  91                 window.modalEnable((Dialog)target);
  92             }
  93         }
  94     }
  95 
  96     synchronized void blockWindow(WWindowPeer window) {
  97         blockedWindows.add(window);
  98         if (hwnd != 0) {
  99             window.modalDisable((Dialog)target, hwnd);
 100         }
 101     }
 102     synchronized void unblockWindow(WWindowPeer window) {
 103         blockedWindows.remove(window);
 104         if (hwnd != 0) {
 105             window.modalEnable((Dialog)target);
 106         }
 107     }
 108 
 109     @Override
 110     public void blockWindows(java.util.List<Window> toBlock) {
 111         for (Window w : toBlock) {
 112             WWindowPeer wp = (WWindowPeer)AWTAccessor.getComponentAccessor().getPeer(w);
 113             if (wp != null) {
 114                 blockWindow(wp);
 115             }
 116         }
 117     }
 118 
 119     @Override
 120     public native void toFront();
 121     @Override
 122     public native void toBack();
 123 
 124     // unused methods.  Overridden to disable this functionality as
 125     // it requires HWND which is not available for FileDialog
 126     @Override
 127     void initialize() {}
 128     @Override
 129     public void updateAlwaysOnTopState() {}
 130     @Override
 131     public void setResizable(boolean resizable) {}
 132     @Override
 133     void hide() {}
 134     @Override
 135     void enable() {}
 136     @Override
 137     void disable() {}
 138     @Override
 139     public void reshape(int x, int y, int width, int height) {}
 140     public boolean handleEvent(Event e) { return false; }
 141     @Override
 142     public void setForeground(Color c) {}
 143     @Override
 144     public void setBackground(Color c) {}
 145     @Override
 146     public void setFont(Font f) {}
 147     @Override
 148     public void updateMinimumSize() {}
 149     @Override
 150     public void updateIconImages() {}
 151     public boolean requestFocus(boolean temporary, boolean focusedWindowChangeAllowed) {
 152         return false;
 153     }
 154 
 155     @Override
 156     public boolean requestFocus
 157          (Component lightweightChild, boolean temporary,
 158           boolean focusedWindowChangeAllowed, long time, CausedFocusEvent.Cause cause)
 159     {
 160 
 161         return false;
 162     }
 163 
 164     @Override
 165     public void updateFocusableWindowState() {}
 166     @Override
 167     void start() {}
 168     @Override
 169     public void beginValidate() {}
 170     @Override
 171     public void endValidate() {}
 172     void invalidate(int x, int y, int width, int height) {}
 173     @Override
 174     public void addDropTarget(DropTarget dt) {}
 175     @Override
 176     public void removeDropTarget(DropTarget dt) {}
 177     @Override
 178     public void setZOrder(ComponentPeer above) {}
 179 
 180     /**
 181      * Initialize JNI field and method ids
 182      */
 183     private static native void initIDs();
 184 
 185     // The effects are not supported for system dialogs.
 186     @Override
 187     public void applyShape(sun.java2d.pipe.Region shape) {}
 188     @Override
 189     public void setOpacity(float opacity) {}
 190     @Override
 191     public void setOpaque(boolean isOpaque) {}
 192     public void updateWindow(java.awt.image.BufferedImage backBuffer) {}
 193 
 194     // the file/print dialogs are native dialogs and
 195     // the native system does their own rendering
 196     @Override
 197     public void createScreenSurface(boolean isResize) {}
 198     @Override
 199     public void replaceSurfaceData() {}
 200 }