Implemented getClipboard on Win32
This commit is contained in:
parent
f0954a9a70
commit
7f28edb980
|
@ -59,6 +59,7 @@ public class SysTest {
|
|||
testTimer();
|
||||
testPriority();
|
||||
testUrl();
|
||||
testClipboard();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -174,6 +175,13 @@ public class SysTest {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the clipboard. Helps to have something in it first...
|
||||
*/
|
||||
private void testClipboard() {
|
||||
System.out.println("Contents of clipboard: '"+Sys.getClipboard()+"'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the Sys class, and serves as basic usage test
|
||||
*
|
||||
|
|
|
@ -177,8 +177,44 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_nOpenURL
|
|||
}
|
||||
|
||||
|
||||
|
||||
const void * getClipboard(int type)
|
||||
{
|
||||
|
||||
void * ret;
|
||||
|
||||
// Open the clipboard
|
||||
if (!OpenClipboard(NULL))
|
||||
return NULL;
|
||||
|
||||
HANDLE hglb = GetClipboardData(type);
|
||||
if (hglb != NULL) {
|
||||
ret = GlobalLock(hglb);
|
||||
if (ret != NULL) {
|
||||
GlobalUnlock(hglb);
|
||||
}
|
||||
}
|
||||
|
||||
// Close the clipboard now we're done
|
||||
CloseClipboard();
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_lwjgl_Sys_getClipboard
|
||||
(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
return NULL;
|
||||
// Check to see if there's text available in the clipboard
|
||||
BOOL textAvailable = IsClipboardFormatAvailable(CF_TEXT);
|
||||
BOOL unicodeAvailable = IsClipboardFormatAvailable(CF_UNICODETEXT);
|
||||
|
||||
if (unicodeAvailable) {
|
||||
const wchar_t * str = (const wchar_t *) getClipboard(CF_UNICODETEXT);
|
||||
return env->NewString(str, wcslen(str));
|
||||
} else if (textAvailable) {
|
||||
return env->NewStringUTF((const char *) getClipboard(CF_TEXT));
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue