jdk/src/macosx/classes/sun/lwawt/LWContainerPeer.java
author mcherkas
Mon, 28 Jul 2014 16:09:26 +0400
changeset 26008 ccab11700f07
parent 20153 d5bf90bfcb6d
permissions -rw-r--r--
8047288: Fixes endless loop on mac caused by invoking Windows.isFocusable() on Appkit thread. Reviewed-by: ant, pchelko Contributed-by: artem.malinko@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     1
/*
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
     2
 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     4
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    10
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    15
 * accompanied this code).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    16
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    20
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    23
 * questions.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    24
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    25
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    26
package sun.lwawt;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    27
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    28
import sun.awt.SunGraphicsCallback;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    29
import sun.java2d.pipe.Region;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    30
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    31
import java.awt.Color;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    32
import java.awt.Container;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    33
import java.awt.Font;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    34
import java.awt.Graphics;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    35
import java.awt.Insets;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    36
import java.awt.Rectangle;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    37
import java.awt.peer.ContainerPeer;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    38
import java.util.LinkedList;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    39
import java.util.List;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    40
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    41
import javax.swing.JComponent;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    42
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    43
abstract class LWContainerPeer<T extends Container, D extends JComponent>
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
    44
        extends LWCanvasPeer<T, D> implements ContainerPeer {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    45
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
    46
    /**
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
    47
     * List of child peers sorted by z-order from bottom-most to top-most.
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
    48
     */
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
    49
    private final List<LWComponentPeer<?, ?>> childPeers = new LinkedList<>();
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
    50
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
    51
    LWContainerPeer(final T target, final PlatformComponent platformComponent) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    52
        super(target, platformComponent);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    53
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    54
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
    55
    final void addChildPeer(final LWComponentPeer<?, ?> child) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    56
        synchronized (getPeerTreeLock()) {
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
    57
            childPeers.add(childPeers.size(), child);
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
    58
            // TODO: repaint
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    59
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    60
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    61
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
    62
    final void removeChildPeer(final LWComponentPeer<?, ?> child) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    63
        synchronized (getPeerTreeLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    64
            childPeers.remove(child);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    65
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    66
        // TODO: repaint
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    67
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    68
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    69
    // Used by LWComponentPeer.setZOrder()
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
    70
    final void setChildPeerZOrder(final LWComponentPeer<?, ?> peer,
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
    71
                                  final LWComponentPeer<?, ?> above) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    72
        synchronized (getPeerTreeLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    73
            childPeers.remove(peer);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    74
            int index = (above != null) ? childPeers.indexOf(above) : childPeers.size();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    75
            if (index >= 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    76
                childPeers.add(index, peer);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    77
            } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    78
                // TODO: log
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    79
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    80
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    81
        // TODO: repaint
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    82
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    83
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    84
    // ---- PEER METHODS ---- //
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    85
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    86
    /*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    87
     * Overridden in LWWindowPeer.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    88
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    89
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    90
    public Insets getInsets() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    91
        return new Insets(0, 0, 0, 0);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    92
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    93
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    94
    @Override
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
    95
    public final void beginValidate() {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    96
        // TODO: it seems that begin/endValidate() is only useful
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    97
        // for heavyweight windows, when a batch movement for
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    98
        // child windows  occurs. That's why no-op
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    99
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   100
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   101
    @Override
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   102
    public final void endValidate() {
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   103
        // TODO: it seems that begin/endValidate() is only useful
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   104
        // for heavyweight windows, when a batch movement for
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   105
        // child windows  occurs. That's why no-op
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   106
    }
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   107
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   108
    @Override
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   109
    public final void beginLayout() {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   110
        // Skip all painting till endLayout()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   111
        setLayouting(true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   112
    }
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   113
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   114
    @Override
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   115
    public final void endLayout() {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   116
        setLayouting(false);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   117
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   118
        // Post an empty event to flush all the pending target paints
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   119
        postPaintEvent(0, 0, 0, 0);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   120
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   121
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   122
    // ---- PEER NOTIFICATIONS ---- //
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   123
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   124
    /**
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   125
     * Returns a copy of the childPeer collection.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   126
     */
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   127
    @SuppressWarnings("unchecked")
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   128
    final List<LWComponentPeer<?, ?>> getChildren() {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   129
        synchronized (getPeerTreeLock()) {
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   130
            Object copy = ((LinkedList<?>) childPeers).clone();
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   131
            return (List<LWComponentPeer<?, ?>>) copy;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   132
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   133
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   134
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   135
    @Override
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   136
    final Region getVisibleRegion() {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   137
        return cutChildren(super.getVisibleRegion(), null);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   138
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   139
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   140
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   141
     * Removes bounds of children above specific child from the region. If above
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   142
     * is null removes all bounds of children.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   143
     */
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   144
    final Region cutChildren(Region r, final LWComponentPeer<?, ?> above) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   145
        boolean aboveFound = above == null;
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   146
        for (final LWComponentPeer<?, ?> child : getChildren()) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   147
            if (!aboveFound && child == above) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   148
                aboveFound = true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   149
                continue;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   150
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   151
            if (aboveFound) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   152
                if(child.isVisible()){
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   153
                    final Rectangle cb = child.getBounds();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   154
                    final Region cr = child.getRegion();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   155
                    final Region tr = cr.getTranslatedRegion(cb.x, cb.y);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   156
                    r = r.getDifference(tr.getIntersection(getContentSize()));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   157
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   158
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   159
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   160
        return r;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   161
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   162
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   163
    // ---- UTILITY METHODS ---- //
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   164
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   165
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   166
     * Finds a top-most visible component for the given point. The location is
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   167
     * specified relative to the peer's parent.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   168
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   169
    @Override
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   170
    final LWComponentPeer<?, ?> findPeerAt(int x, int y) {
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   171
        LWComponentPeer<?, ?> peer = super.findPeerAt(x, y);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   172
        final Rectangle r = getBounds();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   173
        // Translate to this container's coordinates to pass to children
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   174
        x -= r.x;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   175
        y -= r.y;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   176
        if (peer != null && getContentSize().contains(x, y)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   177
            synchronized (getPeerTreeLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   178
                for (int i = childPeers.size() - 1; i >= 0; --i) {
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   179
                    LWComponentPeer<?, ?> p = childPeers.get(i).findPeerAt(x, y);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   180
                    if (p != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   181
                        peer = p;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   182
                        break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   183
                    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   184
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   185
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   186
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   187
        return peer;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   188
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   189
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   190
    /*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   191
    * Called by the container when any part of this peer or child
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   192
    * peers should be repainted
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   193
    */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   194
    @Override
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   195
    final void repaintPeer(final Rectangle r) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   196
        final Rectangle toPaint = getSize().intersection(r);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   197
        if (!isShowing() || toPaint.isEmpty()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   198
            return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   199
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   200
        // First, post the PaintEvent for this peer
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   201
        super.repaintPeer(toPaint);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   202
        // Second, handle all the children
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   203
        // Use the straight order of children, so the bottom
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   204
        // ones are painted first
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   205
        repaintChildren(toPaint);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   206
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   207
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   208
    /**
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   209
     * Paints all the child peers in the straight z-order, so the
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   210
     * bottom-most ones are painted first.
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   211
     */
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   212
    private void repaintChildren(final Rectangle r) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   213
        final Rectangle content = getContentSize();
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   214
        for (final LWComponentPeer<?, ?> child : getChildren()) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   215
            final Rectangle childBounds = child.getBounds();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   216
            Rectangle toPaint = r.intersection(childBounds);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   217
            toPaint = toPaint.intersection(content);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   218
            toPaint.translate(-childBounds.x, -childBounds.y);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   219
            child.repaintPeer(toPaint);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   220
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   221
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   222
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   223
    Rectangle getContentSize() {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   224
        return getSize();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   225
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   226
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   227
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   228
    public void setEnabled(final boolean e) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   229
        super.setEnabled(e);
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   230
        for (final LWComponentPeer<?, ?> child : getChildren()) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   231
            child.setEnabled(e && child.getTarget().isEnabled());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   232
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   233
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   234
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   235
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   236
    public void setBackground(final Color c) {
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   237
        for (final LWComponentPeer<?, ?> child : getChildren()) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   238
            if (!child.getTarget().isBackgroundSet()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   239
                child.setBackground(c);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   240
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   241
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   242
        super.setBackground(c);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   243
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   244
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   245
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   246
    public void setForeground(final Color c) {
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   247
        for (final LWComponentPeer<?, ?> child : getChildren()) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   248
            if (!child.getTarget().isForegroundSet()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   249
                child.setForeground(c);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   250
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   251
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   252
        super.setForeground(c);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   253
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   254
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   255
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   256
    public void setFont(final Font f) {
20153
d5bf90bfcb6d 8005255: [macosx] Cleanup warnings in sun.lwawt
serb
parents: 13993
diff changeset
   257
        for (final LWComponentPeer<?, ?> child : getChildren()) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   258
            if (!child.getTarget().isFontSet()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   259
                child.setFont(f);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   260
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   261
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   262
        super.setFont(f);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   263
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   264
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   265
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   266
    public final void paint(final Graphics g) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   267
        super.paint(g);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   268
        SunGraphicsCallback.PaintHeavyweightComponentsCallback.getInstance()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   269
                .runComponents(getTarget().getComponents(), g,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   270
                               SunGraphicsCallback.LIGHTWEIGHTS
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   271
                               | SunGraphicsCallback.HEAVYWEIGHTS);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   272
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   273
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   274
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   275
    public final void print(final Graphics g) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   276
        super.print(g);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   277
        SunGraphicsCallback.PrintHeavyweightComponentsCallback.getInstance()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   278
                .runComponents(getTarget().getComponents(), g,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   279
                               SunGraphicsCallback.LIGHTWEIGHTS
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   280
                               | SunGraphicsCallback.HEAVYWEIGHTS);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   281
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   282
}