1 /* |
|
2 * Copyright 1995-2008 Sun Microsystems, Inc. All Rights Reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Sun designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Sun in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 * have any questions. |
|
24 */ |
|
25 |
|
26 package sun.awt.motif; |
|
27 |
|
28 import java.awt.*; |
|
29 import java.awt.peer.*; |
|
30 import java.awt.event.PaintEvent; |
|
31 import java.awt.event.MouseEvent; |
|
32 import java.awt.event.InputEvent; |
|
33 |
|
34 import sun.awt.*; |
|
35 import sun.awt.image.ToolkitImage; |
|
36 import sun.awt.image.SunVolatileImage; |
|
37 import java.awt.image.ImageProducer; |
|
38 import java.awt.image.ImageObserver; |
|
39 import java.awt.image.ColorModel; |
|
40 import java.awt.image.VolatileImage; |
|
41 |
|
42 import java.awt.dnd.DropTarget; |
|
43 import java.awt.dnd.peer.DropTargetPeer; |
|
44 |
|
45 import sun.java2d.SunGraphics2D; |
|
46 import sun.java2d.SurfaceData; |
|
47 |
|
48 import java.lang.reflect.Method; |
|
49 |
|
50 import java.util.logging.*; |
|
51 |
|
52 import sun.java2d.pipe.Region; |
|
53 |
|
54 |
|
55 public /* REMIND: should not be public */ |
|
56 abstract class MComponentPeer implements ComponentPeer, DropTargetPeer, X11ComponentPeer { |
|
57 |
|
58 private static final Logger log = Logger.getLogger("sun.awt.motif.MComponentPeer"); |
|
59 private static final Logger focusLog = Logger.getLogger("sun.awt.motif.focus.MComponentPeer"); |
|
60 |
|
61 Component target; |
|
62 long pData; |
|
63 long jniGlobalRef; |
|
64 protected X11GraphicsConfig graphicsConfig; |
|
65 SurfaceData surfaceData; |
|
66 int oldWidth = -1; |
|
67 int oldHeight = -1; |
|
68 |
|
69 private RepaintArea paintArea; |
|
70 |
|
71 boolean isLayouting = false; |
|
72 boolean paintPending = false; |
|
73 |
|
74 protected boolean disposed = false; |
|
75 private static int JAWT_LOCK_ERROR=0x00000001; |
|
76 private static int JAWT_LOCK_CLIP_CHANGED=0x00000002; |
|
77 private static int JAWT_LOCK_BOUNDS_CHANGED=0x00000004; |
|
78 private static int JAWT_LOCK_SURFACE_CHANGED=0x00000008; |
|
79 private int drawState = JAWT_LOCK_CLIP_CHANGED | |
|
80 JAWT_LOCK_BOUNDS_CHANGED | |
|
81 JAWT_LOCK_SURFACE_CHANGED; |
|
82 |
|
83 /* These are the enumerated types in awt_p.h*/ |
|
84 static final int MOTIF_NA = 0 ; |
|
85 static final int MOTIF_V1 = 1 ; |
|
86 static final int MOTIF_V2 = 2 ; |
|
87 |
|
88 private Font font; |
|
89 private long backBuffer = 0; |
|
90 private VolatileImage xBackBuffer = null; |
|
91 |
|
92 static { |
|
93 initIDs(); |
|
94 } |
|
95 |
|
96 /* initialize the fieldIDs of fields that may be accessed from C */ |
|
97 private native static void initIDs(); |
|
98 |
|
99 |
|
100 /* This will return the last state of a window. ie the specific |
|
101 * "gotcha" is that if you iconify a window its obscurity remains |
|
102 * unchanged. Current use of this is just in user-initiated scrolling. |
|
103 * If that use expands to more cases you may need to "and" this with |
|
104 * the value of the iconic state of a Frame. |
|
105 * Note that de-iconifying an X11 window DOES generate a new event |
|
106 * correctly notifying you of the new visibility of the window |
|
107 */ |
|
108 public boolean isObscured() { |
|
109 |
|
110 Container container = (target instanceof Container) ? |
|
111 (Container)target : target.getParent(); |
|
112 |
|
113 if (container == null) { |
|
114 return true; |
|
115 } |
|
116 |
|
117 Container parent; |
|
118 while ((parent = container.getParent()) != null) { |
|
119 container = parent; |
|
120 } |
|
121 |
|
122 if (container instanceof Window) { |
|
123 MWindowPeer wpeer = (MWindowPeer)(container.getPeer()); |
|
124 if (wpeer != null) { |
|
125 return (wpeer.winAttr.visibilityState != |
|
126 MWindowAttributes.AWT_UNOBSCURED); |
|
127 } |
|
128 } |
|
129 return true; |
|
130 } |
|
131 |
|
132 public boolean canDetermineObscurity() { |
|
133 return true; |
|
134 } |
|
135 |
|
136 abstract void create(MComponentPeer parent); |
|
137 void create(MComponentPeer parent, Object arg) { |
|
138 create(parent); |
|
139 } |
|
140 |
|
141 void EFcreate(MComponentPeer parent, int x){} |
|
142 |
|
143 native void pInitialize(); |
|
144 native void pShow(); |
|
145 native void pHide(); |
|
146 native void pEnable(); |
|
147 native void pDisable(); |
|
148 native void pReshape(int x, int y, int width, int height); |
|
149 native void pDispose(); |
|
150 native void pMakeCursorVisible(); |
|
151 native Point pGetLocationOnScreen(); |
|
152 native Point pGetLocationOnScreen2(Window win, MWindowPeer wpeer); |
|
153 native void pSetForeground(Color c); |
|
154 native void pSetBackground(Color c); |
|
155 private native void pSetFont(Font f); |
|
156 |
|
157 //Added for bug 4175560 |
|
158 //Returns the native representation for the Color argument, |
|
159 //using the given GraphicsConfiguration. |
|
160 native int getNativeColor(Color clr, GraphicsConfiguration gc); |
|
161 |
|
162 // Returns the parent of the component, without invoking client |
|
163 // code. This must go through native code, because it invokes |
|
164 // private methods in the java.awt package, which we cannot |
|
165 // do from this package. |
|
166 static native Container getParent_NoClientCode(Component component); |
|
167 |
|
168 // Returns the parent of the component, without invoking client |
|
169 // code. This must go through native code, because it invokes |
|
170 // private methods in the java.awt package, which we cannot |
|
171 // do from this package. |
|
172 static native Component[] getComponents_NoClientCode(Container container); |
|
173 |
|
174 void initialize() { |
|
175 if (!target.isVisible()) { |
|
176 hide(); |
|
177 } |
|
178 Color c; |
|
179 Font f; |
|
180 Cursor cursor; |
|
181 |
|
182 pInitialize(); |
|
183 |
|
184 if ((c = target.getForeground()) != null) { |
|
185 setForeground(c); |
|
186 } |
|
187 if ((c = target.getBackground()) != null) { |
|
188 setBackground(c); |
|
189 } |
|
190 if ((f = target.getFont()) != null) { |
|
191 setFont(f); |
|
192 } |
|
193 pSetCursor(target.getCursor()); |
|
194 if (!target.isEnabled()) { |
|
195 disable(); |
|
196 } |
|
197 Rectangle r = target.getBounds(); |
|
198 reshape(r.x, r.y, r.width, r.height); |
|
199 if (target.isVisible()) { |
|
200 show(); |
|
201 } |
|
202 |
|
203 surfaceData = graphicsConfig.createSurfaceData(this); |
|
204 } |
|
205 |
|
206 public void init(Component target, Object arg) { |
|
207 this.target = target; |
|
208 this.paintArea = new RepaintArea(); |
|
209 |
|
210 Container parent = MToolkit.getNativeContainer(target); |
|
211 MComponentPeer parentPeer = (MComponentPeer) MToolkit.targetToPeer(parent); |
|
212 create(parentPeer, arg); |
|
213 |
|
214 initialize(); |
|
215 } |
|
216 |
|
217 MComponentPeer(Component target, Object arg) { |
|
218 init(target, arg); |
|
219 } |
|
220 |
|
221 MComponentPeer() {} |
|
222 |
|
223 public void init(Component target) { |
|
224 this.target = target; |
|
225 this.paintArea = new RepaintArea(); |
|
226 |
|
227 Container parent = MToolkit.getNativeContainer(target); |
|
228 MComponentPeer parentPeer = (MComponentPeer) MToolkit.targetToPeer(parent); |
|
229 create(parentPeer); |
|
230 |
|
231 if (parent != null && parent instanceof ScrollPane) { |
|
232 MScrollPanePeer speer = (MScrollPanePeer) parentPeer; |
|
233 speer.setScrollChild(this); |
|
234 } |
|
235 initialize(); |
|
236 } |
|
237 |
|
238 MComponentPeer(Component target) { |
|
239 init(target); |
|
240 } |
|
241 |
|
242 protected void finalize() throws Throwable { |
|
243 dispose(); |
|
244 super.finalize(); |
|
245 } |
|
246 |
|
247 public void setForeground(Color c) { |
|
248 pSetForeground(c); |
|
249 } |
|
250 |
|
251 public void setBackground(Color c) { |
|
252 pSetBackground(c); |
|
253 } |
|
254 |
|
255 public void updateCursorImmediately() { |
|
256 MGlobalCursorManager.getCursorManager().updateCursorImmediately(); |
|
257 } |
|
258 |
|
259 public void setFont(Font f) { |
|
260 ComponentPeer peer; |
|
261 if (f == null) { |
|
262 f = defaultFont; |
|
263 } |
|
264 pSetFont(f); |
|
265 if ( target instanceof Container ) { |
|
266 Container container = (Container) target; |
|
267 int count = container.getComponentCount(); |
|
268 Component[] children = container.getComponents(); |
|
269 for (int i=0; i<count; i++) { |
|
270 if ( children[i] != null ) { |
|
271 /* |
|
272 ** note: recursion in the widget in pSetFont() has by now broken any |
|
273 ** children with different Fonts - so fix now: |
|
274 */ |
|
275 peer = children[i].getPeer(); |
|
276 if (peer != null) { |
|
277 Font rightFont = children[i].getFont(); |
|
278 if (!f.equals(rightFont)) { |
|
279 peer.setFont(rightFont); |
|
280 } else |
|
281 if (children[i] instanceof Container) { |
|
282 peer.setFont(f); |
|
283 } |
|
284 } |
|
285 } |
|
286 } |
|
287 } |
|
288 |
|
289 /* |
|
290 * Keep a reference to the java.awt.Font object in order to |
|
291 * preserve the XFontStructs which underlying widgets are using. |
|
292 * Save this AFTER changing the widgets in order to keep the |
|
293 * previous reference (if any) alive. |
|
294 */ |
|
295 font = f; |
|
296 } |
|
297 |
|
298 |
|
299 public native void setTargetBackground(Color c); |
|
300 public native void pSetCursor(Cursor c); |
|
301 public native void pSetScrollbarBackground(Color c); |
|
302 public native void pSetInnerForeground(Color c); |
|
303 |
|
304 public boolean isFocusable() { |
|
305 return false; |
|
306 } |
|
307 |
|
308 public SurfaceData getSurfaceData() { |
|
309 return surfaceData; |
|
310 } |
|
311 |
|
312 public ColorModel getColorModel() { |
|
313 return graphicsConfig.getColorModel(); |
|
314 } |
|
315 |
|
316 public ColorModel getColorModel(int transparency) { |
|
317 return graphicsConfig.getColorModel(transparency); |
|
318 } |
|
319 |
|
320 public int updatePriority() { |
|
321 return Thread.NORM_PRIORITY; |
|
322 } |
|
323 |
|
324 public void repaint(long tm, int x, int y, int width, int height) { |
|
325 } |
|
326 |
|
327 public void paint(Graphics g) { |
|
328 Dimension d = target.getSize(); |
|
329 if (g instanceof Graphics2D || |
|
330 g instanceof sun.awt.Graphics2Delegate) { |
|
331 // background color is setup correctly, so just use clearRect |
|
332 g.clearRect(0, 0, d.width, d.height); |
|
333 } else { |
|
334 // emulate clearRect |
|
335 g.setColor(target.getBackground()); |
|
336 g.fillRect(0, 0, d.width, d.height); |
|
337 g.setColor(target.getForeground()); |
|
338 } |
|
339 |
|
340 target.paint(g); |
|
341 } |
|
342 public void print(Graphics g) { |
|
343 Dimension d = target.getSize(); |
|
344 if (g instanceof Graphics2D || |
|
345 g instanceof sun.awt.Graphics2Delegate) { |
|
346 // background color is setup correctly, so just use clearRect |
|
347 g.clearRect(0, 0, d.width, d.height); |
|
348 } else { |
|
349 // emulate clearRect |
|
350 g.setColor(target.getBackground()); |
|
351 g.fillRect(0, 0, d.width, d.height); |
|
352 g.setColor(target.getForeground()); |
|
353 } |
|
354 |
|
355 target.print(g); |
|
356 } |
|
357 |
|
358 public void coalescePaintEvent(PaintEvent e) { |
|
359 Rectangle r = e.getUpdateRect(); |
|
360 paintArea.add(r, e.getID()); |
|
361 |
|
362 if (log.isLoggable(Level.FINEST)) { |
|
363 switch(e.getID()) { |
|
364 case PaintEvent.UPDATE: |
|
365 log.log(Level.FINEST, "coalescePaintEvent: UPDATE: add: x = " + |
|
366 r.x + ", y = " + r.y + ", width = " + r.width + ", height = " + r.height); |
|
367 return; |
|
368 case PaintEvent.PAINT: |
|
369 log.log(Level.FINEST, "coalescePaintEvent: PAINT: add: x = " + |
|
370 r.x + ", y = " + r.y + ", width = " + r.width + ", height = " + r.height); |
|
371 return; |
|
372 } |
|
373 } |
|
374 } |
|
375 |
|
376 native void nativeHandleEvent(AWTEvent e); |
|
377 |
|
378 /** |
|
379 * Returns whether or not this component should be given focus on mouse click. |
|
380 * Default implementation return whether or not this peer is "focusable" |
|
381 * Descendants might want to override it to extend/restrict conditions at which this |
|
382 * component should be focused by click (see MCanvasPeer and MPanelPeer) |
|
383 */ |
|
384 protected boolean shouldFocusOnClick() { |
|
385 return isFocusable(); |
|
386 } |
|
387 |
|
388 /** |
|
389 * Checks whether or not this component would be focused by native system if it would be allowed to do so. |
|
390 * Currently it checks that it displayable, visible, enabled and focusable. |
|
391 */ |
|
392 static boolean canBeFocusedByClick(Component component) { |
|
393 if (component == null) { |
|
394 return false; |
|
395 } else { |
|
396 return component.isDisplayable() && component.isVisible() && component.isEnabled() && component.isFocusable(); |
|
397 } |
|
398 } |
|
399 |
|
400 static Method requestFocusWithCause; |
|
401 |
|
402 static void callRequestFocusInWindow(Component target, CausedFocusEvent.Cause cause) { |
|
403 if (requestFocusWithCause == null) { |
|
404 requestFocusWithCause = SunToolkit.getMethod(Component.class, "requestFocusInWindow", new Class[] {CausedFocusEvent.Cause.class}); |
|
405 } |
|
406 if (requestFocusWithCause != null) { |
|
407 try { |
|
408 requestFocusWithCause.invoke(target, new Object[] {cause}); |
|
409 } catch (Exception e) { |
|
410 e.printStackTrace(); |
|
411 } |
|
412 } |
|
413 } |
|
414 |
|
415 public void handleEvent(AWTEvent e) { |
|
416 int id = e.getID(); |
|
417 |
|
418 switch(id) { |
|
419 case PaintEvent.PAINT: |
|
420 // Got native painting |
|
421 paintPending = false; |
|
422 // Fallthrough to next statement |
|
423 case PaintEvent.UPDATE: |
|
424 // Skip all painting while layouting and all UPDATEs |
|
425 // while waiting for native paint |
|
426 if (!isLayouting && !paintPending) { |
|
427 paintArea.paint(target,false); |
|
428 } |
|
429 return; |
|
430 case MouseEvent.MOUSE_PRESSED: |
|
431 if (target == e.getSource() && !((InputEvent)e).isConsumed() && shouldFocusOnClick() |
|
432 && !target.isFocusOwner() && canBeFocusedByClick(target)) |
|
433 { |
|
434 callRequestFocusInWindow(target, CausedFocusEvent.Cause.MOUSE_EVENT); |
|
435 } |
|
436 break; |
|
437 default: |
|
438 break; |
|
439 } |
|
440 |
|
441 // Call the native code |
|
442 nativeHandleEvent(e); |
|
443 } |
|
444 |
|
445 /* New API for 1.1 */ |
|
446 public Dimension getMinimumSize() { |
|
447 return target.getSize(); |
|
448 } |
|
449 |
|
450 /* New API for 1.1 */ |
|
451 public Dimension getPreferredSize() { |
|
452 return getMinimumSize(); |
|
453 } |
|
454 |
|
455 // Do nothing for heavyweight implementation |
|
456 public void layout() {} |
|
457 |
|
458 public Rectangle getBounds() { |
|
459 return ((Component)target).getBounds(); |
|
460 } |
|
461 |
|
462 public Object getTarget() { |
|
463 return target; |
|
464 } |
|
465 |
|
466 public java.awt.Toolkit getToolkit() { |
|
467 // XXX: bogus |
|
468 return Toolkit.getDefaultToolkit(); |
|
469 } |
|
470 |
|
471 // fallback default font object |
|
472 final static Font defaultFont = new Font(Font.DIALOG, Font.PLAIN, 12); |
|
473 |
|
474 public synchronized Graphics getGraphics() { |
|
475 if (!disposed) { |
|
476 Component target = (Component) this.target; |
|
477 |
|
478 /* Fix for bug 4746122. Color and Font shouldn't be null */ |
|
479 Color bgColor = target.getBackground(); |
|
480 if (bgColor == null) { |
|
481 bgColor = SystemColor.window; |
|
482 } |
|
483 Color fgColor = target.getForeground(); |
|
484 if (fgColor == null) { |
|
485 fgColor = SystemColor.windowText; |
|
486 } |
|
487 Font font = target.getFont(); |
|
488 if (font == null) { |
|
489 font = defaultFont; |
|
490 } |
|
491 return new SunGraphics2D(surfaceData, fgColor, bgColor, font); |
|
492 } |
|
493 |
|
494 return null; |
|
495 } |
|
496 |
|
497 public Image createImage(ImageProducer producer) { |
|
498 return new ToolkitImage(producer); |
|
499 } |
|
500 |
|
501 public Image createImage(int width, int height) { |
|
502 return graphicsConfig.createAcceleratedImage(target, width, height); |
|
503 } |
|
504 |
|
505 public VolatileImage createVolatileImage(int width, int height) { |
|
506 return new SunVolatileImage(target, width, height); |
|
507 } |
|
508 |
|
509 public boolean prepareImage(Image img, int w, int h, ImageObserver o) { |
|
510 return getToolkit().prepareImage(img, w, h, o); |
|
511 } |
|
512 |
|
513 public int checkImage(Image img, int w, int h, ImageObserver o) { |
|
514 return getToolkit().checkImage(img, w, h, o); |
|
515 } |
|
516 |
|
517 public FontMetrics getFontMetrics(Font font) { |
|
518 return X11FontMetrics.getFontMetrics(font); |
|
519 } |
|
520 |
|
521 /* |
|
522 * Subclasses should override disposeImpl() instead of dispose(). Client |
|
523 * code should always invoke dispose(), never disposeImpl(). |
|
524 */ |
|
525 protected void disposeImpl() { |
|
526 SurfaceData oldData = surfaceData; |
|
527 surfaceData = null; |
|
528 oldData.invalidate(); |
|
529 MToolkit.targetDisposedPeer(target, this); |
|
530 pDispose(); |
|
531 } |
|
532 public final void dispose() { |
|
533 boolean call_disposeImpl = false; |
|
534 |
|
535 if (!disposed) { |
|
536 synchronized (this) { |
|
537 SunToolkit.awtLock(); |
|
538 try { |
|
539 if (!disposed) { |
|
540 disposed = call_disposeImpl = true; |
|
541 } |
|
542 } finally { |
|
543 SunToolkit.awtUnlock(); |
|
544 } |
|
545 } |
|
546 } |
|
547 |
|
548 if (call_disposeImpl) { |
|
549 disposeImpl(); |
|
550 } |
|
551 } |
|
552 |
|
553 native static boolean processSynchronousLightweightTransfer(Component heavyweight, Component descendant, |
|
554 boolean temporary, boolean focusedWindowChangeAllowed, |
|
555 long time); |
|
556 public boolean requestFocus |
|
557 (Component lightweightChild, boolean temporary, |
|
558 boolean focusedWindowChangeAllowed, long time, CausedFocusEvent.Cause cause) { |
|
559 if (processSynchronousLightweightTransfer((Component)target, lightweightChild, temporary, |
|
560 focusedWindowChangeAllowed, time)) { |
|
561 return true; |
|
562 } else { |
|
563 if (focusLog.isLoggable(Level.FINER)) { |
|
564 focusLog.log(Level.FINER, "Current native focused window " + getNativeFocusedWindow()); |
|
565 } |
|
566 /** |
|
567 * The problems with requests in non-focused window arise because shouldNativelyFocusHeavyweight |
|
568 * checks that native window is focused while appropriate WINDOW_GAINED_FOCUS has not yet |
|
569 * been processed - it is in EventQueue. Thus, SNFH allows native request and stores request record |
|
570 * in requests list - and it breaks our requests sequence as first record on WGF should be the last focus |
|
571 * owner which had focus before WLF. So, we should not add request record for such requests |
|
572 * but store this component in mostRecent - and return true as before for compatibility. |
|
573 */ |
|
574 Container parent = (target instanceof Container) ? ((Container)target) : (target.getParent()); |
|
575 // Search for parent window |
|
576 while (parent != null && !(parent instanceof Window)) { |
|
577 parent = getParent_NoClientCode(parent); |
|
578 } |
|
579 if (parent != null) { |
|
580 Window parentWindow = (Window)parent; |
|
581 // and check that it is focused |
|
582 if (focusLog.isLoggable(Level.FINER)) { |
|
583 focusLog.log(Level.FINER, "Parent window " + parentWindow); |
|
584 } |
|
585 if (!parentWindow.isFocused() && getNativeFocusedWindow() == parentWindow) { |
|
586 // if it is not - skip requesting focus on Solaris |
|
587 // but return true for compatibility. |
|
588 return true; |
|
589 } else if (getNativeFocusedWindow() != parentWindow) { |
|
590 WindowPeer wpeer = (WindowPeer)parentWindow.getPeer(); |
|
591 boolean res = wpeer.requestWindowFocus(); |
|
592 if (focusLog.isLoggable(Level.FINER)) { |
|
593 focusLog.log(Level.FINER, "Requested window focus: " + res); |
|
594 } |
|
595 // If parent window can be made focused and has been made focused(synchronously) |
|
596 // then we can proceed with children, otherwise we retreat. |
|
597 if (!(res && parentWindow.isFocused())) { |
|
598 focusLog.finer("Waiting for asynchronous processing of window focus request"); |
|
599 KeyboardFocusManagerPeerImpl.removeLastFocusRequest(target); |
|
600 return false; |
|
601 } |
|
602 } |
|
603 } |
|
604 return _requestFocus(lightweightChild, temporary, focusedWindowChangeAllowed, time, cause); |
|
605 } |
|
606 } |
|
607 |
|
608 native boolean _requestFocus |
|
609 (Component lightweightChild, boolean temporary, |
|
610 boolean focusedWindowChangeAllowed, long time, CausedFocusEvent.Cause cause); |
|
611 |
|
612 static native Window getNativeFocusedWindow(); |
|
613 |
|
614 /* |
|
615 * Post an event to the event queue. |
|
616 */ |
|
617 // NOTE: This method may be called by privileged threads. |
|
618 // DO NOT INVOKE CLIENT CODE ON THIS THREAD! |
|
619 void postEvent(AWTEvent event) { |
|
620 MToolkit.postEvent(MToolkit.targetToAppContext(target), event); |
|
621 } |
|
622 |
|
623 /* Callbacks for window-system events to the frame |
|
624 * |
|
625 * NOTE: This method may be called by privileged threads. |
|
626 * DO NOT INVOKE CLIENT CODE ON THIS THREAD! |
|
627 */ |
|
628 void handleExpose(int x, int y, int w, int h) { |
|
629 if ( !ComponentAccessor.getIgnoreRepaint(target) ) { |
|
630 postEvent(new PaintEvent(target, PaintEvent.PAINT, |
|
631 new Rectangle(x, y, w, h))); |
|
632 } |
|
633 } |
|
634 |
|
635 /* Callbacks for window-system events to the frame |
|
636 * |
|
637 * NOTE: This method may be called by privileged threads. |
|
638 * DO NOT INVOKE CLIENT CODE ON THIS THREAD! |
|
639 */ |
|
640 void handleRepaint(int x, int y, int w, int h) { |
|
641 if ( !ComponentAccessor.getIgnoreRepaint(target) ) { |
|
642 postEvent(new PaintEvent(target, PaintEvent.UPDATE, |
|
643 new Rectangle(x, y, w, h))); |
|
644 } |
|
645 } |
|
646 |
|
647 /* Return the component's z-order position relative to |
|
648 * other peer'd siblings (don't count lightweight siblings |
|
649 * or siblings who don't yet have valid peers). |
|
650 * |
|
651 * NOTE: This method may be called by privileged threads. |
|
652 * DO NOT INVOKE CLIENT CODE ON THIS THREAD! |
|
653 */ |
|
654 public int getZOrderPosition_NoClientCode() { |
|
655 // SECURITY: use _NoClientCode() methods, because we may |
|
656 // be running on a privileged thread |
|
657 Container p = getParent_NoClientCode(target); |
|
658 if (p != null) { |
|
659 // SECURITY: use _NoClientCode() methods, because we may |
|
660 // be running on a privileged thread |
|
661 Component children[] = getComponents_NoClientCode(p); |
|
662 int i; |
|
663 int index = 0; |
|
664 for (i = 0; i < children.length; i++) { |
|
665 if (children[i] == target) { |
|
666 return index; |
|
667 } else { |
|
668 Object cpeer = MToolkit.targetToPeer(children[i]); |
|
669 if (cpeer != null && |
|
670 !(cpeer instanceof java.awt.peer.LightweightPeer)) { |
|
671 index++; |
|
672 } |
|
673 } |
|
674 } |
|
675 } |
|
676 return -1; |
|
677 } |
|
678 |
|
679 /* |
|
680 * drawXXX() methods are used to print the native components by |
|
681 * rendering the Motif look ourselves. |
|
682 * ToDo(aim): needs to query native motif for more accurate color |
|
683 * information. |
|
684 */ |
|
685 void draw3DOval(Graphics g, Color bg, |
|
686 int x, int y, int w, int h, boolean raised) { |
|
687 Color c = g.getColor(); |
|
688 Color shadow = bg.darker(); |
|
689 Color highlight = bg.brighter(); |
|
690 |
|
691 g.setColor(raised ? highlight : shadow); |
|
692 g.drawArc(x, y, w, h, 45, 180); |
|
693 g.setColor(raised ? shadow : highlight); |
|
694 g.drawArc(x, y, w, h, 225, 180); |
|
695 g.setColor(c); |
|
696 } |
|
697 void draw3DRect(Graphics g, Color bg, |
|
698 int x, int y, int width, int height, |
|
699 boolean raised) { |
|
700 Color c = g.getColor(); |
|
701 Color shadow = bg.darker(); |
|
702 Color highlight = bg.brighter(); |
|
703 |
|
704 g.setColor(raised ? highlight : shadow); |
|
705 g.drawLine(x, y, x, y + height); |
|
706 g.drawLine(x + 1, y, x + width - 1, y); |
|
707 g.setColor(raised ? shadow : highlight); |
|
708 g.drawLine(x + 1, y + height, x + width, y + height); |
|
709 g.drawLine(x + width, y, x + width, y + height - 1); |
|
710 g.setColor(c); |
|
711 } |
|
712 void drawScrollbar(Graphics g, Color bg, int thickness, int length, |
|
713 int min, int max, int val, int vis, boolean horizontal) { |
|
714 Color c = g.getColor(); |
|
715 double f = (double)(length - 2*(thickness-1)) / Math.max(1, ((max - min) + vis)); |
|
716 int v1 = thickness + (int)(f * (val - min)); |
|
717 int v2 = (int)(f * vis); |
|
718 int w2 = thickness-4; |
|
719 int tpts_x[] = new int[3]; |
|
720 int tpts_y[] = new int[3]; |
|
721 |
|
722 if (length < 3*w2 ) { |
|
723 v1 = v2 = 0; |
|
724 if (length < 2*w2 + 2) { |
|
725 w2 = (length-2)/2; |
|
726 } |
|
727 } else if (v2 < 7) { |
|
728 // enforce a minimum handle size |
|
729 v1 = Math.max(0, v1 - ((7 - v2)>>1)); |
|
730 v2 = 7; |
|
731 } |
|
732 |
|
733 int ctr = thickness/2; |
|
734 int sbmin = ctr - w2/2; |
|
735 int sbmax = ctr + w2/2; |
|
736 |
|
737 // paint the background slightly darker |
|
738 { |
|
739 Color d = new Color((int) (bg.getRed() * 0.85), |
|
740 (int) (bg.getGreen() * 0.85), |
|
741 (int) (bg.getBlue() * 0.85)); |
|
742 |
|
743 g.setColor(d); |
|
744 if (horizontal) { |
|
745 g.fillRect(0, 0, length, thickness); |
|
746 } else { |
|
747 g.fillRect(0, 0, thickness, length); |
|
748 } |
|
749 } |
|
750 |
|
751 // paint the thumb and arrows in the normal background color |
|
752 g.setColor(bg); |
|
753 if (v1 > 0) { |
|
754 if (horizontal) { |
|
755 g.fillRect(v1, 3, v2, thickness-3); |
|
756 } else { |
|
757 g.fillRect(3, v1, thickness-3, v2); |
|
758 } |
|
759 } |
|
760 |
|
761 tpts_x[0] = ctr; tpts_y[0] = 2; |
|
762 tpts_x[1] = sbmin; tpts_y[1] = w2; |
|
763 tpts_x[2] = sbmax; tpts_y[2] = w2; |
|
764 if (horizontal) { |
|
765 g.fillPolygon(tpts_y, tpts_x, 3); |
|
766 } else { |
|
767 g.fillPolygon(tpts_x, tpts_y, 3); |
|
768 } |
|
769 |
|
770 tpts_y[0] = length-2; |
|
771 tpts_y[1] = length-w2; |
|
772 tpts_y[2] = length-w2; |
|
773 if (horizontal) { |
|
774 g.fillPolygon(tpts_y, tpts_x, 3); |
|
775 } else { |
|
776 g.fillPolygon(tpts_x, tpts_y, 3); |
|
777 } |
|
778 |
|
779 Color highlight = bg.brighter(); |
|
780 |
|
781 // // // // draw the "highlighted" edges |
|
782 g.setColor(highlight); |
|
783 |
|
784 // outline & arrows |
|
785 if (horizontal) { |
|
786 g.drawLine(1, thickness, length - 1, thickness); |
|
787 g.drawLine(length - 1, 1, length - 1, thickness); |
|
788 |
|
789 // arrows |
|
790 g.drawLine(1, ctr, w2, sbmin); |
|
791 g.drawLine(length - w2, sbmin, length - w2, sbmax); |
|
792 g.drawLine(length - w2, sbmin, length - 2, ctr); |
|
793 |
|
794 } else { |
|
795 g.drawLine(thickness, 1, thickness, length - 1); |
|
796 g.drawLine(1, length - 1, thickness, length - 1); |
|
797 |
|
798 // arrows |
|
799 g.drawLine(ctr, 1, sbmin, w2); |
|
800 g.drawLine(sbmin, length - w2, sbmax, length - w2); |
|
801 g.drawLine(sbmin, length - w2, ctr, length - 2); |
|
802 } |
|
803 |
|
804 // thumb |
|
805 if (v1 > 0) { |
|
806 if (horizontal) { |
|
807 g.drawLine(v1, 2, v1 + v2, 2); |
|
808 g.drawLine(v1, 2, v1, thickness-3); |
|
809 } else { |
|
810 g.drawLine(2, v1, 2, v1 + v2); |
|
811 g.drawLine(2, v1, thickness-3, v1); |
|
812 } |
|
813 } |
|
814 |
|
815 Color shadow = bg.darker(); |
|
816 |
|
817 // // // // draw the "shadowed" edges |
|
818 g.setColor(shadow); |
|
819 |
|
820 // outline && arrows |
|
821 if (horizontal) { |
|
822 g.drawLine(0, 0, 0, thickness); |
|
823 g.drawLine(0, 0, length - 1, 0); |
|
824 |
|
825 // arrows |
|
826 g.drawLine(w2, sbmin, w2, sbmax); |
|
827 g.drawLine(w2, sbmax, 1, ctr); |
|
828 g.drawLine(length-2, ctr, length-w2, sbmax); |
|
829 |
|
830 } else { |
|
831 g.drawLine(0, 0, thickness, 0); |
|
832 g.drawLine(0, 0, 0, length - 1); |
|
833 |
|
834 // arrows |
|
835 g.drawLine(sbmin, w2, sbmax, w2); |
|
836 g.drawLine(sbmax, w2, ctr, 1); |
|
837 g.drawLine(ctr, length-2, sbmax, length-w2); |
|
838 } |
|
839 |
|
840 // thumb |
|
841 if (v1 > 0) { |
|
842 if (horizontal) { |
|
843 g.drawLine(v1 + v2, 2, v1 + v2, thickness-2); |
|
844 g.drawLine(v1, thickness-2, v1 + v2, thickness-2); |
|
845 } else { |
|
846 g.drawLine(2, v1 + v2, thickness-2, v1 + v2); |
|
847 g.drawLine(thickness-2, v1, thickness-2, v1 + v2); |
|
848 } |
|
849 } |
|
850 g.setColor(c); |
|
851 } |
|
852 |
|
853 public String toString() { |
|
854 return getClass().getName() + "[" + target + "]"; |
|
855 } |
|
856 |
|
857 /* New 1.1 API */ |
|
858 public void setVisible(boolean b) { |
|
859 if (b) { |
|
860 Dimension s = target.getSize(); |
|
861 oldWidth = s.width; |
|
862 oldHeight = s.height; |
|
863 pShow(); |
|
864 } else { |
|
865 pHide(); |
|
866 } |
|
867 } |
|
868 |
|
869 /* New 1.1 API */ |
|
870 public void setEnabled(boolean b) { |
|
871 if (b) { |
|
872 pEnable(); |
|
873 } else { |
|
874 pDisable(); |
|
875 } |
|
876 } |
|
877 |
|
878 /* New 1.1 API */ |
|
879 public Point getLocationOnScreen() { |
|
880 synchronized (target.getTreeLock()) { |
|
881 Component comp = target; |
|
882 while (comp != null && !(comp instanceof Window)) { |
|
883 comp = getParent_NoClientCode(comp); |
|
884 } |
|
885 |
|
886 // applets, embedded, etc - translate directly |
|
887 if (comp == null || comp instanceof sun.awt.EmbeddedFrame) { |
|
888 return pGetLocationOnScreen(); |
|
889 } |
|
890 |
|
891 MWindowPeer wpeer = (MWindowPeer)(MToolkit.targetToPeer(comp)); |
|
892 if (wpeer == null) { |
|
893 return pGetLocationOnScreen(); |
|
894 } |
|
895 return pGetLocationOnScreen2((Window)comp, wpeer); |
|
896 } |
|
897 } |
|
898 |
|
899 public int serialNum = 0; |
|
900 |
|
901 /* Returns the native paint should be posted after setting new size |
|
902 */ |
|
903 public boolean checkNativePaintOnSetBounds(int width, int height) { |
|
904 return (width != oldWidth) || (height != oldHeight); |
|
905 } |
|
906 |
|
907 void setBounds(int x, int y, int width, int height) { |
|
908 setBounds(x, y, width, height, SET_BOUNDS); |
|
909 } |
|
910 |
|
911 /* New 1.1 API */ |
|
912 public void setBounds(int x, int y, int width, int height, int op) { |
|
913 if (disposed) return; |
|
914 |
|
915 Container parent = getParent_NoClientCode(target); |
|
916 |
|
917 // Should set paintPending before reshape to prevent |
|
918 // thread race between PaintEvent and setBounds |
|
919 // This part of the 4267393 fix proved to be unstable under solaris, |
|
920 // dissabled due to regressions 4418155, 4486762, 4490079 |
|
921 paintPending = false; //checkNativePaintOnSetBounds(width, height); |
|
922 |
|
923 // Note: it would be ideal to NOT execute this if it's |
|
924 // merely a Move which is occurring. |
|
925 if (parent != null && parent instanceof ScrollPane) { |
|
926 MScrollPanePeer speer = (MScrollPanePeer)parent.getPeer(); |
|
927 if (!speer.ignore) { |
|
928 pReshape(x, y, width, height); |
|
929 speer.childResized(width, height); |
|
930 } |
|
931 } else { |
|
932 pReshape(x, y, width, height); |
|
933 } |
|
934 |
|
935 if ((width != oldWidth) || (height != oldHeight)) { |
|
936 SurfaceData oldData = surfaceData; |
|
937 if (oldData != null) { |
|
938 surfaceData = graphicsConfig.createSurfaceData(this); |
|
939 oldData.invalidate(); |
|
940 } |
|
941 oldWidth = width; |
|
942 oldHeight = height; |
|
943 } |
|
944 validateSurface(width, height); |
|
945 serialNum++; |
|
946 } |
|
947 |
|
948 void validateSurface(int width, int height) { |
|
949 SunToolkit.awtLock(); |
|
950 try { |
|
951 if (!disposed && (width != oldWidth || height != oldHeight)) { |
|
952 SurfaceData oldData = surfaceData; |
|
953 if (oldData != null) { |
|
954 surfaceData = graphicsConfig.createSurfaceData(this); |
|
955 oldData.invalidate(); |
|
956 } |
|
957 oldWidth = width; |
|
958 oldHeight = height; |
|
959 } |
|
960 } finally { |
|
961 SunToolkit.awtUnlock(); |
|
962 } |
|
963 } |
|
964 |
|
965 public void beginValidate() { |
|
966 } |
|
967 |
|
968 native void restoreFocus(); |
|
969 |
|
970 public void endValidate() { |
|
971 restoreFocus(); |
|
972 } |
|
973 |
|
974 public void beginLayout() { |
|
975 // Skip all painting till endLayout |
|
976 isLayouting = true; |
|
977 } |
|
978 |
|
979 public void endLayout() { |
|
980 if (!paintPending && !paintArea.isEmpty() && |
|
981 !((Component)target).getIgnoreRepaint()) { |
|
982 // if not waiting for native painting repaint damaged area |
|
983 postEvent(new PaintEvent((Component)target, PaintEvent.PAINT, |
|
984 new Rectangle())); |
|
985 } |
|
986 isLayouting = false; |
|
987 } |
|
988 |
|
989 /** |
|
990 * DEPRECATED: Replaced by setVisible(boolean). |
|
991 */ |
|
992 public void show() { |
|
993 setVisible(true); |
|
994 } |
|
995 |
|
996 /** |
|
997 * DEPRECATED: Replaced by setVisible(boolean). |
|
998 */ |
|
999 public void hide() { |
|
1000 setVisible(false); |
|
1001 } |
|
1002 |
|
1003 /** |
|
1004 * DEPRECATED: Replaced by setEnabled(boolean). |
|
1005 */ |
|
1006 public void enable() { |
|
1007 setEnabled(true); |
|
1008 } |
|
1009 |
|
1010 /** |
|
1011 * DEPRECATED: Replaced by setEnabled(boolean). |
|
1012 */ |
|
1013 public void disable() { |
|
1014 setEnabled(false); |
|
1015 } |
|
1016 |
|
1017 /** |
|
1018 * DEPRECATED: Replaced by setBounds(int, int, int, int). |
|
1019 */ |
|
1020 public void reshape(int x, int y, int width, int height) { |
|
1021 setBounds(x, y, width, height); |
|
1022 } |
|
1023 |
|
1024 /** |
|
1025 * DEPRECATED: Replaced by getMinimumSize(). |
|
1026 */ |
|
1027 public Dimension minimumSize() { |
|
1028 return getMinimumSize(); |
|
1029 } |
|
1030 |
|
1031 /** |
|
1032 * DEPRECATED: Replaced by getPreferredSize(). |
|
1033 */ |
|
1034 public Dimension preferredSize() { |
|
1035 return getPreferredSize(); |
|
1036 } |
|
1037 |
|
1038 /** |
|
1039 * |
|
1040 */ |
|
1041 |
|
1042 public void addDropTarget(DropTarget dt) { |
|
1043 if (MToolkit.useMotifDnD()) { |
|
1044 addNativeDropTarget(dt); |
|
1045 } else { |
|
1046 Component comp = target; |
|
1047 while(!(comp == null || comp instanceof java.awt.Window)) { |
|
1048 comp = getParent_NoClientCode(comp); |
|
1049 } |
|
1050 |
|
1051 if (comp instanceof Window) { |
|
1052 MWindowPeer wpeer = (MWindowPeer)(comp.getPeer()); |
|
1053 if (wpeer != null) { |
|
1054 wpeer.addDropTarget(); |
|
1055 } |
|
1056 } |
|
1057 } |
|
1058 } |
|
1059 |
|
1060 /** |
|
1061 * |
|
1062 */ |
|
1063 |
|
1064 public void removeDropTarget(DropTarget dt) { |
|
1065 if (MToolkit.useMotifDnD()) { |
|
1066 removeNativeDropTarget(dt); |
|
1067 } else { |
|
1068 Component comp = target; |
|
1069 while(!(comp == null || comp instanceof java.awt.Window)) { |
|
1070 comp = getParent_NoClientCode(comp); |
|
1071 } |
|
1072 |
|
1073 if (comp instanceof Window) { |
|
1074 MWindowPeer wpeer = (MWindowPeer)(comp.getPeer()); |
|
1075 if (wpeer != null) { |
|
1076 wpeer.removeDropTarget(); |
|
1077 } |
|
1078 } |
|
1079 } |
|
1080 } |
|
1081 |
|
1082 public void notifyTextComponentChange(boolean add){ |
|
1083 Container parent = getParent_NoClientCode(target); |
|
1084 while(!(parent == null || |
|
1085 parent instanceof java.awt.Frame || |
|
1086 parent instanceof java.awt.Dialog)) { |
|
1087 parent = getParent_NoClientCode(parent); |
|
1088 } |
|
1089 |
|
1090 if (parent instanceof java.awt.Frame || |
|
1091 parent instanceof java.awt.Dialog) { |
|
1092 if (add) |
|
1093 ((MInputMethodControl)parent.getPeer()).addTextComponent((MComponentPeer)this); |
|
1094 else |
|
1095 ((MInputMethodControl)parent.getPeer()).removeTextComponent((MComponentPeer)this); |
|
1096 } |
|
1097 } |
|
1098 |
|
1099 native void addNativeDropTarget(DropTarget dt); |
|
1100 |
|
1101 native void removeNativeDropTarget(DropTarget dt); |
|
1102 |
|
1103 public GraphicsConfiguration getGraphicsConfiguration() { |
|
1104 GraphicsConfiguration ret = graphicsConfig; |
|
1105 if (ret == null) { |
|
1106 ret = target.getGraphicsConfiguration(); |
|
1107 } |
|
1108 return ret; |
|
1109 } |
|
1110 |
|
1111 // Returns true if we are inside begin/endLayout and |
|
1112 // are waiting for native painting |
|
1113 public boolean isPaintPending() { |
|
1114 return paintPending && isLayouting; |
|
1115 } |
|
1116 |
|
1117 public boolean handlesWheelScrolling() { |
|
1118 return false; |
|
1119 } |
|
1120 |
|
1121 /** |
|
1122 * The following multibuffering-related methods delegate to our |
|
1123 * associated GraphicsConfig (X11 or GLX) to handle the appropriate |
|
1124 * native windowing system specific actions. |
|
1125 */ |
|
1126 |
|
1127 private native long getWindow(long pData); |
|
1128 |
|
1129 public long getContentWindow() { |
|
1130 return getWindow(pData); |
|
1131 } |
|
1132 |
|
1133 public void createBuffers(int numBuffers, BufferCapabilities caps) |
|
1134 throws AWTException |
|
1135 { |
|
1136 backBuffer = graphicsConfig.createBackBuffer(this, numBuffers, caps); |
|
1137 xBackBuffer = graphicsConfig.createBackBufferImage(target, |
|
1138 backBuffer); |
|
1139 } |
|
1140 |
|
1141 public void flip(int x1, int y1, int x2, int y2, |
|
1142 BufferCapabilities.FlipContents flipAction) |
|
1143 { |
|
1144 if (backBuffer == 0) { |
|
1145 throw new IllegalStateException("Buffers have not been created"); |
|
1146 } |
|
1147 graphicsConfig.flip(this, target, xBackBuffer, |
|
1148 x1, y1, x2, y2, flipAction); |
|
1149 } |
|
1150 |
|
1151 public Image getBackBuffer() { |
|
1152 if (backBuffer == 0) { |
|
1153 throw new IllegalStateException("Buffers have not been created"); |
|
1154 } |
|
1155 return xBackBuffer; |
|
1156 } |
|
1157 |
|
1158 public void destroyBuffers() { |
|
1159 graphicsConfig.destroyBackBuffer(backBuffer); |
|
1160 backBuffer = 0; |
|
1161 xBackBuffer = null; |
|
1162 } |
|
1163 |
|
1164 /** |
|
1165 * @see java.awt.peer.ComponentPeer#isReparentSupported |
|
1166 */ |
|
1167 public boolean isReparentSupported() { |
|
1168 return false; |
|
1169 } |
|
1170 |
|
1171 /** |
|
1172 * @see java.awt.peer.ComponentPeer#reparent |
|
1173 */ |
|
1174 public void reparent(ContainerPeer newNativeParent) { |
|
1175 throw new UnsupportedOperationException(); |
|
1176 } |
|
1177 |
|
1178 /** |
|
1179 * Applies the shape to the native component window. |
|
1180 * @since 1.7 |
|
1181 */ |
|
1182 public void applyShape(Region shape) { |
|
1183 } |
|
1184 |
|
1185 } |
|