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.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 @Override 45 public native void setState(int state); 46 @Override 47 public native int getState(); 48 49 // sync target and peer 50 public void setExtendedState(int state) { 51 AWTAccessor.getFrameAccessor().setExtendedState((Frame)target, state); 52 } 53 public int getExtendedState() { 54 return AWTAccessor.getFrameAccessor().getExtendedState((Frame)target); 55 } 56 57 // Convenience methods to save us from trouble of extracting 58 // Rectangle fields in native code. 59 private native void setMaximizedBounds(int x, int y, int w, int h); 60 private native void clearMaximizedBounds(); 61 62 private static final boolean keepOnMinimize = "true".equals( 63 AccessController.doPrivileged( 64 new GetPropertyAction( 65 "sun.awt.keepWorkingSetOnMinimize"))); 66 67 @Override 68 public void setMaximizedBounds(Rectangle b) { 69 if (b == null) { 70 clearMaximizedBounds(); 71 } else { 72 Rectangle adjBounds = (Rectangle)b.clone(); 73 adjustMaximizedBounds(adjBounds); 74 setMaximizedBounds(adjBounds.x, adjBounds.y, adjBounds.width, adjBounds.height); 75 } 76 } 77 78 /** 79 * The incoming bounds describe the maximized size and position of the 80 * window on the monitor that displays the window. But the window manager 81 * expects that the bounds are based on the size and position of the 82 * primary monitor, even if the window ultimately maximizes onto a 83 * secondary monitor. And the window manager adjusts these values to 84 * compensate for differences between the primary monitor and the monitor 85 * that displays the window. 86 * The method translates the incoming bounds to the values acceptable 87 * by the window manager. For more details, please refer to 6699851. 88 */ 89 private void adjustMaximizedBounds(Rectangle b) { 90 GraphicsConfiguration currentDevGC = getGraphicsConfiguration(); 91 92 GraphicsDevice primaryDev = GraphicsEnvironment 93 .getLocalGraphicsEnvironment().getDefaultScreenDevice(); 94 GraphicsConfiguration primaryDevGC = primaryDev.getDefaultConfiguration(); 95 96 if (currentDevGC != null && currentDevGC != primaryDevGC) { 97 Rectangle currentDevBounds = currentDevGC.getBounds(); 98 Rectangle primaryDevBounds = primaryDevGC.getBounds(); 99 100 boolean isCurrentDevLarger = 101 ((currentDevBounds.width - primaryDevBounds.width > 0) || 102 (currentDevBounds.height - primaryDevBounds.height > 0)); 103 104 // the window manager doesn't seem to compensate for differences when 105 // the primary monitor is larger than the monitor that display the window 106 if (isCurrentDevLarger) { 107 b.width -= (currentDevBounds.width - primaryDevBounds.width); 108 b.height -= (currentDevBounds.height - primaryDevBounds.height); 109 } 110 } 111 } 112 113 @Override 114 public boolean updateGraphicsData(GraphicsConfiguration gc) { 115 boolean result = super.updateGraphicsData(gc); 116 Rectangle bounds = AWTAccessor.getFrameAccessor(). 117 getMaximizedBounds((Frame)target); 118 if (bounds != null) { 119 setMaximizedBounds(bounds); 120 } 121 return result; 122 } 123 124 @Override 125 boolean isTargetUndecorated() { 126 return ((Frame)target).isUndecorated(); 127 } 128 129 @Override 130 public void reshape(int x, int y, int width, int height) { 131 if (((Frame)target).isUndecorated()) { 132 super.reshape(x, y, width, height); 133 } else { 134 reshapeFrame(x, y, width, height); 135 } 136 } 137 138 @Override 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 @Override 154 public void setMenuBar(MenuBar mb) { 155 WMenuBarPeer mbPeer = (WMenuBarPeer) WToolkit.targetToPeer(mb); 156 if (mbPeer != null) { 157 if (mbPeer.framePeer != this) { 158 mb.removeNotify(); 159 mb.addNotify(); 160 mbPeer = (WMenuBarPeer) WToolkit.targetToPeer(mb); 161 if (mbPeer != null && mbPeer.framePeer != this) { 162 throw new IllegalStateException("Wrong parent peer"); 163 } 164 } 165 if (mbPeer != null) { 166 addChildPeer(mbPeer); 167 } 168 } 169 setMenuBar0(mbPeer); 170 updateInsets(insets_); 171 } 172 173 // Note: Because this method calls resize(), which may be overridden 174 // by client code, this method must not be executed on the toolkit 175 // thread. 176 private native void setMenuBar0(WMenuBarPeer mbPeer); 177 178 // Toolkit & peer internals 179 180 WFramePeer(Frame target) { 181 super(target); 182 183 InputMethodManager imm = InputMethodManager.getInstance(); 184 String menuString = imm.getTriggerMenuString(); 185 if (menuString != null) 186 { 187 pSetIMMOption(menuString); 188 } 189 } 190 191 native void createAwtFrame(WComponentPeer parent); 192 @Override 193 void create(WComponentPeer parent) { 194 preCreate(parent); 195 createAwtFrame(parent); 196 } 197 198 @Override 199 void initialize() { 200 super.initialize(); 201 202 Frame target = (Frame)this.target; 203 204 if (target.getTitle() != null) { 205 setTitle(target.getTitle()); 206 } 207 setResizable(target.isResizable()); 208 setState(target.getExtendedState()); 209 } 210 211 private static native int getSysMenuHeight(); 212 213 native void pSetIMMOption(String option); 214 void notifyIMMOptionChange(){ 215 InputMethodManager.getInstance().notifyChangeRequest((Component)target); 216 } 217 218 @Override 219 public void setBoundsPrivate(int x, int y, int width, int height) { 220 setBounds(x, y, width, height, SET_BOUNDS); 221 } 222 @Override 223 public Rectangle getBoundsPrivate() { 224 return getBounds(); 225 } 226 227 // TODO: implement it in peers. WLightweightFramePeer may implement lw version. 228 @Override 229 public void emulateActivation(boolean activate) { 230 synthesizeWmActivate(activate); 231 } 232 233 private native void synthesizeWmActivate(boolean activate); 234 }