src/java.desktop/unix/classes/sun/awt/X11/XEmbeddingContainer.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 2014, Oracle and/or its affiliates. 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.awt.X11;
  27 
  28 import java.awt.*;
  29 import java.util.HashMap;
  30 import java.awt.event.KeyEvent;
  31 import java.lang.reflect.*;
  32 import sun.awt.AWTAccessor;
  33 
  34 public class XEmbeddingContainer extends XEmbedHelper implements XEventDispatcher {
  35     HashMap<Long, java.awt.peer.ComponentPeer> children = new HashMap<>();
  36 
  37     XEmbeddingContainer() {
  38     }
  39 
  40     XWindow embedder;
  41     void install(XWindow embedder) {
  42         this.embedder = embedder;
  43         XToolkit.addEventDispatcher(embedder.getWindow(), this);
  44     }
  45     void deinstall() {
  46         XToolkit.removeEventDispatcher(embedder.getWindow(), this);
  47     }
  48 
  49     @SuppressWarnings("deprecation")
  50     void add(long child) {
  51         if (checkXEmbed(child)) {
  52             Component proxy = createChildProxy(child);
  53             ((Container)embedder.getTarget()).add("Center", proxy);
  54             if (proxy.getPeer() != null) {
  55                 children.put(Long.valueOf(child), proxy.getPeer());


  56             }
  57         }
  58     }
  59 
  60     Component createChildProxy(long child) {
  61         return new XEmbedChildProxy(this, child);
  62     }
  63     void notifyChildEmbedded(long child) {
  64         sendMessage(child, XEMBED_EMBEDDED_NOTIFY, embedder.getWindow(), XEMBED_VERSION, 0);
  65     }
  66 
  67     void childResized(Component child) {
  68     }
  69 
  70     boolean checkXEmbed(long child) {
  71         long data = unsafe.allocateMemory(8);
  72         try {
  73             if (XEmbedInfo.getAtomData(child, data, 2)) {
  74                 int protocol = unsafe.getInt(data);
  75                 int flags = unsafe.getInt(data);


   1 /*
   2  * Copyright (c) 2003, 2015, Oracle and/or its affiliates. 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.awt.X11;
  27 
  28 import java.awt.*;
  29 import java.util.HashMap;
  30 import java.awt.event.KeyEvent;

  31 import sun.awt.AWTAccessor;
  32 
  33 public class XEmbeddingContainer extends XEmbedHelper implements XEventDispatcher {
  34     HashMap<Long, java.awt.peer.ComponentPeer> children = new HashMap<>();
  35 
  36     XEmbeddingContainer() {
  37     }
  38 
  39     XWindow embedder;
  40     void install(XWindow embedder) {
  41         this.embedder = embedder;
  42         XToolkit.addEventDispatcher(embedder.getWindow(), this);
  43     }
  44     void deinstall() {
  45         XToolkit.removeEventDispatcher(embedder.getWindow(), this);
  46     }
  47 

  48     void add(long child) {
  49         if (checkXEmbed(child)) {
  50             Component proxy = createChildProxy(child);
  51             ((Container)embedder.getTarget()).add("Center", proxy);
  52             XEmbeddedFramePeer peer = AWTAccessor.getComponentAccessor()
  53                                                  .getPeer(proxy);
  54             if (peer != null) {
  55                 children.put(Long.valueOf(child), peer);
  56             }
  57         }
  58     }
  59 
  60     Component createChildProxy(long child) {
  61         return new XEmbedChildProxy(this, child);
  62     }
  63     void notifyChildEmbedded(long child) {
  64         sendMessage(child, XEMBED_EMBEDDED_NOTIFY, embedder.getWindow(), XEMBED_VERSION, 0);
  65     }
  66 
  67     void childResized(Component child) {
  68     }
  69 
  70     boolean checkXEmbed(long child) {
  71         long data = unsafe.allocateMemory(8);
  72         try {
  73             if (XEmbedInfo.getAtomData(child, data, 2)) {
  74                 int protocol = unsafe.getInt(data);
  75                 int flags = unsafe.getInt(data);