jdk/src/solaris/classes/sun/awt/motif/MEmbeddedFramePeer.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 129 f995b9c9c5fa
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 129
diff changeset
     2
 * Copyright 1996-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt.motif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import sun.awt.EmbeddedFrame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.logging.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.AWTKeyStroke;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.Container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.LinkedList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.java2d.SurfaceData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public class MEmbeddedFramePeer extends MFramePeer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private static final Logger xembedLog = Logger.getLogger("sun.awt.motif.xembed.MEmbeddedFramePeer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
//     A detail code is required for XEMBED_FOCUS_IN. The following values are valid:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
/* Details for  XEMBED_FOCUS_IN: */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    final static int XEMBED_FOCUS_CURRENT       =       0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    final static int XEMBED_FOCUS_FIRST         =       1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    final static int XEMBED_FOCUS_LAST  =       2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    LinkedList<AWTKeyStroke> strokes = new LinkedList<AWTKeyStroke>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public MEmbeddedFramePeer(EmbeddedFrame target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        super(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        xembedLog.fine("Creating XEmbed-enabled motif embedded frame, frame supports XEmbed:" + supportsXEmbed());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    void create(MComponentPeer parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        NEFcreate(parent, ((MEmbeddedFrame)target).handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    native void NEFcreate(MComponentPeer parent, long handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    native void pShowImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    void pShow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        pShowImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    boolean supportsXEmbed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        EmbeddedFrame frame = (EmbeddedFrame)target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        if (frame != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            return frame.supportsXEmbed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public void setVisible(boolean vis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        super.setVisible(vis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        xembedLog.fine("Peer made visible");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        if (vis && !supportsXEmbed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            xembedLog.fine("Synthesizing FocusIn");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            // Fix for 4878303 - generate WINDOW_GAINED_FOCUS and update if we were focused
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            // since noone will do it for us(WM does it for regular top-levels)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            synthesizeFocusInOut(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public native void synthesizeFocusInOut(boolean b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    native boolean isXEmbedActive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    native boolean isXEmbedApplicationActive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    native void requestXEmbedFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public boolean requestWindowFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        xembedLog.fine("In requestWindowFocus");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        // Should check for active state of host application
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        if (isXEmbedActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            if (isXEmbedApplicationActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                xembedLog.fine("Requesting focus from embedding host");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                requestXEmbedFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                xembedLog.fine("Host application is not active");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            xembedLog.fine("Requesting focus from X");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            return super.requestWindowFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    void registerAccelerator(AWTKeyStroke stroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
//         if (stroke == null) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
//         strokes.add(stroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
//         if (isXEmbedActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
//             nativeRegisterAccelerator(stroke, strokes.size()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
//         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    void unregisterAccelerator(AWTKeyStroke stroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
//         if (stroke == null) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
//         if (isXEmbedActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
//             int index = strokes.indexOf(stroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
//             nativeUnregisterAccelerator(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
//         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    void notifyStarted() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        // Register accelerators
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
//         int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
//         Iterator<AWTKeyStroke> iter = strokes.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
//         while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
//             nativeRegisterAccelerator(iter.next(), i++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
//         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        updateDropTarget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    native void traverseOut(boolean direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    void handleFocusIn(int detail) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        xembedLog.log(Level.FINE, "handleFocusIn {0}", new Object[]{Integer.valueOf(detail)});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        switch(detail) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
          case XEMBED_FOCUS_CURRENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
              // Do nothing - just restore to the current value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
          case XEMBED_FOCUS_FIRST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
              SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                      public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                          Component comp = ((Container)target).getFocusTraversalPolicy().getFirstComponent((Container)target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                          if (comp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                              comp.requestFocusInWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                      }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
          case XEMBED_FOCUS_LAST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
              SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                      public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                          Component comp = ((Container)target).getFocusTraversalPolicy().getLastComponent((Container)target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                          if (comp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                              comp.requestFocusInWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                      }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public void handleWindowFocusIn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        super.handleWindowFocusIn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        xembedLog.fine("windowFocusIn");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public void handleWindowFocusOut(Window oppositeWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        super.handleWindowFocusOut(oppositeWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        xembedLog.fine("windowFocusOut, opposite is null?:" + (oppositeWindow==null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    native void pReshapePrivate(int x, int y, int w, int h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public void setBoundsPrivate(int x, int y, int width, int height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (disposed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        // Should set paintPending before reshape to prevent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        // thread race between PaintEvent and setBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        // This part of the 4267393 fix proved to be unstable under solaris,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        // dissabled due to regressions 4418155, 4486762, 4490079
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        paintPending = false; //checkNativePaintOnSetBounds(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        pReshapePrivate(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if ((width != oldWidth) || (height != oldHeight))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            SurfaceData oldData = surfaceData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            if (oldData != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                surfaceData = graphicsConfig.createSurfaceData(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                oldData.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            oldWidth = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            oldHeight = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        validateSurface(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        serialNum++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public native Rectangle getBoundsPrivate();
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   207
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   208
    @Override
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   209
    Rectangle constrainBounds(int x, int y, int width, int height) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   210
        // We don't constrain the bounds of the EmbeddedFrames
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   211
        return new Rectangle(x, y, width, height);
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   212
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
}