zenilib: zenilib/jni/external/sdl/src/video/bwindow/SDL_bclipboard.cc Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SDL_bclipboard.cc
Go to the documentation of this file.
1 /*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2013 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_config.h"
22
23 #if SDL_VIDEO_DRIVER_BWINDOW
24
25 /* BWindow based framebuffer 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 BE_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
54 char *BE_GetClipboardText(_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 } else {
65 be_clipboard->Unlock();
66 }
67 be_clipboard->Unlock();
68 }
69
70 if (!text) {
71 result = SDL_strdup("");
72 } else {
73 /* Copy the data and pass on to SDL */
74 result = (char*)SDL_calloc(1, sizeof(char*)*length);
75 SDL_strlcpy(result, text, length);
76 }
77
78 return result;
79 }
80
81 SDL_bool BE_HasClipboardText(_THIS) {
82 SDL_bool result = SDL_FALSE;
83 char *text = BE_GetClipboardText(_this);
84 if (text) {
85 result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
86 SDL_free(text);
87 }
88 return result;
89 }
90
91 #ifdef __cplusplus
92 }
93 #endif
94
95 #endif /* SDL_VIDEO_DRIVER_BWINDOW */
SDL_calloc
DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size)
NULL
#define NULL
Definition: ftobjs.h:61
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:116
SDL_TRUE
Definition: SDL_stdinc.h:119
SDL_free
DECLSPEC void SDLCALL SDL_free(void *mem)
SDL_FALSE
Definition: SDL_stdinc.h:118
SDL_config.h
_this
static SDL_VideoDevice * _this
Definition: SDL_video.c:92
result
GLuint64EXT * result
Definition: glew.h:12708
length
GLsizei GLsizei * length
Definition: gl2ext.h:792
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
SDL_strdup
DECLSPEC char *SDLCALL SDL_strdup(const char *str)
Definition: SDL_string.c:511
SDL_strlcpy
DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen)
Definition: SDL_string.c:448
BE_GetClipboardText
char * BE_GetClipboardText(_THIS)
BE_SetClipboardText
int BE_SetClipboardText(_THIS, const char *text)
SDL_timer.h
BE_HasClipboardText
SDL_bool BE_HasClipboardText(_THIS)
SDL_BWin.h