|
1 /* |
|
2 * Copyright 1996-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 |
|
26 package sun.awt.motif; |
|
27 |
|
28 import sun.awt.EmbeddedFrame; |
|
29 import java.util.logging.*; |
|
30 import java.awt.Component; |
|
31 import java.awt.Point; |
|
32 import java.awt.Rectangle; |
|
33 import java.awt.Window; |
|
34 import java.awt.AWTKeyStroke; |
|
35 import java.awt.Component; |
|
36 import java.awt.Container; |
|
37 import sun.awt.SunToolkit; |
|
38 import java.util.LinkedList; |
|
39 import java.util.Iterator; |
|
40 |
|
41 import sun.java2d.SurfaceData; |
|
42 |
|
43 public class MEmbeddedFramePeer extends MFramePeer { |
|
44 private static final Logger xembedLog = Logger.getLogger("sun.awt.motif.xembed.MEmbeddedFramePeer"); |
|
45 |
|
46 // A detail code is required for XEMBED_FOCUS_IN. The following values are valid: |
|
47 /* Details for XEMBED_FOCUS_IN: */ |
|
48 final static int XEMBED_FOCUS_CURRENT = 0; |
|
49 final static int XEMBED_FOCUS_FIRST = 1; |
|
50 final static int XEMBED_FOCUS_LAST = 2; |
|
51 |
|
52 LinkedList<AWTKeyStroke> strokes = new LinkedList<AWTKeyStroke>(); |
|
53 |
|
54 public MEmbeddedFramePeer(EmbeddedFrame target) { |
|
55 super(target); |
|
56 xembedLog.fine("Creating XEmbed-enabled motif embedded frame, frame supports XEmbed:" + supportsXEmbed()); |
|
57 } |
|
58 |
|
59 void create(MComponentPeer parent) { |
|
60 NEFcreate(parent, ((MEmbeddedFrame)target).handle); |
|
61 } |
|
62 native void NEFcreate(MComponentPeer parent, long handle); |
|
63 native void pShowImpl(); |
|
64 void pShow() { |
|
65 pShowImpl(); |
|
66 } |
|
67 |
|
68 boolean supportsXEmbed() { |
|
69 EmbeddedFrame frame = (EmbeddedFrame)target; |
|
70 if (frame != null) { |
|
71 return frame.supportsXEmbed(); |
|
72 } else { |
|
73 return false; |
|
74 } |
|
75 } |
|
76 |
|
77 public void setVisible(boolean vis) { |
|
78 super.setVisible(vis); |
|
79 xembedLog.fine("Peer made visible"); |
|
80 if (vis && !supportsXEmbed()) { |
|
81 xembedLog.fine("Synthesizing FocusIn"); |
|
82 // Fix for 4878303 - generate WINDOW_GAINED_FOCUS and update if we were focused |
|
83 // since noone will do it for us(WM does it for regular top-levels) |
|
84 synthesizeFocusInOut(true); |
|
85 } |
|
86 } |
|
87 public native void synthesizeFocusInOut(boolean b); |
|
88 |
|
89 native boolean isXEmbedActive(); |
|
90 native boolean isXEmbedApplicationActive(); |
|
91 native void requestXEmbedFocus(); |
|
92 |
|
93 public boolean requestWindowFocus() { |
|
94 xembedLog.fine("In requestWindowFocus"); |
|
95 // Should check for active state of host application |
|
96 if (isXEmbedActive()) { |
|
97 if (isXEmbedApplicationActive()) { |
|
98 xembedLog.fine("Requesting focus from embedding host"); |
|
99 requestXEmbedFocus(); |
|
100 return true; |
|
101 } else { |
|
102 xembedLog.fine("Host application is not active"); |
|
103 return false; |
|
104 } |
|
105 } else { |
|
106 xembedLog.fine("Requesting focus from X"); |
|
107 return super.requestWindowFocus(); |
|
108 } |
|
109 } |
|
110 |
|
111 void registerAccelerator(AWTKeyStroke stroke) { |
|
112 // if (stroke == null) return; |
|
113 // strokes.add(stroke); |
|
114 // if (isXEmbedActive()) { |
|
115 // nativeRegisterAccelerator(stroke, strokes.size()-1); |
|
116 // } |
|
117 } |
|
118 |
|
119 void unregisterAccelerator(AWTKeyStroke stroke) { |
|
120 // if (stroke == null) return; |
|
121 // if (isXEmbedActive()) { |
|
122 // int index = strokes.indexOf(stroke); |
|
123 // nativeUnregisterAccelerator(index); |
|
124 // } |
|
125 } |
|
126 |
|
127 void notifyStarted() { |
|
128 // Register accelerators |
|
129 // int i = 0; |
|
130 // Iterator<AWTKeyStroke> iter = strokes.iterator(); |
|
131 // while (iter.hasNext()) { |
|
132 // nativeRegisterAccelerator(iter.next(), i++); |
|
133 // } |
|
134 |
|
135 updateDropTarget(); |
|
136 } |
|
137 |
|
138 native void traverseOut(boolean direction); |
|
139 |
|
140 void handleFocusIn(int detail) { |
|
141 xembedLog.log(Level.FINE, "handleFocusIn {0}", new Object[]{Integer.valueOf(detail)}); |
|
142 switch(detail) { |
|
143 case XEMBED_FOCUS_CURRENT: |
|
144 // Do nothing - just restore to the current value |
|
145 break; |
|
146 case XEMBED_FOCUS_FIRST: |
|
147 SunToolkit.executeOnEventHandlerThread(target, new Runnable() { |
|
148 public void run() { |
|
149 Component comp = ((Container)target).getFocusTraversalPolicy().getFirstComponent((Container)target); |
|
150 if (comp != null) { |
|
151 comp.requestFocusInWindow(); |
|
152 } |
|
153 }}); |
|
154 break; |
|
155 case XEMBED_FOCUS_LAST: |
|
156 SunToolkit.executeOnEventHandlerThread(target, new Runnable() { |
|
157 public void run() { |
|
158 Component comp = ((Container)target).getFocusTraversalPolicy().getLastComponent((Container)target); |
|
159 if (comp != null) { |
|
160 comp.requestFocusInWindow(); |
|
161 } |
|
162 }}); |
|
163 break; |
|
164 } |
|
165 } |
|
166 public void handleWindowFocusIn() { |
|
167 super.handleWindowFocusIn(); |
|
168 xembedLog.fine("windowFocusIn"); |
|
169 } |
|
170 public void handleWindowFocusOut(Window oppositeWindow) { |
|
171 super.handleWindowFocusOut(oppositeWindow); |
|
172 xembedLog.fine("windowFocusOut, opposite is null?:" + (oppositeWindow==null)); |
|
173 } |
|
174 |
|
175 native void pReshapePrivate(int x, int y, int w, int h); |
|
176 |
|
177 public void setBoundsPrivate(int x, int y, int width, int height) |
|
178 { |
|
179 if (disposed) |
|
180 { |
|
181 return; |
|
182 } |
|
183 |
|
184 // Should set paintPending before reshape to prevent |
|
185 // thread race between PaintEvent and setBounds |
|
186 // This part of the 4267393 fix proved to be unstable under solaris, |
|
187 // dissabled due to regressions 4418155, 4486762, 4490079 |
|
188 paintPending = false; //checkNativePaintOnSetBounds(width, height); |
|
189 |
|
190 pReshapePrivate(x, y, width, height); |
|
191 |
|
192 if ((width != oldWidth) || (height != oldHeight)) |
|
193 { |
|
194 SurfaceData oldData = surfaceData; |
|
195 if (oldData != null) { |
|
196 surfaceData = graphicsConfig.createSurfaceData(this); |
|
197 oldData.invalidate(); |
|
198 } |
|
199 oldWidth = width; |
|
200 oldHeight = height; |
|
201 } |
|
202 validateSurface(width, height); |
|
203 serialNum++; |
|
204 } |
|
205 |
|
206 public native Rectangle getBoundsPrivate(); |
|
207 } |