Skip to content

Commit

Permalink
Added hint to getKeyCodeForChar to enable numeric keypad
Browse files Browse the repository at this point in the history
  • Loading branch information
beldenfox committed Nov 16, 2023
1 parent 2e73304 commit ebd07f1
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,16 @@ public class KeyEvent {
* Returns a VK_ code of a key capable of producing the given unicode
* character with respect to the currently active keyboard layout or
* VK_UNDEFINED if the character isn't present in the current layout.
* The hint is the KeyCode of the key the system is attempting to match.
* It can be used to optimize the search or to distinguish between the
* main keyboard and the numeric keypad.
*
* @param c the character
* @param hint the code of the key the system is attempting to match
* @return integer code for the given char
*/
public static int getKeyCodeForChar(char c) {
return Application.getKeyCodeForChar(c);
public static int getKeyCodeForChar(char c, int hint) {
return Application.getKeyCodeForChar(c, hint);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,17 +738,21 @@ public final boolean supportsSystemMenu() {
return _supportsSystemMenu();
}

protected abstract int _getKeyCodeForChar(char c);
protected abstract int _getKeyCodeForChar(char c, int hint);
/**
* Returns a VK_ code of a key capable of producing the given unicode
* character with respect to the currently active keyboard layout or
* VK_UNDEFINED if the character isn't present in the current layout.
* The hint is the KeyCode of the key the system is attempting to match.
* It can be used to optimize the search or to distinguish between the
* main keyboard and the numeric keypad.
*
* @param c the character
* @param hint the code of the key the system is attempting to match
* @return integer code for the given char
*/
public static int getKeyCodeForChar(char c) {
return application._getKeyCodeForChar(c);
public static int getKeyCodeForChar(char c, int hint) {
return application._getKeyCodeForChar(c, hint);
}

protected int _isKeyLocked(int keyCode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ protected boolean _supportsInputMethods() {
}

@Override
protected native int _getKeyCodeForChar(char c);
protected native int _getKeyCodeForChar(char c, int hint);

@Override
protected native int _isKeyLocked(int keyCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,5 +283,5 @@ public boolean hasMultiTouch() {
}

@Override
protected native int _getKeyCodeForChar(char c);
protected native int _getKeyCodeForChar(char c, int hint);
}
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public String getDataDirectory() {
}

@Override
protected native int _getKeyCodeForChar(char c);
protected native int _getKeyCodeForChar(char c, int hint);

@Override
protected native int _isKeyLocked(int keyCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private char[] getKeyChars(KeyState state, int key) {
return c == '\000' ? NO_CHAR : new char[] { c };
}

int getKeyCodeForChar(char c) {
int getKeyCodeForChar(char c, int hint) {
c = Character.toUpperCase(c);
// remove shift modification
switch (c) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ void leaveDndEventLoop() {
}

@Override
protected int _getKeyCodeForChar(char c) {
return KeyInput.getInstance().getKeyCodeForChar(c);
protected int _getKeyCodeForChar(char c, int hint) {
return KeyInput.getInstance().getKeyCodeForChar(c, hint);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ public String getDataDirectory() {
}

@Override
protected native int _getKeyCodeForChar(char c);
protected native int _getKeyCodeForChar(char c, int hint);

@Override
protected native int _isKeyLocked(int keyCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public Shape createStrokedShape(Shape shape, StrokeType pgtype, double strokewid
}

@Override
public int getKeyCodeForChar(String character) {
public int getKeyCodeForChar(String character, int hint) {
throw new UnsupportedOperationException("Not supported yet.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ protected static final double clampStopOffset(double offset) {
float[] dashArray,
float dashOffset);

public abstract int getKeyCodeForChar(String character);
public abstract int getKeyCodeForChar(String character, int hint);
public abstract Dimension2D getBestCursorSize(int preferredWidth, int preferredHeight);
public abstract int getMaximumCursorColors();
public abstract PathElement[] convertShapeToFXPath(Object shape);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1079,10 +1079,10 @@ public Shape createStrokedShape(Shape shape,
return 2;
}

@Override public int getKeyCodeForChar(String character) {
@Override public int getKeyCodeForChar(String character, int hint) {
return (character.length() == 1)
? com.sun.glass.events.KeyEvent.getKeyCodeForChar(
character.charAt(0))
character.charAt(0), hint)
: com.sun.glass.events.KeyEvent.VK_UNDEFINED;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public boolean match(final KeyEvent event) {
return false;
}
return (event.getCode().getCode()
== Toolkit.getToolkit().getKeyCodeForChar(getCharacter()))
== Toolkit.getToolkit().getKeyCodeForChar(getCharacter(), event.getCode().getCode()))
&& super.match(event);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,10 @@ extern "C" {
/*
* Class: com_sun_glass_ui_gtk_GtkApplication
* Method: _getKeyCodeForChar
* Signature: (C)I
* Signature: (CI)I
*/
JNIEXPORT jint JNICALL Java_com_sun_glass_ui_gtk_GtkApplication__1getKeyCodeForChar
(JNIEnv *env, jobject jApplication, jchar character)
(JNIEnv *env, jobject jApplication, jchar character, jint hint)
{
(void)env;
(void)jApplication;
Expand Down
4 changes: 2 additions & 2 deletions modules/javafx.graphics/src/main/native-glass/ios/GlassKey.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
/*
* Class: com_sun_glass_ui_ios_IosApplication
* Method: _getKeyCodeForChar
* Signature: (C)I
* Signature: (CI)I
*/
JNIEXPORT jint JNICALL Java_com_sun_glass_ui_ios_IosApplication__1getKeyCodeForChar
(JNIEnv * env, jobject jApplication, jchar c)
(JNIEnv * env, jobject jApplication, jchar c, jint hint)
{
GLASS_LOG("Java_com_sun_glass_ui_ios_IosApplication__1getKeyCodeForChar");

Expand Down
4 changes: 2 additions & 2 deletions modules/javafx.graphics/src/main/native-glass/mac/GlassKey.m
Original file line number Diff line number Diff line change
Expand Up @@ -603,10 +603,10 @@ BOOL GetMacKey(jint javaKeyCode, unsigned short *outMacKeyCode)
/*
* Class: com_sun_glass_ui_mac_MacApplication
* Method: _getKeyCodeForChar
* Signature: (C)I
* Signature: (CI)I
*/
JNIEXPORT jint JNICALL Java_com_sun_glass_ui_mac_MacApplication__1getKeyCodeForChar
(JNIEnv * env, jobject jApplication, jchar c)
(JNIEnv * env, jobject jApplication, jchar c, jint hint)
{
LOG("Java_com_sun_glass_ui_mac_MacApplication__1getKeyCodeForChar");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,10 @@ BOOL IsExtendedKey(UINT vkey) {
/*
* Class: Java_com_sun_glass_ui_win_WinApplication
* Method: _getKeyCodeForChar
* Signature: (C)I
* Signature: (CI)I
*/
JNIEXPORT jint JNICALL Java_com_sun_glass_ui_win_WinApplication__1getKeyCodeForChar
(JNIEnv * env, jobject jApplication, jchar c)
(JNIEnv * env, jobject jApplication, jchar c, jint hint)
{
// The Delete key doesn't generate a character so ViewContainer::HandleViewKeyEvent
// synthesizes one. Here we reverse that process.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

public class MonocleApplicationShim {

public static int _getKeyCodeForChar(char c) {
return MonocleApplication.getKeyCodeForChar(c);
public static int _getKeyCodeForChar(char c, int hint) {
return MonocleApplication.getKeyCodeForChar(c, hint);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ public void waitFor(Task t) {
}

@Override
public int getKeyCodeForChar(String character) {
public int getKeyCodeForChar(String character, int hint) {
if (charToKeyCodeMap != null) {
final KeyCode keyCode = charToKeyCodeMap.get(character);
if (keyCode != null) {
Expand Down

0 comments on commit ebd07f1

Please sign in to comment.