jdk/src/solaris/classes/sun/awt/X11/XCanvasPeer.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.ComponentAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.awt.X11GraphicsConfig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.awt.X11GraphicsDevice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
class XCanvasPeer extends XComponentPeer implements CanvasPeer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    private boolean eraseBackgroundDisabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    XCanvasPeer() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    XCanvasPeer(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        super(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    XCanvasPeer(Component target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        super(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    void preInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        super.preInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        if (SunToolkit.getSunAwtNoerasebackground()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            disableBackgroundErase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    void resetTargetGC(Component target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        ComponentAccessor.resetGC(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * Called when the Window this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * Canvas is on is moved onto another Xinerama screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Canvases can be created with a non-defulat GraphicsConfiguration.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * GraphicsConfiguration needs to be changed to one on the new screen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * preferably with the same visual ID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * Up-called for other windows peer instances (XPanelPeer, XWindowPeer).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Should only be called from the event thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public void displayChanged(int screenNum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        resetLocalGC(screenNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        resetTargetGC(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /* Set graphicsConfig to a GraphicsConfig with the same visual on the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * screen, which should be easy in Xinerama mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Should only be called from displayChanged(), and therefore only from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * the event thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    void resetLocalGC(int screenNum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        // Opt: Only need to do if we're not using the default GC
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        if (graphicsConfig != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            X11GraphicsConfig parentgc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            // save vis id of current gc
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            int visual = graphicsConfig.getVisual();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            X11GraphicsDevice newDev = (X11GraphicsDevice) GraphicsEnvironment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                getLocalGraphicsEnvironment().
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                getScreenDevices()[screenNum];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            for (int i = 0; i < newDev.getNumConfigs(screenNum); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                if (visual == newDev.getConfigVisualId(i, screenNum)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                    // use that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                    graphicsConfig = (X11GraphicsConfig)newDev.getConfigurations()[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            // just in case...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            if (graphicsConfig == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                graphicsConfig = (X11GraphicsConfig) GraphicsEnvironment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                    getLocalGraphicsEnvironment().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                    getScreenDevices()[screenNum].
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                    getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    protected boolean shouldFocusOnClick() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        // Canvas should always be able to be focused by mouse clicks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public void disableBackgroundErase() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        eraseBackgroundDisabled = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    protected boolean doEraseBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return !eraseBackgroundDisabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        boolean doRepaint = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        if( getPeerBackground() == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
           !getPeerBackground().equals( c ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            doRepaint = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        super.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        if( doRepaint ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            target.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
}