#include "SDL_internal.h"
#ifdef SDL_VIDEO_DRIVER_HAIKU
#include <unistd.h>
#include <TypeConstants.h>
#include "SDL_BWin.h"
#include "../SDL_sysvideo.h"
#ifdef __cplusplus
extern "C" {
#endif
bool HAIKU_SetClipboardText(SDL_VideoDevice *_this, const char *text)
{
BMessage *clip = NULL;
if (be_clipboard->Lock()) {
be_clipboard->Clear();
if ((clip = be_clipboard->Data())) {
ssize_t asciiLength = 0;
for (; text[asciiLength] != 0; ++asciiLength) {}
clip->AddData("text/plain", B_MIME_TYPE, text, asciiLength);
be_clipboard->Commit();
}
be_clipboard->Unlock();
}
return true;
}
char *HAIKU_GetClipboardText(SDL_VideoDevice *_this) {
BMessage *clip = NULL;
const char *text = NULL;
ssize_t length;
char *result;
if (be_clipboard->Lock()) {
if ((clip = be_clipboard->Data())) {
clip->FindData("text/plain", B_MIME_TYPE, (const void **)&text,
&length);
}
be_clipboard->Unlock();
}
if (!text) {
result = SDL_strdup("");
} else {
result = (char *)SDL_malloc((length + 1) * sizeof(char));
SDL_strlcpy(result, text, length + 1);
}
return result;
}
bool HAIKU_HasClipboardText(SDL_VideoDevice *_this) {
bool result = false;
char *text = HAIKU_GetClipboardText(_this);
if (text) {
result = (text[0] != '\0');
SDL_free(text);
}
return result;
}
#ifdef __cplusplus
}
#endif
#endif