author | darcy |
Thu, 13 Mar 2014 12:40:27 -0700 | |
changeset 23647 | 41d22f2dbeb5 |
parent 22584 | eed64ee05369 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
20165
diff
changeset
|
2 |
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.awt.X11; |
|
27 |
||
28 |
import java.awt.*; |
|
29 |
import java.awt.peer.ComponentPeer; |
|
30 |
import java.lang.ref.WeakReference; |
|
4371
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
439
diff
changeset
|
31 |
import sun.awt.AWTAccessor; |
2 | 32 |
|
33 |
import sun.awt.GlobalCursorManager; |
|
34 |
import sun.awt.SunToolkit; |
|
35 |
||
36 |
public final class XGlobalCursorManager extends GlobalCursorManager { |
|
37 |
||
38 |
// cached nativeContainer |
|
39 |
private WeakReference<Component> nativeContainer; |
|
40 |
||
41 |
||
42 |
/** |
|
43 |
* The XGlobalCursorManager is a singleton. |
|
44 |
*/ |
|
45 |
private static XGlobalCursorManager manager; |
|
46 |
||
47 |
||
48 |
static GlobalCursorManager getCursorManager() { |
|
49 |
if (manager == null) { |
|
50 |
manager = new XGlobalCursorManager(); |
|
51 |
} |
|
52 |
return manager; |
|
53 |
} |
|
54 |
||
55 |
/** |
|
56 |
* Should be called in response to a native mouse enter or native mouse |
|
57 |
* button released message. Should not be called during a mouse drag. |
|
58 |
*/ |
|
59 |
static void nativeUpdateCursor(Component heavy) { |
|
60 |
XGlobalCursorManager.getCursorManager().updateCursorLater(heavy); |
|
61 |
} |
|
62 |
||
63 |
||
64 |
protected void setCursor(Component comp, Cursor cursor, boolean useCache) { |
|
65 |
if (comp == null) { |
|
66 |
return; |
|
67 |
} |
|
68 |
||
69 |
Cursor cur = useCache ? cursor : getCapableCursor(comp); |
|
70 |
||
71 |
Component nc = null; |
|
72 |
if (useCache) { |
|
73 |
synchronized (this) { |
|
74 |
nc = nativeContainer.get(); |
|
75 |
} |
|
76 |
} else { |
|
4371
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
439
diff
changeset
|
77 |
nc = SunToolkit.getHeavyweightComponent(comp); |
2 | 78 |
} |
79 |
||
80 |
if (nc != null) { |
|
4371
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
439
diff
changeset
|
81 |
ComponentPeer nc_peer = AWTAccessor.getComponentAccessor().getPeer(nc); |
2 | 82 |
if (nc_peer instanceof XComponentPeer) { |
83 |
synchronized (this) { |
|
84 |
nativeContainer = new WeakReference<Component>(nc); |
|
85 |
} |
|
86 |
||
8133
c7e4a02e928e
6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
5506
diff
changeset
|
87 |
//6431076. A subcomponents (a XTextArea in particular) |
c7e4a02e928e
6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
5506
diff
changeset
|
88 |
//may want to override the cursor over some of their parts. |
c7e4a02e928e
6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
5506
diff
changeset
|
89 |
((XComponentPeer)nc_peer).pSetCursor(cur, false); |
2 | 90 |
// in case of grab we do for Swing we need to update keep cursor updated |
91 |
// (we don't need this in case of AWT menus). Window Manager consider |
|
92 |
// the grabber as a current window and use its cursor. So we need to |
|
93 |
// change cursor on the grabber too. |
|
94 |
updateGrabbedCursor(cur); |
|
95 |
} |
|
96 |
} |
|
97 |
} |
|
98 |
||
99 |
/** |
|
100 |
* Updates cursor on the grabber if it is window peer (i.e. current grab is for |
|
101 |
* Swing, not for AWT. |
|
102 |
*/ |
|
103 |
private static void updateGrabbedCursor(Cursor cur) { |
|
104 |
XBaseWindow target = XAwtState.getGrabWindow(); |
|
105 |
if (target instanceof XWindowPeer) { |
|
106 |
XWindowPeer grabber = (XWindowPeer) target; |
|
107 |
grabber.pSetCursor(cur); |
|
108 |
} |
|
109 |
} |
|
110 |
||
111 |
protected void updateCursorOutOfJava() { |
|
112 |
// in case we have grabbed input for Swing we need to reset cursor |
|
113 |
// when mouse pointer is out of any java toplevel. |
|
114 |
// let's use default cursor for this. |
|
115 |
updateGrabbedCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
|
116 |
} |
|
117 |
||
118 |
protected void getCursorPos(Point p) { |
|
119 |
||
120 |
if (!((XToolkit)Toolkit.getDefaultToolkit()).getLastCursorPos(p)) { |
|
121 |
XToolkit.awtLock(); |
|
122 |
try { |
|
123 |
long display = XToolkit.getDisplay(); |
|
124 |
long root_window = XlibWrapper.RootWindow(display, |
|
125 |
XlibWrapper.DefaultScreen(display)); |
|
126 |
||
127 |
XlibWrapper.XQueryPointer(display, root_window, |
|
128 |
XlibWrapper.larg1, |
|
129 |
XlibWrapper.larg2, |
|
130 |
XlibWrapper.larg3, |
|
131 |
XlibWrapper.larg4, |
|
132 |
XlibWrapper.larg5, |
|
133 |
XlibWrapper.larg6, |
|
134 |
XlibWrapper.larg7); |
|
135 |
||
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
20165
diff
changeset
|
136 |
p.x = XlibWrapper.unsafe.getInt(XlibWrapper.larg3); |
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
20165
diff
changeset
|
137 |
p.y = XlibWrapper.unsafe.getInt(XlibWrapper.larg4); |
2 | 138 |
} finally { |
139 |
XToolkit.awtUnlock(); |
|
140 |
} |
|
141 |
} |
|
142 |
} |
|
143 |
protected Component findHeavyweightUnderCursor() { |
|
144 |
return XAwtState.getComponentMouseEntered(); |
|
145 |
} |
|
146 |
||
147 |
/* |
|
20165
75e673bbdba6
8007155: [macosx] Disabled panel takes mouse input in JLayeredPane
alexsch
parents:
13604
diff
changeset
|
148 |
* native method to call corresponding methods in Component |
2 | 149 |
*/ |
150 |
protected Point getLocationOnScreen(Component c) { |
|
151 |
return c.getLocationOnScreen(); |
|
152 |
} |
|
153 |
||
154 |
protected Component findHeavyweightUnderCursor(boolean useCache) { |
|
155 |
return findHeavyweightUnderCursor(); |
|
156 |
} |
|
157 |
||
158 |
private Cursor getCapableCursor(Component comp) { |
|
4371
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
439
diff
changeset
|
159 |
AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor(); |
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
439
diff
changeset
|
160 |
|
2 | 161 |
Component c = comp; |
162 |
while ((c != null) && !(c instanceof Window) |
|
4371
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
439
diff
changeset
|
163 |
&& compAccessor.isEnabled(c) |
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
439
diff
changeset
|
164 |
&& compAccessor.isVisible(c) |
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
439
diff
changeset
|
165 |
&& compAccessor.isDisplayable(c)) |
2 | 166 |
{ |
4371
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
439
diff
changeset
|
167 |
c = compAccessor.getParent(c); |
2 | 168 |
} |
169 |
if (c instanceof Window) { |
|
4371
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
439
diff
changeset
|
170 |
return (compAccessor.isEnabled(c) |
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
439
diff
changeset
|
171 |
&& compAccessor.isVisible(c) |
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
439
diff
changeset
|
172 |
&& compAccessor.isDisplayable(c) |
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
439
diff
changeset
|
173 |
&& compAccessor.isEnabled(comp)) |
2 | 174 |
? |
4371
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
439
diff
changeset
|
175 |
compAccessor.getCursor(comp) |
2 | 176 |
: |
177 |
Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); |
|
178 |
} else if (c == null) { |
|
179 |
return null; |
|
180 |
} |
|
4371
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
439
diff
changeset
|
181 |
return getCapableCursor(compAccessor.getParent(c)); |
2 | 182 |
} |
183 |
||
184 |
/* This methods needs to be called from within XToolkit.awtLock / XToolkit.awtUnlock section. */ |
|
185 |
||
186 |
static long getCursor(Cursor c) { |
|
187 |
||
188 |
long pData = 0; |
|
189 |
int type = 0; |
|
190 |
try { |
|
13604 | 191 |
pData = AWTAccessor.getCursorAccessor().getPData(c); |
192 |
type = AWTAccessor.getCursorAccessor().getType(c); |
|
2 | 193 |
} |
194 |
catch (Exception e) |
|
195 |
{ |
|
196 |
e.printStackTrace(); |
|
197 |
} |
|
198 |
||
199 |
if (pData != 0) return pData; |
|
200 |
||
201 |
int cursorType = 0; |
|
202 |
switch (type) { |
|
203 |
case Cursor.DEFAULT_CURSOR: |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
2
diff
changeset
|
204 |
cursorType = XCursorFontConstants.XC_left_ptr; |
2 | 205 |
break; |
206 |
case Cursor.CROSSHAIR_CURSOR: |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
2
diff
changeset
|
207 |
cursorType = XCursorFontConstants.XC_crosshair; |
2 | 208 |
break; |
209 |
case Cursor.TEXT_CURSOR: |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
2
diff
changeset
|
210 |
cursorType = XCursorFontConstants.XC_xterm; |
2 | 211 |
break; |
212 |
case Cursor.WAIT_CURSOR: |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
2
diff
changeset
|
213 |
cursorType = XCursorFontConstants.XC_watch; |
2 | 214 |
break; |
215 |
case Cursor.SW_RESIZE_CURSOR: |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
2
diff
changeset
|
216 |
cursorType = XCursorFontConstants.XC_bottom_left_corner; |
2 | 217 |
break; |
218 |
case Cursor.NW_RESIZE_CURSOR: |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
2
diff
changeset
|
219 |
cursorType = XCursorFontConstants.XC_top_left_corner; |
2 | 220 |
break; |
221 |
case Cursor.SE_RESIZE_CURSOR: |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
2
diff
changeset
|
222 |
cursorType = XCursorFontConstants.XC_bottom_right_corner; |
2 | 223 |
break; |
224 |
case Cursor.NE_RESIZE_CURSOR: |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
2
diff
changeset
|
225 |
cursorType = XCursorFontConstants.XC_top_right_corner; |
2 | 226 |
break; |
227 |
case Cursor.S_RESIZE_CURSOR: |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
2
diff
changeset
|
228 |
cursorType = XCursorFontConstants.XC_bottom_side; |
2 | 229 |
break; |
230 |
case Cursor.N_RESIZE_CURSOR: |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
2
diff
changeset
|
231 |
cursorType = XCursorFontConstants.XC_top_side; |
2 | 232 |
break; |
233 |
case Cursor.W_RESIZE_CURSOR: |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
2
diff
changeset
|
234 |
cursorType = XCursorFontConstants.XC_left_side; |
2 | 235 |
break; |
236 |
case Cursor.E_RESIZE_CURSOR: |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
2
diff
changeset
|
237 |
cursorType = XCursorFontConstants.XC_right_side; |
2 | 238 |
break; |
239 |
case Cursor.HAND_CURSOR: |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
2
diff
changeset
|
240 |
cursorType = XCursorFontConstants.XC_hand2; |
2 | 241 |
break; |
242 |
case Cursor.MOVE_CURSOR: |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
2
diff
changeset
|
243 |
cursorType = XCursorFontConstants.XC_fleur; |
2 | 244 |
break; |
245 |
} |
|
246 |
||
247 |
XToolkit.awtLock(); |
|
248 |
try { |
|
249 |
pData =(long) XlibWrapper.XCreateFontCursor(XToolkit.getDisplay(), cursorType); |
|
250 |
} |
|
251 |
finally { |
|
252 |
XToolkit.awtUnlock(); |
|
253 |
} |
|
254 |
||
255 |
setPData(c,pData); |
|
256 |
return pData; |
|
257 |
} |
|
258 |
||
259 |
||
260 |
static void setPData(Cursor c, long pData) { |
|
261 |
try { |
|
13604 | 262 |
AWTAccessor.getCursorAccessor().setPData(c, pData); |
2 | 263 |
} |
264 |
catch (Exception e) |
|
265 |
{ |
|
266 |
e.printStackTrace(); |
|
267 |
} |
|
268 |
||
269 |
} |
|
270 |
} |