jdk/src/solaris/classes/sun/awt/motif/MEmbeddedFrame.java
changeset 1203 3e5496df0d2b
parent 1202 5a725d2f0daa
parent 1201 e87f9c042699
child 1211 b659a7cee935
equal deleted inserted replaced
1202:5a725d2f0daa 1203:3e5496df0d2b
     1 /*
       
     2  * Copyright 1996-2004 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 java.awt.Component;
       
    29 import java.awt.peer.FramePeer;
       
    30 import sun.awt.EmbeddedFrame;
       
    31 import java.awt.peer.ComponentPeer;
       
    32 import sun.awt.*;
       
    33 import java.awt.*;
       
    34 
       
    35 public class MEmbeddedFrame extends EmbeddedFrame {
       
    36 
       
    37     /**
       
    38      * Widget id of the shell widget
       
    39      */
       
    40     long handle;
       
    41 
       
    42     public enum IDKind {
       
    43         WIDGET,
       
    44         WINDOW
       
    45     };
       
    46 
       
    47     public MEmbeddedFrame() {
       
    48     }
       
    49 
       
    50     /**
       
    51      * Backward-compatible implementation. This constructor takes widget which represents Frame's
       
    52      * shell and uses it as top-level to build hierarchy of top-level widgets upon. It assumes that
       
    53      * no XEmbed support is provided.
       
    54      * @param widget a valid Xt widget pointer.
       
    55      */
       
    56     public MEmbeddedFrame(long widget) {
       
    57         this(widget, IDKind.WIDGET, false);
       
    58     }
       
    59 
       
    60     /**
       
    61      * New constructor, gets X Window id and allows to specify whether XEmbed is supported by parent
       
    62      * X window. Creates hierarchy of top-level widgets under supplied window ID.
       
    63      * @param winid a valid X window
       
    64      * @param supportsXEmbed whether the host application supports XEMBED protocol
       
    65      */
       
    66     public MEmbeddedFrame(long winid, boolean supportsXEmbed) {
       
    67         this(winid, IDKind.WINDOW, supportsXEmbed);
       
    68     }
       
    69 
       
    70     /**
       
    71      * Creates embedded frame using ID as parent.
       
    72      * @param ID parent ID
       
    73      * @param supportsXEmbed whether the host application supports XEMBED protocol
       
    74      * @param kind if WIDGET, ID represents a valid Xt widget pointer; if WINDOW, ID is a valid X Window
       
    75      * ID
       
    76      */
       
    77     public MEmbeddedFrame(long ID, IDKind kind, boolean supportsXEmbed) {
       
    78         super(supportsXEmbed);
       
    79         if (kind == IDKind.WIDGET) {
       
    80             this.handle = ID;
       
    81         } else {
       
    82             this.handle = getWidget(ID);
       
    83         }
       
    84         MToolkit toolkit = (MToolkit)Toolkit.getDefaultToolkit();
       
    85         setPeer(toolkit.createEmbeddedFrame(this));
       
    86         /*
       
    87          * addNotify() creates a LightweightDispatcher that propagates
       
    88          * SunDropTargetEvents to subcomponents.
       
    89          * NOTE: show() doesn't call addNotify() for embedded frames.
       
    90          */
       
    91         addNotify();
       
    92         show();
       
    93     }
       
    94 
       
    95     public void synthesizeWindowActivation(boolean b) {
       
    96         MEmbeddedFramePeer peer = (MEmbeddedFramePeer)getPeer();
       
    97         if (peer != null) {
       
    98             if (peer.supportsXEmbed()) {
       
    99                 if (peer.isXEmbedActive()) {
       
   100                     // If XEmbed is active no synthetic focus events are allowed - everything
       
   101                     // should go through XEmbed
       
   102                     if (b) {
       
   103                         peer.requestXEmbedFocus();
       
   104                     }
       
   105                 }
       
   106             } else {
       
   107                 peer.synthesizeFocusInOut(b);
       
   108             }
       
   109         }
       
   110     }
       
   111 
       
   112     public void show() {
       
   113         if (handle != 0) {
       
   114             mapWidget(handle);
       
   115         }
       
   116         super.show();
       
   117     }
       
   118 
       
   119     protected boolean traverseOut(boolean direction) {
       
   120         MEmbeddedFramePeer xefp = (MEmbeddedFramePeer) getPeer();
       
   121         xefp.traverseOut(direction);
       
   122         return true;
       
   123     }
       
   124 
       
   125     // Native methods to handle widget <-> X Windows mapping
       
   126     //
       
   127     static native long getWidget(long winid);
       
   128     static native int mapWidget(long widget);
       
   129     public void registerAccelerator(AWTKeyStroke stroke) {
       
   130         MEmbeddedFramePeer xefp = (MEmbeddedFramePeer) getPeer();
       
   131         if (xefp != null) {
       
   132             xefp.registerAccelerator(stroke);
       
   133         }
       
   134     }
       
   135     public void unregisterAccelerator(AWTKeyStroke stroke) {
       
   136         MEmbeddedFramePeer xefp = (MEmbeddedFramePeer) getPeer();
       
   137         if (xefp != null) {
       
   138             xefp.unregisterAccelerator(stroke);
       
   139         }
       
   140     }
       
   141 }