src/macosx/classes/sun/lwawt/macosx/CPlatformResponder.java

Print this page




 108     }
 109 
 110     private void dispatchScrollEvent(final int x, final int y,
 111                                      final int modifiers, final double delta) {
 112         final long when = System.currentTimeMillis();
 113         final int scrollType = MouseWheelEvent.WHEEL_UNIT_SCROLL;
 114         final int scrollAmount = 1;
 115         int wheelRotation = (int) delta;
 116         int signum = (int) Math.signum(delta);
 117         if (signum * delta < 1) {
 118             wheelRotation = signum;
 119         }
 120         // invert the wheelRotation for the peer
 121         eventNotifier.notifyMouseWheelEvent(when, x, y, modifiers, scrollType,
 122                 scrollAmount, -wheelRotation, -delta, null);
 123     }
 124 
 125     /**
 126      * Handles key events.
 127      */
 128     void handleKeyEvent(int eventType, int modifierFlags, String chars,
 129                         short keyCode, boolean needsKeyTyped, boolean needsKeyReleased) {
 130         boolean isFlagsChangedEvent =
 131             isNpapiCallback ? (eventType == CocoaConstants.NPCocoaEventFlagsChanged) :
 132                               (eventType == CocoaConstants.NSFlagsChanged);
 133 
 134         int jeventType = KeyEvent.KEY_PRESSED;
 135         int jkeyCode = KeyEvent.VK_UNDEFINED;
 136         int jkeyLocation = KeyEvent.KEY_LOCATION_UNKNOWN;
 137         boolean postsTyped = false;
 138 
 139         char testChar = KeyEvent.CHAR_UNDEFINED;
 140         boolean isDeadChar = (chars!= null && chars.length() == 0);
 141 
 142         if (isFlagsChangedEvent) {
 143             int[] in = new int[] {modifierFlags, keyCode};
 144             int[] out = new int[3]; // [jkeyCode, jkeyLocation, jkeyType]
 145 
 146             NSEvent.nsKeyModifiersToJavaKeyInfo(in, out);
 147 
 148             jkeyCode = out[0];
 149             jkeyLocation = out[1];
 150             jeventType = out[2];
 151         } else {
 152             if (chars != null && chars.length() > 0) {
 153                 testChar = chars.charAt(0);
 154             }
 155 
 156             int[] in = new int[] {testChar, isDeadChar ? 1 : 0, modifierFlags, keyCode};



 157             int[] out = new int[3]; // [jkeyCode, jkeyLocation, deadChar]
 158 
 159             postsTyped = NSEvent.nsToJavaKeyInfo(in, out);
 160             if (!postsTyped) {
 161                 testChar = KeyEvent.CHAR_UNDEFINED;
 162             }
 163 
 164             if(isDeadChar){
 165                 testChar = (char) out[2];
 166                 if(testChar == 0){
 167                     return;
 168                 }
 169             }
 170 
 171             jkeyCode = out[0];
 172             jkeyLocation = out[1];
 173             jeventType = isNpapiCallback ? NSEvent.npToJavaEventType(eventType) :
 174                                            NSEvent.nsToJavaEventType(eventType);
 175         }
 176 




 108     }
 109 
 110     private void dispatchScrollEvent(final int x, final int y,
 111                                      final int modifiers, final double delta) {
 112         final long when = System.currentTimeMillis();
 113         final int scrollType = MouseWheelEvent.WHEEL_UNIT_SCROLL;
 114         final int scrollAmount = 1;
 115         int wheelRotation = (int) delta;
 116         int signum = (int) Math.signum(delta);
 117         if (signum * delta < 1) {
 118             wheelRotation = signum;
 119         }
 120         // invert the wheelRotation for the peer
 121         eventNotifier.notifyMouseWheelEvent(when, x, y, modifiers, scrollType,
 122                 scrollAmount, -wheelRotation, -delta, null);
 123     }
 124 
 125     /**
 126      * Handles key events.
 127      */
 128     void handleKeyEvent(int eventType, int modifierFlags, String chars, String charsIgnoringModifiers,
 129                         short keyCode, boolean needsKeyTyped, boolean needsKeyReleased) {
 130         boolean isFlagsChangedEvent =
 131             isNpapiCallback ? (eventType == CocoaConstants.NPCocoaEventFlagsChanged) :
 132                               (eventType == CocoaConstants.NSFlagsChanged);
 133 
 134         int jeventType = KeyEvent.KEY_PRESSED;
 135         int jkeyCode = KeyEvent.VK_UNDEFINED;
 136         int jkeyLocation = KeyEvent.KEY_LOCATION_UNKNOWN;
 137         boolean postsTyped = false;
 138 
 139         char testChar = KeyEvent.CHAR_UNDEFINED;
 140         boolean isDeadChar = (chars!= null && chars.length() == 0);
 141 
 142         if (isFlagsChangedEvent) {
 143             int[] in = new int[] {modifierFlags, keyCode};
 144             int[] out = new int[3]; // [jkeyCode, jkeyLocation, jkeyType]
 145 
 146             NSEvent.nsKeyModifiersToJavaKeyInfo(in, out);
 147 
 148             jkeyCode = out[0];
 149             jkeyLocation = out[1];
 150             jeventType = out[2];
 151         } else {
 152             if (chars != null && chars.length() > 0) {
 153                 testChar = chars.charAt(0);
 154             }
 155 
 156             char testCharIgnoringModifiers = charsIgnoringModifiers != null && charsIgnoringModifiers.length() > 0 ?
 157                     charsIgnoringModifiers.charAt(0) : KeyEvent.CHAR_UNDEFINED;
 158 
 159             int[] in = new int[] {testCharIgnoringModifiers, isDeadChar ? 1 : 0, modifierFlags, keyCode};
 160             int[] out = new int[3]; // [jkeyCode, jkeyLocation, deadChar]
 161 
 162             postsTyped = NSEvent.nsToJavaKeyInfo(in, out);
 163             if (!postsTyped) {
 164                 testChar = KeyEvent.CHAR_UNDEFINED;
 165             }
 166 
 167             if(isDeadChar){
 168                 testChar = (char) out[2];
 169                 if(testChar == 0){
 170                     return;
 171                 }
 172             }
 173 
 174             jkeyCode = out[0];
 175             jkeyLocation = out[1];
 176             jeventType = isNpapiCallback ? NSEvent.npToJavaEventType(eventType) :
 177                                            NSEvent.nsToJavaEventType(eventType);
 178         }
 179