diff options
Diffstat (limited to 'contrib/SDL-3.2.8/src/video/haiku/SDL_bclipboard.cc')
| -rw-r--r-- | contrib/SDL-3.2.8/src/video/haiku/SDL_bclipboard.cc | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/video/haiku/SDL_bclipboard.cc b/contrib/SDL-3.2.8/src/video/haiku/SDL_bclipboard.cc new file mode 100644 index 0000000..ff2bc6b --- /dev/null +++ b/contrib/SDL-3.2.8/src/video/haiku/SDL_bclipboard.cc | |||
| @@ -0,0 +1,93 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> | ||
| 4 | |||
| 5 | This software is provided 'as-is', without any express or implied | ||
| 6 | warranty. In no event will the authors be held liable for any damages | ||
| 7 | arising from the use of this software. | ||
| 8 | |||
| 9 | Permission is granted to anyone to use this software for any purpose, | ||
| 10 | including commercial applications, and to alter it and redistribute it | ||
| 11 | freely, subject to the following restrictions: | ||
| 12 | |||
| 13 | 1. The origin of this software must not be misrepresented; you must not | ||
| 14 | claim that you wrote the original software. If you use this software | ||
| 15 | in a product, an acknowledgment in the product documentation would be | ||
| 16 | appreciated but is not required. | ||
| 17 | 2. Altered source versions must be plainly marked as such, and must not be | ||
| 18 | misrepresented as being the original software. | ||
| 19 | 3. This notice may not be removed or altered from any source distribution. | ||
| 20 | */ | ||
| 21 | #include "SDL_internal.h" | ||
| 22 | |||
| 23 | #ifdef SDL_VIDEO_DRIVER_HAIKU | ||
| 24 | |||
| 25 | // BWindow based clipboard implementation | ||
| 26 | |||
| 27 | #include <unistd.h> | ||
| 28 | #include <TypeConstants.h> | ||
| 29 | |||
| 30 | #include "SDL_BWin.h" | ||
| 31 | #include "../SDL_sysvideo.h" | ||
| 32 | |||
| 33 | #ifdef __cplusplus | ||
| 34 | extern "C" { | ||
| 35 | #endif | ||
| 36 | |||
| 37 | bool HAIKU_SetClipboardText(SDL_VideoDevice *_this, const char *text) | ||
| 38 | { | ||
| 39 | BMessage *clip = NULL; | ||
| 40 | if (be_clipboard->Lock()) { | ||
| 41 | be_clipboard->Clear(); | ||
| 42 | if ((clip = be_clipboard->Data())) { | ||
| 43 | // Presumably the string of characters is ascii-format | ||
| 44 | ssize_t asciiLength = 0; | ||
| 45 | for (; text[asciiLength] != 0; ++asciiLength) {} | ||
| 46 | clip->AddData("text/plain", B_MIME_TYPE, text, asciiLength); | ||
| 47 | be_clipboard->Commit(); | ||
| 48 | } | ||
| 49 | be_clipboard->Unlock(); | ||
| 50 | } | ||
| 51 | return true; | ||
| 52 | } | ||
| 53 | |||
| 54 | char *HAIKU_GetClipboardText(SDL_VideoDevice *_this) { | ||
| 55 | BMessage *clip = NULL; | ||
| 56 | const char *text = NULL; | ||
| 57 | ssize_t length; | ||
| 58 | char *result; | ||
| 59 | if (be_clipboard->Lock()) { | ||
| 60 | if ((clip = be_clipboard->Data())) { | ||
| 61 | // Presumably the string of characters is ascii-format | ||
| 62 | clip->FindData("text/plain", B_MIME_TYPE, (const void**)&text, | ||
| 63 | &length); | ||
| 64 | } | ||
| 65 | be_clipboard->Unlock(); | ||
| 66 | } | ||
| 67 | |||
| 68 | if (!text) { | ||
| 69 | result = SDL_strdup(""); | ||
| 70 | } else { | ||
| 71 | // Copy the data and pass on to SDL | ||
| 72 | result = (char *)SDL_malloc((length + 1) * sizeof(char)); | ||
| 73 | SDL_strlcpy(result, text, length + 1); | ||
| 74 | } | ||
| 75 | |||
| 76 | return result; | ||
| 77 | } | ||
| 78 | |||
| 79 | bool HAIKU_HasClipboardText(SDL_VideoDevice *_this) { | ||
| 80 | bool result = false; | ||
| 81 | char *text = HAIKU_GetClipboardText(_this); | ||
| 82 | if (text) { | ||
| 83 | result = (text[0] != '\0'); | ||
| 84 | SDL_free(text); | ||
| 85 | } | ||
| 86 | return result; | ||
| 87 | } | ||
| 88 | |||
| 89 | #ifdef __cplusplus | ||
| 90 | } | ||
| 91 | #endif | ||
| 92 | |||
| 93 | #endif // SDL_VIDEO_DRIVER_HAIKU | ||
