SDL 2.0
SDL_bclipboard.cc
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2019 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#if 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_timer.h"
32#include "../SDL_sysvideo.h"
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38int HAIKU_SetClipboardText(_THIS, const char *text) {
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 0;
52}
53
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));
74 }
75
76 return result;
77}
78
82 if (text) {
83 result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
85 }
86 return result;
87}
88
89#ifdef __cplusplus
90}
91#endif
92
93#endif /* SDL_VIDEO_DRIVER_HAIKU */
94
95/* vi: set ts=4 sw=4 expandtab: */
#define _THIS
char * HAIKU_GetClipboardText(_THIS)
int HAIKU_SetClipboardText(_THIS, const char *text)
SDL_bool HAIKU_HasClipboardText(_THIS)
#define SDL_malloc
#define SDL_strlcpy
#define SDL_free
#define SDL_strdup
GLuint64EXT * result
GLuint GLsizei GLsizei * length
SDL_bool
Definition: SDL_stdinc.h:162
@ SDL_TRUE
Definition: SDL_stdinc.h:164
@ SDL_FALSE
Definition: SDL_stdinc.h:163
static SDL_VideoDevice * _this
Definition: SDL_video.c:118
#define NULL
Definition: begin_code.h:167
static char text[MAX_TEXT_LENGTH]
Definition: testime.c:47