Windows: Moved NativeSysImplementation.java to WindowsSysImplementation.java and moved some native code to java.

This commit is contained in:
Elias Naur 2006-07-15 19:45:36 +00:00
parent 008c59a301
commit d9afe6b784
6 changed files with 32 additions and 133 deletions

View File

@ -514,7 +514,7 @@
<class name="org.lwjgl.opengl.WindowsPbufferPeerInfo" />
<class name="org.lwjgl.opengl.WindowsDisplay" />
<class name="org.lwjgl.opengl.WindowsRegistry" />
<class name="org.lwjgl.NativeSysImplementation" />
<class name="org.lwjgl.WindowsSysImplementation" />
<class name="org.lwjgl.opengl.WindowsAWTGLCanvasPeerInfo" />
<class name="org.lwjgl.opengl.WindowsPeerInfo" />
<class name="org.lwjgl.opengl.WindowsDisplayPeerInfo" />

View File

@ -57,7 +57,7 @@ public final class Sys {
private static final String VERSION = "1.0beta2";
/** Current version of the JNI library */
static final int JNI_VERSION = 2;
static final int JNI_VERSION = 3;
/** The implementation instance to delegate platform specific behavior to */
private final static SysImplementation implementation;
@ -114,7 +114,7 @@ public final class Sys {
class_name = "org.lwjgl.LinuxSysImplementation";
break;
case LWJGLUtil.PLATFORM_WINDOWS:
class_name = "org.lwjgl.Win32SysImplementation";
class_name = "org.lwjgl.WindowsSysImplementation";
break;
case LWJGLUtil.PLATFORM_MACOSX:
class_name = "org.lwjgl.MacOSXSysImplementation";

View File

@ -1,43 +0,0 @@
/*
* Copyright (c) 2002-2004 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * 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 'LWJGL' 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
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* 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.
*/
package org.lwjgl;
/**
* <p>
* Win32 SysImplementation. This is just a straightforward NativsSysImplementation.
* </p>
* @author $Author$
* @version $Revision$
* $Id$
*/
class Win32SysImplementation extends NativeSysImplementation {
}

View File

@ -31,26 +31,43 @@
*/
package org.lwjgl;
import java.security.AccessController;
import java.security.PrivilegedExceptionAction;
import java.security.PrivilegedActionException;
/**
* A SysImplementation that uses native calls only.
* <p>
* @author $Author$
* @version $Revision$
* $Id$
*/
class NativeSysImplementation extends DefaultSysImplementation {
class WindowsSysImplementation extends DefaultSysImplementation {
static {
Sys.initialize();
}
public native long getTimerResolution();
public long getTimerResolution() {
return 1000;
}
public native long getTime();
public native void alert(String title, String message);
public native boolean openURL(String url);
public boolean openURL(final String url) {
try {
AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws Exception {
Runtime.getRuntime().exec(new String[]{"rundll32", "url.dll,FileProtocolHandler", url});
return null;
}
});
return true;
} catch (PrivilegedActionException e) {
LWJGLUtil.log("Failed to open url (" + url + "): " + e.getCause().getMessage());
return false;
}
}
public native String getClipboard();
}

View File

@ -69,6 +69,7 @@ public class DisplayTest {
System.out.println("Info about current:");
System.out.println("Graphics card: " + Display.getAdapter() + ", version: " + Display.getVersion());
System.exit(1);
System.out.println("Resolution: " +
Display.getDisplayMode().getWidth() + "x" +
Display.getDisplayMode().getHeight() + "x" +

View File

@ -41,48 +41,21 @@
#include "Window.h"
#include "mmsystem.h"
#include "org_lwjgl_NativeSysImplementation.h"
#include "org_lwjgl_WindowsSysImplementation.h"
#include "common_tools.h"
#include <malloc.h>
/*
* Class: org_lwjgl_Sys
* Method: getTimerResolution
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_org_lwjgl_NativeSysImplementation_getTimerResolution
(JNIEnv * env, jobject ignored)
{
return (jlong) 1000L;
}
/*
* Class: org_lwjgl_Sys
* Method: ngetTime
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_org_lwjgl_NativeSysImplementation_getTime
(JNIEnv * env, jobject ignored)
{
MMRESULT result;
JNIEXPORT jlong JNICALL Java_org_lwjgl_WindowsSysImplementation_getTime(JNIEnv * env, jobject ignored) {
DWORD time;
result = timeBeginPeriod(1);
timeBeginPeriod(1);
time = timeGetTime();
result = timeEndPeriod(1);
timeEndPeriod(1);
return time;
}
/*
* Class: org_lwjgl_Sys
* Method: alert
* Signature: (Ljava/lang/String;Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_NativeSysImplementation_alert
(JNIEnv * env, jobject ignored, jstring title, jstring message)
{
JNIEXPORT void JNICALL Java_org_lwjgl_WindowsSysImplementation_alert(JNIEnv * env, jobject ignored, jstring title, jstring message) {
char * eMessageText = GetStringNativeChars(env, message);
char * cTitleBarText = GetStringNativeChars(env, title);
MessageBox(getCurrentHWND(), eMessageText, cTitleBarText, MB_OK | MB_TOPMOST);
@ -93,56 +66,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_NativeSysImplementation_alert
free(cTitleBarText);
}
/*
* Class: org_lwjgl_Sys
* Method: openURL
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT jboolean JNICALL Java_org_lwjgl_NativeSysImplementation_openURL
(JNIEnv * env, jobject ignored, jstring url)
{
#define BUFFER_SIZE 1024
const char *std_args = "rundll32 url.dll,FileProtocolHandler ";
STARTUPINFO si;
PROCESS_INFORMATION pi;
char * urlString = GetStringNativeChars(env, url);
char command[BUFFER_SIZE];
strncpy_s(command, BUFFER_SIZE, "", 1);
strncat_s(command, BUFFER_SIZE, std_args, _TRUNCATE);
strncat_s(command, BUFFER_SIZE, urlString, _TRUNCATE);
free(urlString);
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.
)
{
printfDebugJava(env, "Failed to open URL %s", urlString);
return JNI_FALSE;
}
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return JNI_TRUE;
}
JNIEXPORT jstring JNICALL Java_org_lwjgl_NativeSysImplementation_getClipboard
JNIEXPORT jstring JNICALL Java_org_lwjgl_WindowsSysImplementation_getClipboard
(JNIEnv * env, jobject ignored)
{
// Check to see if there's text available in the clipboard