Update SDL_HasClipboardText functions to return value based on clipboard content; Fix memory leak in fallback SetClipboard implementation
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
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.
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:
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.
21 #include "SDL_config.h"
23 #include "SDL_cocoavideo.h"
24 #include "../../events/SDL_clipboardevents_c.h"
29 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
30 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
32 if (data->osversion >= 0x1060) {
33 return NSPasteboardTypeString;
35 return NSStringPboardType;
38 return NSStringPboardType;
43 Cocoa_SetClipboardText(_THIS, const char *text)
45 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
46 NSAutoreleasePool *pool;
47 NSPasteboard *pasteboard;
48 NSString *format = GetTextFormat(_this);
50 pool = [[NSAutoreleasePool alloc] init];
52 pasteboard = [NSPasteboard generalPasteboard];
53 data->clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil];
54 [pasteboard setString:[NSString stringWithUTF8String:text] forType:format];
62 Cocoa_GetClipboardText(_THIS)
64 NSAutoreleasePool *pool;
65 NSPasteboard *pasteboard;
66 NSString *format = GetTextFormat(_this);
70 pool = [[NSAutoreleasePool alloc] init];
72 pasteboard = [NSPasteboard generalPasteboard];
73 available = [pasteboard availableTypeFromArray: [NSArray arrayWithObject:format]];
74 if ([available isEqualToString:format]) {
78 string = [pasteboard stringForType:format];
82 utf8 = [string UTF8String];
84 text = SDL_strdup(utf8);
86 text = SDL_strdup("");
95 Cocoa_HasClipboardText(_THIS)
97 SDL_bool result = SDL_FALSE;
98 char *text = Cocoa_GetClipboardText(_this);
100 result = (SDL_strlen(text)>0) ? SDL_TRUE : SDL_FALSE;
107 Cocoa_CheckClipboardUpdate(struct SDL_VideoData * data)
109 NSAutoreleasePool *pool;
110 NSPasteboard *pasteboard;
113 pool = [[NSAutoreleasePool alloc] init];
115 pasteboard = [NSPasteboard generalPasteboard];
116 count = [pasteboard changeCount];
117 if (count != data->clipboard_count) {
118 if (data->clipboard_count) {
119 SDL_SendClipboardUpdate();
121 data->clipboard_count = count;
127 /* vi: set ts=4 sw=4 expandtab: */