1 /*
   2  * Copyright (c) 1996, 2008, 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 
  29 import java.awt.*;
  30 import java.awt.peer.*;
  31 import java.awt.image.ImageObserver;
  32 
  33 import java.awt.image.Raster;
  34 import java.awt.image.DataBuffer;
  35 import java.awt.image.DataBufferInt;
  36 import java.awt.image.BufferedImage;
  37 
  38 import java.awt.image.ColorModel;
  39 
  40 import sun.awt.image.ImageRepresentation;
  41 import sun.awt.image.IntegerComponentRaster;
  42 import sun.awt.image.ToolkitImage;
  43 import sun.awt.im.*;
  44 import sun.awt.Win32GraphicsDevice;
  45 import sun.awt.AWTAccessor;
  46 
  47 class WFramePeer extends WWindowPeer implements FramePeer {
  48 
  49     static {
  50         initIDs();
  51     }
  52 
  53     // initialize JNI field and method IDs
  54     private static native void initIDs();
  55 
  56     // FramePeer implementation
  57     public native void setState(int state);
  58     public native int getState();
  59 
  60     // sync target and peer
  61     public void setExtendedState(int state) {
  62         AWTAccessor.getFrameAccessor().setExtendedState((Frame)target, state);
  63     }
  64     public int getExtendedState() {
  65         return AWTAccessor.getFrameAccessor().getExtendedState((Frame)target);
  66     }
  67 
  68     // Convenience methods to save us from trouble of extracting
  69     // Rectangle fields in native code.
  70     private native void setMaximizedBounds(int x, int y, int w, int h);
  71     private native void clearMaximizedBounds();
  72 
  73     private static final boolean keepOnMinimize = "true".equals(
  74         (String)java.security.AccessController.doPrivileged(
  75             new sun.security.action.GetPropertyAction(
  76                 "sun.awt.keepWorkingSetOnMinimize")));
  77 
  78     public void setMaximizedBounds(Rectangle b) {
  79         if (b == null) {
  80             clearMaximizedBounds();
  81         } else {
  82             Rectangle adjBounds = (Rectangle)b.clone();
  83             adjustMaximizedBounds(adjBounds);
  84             setMaximizedBounds(adjBounds.x, adjBounds.y, adjBounds.width, adjBounds.height);
  85         }
  86     }
  87 
  88     /**
  89      * The incoming bounds describe the maximized size and position of the
  90      * window on the monitor that displays the window. But the window manager
  91      * expects that the bounds are based on the size and position of the
  92      * primary monitor, even if the window ultimately maximizes onto a
  93      * secondary monitor. And the window manager adjusts these values to
  94      * compensate for differences between the primary monitor and the monitor
  95      * that displays the window.
  96      * The method translates the incoming bounds to the values acceptable
  97      * by the window manager. For more details, please refer to 6699851.
  98      */
  99     private void adjustMaximizedBounds(Rectangle b) {
 100         GraphicsConfiguration currentDevGC = getGraphicsConfiguration();
 101 
 102         GraphicsDevice primaryDev = GraphicsEnvironment
 103             .getLocalGraphicsEnvironment().getDefaultScreenDevice();
 104         GraphicsConfiguration primaryDevGC = primaryDev.getDefaultConfiguration();
 105 
 106         if (currentDevGC != null && currentDevGC != primaryDevGC) {
 107             Rectangle currentDevBounds = currentDevGC.getBounds();
 108             Rectangle primaryDevBounds = primaryDevGC.getBounds();
 109 
 110             b.width -= (currentDevBounds.width - primaryDevBounds.width);
 111             b.height -= (currentDevBounds.height - primaryDevBounds.height);
 112         }
 113     }
 114 
 115     @Override
 116     public boolean updateGraphicsData(GraphicsConfiguration gc) {
 117         boolean result = super.updateGraphicsData(gc);
 118         Rectangle bounds = AWTAccessor.getFrameAccessor().
 119                                getMaximizedBounds((Frame)target);
 120         if (bounds != null) {
 121             setMaximizedBounds(bounds);
 122         }
 123         return result;
 124     }
 125 
 126     @Override
 127     boolean isTargetUndecorated() {
 128         return ((Frame)target).isUndecorated();
 129     }
 130 
 131     public void reshape(int x, int y, int width, int height) {
 132         if (((Frame)target).isUndecorated()) {
 133             super.reshape(x, y, width, height);
 134         } else {
 135             reshapeFrame(x, y, width, height);
 136         }
 137     }
 138 
 139     public Dimension getMinimumSize() {
 140         Dimension d = new Dimension();
 141         if (!((Frame)target).isUndecorated()) {
 142             d.setSize(getSysMinWidth(), getSysMinHeight());
 143         }
 144         if (((Frame)target).getMenuBar() != null) {
 145             d.height += getSysMenuHeight();
 146         }
 147         return d;
 148     }
 149 
 150     // Note: Because this method calls resize(), which may be overridden
 151     // by client code, this method must not be executed on the toolkit
 152     // thread.
 153     public void setMenuBar(MenuBar mb) {
 154         WMenuBarPeer mbPeer = (WMenuBarPeer) WToolkit.targetToPeer(mb);
 155         setMenuBar0(mbPeer);
 156         updateInsets(insets_);
 157     }
 158 
 159     // Note: Because this method calls resize(), which may be overridden
 160     // by client code, this method must not be executed on the toolkit
 161     // thread.
 162     private native void setMenuBar0(WMenuBarPeer mbPeer);
 163 
 164     // Toolkit & peer internals
 165 
 166     WFramePeer(Frame target) {
 167         super(target);
 168 
 169         InputMethodManager imm = InputMethodManager.getInstance();
 170         String menuString = imm.getTriggerMenuString();
 171         if (menuString != null)
 172         {
 173           pSetIMMOption(menuString);
 174         }
 175     }
 176 
 177     native void createAwtFrame(WComponentPeer parent);
 178     void create(WComponentPeer parent) {
 179         preCreate(parent);
 180         createAwtFrame(parent);
 181     }
 182 
 183     void initialize() {
 184         super.initialize();
 185 
 186         Frame target = (Frame)this.target;
 187 
 188         if (target.getTitle() != null) {
 189             setTitle(target.getTitle());
 190         }
 191         setResizable(target.isResizable());
 192         setState(target.getExtendedState());
 193     }
 194 
 195     private native static int getSysMenuHeight();
 196 
 197     native void pSetIMMOption(String option);
 198     void notifyIMMOptionChange(){
 199       InputMethodManager.getInstance().notifyChangeRequest((Component)target);
 200     }
 201 
 202     public void setBoundsPrivate(int x, int y, int width, int height) {
 203         setBounds(x, y, width, height, SET_BOUNDS);
 204     }
 205     public Rectangle getBoundsPrivate() {
 206         return getBounds();
 207     }
 208 }