author | yan |
Mon, 06 Oct 2008 16:45:00 +0400 | |
changeset 1966 | 12a51fb0db0d |
parent 887 | 0aab8d3fa11a |
child 1978 | 8b981ce05cd0 |
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 |
package sun.awt.X11; |
|
26 |
||
27 |
import java.awt.AWTEvent; |
|
28 |
import java.awt.AWTException; |
|
29 |
import java.awt.BufferCapabilities; |
|
30 |
import java.awt.Color; |
|
31 |
import java.awt.Component; |
|
32 |
import java.awt.Container; |
|
33 |
import java.awt.Cursor; |
|
34 |
import java.awt.Dimension; |
|
35 |
import java.awt.Font; |
|
36 |
import java.awt.FontMetrics; |
|
37 |
import java.awt.Graphics; |
|
38 |
import java.awt.Image; |
|
39 |
import java.awt.Insets; |
|
40 |
import java.awt.KeyboardFocusManager; |
|
41 |
import java.awt.Rectangle; |
|
42 |
import java.awt.SystemColor; |
|
43 |
import java.awt.Toolkit; |
|
44 |
import java.awt.Window; |
|
45 |
import java.awt.dnd.DropTarget; |
|
46 |
import java.awt.dnd.peer.DropTargetPeer; |
|
47 |
import java.awt.event.FocusEvent; |
|
48 |
import java.awt.event.InputEvent; |
|
49 |
import java.awt.event.InputMethodEvent; |
|
50 |
import java.awt.event.KeyEvent; |
|
51 |
import java.awt.event.MouseEvent; |
|
52 |
import java.awt.event.MouseWheelEvent; |
|
53 |
import java.awt.event.PaintEvent; |
|
54 |
import java.awt.event.WindowEvent; |
|
55 |
import java.awt.event.InvocationEvent; |
|
56 |
import java.awt.image.ImageObserver; |
|
57 |
import java.awt.image.ImageProducer; |
|
58 |
import java.awt.image.VolatileImage; |
|
59 |
import java.awt.peer.ComponentPeer; |
|
60 |
import java.awt.peer.ContainerPeer; |
|
61 |
import java.awt.peer.LightweightPeer; |
|
62 |
import java.lang.reflect.*; |
|
63 |
import java.security.*; |
|
64 |
import java.util.Collection; |
|
65 |
import java.util.HashSet; |
|
66 |
import java.util.Set; |
|
67 |
import java.util.Vector; |
|
68 |
import java.util.logging.*; |
|
69 |
import sun.awt.*; |
|
70 |
import sun.awt.event.IgnorePaintEvent; |
|
71 |
import sun.awt.image.SunVolatileImage; |
|
72 |
import sun.awt.image.ToolkitImage; |
|
887 | 73 |
import sun.java2d.BackBufferCapsProvider; |
2 | 74 |
import sun.java2d.pipe.Region; |
75 |
||
887 | 76 |
public class XComponentPeer extends XWindow implements ComponentPeer, DropTargetPeer, |
77 |
BackBufferCapsProvider |
|
78 |
{ |
|
2 | 79 |
/* FIX ME: these constants copied from java.awt.KeyboardFocusManager */ |
80 |
static final int SNFH_FAILURE = 0; |
|
81 |
static final int SNFH_SUCCESS_HANDLED = 1; |
|
82 |
static final int SNFH_SUCCESS_PROCEED = 2; |
|
83 |
||
84 |
private static final Logger log = Logger.getLogger("sun.awt.X11.XComponentPeer"); |
|
85 |
private static final Logger buffersLog = Logger.getLogger("sun.awt.X11.XComponentPeer.multibuffer"); |
|
86 |
private static final Logger focusLog = Logger.getLogger("sun.awt.X11.focus.XComponentPeer"); |
|
87 |
private static final Logger fontLog = Logger.getLogger("sun.awt.X11.font.XComponentPeer"); |
|
88 |
private static final Logger enableLog = Logger.getLogger("sun.awt.X11.enable.XComponentPeer"); |
|
89 |
private static final Logger shapeLog = Logger.getLogger("sun.awt.X11.shape.XComponentPeer"); |
|
90 |
||
91 |
boolean paintPending = false; |
|
92 |
boolean isLayouting = false; |
|
93 |
boolean enabled; |
|
94 |
||
95 |
// Actually used only by XDecoratedPeer |
|
96 |
protected int boundsOperation; |
|
97 |
||
98 |
Color foreground; |
|
99 |
Color background; |
|
100 |
||
101 |
// Colors calculated as on Motif using MotifColorUtilties. |
|
102 |
// If you use these, call updateMotifColors() in the peer's Constructor and |
|
103 |
// setBackground(). Examples are XCheckboxPeer and XButtonPeer. |
|
104 |
Color darkShadow; |
|
105 |
Color lightShadow; |
|
106 |
Color selectColor; |
|
107 |
||
108 |
Font font; |
|
109 |
private long backBuffer = 0; |
|
110 |
private VolatileImage xBackBuffer = null; |
|
111 |
||
112 |
static Color[] systemColors; |
|
113 |
||
114 |
XComponentPeer() { |
|
115 |
} |
|
116 |
||
117 |
XComponentPeer (XCreateWindowParams params) { |
|
118 |
super(params); |
|
119 |
} |
|
120 |
||
121 |
XComponentPeer(Component target, long parentWindow, Rectangle bounds) { |
|
122 |
super(target, parentWindow, bounds); |
|
123 |
} |
|
124 |
||
125 |
/** |
|
126 |
* Standard peer constructor, with corresponding Component |
|
127 |
*/ |
|
128 |
XComponentPeer(Component target) { |
|
129 |
super(target); |
|
130 |
} |
|
131 |
||
132 |
||
133 |
void preInit(XCreateWindowParams params) { |
|
134 |
super.preInit(params); |
|
135 |
boundsOperation = DEFAULT_OPERATION; |
|
136 |
} |
|
137 |
void postInit(XCreateWindowParams params) { |
|
138 |
super.postInit(params); |
|
139 |
Color c; |
|
140 |
Font f; |
|
141 |
Cursor cursor; |
|
142 |
||
143 |
pSetCursor(target.getCursor()); |
|
144 |
||
145 |
foreground = target.getForeground(); |
|
146 |
background = target.getBackground(); |
|
147 |
font = target.getFont(); |
|
148 |
||
149 |
if (isInitialReshape()) { |
|
150 |
Rectangle r = target.getBounds(); |
|
151 |
reshape(r.x, r.y, r.width, r.height); |
|
152 |
} |
|
153 |
||
154 |
enabled = target.isEnabled(); |
|
155 |
||
156 |
// If any of our heavyweight ancestors are disable, we should be too |
|
157 |
// See 6176875 for more information |
|
158 |
Component comp = target; |
|
159 |
while( !(comp == null || comp instanceof Window) ) { |
|
160 |
comp = comp.getParent(); |
|
161 |
if( comp != null && !comp.isEnabled() && !comp.isLightweight() ){ |
|
162 |
setEnabled(false); |
|
163 |
break; |
|
164 |
} |
|
165 |
} |
|
166 |
enableLog.log(Level.FINE, "Initial enable state: {0}", new Object[] {Boolean.valueOf(enabled)}); |
|
167 |
||
168 |
if (target.isVisible()) { |
|
169 |
show(); |
|
170 |
} |
|
171 |
} |
|
172 |
||
173 |
protected boolean isInitialReshape() { |
|
174 |
return true; |
|
175 |
} |
|
176 |
||
177 |
public void reparent(ContainerPeer newNativeParent) { |
|
178 |
XComponentPeer newPeer = (XComponentPeer)newNativeParent; |
|
179 |
XToolkit.awtLock(); |
|
180 |
try { |
|
181 |
XlibWrapper.XReparentWindow(XToolkit.getDisplay(), getWindow(), newPeer.getContentWindow(), x, y); |
|
182 |
parentWindow = newPeer; |
|
183 |
} finally { |
|
184 |
XToolkit.awtUnlock(); |
|
185 |
} |
|
186 |
} |
|
187 |
public boolean isReparentSupported() { |
|
188 |
return System.getProperty("sun.awt.X11.XComponentPeer.reparentNotSupported", "false").equals("false"); |
|
189 |
} |
|
190 |
||
191 |
public boolean isObscured() { |
|
192 |
Container container = (target instanceof Container) ? |
|
193 |
(Container)target : target.getParent(); |
|
194 |
||
195 |
if (container == null) { |
|
196 |
return true; |
|
197 |
} |
|
198 |
||
199 |
Container parent; |
|
200 |
while ((parent = container.getParent()) != null) { |
|
201 |
container = parent; |
|
202 |
} |
|
203 |
||
204 |
if (container instanceof Window) { |
|
205 |
XWindowPeer wpeer = (XWindowPeer)(container.getPeer()); |
|
206 |
if (wpeer != null) { |
|
207 |
return (wpeer.winAttr.visibilityState != |
|
208 |
wpeer.winAttr.AWT_UNOBSCURED); |
|
209 |
} |
|
210 |
} |
|
211 |
return true; |
|
212 |
} |
|
213 |
||
214 |
public boolean canDetermineObscurity() { |
|
215 |
return true; |
|
216 |
} |
|
217 |
||
218 |
static XComponentPeer getNativeContainer(Component comp) { |
|
219 |
if (comp == null) { |
|
220 |
return null; |
|
221 |
} |
|
222 |
||
223 |
synchronized(comp.getTreeLock()) { |
|
224 |
while (comp != null && (ComponentAccessor.getPeer(comp) instanceof LightweightPeer)) { |
|
225 |
comp = ComponentAccessor.getParent_NoClientCode(comp); |
|
226 |
} |
|
227 |
||
228 |
if (comp != null) { |
|
229 |
ComponentPeer peer = ComponentAccessor.getPeer(comp); |
|
230 |
if (peer != null && peer instanceof XComponentPeer) { |
|
231 |
return (XComponentPeer)peer; |
|
232 |
} |
|
233 |
} |
|
234 |
} |
|
235 |
||
236 |
return null; |
|
237 |
} |
|
238 |
||
239 |
/************************************************* |
|
240 |
* FOCUS STUFF |
|
241 |
*************************************************/ |
|
242 |
||
243 |
/** |
|
244 |
* Keeps the track of focused state of the _NATIVE_ window |
|
245 |
*/ |
|
246 |
boolean bHasFocus = false; |
|
247 |
||
248 |
/** |
|
249 |
* Descendants should use this method to determine whether or not native window |
|
250 |
* has focus. |
|
251 |
*/ |
|
252 |
final public boolean hasFocus() { |
|
253 |
return bHasFocus; |
|
254 |
} |
|
255 |
||
256 |
/** |
|
257 |
* Called when component receives focus |
|
258 |
*/ |
|
259 |
public void focusGained(FocusEvent e) { |
|
260 |
focusLog.log(Level.FINE, "{0}", new Object[] {e}); |
|
261 |
bHasFocus = true; |
|
262 |
} |
|
263 |
||
264 |
/** |
|
265 |
* Called when component loses focus |
|
266 |
*/ |
|
267 |
public void focusLost(FocusEvent e) { |
|
268 |
focusLog.log(Level.FINE, "{0}", new Object[] {e}); |
|
269 |
bHasFocus = false; |
|
270 |
} |
|
271 |
||
272 |
public boolean isFocusable() { |
|
273 |
/* should be implemented by other sub-classes */ |
|
274 |
return false; |
|
275 |
} |
|
276 |
||
277 |
private static Class seClass; |
|
278 |
private static Constructor seCtor; |
|
279 |
||
280 |
final static AWTEvent wrapInSequenced(AWTEvent event) { |
|
281 |
try { |
|
282 |
if (seClass == null) { |
|
283 |
seClass = Class.forName("java.awt.SequencedEvent"); |
|
284 |
} |
|
285 |
||
286 |
if (seCtor == null) { |
|
287 |
seCtor = (Constructor) AccessController.doPrivileged(new PrivilegedExceptionAction() { |
|
288 |
public Object run() throws Exception { |
|
289 |
Constructor ctor = seClass.getConstructor(new Class[] { AWTEvent.class }); |
|
290 |
ctor.setAccessible(true); |
|
291 |
return ctor; |
|
292 |
} |
|
293 |
}); |
|
294 |
} |
|
295 |
||
296 |
return (AWTEvent) seCtor.newInstance(new Object[] { event }); |
|
297 |
} |
|
298 |
catch (ClassNotFoundException e) { |
|
299 |
throw new NoClassDefFoundError("java.awt.SequencedEvent."); |
|
300 |
} |
|
301 |
catch (PrivilegedActionException ex) { |
|
302 |
throw new NoClassDefFoundError("java.awt.SequencedEvent."); |
|
303 |
} |
|
304 |
catch (InstantiationException e) { |
|
305 |
assert false; |
|
306 |
} |
|
307 |
catch (IllegalAccessException e) { |
|
308 |
assert false; |
|
309 |
} |
|
310 |
catch (InvocationTargetException e) { |
|
311 |
assert false; |
|
312 |
} |
|
313 |
||
314 |
return null; |
|
315 |
} |
|
316 |
||
317 |
/** |
|
318 |
* Returns whether or not this component should be given focus on mouse click. |
|
319 |
* Default implementation return whether or not this peer is "focusable" |
|
320 |
* Descendants might want to override it to extend/restrict conditions at which this |
|
321 |
* component should be focused by click (see MCanvasPeer and MPanelPeer) |
|
322 |
*/ |
|
323 |
protected boolean shouldFocusOnClick() { |
|
324 |
return isFocusable(); |
|
325 |
} |
|
326 |
||
327 |
/** |
|
328 |
* Checks whether or not this component would be focused by native system if it would be allowed to do so. |
|
329 |
* Currently it checks that it displayable, visible, enabled and focusable. |
|
330 |
*/ |
|
331 |
static boolean canBeFocusedByClick(Component component) { |
|
332 |
if (component == null) { |
|
333 |
return false; |
|
334 |
} else { |
|
335 |
return component.isDisplayable() && component.isVisible() && component.isEnabled() && component.isFocusable(); |
|
336 |
} |
|
337 |
} |
|
338 |
||
339 |
static Window getContainingWindow(Component comp) { |
|
340 |
while (comp != null && !(comp instanceof Window)) { |
|
341 |
comp = comp.getParent(); |
|
342 |
} |
|
343 |
||
344 |
return (Window)comp; |
|
345 |
} |
|
346 |
||
347 |
static Method processSynchronousLightweightTransferMethod; |
|
348 |
static boolean processSynchronousLightweightTransfer(Component heavyweight, Component descendant, |
|
349 |
boolean temporary, boolean focusedWindowChangeAllowed, |
|
350 |
long time) |
|
351 |
{ |
|
352 |
try { |
|
353 |
if (processSynchronousLightweightTransferMethod == null) { |
|
354 |
processSynchronousLightweightTransferMethod = |
|
355 |
(Method)AccessController.doPrivileged( |
|
356 |
new PrivilegedExceptionAction() { |
|
357 |
public Object run() throws IllegalAccessException, NoSuchMethodException |
|
358 |
{ |
|
359 |
Method m = KeyboardFocusManager.class. |
|
360 |
getDeclaredMethod("processSynchronousLightweightTransfer", |
|
361 |
new Class[] {Component.class, Component.class, |
|
362 |
Boolean.TYPE, Boolean.TYPE, |
|
363 |
Long.TYPE}); |
|
364 |
m.setAccessible(true); |
|
365 |
return m; |
|
366 |
} |
|
367 |
}); |
|
368 |
} |
|
369 |
Object[] params = new Object[] { |
|
370 |
heavyweight, |
|
371 |
descendant, |
|
372 |
Boolean.valueOf(temporary), |
|
373 |
Boolean.valueOf(focusedWindowChangeAllowed), |
|
374 |
Long.valueOf(time) |
|
375 |
}; |
|
376 |
return ((Boolean)processSynchronousLightweightTransferMethod.invoke(null, params)).booleanValue(); |
|
377 |
} catch (PrivilegedActionException pae) { |
|
378 |
pae.printStackTrace(); |
|
379 |
return false; |
|
380 |
} catch (IllegalAccessException iae) { |
|
381 |
iae.printStackTrace(); |
|
382 |
return false; |
|
383 |
} catch (IllegalArgumentException iaee) { |
|
384 |
iaee.printStackTrace(); |
|
385 |
return false; |
|
386 |
} catch (InvocationTargetException ite) { |
|
387 |
ite.printStackTrace(); |
|
388 |
return false; |
|
389 |
} |
|
390 |
} |
|
391 |
||
392 |
static Method requestFocusWithCause; |
|
393 |
||
394 |
static void callRequestFocus(Component target, CausedFocusEvent.Cause cause) { |
|
395 |
if (requestFocusWithCause == null) { |
|
396 |
requestFocusWithCause = SunToolkit.getMethod(Component.class, "requestFocus", new Class[] {CausedFocusEvent.Cause.class}); |
|
397 |
} |
|
398 |
if (requestFocusWithCause != null) { |
|
399 |
try { |
|
400 |
requestFocusWithCause.invoke(target, new Object[] {cause}); |
|
401 |
} catch (Exception e) { |
|
402 |
e.printStackTrace(); |
|
403 |
} |
|
404 |
} |
|
405 |
} |
|
406 |
||
407 |
final public boolean requestFocus(Component lightweightChild, boolean temporary, |
|
408 |
boolean focusedWindowChangeAllowed, long time, CausedFocusEvent.Cause cause) |
|
409 |
{ |
|
410 |
if (processSynchronousLightweightTransfer(target, lightweightChild, temporary, |
|
411 |
focusedWindowChangeAllowed, time)) |
|
412 |
{ |
|
413 |
return true; |
|
414 |
} |
|
415 |
||
416 |
int result = XKeyboardFocusManagerPeer |
|
417 |
.shouldNativelyFocusHeavyweight(target, lightweightChild, |
|
418 |
temporary, focusedWindowChangeAllowed, time, cause); |
|
419 |
||
420 |
switch (result) { |
|
421 |
case SNFH_FAILURE: |
|
422 |
return false; |
|
423 |
case SNFH_SUCCESS_PROCEED: |
|
424 |
// Currently we just generate focus events like we deal with lightweight instead of calling |
|
425 |
// XSetInputFocus on native window |
|
442
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
426 |
if (focusLog.isLoggable(Level.FINER)) focusLog.finer("Proceeding with request to " + |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
427 |
lightweightChild + " in " + target); |
2 | 428 |
/** |
429 |
* The problems with requests in non-focused window arise because shouldNativelyFocusHeavyweight |
|
430 |
* checks that native window is focused while appropriate WINDOW_GAINED_FOCUS has not yet |
|
431 |
* been processed - it is in EventQueue. Thus, SNFH allows native request and stores request record |
|
442
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
432 |
* in requests list - and it breaks our requests sequence as first record on WGF should be the last |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
433 |
* focus owner which had focus before WLF. So, we should not add request record for such requests |
2 | 434 |
* but store this component in mostRecent - and return true as before for compatibility. |
435 |
*/ |
|
436 |
Window parentWindow = getContainingWindow(target); |
|
442
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
437 |
if (parentWindow == null) { |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
438 |
return rejectFocusRequestHelper("WARNING: Parent window is null"); |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
439 |
} |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
440 |
XWindowPeer wpeer = (XWindowPeer)parentWindow.getPeer(); |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
441 |
if (wpeer == null) { |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
442 |
return rejectFocusRequestHelper("WARNING: Parent window's peer is null"); |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
443 |
} |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
444 |
/* |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
445 |
* Passing null 'actualFocusedWindow' as we don't want to restore focus on it |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
446 |
* when a component inside a Frame is requesting focus. |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
447 |
* See 6314575 for details. |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
448 |
*/ |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
449 |
boolean res = wpeer.requestWindowFocus(null); |
2 | 450 |
|
442
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
451 |
if (focusLog.isLoggable(Level.FINER)) focusLog.finer("Requested window focus: " + res); |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
452 |
// If parent window can be made focused and has been made focused(synchronously) |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
453 |
// then we can proceed with children, otherwise we retreat. |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
454 |
if (!(res && parentWindow.isFocused())) { |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
455 |
return rejectFocusRequestHelper("Waiting for asynchronous processing of the request"); |
2 | 456 |
} |
457 |
||
458 |
// NOTE: We simulate heavyweight behavior of Motif - component receives focus right |
|
459 |
// after request, not after event. Normally, we should better listen for event |
|
460 |
// by listeners. |
|
461 |
return XKeyboardFocusManagerPeer.simulateMotifRequestFocus(lightweightChild, target, temporary, |
|
462 |
focusedWindowChangeAllowed, time, cause); |
|
463 |
// Motif compatibility code |
|
464 |
case SNFH_SUCCESS_HANDLED: |
|
465 |
// Either lightweight or excessive request - all events are generated. |
|
466 |
return true; |
|
467 |
} |
|
468 |
return false; |
|
469 |
} |
|
470 |
||
442
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
471 |
private boolean rejectFocusRequestHelper(String logMsg) { |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
472 |
if (focusLog.isLoggable(Level.FINER)) focusLog.finer(logMsg); |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
473 |
KeyboardFocusManagerPeerImpl.removeLastFocusRequest(target); |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
474 |
return false; |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
475 |
} |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
476 |
|
2 | 477 |
void handleJavaFocusEvent(AWTEvent e) { |
478 |
if (focusLog.isLoggable(Level.FINER)) focusLog.finer(e.toString()); |
|
479 |
if (e.getID() == FocusEvent.FOCUS_GAINED) { |
|
480 |
focusGained((FocusEvent)e); |
|
481 |
} else { |
|
482 |
focusLost((FocusEvent)e); |
|
483 |
} |
|
484 |
} |
|
485 |
||
486 |
void handleJavaWindowFocusEvent(AWTEvent e) { |
|
487 |
} |
|
488 |
||
489 |
/************************************************* |
|
490 |
* END OF FOCUS STUFF |
|
491 |
*************************************************/ |
|
492 |
||
493 |
||
494 |
||
495 |
public void setVisible(boolean b) { |
|
496 |
xSetVisible(b); |
|
497 |
} |
|
498 |
||
499 |
public void show() { |
|
500 |
setVisible(true); |
|
501 |
} |
|
502 |
||
503 |
public void hide() { |
|
504 |
setVisible(false); |
|
505 |
} |
|
506 |
||
507 |
||
508 |
/** |
|
509 |
* @see java.awt.peer.ComponentPeer |
|
510 |
*/ |
|
511 |
public void setEnabled(boolean value) { |
|
512 |
enableLog.log(Level.FINE, "{0}ing {1}", new Object[] {(value?"Enabl":"Disabl"), this}); |
|
513 |
boolean repaintNeeded = (enabled != value); |
|
514 |
enabled = value; |
|
515 |
if (target instanceof Container) { |
|
516 |
Component list[] = ((Container)target).getComponents(); |
|
517 |
for (int i = 0; i < list.length; ++i) { |
|
518 |
boolean childEnabled = list[i].isEnabled(); |
|
519 |
ComponentPeer p = list[i].getPeer(); |
|
520 |
if ( p != null ) { |
|
521 |
p.setEnabled(value && childEnabled); |
|
522 |
} |
|
523 |
} |
|
524 |
} |
|
525 |
if (repaintNeeded) { |
|
526 |
repaint(); |
|
527 |
} |
|
528 |
} |
|
529 |
||
530 |
// |
|
531 |
// public so aw/Window can call it |
|
532 |
// |
|
533 |
public boolean isEnabled() { |
|
534 |
return enabled; |
|
535 |
} |
|
536 |
||
537 |
||
538 |
||
539 |
public void enable() { |
|
540 |
setEnabled(true); |
|
541 |
} |
|
542 |
||
543 |
public void disable() { |
|
544 |
setEnabled(false); |
|
545 |
} |
|
546 |
||
547 |
public void paint(Graphics g) { |
|
548 |
} |
|
549 |
public void repaint(long tm, int x, int y, int width, int height) { |
|
550 |
repaint(); |
|
551 |
} |
|
552 |
||
553 |
||
554 |
public Graphics getGraphics() { |
|
555 |
return getGraphics(surfaceData, getPeerForeground(), getPeerBackground(), getPeerFont()); |
|
556 |
} |
|
557 |
||
558 |
||
559 |
||
560 |
public void print(Graphics g) { |
|
561 |
// clear rect here to emulate X clears rect before Expose |
|
562 |
g.setColor(target.getBackground()); |
|
563 |
g.fillRect(0, 0, target.getWidth(), target.getHeight()); |
|
564 |
g.setColor(target.getForeground()); |
|
565 |
// paint peer |
|
566 |
paint(g); |
|
567 |
// allow target to change the picture |
|
568 |
target.print(g); |
|
569 |
} |
|
570 |
||
571 |
public void setBounds(int x, int y, int width, int height, int op) { |
|
572 |
this.x = x; |
|
573 |
this.y = y; |
|
574 |
this.width = width; |
|
575 |
this.height = height; |
|
576 |
xSetBounds(x,y,width,height); |
|
577 |
validateSurface(); |
|
578 |
layout(); |
|
579 |
} |
|
580 |
||
581 |
public void reshape(int x, int y, int width, int height) { |
|
582 |
setBounds(x, y, width, height, SET_BOUNDS); |
|
583 |
} |
|
584 |
||
585 |
public void coalescePaintEvent(PaintEvent e) { |
|
586 |
Rectangle r = e.getUpdateRect(); |
|
587 |
if (!(e instanceof IgnorePaintEvent)) { |
|
588 |
paintArea.add(r, e.getID()); |
|
589 |
} |
|
590 |
if (true) { |
|
591 |
switch(e.getID()) { |
|
592 |
case PaintEvent.UPDATE: |
|
593 |
log.finer("XCP coalescePaintEvent : UPDATE : add : x = " + |
|
594 |
r.x + ", y = " + r.y + ", width = " + r.width + ",height = " + r.height); |
|
595 |
return; |
|
596 |
case PaintEvent.PAINT: |
|
597 |
log.finer("XCP coalescePaintEvent : PAINT : add : x = " + |
|
598 |
r.x + ", y = " + r.y + ", width = " + r.width + ",height = " + r.height); |
|
599 |
return; |
|
600 |
} |
|
601 |
} |
|
602 |
} |
|
603 |
||
604 |
XWindowPeer getParentTopLevel() { |
|
605 |
Container parent = (target instanceof Container) ? ((Container)target) : (ComponentAccessor.getParent_NoClientCode(target)); |
|
606 |
// Search for parent window |
|
607 |
while (parent != null && !(parent instanceof Window)) { |
|
608 |
parent = ComponentAccessor.getParent_NoClientCode(parent); |
|
609 |
} |
|
610 |
if (parent != null) { |
|
611 |
return (XWindowPeer)ComponentAccessor.getPeer(parent); |
|
612 |
} else { |
|
613 |
return null; |
|
614 |
} |
|
615 |
} |
|
616 |
||
617 |
/* This method is intended to be over-ridden by peers to perform user interaction */ |
|
618 |
void handleJavaMouseEvent(MouseEvent e) { |
|
619 |
switch (e.getID()) { |
|
620 |
case MouseEvent.MOUSE_PRESSED: |
|
621 |
if (target == e.getSource() && shouldFocusOnClick() |
|
622 |
&& !target.isFocusOwner() && canBeFocusedByClick(target)) |
|
623 |
{ |
|
624 |
XWindowPeer parentXWindow = getParentTopLevel(); |
|
625 |
Window parentWindow = ((Window)parentXWindow.getTarget()); |
|
626 |
// Simple windows are non-focusable in X terms but focusable in Java terms. |
|
627 |
// As X-non-focusable they don't receive any focus events - we should generate them |
|
628 |
// by ourselfves. |
|
629 |
// if (parentXWindow.isFocusableWindow() /*&& parentXWindow.isSimpleWindow()*/ && |
|
630 |
// !(getCurrentNativeFocusedWindow() == parentWindow)) |
|
631 |
// { |
|
632 |
// setCurrentNativeFocusedWindow(parentWindow); |
|
633 |
// WindowEvent wfg = new WindowEvent(parentWindow, WindowEvent.WINDOW_GAINED_FOCUS); |
|
634 |
// parentWindow.dispatchEvent(wfg); |
|
635 |
// } |
|
636 |
callRequestFocus(target, CausedFocusEvent.Cause.MOUSE_EVENT); |
|
637 |
} |
|
638 |
break; |
|
639 |
} |
|
640 |
} |
|
641 |
||
642 |
/* This method is intended to be over-ridden by peers to perform user interaction */ |
|
643 |
void handleJavaKeyEvent(KeyEvent e) { |
|
644 |
} |
|
645 |
||
646 |
/* This method is intended to be over-ridden by peers to perform user interaction */ |
|
647 |
void handleJavaMouseWheelEvent(MouseWheelEvent e) { |
|
648 |
} |
|
649 |
||
650 |
||
651 |
/* This method is intended to be over-ridden by peers to perform user interaction */ |
|
652 |
void handleJavaInputMethodEvent(InputMethodEvent e) { |
|
653 |
} |
|
654 |
||
655 |
void handleF10JavaKeyEvent(KeyEvent e) { |
|
656 |
if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_F10) { |
|
657 |
XWindowPeer winPeer = this.getToplevelXWindow(); |
|
658 |
if (winPeer instanceof XFramePeer) { |
|
659 |
XMenuBarPeer mPeer = ((XFramePeer)winPeer).getMenubarPeer(); |
|
660 |
if (mPeer != null) { |
|
661 |
mPeer.handleF10KeyPress(e); |
|
662 |
} |
|
663 |
} |
|
664 |
} |
|
665 |
} |
|
666 |
||
667 |
public void handleEvent(java.awt.AWTEvent e) { |
|
668 |
if ((e instanceof InputEvent) && !((InputEvent)e).isConsumed() && target.isEnabled()) { |
|
669 |
if (e instanceof MouseEvent) { |
|
670 |
if (e instanceof MouseWheelEvent) { |
|
671 |
handleJavaMouseWheelEvent((MouseWheelEvent) e); |
|
672 |
} |
|
673 |
else |
|
674 |
handleJavaMouseEvent((MouseEvent) e); |
|
675 |
} |
|
676 |
else if (e instanceof KeyEvent) { |
|
677 |
handleF10JavaKeyEvent((KeyEvent)e); |
|
678 |
handleJavaKeyEvent((KeyEvent)e); |
|
679 |
} |
|
680 |
} |
|
681 |
else if (e instanceof KeyEvent && !((InputEvent)e).isConsumed()) { |
|
682 |
// even if target is disabled. |
|
683 |
handleF10JavaKeyEvent((KeyEvent)e); |
|
684 |
} |
|
685 |
else if (e instanceof InputMethodEvent) { |
|
686 |
handleJavaInputMethodEvent((InputMethodEvent) e); |
|
687 |
} |
|
688 |
||
689 |
int id = e.getID(); |
|
690 |
||
691 |
switch(id) { |
|
692 |
case PaintEvent.PAINT: |
|
693 |
// Got native painting |
|
694 |
paintPending = false; |
|
695 |
// Fallthrough to next statement |
|
696 |
case PaintEvent.UPDATE: |
|
697 |
// Skip all painting while layouting and all UPDATEs |
|
698 |
// while waiting for native paint |
|
699 |
if (!isLayouting && !paintPending) { |
|
700 |
paintArea.paint(target,false); |
|
701 |
} |
|
702 |
return; |
|
703 |
case FocusEvent.FOCUS_LOST: |
|
704 |
case FocusEvent.FOCUS_GAINED: |
|
705 |
handleJavaFocusEvent(e); |
|
706 |
break; |
|
707 |
case WindowEvent.WINDOW_LOST_FOCUS: |
|
708 |
case WindowEvent.WINDOW_GAINED_FOCUS: |
|
709 |
handleJavaWindowFocusEvent(e); |
|
710 |
break; |
|
711 |
default: |
|
712 |
break; |
|
713 |
} |
|
714 |
||
715 |
} |
|
716 |
||
717 |
public void handleButtonPressRelease(XEvent xev) { |
|
718 |
/* |
|
719 |
* Fix for 6385277. |
|
720 |
* We request focus on simple Window by click in order |
|
721 |
* to make it behave like Frame/Dialog in this case and also to unify |
|
722 |
* the behaviour with what we have on MS Windows. |
|
723 |
* handleJavaMouseEvent() would be more suitable place to do this |
|
724 |
* but we want Swing to have this functionality also. |
|
725 |
*/ |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
726 |
if (xev.get_type() == XConstants.ButtonPress) { |
2 | 727 |
final XWindowPeer parentXWindow = getParentTopLevel(); |
728 |
Window parentWindow = (Window)parentXWindow.getTarget(); |
|
729 |
if (parentXWindow.isFocusableWindow() && parentXWindow.isSimpleWindow() && |
|
730 |
XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow() != parentWindow) |
|
731 |
{ |
|
732 |
postEvent(new InvocationEvent(parentWindow, new Runnable() { |
|
733 |
public void run() { |
|
734 |
// Request focus on the EDT of 'parentWindow' because |
|
735 |
// XDecoratedPeer.requestWindowFocus() calls client code. |
|
736 |
parentXWindow.requestXFocus(); |
|
737 |
} |
|
738 |
})); |
|
739 |
} |
|
740 |
} |
|
741 |
super.handleButtonPressRelease(xev); |
|
742 |
} |
|
743 |
||
744 |
public Dimension getMinimumSize() { |
|
745 |
return target.getSize(); |
|
746 |
} |
|
747 |
||
748 |
public Dimension getPreferredSize() { |
|
749 |
return getMinimumSize(); |
|
750 |
} |
|
751 |
||
752 |
public void layout() {} |
|
753 |
||
754 |
public java.awt.Toolkit getToolkit() { |
|
755 |
return Toolkit.getDefaultToolkit(); |
|
756 |
} |
|
757 |
||
758 |
void updateMotifColors(Color bg) { |
|
759 |
int red = bg.getRed(); |
|
760 |
int green = bg.getGreen(); |
|
761 |
int blue = bg.getBlue(); |
|
762 |
||
763 |
darkShadow = new Color(MotifColorUtilities.calculateBottomShadowFromBackground(red,green,blue)); |
|
764 |
lightShadow = new Color(MotifColorUtilities.calculateTopShadowFromBackground(red,green,blue)); |
|
765 |
selectColor= new Color(MotifColorUtilities.calculateSelectFromBackground(red,green,blue)); |
|
766 |
} |
|
767 |
||
768 |
/* |
|
769 |
* Draw a 3D rectangle using the Motif colors. |
|
770 |
* "Normal" rectangles have shadows on the bottom. |
|
771 |
* "Depressed" rectangles (such as pressed buttons) have shadows on the top, |
|
772 |
* in which case true should be passed for topShadow. |
|
773 |
*/ |
|
774 |
public void drawMotif3DRect(Graphics g, |
|
775 |
int x, int y, int width, int height, |
|
776 |
boolean topShadow) { |
|
777 |
g.setColor(topShadow ? darkShadow : lightShadow); |
|
778 |
g.drawLine(x, y, x+width, y); // top |
|
779 |
g.drawLine(x, y+height, x, y); // left |
|
780 |
||
781 |
g.setColor(topShadow ? lightShadow : darkShadow ); |
|
782 |
g.drawLine(x+1, y+height, x+width, y+height); // bottom |
|
783 |
g.drawLine(x+width, y+height, x+width, y+1); // right |
|
784 |
} |
|
785 |
||
786 |
public void setBackground(Color c) { |
|
787 |
if (log.isLoggable(Level.FINE)) log.fine("Set background to " + c); |
|
788 |
synchronized (getStateLock()) { |
|
789 |
background = c; |
|
790 |
} |
|
791 |
super.setBackground(c); |
|
792 |
repaint(); |
|
793 |
} |
|
794 |
||
795 |
public void setForeground(Color c) { |
|
796 |
if (log.isLoggable(Level.FINE)) log.fine("Set foreground to " + c); |
|
797 |
synchronized (getStateLock()) { |
|
798 |
foreground = c; |
|
799 |
} |
|
800 |
repaint(); |
|
801 |
} |
|
802 |
||
803 |
/** |
|
804 |
* Gets the font metrics for the specified font. |
|
805 |
* @param font the font for which font metrics is to be |
|
806 |
* obtained |
|
807 |
* @return the font metrics for <code>font</code> |
|
808 |
* @see #getFont |
|
809 |
* @see #getPeer |
|
810 |
* @see java.awt.peer.ComponentPeer#getFontMetrics(Font) |
|
811 |
* @see Toolkit#getFontMetrics(Font) |
|
812 |
* @since JDK1.0 |
|
813 |
*/ |
|
814 |
public FontMetrics getFontMetrics(Font font) { |
|
815 |
if (fontLog.isLoggable(Level.FINE)) fontLog.fine("Getting font metrics for " + font); |
|
816 |
return sun.font.FontDesignMetrics.getMetrics(font); |
|
817 |
} |
|
818 |
||
819 |
public void setFont(Font f) { |
|
820 |
synchronized (getStateLock()) { |
|
821 |
if (f == null) { |
|
116
9c43d9eb1029
6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents:
2
diff
changeset
|
822 |
f = XWindow.getDefaultFont(); |
2 | 823 |
} |
824 |
font = f; |
|
825 |
} |
|
826 |
// as it stands currently we dont need to do layout or repaint since |
|
827 |
// layout is done in the Component upon setFont. |
|
828 |
//layout(); |
|
829 |
// target.repaint(); |
|
830 |
//repaint()? |
|
831 |
} |
|
832 |
||
833 |
public Font getFont() { |
|
834 |
return font; |
|
835 |
} |
|
836 |
||
837 |
public void updateCursorImmediately() { |
|
838 |
XGlobalCursorManager.getCursorManager().updateCursorImmediately(); |
|
839 |
} |
|
840 |
||
841 |
public void pSetCursor(Cursor cursor) { |
|
842 |
XToolkit.awtLock(); |
|
843 |
try { |
|
844 |
long xcursor = XGlobalCursorManager.getCursor(cursor); |
|
845 |
||
846 |
XSetWindowAttributes xwa = new XSetWindowAttributes(); |
|
847 |
xwa.set_cursor(xcursor); |
|
848 |
||
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
849 |
long valuemask = XConstants.CWCursor; |
2 | 850 |
|
851 |
XlibWrapper.XChangeWindowAttributes(XToolkit.getDisplay(),getWindow(),valuemask,xwa.pData); |
|
852 |
XlibWrapper.XFlush(XToolkit.getDisplay()); |
|
853 |
xwa.dispose(); |
|
854 |
} finally { |
|
855 |
XToolkit.awtUnlock(); |
|
856 |
} |
|
857 |
} |
|
858 |
||
859 |
public Image createImage(ImageProducer producer) { |
|
860 |
return new ToolkitImage(producer); |
|
861 |
} |
|
862 |
||
863 |
public Image createImage(int width, int height) { |
|
864 |
return graphicsConfig.createAcceleratedImage(target, width, height); |
|
865 |
} |
|
866 |
||
867 |
public VolatileImage createVolatileImage(int width, int height) { |
|
868 |
return new SunVolatileImage(target, width, height); |
|
869 |
} |
|
870 |
||
871 |
public boolean prepareImage(Image img, int w, int h, ImageObserver o) { |
|
872 |
return getToolkit().prepareImage(img, w, h, o); |
|
873 |
} |
|
874 |
||
875 |
public int checkImage(Image img, int w, int h, ImageObserver o) { |
|
876 |
return getToolkit().checkImage(img, w, h, o); |
|
877 |
} |
|
878 |
||
879 |
public Dimension preferredSize() { |
|
880 |
return getPreferredSize(); |
|
881 |
} |
|
882 |
||
883 |
public Dimension minimumSize() { |
|
884 |
return getMinimumSize(); |
|
885 |
} |
|
886 |
||
887 |
public Insets getInsets() { |
|
888 |
return new Insets(0, 0, 0, 0); |
|
889 |
} |
|
890 |
||
891 |
public void beginValidate() { |
|
892 |
} |
|
893 |
||
894 |
public void endValidate() { |
|
895 |
} |
|
896 |
||
897 |
||
898 |
/** |
|
899 |
* DEPRECATED: Replaced by getInsets(). |
|
900 |
*/ |
|
901 |
||
902 |
public Insets insets() { |
|
903 |
return getInsets(); |
|
904 |
} |
|
905 |
||
906 |
// Returns true if we are inside begin/endLayout and |
|
907 |
// are waiting for native painting |
|
908 |
public boolean isPaintPending() { |
|
909 |
return paintPending && isLayouting; |
|
910 |
} |
|
911 |
||
912 |
public boolean handlesWheelScrolling() { |
|
913 |
return false; |
|
914 |
} |
|
915 |
||
916 |
public void beginLayout() { |
|
917 |
// Skip all painting till endLayout |
|
918 |
isLayouting = true; |
|
919 |
||
920 |
} |
|
921 |
||
922 |
public void endLayout() { |
|
923 |
if (!paintPending && !paintArea.isEmpty() |
|
924 |
&& !ComponentAccessor.getIgnoreRepaint(target)) |
|
925 |
{ |
|
926 |
// if not waiting for native painting repaint damaged area |
|
927 |
postEvent(new PaintEvent(target, PaintEvent.PAINT, |
|
928 |
new Rectangle())); |
|
929 |
} |
|
930 |
isLayouting = false; |
|
931 |
} |
|
932 |
||
933 |
public Color getWinBackground() { |
|
934 |
return getPeerBackground(); |
|
935 |
} |
|
936 |
||
937 |
static int[] getRGBvals(Color c) { |
|
938 |
||
939 |
int rgbvals[] = new int[3]; |
|
940 |
||
941 |
rgbvals[0] = c.getRed(); |
|
942 |
rgbvals[1] = c.getGreen(); |
|
943 |
rgbvals[2] = c.getBlue(); |
|
944 |
||
945 |
return rgbvals; |
|
946 |
} |
|
947 |
||
948 |
static final int BACKGROUND_COLOR = 0; |
|
949 |
static final int HIGHLIGHT_COLOR = 1; |
|
950 |
static final int SHADOW_COLOR = 2; |
|
951 |
static final int FOREGROUND_COLOR = 3; |
|
952 |
||
953 |
public Color[] getGUIcolors() { |
|
954 |
Color c[] = new Color[4]; |
|
955 |
float backb, highb, shadowb, hue, saturation; |
|
956 |
c[BACKGROUND_COLOR] = getWinBackground(); |
|
957 |
if (c[BACKGROUND_COLOR] == null) { |
|
958 |
c[BACKGROUND_COLOR] = super.getWinBackground(); |
|
959 |
} |
|
960 |
if (c[BACKGROUND_COLOR] == null) { |
|
961 |
c[BACKGROUND_COLOR] = Color.lightGray; |
|
962 |
} |
|
963 |
||
964 |
int[] rgb = getRGBvals(c[BACKGROUND_COLOR]); |
|
965 |
||
966 |
float[] hsb = Color.RGBtoHSB(rgb[0],rgb[1],rgb[2],null); |
|
967 |
||
968 |
hue = hsb[0]; |
|
969 |
saturation = hsb[1]; |
|
970 |
backb = hsb[2]; |
|
971 |
||
972 |
||
973 |
/* Calculate Highlight Brightness */ |
|
974 |
||
975 |
highb = backb + 0.2f; |
|
976 |
shadowb = backb - 0.4f; |
|
977 |
if ((highb > 1.0) ) { |
|
978 |
if ((1.0 - backb) < 0.05) { |
|
979 |
highb = shadowb + 0.25f; |
|
980 |
} else { |
|
981 |
highb = 1.0f; |
|
982 |
} |
|
983 |
} else { |
|
984 |
if (shadowb < 0.0) { |
|
985 |
if ((backb - 0.0) < 0.25) { |
|
986 |
highb = backb + 0.75f; |
|
987 |
shadowb = highb - 0.2f; |
|
988 |
} else { |
|
989 |
shadowb = 0.0f; |
|
990 |
} |
|
991 |
} |
|
992 |
} |
|
993 |
c[HIGHLIGHT_COLOR] = Color.getHSBColor(hue,saturation,highb); |
|
994 |
c[SHADOW_COLOR] = Color.getHSBColor(hue,saturation,shadowb); |
|
995 |
||
996 |
||
997 |
/* |
|
998 |
c[SHADOW_COLOR] = c[BACKGROUND_COLOR].darker(); |
|
999 |
int r2 = c[SHADOW_COLOR].getRed(); |
|
1000 |
int g2 = c[SHADOW_COLOR].getGreen(); |
|
1001 |
int b2 = c[SHADOW_COLOR].getBlue(); |
|
1002 |
*/ |
|
1003 |
||
1004 |
c[FOREGROUND_COLOR] = getPeerForeground(); |
|
1005 |
if (c[FOREGROUND_COLOR] == null) { |
|
1006 |
c[FOREGROUND_COLOR] = Color.black; |
|
1007 |
} |
|
1008 |
/* |
|
1009 |
if ((c[BACKGROUND_COLOR].equals(c[HIGHLIGHT_COLOR])) |
|
1010 |
&& (c[BACKGROUND_COLOR].equals(c[SHADOW_COLOR]))) { |
|
1011 |
c[SHADOW_COLOR] = new Color(c[BACKGROUND_COLOR].getRed() + 75, |
|
1012 |
c[BACKGROUND_COLOR].getGreen() + 75, |
|
1013 |
c[BACKGROUND_COLOR].getBlue() + 75); |
|
1014 |
c[HIGHLIGHT_COLOR] = c[SHADOW_COLOR].brighter(); |
|
1015 |
} else if (c[BACKGROUND_COLOR].equals(c[HIGHLIGHT_COLOR])) { |
|
1016 |
c[HIGHLIGHT_COLOR] = c[SHADOW_COLOR]; |
|
1017 |
c[SHADOW_COLOR] = c[SHADOW_COLOR].darker(); |
|
1018 |
} |
|
1019 |
*/ |
|
1020 |
if (! isEnabled()) { |
|
1021 |
c[BACKGROUND_COLOR] = c[BACKGROUND_COLOR].darker(); |
|
1022 |
// Reduce the contrast |
|
1023 |
// Calculate the NTSC gray (NB: REC709 L* might be better!) |
|
1024 |
// for foreground and background; then multiply the foreground |
|
1025 |
// by the average lightness |
|
1026 |
||
1027 |
||
1028 |
Color tc = c[BACKGROUND_COLOR]; |
|
1029 |
int bg = tc.getRed() * 30 + tc.getGreen() * 59 + tc.getBlue() * 11; |
|
1030 |
||
1031 |
tc = c[FOREGROUND_COLOR]; |
|
1032 |
int fg = tc.getRed() * 30 + tc.getGreen() * 59 + tc.getBlue() * 11; |
|
1033 |
||
1034 |
float ave = (float) ((fg + bg) / 51000.0); |
|
1035 |
// 255 * 100 * 2 |
|
1036 |
||
1037 |
Color newForeground = new Color((int) (tc.getRed() * ave), |
|
1038 |
(int) (tc.getGreen() * ave), |
|
1039 |
(int) (tc.getBlue() * ave)); |
|
1040 |
||
1041 |
if (newForeground.equals(c[FOREGROUND_COLOR])) { |
|
1042 |
// This probably means the foreground color is black or white |
|
1043 |
newForeground = new Color(ave, ave, ave); |
|
1044 |
} |
|
1045 |
c[FOREGROUND_COLOR] = newForeground; |
|
1046 |
||
1047 |
} |
|
1048 |
||
1049 |
||
1050 |
return c; |
|
1051 |
} |
|
1052 |
||
1053 |
/** |
|
1054 |
* Returns an array of Colors similar to getGUIcolors(), but using the |
|
1055 |
* System colors. This is useful if pieces of a Component (such as |
|
1056 |
* the integrated scrollbars of a List) should retain the System color |
|
1057 |
* instead of the background color set by Component.setBackground(). |
|
1058 |
*/ |
|
1059 |
static Color[] getSystemColors() { |
|
1060 |
if (systemColors == null) { |
|
1061 |
systemColors = new Color[4]; |
|
1062 |
systemColors[BACKGROUND_COLOR] = SystemColor.window; |
|
1063 |
systemColors[HIGHLIGHT_COLOR] = SystemColor.controlLtHighlight; |
|
1064 |
systemColors[SHADOW_COLOR] = SystemColor.controlShadow; |
|
1065 |
systemColors[FOREGROUND_COLOR] = SystemColor.windowText; |
|
1066 |
} |
|
1067 |
return systemColors; |
|
1068 |
} |
|
1069 |
||
1070 |
/** |
|
1071 |
* Draw a 3D oval. |
|
1072 |
*/ |
|
1073 |
public void draw3DOval(Graphics g, Color colors[], |
|
1074 |
int x, int y, int w, int h, boolean raised) |
|
1075 |
{ |
|
1076 |
Color c = g.getColor(); |
|
1077 |
g.setColor(raised ? colors[HIGHLIGHT_COLOR] : colors[SHADOW_COLOR]); |
|
1078 |
g.drawArc(x, y, w, h, 45, 180); |
|
1079 |
g.setColor(raised ? colors[SHADOW_COLOR] : colors[HIGHLIGHT_COLOR]); |
|
1080 |
g.drawArc(x, y, w, h, 225, 180); |
|
1081 |
g.setColor(c); |
|
1082 |
} |
|
1083 |
||
1084 |
public void draw3DRect(Graphics g, Color colors[], |
|
1085 |
int x, int y, int width, int height, boolean raised) |
|
1086 |
{ |
|
1087 |
Color c = g.getColor(); |
|
1088 |
g.setColor(raised ? colors[HIGHLIGHT_COLOR] : colors[SHADOW_COLOR]); |
|
1089 |
g.drawLine(x, y, x, y + height); |
|
1090 |
g.drawLine(x + 1, y, x + width - 1, y); |
|
1091 |
g.setColor(raised ? colors[SHADOW_COLOR] : colors[HIGHLIGHT_COLOR]); |
|
1092 |
g.drawLine(x + 1, y + height, x + width, y + height); |
|
1093 |
g.drawLine(x + width, y, x + width, y + height - 1); |
|
1094 |
g.setColor(c); |
|
1095 |
} |
|
1096 |
||
1097 |
/* |
|
1098 |
* drawXXX() methods are used to print the native components by |
|
1099 |
* rendering the Motif look ourselves. |
|
1100 |
* ToDo(aim): needs to query native motif for more accurate color |
|
1101 |
* information. |
|
1102 |
*/ |
|
1103 |
void draw3DOval(Graphics g, Color bg, |
|
1104 |
int x, int y, int w, int h, boolean raised) |
|
1105 |
{ |
|
1106 |
Color c = g.getColor(); |
|
1107 |
Color shadow = bg.darker(); |
|
1108 |
Color highlight = bg.brighter(); |
|
1109 |
||
1110 |
g.setColor(raised ? highlight : shadow); |
|
1111 |
g.drawArc(x, y, w, h, 45, 180); |
|
1112 |
g.setColor(raised ? shadow : highlight); |
|
1113 |
g.drawArc(x, y, w, h, 225, 180); |
|
1114 |
g.setColor(c); |
|
1115 |
} |
|
1116 |
||
1117 |
void draw3DRect(Graphics g, Color bg, |
|
1118 |
int x, int y, int width, int height, |
|
1119 |
boolean raised) { |
|
1120 |
Color c = g.getColor(); |
|
1121 |
Color shadow = bg.darker(); |
|
1122 |
Color highlight = bg.brighter(); |
|
1123 |
||
1124 |
g.setColor(raised ? highlight : shadow); |
|
1125 |
g.drawLine(x, y, x, y + height); |
|
1126 |
g.drawLine(x + 1, y, x + width - 1, y); |
|
1127 |
g.setColor(raised ? shadow : highlight); |
|
1128 |
g.drawLine(x + 1, y + height, x + width, y + height); |
|
1129 |
g.drawLine(x + width, y, x + width, y + height - 1); |
|
1130 |
g.setColor(c); |
|
1131 |
} |
|
1132 |
||
1133 |
void drawScrollbar(Graphics g, Color bg, int thickness, int length, |
|
1134 |
int min, int max, int val, int vis, boolean horizontal) { |
|
1135 |
Color c = g.getColor(); |
|
1136 |
double f = (double)(length - 2*(thickness-1)) / Math.max(1, ((max - min) + vis)); |
|
1137 |
int v1 = thickness + (int)(f * (val - min)); |
|
1138 |
int v2 = (int)(f * vis); |
|
1139 |
int w2 = thickness-4; |
|
1140 |
int tpts_x[] = new int[3]; |
|
1141 |
int tpts_y[] = new int[3]; |
|
1142 |
||
1143 |
if (length < 3*w2 ) { |
|
1144 |
v1 = v2 = 0; |
|
1145 |
if (length < 2*w2 + 2) { |
|
1146 |
w2 = (length-2)/2; |
|
1147 |
} |
|
1148 |
} else if (v2 < 7) { |
|
1149 |
// enforce a minimum handle size |
|
1150 |
v1 = Math.max(0, v1 - ((7 - v2)>>1)); |
|
1151 |
v2 = 7; |
|
1152 |
} |
|
1153 |
||
1154 |
int ctr = thickness/2; |
|
1155 |
int sbmin = ctr - w2/2; |
|
1156 |
int sbmax = ctr + w2/2; |
|
1157 |
||
1158 |
// paint the background slightly darker |
|
1159 |
{ |
|
1160 |
Color d = new Color((int) (bg.getRed() * 0.85), |
|
1161 |
(int) (bg.getGreen() * 0.85), |
|
1162 |
(int) (bg.getBlue() * 0.85)); |
|
1163 |
||
1164 |
g.setColor(d); |
|
1165 |
if (horizontal) { |
|
1166 |
g.fillRect(0, 0, length, thickness); |
|
1167 |
} else { |
|
1168 |
g.fillRect(0, 0, thickness, length); |
|
1169 |
} |
|
1170 |
} |
|
1171 |
||
1172 |
// paint the thumb and arrows in the normal background color |
|
1173 |
g.setColor(bg); |
|
1174 |
if (v1 > 0) { |
|
1175 |
if (horizontal) { |
|
1176 |
g.fillRect(v1, 3, v2, thickness-3); |
|
1177 |
} else { |
|
1178 |
g.fillRect(3, v1, thickness-3, v2); |
|
1179 |
} |
|
1180 |
} |
|
1181 |
||
1182 |
tpts_x[0] = ctr; tpts_y[0] = 2; |
|
1183 |
tpts_x[1] = sbmin; tpts_y[1] = w2; |
|
1184 |
tpts_x[2] = sbmax; tpts_y[2] = w2; |
|
1185 |
if (horizontal) { |
|
1186 |
g.fillPolygon(tpts_y, tpts_x, 3); |
|
1187 |
} else { |
|
1188 |
g.fillPolygon(tpts_x, tpts_y, 3); |
|
1189 |
} |
|
1190 |
||
1191 |
tpts_y[0] = length-2; |
|
1192 |
tpts_y[1] = length-w2; |
|
1193 |
tpts_y[2] = length-w2; |
|
1194 |
if (horizontal) { |
|
1195 |
g.fillPolygon(tpts_y, tpts_x, 3); |
|
1196 |
} else { |
|
1197 |
g.fillPolygon(tpts_x, tpts_y, 3); |
|
1198 |
} |
|
1199 |
||
1200 |
Color highlight = bg.brighter(); |
|
1201 |
||
1202 |
// // // // draw the "highlighted" edges |
|
1203 |
g.setColor(highlight); |
|
1204 |
||
1205 |
// outline & arrows |
|
1206 |
if (horizontal) { |
|
1207 |
g.drawLine(1, thickness, length - 1, thickness); |
|
1208 |
g.drawLine(length - 1, 1, length - 1, thickness); |
|
1209 |
||
1210 |
// arrows |
|
1211 |
g.drawLine(1, ctr, w2, sbmin); |
|
1212 |
g.drawLine(length - w2, sbmin, length - w2, sbmax); |
|
1213 |
g.drawLine(length - w2, sbmin, length - 2, ctr); |
|
1214 |
||
1215 |
} else { |
|
1216 |
g.drawLine(thickness, 1, thickness, length - 1); |
|
1217 |
g.drawLine(1, length - 1, thickness, length - 1); |
|
1218 |
||
1219 |
// arrows |
|
1220 |
g.drawLine(ctr, 1, sbmin, w2); |
|
1221 |
g.drawLine(sbmin, length - w2, sbmax, length - w2); |
|
1222 |
g.drawLine(sbmin, length - w2, ctr, length - 2); |
|
1223 |
} |
|
1224 |
||
1225 |
// thumb |
|
1226 |
if (v1 > 0) { |
|
1227 |
if (horizontal) { |
|
1228 |
g.drawLine(v1, 2, v1 + v2, 2); |
|
1229 |
g.drawLine(v1, 2, v1, thickness-3); |
|
1230 |
} else { |
|
1231 |
g.drawLine(2, v1, 2, v1 + v2); |
|
1232 |
g.drawLine(2, v1, thickness-3, v1); |
|
1233 |
} |
|
1234 |
} |
|
1235 |
||
1236 |
Color shadow = bg.darker(); |
|
1237 |
||
1238 |
// // // // draw the "shadowed" edges |
|
1239 |
g.setColor(shadow); |
|
1240 |
||
1241 |
// outline && arrows |
|
1242 |
if (horizontal) { |
|
1243 |
g.drawLine(0, 0, 0, thickness); |
|
1244 |
g.drawLine(0, 0, length - 1, 0); |
|
1245 |
||
1246 |
// arrows |
|
1247 |
g.drawLine(w2, sbmin, w2, sbmax); |
|
1248 |
g.drawLine(w2, sbmax, 1, ctr); |
|
1249 |
g.drawLine(length-2, ctr, length-w2, sbmax); |
|
1250 |
||
1251 |
} else { |
|
1252 |
g.drawLine(0, 0, thickness, 0); |
|
1253 |
g.drawLine(0, 0, 0, length - 1); |
|
1254 |
||
1255 |
// arrows |
|
1256 |
g.drawLine(sbmin, w2, sbmax, w2); |
|
1257 |
g.drawLine(sbmax, w2, ctr, 1); |
|
1258 |
g.drawLine(ctr, length-2, sbmax, length-w2); |
|
1259 |
} |
|
1260 |
||
1261 |
// thumb |
|
1262 |
if (v1 > 0) { |
|
1263 |
if (horizontal) { |
|
1264 |
g.drawLine(v1 + v2, 2, v1 + v2, thickness-2); |
|
1265 |
g.drawLine(v1, thickness-2, v1 + v2, thickness-2); |
|
1266 |
} else { |
|
1267 |
g.drawLine(2, v1 + v2, thickness-2, v1 + v2); |
|
1268 |
g.drawLine(thickness-2, v1, thickness-2, v1 + v2); |
|
1269 |
} |
|
1270 |
} |
|
1271 |
g.setColor(c); |
|
1272 |
} |
|
1273 |
||
1274 |
/** |
|
1275 |
* The following multibuffering-related methods delegate to our |
|
1276 |
* associated GraphicsConfig (X11 or GLX) to handle the appropriate |
|
1277 |
* native windowing system specific actions. |
|
1278 |
*/ |
|
1279 |
||
887 | 1280 |
private BufferCapabilities backBufferCaps; |
1281 |
||
2 | 1282 |
public void createBuffers(int numBuffers, BufferCapabilities caps) |
1283 |
throws AWTException |
|
1284 |
{ |
|
1285 |
if (buffersLog.isLoggable(Level.FINE)) { |
|
1286 |
buffersLog.fine("createBuffers(" + numBuffers + ", " + caps + ")"); |
|
1287 |
} |
|
887 | 1288 |
// set the caps first, they're used when creating the bb |
1289 |
backBufferCaps = caps; |
|
2 | 1290 |
backBuffer = graphicsConfig.createBackBuffer(this, numBuffers, caps); |
1291 |
xBackBuffer = graphicsConfig.createBackBufferImage(target, |
|
1292 |
backBuffer); |
|
1293 |
} |
|
1294 |
||
887 | 1295 |
@Override |
1296 |
public BufferCapabilities getBackBufferCaps() { |
|
1297 |
return backBufferCaps; |
|
1298 |
} |
|
1299 |
||
1300 |
public void flip(int x1, int y1, int x2, int y2, |
|
1301 |
BufferCapabilities.FlipContents flipAction) |
|
1302 |
{ |
|
2 | 1303 |
if (buffersLog.isLoggable(Level.FINE)) { |
1304 |
buffersLog.fine("flip(" + flipAction + ")"); |
|
1305 |
} |
|
1306 |
if (backBuffer == 0) { |
|
1307 |
throw new IllegalStateException("Buffers have not been created"); |
|
1308 |
} |
|
887 | 1309 |
graphicsConfig.flip(this, target, xBackBuffer, |
1310 |
x1, y1, x2, y2, flipAction); |
|
2 | 1311 |
} |
1312 |
||
1313 |
public Image getBackBuffer() { |
|
1314 |
if (buffersLog.isLoggable(Level.FINE)) { |
|
1315 |
buffersLog.fine("getBackBuffer()"); |
|
1316 |
} |
|
1317 |
if (backBuffer == 0) { |
|
1318 |
throw new IllegalStateException("Buffers have not been created"); |
|
1319 |
} |
|
1320 |
return xBackBuffer; |
|
1321 |
} |
|
1322 |
||
1323 |
public void destroyBuffers() { |
|
1324 |
if (buffersLog.isLoggable(Level.FINE)) { |
|
1325 |
buffersLog.fine("destroyBuffers()"); |
|
1326 |
} |
|
1327 |
graphicsConfig.destroyBackBuffer(backBuffer); |
|
1328 |
backBuffer = 0; |
|
1329 |
xBackBuffer = null; |
|
1330 |
} |
|
1331 |
||
1332 |
// End of multi-buffering |
|
1333 |
||
1334 |
public void notifyTextComponentChange(boolean add){ |
|
1335 |
Container parent = ComponentAccessor.getParent_NoClientCode(target); |
|
1336 |
while(!(parent == null || |
|
1337 |
parent instanceof java.awt.Frame || |
|
1338 |
parent instanceof java.awt.Dialog)) { |
|
1339 |
parent = ComponentAccessor.getParent_NoClientCode(parent); |
|
1340 |
} |
|
1341 |
||
1342 |
/* FIX ME - FIX ME need to implement InputMethods |
|
1343 |
if (parent instanceof java.awt.Frame || |
|
1344 |
parent instanceof java.awt.Dialog) { |
|
1345 |
if (add) |
|
1346 |
((MInputMethodControl)parent.getPeer()).addTextComponent((MComponentPeer)this); |
|
1347 |
else |
|
1348 |
((MInputMethodControl)parent.getPeer()).removeTextComponent((MComponentPeer)this); |
|
1349 |
} |
|
1350 |
*/ |
|
1351 |
} |
|
1352 |
||
1353 |
/** |
|
1354 |
* Returns true if this event is disabled and shouldn't be processed by window |
|
1355 |
* Currently if target component is disabled the following event will be disabled on window: |
|
1356 |
* ButtonPress, ButtonRelease, KeyPress, KeyRelease, EnterNotify, LeaveNotify, MotionNotify |
|
1357 |
*/ |
|
1358 |
protected boolean isEventDisabled(XEvent e) { |
|
1359 |
enableLog.log(Level.FINEST, "Component is {1}, checking for disabled event {0}", new Object[] {e, (isEnabled()?"enabled":"disable")}); |
|
1360 |
if (!isEnabled()) { |
|
1361 |
switch (e.get_type()) { |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
1362 |
case XConstants.ButtonPress: |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
1363 |
case XConstants.ButtonRelease: |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
1364 |
case XConstants.KeyPress: |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
1365 |
case XConstants.KeyRelease: |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
1366 |
case XConstants.EnterNotify: |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
1367 |
case XConstants.LeaveNotify: |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
1368 |
case XConstants.MotionNotify: |
2 | 1369 |
enableLog.log(Level.FINER, "Event {0} is disable", new Object[] {e}); |
1370 |
return true; |
|
1371 |
} |
|
1372 |
} |
|
1373 |
switch(e.get_type()) { |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
1374 |
case XConstants.MapNotify: |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
1375 |
case XConstants.UnmapNotify: |
2 | 1376 |
return true; |
1377 |
} |
|
1378 |
return super.isEventDisabled(e); |
|
1379 |
} |
|
1380 |
||
1381 |
Color getPeerBackground() { |
|
1382 |
return background; |
|
1383 |
} |
|
1384 |
||
1385 |
Color getPeerForeground() { |
|
1386 |
return foreground; |
|
1387 |
} |
|
1388 |
||
1389 |
Font getPeerFont() { |
|
1390 |
return font; |
|
1391 |
} |
|
1392 |
||
1393 |
Dimension getPeerSize() { |
|
1394 |
return new Dimension(width,height); |
|
1395 |
} |
|
1396 |
||
1397 |
public void setBoundsOperation(int operation) { |
|
1398 |
synchronized(getStateLock()) { |
|
1399 |
if (boundsOperation == DEFAULT_OPERATION) { |
|
1400 |
boundsOperation = operation; |
|
1401 |
} else if (operation == RESET_OPERATION) { |
|
1402 |
boundsOperation = DEFAULT_OPERATION; |
|
1403 |
} |
|
1404 |
} |
|
1405 |
} |
|
1406 |
||
1407 |
static String operationToString(int operation) { |
|
1408 |
switch (operation) { |
|
1409 |
case SET_LOCATION: |
|
1410 |
return "SET_LOCATION"; |
|
1411 |
case SET_SIZE: |
|
1412 |
return "SET_SIZE"; |
|
1413 |
case SET_CLIENT_SIZE: |
|
1414 |
return "SET_CLIENT_SIZE"; |
|
1415 |
default: |
|
1416 |
case SET_BOUNDS: |
|
1417 |
return "SET_BOUNDS"; |
|
1418 |
} |
|
1419 |
} |
|
1420 |
||
1421 |
public void restack() { |
|
1422 |
synchronized(target.getTreeLock()) { |
|
1423 |
// Build the list of X windows in the window corresponding to this container |
|
1424 |
// This list is already in correct Java stacking order |
|
1425 |
Container cont = (Container)target; |
|
1426 |
Vector order = new Vector(cont.getComponentCount()); |
|
1427 |
HashSet set = new HashSet(); |
|
1428 |
||
1429 |
addTree(order, set, cont); |
|
1430 |
||
1431 |
XToolkit.awtLock(); |
|
1432 |
try { |
|
1433 |
// Get the current list of X window in X window. Some of the windows |
|
1434 |
// might be only native |
|
1435 |
XQueryTree qt = new XQueryTree(getContentWindow()); |
|
1436 |
try { |
|
1437 |
if (qt.execute() != 0) { |
|
1438 |
if (qt.get_nchildren() != 0) { |
|
1439 |
long pchildren = qt.get_children(); |
|
1440 |
int j = 0; // index to insert |
|
1441 |
for (int i = 0; i < qt.get_nchildren(); i++) { |
|
1442 |
Long w = Long.valueOf(Native.getLong(pchildren, i)); |
|
1443 |
if (!set.contains(w)) { |
|
1444 |
set.add(w); |
|
1445 |
order.add(j++, w); |
|
1446 |
} |
|
1447 |
} |
|
1448 |
} |
|
1449 |
} |
|
1450 |
||
1451 |
if (order.size() != 0) { |
|
1452 |
// Create native array of the windows |
|
1453 |
long windows = Native.allocateLongArray(order.size()); |
|
1454 |
Native.putLong(windows, order); |
|
1455 |
||
1456 |
// Restack native window according to the new order |
|
1457 |
XlibWrapper.XRestackWindows(XToolkit.getDisplay(), windows, order.size()); |
|
1458 |
||
1459 |
XlibWrapper.unsafe.freeMemory(windows); |
|
1460 |
} |
|
1461 |
} finally { |
|
1462 |
qt.dispose(); |
|
1463 |
} |
|
1464 |
} finally { |
|
1465 |
XToolkit.awtUnlock(); |
|
1466 |
} |
|
1467 |
} |
|
1468 |
} |
|
1469 |
||
1470 |
public boolean isRestackSupported() { |
|
1471 |
return true; |
|
1472 |
} |
|
1473 |
||
1474 |
private void addTree(Collection order, Set set, Container cont) { |
|
1475 |
for (int i = 0; i < cont.getComponentCount(); i++) { |
|
1476 |
Component comp = cont.getComponent(i); |
|
1477 |
ComponentPeer peer = comp.getPeer(); |
|
1478 |
if (peer instanceof XComponentPeer) { |
|
1479 |
Long window = Long.valueOf(((XComponentPeer)peer).getWindow()); |
|
1480 |
if (!set.contains(window)) { |
|
1481 |
set.add(window); |
|
1482 |
order.add(window); |
|
1483 |
} |
|
1484 |
} else if (comp instanceof Container) { |
|
1485 |
// It is lightweight container, it might contain heavyweight components attached to this |
|
1486 |
// peer |
|
1487 |
addTree(order, set, (Container)comp); |
|
1488 |
} |
|
1489 |
} |
|
1490 |
} |
|
1491 |
||
1492 |
/****** DropTargetPeer implementation ********************/ |
|
1493 |
||
1494 |
public void addDropTarget(DropTarget dt) { |
|
1495 |
Component comp = target; |
|
1496 |
while(!(comp == null || comp instanceof Window)) { |
|
1497 |
comp = comp.getParent(); |
|
1498 |
} |
|
1499 |
||
1500 |
if (comp instanceof Window) { |
|
1501 |
XWindowPeer wpeer = (XWindowPeer)(comp.getPeer()); |
|
1502 |
if (wpeer != null) { |
|
1503 |
wpeer.addDropTarget(); |
|
1504 |
} |
|
1505 |
} |
|
1506 |
} |
|
1507 |
||
1508 |
public void removeDropTarget(DropTarget dt) { |
|
1509 |
Component comp = target; |
|
1510 |
while(!(comp == null || comp instanceof Window)) { |
|
1511 |
comp = comp.getParent(); |
|
1512 |
} |
|
1513 |
||
1514 |
if (comp instanceof Window) { |
|
1515 |
XWindowPeer wpeer = (XWindowPeer)(comp.getPeer()); |
|
1516 |
if (wpeer != null) { |
|
1517 |
wpeer.removeDropTarget(); |
|
1518 |
} |
|
1519 |
} |
|
1520 |
} |
|
1521 |
||
1522 |
/** |
|
1523 |
* Applies the shape to the X-window. |
|
1524 |
* @since 1.7 |
|
1525 |
*/ |
|
1526 |
public void applyShape(Region shape) { |
|
1527 |
if (XlibUtil.isShapingSupported()) { |
|
1528 |
if (shapeLog.isLoggable(Level.FINER)) { |
|
1529 |
shapeLog.finer( |
|
1530 |
"*** INFO: Setting shape: PEER: " + this |
|
1531 |
+ "; WINDOW: " + getWindow() |
|
1532 |
+ "; TARGET: " + target |
|
1533 |
+ "; SHAPE: " + shape); |
|
1534 |
} |
|
1535 |
XToolkit.awtLock(); |
|
1536 |
try { |
|
1537 |
XlibWrapper.SetRectangularShape( |
|
1538 |
XToolkit.getDisplay(), |
|
1539 |
getWindow(), |
|
1540 |
shape.getLoX(), shape.getLoY(), |
|
1541 |
shape.getHiX(), shape.getHiY(), |
|
1542 |
(shape.isRectangular() ? null : shape) |
|
1543 |
); |
|
1544 |
} finally { |
|
1545 |
XToolkit.awtUnlock(); |
|
1546 |
} |
|
1547 |
} else { |
|
1548 |
if (shapeLog.isLoggable(Level.FINER)) { |
|
1549 |
shapeLog.finer("*** WARNING: Shaping is NOT supported!"); |
|
1550 |
} |
|
1551 |
} |
|
1552 |
} |
|
1553 |
} |