001: /*
002: * Copyright 1995-2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025: package sun.awt.motif;
026:
027: import java.awt.*;
028: import java.awt.peer.*;
029: import sun.awt.DisplayChangedListener;
030: import sun.awt.X11GraphicsConfig;
031: import sun.awt.X11GraphicsDevice;
032: import sun.awt.X11GraphicsEnvironment;
033:
034: class MCanvasPeer extends MComponentPeer implements CanvasPeer,
035: DisplayChangedListener {
036:
037: native void create(MComponentPeer parent);
038:
039: private static native void initIDs();
040:
041: static {
042: initIDs();
043: }
044:
045: MCanvasPeer() {
046: }
047:
048: MCanvasPeer(Component target) {
049: super (target);
050: }
051:
052: MCanvasPeer(Component target, Object arg) {
053: super (target, arg);
054: }
055:
056: /* --- DisplayChangedListener Stuff --- */
057: public void displayChanged() {
058: }
059:
060: public void paletteChanged() {
061: }
062:
063: native void resetTargetGC(Component target);
064:
065: /*
066: * Called when the Window this
067: * Canvas is on is moved onto another Xinerama screen.
068: *
069: * Canvases can be created with a non-defulat GraphicsConfiguration. The
070: * GraphicsConfiguration needs to be changed to one on the new screen,
071: * preferably with the same visual ID.
072: *
073: * Up-called for other windows peer instances (WPanelPeer, WWindowPeer).
074: *
075: * Should only be called from the event thread.
076: */
077: public void displayChanged(int screenNum) {
078: resetLocalGC(screenNum);
079: resetTargetGC(target); /* call Canvas.setGCFromPeer() via native */
080: }
081:
082: /* Set graphicsConfig to a GraphicsConfig with the same visual on the new
083: * screen, which should be easy in Xinerama mode.
084: *
085: * Should only be called from displayChanged(), and therefore only from
086: * the event thread.
087: */
088: void resetLocalGC(int screenNum) {
089: // Opt: Only need to do if we're not using the default GC
090: if (graphicsConfig != null) {
091: X11GraphicsConfig parentgc;
092: // save vis id of current gc
093: int visual = graphicsConfig.getVisual();
094:
095: X11GraphicsDevice newDev = (X11GraphicsDevice) GraphicsEnvironment
096: .getLocalGraphicsEnvironment().getScreenDevices()[screenNum];
097:
098: for (int i = 0; i < newDev.getNumConfigs(screenNum); i++) {
099: if (visual == newDev.getConfigVisualId(i, screenNum)) {
100: // use that
101: graphicsConfig = (X11GraphicsConfig) newDev
102: .getConfigurations()[i];
103: break;
104: }
105: }
106: // just in case...
107: if (graphicsConfig == null) {
108: graphicsConfig = (X11GraphicsConfig) GraphicsEnvironment
109: .getLocalGraphicsEnvironment()
110: .getScreenDevices()[screenNum]
111: .getDefaultConfiguration();
112: }
113: }
114: }
115:
116: protected boolean shouldFocusOnClick() {
117: // Canvas should always be able to be focused by mouse clicks.
118: return true;
119: }
120: }
|