001: /*
002: * Copyright 1996-2004 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 java.awt.Component;
029: import java.awt.peer.FramePeer;
030: import sun.awt.EmbeddedFrame;
031: import java.awt.peer.ComponentPeer;
032: import sun.awt.*;
033: import java.awt.*;
034:
035: public class MEmbeddedFrame extends EmbeddedFrame {
036:
037: /**
038: * Widget id of the shell widget
039: */
040: long handle;
041:
042: public enum IDKind {
043: WIDGET, WINDOW
044: };
045:
046: public MEmbeddedFrame() {
047: }
048:
049: /**
050: * Backward-compatible implementation. This constructor takes widget which represents Frame's
051: * shell and uses it as top-level to build hierarchy of top-level widgets upon. It assumes that
052: * no XEmbed support is provided.
053: * @param widget a valid Xt widget pointer.
054: */
055: public MEmbeddedFrame(long widget) {
056: this (widget, IDKind.WIDGET, false);
057: }
058:
059: /**
060: * New constructor, gets X Window id and allows to specify whether XEmbed is supported by parent
061: * X window. Creates hierarchy of top-level widgets under supplied window ID.
062: * @param winid a valid X window
063: * @param supportsXEmbed whether the host application supports XEMBED protocol
064: */
065: public MEmbeddedFrame(long winid, boolean supportsXEmbed) {
066: this (winid, IDKind.WINDOW, supportsXEmbed);
067: }
068:
069: /**
070: * Creates embedded frame using ID as parent.
071: * @param ID parent ID
072: * @param supportsXEmbed whether the host application supports XEMBED protocol
073: * @param kind if WIDGET, ID represents a valid Xt widget pointer; if WINDOW, ID is a valid X Window
074: * ID
075: */
076: public MEmbeddedFrame(long ID, IDKind kind, boolean supportsXEmbed) {
077: super (supportsXEmbed);
078: if (kind == IDKind.WIDGET) {
079: this .handle = ID;
080: } else {
081: this .handle = getWidget(ID);
082: }
083: MToolkit toolkit = (MToolkit) Toolkit.getDefaultToolkit();
084: setPeer(toolkit.createEmbeddedFrame(this ));
085: /*
086: * addNotify() creates a LightweightDispatcher that propagates
087: * SunDropTargetEvents to subcomponents.
088: * NOTE: show() doesn't call addNotify() for embedded frames.
089: */
090: addNotify();
091: show();
092: }
093:
094: public void synthesizeWindowActivation(boolean b) {
095: MEmbeddedFramePeer peer = (MEmbeddedFramePeer) getPeer();
096: if (peer != null) {
097: if (peer.supportsXEmbed()) {
098: if (peer.isXEmbedActive()) {
099: // If XEmbed is active no synthetic focus events are allowed - everything
100: // should go through XEmbed
101: if (b) {
102: peer.requestXEmbedFocus();
103: }
104: }
105: } else {
106: peer.synthesizeFocusInOut(b);
107: }
108: }
109: }
110:
111: public void show() {
112: if (handle != 0) {
113: mapWidget(handle);
114: }
115: super .show();
116: }
117:
118: protected boolean traverseOut(boolean direction) {
119: MEmbeddedFramePeer xefp = (MEmbeddedFramePeer) getPeer();
120: xefp.traverseOut(direction);
121: return true;
122: }
123:
124: // Native methods to handle widget <-> X Windows mapping
125: //
126: static native long getWidget(long winid);
127:
128: static native int mapWidget(long widget);
129:
130: public void registerAccelerator(AWTKeyStroke stroke) {
131: MEmbeddedFramePeer xefp = (MEmbeddedFramePeer) getPeer();
132: if (xefp != null) {
133: xefp.registerAccelerator(stroke);
134: }
135: }
136:
137: public void unregisterAccelerator(AWTKeyStroke stroke) {
138: MEmbeddedFramePeer xefp = (MEmbeddedFramePeer) getPeer();
139: if (xefp != null) {
140: xefp.unregisterAccelerator(stroke);
141: }
142: }
143: }
|