From 754f9177304442e4bafe65eeda0710fb53fef79d Mon Sep 17 00:00:00 2001 From: Caspian Rychlik-Prince Date: Tue, 28 Oct 2003 16:23:17 +0000 Subject: [PATCH] New Sys.openURL command added --- src/java/org/lwjgl/Sys.java | 13 ++++++ src/native/common/org_lwjgl_Sys.h | 8 ++-- src/native/linux/org_lwjgl_Sys.cpp | 47 ++++++++++++++-------- src/native/macosx/org_lwjgl_Sys.cpp | 33 ++++++++++++++- src/native/win32/org_lwjgl_Sys.cpp | 47 ++++++++++++++++++++++ src/native/win32/org_lwjgl_input_Mouse.cpp | 2 +- 6 files changed, 127 insertions(+), 23 deletions(-) diff --git a/src/java/org/lwjgl/Sys.java b/src/java/org/lwjgl/Sys.java index 7c2bcd43..b067c3c8 100644 --- a/src/java/org/lwjgl/Sys.java +++ b/src/java/org/lwjgl/Sys.java @@ -213,4 +213,17 @@ public final class Sys { * public static native int getDirectBufferAddress(Buffer buf); */ + + /** + * Open the system web browser and point it at the specified URL. It is recommended + * that this not be called whilst your game is running, but on application exit in + * a shutdown hook, as the screen resolution will not be reset when the browser is + * brought into view. + * + * There is no guarantee that this will work, nor that we can detect if it has + * failed - hence we don't return success code or throw an Exception. This is just a + * best attempt at opening the URL given - don't rely on it to work! + * @param url The URL + */ + public static native void openURL(String url); } diff --git a/src/native/common/org_lwjgl_Sys.h b/src/native/common/org_lwjgl_Sys.h index 8da2e8b2..128a9574 100644 --- a/src/native/common/org_lwjgl_Sys.h +++ b/src/native/common/org_lwjgl_Sys.h @@ -62,11 +62,11 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_alert /* * Class: org_lwjgl_Sys - * Method: getDirectBufferAddress - * Signature: (Ljava/nio/Buffer;)I -JNIEXPORT jint JNICALL Java_org_lwjgl_Sys_getDirectBufferAddress - (JNIEnv *, jclass, jobject); + * Method: openURL + * Signature: (Ljava/lang/String;)V */ +JNIEXPORT void JNICALL Java_org_lwjgl_Sys_openURL + (JNIEnv *, jclass, jstring); #ifdef __cplusplus } diff --git a/src/native/linux/org_lwjgl_Sys.cpp b/src/native/linux/org_lwjgl_Sys.cpp index 0740fd38..97f9e41a 100644 --- a/src/native/linux/org_lwjgl_Sys.cpp +++ b/src/native/linux/org_lwjgl_Sys.cpp @@ -1,35 +1,35 @@ -/* +/* * Copyright (c) 2002 Light Weight Java Game Library Project * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are + * modification, are permitted provided that the following conditions are * met: - * - * * Redistributions of source code must retain the above copyright + * + * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions 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 'Light Weight Java Game Library' nor the names of - * its contributors may be used to endorse or promote products derived + * * Neither the name of 'Light Weight Java Game Library' nor the names of + * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - + /** * $Id$ * @@ -65,7 +65,7 @@ static long queryTime(void) { #ifdef _DEBUG printf("Could not read current time\n"); #endif - } + } long result = tv.tv_sec * 1000000l + tv.tv_usec; return result; @@ -109,7 +109,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setProcessPriority int linux_priority; int max_pri, min_pri; struct sched_param sched_pri; - + if (sched_getscheduler(0) != SCHED_OTHER) { // Reset scheduler to normal sched_pri.sched_priority = 0; @@ -120,7 +120,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setProcessPriority return; } } - + switch (priority) { case org_lwjgl_Sys_REALTIME_PRIORITY: min_pri = sched_get_priority_min(SCHED_FIFO); @@ -174,3 +174,16 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_alert(JNIEnv * env, jclass clazz, jstr env->ReleaseStringUTFChars(message, eMessageText); env->ReleaseStringUTFChars(title, cTitleBarText); } + +/* + * Class: org_lwjgl_Sys + * Method: openURL + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_lwjgl_Sys_openURL + (JNIEnv * env, jclass clazz, jstring url) +{ + const char * urlString = env->GetStringUTFChars(url, NULL); + printf("*** Please visit %s\n", urlString); + env->ReleaseStringUTFChars(url, urlString); +} \ No newline at end of file diff --git a/src/native/macosx/org_lwjgl_Sys.cpp b/src/native/macosx/org_lwjgl_Sys.cpp index b8ec1c8e..21f2321c 100644 --- a/src/native/macosx/org_lwjgl_Sys.cpp +++ b/src/native/macosx/org_lwjgl_Sys.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include "org_lwjgl_Sys.h" long int hires_timer_freq; // Hires timer frequency @@ -106,7 +107,9 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setTime JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setProcessPriority (JNIEnv * env, jclass clazz, jint priority) { - printf("Unsupported"); +#ifdef _DEBUG + printf("Unsupported\n"); +#endif } /* @@ -124,3 +127,31 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_alert(JNIEnv * env, jclass clazz, jstr env->ReleaseStringUTFChars(message, eMessageText); env->ReleaseStringUTFChars(title, cTitleBarText); } + +/* + * Class: org_lwjgl_Sys + * Method: openURL + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_lwjgl_Sys_openURL + (JNIEnv * env, jclass clazz, jstring url) +{ + const char * urlString = env->GetStringUTFChars(url, NULL); + + OSStatus err; + ICInstance inst; + long startSel; + long endSel; + Str255 urlStr; + + CopyCStringToPascal(urlString, urlStr); + env->ReleaseStringUTFChars(url, urlString); + + err = ICStart(&inst, '????'); // Use your creator code if you have one! + if (err == noErr) { + startSel = 0; + endSel = urlStr[0]; + err = ICLaunchURL(inst, "\p", (char *) &urlStr[1], urlStr[0], &startSel, &endSel); + (void) ICStop(inst); + } +} \ No newline at end of file diff --git a/src/native/win32/org_lwjgl_Sys.cpp b/src/native/win32/org_lwjgl_Sys.cpp index 17fe3484..4c91c79e 100644 --- a/src/native/win32/org_lwjgl_Sys.cpp +++ b/src/native/win32/org_lwjgl_Sys.cpp @@ -153,3 +153,50 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_Sys_getDirectBufferAddress return (jint) env->GetDirectBufferAddress(buf); } */ + +/* + * Class: org_lwjgl_Sys + * Method: openURL + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_lwjgl_Sys_openURL + (JNIEnv * env, jclass clazz, jstring url) +{ + const char * urlString = env->GetStringUTFChars(url, NULL); + + char command[256]; + strcpy(command, ""); + strcat(command, "rundll32 url.dll,FileProtocolHandler "); + strncat(command, urlString, 200); // Prevent buffer overflow + env->ReleaseStringUTFChars(url, urlString); + + STARTUPINFO si; + PROCESS_INFORMATION pi; + + ZeroMemory( &si, sizeof(si) ); + si.cb = sizeof(si); + ZeroMemory( &pi, sizeof(pi) ); + + // Start the child process. + if( !CreateProcess( NULL, // No module name (use command line). + command, // Command line. + NULL, // Process handle not inheritable. + NULL, // Thread handle not inheritable. + FALSE, // Set handle inheritance to FALSE. + 0, // No creation flags. + NULL, // Use parent's environment block. + NULL, // Use parent's starting directory. + &si, // Pointer to STARTUPINFO structure. + &pi ) // Pointer to PROCESS_INFORMATION structure. + ) + { +#ifdef _DEBUG + printf("Failed to open URL %s\n", urlString); +#endif + } + + // Close process and thread handles. + CloseHandle( pi.hProcess ); + CloseHandle( pi.hThread ); + +} diff --git a/src/native/win32/org_lwjgl_input_Mouse.cpp b/src/native/win32/org_lwjgl_input_Mouse.cpp index 177665ba..85f9dd92 100644 --- a/src/native/win32/org_lwjgl_input_Mouse.cpp +++ b/src/native/win32/org_lwjgl_input_Mouse.cpp @@ -515,7 +515,7 @@ static void UpdateMouseFields(JNIEnv *env, jclass clsMouse) { } } jbyteArray mButtonsArray = (jbyteArray) env->GetStaticObjectField(clsMouse, fidMButtons); - env->SetByteArrayRegion(mButtonsArray, 0, mButtoncount, diMouseState.rgbButtons); + env->SetByteArrayRegion(mButtonsArray, 0, mButtoncount, (const signed char *) diMouseState.rgbButtons); } /**