Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 69712 invoked from network); 14 Aug 2007 08:14:29 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 14 Aug 2007 08:14:29 -0000 Received: (qmail 91012 invoked by uid 500); 14 Aug 2007 08:14:27 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 90988 invoked by uid 500); 14 Aug 2007 08:14:27 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 90979 invoked by uid 99); 14 Aug 2007 08:14:27 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Aug 2007 01:14:27 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Aug 2007 08:14:28 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 363441A981D; Tue, 14 Aug 2007 01:14:08 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r565654 - in /harmony/enhanced/classlib/trunk/modules/awt/src/main: java/common/java/awt/ java/common/org/apache/harmony/awt/wtk/ java/unix/org/apache/harmony/awt/wtk/linux/ java/windows/org/apache/harmony/awt/wtk/windows/ native/gl/windows/ Date: Tue, 14 Aug 2007 08:14:07 -0000 To: commits@harmony.apache.org From: apetrenko@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070814081408.363441A981D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: apetrenko Date: Tue Aug 14 01:14:07 2007 New Revision: 565654 URL: http://svn.apache.org/viewvc?view=rev&rev=565654 Log: Patch for HARMONY-4423 "[classlib][awt][jedit] Toolkit.getLockingKeyState() is not implemented" Added: harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/windows/LockingKeys.cpp (with props) Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Toolkit.java harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/wtk/WTK.java harmony/enhanced/classlib/trunk/modules/awt/src/main/java/unix/org/apache/harmony/awt/wtk/linux/LinuxWTK.java harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinWTK.java harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/windows/makefile Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Toolkit.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Toolkit.java?view=diff&rev=565654&r1=565653&r2=565654 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Toolkit.java (original) +++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Toolkit.java Tue Aug 14 01:14:07 2007 @@ -28,6 +28,7 @@ import java.awt.event.AWTEventListener; import java.awt.event.AWTEventListenerProxy; import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; import java.awt.im.InputMethodHighlight; import java.awt.image.ColorModel; import java.awt.image.ImageObserver; @@ -795,16 +796,16 @@ } } - public boolean getLockingKeyState(int a0) throws UnsupportedOperationException, org.apache.harmony.luni.util.NotImplementedException { - lockAWT(); - try { - } finally { - unlockAWT(); - } - if (true) { - throw new RuntimeException("Method is not implemented"); //TODO: implement //$NON-NLS-1$ + public boolean getLockingKeyState(int keyCode) throws UnsupportedOperationException { + + if (keyCode != KeyEvent.VK_CAPS_LOCK && + keyCode != KeyEvent.VK_NUM_LOCK && + keyCode != KeyEvent.VK_SCROLL_LOCK && + keyCode != KeyEvent.VK_KANA_LOCK) { + throw new IllegalArgumentException(); } - return true; + + return wtk.getLockingState(keyCode); } public int getMaximumCursorColors() throws HeadlessException { @@ -952,16 +953,16 @@ } } - public void setLockingKeyState(int a0, boolean a1) throws UnsupportedOperationException, org.apache.harmony.luni.util.NotImplementedException { - lockAWT(); - try { - } finally { - unlockAWT(); - } - if (true) { - throw new RuntimeException("Method is not implemented"); //TODO: implement //$NON-NLS-1$ + public void setLockingKeyState(int keyCode, boolean on) throws UnsupportedOperationException { + + if (keyCode != KeyEvent.VK_CAPS_LOCK && + keyCode != KeyEvent.VK_NUM_LOCK && + keyCode != KeyEvent.VK_SCROLL_LOCK && + keyCode != KeyEvent.VK_KANA_LOCK) { + throw new IllegalArgumentException(); } - return; + + wtk.setLockingState(keyCode, on); } void onQueueEmpty() { Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/wtk/WTK.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/wtk/WTK.java?view=diff&rev=565654&r1=565653&r2=565654 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/wtk/WTK.java (original) +++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/wtk/WTK.java Tue Aug 14 01:14:07 2007 @@ -58,4 +58,10 @@ * @return implementation of NativeIM */ public abstract NativeIM getNativeIM(); + + /** + * Perform platform specific operations with locking keys. + */ + public abstract boolean getLockingState(int keyCode); + public abstract void setLockingState(int keyCode, boolean on); } Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/unix/org/apache/harmony/awt/wtk/linux/LinuxWTK.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/unix/org/apache/harmony/awt/wtk/linux/LinuxWTK.java?view=diff&rev=565654&r1=565653&r2=565654 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/unix/org/apache/harmony/awt/wtk/linux/LinuxWTK.java (original) +++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/unix/org/apache/harmony/awt/wtk/linux/LinuxWTK.java Tue Aug 14 01:14:07 2007 @@ -89,6 +89,15 @@ return null; } + public boolean getLockingState(int keyCode) { + // TODO implement + return false; + } + + public void setLockingState(int keyCode, boolean on) { + // TODO implement + } + private final LinuxWindowFactory windowFactory = new LinuxWindowFactory(); private final LinuxEventQueue eventQueue = new LinuxEventQueue(windowFactory); private final GraphicsFactory graphicsFactory = new org.apache.harmony.awt.gl.linux.LinuxGraphics2DFactory(); Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinWTK.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinWTK.java?view=diff&rev=565654&r1=565653&r2=565654 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinWTK.java (original) +++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/windows/org/apache/harmony/awt/wtk/windows/WinWTK.java Tue Aug 14 01:14:07 2007 @@ -27,6 +27,10 @@ public class WinWTK extends WTK { + static { + System.loadLibrary("gl"); //$NON-NLS-1$ + } + /** * @see org.apache.harmony.awt.wtk.WTK#getGraphicsFactory() */ @@ -97,6 +101,10 @@ } return im; } + + public native boolean getLockingState(int keyCode); + + public native void setLockingState(int keyCode, boolean on); private final WinSystemProperties systemProperties = new WinSystemProperties(); private final WinEventQueue eventQueue = new WinEventQueue(systemProperties); Added: harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/windows/LockingKeys.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/windows/LockingKeys.cpp?view=auto&rev=565654 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/windows/LockingKeys.cpp (added) +++ harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/windows/LockingKeys.cpp Tue Aug 14 01:14:07 2007 @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /** + * @author Ilya Berezhniuk + * @version $Revision$ + * + */ + +#include +#include "exceptions.h" + +// C declarations +extern "C" { +JNIEXPORT jboolean JNICALL Java_org_apache_harmony_awt_wtk_windows_WinWTK_getLockingState + (JNIEnv *env, jclass cls, jint keyCode); +JNIEXPORT void JNICALL Java_org_apache_harmony_awt_wtk_windows_WinWTK_setLockingState + (JNIEnv *env, jclass cls, jint keyCode, jboolean on); +} + + +static inline bool is_kana_present() +{ + return (MapVirtualKey(VK_KANA, 0) != 0); +} + +// Translate Java VK to Win32 VK +static inline int get_virt_locking_key(jint code) +{ + switch (code) + { + case 20:/*VK_CAPS_LOCK*/ + return VK_CAPITAL; + case 144:/*VK_NUM_LOCK*/ + return VK_NUMLOCK; + case 145:/*VK_SCROLL_LOCK*/ + return VK_SCROLL; + case 262:/*VK_KANA_LOCK*/ + return VK_KANA; + } + + return 0; +} + + +/* + * Class: org_apache_harmony_awt_wtk_windows_WinWTK + * Method: nativeGetLockingState + * Signature: (I)Z + */ +JNIEXPORT jboolean JNICALL Java_org_apache_harmony_awt_wtk_windows_WinWTK_getLockingState + (JNIEnv *env, jclass cls, jint keyCode) +{ + int vk = get_virt_locking_key(keyCode); + + if (vk == 0) + return JNI_FALSE; + + if (vk == VK_KANA && !is_kana_present()) + { + throwNewExceptionByName(env, "java/lang/UnsupportedOperationException", + "Keyboard doesn't have KANA key"); + return JNI_FALSE; // We shouldn't reach this return + } + + return (GetKeyState(vk) & 1) ? JNI_TRUE : JNI_FALSE; +} + +/* + * Class: org_apache_harmony_awt_wtk_windows_WinWTK + * Method: nativeSetLockingState + * Signature: (IZ)V + */ +JNIEXPORT void JNICALL Java_org_apache_harmony_awt_wtk_windows_WinWTK_setLockingState + (JNIEnv *env, jclass cls, jint keyCode, jboolean on) +{ + int vk = get_virt_locking_key(keyCode); + + if (vk == 0) + return; + + if (vk == VK_KANA && !is_kana_present()) + { + throwNewExceptionByName(env, "java/lang/UnsupportedOperationException", + "Keyboard doesn't have KANA key"); + return; // We shouldn't reach this return + } + + bool enabled = ((GetKeyState(vk) & 1) != 0); + + if ((enabled && on) || (!enabled && !on)) + return; + + LPARAM extra = GetMessageExtraInfo(); + + INPUT inp[2] = {{INPUT_KEYBOARD}, {INPUT_KEYBOARD}}; + inp[0].ki.wVk = inp[1].ki.wVk = vk; + inp[0].ki.time = inp[1].ki.time = 0; + inp[0].ki.dwExtraInfo = inp[1].ki.dwExtraInfo = extra; + inp[0].ki.dwFlags = 0; + inp[1].ki.dwFlags = KEYEVENTF_KEYUP; + + SendInput(2, inp, sizeof(INPUT)); +} Propchange: harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/windows/LockingKeys.cpp ------------------------------------------------------------------------------ svn:eol-style = native Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/windows/makefile URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/windows/makefile?view=diff&rev=565654&r1=565653&r2=565654 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/windows/makefile (original) +++ harmony/enhanced/classlib/trunk/modules/awt/src/main/native/gl/windows/makefile Tue Aug 14 01:14:07 2007 @@ -23,7 +23,7 @@ LIBNAME=$(LIBPATH)$(LIBBASE).lib HYLDFLAGS = $(HYLDFLAGS) -def:$(LIBBASE).def -HYCFLAGS = $(HYCFLAGS) /I$(SHAREDSUB)include /I$(SHAREDSUB) \ +HYCFLAGS = $(HYCFLAGS) /D_WIN32_WINNT=0x0500 /I$(SHAREDSUB)include /I$(SHAREDSUB) \ /I$(PNG_DIR) /Iinclude BUILDFILES = \ @@ -32,6 +32,7 @@ WinGDIPGraphics2D.obj \ WinGraphicsEnvironment.obj \ WinThemeGraphics.obj \ + LockingKeys.obj \ $(SHAREDSUB)blitter.obj \ $(SHAREDSUB)gifdecoder.obj \ $(SHAREDSUB)LUTTables.obj \