author | yan |
Mon, 06 Oct 2008 16:45:00 +0400 | |
changeset 1966 | 12a51fb0db0d |
parent 1962 | 6c293d33645b |
child 2472 | b7aba00cabb6 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
116
9c43d9eb1029
6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents:
2
diff
changeset
|
2 |
* Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved. |
2 | 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. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
package sun.awt.X11; |
|
27 |
||
28 |
import java.awt.*; |
|
29 |
import java.awt.event.*; |
|
30 |
import java.awt.peer.ComponentPeer; |
|
31 |
import java.awt.image.ColorModel; |
|
32 |
||
33 |
import java.lang.ref.WeakReference; |
|
34 |
||
35 |
import java.lang.reflect.Field; |
|
36 |
import java.lang.reflect.Method; |
|
37 |
||
38 |
import java.util.logging.Level; |
|
39 |
import java.util.logging.Logger; |
|
40 |
||
41 |
import sun.awt.*; |
|
42 |
||
43 |
import sun.awt.image.PixelConverter; |
|
44 |
||
45 |
import sun.java2d.SunGraphics2D; |
|
46 |
import sun.java2d.SurfaceData; |
|
47 |
||
48 |
public class XWindow extends XBaseWindow implements X11ComponentPeer { |
|
49 |
private static Logger log = Logger.getLogger("sun.awt.X11.XWindow"); |
|
50 |
private static Logger insLog = Logger.getLogger("sun.awt.X11.insets.XWindow"); |
|
51 |
private static Logger eventLog = Logger.getLogger("sun.awt.X11.event.XWindow"); |
|
52 |
private static final Logger focusLog = Logger.getLogger("sun.awt.X11.focus.XWindow"); |
|
53 |
private static Logger keyEventLog = Logger.getLogger("sun.awt.X11.kye.XWindow"); |
|
54 |
/* If a motion comes in while a multi-click is pending, |
|
55 |
* allow a smudge factor so that moving the mouse by a small |
|
56 |
* amount does not wipe out the multi-click state variables. |
|
57 |
*/ |
|
58 |
private final static int AWT_MULTICLICK_SMUDGE = 4; |
|
59 |
// ButtonXXX events stuff |
|
60 |
static int rbutton = 0; |
|
61 |
static int lastX = 0, lastY = 0; |
|
62 |
static long lastTime = 0; |
|
63 |
static long lastButton = 0; |
|
64 |
static WeakReference lastWindowRef = null; |
|
65 |
static int clickCount = 0; |
|
66 |
||
67 |
// used to check if we need to re-create surfaceData. |
|
68 |
int oldWidth = -1; |
|
69 |
int oldHeight = -1; |
|
70 |
||
71 |
||
72 |
protected X11GraphicsConfig graphicsConfig; |
|
73 |
protected AwtGraphicsConfigData graphicsConfigData; |
|
74 |
||
75 |
private boolean reparented; |
|
76 |
||
77 |
XWindow parent; |
|
78 |
||
79 |
Component target; |
|
80 |
||
81 |
private static int JAWT_LOCK_ERROR=0x00000001; |
|
82 |
private static int JAWT_LOCK_CLIP_CHANGED=0x00000002; |
|
83 |
private static int JAWT_LOCK_BOUNDS_CHANGED=0x00000004; |
|
84 |
private static int JAWT_LOCK_SURFACE_CHANGED=0x00000008; |
|
85 |
private int drawState = JAWT_LOCK_CLIP_CHANGED | |
|
86 |
JAWT_LOCK_BOUNDS_CHANGED | |
|
87 |
JAWT_LOCK_SURFACE_CHANGED; |
|
88 |
||
89 |
public static final String TARGET = "target", |
|
90 |
REPARENTED = "reparented"; // whether it is reparented by default |
|
91 |
||
92 |
SurfaceData surfaceData; |
|
93 |
||
94 |
XRepaintArea paintArea; |
|
116
9c43d9eb1029
6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents:
2
diff
changeset
|
95 |
|
2 | 96 |
// fallback default font object |
116
9c43d9eb1029
6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents:
2
diff
changeset
|
97 |
private static Font defaultFont; |
9c43d9eb1029
6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents:
2
diff
changeset
|
98 |
|
9c43d9eb1029
6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents:
2
diff
changeset
|
99 |
static synchronized Font getDefaultFont() { |
9c43d9eb1029
6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents:
2
diff
changeset
|
100 |
if (null == defaultFont) { |
9c43d9eb1029
6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents:
2
diff
changeset
|
101 |
defaultFont = new Font(Font.DIALOG, Font.PLAIN, 12); |
9c43d9eb1029
6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents:
2
diff
changeset
|
102 |
} |
9c43d9eb1029
6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents:
2
diff
changeset
|
103 |
return defaultFont; |
9c43d9eb1029
6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents:
2
diff
changeset
|
104 |
} |
2 | 105 |
|
447
0fb5f354ad70
6430553: MouseClick event should not be fired if MouseRelease happened without MousePress
dav
parents:
439
diff
changeset
|
106 |
/* A bitmask keeps the button's numbers as Button1Mask, Button2Mask, Button3Mask |
0fb5f354ad70
6430553: MouseClick event should not be fired if MouseRelease happened without MousePress
dav
parents:
439
diff
changeset
|
107 |
* which are allowed to |
0fb5f354ad70
6430553: MouseClick event should not be fired if MouseRelease happened without MousePress
dav
parents:
439
diff
changeset
|
108 |
* generate the CLICK event after the RELEASE has happened. |
0fb5f354ad70
6430553: MouseClick event should not be fired if MouseRelease happened without MousePress
dav
parents:
439
diff
changeset
|
109 |
* There are conditions that must be true for that sending CLICK event: |
0fb5f354ad70
6430553: MouseClick event should not be fired if MouseRelease happened without MousePress
dav
parents:
439
diff
changeset
|
110 |
* 1) button was initially PRESSED |
0fb5f354ad70
6430553: MouseClick event should not be fired if MouseRelease happened without MousePress
dav
parents:
439
diff
changeset
|
111 |
* 2) no movement or drag has happened until RELEASE |
0fb5f354ad70
6430553: MouseClick event should not be fired if MouseRelease happened without MousePress
dav
parents:
439
diff
changeset
|
112 |
*/ |
0fb5f354ad70
6430553: MouseClick event should not be fired if MouseRelease happened without MousePress
dav
parents:
439
diff
changeset
|
113 |
private int mouseButtonClickAllowed = 0; |
2 | 114 |
|
115 |
native int getNativeColor(Color clr, GraphicsConfiguration gc); |
|
116 |
native void getWMInsets(long window, long left, long top, long right, long bottom, long border); |
|
117 |
native long getTopWindow(long window, long rootWin); |
|
118 |
native void getWindowBounds(long window, long x, long y, long width, long height); |
|
119 |
private native static void initIDs(); |
|
120 |
||
121 |
private static Field isPostedField; |
|
122 |
static { |
|
123 |
initIDs(); |
|
124 |
} |
|
125 |
||
126 |
XWindow(XCreateWindowParams params) { |
|
127 |
super(params); |
|
128 |
} |
|
129 |
||
130 |
XWindow() { |
|
131 |
} |
|
132 |
||
133 |
XWindow(long parentWindow, Rectangle bounds) { |
|
134 |
super(new XCreateWindowParams(new Object[] { |
|
135 |
BOUNDS, bounds, |
|
136 |
PARENT_WINDOW, Long.valueOf(parentWindow)})); |
|
137 |
} |
|
138 |
||
139 |
XWindow(Component target, long parentWindow, Rectangle bounds) { |
|
140 |
super(new XCreateWindowParams(new Object[] { |
|
141 |
BOUNDS, bounds, |
|
142 |
PARENT_WINDOW, Long.valueOf(parentWindow), |
|
143 |
TARGET, target})); |
|
144 |
} |
|
145 |
||
146 |
XWindow(Component target, long parentWindow) { |
|
147 |
this(target, parentWindow, target.getBounds()); |
|
148 |
} |
|
149 |
||
150 |
XWindow(Component target) { |
|
151 |
this(target, (target.getParent() == null) ? 0 : getParentWindowID(target), target.getBounds()); |
|
152 |
} |
|
153 |
||
154 |
XWindow(Object target) { |
|
155 |
this(null, 0, null); |
|
156 |
} |
|
157 |
||
158 |
/* This create is used by the XEmbeddedFramePeer since it has to create the window |
|
159 |
as a child of the netscape window. This netscape window is passed in as wid */ |
|
160 |
XWindow(long parentWindow) { |
|
161 |
super(new XCreateWindowParams(new Object[] { |
|
162 |
PARENT_WINDOW, Long.valueOf(parentWindow), |
|
163 |
REPARENTED, Boolean.TRUE, |
|
164 |
EMBEDDED, Boolean.TRUE})); |
|
165 |
} |
|
166 |
||
167 |
protected void initGraphicsConfiguration() { |
|
168 |
graphicsConfig = (X11GraphicsConfig) target.getGraphicsConfiguration(); |
|
169 |
graphicsConfigData = new AwtGraphicsConfigData(graphicsConfig.getAData()); |
|
170 |
} |
|
171 |
||
172 |
void preInit(XCreateWindowParams params) { |
|
173 |
super.preInit(params); |
|
174 |
reparented = Boolean.TRUE.equals(params.get(REPARENTED)); |
|
175 |
||
176 |
target = (Component)params.get(TARGET); |
|
177 |
||
178 |
initGraphicsConfiguration(); |
|
179 |
||
180 |
AwtGraphicsConfigData gData = getGraphicsConfigurationData(); |
|
181 |
X11GraphicsConfig config = (X11GraphicsConfig) getGraphicsConfiguration(); |
|
182 |
XVisualInfo visInfo = gData.get_awt_visInfo(); |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
183 |
params.putIfNull(EVENT_MASK, XConstants.KeyPressMask | XConstants.KeyReleaseMask |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
184 |
| XConstants.FocusChangeMask | XConstants.ButtonPressMask | XConstants.ButtonReleaseMask |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
185 |
| XConstants.EnterWindowMask | XConstants.LeaveWindowMask | XConstants.PointerMotionMask |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
186 |
| XConstants.ButtonMotionMask | XConstants.ExposureMask | XConstants.StructureNotifyMask); |
2 | 187 |
|
188 |
if (target != null) { |
|
189 |
params.putIfNull(BOUNDS, target.getBounds()); |
|
190 |
} else { |
|
191 |
params.putIfNull(BOUNDS, new Rectangle(0, 0, MIN_SIZE, MIN_SIZE)); |
|
192 |
} |
|
193 |
params.putIfNull(BORDER_PIXEL, Long.valueOf(0)); |
|
194 |
getColorModel(); // fix 4948833: this call forces the color map to be initialized |
|
195 |
params.putIfNull(COLORMAP, gData.get_awt_cmap()); |
|
196 |
params.putIfNull(DEPTH, gData.get_awt_depth()); |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
197 |
params.putIfNull(VISUAL_CLASS, Integer.valueOf((int)XConstants.InputOutput)); |
2 | 198 |
params.putIfNull(VISUAL, visInfo.get_visual()); |
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
199 |
params.putIfNull(VALUE_MASK, XConstants.CWBorderPixel | XConstants.CWEventMask | XConstants.CWColormap); |
2 | 200 |
Long parentWindow = (Long)params.get(PARENT_WINDOW); |
201 |
if (parentWindow == null || parentWindow.longValue() == 0) { |
|
202 |
XToolkit.awtLock(); |
|
203 |
try { |
|
204 |
int screen = visInfo.get_screen(); |
|
205 |
if (screen != -1) { |
|
206 |
params.add(PARENT_WINDOW, XlibWrapper.RootWindow(XToolkit.getDisplay(), screen)); |
|
207 |
} else { |
|
208 |
params.add(PARENT_WINDOW, XToolkit.getDefaultRootWindow()); |
|
209 |
} |
|
210 |
} finally { |
|
211 |
XToolkit.awtUnlock(); |
|
212 |
} |
|
213 |
} |
|
214 |
||
215 |
paintArea = new XRepaintArea(); |
|
216 |
if (target != null) { |
|
217 |
this.parent = getParentXWindowObject(target.getParent()); |
|
218 |
} |
|
219 |
||
220 |
params.putIfNull(BACKING_STORE, XToolkit.getBackingStoreType()); |
|
221 |
} |
|
222 |
||
223 |
void postInit(XCreateWindowParams params) { |
|
224 |
super.postInit(params); |
|
225 |
||
226 |
setWMClass(getWMClass()); |
|
227 |
||
228 |
surfaceData = graphicsConfig.createSurfaceData(this); |
|
229 |
Color c; |
|
230 |
if (target != null && (c = target.getBackground()) != null) { |
|
231 |
// We need a version of setBackground that does not call repaint !! |
|
232 |
// and one that does not get overridden. The problem is that in postInit |
|
233 |
// we call setBackground and we dont have all the stuff initialized to |
|
234 |
// do a full paint for most peers. So we cannot call setBackground in postInit. |
|
235 |
// instead we need to call xSetBackground. |
|
236 |
xSetBackground(c); |
|
237 |
} |
|
238 |
} |
|
239 |
||
240 |
public GraphicsConfiguration getGraphicsConfiguration() { |
|
241 |
if (graphicsConfig == null) { |
|
242 |
initGraphicsConfiguration(); |
|
243 |
} |
|
244 |
return graphicsConfig; |
|
245 |
} |
|
246 |
||
247 |
public AwtGraphicsConfigData getGraphicsConfigurationData() { |
|
248 |
if (graphicsConfigData == null) { |
|
249 |
initGraphicsConfiguration(); |
|
250 |
} |
|
251 |
return graphicsConfigData; |
|
252 |
} |
|
253 |
||
254 |
protected String[] getWMClass() { |
|
255 |
return new String[] {XToolkit.getCorrectXIDString(getClass().getName()), XToolkit.getAWTAppClassName()}; |
|
256 |
} |
|
257 |
||
258 |
void setReparented(boolean newValue) { |
|
259 |
reparented = newValue; |
|
260 |
} |
|
261 |
||
262 |
boolean isReparented() { |
|
263 |
return reparented; |
|
264 |
} |
|
265 |
||
266 |
static long getParentWindowID(Component target) { |
|
267 |
||
268 |
ComponentPeer peer = target.getParent().getPeer(); |
|
269 |
Component temp = target.getParent(); |
|
270 |
while (!(peer instanceof XWindow)) |
|
271 |
{ |
|
272 |
temp = temp.getParent(); |
|
273 |
peer = temp.getPeer(); |
|
274 |
} |
|
275 |
||
276 |
if (peer != null && peer instanceof XWindow) |
|
277 |
return ((XWindow)peer).getContentWindow(); |
|
278 |
else return 0; |
|
279 |
} |
|
280 |
||
281 |
||
282 |
static XWindow getParentXWindowObject(Component target) { |
|
283 |
if (target == null) return null; |
|
284 |
Component temp = target.getParent(); |
|
285 |
if (temp == null) return null; |
|
286 |
ComponentPeer peer = temp.getPeer(); |
|
287 |
if (peer == null) return null; |
|
288 |
while ((peer != null) && !(peer instanceof XWindow)) |
|
289 |
{ |
|
290 |
temp = temp.getParent(); |
|
291 |
peer = temp.getPeer(); |
|
292 |
} |
|
293 |
if (peer != null && peer instanceof XWindow) |
|
294 |
return (XWindow) peer; |
|
295 |
else return null; |
|
296 |
} |
|
297 |
||
298 |
||
299 |
boolean isParentOf(XWindow win) { |
|
300 |
if (!(target instanceof Container) || win == null || win.getTarget() == null) { |
|
301 |
return false; |
|
302 |
} |
|
303 |
Container parent = ComponentAccessor.getParent_NoClientCode(win.target); |
|
304 |
while (parent != null && parent != target) { |
|
305 |
parent = ComponentAccessor.getParent_NoClientCode(parent); |
|
306 |
} |
|
307 |
return (parent == target); |
|
308 |
} |
|
309 |
||
310 |
public Object getTarget() { |
|
311 |
return target; |
|
312 |
} |
|
313 |
public Component getEventSource() { |
|
314 |
return target; |
|
315 |
} |
|
316 |
||
317 |
public ColorModel getColorModel(int transparency) { |
|
318 |
return graphicsConfig.getColorModel (transparency); |
|
319 |
} |
|
320 |
||
321 |
public ColorModel getColorModel() { |
|
322 |
if (graphicsConfig != null) { |
|
323 |
return graphicsConfig.getColorModel (); |
|
324 |
} |
|
325 |
else { |
|
326 |
return XToolkit.getStaticColorModel(); |
|
327 |
} |
|
328 |
} |
|
329 |
||
330 |
Graphics getGraphics(SurfaceData surfData, Color afore, Color aback, Font afont) { |
|
331 |
if (surfData == null) return null; |
|
332 |
||
333 |
Component target = (Component) this.target; |
|
334 |
||
335 |
/* Fix for bug 4746122. Color and Font shouldn't be null */ |
|
336 |
Color bgColor = aback; |
|
337 |
if (bgColor == null) { |
|
338 |
bgColor = SystemColor.window; |
|
339 |
} |
|
340 |
Color fgColor = afore; |
|
341 |
if (fgColor == null) { |
|
342 |
fgColor = SystemColor.windowText; |
|
343 |
} |
|
344 |
Font font = afont; |
|
345 |
if (font == null) { |
|
116
9c43d9eb1029
6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents:
2
diff
changeset
|
346 |
font = XWindow.getDefaultFont(); |
2 | 347 |
} |
348 |
return new SunGraphics2D(surfData, fgColor, bgColor, font); |
|
349 |
} |
|
350 |
||
351 |
public Graphics getGraphics() { |
|
352 |
return getGraphics(surfaceData, |
|
353 |
target.getForeground(), |
|
354 |
target.getBackground(), |
|
355 |
target.getFont()); |
|
356 |
} |
|
357 |
||
358 |
public FontMetrics getFontMetrics(Font font) { |
|
359 |
return Toolkit.getDefaultToolkit().getFontMetrics(font); |
|
360 |
} |
|
361 |
||
362 |
public Rectangle getTargetBounds() { |
|
363 |
return target.getBounds(); |
|
364 |
} |
|
365 |
||
366 |
/** |
|
367 |
* Returns true if the event has been handled and should not be |
|
368 |
* posted to Java. |
|
369 |
*/ |
|
370 |
boolean prePostEvent(AWTEvent e) { |
|
371 |
return false; |
|
372 |
} |
|
373 |
||
374 |
static Method m_sendMessage; |
|
375 |
static void sendEvent(final AWTEvent e) { |
|
376 |
if (isPostedField == null) { |
|
377 |
isPostedField = SunToolkit.getField(AWTEvent.class, "isPosted"); |
|
378 |
} |
|
379 |
PeerEvent pe = new PeerEvent(Toolkit.getDefaultToolkit(), new Runnable() { |
|
380 |
public void run() { |
|
381 |
try { |
|
382 |
isPostedField.setBoolean(e, true); |
|
383 |
} catch (IllegalArgumentException e) { |
|
384 |
assert(false); |
|
385 |
} catch (IllegalAccessException e) { |
|
386 |
assert(false); |
|
387 |
} |
|
388 |
((Component)e.getSource()).dispatchEvent(e); |
|
389 |
} |
|
390 |
}, PeerEvent.ULTIMATE_PRIORITY_EVENT); |
|
391 |
if (focusLog.isLoggable(Level.FINER) && (e instanceof FocusEvent)) focusLog.finer("Sending " + e); |
|
392 |
XToolkit.postEvent(XToolkit.targetToAppContext(e.getSource()), pe); |
|
393 |
} |
|
394 |
||
395 |
||
396 |
/* |
|
397 |
* Post an event to the event queue. |
|
398 |
*/ |
|
399 |
// NOTE: This method may be called by privileged threads. |
|
400 |
// DO NOT INVOKE CLIENT CODE ON THIS THREAD! |
|
401 |
void postEvent(AWTEvent event) { |
|
402 |
XToolkit.postEvent(XToolkit.targetToAppContext(event.getSource()), event); |
|
403 |
} |
|
404 |
||
405 |
static void postEventStatic(AWTEvent event) { |
|
406 |
XToolkit.postEvent(XToolkit.targetToAppContext(event.getSource()), event); |
|
407 |
} |
|
408 |
||
409 |
public void postEventToEventQueue(final AWTEvent event) { |
|
410 |
//fix for 6239938 : Choice drop-down does not disappear when it loses focus, on XToolkit |
|
411 |
if (!prePostEvent(event)) { |
|
412 |
//event hasn't been handled and must be posted to EventQueue |
|
413 |
postEvent(event); |
|
414 |
} |
|
415 |
} |
|
416 |
||
417 |
// overriden in XCanvasPeer |
|
418 |
protected boolean doEraseBackground() { |
|
419 |
return true; |
|
420 |
} |
|
421 |
||
422 |
// We need a version of setBackground that does not call repaint !! |
|
423 |
// and one that does not get overridden. The problem is that in postInit |
|
424 |
// we call setBackground and we dont have all the stuff initialized to |
|
425 |
// do a full paint for most peers. So we cannot call setBackground in postInit. |
|
426 |
final public void xSetBackground(Color c) { |
|
427 |
XToolkit.awtLock(); |
|
428 |
try { |
|
429 |
winBackground(c); |
|
430 |
// fix for 6558510: handle sun.awt.noerasebackground flag, |
|
431 |
// see doEraseBackground() and preInit() methods in XCanvasPeer |
|
432 |
if (!doEraseBackground()) { |
|
433 |
return; |
|
434 |
} |
|
435 |
// 6304250: XAWT: Items in choice show a blue border on OpenGL + Solaris10 when background color is set |
|
436 |
// Note: When OGL is enabled, surfaceData.pixelFor() will not |
|
437 |
// return a pixel value appropriate for passing to |
|
438 |
// XSetWindowBackground(). Therefore, we will use the ColorModel |
|
439 |
// for this component in order to calculate a pixel value from |
|
440 |
// the given RGB value. |
|
441 |
ColorModel cm = getColorModel(); |
|
442 |
int pixel = PixelConverter.instance.rgbToPixel(c.getRGB(), cm); |
|
443 |
XlibWrapper.XSetWindowBackground(XToolkit.getDisplay(), getContentWindow(), pixel); |
|
444 |
} |
|
445 |
finally { |
|
446 |
XToolkit.awtUnlock(); |
|
447 |
} |
|
448 |
} |
|
449 |
||
450 |
public void setBackground(Color c) { |
|
451 |
xSetBackground(c); |
|
452 |
} |
|
453 |
||
454 |
Color backgroundColor; |
|
455 |
void winBackground(Color c) { |
|
456 |
backgroundColor = c; |
|
457 |
} |
|
458 |
||
459 |
public Color getWinBackground() { |
|
460 |
Color c = null; |
|
461 |
||
462 |
if (backgroundColor != null) { |
|
463 |
c = backgroundColor; |
|
464 |
} else if (parent != null) { |
|
465 |
c = parent.getWinBackground(); |
|
466 |
} |
|
467 |
||
468 |
if (c instanceof SystemColor) { |
|
469 |
c = new Color(c.getRGB()); |
|
470 |
} |
|
471 |
||
472 |
return c; |
|
473 |
} |
|
474 |
||
475 |
public boolean isEmbedded() { |
|
476 |
return embedded; |
|
477 |
} |
|
478 |
||
479 |
public void repaint(int x,int y, int width, int height) { |
|
480 |
if (!isVisible()) { |
|
481 |
return; |
|
482 |
} |
|
483 |
Graphics g = getGraphics(); |
|
484 |
if (g != null) { |
|
485 |
try { |
|
486 |
g.setClip(x,y,width,height); |
|
487 |
paint(g); |
|
488 |
} finally { |
|
489 |
g.dispose(); |
|
490 |
} |
|
491 |
} |
|
492 |
} |
|
493 |
||
494 |
public void repaint() { |
|
495 |
if (!isVisible()) { |
|
496 |
return; |
|
497 |
} |
|
498 |
Graphics g = getGraphics(); |
|
499 |
if (g != null) { |
|
500 |
try { |
|
501 |
paint(g); |
|
502 |
} finally { |
|
503 |
g.dispose(); |
|
504 |
} |
|
505 |
} |
|
506 |
} |
|
507 |
||
508 |
void paint(Graphics g) { |
|
509 |
} |
|
510 |
||
511 |
//used by Peers to avoid flickering withing paint() |
|
512 |
protected void flush(){ |
|
513 |
XToolkit.awtLock(); |
|
514 |
try { |
|
515 |
XlibWrapper.XFlush(XToolkit.getDisplay()); |
|
516 |
} finally { |
|
517 |
XToolkit.awtUnlock(); |
|
518 |
} |
|
519 |
} |
|
520 |
||
521 |
public void popup(int x, int y, int width, int height) { |
|
522 |
// TBD: grab the pointer |
|
523 |
xSetBounds(x, y, width, height); |
|
524 |
} |
|
525 |
||
526 |
public void handleExposeEvent(XEvent xev) { |
|
527 |
super.handleExposeEvent(xev); |
|
528 |
XExposeEvent xe = xev.get_xexpose(); |
|
529 |
if (isEventDisabled(xev)) { |
|
530 |
return; |
|
531 |
} |
|
532 |
int x = xe.get_x(); |
|
533 |
int y = xe.get_y(); |
|
534 |
int w = xe.get_width(); |
|
535 |
int h = xe.get_height(); |
|
536 |
||
537 |
Component target = (Component)getEventSource(); |
|
538 |
||
539 |
if (!ComponentAccessor.getIgnoreRepaint(target) |
|
540 |
&& ComponentAccessor.getWidth(target) != 0 |
|
541 |
&& ComponentAccessor.getHeight(target) != 0) |
|
542 |
{ |
|
543 |
handleExposeEvent(target, x, y, w, h); |
|
544 |
} |
|
545 |
} |
|
546 |
||
547 |
public void handleExposeEvent(Component target, int x, int y, int w, int h) { |
|
548 |
PaintEvent event = PaintEventDispatcher.getPaintEventDispatcher(). |
|
549 |
createPaintEvent(target, x, y, w, h); |
|
550 |
if (event != null) { |
|
551 |
postEventToEventQueue(event); |
|
552 |
} |
|
553 |
} |
|
554 |
||
555 |
static int getModifiers(int state, int button, int keyCode) { |
|
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
556 |
return getModifiers(state, button, keyCode, 0, false); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
557 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
558 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
559 |
static int getModifiers(int state, int button, int keyCode, int type, boolean wheel_mouse) { |
2 | 560 |
int modifiers = 0; |
561 |
||
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
562 |
if (((state & XConstants.ShiftMask) != 0) ^ (keyCode == KeyEvent.VK_SHIFT)) { |
2 | 563 |
modifiers |= InputEvent.SHIFT_DOWN_MASK; |
564 |
} |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
565 |
if (((state & XConstants.ControlMask) != 0) ^ (keyCode == KeyEvent.VK_CONTROL)) { |
2 | 566 |
modifiers |= InputEvent.CTRL_DOWN_MASK; |
567 |
} |
|
568 |
if (((state & XToolkit.metaMask) != 0) ^ (keyCode == KeyEvent.VK_META)) { |
|
569 |
modifiers |= InputEvent.META_DOWN_MASK; |
|
570 |
} |
|
571 |
if (((state & XToolkit.altMask) != 0) ^ (keyCode == KeyEvent.VK_ALT)) { |
|
572 |
modifiers |= InputEvent.ALT_DOWN_MASK; |
|
573 |
} |
|
574 |
if (((state & XToolkit.modeSwitchMask) != 0) ^ (keyCode == KeyEvent.VK_ALT_GRAPH)) { |
|
575 |
modifiers |= InputEvent.ALT_GRAPH_DOWN_MASK; |
|
576 |
} |
|
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
577 |
//InputEvent.BUTTON_DOWN_MASK array is starting from BUTTON1_DOWN_MASK on index == 0. |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
578 |
// button currently reflects a real button number and starts from 1. (except NOBUTTON which is zero ) |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
579 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
580 |
/* this is an attempt to refactor button IDs in : MouseEvent, InputEvent, XlibWrapper and XWindow.*/ |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
581 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
582 |
//reflects a button number similar to MouseEvent.BUTTON1, 2, 3 etc. |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
583 |
for (int i = 0; i < XConstants.buttonsMask.length; i ++){ |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
584 |
//modifier should be added if : |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
585 |
// 1) current button is now still in PRESSED state (means that user just pressed mouse but not released yet) or |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
586 |
// 2) if Xsystem reports that "state" represents that button was just released. This only happens on RELEASE with 1,2,3 buttons. |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
587 |
// ONLY one of these conditions should be TRUE to add that modifier. |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
588 |
if (((state & XConstants.buttonsMask[i]) != 0) != (button == XConstants.buttons[i])){ |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
589 |
//exclude wheel buttons from adding their numbers as modifiers |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
590 |
if (!wheel_mouse) { |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
591 |
modifiers |= InputEvent.getMaskForButton(i+1); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
592 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
593 |
} |
2 | 594 |
} |
595 |
return modifiers; |
|
596 |
} |
|
597 |
||
598 |
static int getXModifiers(AWTKeyStroke stroke) { |
|
599 |
int mods = stroke.getModifiers(); |
|
600 |
int res = 0; |
|
601 |
if ((mods & (InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK)) != 0) { |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
602 |
res |= XConstants.ShiftMask; |
2 | 603 |
} |
604 |
if ((mods & (InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK)) != 0) { |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
605 |
res |= XConstants.ControlMask; |
2 | 606 |
} |
607 |
if ((mods & (InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK)) != 0) { |
|
608 |
res |= XToolkit.altMask; |
|
609 |
} |
|
610 |
if ((mods & (InputEvent.META_DOWN_MASK | InputEvent.META_MASK)) != 0) { |
|
611 |
res |= XToolkit.metaMask; |
|
612 |
} |
|
613 |
if ((mods & (InputEvent.ALT_GRAPH_DOWN_MASK | InputEvent.ALT_GRAPH_MASK)) != 0) { |
|
614 |
res |= XToolkit.modeSwitchMask; |
|
615 |
} |
|
616 |
return res; |
|
617 |
} |
|
618 |
||
619 |
/** |
|
620 |
* Returns true if this event is disabled and shouldn't be passed to Java. |
|
621 |
* Default implementation returns false for all events. |
|
622 |
*/ |
|
623 |
static int getRightButtonNumber() { |
|
624 |
if (rbutton == 0) { // not initialized yet |
|
625 |
XToolkit.awtLock(); |
|
626 |
try { |
|
627 |
rbutton = XlibWrapper.XGetPointerMapping(XToolkit.getDisplay(), XlibWrapper.ibuffer, 3); |
|
628 |
} |
|
629 |
finally { |
|
630 |
XToolkit.awtUnlock(); |
|
631 |
} |
|
632 |
} |
|
633 |
return rbutton; |
|
634 |
} |
|
635 |
||
636 |
static int getMouseMovementSmudge() { |
|
637 |
//TODO: It's possible to read corresponding settings |
|
638 |
return AWT_MULTICLICK_SMUDGE; |
|
639 |
} |
|
640 |
||
641 |
public void handleButtonPressRelease(XEvent xev) { |
|
642 |
super.handleButtonPressRelease(xev); |
|
643 |
XButtonEvent xbe = xev.get_xbutton(); |
|
644 |
if (isEventDisabled(xev)) { |
|
645 |
return; |
|
646 |
} |
|
647 |
if (eventLog.isLoggable(Level.FINE)) eventLog.fine(xbe.toString()); |
|
648 |
long when; |
|
649 |
int modifiers; |
|
650 |
boolean popupTrigger = false; |
|
651 |
int button=0; |
|
652 |
boolean wheel_mouse = false; |
|
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
653 |
int lbutton = xbe.get_button(); |
2 | 654 |
int type = xev.get_type(); |
655 |
when = xbe.get_time(); |
|
656 |
long jWhen = XToolkit.nowMillisUTC_offset(when); |
|
657 |
||
658 |
int x = xbe.get_x(); |
|
659 |
int y = xbe.get_y(); |
|
660 |
if (xev.get_xany().get_window() != window) { |
|
661 |
Point localXY = toLocal(xbe.get_x_root(), xbe.get_y_root()); |
|
662 |
x = localXY.x; |
|
663 |
y = localXY.y; |
|
664 |
} |
|
665 |
||
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
666 |
if (type == XConstants.ButtonPress) { |
447
0fb5f354ad70
6430553: MouseClick event should not be fired if MouseRelease happened without MousePress
dav
parents:
439
diff
changeset
|
667 |
//Allow this mouse button to generate CLICK event on next ButtonRelease |
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
668 |
mouseButtonClickAllowed |= XConstants.buttonsMask[lbutton]; |
2 | 669 |
XWindow lastWindow = (lastWindowRef != null) ? ((XWindow)lastWindowRef.get()):(null); |
670 |
/* |
|
671 |
multiclick checking |
|
672 |
*/ |
|
673 |
if (eventLog.isLoggable(Level.FINEST)) eventLog.finest("lastWindow = " + lastWindow + ", lastButton " |
|
674 |
+ lastButton + ", lastTime " + lastTime + ", multiClickTime " |
|
675 |
+ XToolkit.getMultiClickTime()); |
|
676 |
if (lastWindow == this && lastButton == lbutton && (when - lastTime) < XToolkit.getMultiClickTime()) { |
|
677 |
clickCount++; |
|
678 |
} else { |
|
679 |
clickCount = 1; |
|
680 |
lastWindowRef = new WeakReference(this); |
|
681 |
lastButton = lbutton; |
|
682 |
lastX = x; |
|
683 |
lastY = y; |
|
684 |
} |
|
685 |
lastTime = when; |
|
686 |
||
687 |
||
688 |
/* |
|
689 |
Check for popup trigger !! |
|
690 |
*/ |
|
691 |
if (lbutton == getRightButtonNumber() || lbutton > 2) { |
|
692 |
popupTrigger = true; |
|
693 |
} else { |
|
694 |
popupTrigger = false; |
|
695 |
} |
|
696 |
} |
|
697 |
||
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
698 |
button = XConstants.buttons[lbutton - 1]; |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
699 |
// 4 and 5 buttons are usually considered assigned to a first wheel |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
700 |
if (lbutton == XConstants.buttons[3] || |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
701 |
lbutton == XConstants.buttons[4]) { |
2 | 702 |
wheel_mouse = true; |
703 |
} |
|
704 |
||
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
705 |
// mapping extra buttons to numbers starting from 4. |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
706 |
if ((button > XConstants.buttons[4]) && (!Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled())){ |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
707 |
return; |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
708 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
709 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
710 |
if (button > XConstants.buttons[4]){ |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
711 |
button -= 2; |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
712 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
713 |
modifiers = getModifiers(xbe.get_state(),button,0, type, wheel_mouse); |
2 | 714 |
|
715 |
if (!wheel_mouse) { |
|
716 |
MouseEvent me = new MouseEvent((Component)getEventSource(), |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
717 |
type == XConstants.ButtonPress ? MouseEvent.MOUSE_PRESSED : MouseEvent.MOUSE_RELEASED, |
2 | 718 |
jWhen,modifiers, x, y, |
719 |
xbe.get_x_root(), |
|
720 |
xbe.get_y_root(), |
|
721 |
clickCount,popupTrigger,button); |
|
722 |
||
723 |
postEventToEventQueue(me); |
|
724 |
||
447
0fb5f354ad70
6430553: MouseClick event should not be fired if MouseRelease happened without MousePress
dav
parents:
439
diff
changeset
|
725 |
if ((type == XConstants.ButtonRelease) && |
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
726 |
((mouseButtonClickAllowed & XConstants.buttonsMask[lbutton]) != 0) ) // No up-button in the drag-state |
2 | 727 |
{ |
728 |
postEventToEventQueue(me = new MouseEvent((Component)getEventSource(), |
|
729 |
MouseEvent.MOUSE_CLICKED, |
|
730 |
jWhen, |
|
731 |
modifiers, |
|
732 |
x, y, |
|
733 |
xbe.get_x_root(), |
|
734 |
xbe.get_y_root(), |
|
735 |
clickCount, |
|
736 |
false, button)); |
|
737 |
} |
|
738 |
||
739 |
} |
|
740 |
else { |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
741 |
if (xev.get_type() == XConstants.ButtonPress) { |
2 | 742 |
MouseWheelEvent mwe = new MouseWheelEvent((Component)getEventSource(),MouseEvent.MOUSE_WHEEL, jWhen, |
743 |
modifiers, |
|
744 |
x, y, |
|
745 |
xbe.get_x_root(), |
|
746 |
xbe.get_y_root(), |
|
747 |
clickCount,false,MouseWheelEvent.WHEEL_UNIT_SCROLL, |
|
748 |
3,button==4 ? -1 : 1); |
|
749 |
postEventToEventQueue(mwe); |
|
750 |
} |
|
751 |
} |
|
752 |
||
447
0fb5f354ad70
6430553: MouseClick event should not be fired if MouseRelease happened without MousePress
dav
parents:
439
diff
changeset
|
753 |
/* Update the state variable AFTER the CLICKED event post. */ |
0fb5f354ad70
6430553: MouseClick event should not be fired if MouseRelease happened without MousePress
dav
parents:
439
diff
changeset
|
754 |
if (type == XConstants.ButtonRelease) { |
0fb5f354ad70
6430553: MouseClick event should not be fired if MouseRelease happened without MousePress
dav
parents:
439
diff
changeset
|
755 |
/* Exclude this mouse button from allowed list.*/ |
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
756 |
mouseButtonClickAllowed &= ~XConstants.buttonsMask[lbutton]; |
447
0fb5f354ad70
6430553: MouseClick event should not be fired if MouseRelease happened without MousePress
dav
parents:
439
diff
changeset
|
757 |
} |
2 | 758 |
} |
759 |
||
760 |
public void handleMotionNotify(XEvent xev) { |
|
761 |
super.handleMotionNotify(xev); |
|
762 |
XMotionEvent xme = xev.get_xmotion(); |
|
763 |
if (isEventDisabled(xev)) { |
|
764 |
return; |
|
765 |
} |
|
766 |
||
1962
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
767 |
int mouseKeyState = 0; //(xme.get_state() & (XConstants.buttonsMask[0] | XConstants.buttonsMask[1] | XConstants.buttonsMask[2])); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
768 |
|
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
769 |
//this doesn't work for extra buttons because Xsystem is sending state==0 for every extra button event. |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
770 |
// we can't correct it in MouseEvent class as we done it with modifiers, because exact type (DRAG|MOVE) |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
771 |
// should be passed from XWindow. |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
772 |
//TODO: eliminate it with some other value obtained w/o AWTLock. |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
773 |
for (int i = 0; i < XToolkit.getNumMouseButtons(); i++){ |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
774 |
// TODO : here is the bug in WM: extra buttons doesn't have state!=0 as they should. |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
775 |
if ((i != 4) && (i != 5)) { |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
776 |
mouseKeyState = mouseKeyState | (xme.get_state() & XConstants.buttonsMask[i]); |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
777 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
778 |
} |
6c293d33645b
6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
447
diff
changeset
|
779 |
|
2 | 780 |
boolean isDragging = (mouseKeyState != 0); |
781 |
int mouseEventType = 0; |
|
782 |
||
783 |
if (isDragging) { |
|
784 |
mouseEventType = MouseEvent.MOUSE_DRAGGED; |
|
785 |
} else { |
|
786 |
mouseEventType = MouseEvent.MOUSE_MOVED; |
|
787 |
} |
|
788 |
||
789 |
/* |
|
790 |
Fix for 6176814 . Add multiclick checking. |
|
791 |
*/ |
|
792 |
int x = xme.get_x(); |
|
793 |
int y = xme.get_y(); |
|
794 |
XWindow lastWindow = (lastWindowRef != null) ? ((XWindow)lastWindowRef.get()):(null); |
|
795 |
||
796 |
if (!(lastWindow == this && |
|
797 |
(xme.get_time() - lastTime) < XToolkit.getMultiClickTime() && |
|
798 |
(Math.abs(lastX - x) < AWT_MULTICLICK_SMUDGE && |
|
799 |
Math.abs(lastY - y) < AWT_MULTICLICK_SMUDGE))) { |
|
800 |
clickCount = 0; |
|
801 |
lastWindowRef = null; |
|
447
0fb5f354ad70
6430553: MouseClick event should not be fired if MouseRelease happened without MousePress
dav
parents:
439
diff
changeset
|
802 |
mouseButtonClickAllowed = 0; |
2 | 803 |
lastTime = 0; |
804 |
lastX = 0; |
|
805 |
lastY = 0; |
|
806 |
} |
|
807 |
||
808 |
long jWhen = XToolkit.nowMillisUTC_offset(xme.get_time()); |
|
809 |
int modifiers = getModifiers(xme.get_state(), 0, 0); |
|
810 |
boolean popupTrigger = false; |
|
811 |
||
812 |
Component source = (Component)getEventSource(); |
|
813 |
||
814 |
if (xme.get_window() != window) { |
|
815 |
Point localXY = toLocal(xme.get_x_root(), xme.get_y_root()); |
|
816 |
x = localXY.x; |
|
817 |
y = localXY.y; |
|
818 |
} |
|
819 |
/* Fix for 5039416. |
|
820 |
* According to canvas.c we shouldn't post any MouseEvent if mouse is dragging and clickCount!=0. |
|
821 |
*/ |
|
822 |
if ((isDragging && clickCount == 0) || !isDragging) { |
|
823 |
MouseEvent mme = new MouseEvent(source, mouseEventType, jWhen, |
|
824 |
modifiers, x, y, xme.get_x_root(), xme.get_y_root(), |
|
825 |
clickCount, popupTrigger, MouseEvent.NOBUTTON); |
|
826 |
postEventToEventQueue(mme); |
|
827 |
} |
|
828 |
} |
|
829 |
||
830 |
||
831 |
// REMIND: need to implement looking for disabled events |
|
832 |
public native boolean x11inputMethodLookupString(long event, long [] keysymArray); |
|
833 |
native boolean haveCurrentX11InputMethodInstance(); |
|
834 |
||
835 |
public void handleXCrossingEvent(XEvent xev) { |
|
836 |
super.handleXCrossingEvent(xev); |
|
837 |
XCrossingEvent xce = xev.get_xcrossing(); |
|
838 |
||
839 |
if (eventLog.isLoggable(Level.FINEST)) eventLog.finest(xce.toString()); |
|
840 |
||
841 |
// Skip event If it was caused by a grab |
|
842 |
// This is needed because on displays with focus-follows-mouse on MousePress X system generates |
|
843 |
// two XCrossing events with mode != NormalNotify. First of them notifies that the mouse has left |
|
844 |
// current component. Second one notifies that it has entered into the same component. |
|
845 |
// This looks like the window under the mouse has actually changed and Java handle these events |
|
846 |
// accordingly. This leads to impossibility to make a double click on Component (6404708) |
|
847 |
XWindowPeer toplevel = getToplevelXWindow(); |
|
848 |
if (toplevel != null && !toplevel.isModalBlocked()){ |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
849 |
if (xce.get_mode() != XConstants.NotifyNormal) { |
2 | 850 |
// 6404708 : need update cursor in accordance with skipping Leave/EnterNotify event |
851 |
// whereas it doesn't need to handled further. |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
852 |
if (xce.get_type() == XConstants.EnterNotify) { |
2 | 853 |
XAwtState.setComponentMouseEntered(getEventSource()); |
854 |
XGlobalCursorManager.nativeUpdateCursor(getEventSource()); |
|
855 |
} else { // LeaveNotify: |
|
856 |
XAwtState.setComponentMouseEntered(null); |
|
857 |
} |
|
858 |
return; |
|
859 |
} |
|
860 |
} |
|
861 |
// X sends XCrossing to all hierarchy so if the edge of child equals to |
|
862 |
// ancestor and mouse enters child, the ancestor will get an event too. |
|
863 |
// From java point the event is bogus as ancestor is obscured, so if |
|
864 |
// the child can get java event itself, we skip it on ancestor. |
|
865 |
long childWnd = xce.get_subwindow(); |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
866 |
if (childWnd != XConstants.None) { |
2 | 867 |
XBaseWindow child = XToolkit.windowToXWindow(childWnd); |
868 |
if (child != null && child instanceof XWindow && |
|
869 |
!child.isEventDisabled(xev)) |
|
870 |
{ |
|
871 |
return; |
|
872 |
} |
|
873 |
} |
|
874 |
||
875 |
// Remember old component with mouse to have the opportunity to send it MOUSE_EXITED. |
|
876 |
final Component compWithMouse = XAwtState.getComponentMouseEntered(); |
|
877 |
if (toplevel != null) { |
|
878 |
if(!toplevel.isModalBlocked()){ |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
879 |
if (xce.get_type() == XConstants.EnterNotify) { |
2 | 880 |
// Change XAwtState's component mouse entered to the up-to-date one before requesting |
881 |
// to update the cursor since XAwtState.getComponentMouseEntered() is used when the |
|
882 |
// cursor is updated (in XGlobalCursorManager.findHeavyweightUnderCursor()). |
|
883 |
XAwtState.setComponentMouseEntered(getEventSource()); |
|
884 |
XGlobalCursorManager.nativeUpdateCursor(getEventSource()); |
|
885 |
} else { // LeaveNotify: |
|
886 |
XAwtState.setComponentMouseEntered(null); |
|
887 |
} |
|
888 |
} else { |
|
889 |
((XComponentPeer) ComponentAccessor.getPeer(target)) |
|
890 |
.pSetCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
|
891 |
} |
|
892 |
} |
|
893 |
||
894 |
if (isEventDisabled(xev)) { |
|
895 |
return; |
|
896 |
} |
|
897 |
||
898 |
long jWhen = XToolkit.nowMillisUTC_offset(xce.get_time()); |
|
899 |
int modifiers = getModifiers(xce.get_state(),0,0); |
|
900 |
int clickCount = 0; |
|
901 |
boolean popupTrigger = false; |
|
902 |
int x = xce.get_x(); |
|
903 |
int y = xce.get_y(); |
|
904 |
if (xce.get_window() != window) { |
|
905 |
Point localXY = toLocal(xce.get_x_root(), xce.get_y_root()); |
|
906 |
x = localXY.x; |
|
907 |
y = localXY.y; |
|
908 |
} |
|
909 |
||
910 |
// This code tracks boundary crossing and ensures MOUSE_ENTER/EXIT |
|
911 |
// are posted in alternate pairs |
|
912 |
if (compWithMouse != null) { |
|
913 |
MouseEvent me = new MouseEvent(compWithMouse, |
|
914 |
MouseEvent.MOUSE_EXITED, jWhen, modifiers, xce.get_x(), |
|
915 |
xce.get_y(), xce.get_x_root(), xce.get_y_root(), clickCount, popupTrigger, |
|
916 |
MouseEvent.NOBUTTON); |
|
917 |
postEventToEventQueue(me); |
|
918 |
eventLog.finest("Clearing last window ref"); |
|
919 |
lastWindowRef = null; |
|
920 |
} |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
921 |
if (xce.get_type() == XConstants.EnterNotify) { |
2 | 922 |
MouseEvent me = new MouseEvent(getEventSource(), MouseEvent.MOUSE_ENTERED, |
923 |
jWhen, modifiers, xce.get_x(), xce.get_y(), xce.get_x_root(), xce.get_y_root(), clickCount, |
|
924 |
popupTrigger, MouseEvent.NOBUTTON); |
|
925 |
postEventToEventQueue(me); |
|
926 |
} |
|
927 |
} |
|
928 |
||
929 |
public void doLayout(int x, int y, int width, int height) {} |
|
930 |
||
931 |
public void handleConfigureNotifyEvent(XEvent xev) { |
|
932 |
Rectangle oldBounds = getBounds(); |
|
933 |
||
934 |
super.handleConfigureNotifyEvent(xev); |
|
935 |
insLog.log(Level.FINER, "Configure, {0}, event disabled: {1}", |
|
116
9c43d9eb1029
6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents:
2
diff
changeset
|
936 |
new Object[] {xev.get_xconfigure(), isEventDisabled(xev)}); |
2 | 937 |
if (isEventDisabled(xev)) { |
938 |
return; |
|
939 |
} |
|
940 |
||
941 |
// if ( Check if it's a resize, a move, or a stacking order change ) |
|
942 |
// { |
|
943 |
Rectangle bounds = getBounds(); |
|
944 |
if (!bounds.getSize().equals(oldBounds.getSize())) { |
|
945 |
postEventToEventQueue(new ComponentEvent(getEventSource(), ComponentEvent.COMPONENT_RESIZED)); |
|
946 |
} |
|
947 |
if (!bounds.getLocation().equals(oldBounds.getLocation())) { |
|
948 |
postEventToEventQueue(new ComponentEvent(getEventSource(), ComponentEvent.COMPONENT_MOVED)); |
|
949 |
} |
|
950 |
// } |
|
951 |
} |
|
952 |
||
953 |
public void handleMapNotifyEvent(XEvent xev) { |
|
954 |
super.handleMapNotifyEvent(xev); |
|
955 |
log.log(Level.FINE, "Mapped {0}", new Object[] {this}); |
|
956 |
if (isEventDisabled(xev)) { |
|
957 |
return; |
|
958 |
} |
|
959 |
ComponentEvent ce; |
|
960 |
||
961 |
ce = new ComponentEvent(getEventSource(), ComponentEvent.COMPONENT_SHOWN); |
|
962 |
postEventToEventQueue(ce); |
|
963 |
} |
|
964 |
||
965 |
public void handleUnmapNotifyEvent(XEvent xev) { |
|
966 |
super.handleUnmapNotifyEvent(xev); |
|
967 |
if (isEventDisabled(xev)) { |
|
968 |
return; |
|
969 |
} |
|
970 |
ComponentEvent ce; |
|
971 |
||
972 |
ce = new ComponentEvent(target, ComponentEvent.COMPONENT_HIDDEN); |
|
973 |
postEventToEventQueue(ce); |
|
974 |
} |
|
975 |
||
976 |
private void dumpKeysymArray(XKeyEvent ev) { |
|
977 |
keyEventLog.fine(" "+Long.toHexString(XlibWrapper.XKeycodeToKeysym(XToolkit.getDisplay(), ev.get_keycode(), 0))+ |
|
978 |
"\n "+Long.toHexString(XlibWrapper.XKeycodeToKeysym(XToolkit.getDisplay(), ev.get_keycode(), 1))+ |
|
979 |
"\n "+Long.toHexString(XlibWrapper.XKeycodeToKeysym(XToolkit.getDisplay(), ev.get_keycode(), 2))+ |
|
980 |
"\n "+Long.toHexString(XlibWrapper.XKeycodeToKeysym(XToolkit.getDisplay(), ev.get_keycode(), 3))); |
|
981 |
} |
|
982 |
/** |
|
983 |
Return unicode character or 0 if no correspondent character found. |
|
984 |
Parameter is a keysym basically from keysymdef.h |
|
985 |
XXX: how about vendor keys? Is there some with Unicode value and not in the list? |
|
986 |
*/ |
|
987 |
char keysymToUnicode( long keysym, int state ) { |
|
988 |
return XKeysym.convertKeysym( keysym, state ); |
|
989 |
} |
|
990 |
int keyEventType2Id( int xEventType ) { |
|
991 |
return xEventType == XConstants.KeyPress ? java.awt.event.KeyEvent.KEY_PRESSED : |
|
992 |
xEventType == XConstants.KeyRelease ? java.awt.event.KeyEvent.KEY_RELEASED : 0; |
|
993 |
} |
|
994 |
static private long xkeycodeToKeysym(XKeyEvent ev) { |
|
995 |
return XKeysym.getKeysym( ev ); |
|
996 |
} |
|
997 |
void logIncomingKeyEvent(XKeyEvent ev) { |
|
998 |
keyEventLog.fine("--XWindow.java:handleKeyEvent:"+ev); |
|
999 |
dumpKeysymArray(ev); |
|
1000 |
keyEventLog.fine("XXXXXXXXXXXXXX javakeycode will be most probably:0x"+ Integer.toHexString(XKeysym.getJavaKeycodeOnly(ev))); |
|
1001 |
} |
|
1002 |
public void handleKeyPress(XEvent xev) { |
|
1003 |
super.handleKeyPress(xev); |
|
1004 |
XKeyEvent ev = xev.get_xkey(); |
|
1005 |
if (eventLog.isLoggable(Level.FINE)) eventLog.fine(ev.toString()); |
|
1006 |
if (isEventDisabled(xev)) { |
|
1007 |
return; |
|
1008 |
} |
|
1009 |
handleKeyPress(ev); |
|
1010 |
} |
|
1011 |
// called directly from this package, unlike handleKeyRelease. |
|
1012 |
// un-final it if you need to override it in a subclass. |
|
1013 |
final void handleKeyPress(XKeyEvent ev) { |
|
1014 |
long keysym[] = new long[2]; |
|
1015 |
char unicodeKey = 0; |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
1016 |
keysym[0] = XConstants.NoSymbol; |
2 | 1017 |
|
1018 |
if (keyEventLog.isLoggable(Level.FINE)) { |
|
1019 |
logIncomingKeyEvent( ev ); |
|
1020 |
} |
|
1021 |
if ( //TODO check if there's an active input method instance |
|
1022 |
// without calling a native method. Is it necessary though? |
|
1023 |
haveCurrentX11InputMethodInstance()) { |
|
1024 |
if (x11inputMethodLookupString(ev.pData, keysym)) { |
|
1025 |
if (keyEventLog.isLoggable(Level.FINE)) { |
|
1026 |
keyEventLog.fine("--XWindow.java XIM did process event; return; dec keysym processed:"+(keysym[0])+ |
|
1027 |
"; hex keysym processed:"+Long.toHexString(keysym[0]) |
|
1028 |
); |
|
1029 |
} |
|
1030 |
return; |
|
1031 |
}else { |
|
1032 |
unicodeKey = keysymToUnicode( keysym[0], ev.get_state() ); |
|
1033 |
if (keyEventLog.isLoggable(Level.FINE)) { |
|
1034 |
keyEventLog.fine("--XWindow.java XIM did NOT process event, hex keysym:"+Long.toHexString(keysym[0])+"\n"+ |
|
1035 |
" unicode key:"+Integer.toHexString((int)unicodeKey)); |
|
1036 |
} |
|
1037 |
} |
|
1038 |
}else { |
|
1039 |
// No input method instance found. For example, there's a Java Input Method. |
|
1040 |
// Produce do-it-yourself keysym and perhaps unicode character. |
|
1041 |
keysym[0] = xkeycodeToKeysym(ev); |
|
1042 |
unicodeKey = keysymToUnicode( keysym[0], ev.get_state() ); |
|
1043 |
if (keyEventLog.isLoggable(Level.FINE)) { |
|
1044 |
keyEventLog.fine("--XWindow.java XIM is absent; hex keysym:"+Long.toHexString(keysym[0])+"\n"+ |
|
1045 |
" unicode key:"+Integer.toHexString((int)unicodeKey)); |
|
1046 |
} |
|
1047 |
} |
|
1048 |
// Keysym should be converted to Unicode, if possible and necessary, |
|
1049 |
// and Java KeyEvent keycode should be calculated. |
|
1050 |
// For press we should post pressed & typed Java events. |
|
1051 |
// |
|
1052 |
// Press event might be not processed to this time because |
|
1053 |
// (1) either XIM could not handle it or |
|
1054 |
// (2) it was Latin 1:1 mapping. |
|
1055 |
// |
|
1056 |
XKeysym.Keysym2JavaKeycode jkc = XKeysym.getJavaKeycode(ev); |
|
1057 |
if( jkc == null ) { |
|
1058 |
jkc = new XKeysym.Keysym2JavaKeycode(java.awt.event.KeyEvent.VK_UNDEFINED, java.awt.event.KeyEvent.KEY_LOCATION_UNKNOWN); |
|
1059 |
} |
|
1060 |
if (keyEventLog.isLoggable(Level.FINE)) { |
|
1061 |
keyEventLog.fine(">>>Fire Event:"+ |
|
1062 |
(ev.get_type() == XConstants.KeyPress ? "KEY_PRESSED; " : "KEY_RELEASED; ")+ |
|
1063 |
"jkeycode:decimal="+jkc.getJavaKeycode()+ |
|
1064 |
", hex=0x"+Integer.toHexString(jkc.getJavaKeycode())+"; " |
|
1065 |
); |
|
1066 |
} |
|
1067 |
postKeyEvent( java.awt.event.KeyEvent.KEY_PRESSED, |
|
1068 |
ev.get_time(), |
|
1069 |
jkc.getJavaKeycode(), |
|
1070 |
(unicodeKey == 0 ? java.awt.event.KeyEvent.CHAR_UNDEFINED : unicodeKey), |
|
1071 |
jkc.getKeyLocation(), |
|
1072 |
ev.get_state(),ev.getPData(), XKeyEvent.getSize()); |
|
1073 |
if( unicodeKey > 0 ) { |
|
1074 |
keyEventLog.fine("fire _TYPED on "+unicodeKey); |
|
1075 |
postKeyEvent( java.awt.event.KeyEvent.KEY_TYPED, |
|
1076 |
ev.get_time(), |
|
1077 |
java.awt.event.KeyEvent.VK_UNDEFINED, |
|
1078 |
unicodeKey, |
|
1079 |
java.awt.event.KeyEvent.KEY_LOCATION_UNKNOWN, |
|
1080 |
ev.get_state(),ev.getPData(), XKeyEvent.getSize()); |
|
1081 |
} |
|
1082 |
||
1083 |
||
1084 |
} |
|
1085 |
||
1086 |
public void handleKeyRelease(XEvent xev) { |
|
1087 |
super.handleKeyRelease(xev); |
|
1088 |
XKeyEvent ev = xev.get_xkey(); |
|
1089 |
if (eventLog.isLoggable(Level.FINE)) eventLog.fine(ev.toString()); |
|
1090 |
if (isEventDisabled(xev)) { |
|
1091 |
return; |
|
1092 |
} |
|
1093 |
handleKeyRelease(ev); |
|
1094 |
} |
|
1095 |
// un-private it if you need to call it from elsewhere |
|
1096 |
private void handleKeyRelease(XKeyEvent ev) { |
|
1097 |
long keysym[] = new long[2]; |
|
1098 |
char unicodeKey = 0; |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
1099 |
keysym[0] = XConstants.NoSymbol; |
2 | 1100 |
|
1101 |
if (keyEventLog.isLoggable(Level.FINE)) { |
|
1102 |
logIncomingKeyEvent( ev ); |
|
1103 |
} |
|
1104 |
// Keysym should be converted to Unicode, if possible and necessary, |
|
1105 |
// and Java KeyEvent keycode should be calculated. |
|
1106 |
// For release we should post released event. |
|
1107 |
// |
|
1108 |
XKeysym.Keysym2JavaKeycode jkc = XKeysym.getJavaKeycode(ev); |
|
1109 |
if( jkc == null ) { |
|
1110 |
jkc = new XKeysym.Keysym2JavaKeycode(java.awt.event.KeyEvent.VK_UNDEFINED, java.awt.event.KeyEvent.KEY_LOCATION_UNKNOWN); |
|
1111 |
} |
|
1112 |
if (keyEventLog.isLoggable(Level.FINE)) { |
|
1113 |
keyEventLog.fine(">>>Fire Event:"+ |
|
1114 |
(ev.get_type() == XConstants.KeyPress ? "KEY_PRESSED; " : "KEY_RELEASED; ")+ |
|
1115 |
"jkeycode:decimal="+jkc.getJavaKeycode()+ |
|
1116 |
", hex=0x"+Integer.toHexString(jkc.getJavaKeycode())+"; " |
|
1117 |
); |
|
1118 |
} |
|
1119 |
// We obtain keysym from IM and derive unicodeKey from it for KeyPress only. |
|
1120 |
// We used to cache that value and retrieve it on KeyRelease, |
|
1121 |
// but in case for example of a dead key+vowel pair, a vowel after a deadkey |
|
1122 |
// might never be cached before. |
|
1123 |
// Also, switching between keyboard layouts, we might cache a wrong letter. |
|
1124 |
// That's why we use the same procedure as if there was no IM instance: do-it-yourself unicode. |
|
1125 |
unicodeKey = keysymToUnicode( xkeycodeToKeysym(ev), ev.get_state() ); |
|
1126 |
||
1127 |
postKeyEvent( java.awt.event.KeyEvent.KEY_RELEASED, |
|
1128 |
ev.get_time(), |
|
1129 |
jkc.getJavaKeycode(), |
|
1130 |
(unicodeKey == 0 ? java.awt.event.KeyEvent.CHAR_UNDEFINED : unicodeKey), |
|
1131 |
jkc.getKeyLocation(), |
|
1132 |
ev.get_state(),ev.getPData(), XKeyEvent.getSize()); |
|
1133 |
||
1134 |
} |
|
1135 |
||
1136 |
public void reshape(Rectangle bounds) { |
|
1137 |
reshape(bounds.x, bounds.y, bounds.width, bounds.height); |
|
1138 |
} |
|
1139 |
||
1140 |
public void reshape(int x, int y, int width, int height) { |
|
1141 |
if (width <= 0) { |
|
1142 |
width = 1; |
|
1143 |
} |
|
1144 |
if (height <= 0) { |
|
1145 |
height = 1; |
|
1146 |
} |
|
1147 |
this.x = x; |
|
1148 |
this.y = y; |
|
1149 |
this.width = width; |
|
1150 |
this.height = height; |
|
1151 |
xSetBounds(x, y, width, height); |
|
1152 |
// Fixed 6322593, 6304251, 6315137: |
|
1153 |
// XWindow's SurfaceData should be invalidated and recreated as part |
|
1154 |
// of the process of resizing the window |
|
1155 |
// see the evaluation of the bug 6304251 for more information |
|
1156 |
validateSurface(); |
|
1157 |
layout(); |
|
1158 |
} |
|
1159 |
||
1160 |
public void layout() {} |
|
1161 |
||
1162 |
boolean isShowing() { |
|
1163 |
return visible; |
|
1164 |
} |
|
1165 |
||
1166 |
boolean isResizable() { |
|
1167 |
return true; |
|
1168 |
} |
|
1169 |
||
1170 |
boolean isLocationByPlatform() { |
|
1171 |
return false; |
|
1172 |
} |
|
1173 |
||
1174 |
void updateSizeHints() { |
|
1175 |
updateSizeHints(x, y, width, height); |
|
1176 |
} |
|
1177 |
||
1178 |
void updateSizeHints(int x, int y, int width, int height) { |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
1179 |
long flags = XUtilConstants.PSize | (isLocationByPlatform() ? 0 : (XUtilConstants.PPosition | XUtilConstants.USPosition)); |
2 | 1180 |
if (!isResizable()) { |
1181 |
log.log(Level.FINER, "Window {0} is not resizable", new Object[] {this}); |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
1182 |
flags |= XUtilConstants.PMinSize | XUtilConstants.PMaxSize; |
2 | 1183 |
} else { |
1184 |
log.log(Level.FINER, "Window {0} is resizable", new Object[] {this}); |
|
1185 |
} |
|
1186 |
setSizeHints(flags, x, y, width, height); |
|
1187 |
} |
|
1188 |
||
1189 |
void updateSizeHints(int x, int y) { |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
1190 |
long flags = isLocationByPlatform() ? 0 : (XUtilConstants.PPosition | XUtilConstants.USPosition); |
2 | 1191 |
if (!isResizable()) { |
1192 |
log.log(Level.FINER, "Window {0} is not resizable", new Object[] {this}); |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
1193 |
flags |= XUtilConstants.PMinSize | XUtilConstants.PMaxSize | XUtilConstants.PSize; |
2 | 1194 |
} else { |
1195 |
log.log(Level.FINER, "Window {0} is resizable", new Object[] {this}); |
|
1196 |
} |
|
1197 |
setSizeHints(flags, x, y, width, height); |
|
1198 |
} |
|
1199 |
||
1200 |
void validateSurface() { |
|
1201 |
if ((width != oldWidth) || (height != oldHeight)) { |
|
1202 |
SurfaceData oldData = surfaceData; |
|
1203 |
if (oldData != null) { |
|
1204 |
surfaceData = graphicsConfig.createSurfaceData(this); |
|
1205 |
oldData.invalidate(); |
|
1206 |
} |
|
1207 |
oldWidth = width; |
|
1208 |
oldHeight = height; |
|
1209 |
} |
|
1210 |
} |
|
1211 |
||
1212 |
public SurfaceData getSurfaceData() { |
|
1213 |
return surfaceData; |
|
1214 |
} |
|
1215 |
||
1216 |
public void dispose() { |
|
1217 |
SurfaceData oldData = surfaceData; |
|
1218 |
surfaceData = null; |
|
1219 |
if (oldData != null) { |
|
1220 |
oldData.invalidate(); |
|
1221 |
} |
|
1222 |
XToolkit.targetDisposedPeer(target, this); |
|
1223 |
destroy(); |
|
1224 |
} |
|
1225 |
||
1226 |
public Point getLocationOnScreen() { |
|
1227 |
synchronized (target.getTreeLock()) { |
|
1228 |
Component comp = target; |
|
1229 |
||
1230 |
while (comp != null && !(comp instanceof Window)) { |
|
1231 |
comp = ComponentAccessor.getParent_NoClientCode(comp); |
|
1232 |
} |
|
1233 |
||
1234 |
// applets, embedded, etc - translate directly |
|
1235 |
// XXX: override in subclass? |
|
1236 |
if (comp == null || comp instanceof sun.awt.EmbeddedFrame) { |
|
1237 |
return toGlobal(0, 0); |
|
1238 |
} |
|
1239 |
||
1240 |
XToolkit.awtLock(); |
|
1241 |
try { |
|
1242 |
Object wpeer = XToolkit.targetToPeer(comp); |
|
1243 |
if (wpeer == null |
|
1244 |
|| !(wpeer instanceof XDecoratedPeer) |
|
1245 |
|| ((XDecoratedPeer)wpeer).configure_seen) |
|
1246 |
{ |
|
1247 |
return toGlobal(0, 0); |
|
1248 |
} |
|
1249 |
||
1250 |
// wpeer is an XDecoratedPeer not yet fully adopted by WM |
|
1251 |
Point pt = toOtherWindow(getContentWindow(), |
|
1252 |
((XDecoratedPeer)wpeer).getContentWindow(), |
|
1253 |
0, 0); |
|
1254 |
||
1255 |
if (pt == null) { |
|
1256 |
pt = new Point(((XBaseWindow)wpeer).getAbsoluteX(), ((XBaseWindow)wpeer).getAbsoluteY()); |
|
1257 |
} |
|
1258 |
pt.x += comp.getX(); |
|
1259 |
pt.y += comp.getY(); |
|
1260 |
return pt; |
|
1261 |
} finally { |
|
1262 |
XToolkit.awtUnlock(); |
|
1263 |
} |
|
1264 |
} |
|
1265 |
} |
|
1266 |
||
1267 |
||
1268 |
static Field bdata; |
|
1269 |
static void setBData(KeyEvent e, byte[] data) { |
|
1270 |
try { |
|
1271 |
if (bdata == null) { |
|
1272 |
bdata = SunToolkit.getField(java.awt.AWTEvent.class, "bdata"); |
|
1273 |
} |
|
1274 |
bdata.set(e, data); |
|
1275 |
} catch (IllegalAccessException ex) { |
|
1276 |
assert false; |
|
1277 |
} |
|
1278 |
} |
|
1279 |
||
1280 |
public void postKeyEvent(int id, long when, int keyCode, char keyChar, |
|
1281 |
int keyLocation, int state, long event, int eventSize) |
|
1282 |
{ |
|
1283 |
long jWhen = XToolkit.nowMillisUTC_offset(when); |
|
1284 |
int modifiers = getModifiers(state, 0, keyCode); |
|
1285 |
KeyEvent ke = new KeyEvent((Component)getEventSource(), id, jWhen, |
|
1286 |
modifiers, keyCode, keyChar, keyLocation); |
|
1287 |
if (event != 0) { |
|
1288 |
byte[] data = Native.toBytes(event, eventSize); |
|
1289 |
setBData(ke, data); |
|
1290 |
} |
|
1291 |
postEventToEventQueue(ke); |
|
1292 |
} |
|
1293 |
||
1294 |
static native int getAWTKeyCodeForKeySym(int keysym); |
|
1295 |
static native int getKeySymForAWTKeyCode(int keycode); |
|
1296 |
} |