zenilib: zenilib/jni/external/sdl/src/video/windows/SDL_windowsclipboard.c 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_windowsclipboard.c
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_WINDOWS
24
25 #include "SDL_windowsvideo.h"
26 #include "SDL_windowswindow.h"
27 #include "../../events/SDL_clipboardevents_c.h"
28
29
30 #ifdef UNICODE
31 #define TEXT_FORMAT CF_UNICODETEXT
32 #else
33 #define TEXT_FORMAT CF_TEXT
34 #endif
35
36
37 /* Get any application owned window handle for clipboard association */
38 static HWND
39 GetWindowHandle(_THIS)
40 {
41 SDL_Window *window;
42
43 window = _this->windows;
44 if (window) {
45 return ((SDL_WindowData *) window->driverdata)->hwnd;
46 }
47 return NULL;
48 }
49
50 int
51 WIN_SetClipboardText(_THIS, const char *text)
52 {
53 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
54 int result = 0;
55
56 if (OpenClipboard(GetWindowHandle(_this))) {
57 HANDLE hMem;
58 LPTSTR tstr;
59 SIZE_T i, size;
60
61 /* Convert the text from UTF-8 to Windows Unicode */
62 tstr = WIN_UTF8ToString(text);
63 if (!tstr) {
64 return -1;
65 }
66
67 /* Find out the size of the data */
68 for (size = 0, i = 0; tstr[i]; ++i, ++size) {
69 if (tstr[i] == '\n' && (i == 0 || tstr[i-1] != '\r')) {
70 /* We're going to insert a carriage return */
71 ++size;
72 }
73 }
74 size = (size+1)*sizeof(*tstr);
75
76 /* Save the data to the clipboard */
77 hMem = GlobalAlloc(GMEM_MOVEABLE, size);
78 if (hMem) {
79 LPTSTR dst = (LPTSTR)GlobalLock(hMem);
80 if (dst) {
81 /* Copy the text over, adding carriage returns as necessary */
82 for (i = 0; tstr[i]; ++i) {
83 if (tstr[i] == '\n' && (i == 0 || tstr[i-1] != '\r')) {
84 *dst++ = '\r';
85 }
86 *dst++ = tstr[i];
87 }
88 *dst = 0;
89 GlobalUnlock(hMem);
90 }
91
92 EmptyClipboard();
93 if (!SetClipboardData(TEXT_FORMAT, hMem)) {
94 result = WIN_SetError("Couldn't set clipboard data");
95 }
96 data->clipboard_count = GetClipboardSequenceNumber();
97 }
98 SDL_free(tstr);
99
100 CloseClipboard();
101 } else {
102 result = WIN_SetError("Couldn't open clipboard");
103 }
104 return result;
105 }
106
107 char *
108 WIN_GetClipboardText(_THIS)
109 {
110 char *text;
111
112 text = NULL;
113 if (IsClipboardFormatAvailable(TEXT_FORMAT) &&
114 OpenClipboard(GetWindowHandle(_this))) {
115 HANDLE hMem;
116 LPTSTR tstr;
117
118 hMem = GetClipboardData(TEXT_FORMAT);
119 if (hMem) {
120 tstr = (LPTSTR)GlobalLock(hMem);
121 text = WIN_StringToUTF8(tstr);
122 GlobalUnlock(hMem);
123 } else {
124 WIN_SetError("Couldn't get clipboard data");
125 }
126 CloseClipboard();
127 }
128 if (!text) {
129 text = SDL_strdup("");
130 }
131 return text;
132 }
133
134 SDL_bool
135 WIN_HasClipboardText(_THIS)
136 {
137 SDL_bool result = SDL_FALSE;
138 char *text = WIN_GetClipboardText(_this);
139 if (text) {
140 result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
141 SDL_free(text);
142 }
143 return result;
144 }
145
146 void
147 WIN_CheckClipboardUpdate(struct SDL_VideoData * data)
148 {
149 const DWORD count = GetClipboardSequenceNumber();
150 if (count != data->clipboard_count) {
151 if (data->clipboard_count) {
152 SDL_SendClipboardUpdate();
153 }
154 data->clipboard_count = count;
155 }
156 }
157
158 #endif /* SDL_VIDEO_DRIVER_WINDOWS */
159
160 /* vi: set ts=4 sw=4 expandtab: */
SDL_VideoData::clipboard_count
NSInteger clipboard_count
Definition: SDL_cocoavideo.h:52
WIN_UTF8ToString
#define WIN_UTF8ToString(S)
Definition: SDL_windows.h:42
NULL
#define NULL
Definition: ftobjs.h:61
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:116
WIN_GetClipboardText
char * WIN_GetClipboardText(_THIS)
SDL_TRUE
Definition: SDL_stdinc.h:119
SDL_VideoDevice::driverdata
void * driverdata
Definition: SDL_sysvideo.h:314
SDL_free
DECLSPEC void SDLCALL SDL_free(void *mem)
if
if(!yyg->yy_init)
Definition: glslang_lex.cpp:1037
SDL_FALSE
Definition: SDL_stdinc.h:118
SDL_config.h
SDL_WindowData
Definition: SDL_androidwindow.h:33
_this
static SDL_VideoDevice * _this
Definition: SDL_video.c:92
result
GLuint64EXT * result
Definition: glew.h:12708
HANDLE
typedef HANDLE(WINAPI *PFNWGLCREATEBUFFERREGIONARBPROC)(HDC hDC
dst
GLenum GLenum dst
Definition: glew.h:2396
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl2ext.h:848
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
SDL_SendClipboardUpdate
int SDL_SendClipboardUpdate(void)
Definition: SDL_clipboardevents.c:31
SDL_strdup
DECLSPEC char *SDLCALL SDL_strdup(const char *str)
Definition: SDL_string.c:511
count
GLint GLsizei count
Definition: gl2ext.h:1011
WIN_StringToUTF8
#define WIN_StringToUTF8(S)
Definition: SDL_windows.h:41
WIN_HasClipboardText
SDL_bool WIN_HasClipboardText(_THIS)
SDL_VideoDevice::windows
SDL_Window * windows
Definition: SDL_sysvideo.h:266
WIN_SetError
int WIN_SetError(const char *prefix)
SDL_Window
Definition: SDL_sysvideo.h:71
DWORD
typedef DWORD(WINAPI *XInputGetState_t)(DWORD dwUserIndex
SDL_VideoData
Definition: SDL_androidvideo.h:35
SDL_Window::driverdata
void * driverdata
Definition: SDL_sysvideo.h:99
i
int i
Definition: pngrutil.c:1377
WIN_CheckClipboardUpdate
void WIN_CheckClipboardUpdate(struct SDL_VideoData *data)
SDL_windowswindow.h
SDL_windowsvideo.h
WIN_SetClipboardText
int WIN_SetClipboardText(_THIS, const char *text)
size
GLsizei size
Definition: gl2ext.h:1467