diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/classes/com/sun/javafx/newt/KeyEvent.java | 460 | ||||
-rwxr-xr-x | src/classes/com/sun/javafx/newt/NewtFactory.java | 18 | ||||
-rwxr-xr-x | src/classes/com/sun/javafx/newt/Window.java | 16 | ||||
-rw-r--r-- | src/classes/com/sun/javafx/newt/awt/AWTWindow.java | 5 | ||||
-rwxr-xr-x | src/classes/com/sun/javafx/newt/macosx/MacWindow.java | 296 | ||||
-rwxr-xr-x | src/classes/com/sun/opengl/util/texture/TextureIO.java.javase | 4 | ||||
-rw-r--r-- | src/classes/javax/media/opengl/GLDrawableFactory.java | 3 | ||||
-rw-r--r--[-rwxr-xr-x] | src/native/newt/InputEvent.h (renamed from src/native/newt/MacWindow.c) | 26 | ||||
-rw-r--r-- | src/native/newt/MacWindow.m | 268 | ||||
-rw-r--r-- | src/native/newt/NewtMacWindow.h | 53 | ||||
-rw-r--r-- | src/native/newt/NewtMacWindow.m | 274 |
11 files changed, 1363 insertions, 60 deletions
diff --git a/src/classes/com/sun/javafx/newt/KeyEvent.java b/src/classes/com/sun/javafx/newt/KeyEvent.java index 92366bc93..b2ab58cba 100644 --- a/src/classes/com/sun/javafx/newt/KeyEvent.java +++ b/src/classes/com/sun/javafx/newt/KeyEvent.java @@ -140,24 +140,147 @@ public class KeyEvent extends InputEvent /** * Constant for the non-numpad <b>left</b> arrow key. + * @see #VK_KP_LEFT */ public static final int VK_LEFT = 0x25; /** * Constant for the non-numpad <b>up</b> arrow key. + * @see #VK_KP_UP */ public static final int VK_UP = 0x26; /** * Constant for the non-numpad <b>right</b> arrow key. + * @see #VK_KP_RIGHT */ public static final int VK_RIGHT = 0x27; /** * Constant for the non-numpad <b>down</b> arrow key. + * @see #VK_KP_DOWN */ public static final int VK_DOWN = 0x28; + /** + * Constant for the comma key, "," + */ + public static final int VK_COMMA = 0x2C; + + /** + * Constant for the minus key, "-" + * @since 1.2 + */ + public static final int VK_MINUS = 0x2D; + + /** + * Constant for the period key, "." + */ + public static final int VK_PERIOD = 0x2E; + + /** + * Constant for the forward slash key, "/" + */ + public static final int VK_SLASH = 0x2F; + + /** VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */ + public static final int VK_0 = 0x30; + public static final int VK_1 = 0x31; + public static final int VK_2 = 0x32; + public static final int VK_3 = 0x33; + public static final int VK_4 = 0x34; + public static final int VK_5 = 0x35; + public static final int VK_6 = 0x36; + public static final int VK_7 = 0x37; + public static final int VK_8 = 0x38; + public static final int VK_9 = 0x39; + + /** + * Constant for the semicolon key, ";" + */ + public static final int VK_SEMICOLON = 0x3B; + + /** + * Constant for the equals key, "=" + */ + public static final int VK_EQUALS = 0x3D; + + /** VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */ + public static final int VK_A = 0x41; + public static final int VK_B = 0x42; + public static final int VK_C = 0x43; + public static final int VK_D = 0x44; + public static final int VK_E = 0x45; + public static final int VK_F = 0x46; + public static final int VK_G = 0x47; + public static final int VK_H = 0x48; + public static final int VK_I = 0x49; + public static final int VK_J = 0x4A; + public static final int VK_K = 0x4B; + public static final int VK_L = 0x4C; + public static final int VK_M = 0x4D; + public static final int VK_N = 0x4E; + public static final int VK_O = 0x4F; + public static final int VK_P = 0x50; + public static final int VK_Q = 0x51; + public static final int VK_R = 0x52; + public static final int VK_S = 0x53; + public static final int VK_T = 0x54; + public static final int VK_U = 0x55; + public static final int VK_V = 0x56; + public static final int VK_W = 0x57; + public static final int VK_X = 0x58; + public static final int VK_Y = 0x59; + public static final int VK_Z = 0x5A; + + /** + * Constant for the open bracket key, "[" + */ + public static final int VK_OPEN_BRACKET = 0x5B; + + /** + * Constant for the back slash key, "\" + */ + public static final int VK_BACK_SLASH = 0x5C; + + /** + * Constant for the close bracket key, "]" + */ + public static final int VK_CLOSE_BRACKET = 0x5D; + + public static final int VK_NUMPAD0 = 0x60; + public static final int VK_NUMPAD1 = 0x61; + public static final int VK_NUMPAD2 = 0x62; + public static final int VK_NUMPAD3 = 0x63; + public static final int VK_NUMPAD4 = 0x64; + public static final int VK_NUMPAD5 = 0x65; + public static final int VK_NUMPAD6 = 0x66; + public static final int VK_NUMPAD7 = 0x67; + public static final int VK_NUMPAD8 = 0x68; + public static final int VK_NUMPAD9 = 0x69; + public static final int VK_MULTIPLY = 0x6A; + public static final int VK_ADD = 0x6B; + + /** + * This constant is obsolete, and is included only for backwards + * compatibility. + * @see #VK_SEPARATOR + */ + public static final int VK_SEPARATER = 0x6C; + + /** + * Constant for the Numpad Separator key. + * @since 1.4 + */ + public static final int VK_SEPARATOR = VK_SEPARATER; + + public static final int VK_SUBTRACT = 0x6D; + public static final int VK_DECIMAL = 0x6E; + public static final int VK_DIVIDE = 0x6F; + public static final int VK_DELETE = 0x7F; /* ASCII DEL */ + public static final int VK_NUM_LOCK = 0x90; + public static final int VK_SCROLL_LOCK = 0x91; + /** Constant for the F1 function key. */ public static final int VK_F1 = 0x70; @@ -275,6 +398,341 @@ public class KeyEvent extends InputEvent public static final int VK_BACK_QUOTE = 0xC0; public static final int VK_QUOTE = 0xDE; - public static final int VK_WINDOWS = 0x020C; + /** + * Constant for the numeric keypad <b>up</b> arrow key. + * @see #VK_UP + * @since 1.2 + */ + public static final int VK_KP_UP = 0xE0; + + /** + * Constant for the numeric keypad <b>down</b> arrow key. + * @see #VK_DOWN + * @since 1.2 + */ + public static final int VK_KP_DOWN = 0xE1; + + /** + * Constant for the numeric keypad <b>left</b> arrow key. + * @see #VK_LEFT + * @since 1.2 + */ + public static final int VK_KP_LEFT = 0xE2; + + /** + * Constant for the numeric keypad <b>right</b> arrow key. + * @see #VK_RIGHT + * @since 1.2 + */ + public static final int VK_KP_RIGHT = 0xE3; + + /* For European keyboards */ + /** @since 1.2 */ + public static final int VK_DEAD_GRAVE = 0x80; + /** @since 1.2 */ + public static final int VK_DEAD_ACUTE = 0x81; + /** @since 1.2 */ + public static final int VK_DEAD_CIRCUMFLEX = 0x82; + /** @since 1.2 */ + public static final int VK_DEAD_TILDE = 0x83; + /** @since 1.2 */ + public static final int VK_DEAD_MACRON = 0x84; + /** @since 1.2 */ + public static final int VK_DEAD_BREVE = 0x85; + /** @since 1.2 */ + public static final int VK_DEAD_ABOVEDOT = 0x86; + /** @since 1.2 */ + public static final int VK_DEAD_DIAERESIS = 0x87; + /** @since 1.2 */ + public static final int VK_DEAD_ABOVERING = 0x88; + /** @since 1.2 */ + public static final int VK_DEAD_DOUBLEACUTE = 0x89; + /** @since 1.2 */ + public static final int VK_DEAD_CARON = 0x8a; + /** @since 1.2 */ + public static final int VK_DEAD_CEDILLA = 0x8b; + /** @since 1.2 */ + public static final int VK_DEAD_OGONEK = 0x8c; + /** @since 1.2 */ + public static final int VK_DEAD_IOTA = 0x8d; + /** @since 1.2 */ + public static final int VK_DEAD_VOICED_SOUND = 0x8e; + /** @since 1.2 */ + public static final int VK_DEAD_SEMIVOICED_SOUND = 0x8f; + + /** @since 1.2 */ + public static final int VK_AMPERSAND = 0x96; + /** @since 1.2 */ + public static final int VK_ASTERISK = 0x97; + /** @since 1.2 */ + public static final int VK_QUOTEDBL = 0x98; + /** @since 1.2 */ + public static final int VK_LESS = 0x99; + + /** @since 1.2 */ + public static final int VK_GREATER = 0xa0; + /** @since 1.2 */ + public static final int VK_BRACELEFT = 0xa1; + /** @since 1.2 */ + public static final int VK_BRACERIGHT = 0xa2; + + /** + * Constant for the "@" key. + * @since 1.2 + */ + public static final int VK_AT = 0x0200; + + /** + * Constant for the ":" key. + * @since 1.2 + */ + public static final int VK_COLON = 0x0201; + + /** + * Constant for the "^" key. + * @since 1.2 + */ + public static final int VK_CIRCUMFLEX = 0x0202; + + /** + * Constant for the "$" key. + * @since 1.2 + */ + public static final int VK_DOLLAR = 0x0203; + + /** + * Constant for the Euro currency sign key. + * @since 1.2 + */ + public static final int VK_EURO_SIGN = 0x0204; + + /** + * Constant for the "!" key. + * @since 1.2 + */ + public static final int VK_EXCLAMATION_MARK = 0x0205; + + /** + * Constant for the inverted exclamation mark key. + * @since 1.2 + */ + public static final int VK_INVERTED_EXCLAMATION_MARK = 0x0206; + + /** + * Constant for the "(" key. + * @since 1.2 + */ + public static final int VK_LEFT_PARENTHESIS = 0x0207; + + /** + * Constant for the "#" key. + * @since 1.2 + */ + public static final int VK_NUMBER_SIGN = 0x0208; + + /** + * Constant for the "+" key. + * @since 1.2 + */ + public static final int VK_PLUS = 0x0209; + + /** + * Constant for the ")" key. + * @since 1.2 + */ + public static final int VK_RIGHT_PARENTHESIS = 0x020A; + + /** + * Constant for the "_" key. + * @since 1.2 + */ + public static final int VK_UNDERSCORE = 0x020B; + + /** + * Constant for the Microsoft Windows "Windows" key. + * It is used for both the left and right version of the key. + * @see #getKeyLocation() + * @since 1.5 + */ + public static final int VK_WINDOWS = 0x020C; + + /** + * Constant for the Microsoft Windows Context Menu key. + * @since 1.5 + */ + public static final int VK_CONTEXT_MENU = 0x020D; + + /* for input method support on Asian Keyboards */ + + /* not clear what this means - listed in Microsoft Windows API */ + public static final int VK_FINAL = 0x0018; + + /** Constant for the Convert function key. */ + /* Japanese PC 106 keyboard, Japanese Solaris keyboard: henkan */ + public static final int VK_CONVERT = 0x001C; + + /** Constant for the Don't Convert function key. */ + /* Japanese PC 106 keyboard: muhenkan */ + public static final int VK_NONCONVERT = 0x001D; + + /** Constant for the Accept or Commit function key. */ + /* Japanese Solaris keyboard: kakutei */ + public static final int VK_ACCEPT = 0x001E; + + /* not clear what this means - listed in Microsoft Windows API */ + public static final int VK_MODECHANGE = 0x001F; + + /* replaced by VK_KANA_LOCK for Microsoft Windows and Solaris; + might still be used on other platforms */ + public static final int VK_KANA = 0x0015; + + /* replaced by VK_INPUT_METHOD_ON_OFF for Microsoft Windows and Solaris; + might still be used for other platforms */ + public static final int VK_KANJI = 0x0019; + + /** + * Constant for the Alphanumeric function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: eisuu */ + public static final int VK_ALPHANUMERIC = 0x00F0; + + /** + * Constant for the Katakana function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: katakana */ + public static final int VK_KATAKANA = 0x00F1; + + /** + * Constant for the Hiragana function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: hiragana */ + public static final int VK_HIRAGANA = 0x00F2; + + /** + * Constant for the Full-Width Characters function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: zenkaku */ + public static final int VK_FULL_WIDTH = 0x00F3; + + /** + * Constant for the Half-Width Characters function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: hankaku */ + public static final int VK_HALF_WIDTH = 0x00F4; + + /** + * Constant for the Roman Characters function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard: roumaji */ + public static final int VK_ROMAN_CHARACTERS = 0x00F5; + + /** + * Constant for the All Candidates function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard - VK_CONVERT + ALT: zenkouho */ + public static final int VK_ALL_CANDIDATES = 0x0100; + + /** + * Constant for the Previous Candidate function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard - VK_CONVERT + SHIFT: maekouho */ + public static final int VK_PREVIOUS_CANDIDATE = 0x0101; + + /** + * Constant for the Code Input function key. + * @since 1.2 + */ + /* Japanese PC 106 keyboard - VK_ALPHANUMERIC + ALT: kanji bangou */ + public static final int VK_CODE_INPUT = 0x0102; + + /** + * Constant for the Japanese-Katakana function key. + * This key switches to a Japanese input method and selects its Katakana input mode. + * @since 1.2 + */ + /* Japanese Macintosh keyboard - VK_JAPANESE_HIRAGANA + SHIFT */ + public static final int VK_JAPANESE_KATAKANA = 0x0103; + + /** + * Constant for the Japanese-Hiragana function key. + * This key switches to a Japanese input method and selects its Hiragana input mode. + * @since 1.2 + */ + /* Japanese Macintosh keyboard */ + public static final int VK_JAPANESE_HIRAGANA = 0x0104; + + /** + * Constant for the Japanese-Roman function key. + * This key switches to a Japanese input method and selects its Roman-Direct input mode. + * @since 1.2 + */ + /* Japanese Macintosh keyboard */ + public static final int VK_JAPANESE_ROMAN = 0x0105; + + /** + * Constant for the locking Kana function key. + * This key locks the keyboard into a Kana layout. + * @since 1.3 + */ + /* Japanese PC 106 keyboard with special Windows driver - eisuu + Control; Japanese Solaris keyboard: kana */ + public static final int VK_KANA_LOCK = 0x0106; + + /** + * Constant for the input method on/off key. + * @since 1.3 + */ + /* Japanese PC 106 keyboard: kanji. Japanese Solaris keyboard: nihongo */ + public static final int VK_INPUT_METHOD_ON_OFF = 0x0107; + + /* for Sun keyboards */ + /** @since 1.2 */ + public static final int VK_CUT = 0xFFD1; + /** @since 1.2 */ + public static final int VK_COPY = 0xFFCD; + /** @since 1.2 */ + public static final int VK_PASTE = 0xFFCF; + /** @since 1.2 */ + public static final int VK_UNDO = 0xFFCB; + /** @since 1.2 */ + public static final int VK_AGAIN = 0xFFC9; + /** @since 1.2 */ + public static final int VK_FIND = 0xFFD0; + /** @since 1.2 */ + public static final int VK_PROPS = 0xFFCA; + /** @since 1.2 */ + public static final int VK_STOP = 0xFFC8; + + /** + * Constant for the Compose function key. + * @since 1.2 + */ + public static final int VK_COMPOSE = 0xFF20; + + /** + * Constant for the AltGraph function key. + * @since 1.2 + */ + public static final int VK_ALT_GRAPH = 0xFF7E; + + /** + * Constant for the Begin key. + * @since 1.5 + */ + public static final int VK_BEGIN = 0xFF58; + + /** + * This value is used to indicate that the keyCode is unknown. + * KEY_TYPED events do not have a keyCode value; this value + * is used instead. + */ + public static final int VK_UNDEFINED = 0x0; } diff --git a/src/classes/com/sun/javafx/newt/NewtFactory.java b/src/classes/com/sun/javafx/newt/NewtFactory.java index ffd530082..f9f8678af 100755 --- a/src/classes/com/sun/javafx/newt/NewtFactory.java +++ b/src/classes/com/sun/javafx/newt/NewtFactory.java @@ -53,7 +53,13 @@ public abstract class NewtFactory { /** Generic AWT wrapped window type, if available */ public static final String AWT = "AWT"; - public static int getPropertyIntValue(String propname) { + // Work-around for initialization order problems on Mac OS X + // between native Newt and (apparently) Fmod + static { + Window.init(getWindowType()); + } + + static int getPropertyIntValue(String propname) { int i=0; String s = System.getProperty(propname); if(null!=s) { @@ -76,13 +82,11 @@ public abstract class NewtFactory { windowType = KD; } else if (osNameLowerCase.startsWith("wind")) { windowType = WINDOWS; - } else if (osNameLowerCase.startsWith("mac os x")) { - // For the time being, use the AWT on Mac OS X since - // there's no advantage to avoiding its usage -- this - // would change if we were running on the iPhone and - // didn't have an AWT + } else if (osNameLowerCase.startsWith("mac os x") || + osNameLowerCase.startsWith("darwin")) { + windowType = MACOSX; + } else if (osNameLowerCase.equals("awt")) { windowType = AWT; - //windowType = MACOSX; } else { windowType = X11; } diff --git a/src/classes/com/sun/javafx/newt/Window.java b/src/classes/com/sun/javafx/newt/Window.java index ab0588e8e..710c88bbe 100755 --- a/src/classes/com/sun/javafx/newt/Window.java +++ b/src/classes/com/sun/javafx/newt/Window.java @@ -47,6 +47,20 @@ public abstract class Window implements NativeWindow public static final boolean DEBUG_WINDOW_EVENT = false; public static final boolean DEBUG_IMPLEMENTATION = false; + // Workaround for initialization order problems on Mac OS X + // between native Newt and (apparently) Fmod -- if Fmod is + // initialized first then the connection to the window server + // breaks, leading to errors from deep within the AppKit + static void init(String type) { + if (NewtFactory.MACOSX.equals(type)) { + try { + getWindowClass(type); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + private static Class getWindowClass(String type) throws ClassNotFoundException { @@ -175,7 +189,7 @@ public abstract class Window implements NativeWindow protected int width, height, x, y; protected int eventMask; - protected String title = "AWT NewtWindow"; + protected String title = "Newt Window"; protected boolean undecorated = false; public String getTitle() { diff --git a/src/classes/com/sun/javafx/newt/awt/AWTWindow.java b/src/classes/com/sun/javafx/newt/awt/AWTWindow.java index 595e84cb0..2315cb1a4 100644 --- a/src/classes/com/sun/javafx/newt/awt/AWTWindow.java +++ b/src/classes/com/sun/javafx/newt/awt/AWTWindow.java @@ -53,6 +53,11 @@ import javax.media.opengl.GLCapabilities; public class AWTWindow extends Window { + public AWTWindow() { + super(); + title = "AWT NewtWindow"; + } + static void setWindowAlpha(java.awt.Window w, float alpha) { // hack for macosx only Object peer = w.getPeer(); diff --git a/src/classes/com/sun/javafx/newt/macosx/MacWindow.java b/src/classes/com/sun/javafx/newt/macosx/MacWindow.java index dce504f83..1eff34b79 100755 --- a/src/classes/com/sun/javafx/newt/macosx/MacWindow.java +++ b/src/classes/com/sun/javafx/newt/macosx/MacWindow.java @@ -39,13 +39,102 @@ import com.sun.javafx.newt.*; import com.sun.opengl.impl.*; public class MacWindow extends Window { + private static final boolean DEBUG = false; - private static native boolean _initIDs(); + private static native boolean initIDs(); + // Window styles + private static final int NSBorderlessWindowMask = 0; + private static final int NSTitledWindowMask = 1 << 0; + private static final int NSClosableWindowMask = 1 << 1; + private static final int NSMiniaturizableWindowMask = 1 << 2; + private static final int NSResizableWindowMask = 1 << 3; + + // Window backing store types + private static final int NSBackingStoreRetained = 0; + private static final int NSBackingStoreNonretained = 1; + private static final int NSBackingStoreBuffered = 2; + + // Key constants handled differently on Mac OS X than other platforms + private static final int NSUpArrowFunctionKey = 0xF700; + private static final int NSDownArrowFunctionKey = 0xF701; + private static final int NSLeftArrowFunctionKey = 0xF702; + private static final int NSRightArrowFunctionKey = 0xF703; + private static final int NSF1FunctionKey = 0xF704; + private static final int NSF2FunctionKey = 0xF705; + private static final int NSF3FunctionKey = 0xF706; + private static final int NSF4FunctionKey = 0xF707; + private static final int NSF5FunctionKey = 0xF708; + private static final int NSF6FunctionKey = 0xF709; + private static final int NSF7FunctionKey = 0xF70A; + private static final int NSF8FunctionKey = 0xF70B; + private static final int NSF9FunctionKey = 0xF70C; + private static final int NSF10FunctionKey = 0xF70D; + private static final int NSF11FunctionKey = 0xF70E; + private static final int NSF12FunctionKey = 0xF70F; + private static final int NSF13FunctionKey = 0xF710; + private static final int NSF14FunctionKey = 0xF711; + private static final int NSF15FunctionKey = 0xF712; + private static final int NSF16FunctionKey = 0xF713; + private static final int NSF17FunctionKey = 0xF714; + private static final int NSF18FunctionKey = 0xF715; + private static final int NSF19FunctionKey = 0xF716; + private static final int NSF20FunctionKey = 0xF717; + private static final int NSF21FunctionKey = 0xF718; + private static final int NSF22FunctionKey = 0xF719; + private static final int NSF23FunctionKey = 0xF71A; + private static final int NSF24FunctionKey = 0xF71B; + private static final int NSF25FunctionKey = 0xF71C; + private static final int NSF26FunctionKey = 0xF71D; + private static final int NSF27FunctionKey = 0xF71E; + private static final int NSF28FunctionKey = 0xF71F; + private static final int NSF29FunctionKey = 0xF720; + private static final int NSF30FunctionKey = 0xF721; + private static final int NSF31FunctionKey = 0xF722; + private static final int NSF32FunctionKey = 0xF723; + private static final int NSF33FunctionKey = 0xF724; + private static final int NSF34FunctionKey = 0xF725; + private static final int NSF35FunctionKey = 0xF726; + private static final int NSInsertFunctionKey = 0xF727; + private static final int NSDeleteFunctionKey = 0xF728; + private static final int NSHomeFunctionKey = 0xF729; + private static final int NSBeginFunctionKey = 0xF72A; + private static final int NSEndFunctionKey = 0xF72B; + private static final int NSPageUpFunctionKey = 0xF72C; + private static final int NSPageDownFunctionKey = 0xF72D; + private static final int NSPrintScreenFunctionKey = 0xF72E; + private static final int NSScrollLockFunctionKey = 0xF72F; + private static final int NSPauseFunctionKey = 0xF730; + private static final int NSSysReqFunctionKey = 0xF731; + private static final int NSBreakFunctionKey = 0xF732; + private static final int NSResetFunctionKey = 0xF733; + private static final int NSStopFunctionKey = 0xF734; + private static final int NSMenuFunctionKey = 0xF735; + private static final int NSUserFunctionKey = 0xF736; + private static final int NSSystemFunctionKey = 0xF737; + private static final int NSPrintFunctionKey = 0xF738; + private static final int NSClearLineFunctionKey = 0xF739; + private static final int NSClearDisplayFunctionKey = 0xF73A; + private static final int NSInsertLineFunctionKey = 0xF73B; + private static final int NSDeleteLineFunctionKey = 0xF73C; + private static final int NSInsertCharFunctionKey = 0xF73D; + private static final int NSDeleteCharFunctionKey = 0xF73E; + private static final int NSPrevFunctionKey = 0xF73F; + private static final int NSNextFunctionKey = 0xF740; + private static final int NSSelectFunctionKey = 0xF741; + private static final int NSExecuteFunctionKey = 0xF742; + private static final int NSUndoFunctionKey = 0xF743; + private static final int NSRedoFunctionKey = 0xF744; + private static final int NSFindFunctionKey = 0xF745; + private static final int NSHelpFunctionKey = 0xF746; + private static final int NSModeSwitchFunctionKey = 0xF747; + + private long nativeWindow; + static { NativeLibLoader.loadNEWT(); - if (_initIDs() == false) { + if (!initIDs()) { throw new RuntimeException("Failed to initialize jmethodIDs"); } } @@ -53,60 +142,201 @@ public class MacWindow extends Window { public MacWindow() { } - protected final void createNative(GLCapabilities caps) { + protected void createNative(GLCapabilities caps) { chosenCaps = (GLCapabilities) caps.clone(); // FIXME: visualID := f1(caps); caps := f2(visualID) visualID = 0; // n/a } - protected final void closeNative() { + protected void closeNative() { + if (nativeWindow != 0) { + close0(nativeWindow); + nativeWindow = 0; + } } public long getSurfaceHandle() { - return 0; - } - - public final int getDisplayWidth() { - return 640; - } - - public final int getDisplayHeight() { - return 480; + if (nativeWindow == 0) { + return 0; + } + return contentView(nativeWindow); } - public final void setVisible(boolean visible) { + public void setVisible(boolean visible) { + if (visible) { + boolean created = false; + if (nativeWindow == 0) { + nativeWindow = createWindow(getX(), getY(), getWidth(), getHeight(), + (isUndecorated() ? + NSBorderlessWindowMask : + NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask), + NSBackingStoreBuffered, + true); + setTitle0(nativeWindow, getTitle()); + created = true; + } + makeKeyAndOrderFront(nativeWindow); + if (created) { + sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); + } + } else { + if (nativeWindow != 0) { + orderOut(nativeWindow); + } + } + + this.visible = visible; } - public final void setSize(int width, int height) { + public void setSize(int width, int height) { + this.width = width; + this.height = height; + if (nativeWindow != 0) { + setContentSize(nativeWindow, width, height); + } } - public final void setPosition(int x, int y) { + public void setPosition(int x, int y) { + this.x = x; + this.y = y; + if (nativeWindow != 0) { + setFrameTopLeftPoint(nativeWindow, x, y); + } } public boolean setFullscreen(boolean fullscreen) { - return true; + // FIXME: implement this + return false; } - protected final void dispatchMessages(int eventMask) { - - } - -/* private void sizeChanged(int newWidth, int newHeight) { - width = newWidth; - height = newHeight; - sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); + if (DEBUG) { + System.out.println("Size changed to " + newWidth + ", " + newHeight); + } + if (width != newWidth || height != newHeight) { + width = newWidth; + height = newHeight; + if (DEBUG) { + System.out.println(" Posted WINDOW_RESIZED event"); + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); + } } - + private void positionChanged(int newX, int newY) { - x = newX; - y = newY; - sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); + if (DEBUG) { + System.out.println("Position changed to " + newX + ", " + newY); + } + if (x != newX || y != newY) { + x = newX; + y = newY; + if (DEBUG) { + System.out.println(" Posted WINDOW_MOVED event"); + } + sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); + } } - + private void windowClosed() { + nativeWindow = 0; + visible = false; } - - private void windowDestroyed() { + + private char convertKeyChar(char keyChar) { + if (keyChar >= NSUpArrowFunctionKey && keyChar <= NSModeSwitchFunctionKey) { + switch (keyChar) { + case NSUpArrowFunctionKey: return KeyEvent.VK_UP; + case NSDownArrowFunctionKey: return KeyEvent.VK_DOWN; + case NSLeftArrowFunctionKey: return KeyEvent.VK_LEFT; + case NSRightArrowFunctionKey: return KeyEvent.VK_RIGHT; + case NSF1FunctionKey: return KeyEvent.VK_F1; + case NSF2FunctionKey: return KeyEvent.VK_F2; + case NSF3FunctionKey: return KeyEvent.VK_F3; + case NSF4FunctionKey: return KeyEvent.VK_F4; + case NSF5FunctionKey: return KeyEvent.VK_F5; + case NSF6FunctionKey: return KeyEvent.VK_F6; + case NSF7FunctionKey: return KeyEvent.VK_F7; + case NSF8FunctionKey: return KeyEvent.VK_F8; + case NSF9FunctionKey: return KeyEvent.VK_F9; + case NSF10FunctionKey: return KeyEvent.VK_F10; + case NSF11FunctionKey: return KeyEvent.VK_F11; + case NSF12FunctionKey: return KeyEvent.VK_F12; + case NSF13FunctionKey: return KeyEvent.VK_F13; + case NSF14FunctionKey: return KeyEvent.VK_F14; + case NSF15FunctionKey: return KeyEvent.VK_F15; + case NSF16FunctionKey: return KeyEvent.VK_F16; + case NSF17FunctionKey: return KeyEvent.VK_F17; + case NSF18FunctionKey: return KeyEvent.VK_F18; + case NSF19FunctionKey: return KeyEvent.VK_F19; + case NSF20FunctionKey: return KeyEvent.VK_F20; + case NSF21FunctionKey: return KeyEvent.VK_F21; + case NSF22FunctionKey: return KeyEvent.VK_F22; + case NSF23FunctionKey: return KeyEvent.VK_F23; + case NSF24FunctionKey: return KeyEvent.VK_F24; + case NSInsertFunctionKey: return KeyEvent.VK_INSERT; + case NSDeleteFunctionKey: return KeyEvent.VK_DELETE; + case NSHomeFunctionKey: return KeyEvent.VK_HOME; + case NSBeginFunctionKey: return KeyEvent.VK_BEGIN; + case NSEndFunctionKey: return KeyEvent.VK_END; + case NSPageUpFunctionKey: return KeyEvent.VK_PAGE_UP; + case NSPageDownFunctionKey: return KeyEvent.VK_PAGE_DOWN; + case NSPrintScreenFunctionKey: return KeyEvent.VK_PRINTSCREEN; + case NSScrollLockFunctionKey: return KeyEvent.VK_SCROLL_LOCK; + case NSPauseFunctionKey: return KeyEvent.VK_PAUSE; + // Not handled: + // NSSysReqFunctionKey + // NSBreakFunctionKey + // NSResetFunctionKey + case NSStopFunctionKey: return KeyEvent.VK_STOP; + // Not handled: + // NSMenuFunctionKey + // NSUserFunctionKey + // NSSystemFunctionKey + // NSPrintFunctionKey + // NSClearLineFunctionKey + // NSClearDisplayFunctionKey + // NSInsertLineFunctionKey + // NSDeleteLineFunctionKey + // NSInsertCharFunctionKey + // NSDeleteCharFunctionKey + // NSPrevFunctionKey + // NSNextFunctionKey + // NSSelectFunctionKey + // NSExecuteFunctionKey + // NSUndoFunctionKey + // NSRedoFunctionKey + // NSFindFunctionKey + // NSHelpFunctionKey + // NSModeSwitchFunctionKey + default: break; + } + } + + // NSEvent's charactersIgnoringModifiers doesn't ignore the shift key + if (keyChar >= 'a' && keyChar <= 'z') { + return Character.toUpperCase(keyChar); + } + + return keyChar; + } + + protected void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) { + keyChar = convertKeyChar(keyChar); + // Note that we send the key char for the key code on this + // platform -- we do not get any useful key codes out of the system + super.sendKeyEvent(eventType, modifiers, keyChar, keyChar); } -*/ + + private native long createWindow(int x, int y, int w, int h, + int windowStyle, + int backingStoreType, + boolean deferCreation); + private native void makeKeyAndOrderFront(long window); + private native void orderOut(long window); + private native void close0(long window); + private native void setTitle0(long window, String title); + protected native void dispatchMessages(int eventMask); + private native long contentView(long window); + private native void setContentSize(long window, int w, int h); + private native void setFrameTopLeftPoint(long window, int x, int y); } diff --git a/src/classes/com/sun/opengl/util/texture/TextureIO.java.javase b/src/classes/com/sun/opengl/util/texture/TextureIO.java.javase index aa2cb1799..29912db24 100755 --- a/src/classes/com/sun/opengl/util/texture/TextureIO.java.javase +++ b/src/classes/com/sun/opengl/util/texture/TextureIO.java.javase @@ -736,6 +736,10 @@ public class TextureIO { if (DEBUG) { e.printStackTrace(); } + } catch (Error e) { + if (DEBUG) { + e.printStackTrace(); + } } // Other special-case writers diff --git a/src/classes/javax/media/opengl/GLDrawableFactory.java b/src/classes/javax/media/opengl/GLDrawableFactory.java index 677441572..dbbb42a0e 100644 --- a/src/classes/javax/media/opengl/GLDrawableFactory.java +++ b/src/classes/javax/media/opengl/GLDrawableFactory.java @@ -121,7 +121,8 @@ public abstract class GLDrawableFactory { if (factoryClassName == null) { if (osNameLowerCase.startsWith("windows")) { factoryClassName = "com.sun.opengl.impl.windows.wgl.WindowsWGLDrawableFactory"; - } else if (osNameLowerCase.startsWith("mac os x")) { + } else if (osNameLowerCase.startsWith("mac os x") || + osNameLowerCase.startsWith("darwin")) { // FIXME: remove this residual dependence on the AWT factoryClassName = "com.sun.opengl.impl.macosx.cgl.awt.MacOSXAWTCGLDrawableFactory"; } else { diff --git a/src/native/newt/MacWindow.c b/src/native/newt/InputEvent.h index 8de574ef3..1284a8535 100755..100644 --- a/src/native/newt/MacWindow.c +++ b/src/native/newt/InputEvent.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -31,21 +31,13 @@ * */ -#include "com_sun_javafx_newt_macosx_MacWindow.h" +#ifndef _INPUT_EVENT_H_ +#define _INPUT_EVENT_H_ -#include "EventListener.h" -#include "MouseEvent.h" -#include "KeyEvent.h" +#define EVENT_SHIFT_MASK 1 +#define EVENT_CTRL_MASK 2 +#define EVENT_META_MASK 4 +#define EVENT_ALT_MASK 8 +#define EVENT_ALT_GRAPH_MASK 32 -#include <stdio.h> - -/* - * Class: com_sun_javafx_newt_macosx_MacWindow - * Method: _initIDs - * Signature: ()Z - */ -JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_macosx_MacWindow__1initIDs - (JNIEnv *env, jclass clazz) -{ - return JNI_TRUE; -} +#endif diff --git a/src/native/newt/MacWindow.m b/src/native/newt/MacWindow.m new file mode 100644 index 000000000..f6b2bf5b2 --- /dev/null +++ b/src/native/newt/MacWindow.m @@ -0,0 +1,268 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +#import <inttypes.h> + +#import "com_sun_javafx_newt_macosx_MacWindow.h" +#import "NewtMacWindow.h" + +#import "EventListener.h" +#import "MouseEvent.h" +#import "KeyEvent.h" + +#import <ApplicationServices/ApplicationServices.h> + +#import <stdio.h> + +NSString* jstringToNSString(JNIEnv* env, jstring jstr) +{ + const jchar* jstrChars = (*env)->GetStringChars(env, jstr, NULL); + NSString* str = [[NSString alloc] initWithCharacters: jstrChars length: (*env)->GetStringLength(env, jstr)]; + (*env)->ReleaseStringChars(env, jstr, jstrChars); + return str; +} + +static BOOL initializedMenuHeight = NO; +static CGFloat menuHeight = 0; + +void setFrameTopLeftPoint(NSWindow* win, jint x, jint y) +{ + NSScreen* screen = [NSScreen mainScreen]; + NSRect screenRect = [screen frame]; + NSPoint pt; + + if (!initializedMenuHeight) { + NSMenu* menu = [NSApp mainMenu]; + BOOL mustRelease = NO; + + if (menu == nil) { + printf("main menu was nil, trying services menu\n"); + menu = [NSApp servicesMenu]; + } + + if (menu == nil) { + printf("services menu was nil, trying an empty menu instance\n"); + menu = [[[NSMenu alloc] initWithTitle: @"Foo"] retain]; + mustRelease = YES; + } + + menuHeight = [menu menuBarHeight]; + + if (mustRelease) { + [menu release]; + } + + initializedMenuHeight = YES; + } + + pt = NSMakePoint(x, screenRect.origin.y + screenRect.size.height - menuHeight - y); + [win setFrameTopLeftPoint: pt]; +} + +/* + * Class: com_sun_javafx_newt_macosx_MacWindow + * Method: initIDs + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_initIDs + (JNIEnv *env, jclass clazz) +{ + // This little bit of magic is needed in order to receive mouse + // motion events and allow key focus to be properly transferred. + // FIXME: are these Carbon APIs? They come from the + // ApplicationServices.framework. + ProcessSerialNumber psn; + if (GetCurrentProcess(&psn) == noErr) { + TransformProcessType(&psn, kProcessTransformToForegroundApplication); + SetFrontProcess(&psn); + } + + // Initialize the shared NSApplication instance + [NSApplication sharedApplication]; + + // Need this when debugging, as it is necessary to attach gdb to + // the running java process -- "gdb java" doesn't work + // printf("Going to sleep for 10 seconds\n"); + // sleep(10); + + return (jboolean) [NewtMacWindow initNatives: env forClass: clazz]; +} + +/* + * Class: com_sun_javafx_newt_macosx_MacWindow + * Method: createWindow + * Signature: (IIIIIIZ)J + */ +JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_createWindow + (JNIEnv *env, jobject jthis, jint x, jint y, jint w, jint h, jint styleMask, jint bufferingType, jboolean deferCreation) +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSRect rect = NSMakeRect(x, y, w, h); + jobject windowObj = (*env)->NewGlobalRef(env, jthis); + + // Allocate the window + NSWindow* window = [[[NewtMacWindow alloc] initWithContentRect: rect + styleMask: (NSUInteger) styleMask + backing: (NSBackingStoreType) bufferingType + defer: YES + javaWindowObject: windowObj] retain]; + + // Immediately re-position the window based on an upper-left coordinate system + setFrameTopLeftPoint(window, x, y); + + // Allocate an NSView + NSView* view = [[NSView alloc] initWithFrame: rect]; + + // specify we want mouse-moved events + [window setAcceptsMouseMovedEvents:YES]; + + // Set the content view + [window setContentView: view]; + + [pool release]; + + return (jlong) ((intptr_t) window); +} + +/* + * Class: com_sun_javafx_newt_macosx_MacWindow + * Method: makeKeyAndOrderFront + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_makeKeyAndOrderFront + (JNIEnv *env, jobject unused, jlong window) +{ + NSWindow* win = (NSWindow*) ((intptr_t) window); + [win makeKeyAndOrderFront: win]; +} + +/* + * Class: com_sun_javafx_newt_macosx_MacWindow + * Method: orderOut + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_orderOut + (JNIEnv *env, jobject unused, jlong window) +{ + NSWindow* win = (NSWindow*) ((intptr_t) window); + [win orderOut: win]; +} + +/* + * Class: com_sun_javafx_newt_macosx_MacWindow + * Method: close0 + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_close0 + (JNIEnv *env, jobject unused, jlong window) +{ + NSWindow* win = (NSWindow*) ((intptr_t) window); + [win close]; +} + +/* + * Class: com_sun_javafx_newt_macosx_MacWindow + * Method: setTitle0 + * Signature: (JLjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_setTitle0 + (JNIEnv *env, jobject unused, jlong window, jstring title) +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSWindow* win = (NSWindow*) ((intptr_t) window); + NSString* str = jstringToNSString(env, title); + [str autorelease]; + [win setTitle: str]; + [pool release]; +} + +/* + * Class: com_sun_javafx_newt_macosx_MacWindow + * Method: dispatchMessages + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_dispatchMessages + (JNIEnv *env, jobject unused, jint eventMask) +{ + NSEvent* event = NULL; + + [NewtMacWindow setJNIEnv: env]; + do { + // FIXME: ignoring event mask for the time being + event = [NSApp nextEventMatchingMask: NSAnyEventMask + untilDate: [NSDate distantPast] + inMode: NSDefaultRunLoopMode + dequeue: YES]; + if (event != NULL) { + [NSApp sendEvent: event]; + } + } while (event != NULL); + [NewtMacWindow setJNIEnv: NULL]; +} + +/* + * Class: com_sun_javafx_newt_macosx_MacWindow + * Method: contentView + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_contentView + (JNIEnv *env, jobject unused, jlong window) +{ + NSWindow* win = (NSWindow*) ((intptr_t) window); + return (jlong) ((intptr_t) [win contentView]); +} + +/* + * Class: com_sun_javafx_newt_macosx_MacWindow + * Method: setContentSize + * Signature: (JII)V + */ +JNIEXPORT void JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_setContentSize + (JNIEnv *env, jobject unused, jlong window, jint w, jint h) +{ + NSWindow* win = (NSWindow*) ((intptr_t) window); + NSSize sz = NSMakeSize(w, h); + [win setContentSize: sz]; +} + +/* + * Class: com_sun_javafx_newt_macosx_MacWindow + * Method: setFrameTopLeftPoint + * Signature: (JII)V + */ +JNIEXPORT void JNICALL Java_com_sun_javafx_newt_macosx_MacWindow_setFrameTopLeftPoint + (JNIEnv *env, jobject unused, jlong window, jint x, jint y) +{ + NSWindow* win = (NSWindow*) ((intptr_t) window); + setFrameTopLeftPoint(win, x, y); +} diff --git a/src/native/newt/NewtMacWindow.h b/src/native/newt/NewtMacWindow.h new file mode 100644 index 000000000..971661ebf --- /dev/null +++ b/src/native/newt/NewtMacWindow.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +#import <AppKit/AppKit.h> +#import "jni.h" + +@interface NewtMacWindow : NSWindow +{ + jobject javaWindowObject; +} + ++ (BOOL) initNatives: (JNIEnv*) env forClass: (jobject) clazz; + +/* Set and cleared during event dispatching cycle */ ++ (void) setJNIEnv: (JNIEnv*) env; + +- (id) initWithContentRect: (NSRect) contentRect + styleMask: (NSUInteger) windowStyle + backing: (NSBackingStoreType) bufferingType + defer: (BOOL) deferCreation + javaWindowObject: (jobject) javaWindowObj; + +@end diff --git a/src/native/newt/NewtMacWindow.m b/src/native/newt/NewtMacWindow.m new file mode 100644 index 000000000..5655f2fa6 --- /dev/null +++ b/src/native/newt/NewtMacWindow.m @@ -0,0 +1,274 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +#import "NewtMacWindow.h" +#import "InputEvent.h" +#import "KeyEvent.h" +#import "MouseEvent.h" + +static jmethodID sendMouseEventID = NULL; +static jmethodID sendKeyEventID = NULL; +static jmethodID sizeChangedID = NULL; +static jmethodID positionChangedID = NULL; +static jmethodID windowClosedID = NULL; + +// This is set while messages are being dispatched and cleared afterward +static JNIEnv* env = NULL; + +@implementation NewtMacWindow + ++ (BOOL) initNatives: (JNIEnv*) env forClass: (jclass) clazz +{ + sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIII)V"); + sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V"); + sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(II)V"); + positionChangedID = (*env)->GetMethodID(env, clazz, "positionChanged", "(II)V"); + windowClosedID = (*env)->GetMethodID(env, clazz, "windowClosed", "()V"); + if (sendMouseEventID && sendKeyEventID && sizeChangedID && positionChangedID && windowClosedID) { + return YES; + } + return NO; +} + ++ (void) setJNIEnv: (JNIEnv*) theEnv +{ + env = theEnv; +} + +- (id) initWithContentRect: (NSRect) contentRect + styleMask: (NSUInteger) windowStyle + backing: (NSBackingStoreType) bufferingType + defer: (BOOL) deferCreation + javaWindowObject: (jobject) javaWindowObj +{ + id res = [super initWithContentRect: contentRect + styleMask: windowStyle + backing: bufferingType + defer: deferCreation]; + javaWindowObject = javaWindowObj; + // Why is this necessary? Without it we don't get any of the + // delegate methods like resizing and window movement. + [self setDelegate: self]; + return res; +} + +static jint mods2JavaMods(NSUInteger mods) +{ + int javaMods = 0; + if (mods & NSShiftKeyMask) { + javaMods |= EVENT_SHIFT_MASK; + } + if (mods & NSControlKeyMask) { + javaMods |= EVENT_CTRL_MASK; + } + if (mods & NSCommandKeyMask) { + javaMods |= EVENT_META_MASK; + } + if (mods & NSAlternateKeyMask) { + javaMods |= EVENT_ALT_MASK; + } + return javaMods; +} + +- (void) sendKeyEvent: (NSEvent*) event eventType: (jint) evType +{ + int i; + jint keyCode = (jint) [event keyCode]; + NSString* chars = [event charactersIgnoringModifiers]; + int len = [chars length]; + jint javaMods = mods2JavaMods([event modifierFlags]); + + if (env == NULL) { + return; + } + + if (javaWindowObject == NULL) { + return; + } + + for (i = 0; i < len; i++) { + // Note: the key code in the NSEvent does not map to anything we can use + jchar keyChar = (jchar) [chars characterAtIndex: i]; + + (*env)->CallVoidMethod(env, javaWindowObject, sendKeyEventID, + evType, javaMods, keyCode, keyChar); + } +} + +- (void) keyDown: (NSEvent*) theEvent +{ + [self sendKeyEvent: theEvent eventType: EVENT_KEY_PRESSED]; +} + +- (void) keyUp: (NSEvent*) theEvent +{ + [self sendKeyEvent: theEvent eventType: EVENT_KEY_RELEASED]; +} + +- (void) sendMouseEvent: (NSEvent*) event eventType: (jint) evType +{ + jint javaMods = mods2JavaMods([event modifierFlags]); + NSPoint location = [event locationInWindow]; + NSRect frameRect = [self frame]; + NSRect contentRect = [self contentRectForFrameRect: frameRect]; + + if (env == NULL) { + return; + } + + if (javaWindowObject == NULL) { + return; + } + + // 1-base the button number + (*env)->CallVoidMethod(env, javaWindowObject, sendMouseEventID, + evType, javaMods, + (jint) location.x, + (jint) (contentRect.size.height - location.y), + (jint) (1 + [event buttonNumber])); +} + +- (void) mouseEntered: (NSEvent*) theEvent +{ + [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_ENTERED]; +} + +- (void) mouseExited: (NSEvent*) theEvent +{ + [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_EXITED]; +} + +- (void) mouseMoved: (NSEvent*) theEvent +{ + [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_MOVED]; +} + +- (void) mouseDown: (NSEvent*) theEvent +{ + [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_PRESSED]; +} + +- (void) mouseDragged: (NSEvent*) theEvent +{ + // Note use of MOUSE_MOVED event type because mouse dragged events are synthesized by Java + [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_MOVED]; +} + +- (void) mouseUp: (NSEvent*) theEvent +{ + [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_RELEASED]; +} + +- (void) rightMouseDown: (NSEvent*) theEvent +{ + [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_PRESSED]; +} + +- (void) rightMouseDragged: (NSEvent*) theEvent +{ + // Note use of MOUSE_MOVED event type because mouse dragged events are synthesized by Java + [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_MOVED]; +} + +- (void) rightMouseUp: (NSEvent*) theEvent +{ + [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_RELEASED]; +} + +- (void) otherMouseDown: (NSEvent*) theEvent +{ + [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_PRESSED]; +} + +- (void) otherMouseDragged: (NSEvent*) theEvent +{ + // Note use of MOUSE_MOVED event type because mouse dragged events are synthesized by Java + [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_MOVED]; +} + +- (void) otherMouseUp: (NSEvent*) theEvent +{ + [self sendMouseEvent: theEvent eventType: EVENT_MOUSE_RELEASED]; +} + +- (void)windowDidResize: (NSNotification*) notification +{ + NSRect frameRect = [self frame]; + NSRect contentRect = [self contentRectForFrameRect: frameRect]; + + if (env == NULL) { + return; + } + + if (javaWindowObject == NULL) { + return; + } + + (*env)->CallVoidMethod(env, javaWindowObject, sizeChangedID, + (jint) contentRect.size.width, + (jint) contentRect.size.height); +} + +- (void)windowDidMove: (NSNotification*) notification +{ + NSRect rect = [self frame]; + + if (env == NULL) { + return; + } + + if (javaWindowObject == NULL) { + return; + } + + // FIXME: this result isn't consistent with setFrameTopLeftPoint + + (*env)->CallVoidMethod(env, javaWindowObject, positionChangedID, + (jint) rect.origin.x, + (jint) rect.origin.y); +} + +- (void)windowWillClose: (NSNotification*) notification +{ + if (env == NULL) { + return; + } + + if (javaWindowObject == NULL) { + return; + } + + (*env)->CallVoidMethod(env, javaWindowObject, windowClosedID); +} + +@end |