jdk/src/solaris/classes/sun/awt/X11/XWindow.java
author son
Thu, 13 Mar 2008 17:08:15 +0300
changeset 116 9c43d9eb1029
parent 2 90ce3da70b43
child 439 3488710b02f8
permissions -rw-r--r--
6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont Summary: unnedded code has been removed. Added getter for XWindow.defaultFont to initialize it lazily. Reviewed-by: dav
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
116
9c43d9eb1029 6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents: 2
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.peer.ComponentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.image.ColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.lang.ref.WeakReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.lang.reflect.Field;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.logging.Level;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.logging.Logger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.awt.image.PixelConverter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import sun.java2d.SunGraphics2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import sun.java2d.SurfaceData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
public class XWindow extends XBaseWindow implements X11ComponentPeer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private static Logger log = Logger.getLogger("sun.awt.X11.XWindow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private static Logger insLog = Logger.getLogger("sun.awt.X11.insets.XWindow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static Logger eventLog = Logger.getLogger("sun.awt.X11.event.XWindow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private static final Logger focusLog = Logger.getLogger("sun.awt.X11.focus.XWindow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private static Logger keyEventLog = Logger.getLogger("sun.awt.X11.kye.XWindow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
  /* If a motion comes in while a multi-click is pending,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
   * allow a smudge factor so that moving the mouse by a small
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
   * amount does not wipe out the multi-click state variables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private final static int AWT_MULTICLICK_SMUDGE = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    // ButtonXXX events stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    static int rbutton = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    static int lastX = 0, lastY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    static long lastTime = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    static long lastButton = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    static WeakReference lastWindowRef = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    static int clickCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    // used to check if we need to re-create surfaceData.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    int oldWidth = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    int oldHeight = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    protected X11GraphicsConfig graphicsConfig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    protected AwtGraphicsConfigData graphicsConfigData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private boolean reparented;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    XWindow parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    Component target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private static int JAWT_LOCK_ERROR=0x00000001;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private static int JAWT_LOCK_CLIP_CHANGED=0x00000002;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private static int JAWT_LOCK_BOUNDS_CHANGED=0x00000004;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private static int JAWT_LOCK_SURFACE_CHANGED=0x00000008;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private int drawState = JAWT_LOCK_CLIP_CHANGED |
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    JAWT_LOCK_BOUNDS_CHANGED |
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    JAWT_LOCK_SURFACE_CHANGED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public static final String TARGET = "target",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        REPARENTED = "reparented"; // whether it is reparented by default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    SurfaceData surfaceData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    XRepaintArea paintArea;
116
9c43d9eb1029 6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents: 2
diff changeset
    95
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    // fallback default font object
116
9c43d9eb1029 6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents: 2
diff changeset
    97
    private static Font defaultFont;
9c43d9eb1029 6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents: 2
diff changeset
    98
9c43d9eb1029 6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents: 2
diff changeset
    99
    static synchronized Font getDefaultFont() {
9c43d9eb1029 6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents: 2
diff changeset
   100
        if (null == defaultFont) {
9c43d9eb1029 6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents: 2
diff changeset
   101
            defaultFont = new Font(Font.DIALOG, Font.PLAIN, 12);
9c43d9eb1029 6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents: 2
diff changeset
   102
        }
9c43d9eb1029 6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents: 2
diff changeset
   103
        return defaultFont;
9c43d9eb1029 6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents: 2
diff changeset
   104
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Keeps all buttons which were pressed at the time of the last mouse
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * drag until all buttons will be released, contains state as bit masks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * Button1Mask, Button2Mask, Button3Mask
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private int mouseDragState = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    native int getNativeColor(Color clr, GraphicsConfiguration gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    native void getWMInsets(long window, long left, long top, long right, long bottom, long border);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    native long getTopWindow(long window, long rootWin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    native void getWindowBounds(long window, long x, long y, long width, long height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    private native static void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private static Field isPostedField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    XWindow(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        super(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    XWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    XWindow(long parentWindow, Rectangle bounds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        super(new XCreateWindowParams(new Object[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            BOUNDS, bounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            PARENT_WINDOW, Long.valueOf(parentWindow)}));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    XWindow(Component target, long parentWindow, Rectangle bounds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        super(new XCreateWindowParams(new Object[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            BOUNDS, bounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            PARENT_WINDOW, Long.valueOf(parentWindow),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            TARGET, target}));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    XWindow(Component target, long parentWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        this(target, parentWindow, target.getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    XWindow(Component target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        this(target, (target.getParent() == null) ? 0 : getParentWindowID(target), target.getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    XWindow(Object target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        this(null, 0, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /* This create is used by the XEmbeddedFramePeer since it has to create the window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
       as a child of the netscape window. This netscape window is passed in as wid */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    XWindow(long parentWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        super(new XCreateWindowParams(new Object[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            PARENT_WINDOW, Long.valueOf(parentWindow),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            REPARENTED, Boolean.TRUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            EMBEDDED, Boolean.TRUE}));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    protected void initGraphicsConfiguration() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        graphicsConfig = (X11GraphicsConfig) target.getGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        graphicsConfigData = new AwtGraphicsConfigData(graphicsConfig.getAData());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    void preInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        super.preInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        reparented = Boolean.TRUE.equals(params.get(REPARENTED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        target = (Component)params.get(TARGET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        initGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        AwtGraphicsConfigData gData = getGraphicsConfigurationData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        X11GraphicsConfig config = (X11GraphicsConfig) getGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        XVisualInfo visInfo = gData.get_awt_visInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        params.putIfNull(EVENT_MASK, KeyPressMask | KeyReleaseMask
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            | FocusChangeMask | ButtonPressMask | ButtonReleaseMask
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            | EnterWindowMask | LeaveWindowMask | PointerMotionMask
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            | ButtonMotionMask | ExposureMask | StructureNotifyMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            params.putIfNull(BOUNDS, target.getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            params.putIfNull(BOUNDS, new Rectangle(0, 0, MIN_SIZE, MIN_SIZE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        params.putIfNull(BORDER_PIXEL, Long.valueOf(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        getColorModel(); // fix 4948833: this call forces the color map to be initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        params.putIfNull(COLORMAP, gData.get_awt_cmap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        params.putIfNull(DEPTH, gData.get_awt_depth());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        params.putIfNull(VISUAL_CLASS, Integer.valueOf((int)XlibWrapper.InputOutput));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        params.putIfNull(VISUAL, visInfo.get_visual());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        params.putIfNull(VALUE_MASK, XlibWrapper.CWBorderPixel | XlibWrapper.CWEventMask | XlibWrapper.CWColormap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        Long parentWindow = (Long)params.get(PARENT_WINDOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (parentWindow == null || parentWindow.longValue() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                int screen = visInfo.get_screen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                if (screen != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    params.add(PARENT_WINDOW, XlibWrapper.RootWindow(XToolkit.getDisplay(), screen));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                    params.add(PARENT_WINDOW, XToolkit.getDefaultRootWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        paintArea = new XRepaintArea();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            this.parent = getParentXWindowObject(target.getParent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        params.putIfNull(BACKING_STORE, XToolkit.getBackingStoreType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    void postInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        super.postInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        setWMClass(getWMClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        surfaceData = graphicsConfig.createSurfaceData(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        Color c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        if (target != null && (c = target.getBackground()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            // We need a version of setBackground that does not call repaint !!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            // and one that does not get overridden. The problem is that in postInit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            // we call setBackground and we dont have all the stuff initialized to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            // do a full paint for most peers. So we cannot call setBackground in postInit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            // instead we need to call xSetBackground.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            xSetBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public GraphicsConfiguration getGraphicsConfiguration() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        if (graphicsConfig == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            initGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        return graphicsConfig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    public AwtGraphicsConfigData getGraphicsConfigurationData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        if (graphicsConfigData == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            initGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        return graphicsConfigData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    protected String[] getWMClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return new String[] {XToolkit.getCorrectXIDString(getClass().getName()), XToolkit.getAWTAppClassName()};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    void setReparented(boolean newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        reparented = newValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    boolean isReparented() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        return reparented;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    static long getParentWindowID(Component target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        ComponentPeer peer = target.getParent().getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        Component temp = target.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        while (!(peer instanceof XWindow))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            temp = temp.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            peer = temp.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        if (peer != null && peer instanceof XWindow)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            return ((XWindow)peer).getContentWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        else return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    static XWindow getParentXWindowObject(Component target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        if (target == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        Component temp = target.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        if (temp == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        ComponentPeer peer = temp.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        if (peer == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        while ((peer != null) && !(peer instanceof XWindow))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            temp = temp.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            peer = temp.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        if (peer != null && peer instanceof XWindow)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            return (XWindow) peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        else return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    boolean isParentOf(XWindow win) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        if (!(target instanceof Container) || win == null || win.getTarget() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        Container parent = ComponentAccessor.getParent_NoClientCode(win.target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        while (parent != null && parent != target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            parent = ComponentAccessor.getParent_NoClientCode(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        return (parent == target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    public Object getTarget() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        return target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public Component getEventSource() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        return target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public ColorModel getColorModel(int transparency) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        return graphicsConfig.getColorModel (transparency);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    public ColorModel getColorModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        if (graphicsConfig != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            return graphicsConfig.getColorModel ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            return XToolkit.getStaticColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    Graphics getGraphics(SurfaceData surfData, Color afore, Color aback, Font afont) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        if (surfData == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        Component target = (Component) this.target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        /* Fix for bug 4746122. Color and Font shouldn't be null */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        Color bgColor = aback;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        if (bgColor == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            bgColor = SystemColor.window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        Color fgColor = afore;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        if (fgColor == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            fgColor = SystemColor.windowText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        Font font = afont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        if (font == null) {
116
9c43d9eb1029 6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents: 2
diff changeset
   344
            font = XWindow.getDefaultFont();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        return new SunGraphics2D(surfData, fgColor, bgColor, font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    public Graphics getGraphics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        return getGraphics(surfaceData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                           target.getForeground(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                           target.getBackground(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                           target.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    public FontMetrics getFontMetrics(Font font) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        return Toolkit.getDefaultToolkit().getFontMetrics(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    public Rectangle getTargetBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        return target.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * Returns true if the event has been handled and should not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * posted to Java.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    boolean prePostEvent(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    static Method m_sendMessage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    static void sendEvent(final AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        if (isPostedField == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            isPostedField = SunToolkit.getField(AWTEvent.class, "isPosted");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        PeerEvent pe = new PeerEvent(Toolkit.getDefaultToolkit(), new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                        isPostedField.setBoolean(e, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                    } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                        assert(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                    } catch (IllegalAccessException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                        assert(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                    ((Component)e.getSource()).dispatchEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            }, PeerEvent.ULTIMATE_PRIORITY_EVENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        if (focusLog.isLoggable(Level.FINER) && (e instanceof FocusEvent)) focusLog.finer("Sending " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        XToolkit.postEvent(XToolkit.targetToAppContext(e.getSource()), pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
 * Post an event to the event queue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
// NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
//       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    void postEvent(AWTEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        XToolkit.postEvent(XToolkit.targetToAppContext(event.getSource()), event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    static void postEventStatic(AWTEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        XToolkit.postEvent(XToolkit.targetToAppContext(event.getSource()), event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    public void postEventToEventQueue(final AWTEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        //fix for 6239938 : Choice drop-down does not disappear when it loses focus, on XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        if (!prePostEvent(event)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            //event hasn't been handled and must be posted to EventQueue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            postEvent(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    // overriden in XCanvasPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    protected boolean doEraseBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    // We need a version of setBackground that does not call repaint !!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    // and one that does not get overridden. The problem is that in postInit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    // we call setBackground and we dont have all the stuff initialized to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    // do a full paint for most peers. So we cannot call setBackground in postInit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    final public void xSetBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            winBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            // fix for 6558510: handle sun.awt.noerasebackground flag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            // see doEraseBackground() and preInit() methods in XCanvasPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            if (!doEraseBackground()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            // 6304250: XAWT: Items in choice show a blue border on OpenGL + Solaris10 when background color is set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            // Note: When OGL is enabled, surfaceData.pixelFor() will not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            // return a pixel value appropriate for passing to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            // XSetWindowBackground().  Therefore, we will use the ColorModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            // for this component in order to calculate a pixel value from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            // the given RGB value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            ColorModel cm = getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            int pixel = PixelConverter.instance.rgbToPixel(c.getRGB(), cm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            XlibWrapper.XSetWindowBackground(XToolkit.getDisplay(), getContentWindow(), pixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        xSetBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    Color backgroundColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    void winBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        backgroundColor = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    public Color getWinBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        Color c = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        if (backgroundColor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            c = backgroundColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        } else if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            c = parent.getWinBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        if (c instanceof SystemColor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            c = new Color(c.getRGB());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    public boolean isEmbedded() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        return embedded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    public  void repaint(int x,int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        if (!isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        Graphics g = getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        if (g != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                g.setClip(x,y,width,height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                g.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    public  void repaint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        if (!isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        Graphics g = getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        if (g != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                g.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    //used by Peers to avoid flickering withing paint()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    protected void flush(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            XlibWrapper.XFlush(XToolkit.getDisplay());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    public void popup(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        // TBD: grab the pointer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        xSetBounds(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    public void handleExposeEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        super.handleExposeEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        XExposeEvent xe = xev.get_xexpose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        if (isEventDisabled(xev)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        int x = xe.get_x();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        int y = xe.get_y();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        int w = xe.get_width();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        int h = xe.get_height();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        Component target = (Component)getEventSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        if (!ComponentAccessor.getIgnoreRepaint(target)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            && ComponentAccessor.getWidth(target) != 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            && ComponentAccessor.getHeight(target) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            handleExposeEvent(target, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    public void handleExposeEvent(Component target, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        PaintEvent event = PaintEventDispatcher.getPaintEventDispatcher().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            createPaintEvent(target, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        if (event != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            postEventToEventQueue(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    static int getModifiers(int state, int button, int keyCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        int modifiers = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        if (((state & XlibWrapper.ShiftMask) != 0) ^ (keyCode == KeyEvent.VK_SHIFT)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            modifiers |= InputEvent.SHIFT_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        if (((state & XlibWrapper.ControlMask) != 0) ^ (keyCode == KeyEvent.VK_CONTROL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            modifiers |= InputEvent.CTRL_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        if (((state & XToolkit.metaMask) != 0) ^ (keyCode == KeyEvent.VK_META)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            modifiers |= InputEvent.META_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        if (((state & XToolkit.altMask) != 0) ^ (keyCode == KeyEvent.VK_ALT)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            modifiers |= InputEvent.ALT_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        if (((state & XToolkit.modeSwitchMask) != 0) ^ (keyCode == KeyEvent.VK_ALT_GRAPH)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            modifiers |= InputEvent.ALT_GRAPH_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        if (((state & XlibWrapper.Button1Mask) != 0) ^ (button == MouseEvent.BUTTON1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            modifiers |= InputEvent.BUTTON1_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        if (((state & XlibWrapper.Button2Mask) != 0) ^ (button == MouseEvent.BUTTON2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            modifiers |= InputEvent.BUTTON2_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        if (((state & XlibWrapper.Button3Mask) != 0) ^ (button == MouseEvent.BUTTON3)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            modifiers |= InputEvent.BUTTON3_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        return modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    static int getXModifiers(AWTKeyStroke stroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        int mods = stroke.getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        int res = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        if ((mods & (InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK)) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            res |= XToolkit.ShiftMask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        if ((mods & (InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK)) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            res |= XToolkit.ControlMask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        if ((mods & (InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK)) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            res |= XToolkit.altMask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        if ((mods & (InputEvent.META_DOWN_MASK | InputEvent.META_MASK)) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            res |= XToolkit.metaMask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        if ((mods & (InputEvent.ALT_GRAPH_DOWN_MASK | InputEvent.ALT_GRAPH_MASK)) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            res |= XToolkit.modeSwitchMask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    private static int getButtonMask(long mouseButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        if (mouseButton == XlibWrapper.Button1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            return XlibWrapper.Button1Mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        } else if (mouseButton == XlibWrapper.Button2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            return XlibWrapper.Button2Mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        } else if (mouseButton == XlibWrapper.Button3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            return XlibWrapper.Button3Mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * Returns true if this event is disabled and shouldn't be passed to Java.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * Default implementation returns false for all events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    static int getRightButtonNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        if (rbutton == 0) { // not initialized yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                rbutton = XlibWrapper.XGetPointerMapping(XToolkit.getDisplay(), XlibWrapper.ibuffer, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        return rbutton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    static int getMouseMovementSmudge() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        //TODO: It's possible to read corresponding settings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        return AWT_MULTICLICK_SMUDGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    public void handleButtonPressRelease(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        super.handleButtonPressRelease(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        XButtonEvent xbe = xev.get_xbutton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        if (isEventDisabled(xev)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        if (eventLog.isLoggable(Level.FINE)) eventLog.fine(xbe.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        long when;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        int modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        boolean popupTrigger = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        int button=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        boolean wheel_mouse = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        long lbutton = xbe.get_button();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        int type = xev.get_type();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        when = xbe.get_time();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        long jWhen = XToolkit.nowMillisUTC_offset(when);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        int x = xbe.get_x();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        int y = xbe.get_y();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        if (xev.get_xany().get_window() != window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            Point localXY = toLocal(xbe.get_x_root(), xbe.get_y_root());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            x = localXY.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            y = localXY.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        if (type == XlibWrapper.ButtonPress) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            XWindow lastWindow = (lastWindowRef != null) ? ((XWindow)lastWindowRef.get()):(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
               multiclick checking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            if (eventLog.isLoggable(Level.FINEST)) eventLog.finest("lastWindow = " + lastWindow + ", lastButton "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                                                                   + lastButton + ", lastTime " + lastTime + ", multiClickTime "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                                                                   + XToolkit.getMultiClickTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            if (lastWindow == this && lastButton == lbutton && (when - lastTime) < XToolkit.getMultiClickTime()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                clickCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                clickCount = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                lastWindowRef = new WeakReference(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                lastButton = lbutton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                lastX = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                lastY = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            lastTime = when;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
               Check for popup trigger !!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            if (lbutton == getRightButtonNumber() || lbutton > 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                popupTrigger = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                popupTrigger = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        if (lbutton == XlibWrapper.Button1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            button = MouseEvent.BUTTON1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        else if (lbutton ==  XlibWrapper.Button2 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            button = MouseEvent.BUTTON2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        else if (lbutton == XlibWrapper.Button3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            button = MouseEvent.BUTTON3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        else if (lbutton == XlibWrapper.Button4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            button = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            wheel_mouse = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        } else if (lbutton == XlibWrapper.Button5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            button = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            wheel_mouse = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        modifiers = getModifiers(xbe.get_state(),button,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        if (!wheel_mouse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            MouseEvent me = new MouseEvent((Component)getEventSource(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                                           type == XlibWrapper.ButtonPress ? MouseEvent.MOUSE_PRESSED : MouseEvent.MOUSE_RELEASED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                                           jWhen,modifiers, x, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                                           xbe.get_x_root(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                                           xbe.get_y_root(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                                           clickCount,popupTrigger,button);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            postEventToEventQueue(me);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            if (((mouseDragState & getButtonMask(lbutton)) == 0) && // No up-button in the drag-state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                (type == XlibWrapper.ButtonRelease))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                postEventToEventQueue(me = new MouseEvent((Component)getEventSource(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                                                     MouseEvent.MOUSE_CLICKED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                                                     jWhen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                                                     modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                                                     x, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                                                     xbe.get_x_root(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                                                     xbe.get_y_root(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                                                     clickCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                                                     false, button));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            if (xev.get_type() == XlibWrapper.ButtonPress) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                MouseWheelEvent mwe = new MouseWheelEvent((Component)getEventSource(),MouseEvent.MOUSE_WHEEL, jWhen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                                                          modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                                                          x, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                                                          xbe.get_x_root(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                                                          xbe.get_y_root(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                                                          clickCount,false,MouseWheelEvent.WHEEL_UNIT_SCROLL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                                                          3,button==4 ?  -1 : 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                postEventToEventQueue(mwe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        mouseDragState &= ~getButtonMask(lbutton); // Exclude the up-button from the drag-state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    public void handleMotionNotify(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        super.handleMotionNotify(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        XMotionEvent xme = xev.get_xmotion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        if (isEventDisabled(xev)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        int mouseKeyState = (xme.get_state() & (Button1Mask | Button2Mask | Button3Mask));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        boolean isDragging = (mouseKeyState != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        int mouseEventType = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        if (isDragging) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            mouseEventType = MouseEvent.MOUSE_DRAGGED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            mouseEventType = MouseEvent.MOUSE_MOVED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
           Fix for 6176814 .  Add multiclick checking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        int x = xme.get_x();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        int y = xme.get_y();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        XWindow lastWindow = (lastWindowRef != null) ? ((XWindow)lastWindowRef.get()):(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        if (!(lastWindow == this &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
              (xme.get_time() - lastTime) < XToolkit.getMultiClickTime()  &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
              (Math.abs(lastX - x) < AWT_MULTICLICK_SMUDGE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
               Math.abs(lastY - y) < AWT_MULTICLICK_SMUDGE))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
          clickCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
          lastWindowRef = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
          mouseDragState = mouseKeyState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
          lastTime = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
          lastX = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
          lastY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        long jWhen = XToolkit.nowMillisUTC_offset(xme.get_time());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        int modifiers = getModifiers(xme.get_state(), 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        boolean popupTrigger = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        Component source = (Component)getEventSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        if (xme.get_window() != window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            Point localXY = toLocal(xme.get_x_root(), xme.get_y_root());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            x = localXY.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            y = localXY.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        /* Fix for 5039416.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
         * According to canvas.c we shouldn't post any MouseEvent if mouse is dragging and clickCount!=0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        if ((isDragging && clickCount == 0) || !isDragging) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            MouseEvent mme = new MouseEvent(source, mouseEventType, jWhen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                                            modifiers, x, y, xme.get_x_root(), xme.get_y_root(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                                            clickCount, popupTrigger, MouseEvent.NOBUTTON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            postEventToEventQueue(mme);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    // REMIND: need to implement looking for disabled events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    public native boolean x11inputMethodLookupString(long event, long [] keysymArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    native boolean haveCurrentX11InputMethodInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    public void handleXCrossingEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        super.handleXCrossingEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        XCrossingEvent xce = xev.get_xcrossing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        if (eventLog.isLoggable(Level.FINEST)) eventLog.finest(xce.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        // Skip event If it was caused by a grab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        // This is needed because on displays with focus-follows-mouse on MousePress X system generates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        // two XCrossing events with mode != NormalNotify. First of them notifies that the mouse has left
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        // current component. Second one notifies that it has entered into the same component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        // This looks like the window under the mouse has actually changed and Java handle these  events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        // accordingly. This leads to impossibility to make a double click on Component (6404708)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        XWindowPeer toplevel = getToplevelXWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        if (toplevel != null && !toplevel.isModalBlocked()){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            if (xce.get_mode() != NotifyNormal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                // 6404708 : need update cursor in accordance with skipping Leave/EnterNotify event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                // whereas it doesn't need to handled further.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                if (xce.get_type() == EnterNotify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                    XAwtState.setComponentMouseEntered(getEventSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                    XGlobalCursorManager.nativeUpdateCursor(getEventSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                } else { // LeaveNotify:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                    XAwtState.setComponentMouseEntered(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        // X sends XCrossing to all hierarchy so if the edge of child equals to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        // ancestor and mouse enters child, the ancestor will get an event too.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        // From java point the event is bogus as ancestor is obscured, so if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        // the child can get java event itself, we skip it on ancestor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        long childWnd = xce.get_subwindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        if (childWnd != None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            XBaseWindow child = XToolkit.windowToXWindow(childWnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            if (child != null && child instanceof XWindow &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                !child.isEventDisabled(xev))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        // Remember old component with mouse to have the opportunity to send it MOUSE_EXITED.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        final Component compWithMouse = XAwtState.getComponentMouseEntered();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        if (toplevel != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
            if(!toplevel.isModalBlocked()){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                if (xce.get_type() == EnterNotify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                    // Change XAwtState's component mouse entered to the up-to-date one before requesting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                    // to update the cursor since XAwtState.getComponentMouseEntered() is used when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                    // cursor is updated (in XGlobalCursorManager.findHeavyweightUnderCursor()).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                    XAwtState.setComponentMouseEntered(getEventSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                    XGlobalCursorManager.nativeUpdateCursor(getEventSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                } else { // LeaveNotify:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                    XAwtState.setComponentMouseEntered(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                ((XComponentPeer) ComponentAccessor.getPeer(target))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                    .pSetCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        if (isEventDisabled(xev)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        long jWhen = XToolkit.nowMillisUTC_offset(xce.get_time());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        int modifiers = getModifiers(xce.get_state(),0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        int clickCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        boolean popupTrigger = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        int x = xce.get_x();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        int y = xce.get_y();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        if (xce.get_window() != window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            Point localXY = toLocal(xce.get_x_root(), xce.get_y_root());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            x = localXY.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            y = localXY.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        // This code tracks boundary crossing and ensures MOUSE_ENTER/EXIT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        // are posted in alternate pairs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        if (compWithMouse != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            MouseEvent me = new MouseEvent(compWithMouse,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
                MouseEvent.MOUSE_EXITED, jWhen, modifiers, xce.get_x(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                xce.get_y(), xce.get_x_root(), xce.get_y_root(), clickCount, popupTrigger,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                MouseEvent.NOBUTTON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            postEventToEventQueue(me);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            eventLog.finest("Clearing last window ref");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            lastWindowRef = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        if (xce.get_type() == EnterNotify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            MouseEvent me = new MouseEvent(getEventSource(), MouseEvent.MOUSE_ENTERED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                jWhen, modifiers, xce.get_x(), xce.get_y(), xce.get_x_root(), xce.get_y_root(), clickCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                popupTrigger, MouseEvent.NOBUTTON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
            postEventToEventQueue(me);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        }
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 void doLayout(int x, int y, int width, int height) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    public void handleConfigureNotifyEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        Rectangle oldBounds = getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        super.handleConfigureNotifyEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        insLog.log(Level.FINER, "Configure, {0}, event disabled: {1}",
116
9c43d9eb1029 6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents: 2
diff changeset
   913
                   new Object[] {xev.get_xconfigure(), isEventDisabled(xev)});
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        if (isEventDisabled(xev)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
//  if ( Check if it's a resize, a move, or a stacking order change )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
//  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        Rectangle bounds = getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        if (!bounds.getSize().equals(oldBounds.getSize())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            postEventToEventQueue(new ComponentEvent(getEventSource(), ComponentEvent.COMPONENT_RESIZED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        if (!bounds.getLocation().equals(oldBounds.getLocation())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
            postEventToEventQueue(new ComponentEvent(getEventSource(), ComponentEvent.COMPONENT_MOVED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
//  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    public void handleMapNotifyEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        super.handleMapNotifyEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        log.log(Level.FINE, "Mapped {0}", new Object[] {this});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        if (isEventDisabled(xev)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        ComponentEvent ce;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        ce = new ComponentEvent(getEventSource(), ComponentEvent.COMPONENT_SHOWN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        postEventToEventQueue(ce);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
    public void handleUnmapNotifyEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        super.handleUnmapNotifyEvent(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        if (isEventDisabled(xev)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        ComponentEvent ce;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        ce = new ComponentEvent(target, ComponentEvent.COMPONENT_HIDDEN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        postEventToEventQueue(ce);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    private void dumpKeysymArray(XKeyEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        keyEventLog.fine("  "+Long.toHexString(XlibWrapper.XKeycodeToKeysym(XToolkit.getDisplay(), ev.get_keycode(), 0))+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                         "\n        "+Long.toHexString(XlibWrapper.XKeycodeToKeysym(XToolkit.getDisplay(), ev.get_keycode(), 1))+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                         "\n        "+Long.toHexString(XlibWrapper.XKeycodeToKeysym(XToolkit.getDisplay(), ev.get_keycode(), 2))+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                         "\n        "+Long.toHexString(XlibWrapper.XKeycodeToKeysym(XToolkit.getDisplay(), ev.get_keycode(), 3)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
       Return unicode character or 0 if no correspondent character found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
       Parameter is a keysym basically from keysymdef.h
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
       XXX: how about vendor keys? Is there some with Unicode value and not in the list?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
    char keysymToUnicode( long keysym, int state ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        return XKeysym.convertKeysym( keysym, state );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    int keyEventType2Id( int xEventType ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        return xEventType == XConstants.KeyPress ? java.awt.event.KeyEvent.KEY_PRESSED :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
               xEventType == XConstants.KeyRelease ? java.awt.event.KeyEvent.KEY_RELEASED : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
    static private long xkeycodeToKeysym(XKeyEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        return XKeysym.getKeysym( ev );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
    void logIncomingKeyEvent(XKeyEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        keyEventLog.fine("--XWindow.java:handleKeyEvent:"+ev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        dumpKeysymArray(ev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        keyEventLog.fine("XXXXXXXXXXXXXX javakeycode will be most probably:0x"+ Integer.toHexString(XKeysym.getJavaKeycodeOnly(ev)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
    public void handleKeyPress(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        super.handleKeyPress(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        XKeyEvent ev = xev.get_xkey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        if (eventLog.isLoggable(Level.FINE)) eventLog.fine(ev.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        if (isEventDisabled(xev)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        handleKeyPress(ev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    // called directly from this package, unlike handleKeyRelease.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    // un-final it if you need to override it in a subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
    final void handleKeyPress(XKeyEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        long keysym[] = new long[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        char unicodeKey = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        keysym[0] = NoSymbol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        if (keyEventLog.isLoggable(Level.FINE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            logIncomingKeyEvent( ev );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        if ( //TODO check if there's an active input method instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
             // without calling a native method. Is it necessary though?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            haveCurrentX11InputMethodInstance()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
            if (x11inputMethodLookupString(ev.pData, keysym)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                if (keyEventLog.isLoggable(Level.FINE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                    keyEventLog.fine("--XWindow.java XIM did process event; return; dec keysym processed:"+(keysym[0])+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                                   "; hex keysym processed:"+Long.toHexString(keysym[0])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                                   );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            }else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                unicodeKey = keysymToUnicode( keysym[0], ev.get_state() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                if (keyEventLog.isLoggable(Level.FINE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                    keyEventLog.fine("--XWindow.java XIM did NOT process event, hex keysym:"+Long.toHexString(keysym[0])+"\n"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                                     "                                         unicode key:"+Integer.toHexString((int)unicodeKey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        }else  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
            // No input method instance found. For example, there's a Java Input Method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            // Produce do-it-yourself keysym and perhaps unicode character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            keysym[0] = xkeycodeToKeysym(ev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            unicodeKey = keysymToUnicode( keysym[0], ev.get_state() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            if (keyEventLog.isLoggable(Level.FINE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                keyEventLog.fine("--XWindow.java XIM is absent;             hex keysym:"+Long.toHexString(keysym[0])+"\n"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                                 "                                         unicode key:"+Integer.toHexString((int)unicodeKey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        // Keysym should be converted to Unicode, if possible and necessary,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        // and Java KeyEvent keycode should be calculated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        // For press we should post pressed & typed Java events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        // Press event might be not processed to this time because
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        //  (1) either XIM could not handle it or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        //  (2) it was Latin 1:1 mapping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        XKeysym.Keysym2JavaKeycode jkc = XKeysym.getJavaKeycode(ev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        if( jkc == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            jkc = new XKeysym.Keysym2JavaKeycode(java.awt.event.KeyEvent.VK_UNDEFINED, java.awt.event.KeyEvent.KEY_LOCATION_UNKNOWN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        if (keyEventLog.isLoggable(Level.FINE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            keyEventLog.fine(">>>Fire Event:"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
               (ev.get_type() == XConstants.KeyPress ? "KEY_PRESSED; " : "KEY_RELEASED; ")+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
               "jkeycode:decimal="+jkc.getJavaKeycode()+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
               ", hex=0x"+Integer.toHexString(jkc.getJavaKeycode())+"; "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
            );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        postKeyEvent( java.awt.event.KeyEvent.KEY_PRESSED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                          ev.get_time(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                          jkc.getJavaKeycode(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                          (unicodeKey == 0 ? java.awt.event.KeyEvent.CHAR_UNDEFINED : unicodeKey),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                          jkc.getKeyLocation(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                          ev.get_state(),ev.getPData(), XKeyEvent.getSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        if( unicodeKey > 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                keyEventLog.fine("fire _TYPED on "+unicodeKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                postKeyEvent( java.awt.event.KeyEvent.KEY_TYPED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                              ev.get_time(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                              java.awt.event.KeyEvent.VK_UNDEFINED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                              unicodeKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                              java.awt.event.KeyEvent.KEY_LOCATION_UNKNOWN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                              ev.get_state(),ev.getPData(), XKeyEvent.getSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
    public void handleKeyRelease(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
        super.handleKeyRelease(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        XKeyEvent ev = xev.get_xkey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        if (eventLog.isLoggable(Level.FINE)) eventLog.fine(ev.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        if (isEventDisabled(xev)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        handleKeyRelease(ev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
    // un-private it if you need to call it from elsewhere
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
    private void handleKeyRelease(XKeyEvent ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        long keysym[] = new long[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        char unicodeKey = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        keysym[0] = NoSymbol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        if (keyEventLog.isLoggable(Level.FINE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
            logIncomingKeyEvent( ev );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        // Keysym should be converted to Unicode, if possible and necessary,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        // and Java KeyEvent keycode should be calculated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        // For release we should post released event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        XKeysym.Keysym2JavaKeycode jkc = XKeysym.getJavaKeycode(ev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        if( jkc == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
            jkc = new XKeysym.Keysym2JavaKeycode(java.awt.event.KeyEvent.VK_UNDEFINED, java.awt.event.KeyEvent.KEY_LOCATION_UNKNOWN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        if (keyEventLog.isLoggable(Level.FINE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
            keyEventLog.fine(">>>Fire Event:"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
               (ev.get_type() == XConstants.KeyPress ? "KEY_PRESSED; " : "KEY_RELEASED; ")+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
               "jkeycode:decimal="+jkc.getJavaKeycode()+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
               ", hex=0x"+Integer.toHexString(jkc.getJavaKeycode())+"; "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
            );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        // We obtain keysym from IM and derive unicodeKey from it for KeyPress only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        // We used to cache that value and retrieve it on KeyRelease,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        // but in case for example of a dead key+vowel pair, a vowel after a deadkey
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        // might never be cached before.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        // Also, switching between keyboard layouts, we might cache a wrong letter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        // That's why we use the same procedure as if there was no IM instance: do-it-yourself unicode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        unicodeKey = keysymToUnicode( xkeycodeToKeysym(ev), ev.get_state() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        postKeyEvent(  java.awt.event.KeyEvent.KEY_RELEASED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                          ev.get_time(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                          jkc.getJavaKeycode(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                          (unicodeKey == 0 ? java.awt.event.KeyEvent.CHAR_UNDEFINED : unicodeKey),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                          jkc.getKeyLocation(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                          ev.get_state(),ev.getPData(), XKeyEvent.getSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
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 void reshape(Rectangle bounds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        reshape(bounds.x, bounds.y, bounds.width, bounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    public void reshape(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        if (width <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
            width = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        if (height <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
            height = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        this.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        this.y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        this.width = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        this.height = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        xSetBounds(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        // Fixed 6322593, 6304251, 6315137:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        // XWindow's SurfaceData should be invalidated and recreated as part
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
        // of the process of resizing the window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        // see the evaluation of the bug 6304251 for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        validateSurface();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        layout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
    public void layout() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    boolean isShowing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        return visible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
    boolean isResizable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
    boolean isLocationByPlatform() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
    void updateSizeHints() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        updateSizeHints(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
    void updateSizeHints(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        long flags = XlibWrapper.PSize | (isLocationByPlatform() ? 0 : (XlibWrapper.PPosition | XlibWrapper.USPosition));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        if (!isResizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
            log.log(Level.FINER, "Window {0} is not resizable", new Object[] {this});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
            flags |= XlibWrapper.PMinSize | XlibWrapper.PMaxSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
            log.log(Level.FINER, "Window {0} is resizable", new Object[] {this});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        setSizeHints(flags, x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
    void updateSizeHints(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
        long flags = isLocationByPlatform() ? 0 : (XlibWrapper.PPosition | XlibWrapper.USPosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
        if (!isResizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
            log.log(Level.FINER, "Window {0} is not resizable", new Object[] {this});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
            flags |= XlibWrapper.PMinSize | XlibWrapper.PMaxSize | XlibWrapper.PSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
            log.log(Level.FINER, "Window {0} is resizable", new Object[] {this});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        setSizeHints(flags, x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
      void validateSurface() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
        if ((width != oldWidth) || (height != oldHeight)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
            SurfaceData oldData = surfaceData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
            if (oldData != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                surfaceData = graphicsConfig.createSurfaceData(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                oldData.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
            oldWidth = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
            oldHeight = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
    public SurfaceData getSurfaceData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        return surfaceData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
    public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        SurfaceData oldData = surfaceData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        surfaceData = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        if (oldData != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
            oldData.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        XToolkit.targetDisposedPeer(target, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
    public Point getLocationOnScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        synchronized (target.getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            Component comp = target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
            while (comp != null && !(comp instanceof Window)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                comp = ComponentAccessor.getParent_NoClientCode(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            // applets, embedded, etc - translate directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
            // XXX: override in subclass?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
            if (comp == null || comp instanceof sun.awt.EmbeddedFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                return toGlobal(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
                Object wpeer = XToolkit.targetToPeer(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                if (wpeer == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
                    || !(wpeer instanceof XDecoratedPeer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
                    || ((XDecoratedPeer)wpeer).configure_seen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                    return toGlobal(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
                // wpeer is an XDecoratedPeer not yet fully adopted by WM
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
                Point pt = toOtherWindow(getContentWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
                                         ((XDecoratedPeer)wpeer).getContentWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
                                         0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                if (pt == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
                    pt = new Point(((XBaseWindow)wpeer).getAbsoluteX(), ((XBaseWindow)wpeer).getAbsoluteY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
                pt.x += comp.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
                pt.y += comp.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
                return pt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
    static Field bdata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
    static void setBData(KeyEvent e, byte[] data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
            if (bdata == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
                bdata = SunToolkit.getField(java.awt.AWTEvent.class, "bdata");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
            bdata.set(e, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        } catch (IllegalAccessException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
            assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
    public void postKeyEvent(int id, long when, int keyCode, char keyChar,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
        int keyLocation, int state, long event, int eventSize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        long jWhen = XToolkit.nowMillisUTC_offset(when);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
        int modifiers = getModifiers(state, 0, keyCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
        KeyEvent ke = new KeyEvent((Component)getEventSource(), id, jWhen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                                   modifiers, keyCode, keyChar, keyLocation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
        if (event != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
            byte[] data = Native.toBytes(event, eventSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
            setBData(ke, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        postEventToEventQueue(ke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
    static native int getAWTKeyCodeForKeySym(int keysym);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
    static native int getKeySymForAWTKeyCode(int keycode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
}