1 /* |
|
2 * Copyright 1995-2005 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 package sun.awt.motif; |
|
26 |
|
27 import java.awt.*; |
|
28 import java.awt.peer.*; |
|
29 import sun.awt.DisplayChangedListener; |
|
30 import sun.awt.X11GraphicsConfig; |
|
31 import sun.awt.X11GraphicsDevice; |
|
32 import sun.awt.X11GraphicsEnvironment; |
|
33 |
|
34 class MCanvasPeer extends MComponentPeer implements CanvasPeer, |
|
35 DisplayChangedListener { |
|
36 |
|
37 native void create(MComponentPeer parent); |
|
38 private static native void initIDs(); |
|
39 static { |
|
40 initIDs(); |
|
41 } |
|
42 |
|
43 MCanvasPeer() {} |
|
44 |
|
45 MCanvasPeer(Component target) { |
|
46 super(target); |
|
47 } |
|
48 |
|
49 MCanvasPeer(Component target, Object arg) { |
|
50 super(target, arg); |
|
51 } |
|
52 |
|
53 /* --- DisplayChangedListener Stuff --- */ |
|
54 public void displayChanged() {} |
|
55 public void paletteChanged() {} |
|
56 native void resetTargetGC(Component target); |
|
57 |
|
58 /* |
|
59 * Called when the Window this |
|
60 * Canvas is on is moved onto another Xinerama screen. |
|
61 * |
|
62 * Canvases can be created with a non-defulat GraphicsConfiguration. The |
|
63 * GraphicsConfiguration needs to be changed to one on the new screen, |
|
64 * preferably with the same visual ID. |
|
65 * |
|
66 * Up-called for other windows peer instances (WPanelPeer, WWindowPeer). |
|
67 * |
|
68 * Should only be called from the event thread. |
|
69 */ |
|
70 public void displayChanged(int screenNum) { |
|
71 resetLocalGC(screenNum); |
|
72 resetTargetGC(target); /* call Canvas.setGCFromPeer() via native */ |
|
73 } |
|
74 |
|
75 /* Set graphicsConfig to a GraphicsConfig with the same visual on the new |
|
76 * screen, which should be easy in Xinerama mode. |
|
77 * |
|
78 * Should only be called from displayChanged(), and therefore only from |
|
79 * the event thread. |
|
80 */ |
|
81 void resetLocalGC(int screenNum) { |
|
82 // Opt: Only need to do if we're not using the default GC |
|
83 if (graphicsConfig != null) { |
|
84 X11GraphicsConfig parentgc; |
|
85 // save vis id of current gc |
|
86 int visual = graphicsConfig.getVisual(); |
|
87 |
|
88 X11GraphicsDevice newDev = (X11GraphicsDevice) GraphicsEnvironment. |
|
89 getLocalGraphicsEnvironment(). |
|
90 getScreenDevices()[screenNum]; |
|
91 |
|
92 for (int i = 0; i < newDev.getNumConfigs(screenNum); i++) { |
|
93 if (visual == newDev.getConfigVisualId(i, screenNum)) { |
|
94 // use that |
|
95 graphicsConfig = (X11GraphicsConfig)newDev.getConfigurations()[i]; |
|
96 break; |
|
97 } |
|
98 } |
|
99 // just in case... |
|
100 if (graphicsConfig == null) { |
|
101 graphicsConfig = (X11GraphicsConfig) GraphicsEnvironment. |
|
102 getLocalGraphicsEnvironment(). |
|
103 getScreenDevices()[screenNum]. |
|
104 getDefaultConfiguration(); |
|
105 } |
|
106 } |
|
107 } |
|
108 |
|
109 protected boolean shouldFocusOnClick() { |
|
110 // Canvas should always be able to be focused by mouse clicks. |
|
111 return true; |
|
112 } |
|
113 } |
|