New Sys.openURL command added

This commit is contained in:
Caspian Rychlik-Prince 2003-10-28 16:23:17 +00:00
parent 9ad6b5eb1f
commit 754f917730
6 changed files with 127 additions and 23 deletions

View File

@ -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);
}

View File

@ -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
}

View File

@ -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);
}

View File

@ -42,6 +42,7 @@
#include <sched.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <Carbon/Carbon.h>
#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);
}
}

View File

@ -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 );
}

View File

@ -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);
}
/**