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 final class WDialogPeer extends WWindowPeer implements DialogPeer {
  40     // Toolkit & peer internals
  41 
  42     // Platform default background for dialogs.  Gets set on target if
  43     // target has none explicitly specified.
  44     static final Color defaultBackground =  SystemColor.control;
  45 
  46     WDialogPeer(Dialog target) {
  47         super(target);
  48 
  49         InputMethodManager imm = InputMethodManager.getInstance();
  50         String menuString = imm.getTriggerMenuString();
  51         if (menuString != null)
  52         {
  53             pSetIMMOption(menuString);
  54         }
  55     }
  56 
  57     native void createAwtDialog(WComponentPeer parent);
  58     @Override
  59     void create(WComponentPeer parent) {
  60         preCreate(parent);
  61         createAwtDialog(parent);
  62     }
  63 
  64     native void showModal();
  65     native void endModal();
  66 
  67     @Override
  68     void initialize() {
  69         Dialog target = (Dialog)this.target;
  70         // Need to set target's background to default _before_ a call
  71         // to super.initialize.
  72         if (!target.isBackgroundSet()) {
  73             target.setBackground(defaultBackground);
  74         }
  75 
  76         super.initialize();
  77 
  78         if (target.getTitle() != null) {
  79             setTitle(target.getTitle());
  80         }
  81         setResizable(target.isResizable());
  82     }
  83 
  84     @Override
  85     protected void realShow() {
  86         Dialog dlg = (Dialog)target;
  87         if (dlg.getModalityType() != Dialog.ModalityType.MODELESS) {
  88             showModal();
  89         } else {
  90             super.realShow();
  91         }
  92     }
  93 
  94     @Override
  95     @SuppressWarnings("deprecation")
  96     void hide() {
  97         Dialog dlg = (Dialog)target;
  98         if (dlg.getModalityType() != Dialog.ModalityType.MODELESS) {
  99             endModal();
 100         } else {
 101             super.hide();
 102         }
 103     }
 104 
 105     @Override
 106     public void blockWindows(java.util.List<Window> toBlock) {
 107         for (Window w : toBlock) {
 108             WWindowPeer wp = AWTAccessor.getComponentAccessor().getPeer(w);
 109             if (wp != null) {
 110                 wp.setModalBlocked((Dialog)target, true);
 111             }
 112         }
 113     }
 114 
 115     @Override
 116     public Dimension getMinimumSize() {
 117         if (((Dialog)target).isUndecorated()) {
 118             return super.getMinimumSize();
 119         }
 120         return new Dimension(scaleDownX(getSysMinWidth()),
 121                              scaleDownY(getSysMinHeight()));
 122     }
 123 
 124     @Override
 125     boolean isTargetUndecorated() {
 126         return ((Dialog)target).isUndecorated();
 127     }
 128 
 129     @Override
 130     public void reshape(int x, int y, int width, int height) {
 131         if (((Dialog)target).isUndecorated()) {
 132             super.reshape(x, y, width, height);
 133         } else {
 134             reshapeFrame(x, y, width, height);
 135         }
 136     }
 137 
 138     native void pSetIMMOption(String option);
 139     void notifyIMMOptionChange(){
 140       InputMethodManager.getInstance().notifyChangeRequest((Component)target);
 141     }
 142 }