1 /*
   2  * Copyright 1996-2008 Sun Microsystems, Inc.  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.  Sun designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  22  * CA 95054 USA or visit www.sun.com if you need additional information or
  23  * have any 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             setMaximizedBounds(b.x, b.y, b.width, b.height);
  83         }
  84     }
  85 
  86     @Override
  87     boolean isTargetUndecorated() {
  88         return ((Frame)target).isUndecorated();
  89     }
  90 
  91     public void reshape(int x, int y, int width, int height) {
  92         if (((Frame)target).isUndecorated()) {
  93             super.reshape(x, y, width, height);
  94         } else {
  95             reshapeFrame(x, y, width, height);
  96         }
  97     }
  98 
  99     public Dimension getMinimumSize() {
 100         Dimension d = new Dimension();
 101         if (!((Frame)target).isUndecorated()) {
 102             d.setSize(getSysMinWidth(), getSysMinHeight());
 103         }
 104         if (((Frame)target).getMenuBar() != null) {
 105             d.height += getSysMenuHeight();
 106         }
 107         return d;
 108     }
 109 
 110     // Note: Because this method calls resize(), which may be overridden
 111     // by client code, this method must not be executed on the toolkit
 112     // thread.
 113     public void setMenuBar(MenuBar mb) {
 114         WMenuBarPeer mbPeer = (WMenuBarPeer) WToolkit.targetToPeer(mb);
 115         setMenuBar0(mbPeer);
 116         updateInsets(insets_);
 117     }
 118 
 119     // Note: Because this method calls resize(), which may be overridden
 120     // by client code, this method must not be executed on the toolkit
 121     // thread.
 122     private native void setMenuBar0(WMenuBarPeer mbPeer);
 123 
 124     // Toolkit & peer internals
 125 
 126     WFramePeer(Frame target) {
 127         super(target);
 128 
 129         InputMethodManager imm = InputMethodManager.getInstance();
 130         String menuString = imm.getTriggerMenuString();
 131         if (menuString != null)
 132         {
 133           pSetIMMOption(menuString);
 134         }
 135     }
 136 
 137     native void createAwtFrame(WComponentPeer parent);
 138     void create(WComponentPeer parent) {
 139         preCreate(parent);
 140         createAwtFrame(parent);
 141     }
 142 
 143     void initialize() {
 144         super.initialize();
 145 
 146         Frame target = (Frame)this.target;
 147 
 148         if (target.getTitle() != null) {
 149             setTitle(target.getTitle());
 150         }
 151         setResizable(target.isResizable());
 152         setState(target.getExtendedState());
 153     }
 154 
 155     private native static int getSysMenuHeight();
 156 
 157     native void pSetIMMOption(String option);
 158     void notifyIMMOptionChange(){
 159       InputMethodManager.getInstance().notifyChangeRequest((Component)target);
 160     }
 161 
 162     public void setBoundsPrivate(int x, int y, int width, int height) {
 163         setBounds(x, y, width, height, SET_BOUNDS);
 164     }
 165     public Rectangle getBoundsPrivate() {
 166         return getBounds();
 167     }
 168 }