You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ap...@apache.org on 2007/08/14 10:14:07 UTC
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/
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 <windows.h>
+#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 \