jdk/src/solaris/native/sun/awt/MouseInfo.c
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 433 a7f6bc61993d
child 5506 202f599c92aa
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 433
diff changeset
     2
 * Copyright 2003-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
#ifdef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
    #error This file should not be included in headless library
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "awt_p.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "awt_Component.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include <jni.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include <jni_util.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
extern int awt_numScreens;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
extern AwtScreenDataPtr x11Screens;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
extern struct ComponentIDs componentIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
extern struct MComponentPeerIDs mComponentPeerIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * Class:     sun_awt_DefaultMouseInfoPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Method:    fillPointWithCoords
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Signature: (Ljava/awt/Point)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
Java_sun_awt_DefaultMouseInfoPeer_fillPointWithCoords(JNIEnv *env, jclass cls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
                                                          jobject point)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     static jclass pointClass = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     jclass pointClassLocal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     static jfieldID xID, yID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     Window rootWindow, childWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     int32_t xr, yr, xw, yw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     uint32_t keys;
433
a7f6bc61993d 6677332: incorrect signatures for JNI methods in XWindow.c and XlibWrapper.c
son
parents: 2
diff changeset
    57
     Bool pointerFound;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     if (pointClass == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
         pointClassLocal = (*env)->FindClass(env, "java/awt/Point");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
         DASSERT(pointClassLocal != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
         if (pointClassLocal == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
             AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
             return (jint)0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
         pointClass = (jclass)(*env)->NewGlobalRef(env, pointClassLocal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
         (*env)->DeleteLocalRef(env, pointClassLocal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
         xID = (*env)->GetFieldID(env, pointClass, "x", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
         yID = (*env)->GetFieldID(env, pointClass, "y", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     for (i = 0; i < awt_numScreens; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
         pointerFound = XQueryPointer(awt_display, x11Screens[i].root,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                           &rootWindow, &childWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                           &xr, &yr, &xw, &yw, &keys);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
         if (pointerFound) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
             (*env)->SetIntField(env, point, xID, xr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
             (*env)->SetIntField(env, point, yID, yr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
             AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
             return (jint)i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     /* This should never happen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     DASSERT(FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     return (jint)0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * Class:     sun_awt_DefaultMouseInfoPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * Method:    isWindowUnderMouse
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * Signature: (Ljava/awt/Window)Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
JNIEXPORT jboolean JNICALL Java_sun_awt_DefaultMouseInfoPeer_isWindowUnderMouse
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
  (JNIEnv * env, jclass cls, jobject window)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    Window rootWindow = None, parentWindow = None, siblingWindow = None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    Window * children = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    int is_the_same_screen = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    int32_t xr = 0, yr = 0, xw = 0, yw = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    uint32_t keys = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    uint32_t nchildren = 0;
433
a7f6bc61993d 6677332: incorrect signatures for JNI methods in XWindow.c and XlibWrapper.c
son
parents: 2
diff changeset
   105
    Bool pointerFound = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    struct FrameData *wdata = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    jobject winPeer = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    if ((*env)->EnsureLocalCapacity(env, 1) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    winPeer = (*env)->GetObjectField(env, window, componentIDs.peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    if (JNU_IsNull(env, winPeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    wdata = (struct FrameData *)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        JNU_GetLongFieldAsPtr(env, winPeer, mComponentPeerIDs.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    (*env)->DeleteLocalRef(env, winPeer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    if (wdata == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    XQueryTree(awt_display, XtWindow(wdata->winData.comp.widget),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    &rootWindow, &parentWindow, &children, &nchildren);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    is_the_same_screen = XQueryPointer(awt_display, parentWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            &rootWindow, &siblingWindow, &xr, &yr, &xw, &yw, &keys);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    if (siblingWindow == XtWindow(wdata->winData.comp.widget) && is_the_same_screen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    return JNI_FALSE ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
}