jdk/src/solaris/classes/sun/awt/X11/XDecoratedPeer.java
author ant
Wed, 09 Apr 2008 09:37:07 +0400
changeset 442 687798d7d7b6
parent 439 3488710b02f8
child 449 7820f232278d
permissions -rw-r--r--
6522725: Component in a minimized Frame has focus and receives key events Summary: XAWT: a window natively focused may request focus in it only synthetically Reviewed-by: son
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
     2
 * Copyright 2002-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.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.ComponentEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.event.InvocationEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.event.WindowEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.logging.Level;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.logging.Logger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.awt.ComponentAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
    39
abstract class XDecoratedPeer extends XWindowPeer {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    private static final Logger log = Logger.getLogger("sun.awt.X11.XDecoratedPeer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private static final Logger insLog = Logger.getLogger("sun.awt.X11.insets.XDecoratedPeer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private static final Logger focusLog = Logger.getLogger("sun.awt.X11.focus.XDecoratedPeer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private final static Logger iconLog = Logger.getLogger("sun.awt.X11.icon.XDecoratedPeer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private static XAtom resize_request = new XAtom("_SUN_AWT_RESIZE_REQUEST", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    // Set to true when we get the first ConfigureNotify after being
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    // reparented - indicates that WM has adopted the top-level.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    boolean configure_seen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    boolean insets_corrected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    XIconWindow iconWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    WindowDimensions dimensions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    XContentWindow content;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    Insets currentInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    XFocusProxyWindow focusProxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    XDecoratedPeer(Window target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        super(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    XDecoratedPeer(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        super(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public long getShell() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        return window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public long getContentWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        return (content == null) ? window : content.getWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    void preInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        super.preInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        if (!resize_request.isInterned()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            resize_request.intern(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        winAttr.initialFocus = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        currentInsets = new Insets(0,0,0,0); // replacemenet for wdata->top, left, bottom, right
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        applyGuessedInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        Rectangle bounds = (Rectangle)params.get(BOUNDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        dimensions = new WindowDimensions(bounds, getRealInsets(), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        params.put(BOUNDS, dimensions.getClientRect());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        insLog.log(Level.FINE, "Initial dimensions {0}", new Object[] { dimensions });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        // Deny default processing of these events on the shell - proxy will take care of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        // them instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        Long eventMask = (Long)params.get(EVENT_MASK);
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
    92
        params.add(EVENT_MASK, Long.valueOf(eventMask.longValue() & ~(XConstants.FocusChangeMask | XConstants.KeyPressMask | XConstants.KeyReleaseMask)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    void postInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        super.postInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        // The lines that follow need to be in a postInit, so they
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        // happen after the X window is created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        initResizability();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        updateSizeHints(dimensions);
115
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
   101
        content = XContentWindow.createContent(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        if (warningWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            warningWindow.toFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        focusProxy = createFocusProxy();
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 setIconHints(java.util.List<XIconInfo> icons) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        if (!XWM.getWM().setNetWMIcon(this, icons)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            if (icons.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                if (iconWindow == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                    iconWindow = new XIconWindow(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                iconWindow.setIconImages(icons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            }
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
    public void updateMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        super.updateMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        updateMinSizeHints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    private void updateMinSizeHints() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        if (isResizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            Dimension minimumSize = getTargetMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            if (minimumSize != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                Insets insets = getRealInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                int minWidth = minimumSize.width - insets.left - insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                int minHeight = minimumSize.height - insets.top - insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                if (minWidth < 0) minWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                if (minHeight < 0) minHeight = 0;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
   134
                setSizeHints(XUtilConstants.PMinSize | (isLocationByPlatform()?0:(XUtilConstants.PPosition | XUtilConstants.USPosition)),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                             getX(), getY(), minWidth, minHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                if (isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                    Rectangle bounds = getShellBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                    int nw = (bounds.width < minWidth) ? minWidth : bounds.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                    int nh = (bounds.height < minHeight) ? minHeight : bounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                    if (nw != bounds.width || nh != bounds.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                        setShellSize(new Rectangle(0, 0, nw, nh));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                boolean isMinSizeSet = isMinSizeSet();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
   146
                XWM.removeSizeHints(this, XUtilConstants.PMinSize);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                /* Some WMs need remap to redecorate the window */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                if (isMinSizeSet && isShowing() && XWM.needRemap(this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                     * Do the re/mapping at the Xlib level.  Since we essentially
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                     * work around a WM bug we don't want this hack to be exposed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                     * to Intrinsics (i.e. don't mess with grabs, callbacks etc).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                    xSetVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                    XToolkit.XSync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                    xSetVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    XFocusProxyWindow createFocusProxy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        return new XFocusProxyWindow(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    protected XAtomList getWMProtocols() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        XAtomList protocols = super.getWMProtocols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        protocols.add(wm_delete_window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        protocols.add(wm_take_focus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        return protocols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public Graphics getGraphics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        return getGraphics(content.surfaceData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                           ComponentAccessor.getForeground(target),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                           ComponentAccessor.getBackground(target),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                           ComponentAccessor.getFont_NoClientCode(target));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public void setTitle(String title) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if (log.isLoggable(Level.FINE)) log.fine("Title is " + title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        winAttr.title = title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        updateWMName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    protected String getWMName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        if (winAttr.title == null || winAttr.title.trim().equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            return " ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            return winAttr.title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    void updateWMName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        super.updateWMName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        String name = getWMName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            if (name == null || name.trim().equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                name = "Java";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            XAtom iconNameAtom = XAtom.get(XAtom.XA_WM_ICON_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            iconNameAtom.setProperty(getWindow(), name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            XAtom netIconNameAtom = XAtom.get("_NET_WM_ICON_NAME");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            netIconNameAtom.setPropertyUTF8(getWindow(), name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public void handleIconify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        postEvent(new WindowEvent((Window)target, WindowEvent.WINDOW_ICONIFIED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    public void handleDeiconify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        postEvent(new WindowEvent((Window)target, WindowEvent.WINDOW_DEICONIFIED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public void handleFocusEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        super.handleFocusEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        XFocusChangeEvent xfe = xev.get_xfocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        // If we somehow received focus events forward it instead to proxy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        // FIXME: Shouldn't we instead check for inferrior?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        focusLog.finer("Received focus event on shell: " + xfe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
//         focusProxy.xRequestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
/***************************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
 *                             I N S E T S   C O D E
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
 **************************************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    protected boolean isInitialReshape() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    Insets difference(Insets i1, Insets i2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        return new Insets(i1.top-i2.top, i1.left - i2.left, i1.bottom-i2.bottom, i1.right-i2.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    void add(Insets i1, Insets i2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        i1.left += i2.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        i1.top += i2.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        i1.right += i2.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        i1.bottom += i2.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    boolean isNull(Insets i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        return (i == null) || ((i.left | i.top | i.right | i.bottom) == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    Insets copy(Insets i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        return new Insets(i.top, i.left, i.bottom, i.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    long reparent_serial = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public void handleReparentNotifyEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        XReparentEvent  xe = xev.get_xreparent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        if (insLog.isLoggable(Level.FINE)) insLog.fine(xe.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        reparent_serial = xe.get_serial();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            long root = XlibWrapper.RootWindow(XToolkit.getDisplay(), getScreenNumber());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            if (isEmbedded()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                setReparented(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                insets_corrected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            Component t = (Component)target;
115
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
   274
            if (getDecorations() == XWindowAttributesData.AWT_DECOR_NONE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                setReparented(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                insets_corrected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                reshape(dimensions, SET_SIZE, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            } else if (xe.get_parent() == root) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                configure_seen = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                insets_corrected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                 * We can be repareted to root for two reasons:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                 *   . setVisible(false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                 *   . WM exited
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                if (isVisible()) { /* WM exited */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                    /* Work around 4775545 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                    XWM.getWM().unshadeKludge(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                    insLog.fine("- WM exited");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                    insLog.fine(" - reparent due to hide");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            } else { /* reparented to WM frame, figure out our insets */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                setReparented(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                insets_corrected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                // Check if we have insets provided by the WM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                Insets correctWM = getWMSetInsets(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                if (correctWM != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                    insLog.log(Level.FINER, "wm-provided insets {0}", new Object[]{correctWM});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                    // If these insets are equal to our current insets - no actions are necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                    Insets dimInsets = dimensions.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                    if (correctWM.equals(dimInsets)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                        insLog.finer("Insets are the same as estimated - no additional reshapes necessary");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                        no_reparent_artifacts = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                        insets_corrected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                        applyGuessedInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                    correctWM = XWM.getWM().getInsets(this, xe.get_window(), xe.get_parent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                    if (correctWM != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                        insLog.log(Level.FINER, "correctWM {0}", new Object[] {correctWM});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                        insLog.log(Level.FINER, "correctWM insets are not available, waiting for configureNotify");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                if (correctWM != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    handleCorrectInsets(correctWM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    protected void handleCorrectInsets(Insets correctWM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
             * Ok, now see if we need adjust window size because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
             * initial insets were wrong (most likely they were).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            Insets correction = difference(correctWM, currentInsets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            insLog.log(Level.FINEST, "Corrention {0}", new Object[] {correction});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            if (!isNull(correction)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                 * Actual insets account for menubar/warning label,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                 * so we can't assign directly but must adjust them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                add(currentInsets, correction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                applyGuessedInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                //Fix for 6318109: PIT: Min Size is not honored properly when a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                //smaller size is specified in setSize(), XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                //update minimum size hints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                updateMinSizeHints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                 * If this window has been sized by a pack() we need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                 * to keep the interior geometry intact.  Since pack()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                 * computed width and height with wrong insets, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                 * must adjust the target dimensions appropriately.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            if (insLog.isLoggable(Level.FINER)) insLog.finer("Dimensions before reparent: " + dimensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            dimensions.setInsets(getRealInsets());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            insets_corrected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            if (isMaximized()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
   368
            if ((getHints().get_flags() & (XUtilConstants.USPosition | XUtilConstants.PPosition)) != 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                reshape(dimensions, SET_BOUNDS, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                reshape(dimensions, SET_SIZE, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    public void handleMoved(WindowDimensions dims) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        Point loc = dims.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        ComponentAccessor.setX((Component)target, loc.x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        ComponentAccessor.setY((Component)target, loc.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        postEvent(new ComponentEvent(target, ComponentEvent.COMPONENT_MOVED));
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
    protected Insets guessInsets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        if (isEmbedded()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            return new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            if (currentInsets.top > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                /* insets were set on wdata by System Properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                return copy(currentInsets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                Insets res = getWMSetInsets(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                if (res == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                    res = XWM.getWM().guessInsets(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    private void applyGuessedInsets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        Insets guessed = guessInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        currentInsets = copy(guessed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        insets = copy(currentInsets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    public void revalidate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        XToolkit.executeOnEventHandlerThread(target, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                    target.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                    target.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    Insets getRealInsets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        if (isNull(insets)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            applyGuessedInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    public Insets getInsets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        Insets in = copy(getRealInsets());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        in.top += getMenuBarHeight() + getWarningWindowHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        if (insLog.isLoggable(Level.FINEST)) insLog.log(Level.FINEST, "Get insets returns {0}", new Object[] {in});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        return in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    boolean gravityBug() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        return XWM.configureGravityBuggy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    // The height of area used to display current active input method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    int getInputMethodHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    void updateSizeHints(WindowDimensions dims) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        Rectangle rec = dims.getClientRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        checkShellRect(rec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        updateSizeHints(rec.x, rec.y, rec.width, rec.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    void updateSizeHints() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        updateSizeHints(dimensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    // Coordinates are that of the target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    // Called only on Toolkit thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    public void reshape(WindowDimensions newDimensions, int op,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                        boolean userReshape)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        if (insLog.isLoggable(Level.FINE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            insLog.fine("Reshaping " + this + " to " + newDimensions + " op " + op + " user reshape " + userReshape);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        }
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   459
        if (userReshape) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   460
            // We handle only userReshape == true cases. It means that
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   461
            // if the window manager or any other part of the windowing
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   462
            // system sets inappropriate size for this window, we can
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   463
            // do nothing but accept it.
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   464
            Rectangle reqBounds = newDimensions.getBounds();
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   465
            Rectangle newBounds = constrainBounds(reqBounds.x, reqBounds.y, reqBounds.width, reqBounds.height);
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   466
            newDimensions = new WindowDimensions(newBounds, newDimensions.getInsets(), newDimensions.isClientSizeSet());
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   467
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            if (!isReparented() || !isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                insLog.log(Level.FINE, "- not reparented({0}) or not visible({1}), default reshape",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                           new Object[] {Boolean.valueOf(isReparented()), Boolean.valueOf(visible)});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                // Fix for 6323293.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                // This actually is needed to preserve compatibility with previous releases -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                // some of licensees are expecting componentMoved event on invisible one while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                // its location changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                Point oldLocation = getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                Point newLocation = new Point(ComponentAccessor.getX((Component)target),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                                              ComponentAccessor.getY((Component)target));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                if (!newLocation.equals(oldLocation)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                    handleMoved(newDimensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                dimensions = new WindowDimensions(newDimensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                updateSizeHints(dimensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                Rectangle client = dimensions.getClientRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                checkShellRect(client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                setShellBounds(client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                if (content != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                    !content.getSize().equals(newDimensions.getSize()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                    reconfigureContentWindow(newDimensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            int wm = XWM.getWMID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            updateChildrenSizes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            applyGuessedInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            Rectangle shellRect = newDimensions.getClientRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            if (gravityBug()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                Insets in = newDimensions.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                shellRect.translate(in.left, in.top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            if ((op & NO_EMBEDDED_CHECK) == 0 && isEmbedded()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                shellRect.setLocation(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            checkShellRectSize(shellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            if (!isEmbedded()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                checkShellRectPos(shellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            op = op & ~NO_EMBEDDED_CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            if (op == SET_LOCATION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                setShellPosition(shellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            } else if (isResizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                if (op == SET_BOUNDS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                    setShellBounds(shellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                    setShellSize(shellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                XWM.setShellNotResizable(this, newDimensions, shellRect, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                if (op == SET_BOUNDS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                    setShellPosition(shellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            reconfigureContentWindow(newDimensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * @param x, y, width, heith - dimensions of the window with insets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    private void reshape(int x, int y, int width, int height, int operation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                         boolean userReshape)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        Rectangle newRec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        boolean setClient = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        WindowDimensions dims = new WindowDimensions(dimensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        switch (operation & (~NO_EMBEDDED_CHECK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
          case SET_LOCATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
              // Set location always sets bounds location. However, until the window is mapped we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
              // should use client coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
              dims.setLocation(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
          case SET_SIZE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
              // Set size sets bounds size. However, until the window is mapped we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
              // should use client coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
              dims.setSize(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
          case SET_CLIENT_SIZE: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
              // Sets client rect size. Width and height contain insets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
              Insets in = currentInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
              width -= in.left+in.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
              height -= in.top+in.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
              dims.setClientSize(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
          case SET_BOUNDS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
              dims.setLocation(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
              dims.setSize(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        if (insLog.isLoggable(Level.FINE)) insLog.log(Level.FINE, "For the operation {0} new dimensions are {1}",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                                                      new Object[] {operationToString(operation), dims});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        reshape(dims, operation, userReshape);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   583
    // This method gets overriden in XFramePeer & XDialogPeer.
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   584
    abstract boolean isTargetUndecorated();
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   585
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   586
    @Override
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   587
    Rectangle constrainBounds(int x, int y, int width, int height) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   588
        // 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: 118
diff changeset
   589
        if (!hasWarningWindow()) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   590
            return new Rectangle(x, y, width, height);
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   591
        }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   592
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   593
        // If it's undecorated or is not currently visible,
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   594
        // apply the same constraints as for the Window.
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   595
        if (!isVisible() || isTargetUndecorated()) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   596
            return super.constrainBounds(x, y, width, height);
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   597
        }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   598
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   599
        // If it's visible & decorated, constraint the size only
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   600
        int newX = x;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   601
        int newY = y;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   602
        int newW = width;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   603
        int newH = height;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   604
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   605
        GraphicsConfiguration gc = ((Window)target).getGraphicsConfiguration();
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   606
        Rectangle sB = gc.getBounds();
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   607
        Insets sIn = ((Window)target).getToolkit().getScreenInsets(gc);
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   608
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   609
        Rectangle curBounds = getBounds();
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   610
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   611
        int maxW = Math.max(sB.width - sIn.left - sIn.right, curBounds.width);
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   612
        int maxH = Math.max(sB.height - sIn.top - sIn.bottom, curBounds.height);
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   613
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   614
        // 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: 118
diff changeset
   615
        if (newW > maxW) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   616
            newW = maxW;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   617
        }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   618
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   619
        if (newH > maxH) {
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   620
            newH = maxH;
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   621
        }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   622
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   623
        return new Rectangle(newX, newY, newW, newH);
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   624
    }
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 118
diff changeset
   625
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * @see java.awt.peer.ComponentPeer#setBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    public void setBounds(int x, int y, int width, int height, int op) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        // TODO: Rewrite with WindowDimensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        reshape(x, y, width, height, op, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        validateSurface();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    // Coordinates are that of the shell
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    void reconfigureContentWindow(WindowDimensions dims) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        if (content == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            insLog.fine("WARNING: Content window is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        content.setContentBounds(dims);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    boolean no_reparent_artifacts = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    public void handleConfigureNotifyEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        assert (SunToolkit.isAWTLockHeldByCurrentThread());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        XConfigureEvent xe = xev.get_xconfigure();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        insLog.log(Level.FINE, "Configure notify {0}", new Object[] {xe});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        // XXX: should really only consider synthetic events, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        if (isReparented()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            configure_seen = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        if (!isMaximized()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            && (xe.get_serial() == reparent_serial || xe.get_window() != getShell())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            && !no_reparent_artifacts)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            insLog.fine("- reparent artifact, skipping");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        no_reparent_artifacts = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
         * When there is a WM we receive some CN before being visible and after.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
         * We should skip all CN which are before being visible, because we assume
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
         * the gravity is in action while it is not yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
         * When there is no WM we receive CN only _before_ being visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
         * We should process these CNs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        if (!isVisible() && XWM.getWMID() != XWM.NO_WM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            insLog.fine(" - not visible, skipping");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
         * Some window managers configure before we are reparented and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
         * the send event flag is set! ugh... (Enlighetenment for one,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
         * possibly MWM as well).  If we haven't been reparented yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
         * this is just the WM shuffling us into position.  Ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
         * it!!!! or we wind up in a bogus location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        int runningWM = XWM.getWMID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        if (insLog.isLoggable(Level.FINE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            insLog.log(Level.FINE, "reparented={0}, visible={1}, WM={2}, decorations={3}",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                    new Object[] {isReparented(), isVisible(), runningWM, getDecorations()});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        if (!isReparented() && isVisible() && runningWM != XWM.NO_WM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                &&  !XWM.isNonReparentingWM()
115
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
   691
                && getDecorations() != XWindowAttributesData.AWT_DECOR_NONE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            insLog.fine("- visible but not reparented, skipping");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        //Last chance to correct insets
115
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
   696
        if (!insets_corrected && getDecorations() != XWindowAttributesData.AWT_DECOR_NONE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            long parent = XlibUtil.getParentWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            Insets correctWM = (parent != -1) ? XWM.getWM().getInsets(this, window, parent) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            if (insLog.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                if (correctWM != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                    insLog.finer("Configure notify - insets : " + correctWM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                    insLog.finer("Configure notify - insets are still not available");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            if (correctWM != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                handleCorrectInsets(correctWM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                //Only one attempt to correct insets is made (to lower risk)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                //if insets are still not available we simply set the flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                insets_corrected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        updateChildrenSizes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        // Bounds of the window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        Rectangle targetBounds = new Rectangle(ComponentAccessor.getX((Component)target),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                ComponentAccessor.getY((Component)target),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                ComponentAccessor.getWidth((Component)target),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                ComponentAccessor.getHeight((Component)target));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        Point newLocation = targetBounds.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        if (xe.get_send_event() || runningWM == XWM.NO_WM || XWM.isNonReparentingWM()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            // Location, Client size + insets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            newLocation = new Point(xe.get_x() - currentInsets.left, xe.get_y() - currentInsets.top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            // CDE/MWM/Metacity/Sawfish bug: if shell is resized using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            // top or left border, we don't receive synthetic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            // ConfigureNotify, only the one from X with zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            // coordinates.  This is the workaround to get real
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            // location, 6261336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            switch (XWM.getWMID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                case XWM.CDE_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                case XWM.MOTIF_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                case XWM.METACITY_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                case XWM.SAWFISH_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                    Point xlocation = queryXLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                    if (log.isLoggable(Level.FINE)) log.log(Level.FINE, "New X location: {0}", new Object[]{xlocation});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                    if (xlocation != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                        newLocation = xlocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        WindowDimensions newDimensions =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                new WindowDimensions(newLocation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                new Dimension(xe.get_width(), xe.get_height()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                copy(currentInsets),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        insLog.log(Level.FINER, "Insets are {0}, new dimensions {1}",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                new Object[] {currentInsets, newDimensions});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        checkIfOnNewScreen(newDimensions.getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        Point oldLocation = getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        dimensions = newDimensions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        if (!newLocation.equals(oldLocation)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            handleMoved(newDimensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        reconfigureContentWindow(newDimensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        updateChildrenSizes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    private void checkShellRectSize(Rectangle shellRect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        if (shellRect.width < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            shellRect.width = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        if (shellRect.height < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            shellRect.height = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    private void checkShellRectPos(Rectangle shellRect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        int wm = XWM.getWMID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        if (wm == XWM.MOTIF_WM || wm == XWM.CDE_WM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            if (shellRect.x == 0 && shellRect.y == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                shellRect.x = shellRect.y = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    private void checkShellRect(Rectangle shellRect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        checkShellRectSize(shellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        checkShellRectPos(shellRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    public void setShellBounds(Rectangle rec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        if (insLog.isLoggable(Level.FINE)) insLog.fine("Setting shell bounds on " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                                                       this + " to " + rec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            updateSizeHints(rec.x, rec.y, rec.width, rec.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            XlibWrapper.XResizeWindow(XToolkit.getDisplay(), getShell(), rec.width, rec.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            XlibWrapper.XMoveWindow(XToolkit.getDisplay(), getShell(), rec.x, rec.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    public void setShellSize(Rectangle rec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        if (insLog.isLoggable(Level.FINE)) insLog.fine("Setting shell size on " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                                                       this + " to " + rec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            updateSizeHints(rec.x, rec.y, rec.width, rec.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            XlibWrapper.XResizeWindow(XToolkit.getDisplay(), getShell(), rec.width, rec.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    public void setShellPosition(Rectangle rec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        if (insLog.isLoggable(Level.FINE)) insLog.fine("Setting shell position on " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                                                       this + " to " + rec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            updateSizeHints(rec.x, rec.y, rec.width, rec.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            XlibWrapper.XMoveWindow(XToolkit.getDisplay(), getShell(), rec.x, rec.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    void initResizability() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        setResizable(winAttr.initialResizability);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    public void setResizable(boolean resizable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        int fs = winAttr.functions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        if (!isResizable() && resizable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
            insets = currentInsets = new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            resetWMSetInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            if (!isEmbedded()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                setReparented(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            winAttr.isResizable = resizable;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
   844
            if ((fs & MWMConstants.MWM_FUNC_ALL) != 0) {
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
   845
                fs &= ~(MWMConstants.MWM_FUNC_RESIZE | MWMConstants.MWM_FUNC_MAXIMIZE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            } else {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
   847
                fs |= (MWMConstants.MWM_FUNC_RESIZE | MWMConstants.MWM_FUNC_MAXIMIZE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            winAttr.functions = fs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
            XWM.setShellResizable(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        } else if (isResizable() && !resizable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            insets = currentInsets = new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            resetWMSetInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            if (!isEmbedded()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                setReparented(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            winAttr.isResizable = resizable;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
   858
            if ((fs & MWMConstants.MWM_FUNC_ALL) != 0) {
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
   859
                fs |= (MWMConstants.MWM_FUNC_RESIZE | MWMConstants.MWM_FUNC_MAXIMIZE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            } else {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
   861
                fs &= ~(MWMConstants.MWM_FUNC_RESIZE | MWMConstants.MWM_FUNC_MAXIMIZE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
            winAttr.functions = fs;
118
35b334a806ab 6522731: Location of the frame changes,when the frame is resized & non-resized.
dcherepanov
parents: 115
diff changeset
   864
            XWM.setShellNotResizable(this, dimensions, dimensions.getBounds(), false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    Rectangle getShellBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        return dimensions.getClientRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        return dimensions.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    public Dimension getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        return dimensions.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    public int getX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        return dimensions.getLocation().x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    public int getY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        return dimensions.getLocation().y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    public Point getLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        return dimensions.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    public int getAbsoluteX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        // NOTE: returning this peer's location which is shell location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        return dimensions.getScreenBounds().x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    public int getAbsoluteY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        // NOTE: returning this peer's location which is shell location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        return dimensions.getScreenBounds().y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    public int getWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        return getSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    public int getHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        return getSize().height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
115
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
   910
    final public WindowDimensions getDimensions() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        return dimensions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    public Point getLocationOnScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            if (configure_seen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                return toGlobal(0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                Point location = target.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                if (insLog.isLoggable(Level.FINE))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                    insLog.log(Level.FINE, "getLocationOnScreen {0} not reparented: {1} ",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                               new Object[] {this, location});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                return location;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
/***************************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
 *              END            OF             I N S E T S   C O D E
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
 **************************************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
    protected boolean isEventDisabled(XEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        switch (e.get_type()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            // Do not generate MOVED/RESIZED events since we generate them by ourselves
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
   939
          case XConstants.ConfigureNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
              return true;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
   941
          case XConstants.EnterNotify:
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
   942
          case XConstants.LeaveNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
              // Disable crossing event on outer borders of Frame so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
              // we receive only one set of cross notifications(first set is from content window)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
              return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
              return super.isEventDisabled(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    int getDecorations() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        return winAttr.decorations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
    int getFunctions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        return winAttr.functions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
    public void setVisible(boolean vis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        log.log(Level.FINER, "Setting {0} to visible {1}", new Object[] {this, Boolean.valueOf(vis)});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        if (vis && !isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            XWM.setShellDecor(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            super.setVisible(vis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            if (winAttr.isResizable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                //Fix for 4320050: Minimum size for java.awt.Frame is not being enforced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                //We need to update frame's minimum size, not to reset it
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 420
diff changeset
   967
                XWM.removeSizeHints(this, XUtilConstants.PMaxSize);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                updateMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            super.setVisible(vis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    protected void suppressWmTakeFocus(boolean doSuppress) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        XAtomList protocols = getWMProtocols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        if (doSuppress) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            protocols.remove(wm_take_focus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            protocols.add(wm_take_focus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        wm_protocols.setAtomListProperty(this, protocols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        if (content != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            content.destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        focusProxy.destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        if (iconWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            iconWindow.destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        super.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    public void handleClientMessage(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        super.handleClientMessage(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        XClientMessageEvent cl = xev.get_xclient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        if ((wm_protocols != null) && (cl.get_message_type() == wm_protocols.getAtom())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            if (cl.get_data(0) == wm_delete_window.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                handleQuit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
            } else if (cl.get_data(0) == wm_take_focus.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                handleWmTakeFocus(cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        } else if (cl.get_message_type() == resize_request.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            reshape((int)cl.get_data(0), (int)cl.get_data(1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                    (int)cl.get_data(2), (int)cl.get_data(3),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                    (int)cl.get_data(4), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    private void handleWmTakeFocus(XClientMessageEvent cl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        focusLog.log(Level.FINE, "WM_TAKE_FOCUS on {0}", new Object[]{this});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        requestWindowFocus(cl.get_data(1), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * Requests focus to this decorated top-level by requesting X input focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * to the shell window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    protected void requestXFocus(long time, boolean timeProvided) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        // We have proxied focus mechanism - instead of shell the focus is held
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        // by "proxy" - invisible mapped window. When we want to set X input focus to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        // toplevel set it on proxy instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        if (focusProxy == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
            if (focusLog.isLoggable(Level.FINE)) focusLog.warning("Focus proxy is null for " + this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            if (focusLog.isLoggable(Level.FINE)) focusLog.fine("Requesting focus to proxy: " + focusProxy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            if (timeProvided) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                focusProxy.xRequestFocus(time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                focusProxy.xRequestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    XFocusProxyWindow getFocusProxy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        return focusProxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
    public void handleQuit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        postEvent(new WindowEvent((Window)target, WindowEvent.WINDOW_CLOSING));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
    final void dumpMe() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        System.err.println(">>> Peer: " + x + ", " + y + ", " + width + ", " + height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
    final void dumpTarget() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        int getWidth = ComponentAccessor.getWidth((Component)target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        int getHeight = ComponentAccessor.getHeight((Component)target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        int getTargetX = ComponentAccessor.getX((Component)target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        int getTargetY = ComponentAccessor.getY((Component)target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        System.err.println(">>> Target: " + getTargetX + ", " + getTargetY + ", " + getWidth + ", " + getHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
    final void dumpShell() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        dumpWindow("Shell", getShell());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    final void dumpContent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
        dumpWindow("Content", getContentWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
    final void dumpParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        long parent = XlibUtil.getParentWindow(getShell());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        if (parent != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
            dumpWindow("Parent", parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
            System.err.println(">>> NO PARENT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
    final void dumpWindow(String id, long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        XWindowAttributes pattr = new XWindowAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                int status =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                    XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                                                     window, pattr.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            System.err.println(">>>> " + id + ": " + pattr.get_x()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                               + ", " + pattr.get_y() + ", " + pattr.get_width()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                               + ", " + pattr.get_height());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            pattr.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
    final void dumpAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        dumpTarget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        dumpMe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        dumpParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        dumpShell();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        dumpContent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
    boolean isMaximized() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
    boolean isOverrideRedirect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
    public boolean requestWindowFocus(long time, boolean timeProvided) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        focusLog.fine("Request for decorated window focus");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        // If this is Frame or Dialog we can't assure focus request success - but we still can try
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        // If this is Window and its owner Frame is active we can be sure request succedded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
        Window focusedWindow = XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        Window activeWindow = XWindowPeer.getDecoratedOwner(focusedWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        focusLog.log(Level.FINER, "Current window is: active={0}, focused={1}",
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1121
                     new Object[]{ Boolean.valueOf(target == activeWindow),
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1122
                                   Boolean.valueOf(target == focusedWindow)});
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        XWindowPeer toFocus = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        while (toFocus.nextTransientFor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
            toFocus = toFocus.nextTransientFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        }
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1128
        if (toFocus == null || !toFocus.focusAllowedFor()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
            // This might change when WM will have property to determine focus policy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
            // Right now, because policy is unknown we can't be sure we succedded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        }
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1133
        if (this == toFocus) {
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1134
            if (isWMStateNetHidden()) {
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1135
                focusLog.fine("The window is unmapped, so rejecting the request");
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1136
                return false;
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1137
            }
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1138
            if (target == activeWindow && target != focusedWindow) {
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1139
                // Happens when an owned window is currently focused
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1140
                focusLog.fine("Focus is on child window - transfering it back to the owner");
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1141
                handleWindowFocusInSync(-1);
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1142
                return true;
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1143
            }
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1144
            Window realNativeFocusedWindow = XWindowPeer.getNativeFocusedWindow();
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1145
            focusLog.finest("Real native focused window: " + realNativeFocusedWindow +
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1146
                            "\nKFM's focused window: " + focusedWindow);
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1147
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1148
            // See 6522725, 6613426.
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1149
            if (target == realNativeFocusedWindow) {
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1150
                focusLog.fine("The window is already natively focused.");
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1151
                return true;
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1152
            }
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1153
        }
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1154
        focusLog.fine("Requesting focus to " + (this == toFocus ? "this window" : toFocus));
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1155
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1156
        if (timeProvided) {
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1157
            toFocus.requestXFocus(time);
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1158
        } else {
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1159
            toFocus.requestXFocus();
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1160
        }
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
  1161
        return (this == toFocus);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
    XWindowPeer actualFocusedWindow = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
    void setActualFocusedWindow(XWindowPeer actualFocusedWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
        synchronized(getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
            this.actualFocusedWindow = actualFocusedWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
    boolean requestWindowFocus(XWindowPeer actualFocusedWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                               long time, boolean timeProvided)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        setActualFocusedWindow(actualFocusedWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        return requestWindowFocus(time, timeProvided);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
    public void handleWindowFocusIn(long serial) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
        if (null == actualFocusedWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
            super.handleWindowFocusIn(serial);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
             * Fix for 6314575.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
             * If this is a result of clicking on one of the Frame's component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
             * then 'actualFocusedWindow' shouldn't be focused. A decision of focusing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
             * it or not should be made after the appropriate Java mouse event (if any)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
             * is handled by the component where 'actualFocusedWindow' value may be reset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
             * The fix is based on the empiric fact consisting in that the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
             * receives native mouse event nearly at the same time the Frame receives
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
             * WM_TAKE_FOCUS (when FocusIn is generated via XSetInputFocus call) but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
             * definetely before the Frame gets FocusIn event (when this method is called).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
            postEvent(new InvocationEvent(target, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
                    XWindowPeer fw = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
                    synchronized (getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
                        fw = actualFocusedWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                        actualFocusedWindow = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
                        if (null == fw || !fw.isVisible() || !fw.isFocusableWindow()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
                            fw = XDecoratedPeer.this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
                    fw.handleWindowFocusIn_Dispatch();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            }));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
    public void handleWindowFocusOut(Window oppositeWindow, long serial) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
        Window actualFocusedWindow = XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        // If the actual focused window is not this decorated window then retain it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        if (actualFocusedWindow != null && actualFocusedWindow != target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            Window owner = XWindowPeer.getDecoratedOwner(actualFocusedWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
            if (owner != null && owner == target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                setActualFocusedWindow((XWindowPeer) ComponentAccessor.getPeer(actualFocusedWindow));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        super.handleWindowFocusOut(oppositeWindow, serial);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
    private Point queryXLocation()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        return XlibUtil.translateCoordinates(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
            getContentWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
            XlibWrapper.RootWindow(XToolkit.getDisplay(), getScreenNumber()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
            new Point(0, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
}