36 37 /** 38 * Helper class implementing XEmbed protocol handling routines(client side) 39 * Window which wants to participate in a protocol should create an instance, 40 * call install and forward all XClientMessageEvents to it. 41 */ 42 public class XEmbedClientHelper extends XEmbedHelper implements XEventDispatcher { 43 private static final PlatformLogger xembedLog = PlatformLogger.getLogger("sun.awt.X11.xembed.XEmbedClientHelper"); 44 45 private XEmbeddedFramePeer embedded; // XEmbed client 46 private long server; // XEmbed server 47 48 private boolean active; 49 private boolean applicationActive; 50 51 XEmbedClientHelper() { 52 super(); 53 } 54 55 void setClient(XEmbeddedFramePeer client) { 56 if (xembedLog.isLoggable(PlatformLogger.FINE)) { 57 xembedLog.fine("XEmbed client: " + client); 58 } 59 if (embedded != null) { 60 XToolkit.removeEventDispatcher(embedded.getWindow(), this); 61 active = false; 62 } 63 embedded = client; 64 if (embedded != null) { 65 XToolkit.addEventDispatcher(embedded.getWindow(), this); 66 } 67 } 68 69 void install() { 70 if (xembedLog.isLoggable(PlatformLogger.FINE)) { 71 xembedLog.fine("Installing xembedder on " + embedded); 72 } 73 long[] info = new long[] { XEMBED_VERSION, XEMBED_MAPPED }; 74 long data = Native.card32ToData(info); 75 try { 76 XEmbedInfo.setAtomData(embedded.getWindow(), data, 2); 77 } finally { 78 unsafe.freeMemory(data); 79 } 80 // XEmbeddedFrame is initially created with a null parent.. 81 // Here it is reparented to the proper parent window. 82 long parentWindow = embedded.getParentWindowHandle(); 83 if (parentWindow != 0) { 84 XToolkit.awtLock(); 85 try { 86 XlibWrapper.XReparentWindow(XToolkit.getDisplay(), 87 embedded.getWindow(), 88 parentWindow, 89 0, 0); 90 } finally { 91 XToolkit.awtUnlock(); 92 } 93 } 94 } 95 96 void handleClientMessage(XEvent xev) { 97 XClientMessageEvent msg = xev.get_xclient(); 98 if (xembedLog.isLoggable(PlatformLogger.FINE)) { 99 xembedLog.fine(msg.toString()); 100 } 101 if (msg.get_message_type() == XEmbed.getAtom()) { 102 if (xembedLog.isLoggable(PlatformLogger.FINE)) { 103 xembedLog.fine("Embedded message: " + msgidToString((int)msg.get_data(1))); 104 } 105 switch ((int)msg.get_data(1)) { 106 case XEMBED_EMBEDDED_NOTIFY: // Notification about embedding protocol start 107 active = true; 108 server = getEmbedder(embedded, msg); 109 // Check if window is reparented. If not - it was created with 110 // parent and so we should update it here. 111 if (!embedded.isReparented()) { 112 embedded.setReparented(true); 113 embedded.updateSizeHints(); 114 } 115 embedded.notifyStarted(); 116 break; 117 case XEMBED_WINDOW_ACTIVATE: 118 applicationActive = true; 119 break; 120 case XEMBED_WINDOW_DEACTIVATE: 121 if (applicationActive) { 122 applicationActive = false; | 36 37 /** 38 * Helper class implementing XEmbed protocol handling routines(client side) 39 * Window which wants to participate in a protocol should create an instance, 40 * call install and forward all XClientMessageEvents to it. 41 */ 42 public class XEmbedClientHelper extends XEmbedHelper implements XEventDispatcher { 43 private static final PlatformLogger xembedLog = PlatformLogger.getLogger("sun.awt.X11.xembed.XEmbedClientHelper"); 44 45 private XEmbeddedFramePeer embedded; // XEmbed client 46 private long server; // XEmbed server 47 48 private boolean active; 49 private boolean applicationActive; 50 51 XEmbedClientHelper() { 52 super(); 53 } 54 55 void setClient(XEmbeddedFramePeer client) { 56 if (xembedLog.isLoggable(PlatformLogger.Level.FINE)) { 57 xembedLog.fine("XEmbed client: " + client); 58 } 59 if (embedded != null) { 60 XToolkit.removeEventDispatcher(embedded.getWindow(), this); 61 active = false; 62 } 63 embedded = client; 64 if (embedded != null) { 65 XToolkit.addEventDispatcher(embedded.getWindow(), this); 66 } 67 } 68 69 void install() { 70 if (xembedLog.isLoggable(PlatformLogger.Level.FINE)) { 71 xembedLog.fine("Installing xembedder on " + embedded); 72 } 73 long[] info = new long[] { XEMBED_VERSION, XEMBED_MAPPED }; 74 long data = Native.card32ToData(info); 75 try { 76 XEmbedInfo.setAtomData(embedded.getWindow(), data, 2); 77 } finally { 78 unsafe.freeMemory(data); 79 } 80 // XEmbeddedFrame is initially created with a null parent.. 81 // Here it is reparented to the proper parent window. 82 long parentWindow = embedded.getParentWindowHandle(); 83 if (parentWindow != 0) { 84 XToolkit.awtLock(); 85 try { 86 XlibWrapper.XReparentWindow(XToolkit.getDisplay(), 87 embedded.getWindow(), 88 parentWindow, 89 0, 0); 90 } finally { 91 XToolkit.awtUnlock(); 92 } 93 } 94 } 95 96 void handleClientMessage(XEvent xev) { 97 XClientMessageEvent msg = xev.get_xclient(); 98 if (xembedLog.isLoggable(PlatformLogger.Level.FINE)) { 99 xembedLog.fine(msg.toString()); 100 } 101 if (msg.get_message_type() == XEmbed.getAtom()) { 102 if (xembedLog.isLoggable(PlatformLogger.Level.FINE)) { 103 xembedLog.fine("Embedded message: " + msgidToString((int)msg.get_data(1))); 104 } 105 switch ((int)msg.get_data(1)) { 106 case XEMBED_EMBEDDED_NOTIFY: // Notification about embedding protocol start 107 active = true; 108 server = getEmbedder(embedded, msg); 109 // Check if window is reparented. If not - it was created with 110 // parent and so we should update it here. 111 if (!embedded.isReparented()) { 112 embedded.setReparented(true); 113 embedded.updateSizeHints(); 114 } 115 embedded.notifyStarted(); 116 break; 117 case XEMBED_WINDOW_ACTIVATE: 118 applicationActive = true; 119 break; 120 case XEMBED_WINDOW_DEACTIVATE: 121 if (applicationActive) { 122 applicationActive = false; |