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
35 extern "C" {
36 #endif
37 
38 int 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;
84  SDL_free(text);
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: */
SDL_strlcpy
#define SDL_strlcpy
Definition: SDL_dynapi_overrides.h:394
NULL
#define NULL
Definition: begin_code.h:167
SDL_timer.h
length
GLuint GLsizei GLsizei * length
Definition: SDL_opengl_glext.h:669
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
HAIKU_SetClipboardText
int HAIKU_SetClipboardText(_THIS, const char *text)
_this
static SDL_VideoDevice * _this
Definition: SDL_video.c:118
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
SDL_FALSE
Definition: SDL_stdinc.h:163
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
text
static char text[MAX_TEXT_LENGTH]
Definition: testime.c:47
HAIKU_GetClipboardText
char * HAIKU_GetClipboardText(_THIS)
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:161
HAIKU_HasClipboardText
SDL_bool HAIKU_HasClipboardText(_THIS)
SDL_BWin.h
SDL_TRUE
Definition: SDL_stdinc.h:164
SDL_strdup
#define SDL_strdup
Definition: SDL_dynapi_overrides.h:397
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:374