1 /* 2 * Copyright (c) 2011, 2015, 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 com.sun.glass.ui.mac; 26 27 import com.sun.glass.events.WindowEvent; 28 import com.sun.glass.events.mac.NpapiEvent; 29 import com.sun.glass.ui.Cursor; 30 import com.sun.glass.ui.Pixels; 31 import com.sun.glass.ui.Screen; 32 import com.sun.glass.ui.View; 33 import com.sun.glass.ui.Window; 34 35 import java.util.Map; 36 37 /** 38 * MacOSX platform implementation class for Window. 39 */ 40 final class MacWindow extends Window { 41 42 private native static void _initIDs(); 43 static { 44 _initIDs(); 45 } 46 47 protected MacWindow(Window owner, Screen screen, int styleMask) { 48 super(owner, screen, styleMask); 49 } 50 protected MacWindow(long parent) { 51 super(parent); 52 } 53 54 @Override 55 protected void setScreen(Screen screen) { 56 // SceneState will be called to update with new scale values 57 // before we return from super.setScreen()... 58 super.setScreen(screen); 59 notifyScaleChanged(1.0f, 1.0f, 60 screen.getRecommendedOutputScaleX(), 61 screen.getRecommendedOutputScaleY()); 62 } 63 64 @Override native protected long _createWindow(long ownerPtr, long screenPtr, int mask); 65 @Override native protected long _createChildWindow(long parent); 66 @Override native protected boolean _close(long ptr); 67 @Override native protected boolean _setView(long ptr, View view); 68 @Override native protected boolean _setMenubar(long ptr, long menubarPtr); 69 @Override native protected boolean _minimize(long ptr, boolean minimize); 70 @Override native protected boolean _maximize(long ptr, boolean maximize, boolean wasMaximized); 71 @Override protected void _setBounds(long ptr, 72 int x, int y, boolean xSet, boolean ySet, 73 int w, int h, int cw, int ch, 74 float xGravity, float yGravity) 75 { 76 float sx = getPlatformScaleX(); 77 float sy = getPlatformScaleY(); 78 if (xSet) x = Math.round( x / sx); 79 if (ySet) y = Math.round( y / sy); 80 if ( w > 0) w = Math.round( w / sx); 81 if ( h > 0) h = Math.round( h / sy); 82 if (cw > 0) cw = Math.round(cw / sx); 83 if (ch > 0) ch = Math.round(ch / sy); 84 _setBounds2(ptr, x, y, xSet, ySet, w, h, cw, ch, xGravity, yGravity); 85 } 86 native protected void _setBounds2(long ptr, int x, int y, boolean xSet, boolean ySet, int w, int h, int cw, int ch, float xGravity, float yGravity); 87 @Override native protected boolean _setVisible(long ptr, boolean visible); 88 @Override native protected boolean _setResizable(long ptr, boolean resizable); 89 90 native private boolean _requestFocus(long ptr); 91 @Override protected boolean _requestFocus(long ptr, int event) { 92 //TODO: provide reasonable impl for all possible events 93 if (event != WindowEvent.FOCUS_LOST) { 94 return _requestFocus(ptr); 95 } 96 return false; 97 } 98 99 @Override native protected void _setFocusable(long ptr, boolean isFocusable); 100 @Override native protected boolean _setTitle(long ptr, String title); 101 @Override native protected void _setLevel(long ptr, int level); 102 @Override native protected void _setAlpha(long ptr, float alpha); 103 @Override native protected boolean _setBackground(long ptr, float r, float g, float b); 104 @Override native protected void _setEnabled(long ptr, boolean enabled); 105 @Override native protected boolean _setMinimumSize(long ptr, int width, int height); 106 @Override native protected boolean _setMaximumSize(long ptr, int width, int height); 107 @Override native protected void _setIcon(long ptr, Pixels pixels); 108 @Override native protected void _toFront(long ptr); 109 @Override native protected void _toBack(long ptr); 110 @Override native protected void _enterModal(long ptr); 111 @Override native protected void _enterModalWithWindow(long dialog, long window); 112 @Override native protected void _exitModal(long ptr); 113 114 @Override native protected boolean _grabFocus(long ptr); 115 @Override native protected void _ungrabFocus(long ptr); 116 117 @Override native protected int _getEmbeddedX(long ptr); 118 @Override native protected int _getEmbeddedY(long ptr); 119 120 @Override 121 protected void notifyResize(int type, int width, int height) { 122 width = Math.round( width * getPlatformScaleX()); 123 height = Math.round(height * getPlatformScaleY()); 124 super.notifyResize(type, width, height); 125 } 126 127 @Override 128 protected void _setCursor(long ptr, Cursor cursor) { 129 ((MacCursor)cursor).set(); 130 } 131 132 @Override 133 public void dispatchNpapiEvent(Map eventInfo) { 134 NpapiEvent.dispatchCocoaNpapiEvent(this, eventInfo); 135 } 136 137 @Override 138 protected void _requestInput(long ptr, String text, int type, double width, double height, 139 double Mxx, double Mxy, double Mxz, double Mxt, 140 double Myx, double Myy, double Myz, double Myt, 141 double Mzx, double Mzy, double Mzz, double Mzt) { 142 throw new UnsupportedOperationException("Not supported yet."); 143 } 144 145 @Override 146 protected void _releaseInput(long ptr) { 147 throw new UnsupportedOperationException("Not supported yet."); 148 } 149 } 150