author | ohair |
Tue, 28 Dec 2010 15:53:50 -0800 | |
changeset 7668 | d4a77089c587 |
parent 6645 | 63ea2d282026 |
child 7762 | 6e45e1e87347 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7668 | 2 |
* Copyright (c) 1996, 2010, 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 |
package sun.awt.windows; |
|
26 |
||
27 |
import java.awt.*; |
|
28 |
import java.awt.peer.*; |
|
29 |
import java.awt.image.VolatileImage; |
|
30 |
import sun.awt.RepaintArea; |
|
31 |
import sun.awt.CausedFocusEvent; |
|
32 |
import sun.awt.image.SunVolatileImage; |
|
33 |
import sun.awt.image.ToolkitImage; |
|
34 |
import java.awt.image.BufferedImage; |
|
35 |
import java.awt.image.ImageProducer; |
|
36 |
import java.awt.image.ImageObserver; |
|
37 |
import java.awt.image.ColorModel; |
|
38 |
import java.awt.event.PaintEvent; |
|
39 |
import java.awt.event.InvocationEvent; |
|
40 |
import java.awt.event.KeyEvent; |
|
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
41 |
import java.awt.event.FocusEvent; |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
42 |
import java.awt.event.MouseEvent; |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
43 |
import java.awt.event.MouseWheelEvent; |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
44 |
import java.awt.event.InputEvent; |
2 | 45 |
import sun.awt.Win32GraphicsConfig; |
2451 | 46 |
import sun.awt.Win32GraphicsEnvironment; |
2 | 47 |
import sun.java2d.InvalidPipeException; |
48 |
import sun.java2d.SurfaceData; |
|
887 | 49 |
import sun.java2d.ScreenUpdateManager; |
2451 | 50 |
import sun.java2d.d3d.D3DSurfaceData; |
2 | 51 |
import sun.java2d.opengl.OGLSurfaceData; |
2451 | 52 |
import sun.java2d.pipe.Region; |
2 | 53 |
import sun.awt.DisplayChangedListener; |
54 |
import sun.awt.PaintEventDispatcher; |
|
2451 | 55 |
import sun.awt.SunToolkit; |
2 | 56 |
import sun.awt.event.IgnorePaintEvent; |
57 |
||
58 |
import java.awt.dnd.DropTarget; |
|
59 |
import java.awt.dnd.peer.DropTargetPeer; |
|
4371
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
4259
diff
changeset
|
60 |
import sun.awt.AWTAccessor; |
2 | 61 |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3084
diff
changeset
|
62 |
import sun.util.logging.PlatformLogger; |
2 | 63 |
|
64 |
public abstract class WComponentPeer extends WObjectPeer |
|
2459
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2451
diff
changeset
|
65 |
implements ComponentPeer, DropTargetPeer |
2 | 66 |
{ |
67 |
/** |
|
68 |
* Handle to native window |
|
69 |
*/ |
|
70 |
protected volatile long hwnd; |
|
71 |
||
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3084
diff
changeset
|
72 |
private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.windows.WComponentPeer"); |
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3084
diff
changeset
|
73 |
private static final PlatformLogger shapeLog = PlatformLogger.getLogger("sun.awt.windows.shape.WComponentPeer"); |
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3084
diff
changeset
|
74 |
private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.windows.focus.WComponentPeer"); |
2 | 75 |
|
76 |
// ComponentPeer implementation |
|
77 |
SurfaceData surfaceData; |
|
78 |
||
79 |
private RepaintArea paintArea; |
|
80 |
||
81 |
protected Win32GraphicsConfig winGraphicsConfig; |
|
82 |
||
83 |
boolean isLayouting = false; |
|
84 |
boolean paintPending = false; |
|
85 |
int oldWidth = -1; |
|
86 |
int oldHeight = -1; |
|
87 |
private int numBackBuffers = 0; |
|
88 |
private VolatileImage backBuffer = null; |
|
887 | 89 |
private BufferCapabilities backBufferCaps = null; |
2 | 90 |
|
91 |
// foreground, background and color are cached to avoid calling back |
|
92 |
// into the Component. |
|
93 |
private Color foreground; |
|
94 |
private Color background; |
|
95 |
private Font font; |
|
96 |
||
97 |
public native boolean isObscured(); |
|
98 |
public boolean canDetermineObscurity() { return true; } |
|
99 |
||
100 |
// DropTarget support |
|
101 |
||
102 |
int nDropTargets; |
|
103 |
long nativeDropTargetContext; // native pointer |
|
104 |
||
105 |
public synchronized native void pShow(); |
|
106 |
public synchronized native void hide(); |
|
107 |
public synchronized native void enable(); |
|
108 |
public synchronized native void disable(); |
|
109 |
||
110 |
public long getHWnd() { |
|
111 |
return hwnd; |
|
112 |
} |
|
113 |
||
114 |
/* New 1.1 API */ |
|
115 |
public native Point getLocationOnScreen(); |
|
116 |
||
117 |
/* New 1.1 API */ |
|
118 |
public void setVisible(boolean b) { |
|
119 |
if (b) { |
|
120 |
show(); |
|
121 |
} else { |
|
122 |
hide(); |
|
123 |
} |
|
124 |
} |
|
125 |
||
126 |
public void show() { |
|
127 |
Dimension s = ((Component)target).getSize(); |
|
128 |
oldHeight = s.height; |
|
129 |
oldWidth = s.width; |
|
130 |
pShow(); |
|
131 |
} |
|
132 |
||
133 |
/* New 1.1 API */ |
|
134 |
public void setEnabled(boolean b) { |
|
135 |
if (b) { |
|
136 |
enable(); |
|
137 |
} else { |
|
138 |
disable(); |
|
139 |
} |
|
140 |
} |
|
141 |
||
142 |
public int serialNum = 0; |
|
143 |
||
144 |
private native void reshapeNoCheck(int x, int y, int width, int height); |
|
145 |
||
146 |
/* New 1.1 API */ |
|
147 |
public void setBounds(int x, int y, int width, int height, int op) { |
|
148 |
// Should set paintPending before reahape to prevent |
|
149 |
// thread race between paint events |
|
150 |
// Native components do redraw after resize |
|
151 |
paintPending = (width != oldWidth) || (height != oldHeight); |
|
152 |
||
153 |
if ( (op & NO_EMBEDDED_CHECK) != 0 ) { |
|
154 |
reshapeNoCheck(x, y, width, height); |
|
155 |
} else { |
|
156 |
reshape(x, y, width, height); |
|
157 |
} |
|
158 |
if ((width != oldWidth) || (height != oldHeight)) { |
|
159 |
// Only recreate surfaceData if this setBounds is called |
|
160 |
// for a resize; a simple move should not trigger a recreation |
|
161 |
try { |
|
162 |
replaceSurfaceData(); |
|
163 |
} catch (InvalidPipeException e) { |
|
164 |
// REMIND : what do we do if our surface creation failed? |
|
165 |
} |
|
166 |
oldWidth = width; |
|
167 |
oldHeight = height; |
|
168 |
} |
|
169 |
||
170 |
serialNum++; |
|
171 |
} |
|
172 |
||
173 |
/* |
|
174 |
* Called from native code (on Toolkit thread) in order to |
|
175 |
* dynamically layout the Container during resizing |
|
176 |
*/ |
|
177 |
void dynamicallyLayoutContainer() { |
|
178 |
// If we got the WM_SIZING, this must be a Container, right? |
|
179 |
// In fact, it must be the top-level Container. |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3084
diff
changeset
|
180 |
if (log.isLoggable(PlatformLogger.FINE)) { |
2 | 181 |
Container parent = WToolkit.getNativeContainer((Component)target); |
182 |
if (parent != null) { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3084
diff
changeset
|
183 |
log.fine("Assertion (parent == null) failed"); |
2 | 184 |
} |
185 |
} |
|
186 |
final Container cont = (Container)target; |
|
187 |
||
188 |
WToolkit.executeOnEventHandlerThread(cont, new Runnable() { |
|
189 |
public void run() { |
|
190 |
// Discarding old paint events doesn't seem to be necessary. |
|
191 |
cont.invalidate(); |
|
192 |
cont.validate(); |
|
193 |
||
2451 | 194 |
if (surfaceData instanceof D3DSurfaceData.D3DWindowSurfaceData || |
887 | 195 |
surfaceData instanceof OGLSurfaceData) |
196 |
{ |
|
197 |
// When OGL or D3D is enabled, it is necessary to |
|
2 | 198 |
// replace the SurfaceData for each dynamic layout |
887 | 199 |
// request so that the viewport stays in sync |
2 | 200 |
// with the window bounds. |
201 |
try { |
|
202 |
replaceSurfaceData(); |
|
203 |
} catch (InvalidPipeException e) { |
|
204 |
// REMIND: this is unlikely to occur for OGL, but |
|
205 |
// what do we do if surface creation fails? |
|
206 |
} |
|
207 |
} |
|
208 |
||
209 |
// Forcing a paint here doesn't seem to be necessary. |
|
210 |
// paintDamagedAreaImmediately(); |
|
211 |
} |
|
212 |
}); |
|
213 |
} |
|
214 |
||
215 |
/* |
|
216 |
* Paints any portion of the component that needs updating |
|
217 |
* before the call returns (similar to the Win32 API UpdateWindow) |
|
218 |
*/ |
|
219 |
void paintDamagedAreaImmediately() { |
|
220 |
// force Windows to send any pending WM_PAINT events so |
|
221 |
// the damage area is updated on the Java side |
|
222 |
updateWindow(); |
|
223 |
// make sure paint events are transferred to main event queue |
|
224 |
// for coalescing |
|
225 |
WToolkit.getWToolkit().flushPendingEvents(); |
|
226 |
// paint the damaged area |
|
227 |
paintArea.paint(target, shouldClearRectBeforePaint()); |
|
228 |
} |
|
229 |
||
230 |
native synchronized void updateWindow(); |
|
231 |
||
232 |
public void paint(Graphics g) { |
|
233 |
((Component)target).paint(g); |
|
234 |
} |
|
235 |
||
236 |
public void repaint(long tm, int x, int y, int width, int height) { |
|
237 |
} |
|
238 |
||
239 |
private static final double BANDING_DIVISOR = 4.0; |
|
240 |
private native int[] createPrintedPixels(int srcX, int srcY, |
|
2808
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2805
diff
changeset
|
241 |
int srcW, int srcH, |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2805
diff
changeset
|
242 |
int alpha); |
2 | 243 |
public void print(Graphics g) { |
244 |
||
245 |
Component comp = (Component)target; |
|
246 |
||
247 |
// To conserve memory usage, we will band the image. |
|
248 |
||
249 |
int totalW = comp.getWidth(); |
|
250 |
int totalH = comp.getHeight(); |
|
251 |
||
252 |
int hInc = (int)(totalH / BANDING_DIVISOR); |
|
253 |
if (hInc == 0) { |
|
254 |
hInc = totalH; |
|
255 |
} |
|
256 |
||
257 |
for (int startY = 0; startY < totalH; startY += hInc) { |
|
258 |
int endY = startY + hInc - 1; |
|
259 |
if (endY >= totalH) { |
|
260 |
endY = totalH - 1; |
|
261 |
} |
|
262 |
int h = endY - startY + 1; |
|
263 |
||
2808
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2805
diff
changeset
|
264 |
Color bgColor = comp.getBackground(); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2805
diff
changeset
|
265 |
int[] pix = createPrintedPixels(0, startY, totalW, h, |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2805
diff
changeset
|
266 |
bgColor == null ? 255 : bgColor.getAlpha()); |
2 | 267 |
if (pix != null) { |
268 |
BufferedImage bim = new BufferedImage(totalW, h, |
|
2451 | 269 |
BufferedImage.TYPE_INT_ARGB); |
2 | 270 |
bim.setRGB(0, 0, totalW, h, pix, 0, totalW); |
271 |
g.drawImage(bim, 0, startY, null); |
|
272 |
bim.flush(); |
|
273 |
} |
|
274 |
} |
|
275 |
||
276 |
comp.print(g); |
|
277 |
} |
|
278 |
||
279 |
public void coalescePaintEvent(PaintEvent e) { |
|
280 |
Rectangle r = e.getUpdateRect(); |
|
281 |
if (!(e instanceof IgnorePaintEvent)) { |
|
282 |
paintArea.add(r, e.getID()); |
|
283 |
} |
|
284 |
||
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3084
diff
changeset
|
285 |
if (log.isLoggable(PlatformLogger.FINEST)) { |
2 | 286 |
switch(e.getID()) { |
287 |
case PaintEvent.UPDATE: |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3084
diff
changeset
|
288 |
log.finest("coalescePaintEvent: UPDATE: add: x = " + |
2 | 289 |
r.x + ", y = " + r.y + ", width = " + r.width + ", height = " + r.height); |
290 |
return; |
|
291 |
case PaintEvent.PAINT: |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3084
diff
changeset
|
292 |
log.finest("coalescePaintEvent: PAINT: add: x = " + |
2 | 293 |
r.x + ", y = " + r.y + ", width = " + r.width + ", height = " + r.height); |
294 |
return; |
|
295 |
} |
|
296 |
} |
|
297 |
} |
|
298 |
||
299 |
public synchronized native void reshape(int x, int y, int width, int height); |
|
300 |
||
301 |
// returns true if the event has been handled and shouldn't be propagated |
|
302 |
// though handleEvent method chain - e.g. WTextFieldPeer returns true |
|
303 |
// on handling '\n' to prevent it from being passed to native code |
|
304 |
public boolean handleJavaKeyEvent(KeyEvent e) { return false; } |
|
305 |
||
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
306 |
public void handleJavaMouseEvent(MouseEvent e) { |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
307 |
switch (e.getID()) { |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
308 |
case MouseEvent.MOUSE_PRESSED: |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
309 |
// Note that Swing requests focus in its own mouse event handler. |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
310 |
if (target == e.getSource() && |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
311 |
!((Component)target).isFocusOwner() && |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
312 |
WKeyboardFocusManagerPeer.shouldFocusOnClick((Component)target)) |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
313 |
{ |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
314 |
WKeyboardFocusManagerPeer.requestFocusFor((Component)target, |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
315 |
CausedFocusEvent.Cause.MOUSE_EVENT); |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
316 |
} |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
317 |
break; |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
318 |
} |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
319 |
} |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
320 |
|
2 | 321 |
native void nativeHandleEvent(AWTEvent e); |
322 |
||
323 |
public void handleEvent(AWTEvent e) { |
|
324 |
int id = e.getID(); |
|
325 |
||
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
326 |
if ((e instanceof InputEvent) && !((InputEvent)e).isConsumed() && |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
327 |
((Component)target).isEnabled()) |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
328 |
{ |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
329 |
if (e instanceof MouseEvent && !(e instanceof MouseWheelEvent)) { |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
330 |
handleJavaMouseEvent((MouseEvent) e); |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
331 |
} else if (e instanceof KeyEvent) { |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
332 |
if (handleJavaKeyEvent((KeyEvent)e)) { |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
333 |
return; |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
334 |
} |
2 | 335 |
} |
336 |
} |
|
337 |
||
338 |
switch(id) { |
|
339 |
case PaintEvent.PAINT: |
|
340 |
// Got native painting |
|
341 |
paintPending = false; |
|
342 |
// Fallthrough to next statement |
|
343 |
case PaintEvent.UPDATE: |
|
344 |
// Skip all painting while layouting and all UPDATEs |
|
345 |
// while waiting for native paint |
|
346 |
if (!isLayouting && ! paintPending) { |
|
347 |
paintArea.paint(target,shouldClearRectBeforePaint()); |
|
348 |
} |
|
349 |
return; |
|
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
350 |
case FocusEvent.FOCUS_LOST: |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
351 |
case FocusEvent.FOCUS_GAINED: |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
352 |
handleJavaFocusEvent((FocusEvent)e); |
2 | 353 |
default: |
354 |
break; |
|
355 |
} |
|
356 |
||
357 |
// Call the native code |
|
358 |
nativeHandleEvent(e); |
|
359 |
} |
|
360 |
||
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
361 |
void handleJavaFocusEvent(FocusEvent fe) { |
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3084
diff
changeset
|
362 |
if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer(fe.toString()); |
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
363 |
setFocus(fe.getID() == FocusEvent.FOCUS_GAINED); |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
364 |
} |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
365 |
|
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
366 |
native void setFocus(boolean doSetFocus); |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
367 |
|
2 | 368 |
public Dimension getMinimumSize() { |
369 |
return ((Component)target).getSize(); |
|
370 |
} |
|
371 |
||
372 |
public Dimension getPreferredSize() { |
|
373 |
return getMinimumSize(); |
|
374 |
} |
|
375 |
||
376 |
// Do nothing for heavyweight implementation |
|
377 |
public void layout() {} |
|
378 |
||
379 |
public Rectangle getBounds() { |
|
380 |
return ((Component)target).getBounds(); |
|
381 |
} |
|
382 |
||
383 |
public boolean isFocusable() { |
|
384 |
return false; |
|
385 |
} |
|
386 |
||
387 |
/* |
|
388 |
* Return the GraphicsConfiguration associated with this peer, either |
|
389 |
* the locally stored winGraphicsConfig, or that of the target Component. |
|
390 |
*/ |
|
391 |
public GraphicsConfiguration getGraphicsConfiguration() { |
|
392 |
if (winGraphicsConfig != null) { |
|
393 |
return winGraphicsConfig; |
|
394 |
} |
|
395 |
else { |
|
396 |
// we don't need a treelock here, since |
|
397 |
// Component.getGraphicsConfiguration() gets it itself. |
|
398 |
return ((Component)target).getGraphicsConfiguration(); |
|
399 |
} |
|
400 |
} |
|
401 |
||
402 |
public SurfaceData getSurfaceData() { |
|
403 |
return surfaceData; |
|
404 |
} |
|
405 |
||
406 |
/** |
|
407 |
* Creates new surfaceData object and invalidates the previous |
|
408 |
* surfaceData object. |
|
409 |
* Replacing the surface data should never lock on any resources which are |
|
410 |
* required by other threads which may have them and may require |
|
411 |
* the tree-lock. |
|
412 |
* This is a degenerate version of replaceSurfaceData(numBackBuffers), so |
|
413 |
* just call that version with our current numBackBuffers. |
|
414 |
*/ |
|
415 |
public void replaceSurfaceData() { |
|
887 | 416 |
replaceSurfaceData(this.numBackBuffers, this.backBufferCaps); |
2 | 417 |
} |
418 |
||
3084
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2808
diff
changeset
|
419 |
public void createScreenSurface(boolean isResize) |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2808
diff
changeset
|
420 |
{ |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2808
diff
changeset
|
421 |
Win32GraphicsConfig gc = (Win32GraphicsConfig)getGraphicsConfiguration(); |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2808
diff
changeset
|
422 |
ScreenUpdateManager mgr = ScreenUpdateManager.getInstance(); |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2808
diff
changeset
|
423 |
|
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2808
diff
changeset
|
424 |
surfaceData = mgr.createScreenSurface(gc, this, numBackBuffers, isResize); |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2808
diff
changeset
|
425 |
} |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2808
diff
changeset
|
426 |
|
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2808
diff
changeset
|
427 |
|
2 | 428 |
/** |
429 |
* Multi-buffer version of replaceSurfaceData. This version is called |
|
430 |
* by createBuffers(), which needs to acquire the same locks in the same |
|
431 |
* order, but also needs to perform additional functions inside the |
|
432 |
* locks. |
|
433 |
*/ |
|
887 | 434 |
public void replaceSurfaceData(int newNumBackBuffers, |
435 |
BufferCapabilities caps) |
|
436 |
{ |
|
437 |
SurfaceData oldData = null; |
|
438 |
VolatileImage oldBB = null; |
|
2 | 439 |
synchronized(((Component)target).getTreeLock()) { |
440 |
synchronized(this) { |
|
441 |
if (pData == 0) { |
|
442 |
return; |
|
443 |
} |
|
444 |
numBackBuffers = newNumBackBuffers; |
|
887 | 445 |
ScreenUpdateManager mgr = ScreenUpdateManager.getInstance(); |
446 |
oldData = surfaceData; |
|
447 |
mgr.dropScreenSurface(oldData); |
|
3084
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2808
diff
changeset
|
448 |
createScreenSurface(true); |
2 | 449 |
if (oldData != null) { |
450 |
oldData.invalidate(); |
|
451 |
} |
|
452 |
||
887 | 453 |
oldBB = backBuffer; |
454 |
if (numBackBuffers > 0) { |
|
455 |
// set the caps first, they're used when creating the bb |
|
456 |
backBufferCaps = caps; |
|
3084
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2808
diff
changeset
|
457 |
Win32GraphicsConfig gc = |
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2808
diff
changeset
|
458 |
(Win32GraphicsConfig)getGraphicsConfiguration(); |
887 | 459 |
backBuffer = gc.createBackBuffer(this); |
460 |
} else if (backBuffer != null) { |
|
461 |
backBufferCaps = null; |
|
2 | 462 |
backBuffer = null; |
463 |
} |
|
464 |
} |
|
465 |
} |
|
887 | 466 |
// it would be better to do this before we create new ones, |
467 |
// but then we'd run into deadlock issues |
|
468 |
if (oldData != null) { |
|
469 |
oldData.flush(); |
|
470 |
// null out the old data to make it collected faster |
|
471 |
oldData = null; |
|
472 |
} |
|
473 |
if (oldBB != null) { |
|
474 |
oldBB.flush(); |
|
475 |
// null out the old data to make it collected faster |
|
476 |
oldData = null; |
|
477 |
} |
|
2 | 478 |
} |
479 |
||
480 |
public void replaceSurfaceDataLater() { |
|
481 |
Runnable r = new Runnable() { |
|
482 |
public void run() { |
|
483 |
// Shouldn't do anything if object is disposed in meanwhile |
|
484 |
// No need for sync as disposeAction in Window is performed |
|
485 |
// on EDT |
|
486 |
if (!isDisposed()) { |
|
487 |
try { |
|
488 |
replaceSurfaceData(); |
|
489 |
} catch (InvalidPipeException e) { |
|
490 |
// REMIND : what do we do if our surface creation failed? |
|
491 |
} |
|
492 |
} |
|
493 |
} |
|
494 |
}; |
|
495 |
// Fix 6255371. |
|
496 |
if (!PaintEventDispatcher.getPaintEventDispatcher().queueSurfaceDataReplacing((Component)target, r)) { |
|
497 |
postEvent(new InvocationEvent(Toolkit.getDefaultToolkit(), r)); |
|
498 |
} |
|
499 |
} |
|
500 |
||
2805
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2648
diff
changeset
|
501 |
public boolean updateGraphicsData(GraphicsConfiguration gc) { |
2459
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2451
diff
changeset
|
502 |
winGraphicsConfig = (Win32GraphicsConfig)gc; |
2 | 503 |
try { |
504 |
replaceSurfaceData(); |
|
505 |
} catch (InvalidPipeException e) { |
|
506 |
// REMIND : what do we do if our surface creation failed? |
|
507 |
} |
|
2805
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2648
diff
changeset
|
508 |
return false; |
2 | 509 |
} |
510 |
||
511 |
//This will return null for Components not yet added to a Container |
|
512 |
public ColorModel getColorModel() { |
|
513 |
GraphicsConfiguration gc = getGraphicsConfiguration(); |
|
514 |
if (gc != null) { |
|
515 |
return gc.getColorModel(); |
|
516 |
} |
|
517 |
else { |
|
518 |
return null; |
|
519 |
} |
|
520 |
} |
|
521 |
||
522 |
//This will return null for Components not yet added to a Container |
|
523 |
public ColorModel getDeviceColorModel() { |
|
524 |
Win32GraphicsConfig gc = |
|
525 |
(Win32GraphicsConfig)getGraphicsConfiguration(); |
|
526 |
if (gc != null) { |
|
527 |
return gc.getDeviceColorModel(); |
|
528 |
} |
|
529 |
else { |
|
530 |
return null; |
|
531 |
} |
|
532 |
} |
|
533 |
||
534 |
//Returns null for Components not yet added to a Container |
|
535 |
public ColorModel getColorModel(int transparency) { |
|
536 |
// return WToolkit.config.getColorModel(transparency); |
|
537 |
GraphicsConfiguration gc = getGraphicsConfiguration(); |
|
538 |
if (gc != null) { |
|
539 |
return gc.getColorModel(transparency); |
|
540 |
} |
|
541 |
else { |
|
542 |
return null; |
|
543 |
} |
|
544 |
} |
|
545 |
public java.awt.Toolkit getToolkit() { |
|
546 |
return Toolkit.getDefaultToolkit(); |
|
547 |
} |
|
548 |
||
549 |
// fallback default font object |
|
550 |
final static Font defaultFont = new Font(Font.DIALOG, Font.PLAIN, 12); |
|
551 |
||
552 |
public Graphics getGraphics() { |
|
4258
50b23b28d857
6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents:
3084
diff
changeset
|
553 |
if (isDisposed()) { |
50b23b28d857
6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents:
3084
diff
changeset
|
554 |
return null; |
50b23b28d857
6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents:
3084
diff
changeset
|
555 |
} |
50b23b28d857
6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents:
3084
diff
changeset
|
556 |
|
50b23b28d857
6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents:
3084
diff
changeset
|
557 |
Component target = (Component)getTarget(); |
50b23b28d857
6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents:
3084
diff
changeset
|
558 |
Window window = SunToolkit.getContainingWindow(target); |
6645
63ea2d282026
6982279: java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java failed due to NPE
anthony
parents:
5506
diff
changeset
|
559 |
if (window != null) { |
4258
50b23b28d857
6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents:
3084
diff
changeset
|
560 |
Graphics g = |
50b23b28d857
6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents:
3084
diff
changeset
|
561 |
((WWindowPeer)window.getPeer()).getTranslucentGraphics(); |
6645
63ea2d282026
6982279: java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java failed due to NPE
anthony
parents:
5506
diff
changeset
|
562 |
// getTranslucentGraphics() returns non-null value for non-opaque windows only |
63ea2d282026
6982279: java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java failed due to NPE
anthony
parents:
5506
diff
changeset
|
563 |
if (g != null) { |
63ea2d282026
6982279: java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java failed due to NPE
anthony
parents:
5506
diff
changeset
|
564 |
// Non-opaque windows do not support heavyweight children. |
63ea2d282026
6982279: java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java failed due to NPE
anthony
parents:
5506
diff
changeset
|
565 |
// Redirect all painting to the Window's Graphics instead. |
63ea2d282026
6982279: java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java failed due to NPE
anthony
parents:
5506
diff
changeset
|
566 |
// The caller is responsible for calling the |
63ea2d282026
6982279: java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java failed due to NPE
anthony
parents:
5506
diff
changeset
|
567 |
// WindowPeer.updateWindow() after painting has finished. |
63ea2d282026
6982279: java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java failed due to NPE
anthony
parents:
5506
diff
changeset
|
568 |
int x = 0, y = 0; |
63ea2d282026
6982279: java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java failed due to NPE
anthony
parents:
5506
diff
changeset
|
569 |
for (Component c = target; c != window; c = c.getParent()) { |
63ea2d282026
6982279: java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java failed due to NPE
anthony
parents:
5506
diff
changeset
|
570 |
x += c.getX(); |
63ea2d282026
6982279: java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java failed due to NPE
anthony
parents:
5506
diff
changeset
|
571 |
y += c.getY(); |
63ea2d282026
6982279: java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java failed due to NPE
anthony
parents:
5506
diff
changeset
|
572 |
} |
4258
50b23b28d857
6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents:
3084
diff
changeset
|
573 |
|
6645
63ea2d282026
6982279: java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java failed due to NPE
anthony
parents:
5506
diff
changeset
|
574 |
g.translate(x, y); |
63ea2d282026
6982279: java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java failed due to NPE
anthony
parents:
5506
diff
changeset
|
575 |
g.clipRect(0, 0, target.getWidth(), target.getHeight()); |
4258
50b23b28d857
6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents:
3084
diff
changeset
|
576 |
|
6645
63ea2d282026
6982279: java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java failed due to NPE
anthony
parents:
5506
diff
changeset
|
577 |
return g; |
63ea2d282026
6982279: java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java failed due to NPE
anthony
parents:
5506
diff
changeset
|
578 |
} |
4258
50b23b28d857
6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents:
3084
diff
changeset
|
579 |
} |
50b23b28d857
6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents:
3084
diff
changeset
|
580 |
|
2 | 581 |
SurfaceData surfaceData = this.surfaceData; |
4258
50b23b28d857
6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
anthony
parents:
3084
diff
changeset
|
582 |
if (surfaceData != null) { |
2 | 583 |
/* Fix for bug 4746122. Color and Font shouldn't be null */ |
584 |
Color bgColor = background; |
|
585 |
if (bgColor == null) { |
|
586 |
bgColor = SystemColor.window; |
|
587 |
} |
|
588 |
Color fgColor = foreground; |
|
589 |
if (fgColor == null) { |
|
590 |
fgColor = SystemColor.windowText; |
|
591 |
} |
|
592 |
Font font = this.font; |
|
593 |
if (font == null) { |
|
594 |
font = defaultFont; |
|
595 |
} |
|
887 | 596 |
ScreenUpdateManager mgr = |
597 |
ScreenUpdateManager.getInstance(); |
|
598 |
return mgr.createGraphics(surfaceData, this, fgColor, |
|
599 |
bgColor, font); |
|
2 | 600 |
} |
601 |
return null; |
|
602 |
} |
|
603 |
public FontMetrics getFontMetrics(Font font) { |
|
604 |
return WFontMetrics.getFontMetrics(font); |
|
605 |
} |
|
606 |
||
607 |
private synchronized native void _dispose(); |
|
608 |
protected void disposeImpl() { |
|
609 |
SurfaceData oldData = surfaceData; |
|
610 |
surfaceData = null; |
|
887 | 611 |
ScreenUpdateManager.getInstance().dropScreenSurface(oldData); |
2 | 612 |
oldData.invalidate(); |
613 |
// remove from updater before calling targetDisposedPeer |
|
614 |
WToolkit.targetDisposedPeer(target, this); |
|
615 |
_dispose(); |
|
616 |
} |
|
617 |
||
618 |
public synchronized void setForeground(Color c) { |
|
619 |
foreground = c; |
|
620 |
_setForeground(c.getRGB()); |
|
621 |
} |
|
622 |
||
623 |
public synchronized void setBackground(Color c) { |
|
624 |
background = c; |
|
625 |
_setBackground(c.getRGB()); |
|
626 |
} |
|
627 |
||
887 | 628 |
/** |
629 |
* This method is intentionally not synchronized as it is called while |
|
630 |
* holding other locks. |
|
631 |
* |
|
632 |
* @see sun.java2d.d3d.D3DScreenUpdateManager#validate(D3DWindowSurfaceData) |
|
633 |
*/ |
|
634 |
public Color getBackgroundNoSync() { |
|
635 |
return background; |
|
636 |
} |
|
637 |
||
2 | 638 |
public native void _setForeground(int rgb); |
639 |
public native void _setBackground(int rgb); |
|
640 |
||
641 |
public synchronized void setFont(Font f) { |
|
642 |
font = f; |
|
643 |
_setFont(f); |
|
644 |
} |
|
645 |
public synchronized native void _setFont(Font f); |
|
646 |
public final void updateCursorImmediately() { |
|
647 |
WGlobalCursorManager.getCursorManager().updateCursorImmediately(); |
|
648 |
} |
|
649 |
||
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
650 |
// TODO: consider moving it to KeyboardFocusManagerPeerImpl |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
651 |
public boolean requestFocus(Component lightweightChild, boolean temporary, |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
652 |
boolean focusedWindowChangeAllowed, long time, |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
653 |
CausedFocusEvent.Cause cause) |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
654 |
{ |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
655 |
if (WKeyboardFocusManagerPeer. |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
656 |
processSynchronousLightweightTransfer((Component)target, lightweightChild, temporary, |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
657 |
focusedWindowChangeAllowed, time)) |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
658 |
{ |
2 | 659 |
return true; |
660 |
} |
|
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
661 |
|
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
662 |
int result = WKeyboardFocusManagerPeer |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
663 |
.shouldNativelyFocusHeavyweight((Component)target, lightweightChild, |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
664 |
temporary, focusedWindowChangeAllowed, |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
665 |
time, cause); |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
666 |
|
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
667 |
switch (result) { |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
668 |
case WKeyboardFocusManagerPeer.SNFH_FAILURE: |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
669 |
return false; |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
670 |
case WKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED: |
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3084
diff
changeset
|
671 |
if (focusLog.isLoggable(PlatformLogger.FINER)) { |
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
672 |
focusLog.finer("Proceeding with request to " + lightweightChild + " in " + target); |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
673 |
} |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
674 |
Window parentWindow = SunToolkit.getContainingWindow((Component)target); |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
675 |
if (parentWindow == null) { |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
676 |
return rejectFocusRequestHelper("WARNING: Parent window is null"); |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
677 |
} |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
678 |
WWindowPeer wpeer = (WWindowPeer)parentWindow.getPeer(); |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
679 |
if (wpeer == null) { |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
680 |
return rejectFocusRequestHelper("WARNING: Parent window's peer is null"); |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
681 |
} |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
682 |
boolean res = wpeer.requestWindowFocus(cause); |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
683 |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3084
diff
changeset
|
684 |
if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer("Requested window focus: " + res); |
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
685 |
// If parent window can be made focused and has been made focused(synchronously) |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
686 |
// then we can proceed with children, otherwise we retreat. |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
687 |
if (!(res && parentWindow.isFocused())) { |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
688 |
return rejectFocusRequestHelper("Waiting for asynchronous processing of the request"); |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
689 |
} |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
690 |
return WKeyboardFocusManagerPeer.deliverFocus(lightweightChild, |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
691 |
(Component)target, |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
692 |
temporary, |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
693 |
focusedWindowChangeAllowed, |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
694 |
time, cause); |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
695 |
|
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
696 |
case WKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED: |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
697 |
// Either lightweight or excessive request - all events are generated. |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
698 |
return true; |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
699 |
} |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
700 |
return false; |
2 | 701 |
} |
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
702 |
|
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
703 |
private boolean rejectFocusRequestHelper(String logMsg) { |
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3084
diff
changeset
|
704 |
if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer(logMsg); |
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
705 |
WKeyboardFocusManagerPeer.removeLastFocusRequest((Component)target); |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
706 |
return false; |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
707 |
} |
2 | 708 |
|
709 |
public Image createImage(ImageProducer producer) { |
|
710 |
return new ToolkitImage(producer); |
|
711 |
} |
|
712 |
||
713 |
public Image createImage(int width, int height) { |
|
714 |
Win32GraphicsConfig gc = |
|
715 |
(Win32GraphicsConfig)getGraphicsConfiguration(); |
|
716 |
return gc.createAcceleratedImage((Component)target, width, height); |
|
717 |
} |
|
718 |
||
719 |
public VolatileImage createVolatileImage(int width, int height) { |
|
720 |
return new SunVolatileImage((Component)target, width, height); |
|
721 |
} |
|
722 |
||
723 |
public boolean prepareImage(Image img, int w, int h, ImageObserver o) { |
|
724 |
return getToolkit().prepareImage(img, w, h, o); |
|
725 |
} |
|
726 |
||
727 |
public int checkImage(Image img, int w, int h, ImageObserver o) { |
|
728 |
return getToolkit().checkImage(img, w, h, o); |
|
729 |
} |
|
730 |
||
731 |
// Object overrides |
|
732 |
||
733 |
public String toString() { |
|
734 |
return getClass().getName() + "[" + target + "]"; |
|
735 |
} |
|
736 |
||
737 |
// Toolkit & peer internals |
|
738 |
||
739 |
private int updateX1, updateY1, updateX2, updateY2; |
|
740 |
||
741 |
WComponentPeer(Component target) { |
|
742 |
this.target = target; |
|
743 |
this.paintArea = new RepaintArea(); |
|
744 |
Container parent = WToolkit.getNativeContainer(target); |
|
745 |
WComponentPeer parentPeer = (WComponentPeer) WToolkit.targetToPeer(parent); |
|
746 |
create(parentPeer); |
|
747 |
// fix for 5088782: check if window object is created successfully |
|
748 |
checkCreation(); |
|
3084
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2808
diff
changeset
|
749 |
|
67ca55732362
6824169: Need to remove some AWT class dependencies
dcherepanov
parents:
2808
diff
changeset
|
750 |
createScreenSurface(false); |
2 | 751 |
initialize(); |
752 |
start(); // Initialize enable/disable state, turn on callbacks |
|
753 |
} |
|
754 |
abstract void create(WComponentPeer parent); |
|
755 |
||
756 |
protected void checkCreation() |
|
757 |
{ |
|
758 |
if ((hwnd == 0) || (pData == 0)) |
|
759 |
{ |
|
760 |
if (createError != null) |
|
761 |
{ |
|
762 |
throw createError; |
|
763 |
} |
|
764 |
else |
|
765 |
{ |
|
766 |
throw new InternalError("couldn't create component peer"); |
|
767 |
} |
|
768 |
} |
|
769 |
} |
|
770 |
||
771 |
synchronized native void start(); |
|
772 |
||
773 |
void initialize() { |
|
774 |
if (((Component)target).isVisible()) { |
|
775 |
show(); // the wnd starts hidden |
|
776 |
} |
|
777 |
Color fg = ((Component)target).getForeground(); |
|
778 |
if (fg != null) { |
|
779 |
setForeground(fg); |
|
780 |
} |
|
781 |
// Set background color in C++, to avoid inheriting a parent's color. |
|
782 |
Font f = ((Component)target).getFont(); |
|
783 |
if (f != null) { |
|
784 |
setFont(f); |
|
785 |
} |
|
786 |
if (! ((Component)target).isEnabled()) { |
|
787 |
disable(); |
|
788 |
} |
|
789 |
Rectangle r = ((Component)target).getBounds(); |
|
790 |
setBounds(r.x, r.y, r.width, r.height, SET_BOUNDS); |
|
791 |
} |
|
792 |
||
793 |
// Callbacks for window-system events to the frame |
|
794 |
||
795 |
// Invoke a update() method call on the target |
|
796 |
void handleRepaint(int x, int y, int w, int h) { |
|
797 |
// Repaints are posted from updateClient now... |
|
798 |
} |
|
799 |
||
800 |
// Invoke a paint() method call on the target, after clearing the |
|
801 |
// damaged area. |
|
802 |
void handleExpose(int x, int y, int w, int h) { |
|
803 |
// Bug ID 4081126 & 4129709 - can't do the clearRect() here, |
|
804 |
// since it interferes with the java thread working in the |
|
805 |
// same window on multi-processor NT machines. |
|
806 |
||
807 |
postPaintIfNecessary(x, y, w, h); |
|
808 |
} |
|
809 |
||
810 |
/* Invoke a paint() method call on the target, without clearing the |
|
811 |
* damaged area. This is normally called by a native control after |
|
812 |
* it has painted itself. |
|
813 |
* |
|
814 |
* NOTE: This is called on the privileged toolkit thread. Do not |
|
815 |
* call directly into user code using this thread! |
|
816 |
*/ |
|
2467
6f07b02fe2c0
6774258: api/java_awt/Component/index.html#PaintUpdate fails randomly
dcherepanov
parents:
2464
diff
changeset
|
817 |
public void handlePaint(int x, int y, int w, int h) { |
2 | 818 |
postPaintIfNecessary(x, y, w, h); |
819 |
} |
|
820 |
||
821 |
private void postPaintIfNecessary(int x, int y, int w, int h) { |
|
4371
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
4259
diff
changeset
|
822 |
if ( !AWTAccessor.getComponentAccessor().getIgnoreRepaint( (Component) target) ) { |
2 | 823 |
PaintEvent event = PaintEventDispatcher.getPaintEventDispatcher(). |
824 |
createPaintEvent((Component)target, x, y, w, h); |
|
825 |
if (event != null) { |
|
826 |
postEvent(event); |
|
827 |
} |
|
828 |
} |
|
829 |
} |
|
830 |
||
831 |
/* |
|
832 |
* Post an event. Queue it for execution by the callback thread. |
|
833 |
*/ |
|
834 |
void postEvent(AWTEvent event) { |
|
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
835 |
preprocessPostEvent(event); |
2 | 836 |
WToolkit.postEvent(WToolkit.targetToAppContext(target), event); |
837 |
} |
|
838 |
||
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
839 |
void preprocessPostEvent(AWTEvent event) {} |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
840 |
|
2 | 841 |
// Routines to support deferred window positioning. |
842 |
public void beginLayout() { |
|
843 |
// Skip all painting till endLayout |
|
844 |
isLayouting = true; |
|
845 |
} |
|
846 |
||
847 |
public void endLayout() { |
|
848 |
if(!paintArea.isEmpty() && !paintPending && |
|
849 |
!((Component)target).getIgnoreRepaint()) { |
|
850 |
// if not waiting for native painting repaint damaged area |
|
851 |
postEvent(new PaintEvent((Component)target, PaintEvent.PAINT, |
|
852 |
new Rectangle())); |
|
853 |
} |
|
854 |
isLayouting = false; |
|
855 |
} |
|
856 |
||
857 |
public native void beginValidate(); |
|
858 |
public native void endValidate(); |
|
859 |
||
860 |
/** |
|
861 |
* DEPRECATED |
|
862 |
*/ |
|
863 |
public Dimension minimumSize() { |
|
864 |
return getMinimumSize(); |
|
865 |
} |
|
866 |
||
867 |
/** |
|
868 |
* DEPRECATED |
|
869 |
*/ |
|
870 |
public Dimension preferredSize() { |
|
871 |
return getPreferredSize(); |
|
872 |
} |
|
873 |
||
874 |
/** |
|
875 |
* register a DropTarget with this native peer |
|
876 |
*/ |
|
877 |
||
878 |
public synchronized void addDropTarget(DropTarget dt) { |
|
879 |
if (nDropTargets == 0) { |
|
880 |
nativeDropTargetContext = addNativeDropTarget(); |
|
881 |
} |
|
882 |
nDropTargets++; |
|
883 |
} |
|
884 |
||
885 |
/** |
|
886 |
* unregister a DropTarget with this native peer |
|
887 |
*/ |
|
888 |
||
889 |
public synchronized void removeDropTarget(DropTarget dt) { |
|
890 |
nDropTargets--; |
|
891 |
if (nDropTargets == 0) { |
|
892 |
removeNativeDropTarget(); |
|
893 |
nativeDropTargetContext = 0; |
|
894 |
} |
|
895 |
} |
|
896 |
||
897 |
/** |
|
898 |
* add the native peer's AwtDropTarget COM object |
|
899 |
* @return reference to AwtDropTarget object |
|
900 |
*/ |
|
901 |
||
902 |
native long addNativeDropTarget(); |
|
903 |
||
904 |
/** |
|
905 |
* remove the native peer's AwtDropTarget COM object |
|
906 |
*/ |
|
907 |
||
908 |
native void removeNativeDropTarget(); |
|
909 |
native boolean nativeHandlesWheelScrolling(); |
|
910 |
||
911 |
public boolean handlesWheelScrolling() { |
|
912 |
// should this be cached? |
|
913 |
return nativeHandlesWheelScrolling(); |
|
914 |
} |
|
915 |
||
916 |
// Returns true if we are inside begin/endLayout and |
|
917 |
// are waiting for native painting |
|
918 |
public boolean isPaintPending() { |
|
919 |
return paintPending && isLayouting; |
|
920 |
} |
|
921 |
||
922 |
/** |
|
923 |
* The following multibuffering-related methods delegate to our |
|
924 |
* associated GraphicsConfig (Win or WGL) to handle the appropriate |
|
925 |
* native windowing system specific actions. |
|
926 |
*/ |
|
927 |
||
887 | 928 |
@Override |
2 | 929 |
public void createBuffers(int numBuffers, BufferCapabilities caps) |
930 |
throws AWTException |
|
931 |
{ |
|
932 |
Win32GraphicsConfig gc = |
|
933 |
(Win32GraphicsConfig)getGraphicsConfiguration(); |
|
934 |
gc.assertOperationSupported((Component)target, numBuffers, caps); |
|
935 |
||
936 |
// Re-create the primary surface with the new number of back buffers |
|
937 |
try { |
|
887 | 938 |
replaceSurfaceData(numBuffers - 1, caps); |
2 | 939 |
} catch (InvalidPipeException e) { |
940 |
throw new AWTException(e.getMessage()); |
|
941 |
} |
|
942 |
} |
|
943 |
||
887 | 944 |
@Override |
945 |
public void destroyBuffers() { |
|
946 |
replaceSurfaceData(0, null); |
|
2 | 947 |
} |
948 |
||
887 | 949 |
@Override |
950 |
public void flip(int x1, int y1, int x2, int y2, |
|
951 |
BufferCapabilities.FlipContents flipAction) |
|
952 |
{ |
|
953 |
VolatileImage backBuffer = this.backBuffer; |
|
2 | 954 |
if (backBuffer == null) { |
955 |
throw new IllegalStateException("Buffers have not been created"); |
|
956 |
} |
|
957 |
Win32GraphicsConfig gc = |
|
958 |
(Win32GraphicsConfig)getGraphicsConfiguration(); |
|
887 | 959 |
gc.flip(this, (Component)target, backBuffer, x1, y1, x2, y2, flipAction); |
2 | 960 |
} |
961 |
||
887 | 962 |
@Override |
2 | 963 |
public synchronized Image getBackBuffer() { |
887 | 964 |
Image backBuffer = this.backBuffer; |
2 | 965 |
if (backBuffer == null) { |
966 |
throw new IllegalStateException("Buffers have not been created"); |
|
967 |
} |
|
968 |
return backBuffer; |
|
969 |
} |
|
887 | 970 |
public BufferCapabilities getBackBufferCaps() { |
971 |
return backBufferCaps; |
|
972 |
} |
|
973 |
public int getBackBuffersNum() { |
|
974 |
return numBackBuffers; |
|
975 |
} |
|
2 | 976 |
|
977 |
/* override and return false on components that DO NOT require |
|
978 |
a clearRect() before painting (i.e. native components) */ |
|
979 |
public boolean shouldClearRectBeforePaint() { |
|
980 |
return true; |
|
981 |
} |
|
982 |
||
983 |
native void pSetParent(ComponentPeer newNativeParent); |
|
984 |
||
985 |
/** |
|
986 |
* @see java.awt.peer.ComponentPeer#reparent |
|
987 |
*/ |
|
988 |
public void reparent(ContainerPeer newNativeParent) { |
|
989 |
pSetParent(newNativeParent); |
|
990 |
} |
|
991 |
||
992 |
/** |
|
993 |
* @see java.awt.peer.ComponentPeer#isReparentSupported |
|
994 |
*/ |
|
995 |
public boolean isReparentSupported() { |
|
996 |
return true; |
|
997 |
} |
|
998 |
||
999 |
public void setBoundsOperation(int operation) { |
|
1000 |
} |
|
1001 |
||
2451 | 1002 |
/** |
1003 |
* Returns whether this component is capable of being hw accelerated. |
|
1004 |
* More specifically, whether rendering to this component or a |
|
1005 |
* BufferStrategy's back-buffer for this component can be hw accelerated. |
|
1006 |
* |
|
1007 |
* Conditions which could prevent hw acceleration include the toplevel |
|
1008 |
* window containing this component being |
|
2648 | 1009 |
* {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT |
1010 |
* PERPIXEL_TRANSLUCENT}. |
|
2451 | 1011 |
* |
1012 |
* @return {@code true} if this component is capable of being hw |
|
1013 |
* accelerated, {@code false} otherwise |
|
2648 | 1014 |
* @see GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT |
2451 | 1015 |
*/ |
1016 |
public boolean isAccelCapable() { |
|
1017 |
boolean isTranslucent = |
|
1018 |
SunToolkit.isContainingTopLevelTranslucent((Component)target); |
|
1019 |
// D3D/OGL and translucent windows interacted poorly in Windows XP; |
|
1020 |
// these problems are no longer present in Vista |
|
1021 |
return !isTranslucent || Win32GraphicsEnvironment.isVistaOS(); |
|
1022 |
} |
|
2 | 1023 |
|
1024 |
native void setRectangularShape(int lox, int loy, int hix, int hiy, |
|
2451 | 1025 |
Region region); |
2 | 1026 |
|
1027 |
||
887 | 1028 |
// REMIND: Temp workaround for issues with using HW acceleration |
1029 |
// in the browser on Vista when DWM is enabled. |
|
1030 |
// @return true if the toplevel container is not an EmbeddedFrame or |
|
1031 |
// if this EmbeddedFrame is acceleration capable, false otherwise |
|
1032 |
private static final boolean isContainingTopLevelAccelCapable(Component c) { |
|
1033 |
while (c != null && !(c instanceof WEmbeddedFrame)) { |
|
1034 |
c = c.getParent(); |
|
1035 |
} |
|
1036 |
if (c == null) { |
|
1037 |
return true; |
|
1038 |
} |
|
1039 |
return ((WEmbeddedFramePeer)c.getPeer()).isAccelCapable(); |
|
1040 |
} |
|
1041 |
||
1042 |
/** |
|
2 | 1043 |
* Applies the shape to the native component window. |
1044 |
* @since 1.7 |
|
1045 |
*/ |
|
2451 | 1046 |
public void applyShape(Region shape) { |
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3084
diff
changeset
|
1047 |
if (shapeLog.isLoggable(PlatformLogger.FINER)) { |
2 | 1048 |
shapeLog.finer( |
1049 |
"*** INFO: Setting shape: PEER: " + this |
|
1050 |
+ "; TARGET: " + target |
|
1051 |
+ "; SHAPE: " + shape); |
|
1052 |
} |
|
1053 |
||
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1954
diff
changeset
|
1054 |
if (shape != null) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1954
diff
changeset
|
1055 |
setRectangularShape(shape.getLoX(), shape.getLoY(), shape.getHiX(), shape.getHiY(), |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1954
diff
changeset
|
1056 |
(shape.isRectangular() ? null : shape)); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1954
diff
changeset
|
1057 |
} else { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1954
diff
changeset
|
1058 |
setRectangularShape(0, 0, 0, 0, null); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
1954
diff
changeset
|
1059 |
} |
2 | 1060 |
} |
1061 |
||
2462
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
1062 |
/** |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
1063 |
* Lowers this component at the bottom of the above component. If the above parameter |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
1064 |
* is null then the method places this component at the top of the Z-order. |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
1065 |
*/ |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
1066 |
public void setZOrder(ComponentPeer above) { |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
1067 |
long aboveHWND = (above != null) ? ((WComponentPeer)above).getHWnd() : 0; |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
1068 |
|
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
1069 |
setZOrder(aboveHWND); |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
1070 |
} |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
1071 |
|
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
1072 |
private native void setZOrder(long above); |
2 | 1073 |
} |