1 /*
   2  * Copyright (c) 2010, 2013, 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.win;
  26 
  27 import com.sun.glass.ui.Cursor;
  28 import com.sun.glass.ui.Pixels;
  29 import com.sun.glass.ui.Screen;
  30 import com.sun.glass.ui.View;
  31 import com.sun.glass.ui.Window;
  32 import java.security.AccessController;
  33 import java.security.PrivilegedAction;
  34 
  35 /**
  36  * MS Windows platform implementation class for Window.
  37  */
  38 class WinWindow extends Window {
  39 
  40     private native static void _initIDs();
  41     static {
  42         _initIDs();
  43     }
  44 
  45     protected WinWindow(Window owner, Screen screen, int styleMask) {
  46         super(owner, screen, styleMask);
  47     }
  48     protected WinWindow(long parent) {
  49         super(parent);
  50     }
  51 
  52     @Override native protected long _createWindow(long ownerPtr, long screenPtr, int mask);
  53     @Override native protected long _createChildWindow(long parent);
  54     @Override native protected boolean _close(long ptr);
  55     @Override native protected boolean _setView(long ptr, View view);
  56     @Override native protected boolean _setMenubar(long ptr, long menubarPtr);
  57     @Override native protected boolean _minimize(long ptr, boolean minimize);
  58     @Override native protected boolean _maximize(long ptr, boolean maximize, boolean wasMaximized);
  59     @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);
  60     @Override native protected boolean _setVisible(long ptr, boolean visible);
  61     @Override native protected boolean _setResizable(long ptr, boolean resizable);
  62     @Override native protected boolean _requestFocus(long ptr, int event);
  63     @Override native protected void _setFocusable(long ptr, boolean isFocusable);
  64     @Override native protected boolean _setTitle(long ptr, String title);
  65     @Override native protected void _setLevel(long ptr, int level);
  66     @Override native protected void _setAlpha(long ptr, float alpha);
  67     @Override native protected boolean _setBackground(long ptr, float r, float g, float b);
  68     @Override native protected void _setEnabled(long ptr, boolean enabled);
  69     @Override native protected boolean _setMinimumSize(long ptr, int width, int height);
  70     @Override native protected boolean _setMaximumSize(long ptr, int width, int height);
  71     @Override native protected void _setIcon(long ptr, Pixels pixels);
  72     @Override native protected void _toFront(long ptr);
  73     @Override native protected void _toBack(long ptr);
  74     @Override native protected void _enterModal(long ptr);
  75     @Override native protected void _enterModalWithWindow(long dialog, long window);
  76     @Override native protected void _exitModal(long ptr);
  77     @Override native protected boolean _grabFocus(long ptr);
  78     @Override native protected void _ungrabFocus(long ptr);
  79     @Override native protected int _getEmbeddedX(long ptr);
  80     @Override native protected int _getEmbeddedY(long ptr);
  81     @Override native protected void _setCursor(long ptr, Cursor cursor);
  82     @Override native protected void _setUpdatesCursor(long prt, boolean updatesCursor);
  83 
  84     @Override
  85     protected void _requestInput(long ptr, String text, int type, double width, double height, 
  86                                     double Mxx, double Mxy, double Mxz, double Mxt,
  87                                     double Myx, double Myy, double Myz, double Myt, 
  88                                     double Mzx, double Mzy, double Mzz, double Mzt) {
  89         throw new UnsupportedOperationException("Not supported yet.");
  90     }
  91 
  92     @Override
  93     protected void _releaseInput(long ptr) {
  94         throw new UnsupportedOperationException("Not supported yet.");
  95     }
  96     
  97 
  98     private boolean deferredClosing = false;
  99     private boolean closingRequested = false;
 100 
 101     /** 
 102      * Defer destroying the window to avoid a crash when using a native dialog
 103      * (like a file chooser).
 104      */
 105     void setDeferredClosing(boolean dc) {
 106         deferredClosing = dc;
 107         if (!deferredClosing && closingRequested) {
 108             close();
 109         }
 110     }
 111 
 112     @Override public void close() {
 113         if (!deferredClosing) {
 114             super.close();
 115         } else {
 116             closingRequested = true;
 117             setVisible(false);
 118         }
 119     }
 120 }