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         setPlatformScale(screen.getUIScale());
  50         setRenderScale(screen.getRenderScale());
  51     }
  52     protected MacWindow(long parent) {
  53         super(parent);
  54     }
  55 
  56     @Override
  57     protected void setScreen(Screen screen) {
  58         // SceneState will be called to update with new scale values
  59         // before we return from super.setScreen()...
  60         setRenderScale(screen.getUIScale());
  61         setRenderScale(screen.getRenderScale());
  62         super.setScreen(screen);
  63     }
  64 
  65     @Override
  66     public float getOutputScale() {
  67         return getRenderScale();
  68     }
  69 
  70     @Override native protected long _createWindow(long ownerPtr, long screenPtr, int mask);
  71     @Override native protected long _createChildWindow(long parent);
  72     @Override native protected boolean _close(long ptr);
  73     @Override native protected boolean _setView(long ptr, View view);
  74     @Override native protected boolean _setMenubar(long ptr, long menubarPtr);
  75     @Override native protected boolean _minimize(long ptr, boolean minimize);
  76     @Override native protected boolean _maximize(long ptr, boolean maximize, boolean wasMaximized);
  77     @Override native protected void _setBounds(long ptr, int x, int y, boolean xSet, boolean ySet, int w, int h, int cw, int ch, float xGravity, float yGravity);
  78     @Override native protected boolean _setVisible(long ptr, boolean visible);
  79     @Override native protected boolean _setResizable(long ptr, boolean resizable);
  80 
  81     native private boolean _requestFocus(long ptr);
  82     @Override protected boolean _requestFocus(long ptr, int event) {
  83         //TODO: provide reasonable impl for all possible events
  84         if (event != WindowEvent.FOCUS_LOST) {
  85             return _requestFocus(ptr);
  86         }
  87         return false;
  88     }
  89 
  90     @Override native protected void _setFocusable(long ptr, boolean isFocusable);
  91     @Override native protected boolean _setTitle(long ptr, String title);
  92     @Override native protected void _setLevel(long ptr, int level);
  93     @Override native protected void _setAlpha(long ptr, float alpha);
  94     @Override native protected boolean _setBackground(long ptr, float r, float g, float b);
  95     @Override native protected void _setEnabled(long ptr, boolean enabled);
  96     @Override native protected boolean _setMinimumSize(long ptr, int width, int height);
  97     @Override native protected boolean _setMaximumSize(long ptr, int width, int height);
  98     @Override native protected void _setIcon(long ptr, Pixels pixels);
  99     @Override native protected void _toFront(long ptr);
 100     @Override native protected void _toBack(long ptr);
 101     @Override native protected void _enterModal(long ptr);
 102     @Override native protected void _enterModalWithWindow(long dialog, long window);
 103     @Override native protected void _exitModal(long ptr);
 104 
 105     @Override native protected boolean _grabFocus(long ptr);
 106     @Override native protected void _ungrabFocus(long ptr);
 107 
 108     @Override native protected int _getEmbeddedX(long ptr);
 109     @Override native protected int _getEmbeddedY(long ptr);
 110 
 111     @Override
 112     protected void _setCursor(long ptr, Cursor cursor) {
 113         ((MacCursor)cursor).set();
 114     }
 115 
 116     @Override
 117     public void dispatchNpapiEvent(Map eventInfo) {
 118         NpapiEvent.dispatchCocoaNpapiEvent(this, eventInfo);
 119     }
 120 
 121     @Override
 122     protected void _requestInput(long ptr, String text, int type, double width, double height,
 123                                     double Mxx, double Mxy, double Mxz, double Mxt,
 124                                     double Myx, double Myy, double Myz, double Myt,
 125                                     double Mzx, double Mzy, double Mzz, double Mzt) {
 126         throw new UnsupportedOperationException("Not supported yet.");
 127     }
 128 
 129     @Override
 130     protected void _releaseInput(long ptr) {
 131         throw new UnsupportedOperationException("Not supported yet.");
 132     }
 133 }
 134