1 /*
   2  * Copyright (c) 1996, 2016, 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.windows;
  26 
  27 import java.util.Vector;
  28 import java.awt.*;
  29 import java.awt.peer.*;
  30 import java.awt.image.ImageObserver;
  31 import sun.awt.image.ImageRepresentation;
  32 import sun.awt.image.IntegerComponentRaster;
  33 import sun.awt.image.ToolkitImage;
  34 import java.awt.image.Raster;
  35 import java.awt.image.DataBuffer;
  36 import java.awt.image.DataBufferInt;
  37 import java.awt.image.BufferedImage;
  38 import sun.awt.im.*;
  39 import sun.awt.Win32GraphicsDevice;
  40 import java.awt.image.ColorModel;
  41 
  42 
  43 class WFramePeer extends WWindowPeer implements FramePeer {
  44 
  45     // FramePeer implementation
  46     public native void setState(int state);
  47     public native int getState();
  48 
  49     // Convenience methods to save us from trouble of extracting
  50     // Rectangle fields in native code.
  51     private native void setMaximizedBounds(int x, int y, int w, int h);
  52     private native void clearMaximizedBounds();
  53 
  54     private static final boolean keepOnMinimize = "true".equals(
  55         (String)java.security.AccessController.doPrivileged(
  56             new sun.security.action.GetPropertyAction(
  57                 "sun.awt.keepWorkingSetOnMinimize")));
  58 
  59     public void setMaximizedBounds(Rectangle b) {
  60         if (b == null) {
  61             clearMaximizedBounds();
  62         } else {
  63             setMaximizedBounds(b.x, b.y, b.width, b.height);
  64         }
  65     }
  66 
  67     @Override
  68     boolean isTargetUndecorated() {
  69         return ((Frame)target).isUndecorated();
  70     }
  71 
  72     public void reshape(int x, int y, int width, int height) {
  73         Rectangle newBounds = constrainBounds(x, y, width, height);
  74 
  75         if (((Frame)target).isUndecorated()) {
  76             super.reshape(newBounds.x, newBounds.y, newBounds.width, newBounds.height);
  77         } else {
  78             reshapeFrame(newBounds.x, newBounds.y, newBounds.width, newBounds.height);
  79         }
  80     }
  81 
  82     public Dimension getMinimumSize() {
  83         Dimension d = new Dimension();
  84         if (!((Frame)target).isUndecorated()) {
  85             d.setSize(getSysMinWidth(), getSysMinHeight());
  86         }
  87         if (((Frame)target).getMenuBar() != null) {
  88             d.height += getSysMenuHeight();
  89         }
  90         return d;
  91     }
  92 
  93     // Note: Because this method calls resize(), which may be overridden
  94     // by client code, this method must not be executed on the toolkit
  95     // thread.
  96     public void setMenuBar(MenuBar mb) {
  97         WMenuBarPeer mbPeer = (WMenuBarPeer) WToolkit.targetToPeer(mb);
  98         if (mbPeer != null) {
  99             if (mbPeer.framePeer != this) {
 100                 mb.removeNotify();
 101                 mb.addNotify();
 102                 mbPeer = (WMenuBarPeer) WToolkit.targetToPeer(mb);
 103                 if (mbPeer != null && mbPeer.framePeer != this) {
 104                     throw new IllegalStateException("Wrong parent peer");
 105                 }
 106             }
 107             if (mbPeer != null) {
 108                 addChildPeer(mbPeer);
 109             }
 110         }
 111         setMenuBar0(mbPeer);
 112         updateInsets(insets_);
 113     }
 114 
 115     // Note: Because this method calls resize(), which may be overridden
 116     // by client code, this method must not be executed on the toolkit
 117     // thread.
 118     private native void setMenuBar0(WMenuBarPeer mbPeer);
 119 
 120     // Toolkit & peer internals
 121 
 122     WFramePeer(Frame target) {
 123         super(target);
 124 
 125         InputMethodManager imm = InputMethodManager.getInstance();
 126         String menuString = imm.getTriggerMenuString();
 127         if (menuString != null)
 128         {
 129           pSetIMMOption(menuString);
 130         }
 131     }
 132 
 133     native void createAwtFrame(WComponentPeer parent);
 134     void create(WComponentPeer parent) {
 135         createAwtFrame(parent);
 136     }
 137 
 138     void initialize() {
 139         super.initialize();
 140 
 141         Frame target = (Frame)this.target;
 142 
 143         if (target.getTitle() != null) {
 144             setTitle(target.getTitle());
 145         }
 146         setResizable(target.isResizable());
 147         setState(target.getExtendedState());
 148     }
 149 
 150     private native static int getSysMenuHeight();
 151 
 152     native void pSetIMMOption(String option);
 153     void notifyIMMOptionChange(){
 154       InputMethodManager.getInstance().notifyChangeRequest((Component)target);
 155     }
 156 
 157     public void setBoundsPrivate(int x, int y, int width, int height) {
 158         setBounds(x, y, width, height, SET_BOUNDS);
 159     }
 160     public Rectangle getBoundsPrivate() {
 161         return getBounds();
 162     }
 163 }