001: /*
002: * Copyright 1996-2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.awt.motif;
027:
028: import sun.awt.EmbeddedFrame;
029: import java.util.logging.*;
030: import java.awt.Component;
031: import java.awt.Point;
032: import java.awt.Rectangle;
033: import java.awt.Window;
034: import java.awt.AWTKeyStroke;
035: import java.awt.Component;
036: import java.awt.Container;
037: import sun.awt.SunToolkit;
038: import java.util.LinkedList;
039: import java.util.Iterator;
040:
041: import sun.java2d.SurfaceData;
042:
043: public class MEmbeddedFramePeer extends MFramePeer {
044: private static final Logger xembedLog = Logger
045: .getLogger("sun.awt.motif.xembed.MEmbeddedFramePeer");
046:
047: // A detail code is required for XEMBED_FOCUS_IN. The following values are valid:
048: /* Details for XEMBED_FOCUS_IN: */
049: final static int XEMBED_FOCUS_CURRENT = 0;
050: final static int XEMBED_FOCUS_FIRST = 1;
051: final static int XEMBED_FOCUS_LAST = 2;
052:
053: LinkedList<AWTKeyStroke> strokes = new LinkedList<AWTKeyStroke>();
054:
055: public MEmbeddedFramePeer(EmbeddedFrame target) {
056: super (target);
057: xembedLog
058: .fine("Creating XEmbed-enabled motif embedded frame, frame supports XEmbed:"
059: + supportsXEmbed());
060: }
061:
062: void create(MComponentPeer parent) {
063: NEFcreate(parent, ((MEmbeddedFrame) target).handle);
064: }
065:
066: native void NEFcreate(MComponentPeer parent, long handle);
067:
068: native void pShowImpl();
069:
070: void pShow() {
071: pShowImpl();
072: }
073:
074: boolean supportsXEmbed() {
075: EmbeddedFrame frame = (EmbeddedFrame) target;
076: if (frame != null) {
077: return frame.supportsXEmbed();
078: } else {
079: return false;
080: }
081: }
082:
083: public void setVisible(boolean vis) {
084: super .setVisible(vis);
085: xembedLog.fine("Peer made visible");
086: if (vis && !supportsXEmbed()) {
087: xembedLog.fine("Synthesizing FocusIn");
088: // Fix for 4878303 - generate WINDOW_GAINED_FOCUS and update if we were focused
089: // since noone will do it for us(WM does it for regular top-levels)
090: synthesizeFocusInOut(true);
091: }
092: }
093:
094: public native void synthesizeFocusInOut(boolean b);
095:
096: native boolean isXEmbedActive();
097:
098: native boolean isXEmbedApplicationActive();
099:
100: native void requestXEmbedFocus();
101:
102: public boolean requestWindowFocus() {
103: xembedLog.fine("In requestWindowFocus");
104: // Should check for active state of host application
105: if (isXEmbedActive()) {
106: if (isXEmbedApplicationActive()) {
107: xembedLog.fine("Requesting focus from embedding host");
108: requestXEmbedFocus();
109: return true;
110: } else {
111: xembedLog.fine("Host application is not active");
112: return false;
113: }
114: } else {
115: xembedLog.fine("Requesting focus from X");
116: return super .requestWindowFocus();
117: }
118: }
119:
120: void registerAccelerator(AWTKeyStroke stroke) {
121: // if (stroke == null) return;
122: // strokes.add(stroke);
123: // if (isXEmbedActive()) {
124: // nativeRegisterAccelerator(stroke, strokes.size()-1);
125: // }
126: }
127:
128: void unregisterAccelerator(AWTKeyStroke stroke) {
129: // if (stroke == null) return;
130: // if (isXEmbedActive()) {
131: // int index = strokes.indexOf(stroke);
132: // nativeUnregisterAccelerator(index);
133: // }
134: }
135:
136: void notifyStarted() {
137: // Register accelerators
138: // int i = 0;
139: // Iterator<AWTKeyStroke> iter = strokes.iterator();
140: // while (iter.hasNext()) {
141: // nativeRegisterAccelerator(iter.next(), i++);
142: // }
143:
144: updateDropTarget();
145: }
146:
147: native void traverseOut(boolean direction);
148:
149: void handleFocusIn(int detail) {
150: xembedLog.log(Level.FINE, "handleFocusIn {0}",
151: new Object[] { Integer.valueOf(detail) });
152: switch (detail) {
153: case XEMBED_FOCUS_CURRENT:
154: // Do nothing - just restore to the current value
155: break;
156: case XEMBED_FOCUS_FIRST:
157: SunToolkit.executeOnEventHandlerThread(target,
158: new Runnable() {
159: public void run() {
160: Component comp = ((Container) target)
161: .getFocusTraversalPolicy()
162: .getFirstComponent(
163: (Container) target);
164: if (comp != null) {
165: comp.requestFocusInWindow();
166: }
167: }
168: });
169: break;
170: case XEMBED_FOCUS_LAST:
171: SunToolkit.executeOnEventHandlerThread(target,
172: new Runnable() {
173: public void run() {
174: Component comp = ((Container) target)
175: .getFocusTraversalPolicy()
176: .getLastComponent(
177: (Container) target);
178: if (comp != null) {
179: comp.requestFocusInWindow();
180: }
181: }
182: });
183: break;
184: }
185: }
186:
187: public void handleWindowFocusIn() {
188: super .handleWindowFocusIn();
189: xembedLog.fine("windowFocusIn");
190: }
191:
192: public void handleWindowFocusOut(Window oppositeWindow) {
193: super .handleWindowFocusOut(oppositeWindow);
194: xembedLog.fine("windowFocusOut, opposite is null?:"
195: + (oppositeWindow == null));
196: }
197:
198: native void pReshapePrivate(int x, int y, int w, int h);
199:
200: public void setBoundsPrivate(int x, int y, int width, int height) {
201: if (disposed) {
202: return;
203: }
204:
205: // Should set paintPending before reshape to prevent
206: // thread race between PaintEvent and setBounds
207: // This part of the 4267393 fix proved to be unstable under solaris,
208: // dissabled due to regressions 4418155, 4486762, 4490079
209: paintPending = false; //checkNativePaintOnSetBounds(width, height);
210:
211: pReshapePrivate(x, y, width, height);
212:
213: if ((width != oldWidth) || (height != oldHeight)) {
214: SurfaceData oldData = surfaceData;
215: if (oldData != null) {
216: surfaceData = graphicsConfig.createSurfaceData(this );
217: oldData.invalidate();
218: }
219: oldWidth = width;
220: oldHeight = height;
221: }
222: validateSurface(width, height);
223: serialNum++;
224: }
225:
226: public native Rectangle getBoundsPrivate();
227: }
|