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