1 /*
   2  * Copyright (c) 2012, 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 
  26 package com.sun.glass.ui.lens;
  27 
  28 import java.util.Map;
  29 
  30 import com.sun.glass.ui.Pixels;
  31 import com.sun.glass.ui.View;
  32 import java.nio.ByteBuffer;
  33 import java.nio.IntBuffer;
  34 import java.nio.Buffer;
  35 
  36 import com.sun.glass.events.ViewEvent;
  37 
  38 final class LensView extends View {
  39 
  40     protected LensView() {
  41         super();
  42     }
  43 
  44     // Constants
  45     private static long multiClickTime =  300;
  46     private static int multiClickMaxX = LensTouchInputSupport.touchTapRadius;
  47     private static int multiClickMaxY = LensTouchInputSupport.touchTapRadius;
  48 
  49     // view variables
  50     private int x;
  51     private int y;
  52     private long nativePtr;
  53 
  54     protected static long _getMultiClickTime() {
  55         if (multiClickTime == -1) {
  56             //multiClickTime = _getMultiClickTime_impl();
  57             //currently calling a native function is meaningless
  58             multiClickTime = 300;
  59         }
  60         return multiClickTime;
  61     }
  62 
  63     protected static int _getMultiClickMaxX() {
  64         if (multiClickMaxX == -1) {
  65             //multiClickMaxX = _getMultiClickMaxX_impl();
  66             //currently calling a native function is meaningless
  67             multiClickMaxX = 2;
  68         }
  69         return multiClickMaxX;
  70     }
  71 
  72     protected static int _getMultiClickMaxY() {
  73         if (multiClickMaxY == -1) {
  74             //multiClickMaxY = _getMultiClickMaxY_impl();
  75             //currently calling a native function is meaningless
  76             multiClickMaxY = 2;
  77         }
  78         return multiClickMaxY;
  79     }
  80 
  81     native private void _paintInt(long ptr, int w, int h, IntBuffer ints,
  82                                   int[] array, int offset);
  83     native private void _paintByte(long ptr, int w, int h, ByteBuffer bytes,
  84                                    byte[] array, int offset);
  85     native private void _paintIntDirect(long ptr, int w, int h, Buffer buffer);
  86 
  87     @Override
  88     protected void _enableInputMethodEvents(long ptr, boolean enable) {
  89     }
  90 
  91 
  92 
  93     @Override
  94     protected long _getNativeView(long ptr) {
  95         //this method is a Windows hack, see View.java for more details
  96         // we just ignore it
  97         return ptr;
  98     }
  99 
 100     @Override
 101     protected int _getX(long ptr) {
 102         return x;
 103     }
 104 
 105     @Override
 106     protected int _getY(long ptr) {
 107         return y;
 108     }
 109 
 110 
 111 
 112     @Override
 113     protected void _scheduleRepaint(long ptr) {
 114         // native code is there but does nothing yet
 115         //throw new UnsupportedOperationException("Not supported yet.");
 116         LensLogger.getLogger().info("Ignoring repaint");
 117     }
 118 
 119 
 120 
 121     @Override protected void _uploadPixels(long nativeViewPtr, Pixels pixels) {
 122         if (getWindow() != null) {
 123             Buffer data = pixels.getPixels();
 124             int width = pixels.getWidth();
 125             int height = pixels.getHeight();
 126 
 127             if (data.isDirect() == true) {
 128                 _paintIntDirect(nativeViewPtr, width, height, data);
 129             } else if (data.hasArray() == true) {
 130                 if (pixels.getBytesPerComponent() == 1) {
 131                     ByteBuffer bytes = (ByteBuffer)data;
 132                     _paintByte(nativeViewPtr, width, height, bytes,
 133                                bytes.array(), bytes.arrayOffset());
 134                 } else {
 135                     IntBuffer ints = (IntBuffer)data;
 136                     int[] intArray = ints.array();
 137 
 138                     _paintInt(nativeViewPtr, width, height, ints,
 139                               intArray, ints.arrayOffset());
 140                 }
 141             }
 142         }
 143     }
 144 
 145     /**
 146      * Events
 147      */
 148 
 149     protected void _notifyMove(int x, int y) {
 150         // used to update x,y for _getX(), _getY()
 151         this.x = x;
 152         this.y = y;
 153         notifyView(ViewEvent.MOVE);
 154     }
 155 
 156     protected void _notifyKey(int type, int keyCode, char[] keyChars,
 157                               int modifiers) {
 158         notifyKey(type, keyCode, keyChars, modifiers);
 159     }
 160 
 161     protected void _notifyMouse(int type, int button,
 162                                 int x, int y, int xAbs, int yAbs, int modifiers,
 163                                 boolean isPopupTrigger, boolean isSynthesized) {
 164         notifyMouse(type, button, x, y, xAbs, yAbs, modifiers, isPopupTrigger,
 165                     isSynthesized);
 166     }
 167 
 168     protected void _notifyScroll(int x, int y, int xAbs, int yAbs,
 169                                  double deltaX, double deltaY, int modifiers,
 170                                  int lines, int chars,
 171                                  int defaultLines, int defaultChars,
 172                                  double xMultiplier, double yMultiplier) {
 173         notifyScroll(x, y, xAbs, yAbs, deltaX, deltaY,
 174                      modifiers, lines, chars,
 175                      defaultLines, defaultChars, xMultiplier, yMultiplier);
 176     }
 177 
 178     protected void _notifyRepaint(int x, int y, int width, int height) {
 179         notifyRepaint(x, y, width, height);
 180     }
 181 
 182     protected void _notifyResize(int width, int height) {
 183         notifyResize(width, height);
 184     }
 185 
 186     protected void _notifyViewEvent(int viewEvent) {
 187         notifyView(viewEvent);
 188     }
 189 
 190     //DnD
 191     protected void _notifyDragEnter(int x, int y, int absx, int absy, int recommendedDropAction) {
 192         notifyDragEnter(x, y, absx, absy, recommendedDropAction);
 193     }
 194     protected void _notifyDragLeave() {
 195         notifyDragLeave();
 196     }
 197     protected void _notifyDragDrop(int x, int y, int absx, int absy, int recommendedDropAction) {
 198         notifyDragDrop(x, y, absx, absy, recommendedDropAction);
 199     }
 200     protected void _notifyDragOver(int x, int y, int absx, int absy, int recommendedDropAction) {
 201         notifyDragOver(x, y, absx, absy, recommendedDropAction);
 202     }
 203 
 204     //Menu event - i.e context menu hint (usually mouse right click)
 205     protected void _notifyMenu(int x, int y, int xAbs, int yAbs, boolean isKeyboardTrigger) {
 206         notifyMenu(x, y, xAbs, yAbs, isKeyboardTrigger);
 207     }
 208 
 209     @Override
 210     protected int _getNativeFrameBuffer(long ptr) {
 211         return 0;
 212     }
 213 
 214     /**
 215      * Native methods
 216      */
 217 
 218     @Override
 219     protected long _create(Map caps) {
 220         this.nativePtr = _createNativeView(caps);
 221         return this.nativePtr;
 222     }
 223 
 224     private native long _createNativeView(Map caps);
 225 
 226     /**
 227     * Assuming this is used to lock the surface for painting
 228     */
 229     @Override
 230     native protected void _begin(long ptr);
 231 
 232     /**
 233      * Assuming this is used to unlock the surface after painting is
 234      * done
 235      */
 236     @Override
 237     native protected  void _end(long ptr);
 238 
 239 
 240     @Override
 241     native protected void _setParent(long ptr, long parentPtr);
 242 
 243     @Override
 244     native protected boolean _close(long ptr);
 245 
 246     @Override
 247     native protected boolean _enterFullscreen(long ptr, boolean animate,
 248                                               boolean keepRatio,
 249                                               boolean hideCursor);
 250 
 251     @Override
 252     native protected void _exitFullscreen(long ptr, boolean animate);
 253 
 254     @Override
 255     public String toString() {
 256         return "LensView[nativePtr=0x" + Long.toHexString(nativePtr) + "]";
 257     }
 258 
 259 }