Add Platform.hasClipboardText() to speed up checking clipboard.

This commit is contained in:
and3md 2017-09-21 18:37:58 +02:00
parent ee28496955
commit 888acfb7d3
6 changed files with 31 additions and 2 deletions

View File

@ -575,6 +575,12 @@ class AndroidPlatform : Platform {
}
protected dstring _clipboardText;
/// check has clipboard text
override bool hasClipboardText(bool mouseBuffer = false) {
return (_clipboardText.length > 0);
}
/// retrieves text from clipboard (when mouseBuffer == true, use mouse selection clipboard - under linux)
override dstring getClipboardText(bool mouseBuffer = false) {
return _clipboardText;

View File

@ -1823,6 +1823,8 @@ class Platform {
* When returned from this method, application is shutting down.
*/
abstract int enterMessageLoop();
/// check has clipboard text
abstract bool hasClipboardText(bool mouseBuffer = false);
/// retrieves text from clipboard (when mouseBuffer == true, use mouse selection clipboard - under linux)
abstract dstring getClipboardText(bool mouseBuffer = false);
/// sets text to clipboard (when mouseBuffer == true, use mouse selection clipboard - under linux)

View File

@ -240,6 +240,12 @@ class ConsolePlatform : Platform {
return 0;
}
private dstring _clipboardText;
/// check has clipboard text
override bool hasClipboardText(bool mouseBuffer = false) {
return (_clipboardText.length > 0);
}
/// retrieves text from clipboard (when mouseBuffer == true, use mouse selection clipboard - under linux)
override dstring getClipboardText(bool mouseBuffer = false) {
return _clipboardText;

View File

@ -1462,10 +1462,13 @@ class SDLPlatform : Platform {
return 0;
}
/// check has clipboard text
override bool hasClipboardText(bool mouseBuffer = false) {
return (SDL_HasClipboardText() == SDL_TRUE);
}
/// retrieves text from clipboard (when mouseBuffer == true, use mouse selection clipboard - under linux)
override dstring getClipboardText(bool mouseBuffer = false) {
if (!SDL_HasClipboardText())
return ""d;
char * txt = SDL_GetClipboardText();
if (!txt)
return ""d;

View File

@ -1158,6 +1158,13 @@ class Win32Platform : Platform {
_windowsToDestroy.length = 0;
}
/// check has clipboard text
override bool hasClipboardText(bool mouseBuffer = false) {
if (mouseBuffer)
return false;
return IsClipboardFormatAvailable(CF_UNICODETEXT);
}
/// retrieves text from clipboard (when mouseBuffer == true, use mouse selection clipboard - under linux)
override dstring getClipboardText(bool mouseBuffer = false) {
dstring res = null;

View File

@ -1633,6 +1633,11 @@ class X11Platform : Platform {
return 0;
}
/// check has clipboard text
override bool hasClipboardText(bool mouseBuffer = false) {
return (localClipboardContent.length != 0);
}
/// retrieves text from clipboard (when mouseBuffer == true, use mouse selection clipboard - under linux)
override dstring getClipboardText(bool mouseBuffer = false) {
return toUTF32(localClipboardContent);