001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Mikhail Danilov
019: * @version $Revision$
020: */package org.apache.harmony.awt.wtk;
021:
022: import java.awt.Insets;
023: import java.awt.Rectangle;
024: import java.awt.Point;
025: import java.awt.event.KeyEvent;
026:
027: import org.apache.harmony.awt.gl.MultiRectArea;
028:
029: /**
030: * The interface describing cross-platform translation of system
031: * messages.
032: *
033: * <p/>Some messages can appear only on specific platform,
034: * but they still can have cross-platform interpretation if the
035: * application should be aware of them and can react using
036: * cross-platform API.
037: *
038: */
039: public abstract class NativeEvent {
040:
041: /**
042: * Message has no common cross-platform
043: * interpretation and should be skipped.
044: */
045: public static final int ID_PLATFORM = 0;
046:
047: /**
048: * Window bounds have changed.
049: */
050: public static final int ID_BOUNDS_CHANGED = -1;
051:
052: /**
053: * Window decoration size has changed.
054: */
055: public static final int ID_INSETS_CHANGED = -2;
056:
057: /**
058: * Window was just created (WM_CREATE on Windows)
059: */
060: public static final int ID_CREATED = -3;
061:
062: /**
063: * Mouse grab was canceled by the native system
064: */
065: public static final int ID_MOUSE_GRAB_CANCELED = -4;
066:
067: /**
068: * System color scheme or visual theme was changed
069: */
070: public static final int ID_THEME_CHANGED = -5;
071:
072: protected long windowId;
073: protected int eventId;
074: protected long otherWindowId;
075:
076: protected Point screenPos;
077: protected Point localPos;
078: protected Rectangle windowRect;
079:
080: protected int modifiers;
081: protected int mouseButton;
082: protected int wheelRotation;
083:
084: protected KeyInfo keyInfo = new KeyInfo();
085:
086: protected int windowState = -1;
087: protected long time;
088:
089: /**
090: * Returns the system window id of the event recipient.
091: * @return HWND on Windows, xwindnow on X
092: */
093: public long getWindowId() {
094: return windowId;
095: }
096:
097: /**
098: * Returns cross-platform event id
099: * should be one of ID_* constants or
100: * id constants from java.awt.AWTEvent subclasess
101: * @return cross-platform event id
102: */
103: public int getEventId() {
104: return eventId;
105: }
106:
107: /**
108: * Returns the position of cursor when event occured relative to
109: * top-left corner of recipient window
110: * @return position of cursor in local coordinates
111: */
112: public Point getLocalPos() {
113: return localPos;
114: }
115:
116: /**
117: * Returns the position of cursor when event occured
118: * in screen coordinates.
119: * @return position of cursor in screen coordinates
120: */
121: public Point getScreenPos() {
122: return screenPos;
123: }
124:
125: /**
126: * The recipient window bounds when the event occured
127: * @return window bounds
128: */
129: public Rectangle getWindowRect() {
130: return windowRect;
131: }
132:
133: /**
134: * Returns the state of keyboard and mouse buttons when the event
135: * occured if event from mouse or keyboard, for other events can
136: * return junk values. The value is bitwise OR of
137: * java.awt.event.InputEvent *_DOWN constants.
138: *
139: * Method is aware of system mouse button swap for left-hand
140: * mouse and return swapped values.
141: * @return bitwise OR of java.awt.event.InputEvent *_DOWN constants
142: */
143: public int getInputModifiers() {
144: return modifiers;
145: }
146:
147: /**
148: * Returns the iconified/maximized state of recipient window if
149: * event is state related, for other events can junk values.
150: * The value has the same meaning as Frame.getExtendedState
151: * It's bitwise OR of ICONIFIED, MAXIMIZED_HORIZ, MAXIMIZED_VERT
152: * @return bitwise OR of ICONIFIED, MAXIMIZED_HORIZ, MAXIMIZED_VERT
153: */
154: public int getWindowState() {
155: return windowState;
156: }
157:
158: /**
159: * The same meaning as java.awt.event.getKeyCode
160: * @return java.awt.event VK_* constant
161: */
162: public int getVKey() {
163: return (keyInfo != null) ? keyInfo.vKey : KeyInfo.DEFAULT_VKEY;
164: }
165:
166: /**
167: * The same meaning as java.awt.event.getKeyLocation
168: * @return java.awt.event KEY_LOCATION_* constant
169: */
170: public int getKeyLocation() {
171: return (keyInfo != null) ? keyInfo.keyLocation
172: : KeyInfo.DEFAULT_LOCATION;
173: }
174:
175: /**
176: * Return the string of characters associated with the event
177: * Has meaning only for KEY_PRESSED as should be translated to
178: * serie of KEY_TYPED events. For dead keys and input methods
179: * one key press can generate multiple key chars.
180: * @return string of characters
181: */
182: public StringBuffer getKeyChars() {
183: if (keyInfo == null) {
184: return null;
185: }
186: if (keyInfo.vKey == KeyEvent.VK_ENTER) {
187: keyInfo.keyChars.setLength(0);
188: keyInfo.setKeyChars('\n');
189: }
190: return keyInfo.keyChars;
191: }
192:
193: public char getLastChar() {
194: if (keyInfo == null || keyInfo.keyChars.length() == 0) {
195: return KeyEvent.CHAR_UNDEFINED;
196: }
197: return keyInfo.keyChars.charAt(keyInfo.keyChars.length() - 1);
198: }
199:
200: /**
201: * Returns the number of mouse button which changed it's state,
202: * otherwise 0.
203: * Left button is 1, middle button is 2, right button is 3.
204: *
205: * Method is aware of system mouse button swap for left-hand
206: * mouse and return swapped values.
207: * @return mouse button number
208: */
209: public int getMouseButton() {
210: return mouseButton;
211: }
212:
213: /**
214: * Returns time when the message was received
215: * @return time in milliseconds
216: */
217: public long getTime() {
218: return time;
219: }
220:
221: /**
222: * For the focus event contains the oposite window.
223: * This means it lost focus if recipient gains it,
224: * or will gain focus if recipient looses it.
225: * @return HWND on Windows, xwindnow on X
226: */
227: public long getOtherWindowId() {
228: return otherWindowId;
229: }
230:
231: /**
232: * Returns the "dirty" area of the window as set of non-intersecting
233: * rectangles. This area is to be painted.
234: * @return non-empty array of null if empty
235: */
236: public abstract MultiRectArea getClipRects();
237:
238: /**
239: * Returns the "dirty" area of the window as one rectangle.
240: * This area is to be painted.
241: * @return non-null Rectangle
242: */
243: public abstract Rectangle getClipBounds();
244:
245: /**
246: * Returns the window insets. Insets is area which belongs to
247: * window somehow but is outside of it's client area,
248: * it usually contains system provided border and titlebar.
249: * @return non-null java.awt.Insets
250: */
251: public abstract Insets getInsets();
252:
253: /**
254: * Returns true if event is popup menu trigger.
255: * @return boolean flag
256: */
257: public abstract boolean getTrigger();
258:
259: /**
260: * Returns the number of "clicks" the mouse wheel was rotated.
261: * @return negative values if the mouse wheel was rotated up/away from the user,
262: * and positive values if the mouse wheel was rotated down/ towards the user
263: */
264: public int getWheelRotation() {
265: return wheelRotation;
266: }
267: }
|