jdk/src/solaris/native/sun/awt/awt_GlobalCursorManager.c
changeset 1192 715cf9378c53
parent 1051 90cf935adb35
parent 1191 f142c1da78c2
child 1193 41afb8ee8f45
equal deleted inserted replaced
1051:90cf935adb35 1192:715cf9378c53
     1 /*
       
     2  * Copyright 1999-2001 Sun Microsystems, Inc.  All Rights Reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Sun designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Sun in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    23  * have any questions.
       
    24  */
       
    25 #ifdef HEADLESS
       
    26     #error This file should not be included in headless library
       
    27 #endif
       
    28 
       
    29 #include "awt_p.h"
       
    30 #include "awt_Component.h"
       
    31 #include "sun_awt_motif_MComponentPeer.h"
       
    32 
       
    33 #include "jni.h"
       
    34 #include "jni_util.h"
       
    35 
       
    36 static jfieldID xID;
       
    37 static jfieldID yID;
       
    38 
       
    39 extern struct MComponentPeerIDs mComponentPeerIDs;
       
    40 extern struct ComponentIDs componentIDs;
       
    41 extern struct ContainerIDs containerIDs;
       
    42 extern jobject getCurComponent();
       
    43 
       
    44 /*
       
    45  * Class:     sun_awt_motif_MGlobalCursorManager
       
    46  * Method:    cacheInit
       
    47  * Signature: ()V
       
    48  */
       
    49 JNIEXPORT void JNICALL Java_sun_awt_motif_MGlobalCursorManager_cacheInit
       
    50   (JNIEnv *env, jclass cls)
       
    51 {
       
    52     jclass clsDimension = (*env)->FindClass(env, "java/awt/Point");
       
    53     xID = (*env)->GetFieldID(env, clsDimension, "x", "I");
       
    54     yID = (*env)->GetFieldID(env, clsDimension, "y", "I");
       
    55 }
       
    56 
       
    57 /*
       
    58  * Class:     sun_awt_motif_MGlobalCursorManager
       
    59  * Method:    getCursorPos
       
    60  * Signature: (Ljava/awt/Point;)Ljava/awt/Component
       
    61  */
       
    62 JNIEXPORT void JNICALL Java_sun_awt_motif_MGlobalCursorManager_getCursorPos
       
    63   (JNIEnv *env, jobject this, jobject point)
       
    64 {
       
    65     Window root, rw, cw;
       
    66     int32_t rx, ry, x, y;
       
    67     uint32_t kbs;
       
    68 
       
    69     AWT_LOCK();
       
    70     root = RootWindow(awt_display, DefaultScreen(awt_display));
       
    71     XQueryPointer(awt_display, root, &rw, &cw, &rx, &ry, &x, &y, &kbs);
       
    72 
       
    73     (*env)->SetIntField(env, point, xID, rx);
       
    74     (*env)->SetIntField(env, point, yID, ry);
       
    75     AWT_FLUSH_UNLOCK();
       
    76 }
       
    77 
       
    78 /*
       
    79  * Class:     sun_awt_motif_MGlobalCursorManager
       
    80  * Method:    getCursorPos
       
    81  * Signature: ()Ljava/awt/Component
       
    82  */
       
    83 JNIEXPORT jobject JNICALL Java_sun_awt_motif_MGlobalCursorManager_findHeavyweightUnderCursor
       
    84   (JNIEnv *env, jobject this)
       
    85 {
       
    86         jobject target;
       
    87 
       
    88     AWT_LOCK();
       
    89         target = getCurComponent();
       
    90     AWT_FLUSH_UNLOCK();
       
    91         return target;
       
    92 }
       
    93 
       
    94 /*
       
    95  * Class:     sun_awt_motif_MGlobalCursorManager
       
    96  * Method:    getLocationOnScreen
       
    97  * Signature: (Ljava/awt/Component;)Ljava/awt/Point
       
    98  */
       
    99 JNIEXPORT jobject JNICALL Java_sun_awt_motif_MGlobalCursorManager_getLocationOnScreen
       
   100   (JNIEnv *env, jobject this, jobject component)
       
   101 {
       
   102     jobject point =
       
   103         (*env)->CallObjectMethod(env, component,
       
   104                                  componentIDs.getLocationOnScreen);
       
   105     return point;
       
   106 }
       
   107 
       
   108 /*
       
   109  * Class:     sun_awt_motif_MGlobalCursorManager
       
   110  * Method:    findComponentAt
       
   111  * Signature: (Ljava/awt/Container;II)Ljava/awt/Component
       
   112  */
       
   113 JNIEXPORT jobject JNICALL
       
   114 Java_sun_awt_motif_MGlobalCursorManager_findComponentAt
       
   115     (JNIEnv *env, jobject this, jobject container, jint x, jint y)
       
   116 {
       
   117     /*
       
   118      * Call private version of Container.findComponentAt with the following
       
   119      * flag set: ignoreEnabled = false (i.e., don't return or recurse into
       
   120      * disabled Components).
       
   121      * NOTE: it may return a JRootPane's glass pane as the target Component.
       
   122      */
       
   123     jobject component =
       
   124         (*env)->CallObjectMethod(env, container, containerIDs.findComponentAt,
       
   125                                  x, y, JNI_FALSE);
       
   126     return component;
       
   127 }