jdk/src/solaris/classes/sun/awt/motif/MWindowPeer.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 1995-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
package sun.awt.motif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.peer.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.image.BufferedImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.image.DataBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.image.DataBufferByte;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.image.DataBufferInt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.image.ImageObserver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.awt.image.ImageRepresentation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.awt.motif.MInputMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.awt.motif.MInputMethodControl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.awt.im.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.awt.DisplayChangedListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.awt.X11GraphicsDevice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
class MWindowPeer extends MPanelPeer implements WindowPeer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
DisplayChangedListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    Insets insets = new Insets( 0, 0, 0, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    MWindowAttributes winAttr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    static Vector allWindows = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    int         iconWidth  = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    int         iconHeight = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    int dropTargetCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    boolean alwaysOnTop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    native void pCreate(MComponentPeer parent, String targetClassName, boolean isFocusableWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    native void pShow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    native void pToFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    native void pShowModal(boolean isModal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    native void pHide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    native void pReshape(int x, int y, int width, int height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    native void pDispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    native void pSetTitle(String title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public native void setState(int state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public native int getState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public native void setResizable(boolean resizable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    native void addTextComponentNative(MComponentPeer tc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    native void removeTextComponentNative();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    native void pSetIMMOption(String option);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    native void pSetMenuBar(MMenuBarPeer mbpeer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    native void setSaveUnder(boolean state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    native void registerX11DropTarget(Component target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    native void unregisterX11DropTarget(Component target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    native void updateAlwaysOnTop(boolean isAlwaysOnTop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    // this function is privileged! do not change it to public!
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private static int getInset(final String name, final int def) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        Integer tmp = (Integer) java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            new sun.security.action.GetIntegerAction(name, def));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        return tmp.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    MWindowPeer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        insets = new Insets(0,0,0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        winAttr = new MWindowAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    MWindowPeer(Window target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        this();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        init(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        allWindows.addElement(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    void create(MComponentPeer parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        pCreate(parent, target.getClass().getName(), ((Window)target).isFocusableWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    void init( Window target ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        if ( winAttr.nativeDecor == true ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            insets.top = getInset("awt.frame.topInset", -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            insets.left = getInset("awt.frame.leftInset", -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            insets.bottom = getInset("awt.frame.bottomInset", -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            insets.right = getInset("awt.frame.rightInset", -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   116
        Rectangle bounds = target.getBounds();
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   117
        sysX = bounds.x;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   118
        sysY = bounds.y;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   119
        sysW = bounds.width;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   120
        sysH = bounds.height;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   121
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        super.init(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        InputMethodManager imm = InputMethodManager.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        String menuString = imm.getTriggerMenuString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        if (menuString != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            pSetIMMOption(menuString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        pSetTitle(winAttr.title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
         * For Windows and undecorated Frames and Dialogs this just
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
         * disables/enables resizing functions in the system menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        setResizable(winAttr.isResizable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        setSaveUnder(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        Font f = target.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        if (f == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            f = defaultFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            target.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        Color c = target.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            target.setBackground(SystemColor.window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            setBackground(SystemColor.window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        c = target.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            target.setForeground(SystemColor.windowText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            setForeground(SystemColor.windowText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        alwaysOnTop = ((Window)target).isAlwaysOnTop() && ((Window)target).isAlwaysOnTopSupported();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        GraphicsConfiguration gc = getGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        ((X11GraphicsDevice)gc.getDevice()).addDisplayChangedListener(this);
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   159
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /* Support for multiple icons is not implemented in MAWT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public void updateIconImages() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        if (this instanceof MFramePeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            ((MFramePeer)this).setIconImage(((Frame)target).getIconImage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /* Not implemented in MAWT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public void updateMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    protected void disposeImpl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        allWindows.removeElement(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        super.disposeImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public native void toBack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public void setAlwaysOnTop(boolean alwaysOnTop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        this.alwaysOnTop = alwaysOnTop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        updateAlwaysOnTop(alwaysOnTop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public void toFront() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        if (target.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            updateFocusableWindowState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            pToFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public void updateFocusableWindowState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        setFocusableWindow(((Window)target).isFocusableWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    native void setFocusableWindow(boolean value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public void setVisible( boolean b ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            updateFocusableWindowState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        super.setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        updateAlwaysOnTop(alwaysOnTop);
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 Insets getInsets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public void handleQuit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        postEvent(new WindowEvent((Window)target, WindowEvent.WINDOW_CLOSING));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    // XXX: nasty WM, foul play.  spank WM author.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    public void handleDestroy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        final Window target = (Window)this.target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        SunToolkit.executeOnEventHandlerThread(target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                                               new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                                                   public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                                                       // This seems like the only reasonable thing we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                                                       // could do in this situation as the native window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                                                       // is already dead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                                                       target.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                                                   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                                               });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public void handleIconify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        postEvent(new WindowEvent((Window)target, WindowEvent.WINDOW_ICONIFIED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public void handleDeiconify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        postEvent(new WindowEvent((Window)target, WindowEvent.WINDOW_DEICONIFIED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public void handleStateChange(int oldState, int newState) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        postEvent(new WindowEvent((Window)target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                                  WindowEvent.WINDOW_STATE_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                                  oldState, newState));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * Called to inform the Window that its size has changed and it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * should layout its children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    public void handleResize(int width, int height) {
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   256
        sysW = width;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   257
        sysH = height;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        // REMIND: Is this secure? Can client code subclass input method?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        if (!tcList.isEmpty() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            !imList.isEmpty()){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            for (i = 0; i < imList.size(); i++){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                ((MInputMethod)imList.elementAt(i)).configureStatus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        validateSurface(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        postEvent(new ComponentEvent(target, ComponentEvent.COMPONENT_RESIZED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * DEPRECATED:  Replaced by getInsets().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    public Insets insets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        return getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public void handleMoved(int x, int y) {
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   280
        sysX = x;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   281
        sysY = y;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        postEvent(new ComponentEvent(target, ComponentEvent.COMPONENT_MOVED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    private native AWTEvent wrapInSequenced(AWTEvent event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    public void handleWindowFocusIn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        /* wrap in Sequenced, then post*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        postEvent(wrapInSequenced((AWTEvent) we));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    public void handleWindowFocusOut(Window oppositeWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_LOST_FOCUS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                                         oppositeWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        /* wrap in Sequenced, then post*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        postEvent(wrapInSequenced((AWTEvent) we));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
// relocation of Imm stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    private Vector imList = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    private Vector tcList = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    // NOTE: This method is called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    void notifyIMMOptionChange(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        // REMIND: IS THIS SECURE??? CAN USER CODE SUBCLASS INPUTMETHODMGR???
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        InputMethodManager.getInstance().notifyChangeRequest(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public void addInputMethod(MInputMethod im) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        if (!imList.contains(im))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            imList.addElement(im);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    public void removeInputMethod(MInputMethod im) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        if (imList.contains(im))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            imList.removeElement(im);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    public void addTextComponent(MComponentPeer tc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        if (tcList.contains(tc))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        if (tcList.isEmpty()){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            addTextComponentNative(tc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            if (!imList.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                for (int i = 0; i < imList.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                    ((MInputMethod)imList.elementAt(i)).reconfigureXIC((MInputMethodControl)this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            MToolkit.executeOnEventHandlerThread(target, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                        synchronized(target.getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                            target.doLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        tcList.addElement(tc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    public void removeTextComponent(MComponentPeer tc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        if (!tcList.contains(tc))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        tcList.removeElement(tc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        if (tcList.isEmpty()){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            removeTextComponentNative();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            if (!imList.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                for (int i = 0; i < imList.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                    ((MInputMethod)imList.elementAt(i)).reconfigureXIC((MInputMethodControl)this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            target.doLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public MComponentPeer getTextComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        if (!tcList.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            return (MComponentPeer)tcList.firstElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    boolean hasDecorations(int decor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        if (!winAttr.nativeDecor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            int myDecor = winAttr.decorations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            boolean hasBits = ((myDecor & decor) == decor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            if ((myDecor & MWindowAttributes.AWT_DECOR_ALL) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                return !hasBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                return hasBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    /* Returns the native paint should be posted after setting new size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    public boolean checkNativePaintOnSetBounds(int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        // Fix for 4418155. Window does not repaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        // automticaly if shrinking. Should not wait for Expose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        return (width > oldWidth) || (height > oldHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
/* --- DisplayChangedListener Stuff --- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    native void resetTargetGC(Component target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    /* Xinerama
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * called to update our GC when dragged onto another screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    public void draggedToNewScreen(int screenNum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        final int finalScreenNum = screenNum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        SunToolkit.executeOnEventHandlerThread((Component)target, new Runnable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                    displayChanged(finalScreenNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    /* Xinerama
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * called to update our GC when dragged onto another screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    public void displayChanged(int screenNum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        // update our GC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        resetLocalGC(screenNum);         /* upcall to MCanvasPeer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        resetTargetGC(target);           /* call Window.resetGC() via native */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        //propagate to children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        super.displayChanged(screenNum); /* upcall to MPanelPeer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * Helper method that executes the displayChanged(screen) method on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * the event dispatch thread.  This method is used in the Xinerama case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * and after display mode change events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    private void executeDisplayChangedOnEDT(int screenNum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        final int finalScreenNum = screenNum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        Runnable dc = new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                displayChanged(finalScreenNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        SunToolkit.executeOnEventHandlerThread((Component)target, dc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * From the DisplayChangedListener interface; called from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * X11GraphicsDevice when the display mode has been changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    public void displayChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        GraphicsConfiguration gc = getGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        int curScreenNum = ((X11GraphicsDevice)gc.getDevice()).getScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        executeDisplayChangedOnEDT(curScreenNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * From the DisplayChangedListener interface; top-levels do not need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * to react to this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    public void paletteChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    public synchronized void addDropTarget() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        if (dropTargetCount == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            registerX11DropTarget(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        dropTargetCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    public synchronized void removeDropTarget() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        dropTargetCount--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        if (dropTargetCount == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            unregisterX11DropTarget(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    protected synchronized void updateDropTarget() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        if (dropTargetCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            unregisterX11DropTarget(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            registerX11DropTarget(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    public boolean requestWindowFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    public void setModalBlocked(Dialog blocker, boolean blocked) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        // do nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    public void postUngrabEvent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        postEvent(new sun.awt.UngrabEvent((Window)target));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    boolean isOwnerOf(MComponentPeer child) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        if (child == null) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        Component comp = child.target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        while (comp != null && !(comp instanceof Window)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            comp = getParent_NoClientCode(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        if (!(comp instanceof Window)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        while (comp != null && !(comp == target) && !(comp instanceof Dialog)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            comp = getParent_NoClientCode(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        return (comp == target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    boolean processUngrabMouseEvent(MComponentPeer compPeer, int x_root, int y_root, int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
          case 4: // ButtonPress
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
              // Check that the target is the child of the grabbed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
              // window or the child of one of the owned windows of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
              // the grabbed window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
              if (!isOwnerOf(compPeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                  postUngrabEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    }
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   519
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   520
    private final boolean hasWarningWindow() {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   521
        return ((Window)target).getWarningString() != null;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   522
    }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   523
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   524
    // This method is overriden at Dialog and Frame peers.
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   525
    boolean isTargetUndecorated() {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   526
        return true;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   527
    }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   528
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   529
    private volatile int sysX = 0;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   530
    private volatile int sysY = 0;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   531
    private volatile int sysW = 0;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   532
    private volatile int sysH = 0;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   533
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   534
    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
   535
        // We don't restrict the setBounds() operation if the code is trusted.
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   536
        if (!hasWarningWindow()) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   537
            return new Rectangle(x, y, width, height);
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   538
        }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   539
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   540
        int newX = x;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   541
        int newY = y;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   542
        int newW = width;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   543
        int newH = height;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   544
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   545
        GraphicsConfiguration gc = ((Window)target).getGraphicsConfiguration();
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   546
        Rectangle sB = gc.getBounds();
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   547
        Insets sIn = ((Window)target).getToolkit().getScreenInsets(gc);
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   548
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   549
        int screenW = sB.width - sIn.left - sIn.right;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   550
        int screenH = sB.height - sIn.top - sIn.bottom;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   551
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   552
        // If it's undecorated or is not currently visible,
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   553
        // then check each point is within the visible part of the screen
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   554
        if (!target.isVisible() || isTargetUndecorated()) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   555
            int screenX = sB.x + sIn.left;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   556
            int screenY = sB.y + sIn.top;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   557
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   558
            // First make sure the size is withing the visible part of the screen
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   559
            if (newW > screenW) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   560
                newW = screenW;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   561
            }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   562
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   563
            if (newH > screenH) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   564
                newH = screenH;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   565
            }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   566
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   567
            // Tweak the location if needed
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   568
            if (newX < screenX) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   569
                newX = screenX;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   570
            } else if (newX + newW > screenX + screenW) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   571
                newX = screenX + screenW - newW;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   572
            }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   573
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   574
            if (newY < screenY) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   575
                newY = screenY;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   576
            } else if (newY + newH > screenY + screenH) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   577
                newY = screenY + screenH - newH;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   578
            }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   579
        } else {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   580
            int maxW = Math.max(screenW, sysW);
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   581
            int maxH = Math.max(screenH, sysH);
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   582
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   583
            // Make sure the size is withing the visible part of the screen
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   584
            // OR is less that the current size of the window.
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   585
            if (newW > maxW) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   586
                newW = maxW;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   587
            }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   588
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   589
            if (newH > maxH) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   590
                newH = maxH;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   591
            }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   592
        }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   593
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   594
        return new Rectangle(newX, newY, newW, newH);
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   595
    }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   596
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   597
    public void setBounds(int x, int y, int width, int height, int op) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   598
        Rectangle newBounds = constrainBounds(x, y, width, height);
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   599
        super.setBounds(newBounds.x, newBounds.y, newBounds.width, newBounds.height, op);
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   600
    }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 2
diff changeset
   601
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
}