jdk/src/solaris/classes/sun/awt/X11/XPanelPeer.java
author yan
Mon, 06 Oct 2008 16:45:00 +0400
changeset 1966 12a51fb0db0d
parent 2 90ce3da70b43
child 2459 08f3416ff334
permissions -rw-r--r--
5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif Summary: Does not work on Motif but works on XToolkit now; implemented using XQueryPointer. Reviewed-by: anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2002-2007 Sun Microsystems, Inc.  All Rights Reserved.
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
import java.awt.peer.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.awt.SunGraphicsCallback;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
public class XPanelPeer extends XCanvasPeer implements PanelPeer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    XEmbeddingContainer embedder = null; //new XEmbeddingContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
     * Embeds the given window into container using XEmbed protocol
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    public void xembed(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        if (embedder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
            embedder.add(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    XPanelPeer() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    XPanelPeer(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        super(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    XPanelPeer(Component target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        super(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    void postInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        super.postInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        if (embedder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            embedder.install(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public Insets getInsets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        return new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        super.paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        /*      SunGraphicsCallback.PaintHeavyweightComponentsCallback.getInstance().
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                runComponents(((Container)target).getComponents(), g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                SunGraphicsCallback.LIGHTWEIGHTS |
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                SunGraphicsCallback.HEAVYWEIGHTS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        */ }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public void print(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        super.print(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        SunGraphicsCallback.PrintHeavyweightComponentsCallback.getInstance().
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            runComponents(((Container)target).getComponents(), g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                          SunGraphicsCallback.LIGHTWEIGHTS |
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                          SunGraphicsCallback.HEAVYWEIGHTS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        Component comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        Container cont = (Container) target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        synchronized(target.getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            int n = cont.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            for(i=0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                comp = cont.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                ComponentPeer peer = comp.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                    Color color = comp.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                    if (color == null || color.equals(c)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                        peer.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        super.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public void setForeground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        setForegroundForHierarchy((Container) target, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private void setForegroundForHierarchy(Container cont, Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        synchronized(target.getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            int n = cont.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            for(int i=0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                Component comp = cont.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                Color color = comp.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                if (color == null || color.equals(c)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                    ComponentPeer cpeer = comp.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                    if (cpeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                        cpeer.setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                    if (cpeer instanceof LightweightPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                        && comp instanceof Container)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                        setForegroundForHierarchy((Container) comp, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                }
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * DEPRECATED:  Replaced by getInsets().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public Insets insets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        return getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * This method is called from XWindowPeer.displayChanged, when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * the window this Panel is on is moved to the new screen, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * display mode is changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * The notification is propagated to the child Canvas components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * Top-level windows and other Panels are notified too as their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * peers are subclasses of XCanvasPeer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public void displayChanged(int screenNum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        super.displayChanged(screenNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        displayChanged((Container)target, screenNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * Recursively iterates through all the HW and LW children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * of the container and calls displayChanged() for HW peers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Iteration through children peers only is not enough as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * displayChanged notification may not be propagated to HW
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * components inside LW containers, see 4452373 for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    private static void displayChanged(Container target, int screenNum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        Component children[] = ((Container)target).getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        for (Component child : children) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            ComponentPeer cpeer = child.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            if (cpeer instanceof XCanvasPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                ((XCanvasPeer)cpeer).displayChanged(screenNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            } else if (child instanceof Container) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                displayChanged((Container)child, screenNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (embedder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            embedder.deinstall();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        super.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    protected boolean shouldFocusOnClick() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        // Return false if this container has children so in that case it won't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        // be focused. Return true otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        return ((Container)target).getComponentCount() == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
}