1 /*
2  * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
3  * Copyright (c) 2010 JogAmp Community. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * - Redistribution of source code must retain the above copyright
10  *   notice, this list of conditions and the following disclaimer.
11  *
12  * - Redistribution in binary form must reproduce the above copyright
13  *   notice, this list of conditions and the following disclaimer in the
14  *   documentation and/or other materials provided with the distribution.
15  *
16  * Neither the name of Sun Microsystems, Inc. or the names of
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * This software is provided "AS IS," without a warranty of any kind. ALL
21  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
22  * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
23  * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
24  * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
25  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
26  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
27  * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
28  * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
29  * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
30  * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
31  * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32  *
33  * You acknowledge that this software is not designed or intended for use
34  * in the design, construction, operation or maintenance of any nuclear
35  * facility.
36  *
37  * Sun gratefully acknowledges that this software was originally authored
38  * and developed by Kenneth Bradley Russell and Christopher John Kline.
39  */
40 
41 package com.jogamp.nativewindow;
42 
43 import com.jogamp.nativewindow.util.InsetsImmutable;
44 import com.jogamp.nativewindow.util.Point;
45 
46 /**
47  * Extend the {@link NativeSurface} interface with windowing
48  * information such as {@link #getWindowHandle() window-handle},
49  * {@link #getWidth() window-size} and {@link #getX() window-position}.
50  * <p>
51  * All values of this interface are represented in window units, if not stated otherwise.
52  * See {@link NativeSurface}.
53  * </p>
54  *
55  * <a name="coordinateSystem"><h5>Coordinate System</h5></a>
56  * <p>
57  *  <ul>
58  *      <li>Abstract screen space has it's origin in the top-left corner, and may not be at 0/0.</li>
59  *      <li>Window origin is in it's top-left corner, see {@link #getX()} and {@link #getY()}. </li>
60  *      <li>Window client-area excludes {@link #getInsets() insets}, i.e. window decoration.</li>
61  *      <li>Window origin is relative to it's parent window if exist, or the screen position (top-level).</li>
62  *  </ul>
63  * </p>
64  * <p>
65  * A window toolkit such as the AWT may either implement this interface
66  * directly with one of its components, or provide and register an
67  * implementation of {@link NativeWindowFactory NativeWindowFactory}
68  * which can create NativeWindow objects for its components.
69  * </p>
70  */
71 public interface NativeWindow extends NativeSurface, NativeSurfaceHolder {
72 
73   /**
74    * {@inheritDoc}
75    * <p>
76    * Returns this instance, which <i>is-a</i> {@link NativeSurface}.
77    * </p>
78    */
79   @Override
getNativeSurface()80   public NativeSurface getNativeSurface();
81 
82   /**
83    * Destroys this window incl. releasing all related resources.
84    */
destroy()85   public void destroy();
86 
87   /**
88    * @return The parent NativeWindow, or null if this NativeWindow is top level.
89    */
getParent()90   public NativeWindow getParent();
91 
92   /**
93    * Returns the window handle for this NativeWindow. <P>
94    *
95    * The window handle shall reflect the platform one
96    * for all window related operations, e.g. open, close, resize. <P>
97    *
98    * On X11 this returns an entity of type Window. <BR>
99    * On Microsoft Windows this returns an entity of type HWND.
100    */
getWindowHandle()101   public long getWindowHandle();
102 
103   /**
104    * Returns the insets defined as the width and height of the window decoration
105    * on the left, right, top and bottom in window units.
106    * <p>
107    * Insets are zero if the window is undecorated, including child windows.
108    * </p>
109    *
110    * <p>
111    * Insets are available only after the native window has been created,
112    * ie. the native window has been made visible.<br>
113    *
114    * The top-level window area's top-left corner is located at
115    * <pre>
116    *   {@link #getX()} - getInsets().{@link InsetsImmutable#getLeftWidth() getLeftWidth()}
117    *   {@link #getY()} - getInsets().{@link InsetsImmutable#getTopHeight() getTopHeight()}
118    * </pre>
119    *
120    * The top-level window size is
121    * <pre>
122    *   {@link #getWidth()}  + getInsets().{@link InsetsImmutable#getTotalWidth() getTotalWidth()}
123    *   {@link #getHeight()} + getInsets().{@link InsetsImmutable#getTotalHeight() getTotalHeight()}
124    * </pre>
125    *
126    * @return insets
127    */
getInsets()128   public InsetsImmutable getInsets();
129 
130   /** Returns the current x position of this window, relative to it's parent. */
131 
132   /**
133    * Returns the x position of the top-left corner
134    * of the client area relative to it's parent in window units.
135    * <p>
136    * If no parent exist (top-level window), this coordinate equals the screen coordinate.
137    * </p>
138    * <p>
139    * Since the position reflects the client area, it does not include the insets.
140    * </p>
141    * <p>
142    * See <a href="#coordinateSystem"> Coordinate System</a>.
143    * </p>
144    * @see #getInsets()
145    * @see #getLocationOnScreen(Point)
146    */
getX()147   public int getX();
148 
149   /**
150    * Returns the current y position of the top-left corner
151    * of the client area relative to it's parent in window units.
152    * <p>
153    * If no parent exist (top-level window), this coordinate equals the screen coordinate.
154    * </p>
155    * <p>
156    * Since the position reflects the client area, it does not include the insets.
157    * </p>
158    * <p>
159    * See <a href="#coordinateSystem"> Coordinate System</a>.
160    * </p>
161    * @see #getInsets()
162    * @see #getLocationOnScreen(Point)
163    */
getY()164   public int getY();
165 
166   /**
167    * Returns the width of the client area excluding insets (window decorations) in window units.
168    * @return width of the client area in window units
169    * @see NativeSurface#getSurfaceWidth()
170    */
getWidth()171   public int getWidth();
172 
173   /**
174    * Returns the height of the client area excluding insets (window decorations) in window units.
175    * @return height of the client area in window units
176    * @see NativeSurface#getSurfaceHeight()
177    */
getHeight()178   public int getHeight();
179 
180   /**
181    * Returns the window's top-left client-area position in the screen.
182    * <p>
183    * If {@link Point} is not <code>null</code>, it is translated about the resulting screen position
184    * and returned.
185    * </p>
186    * <p>
187    * See <a href="#coordinateSystem"> Coordinate System</a>.
188    * </p>
189    * <p>
190    * Since the position reflects the client area, it does not include the insets.
191    * </p>
192    * @param point Optional {@link Point} storage.
193    *              If not null, <code>null</code>, it is translated about the resulting screen position
194    *              and returned.
195    * @see #getX()
196    * @see #getY()
197    * @see #getInsets()
198    */
getLocationOnScreen(Point point)199   public Point getLocationOnScreen(Point point);
200 
201   /** Returns true if this native window owns the focus, otherwise false. */
hasFocus()202   boolean hasFocus();
203 
204 }
205