comparison src/video/cocoa/SDL_cocoaclipboard.m @ 4503:524dfefd554c

Added an event when the clipboard is updated, triggered after the window gains the keyboard focus.
author Sam Lantinga <slouken@libsdl.org>
date Thu, 08 Jul 2010 22:54:03 -0700
parents 0cf025066b6f
children 9faebccfefb3
comparison
equal deleted inserted replaced
4502:b3540fa08474 4503:524dfefd554c
20 slouken@libsdl.org 20 slouken@libsdl.org
21 */ 21 */
22 #include "SDL_config.h" 22 #include "SDL_config.h"
23 23
24 #include "SDL_cocoavideo.h" 24 #include "SDL_cocoavideo.h"
25 #include "../../events/SDL_clipboardevents_c.h"
25 26
26 static NSString * 27 static NSString *
27 GetTextFormat(_THIS) 28 GetTextFormat(_THIS)
28 { 29 {
29 #if MAC_OS_X_VERSION_MAX_ALLOWED < 1060 30 #if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
40 } 41 }
41 42
42 int 43 int
43 Cocoa_SetClipboardText(_THIS, const char *text) 44 Cocoa_SetClipboardText(_THIS, const char *text)
44 { 45 {
46 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
45 NSAutoreleasePool *pool; 47 NSAutoreleasePool *pool;
46 NSPasteboard *pasteboard; 48 NSPasteboard *pasteboard;
47 NSString *format = GetTextFormat(_this); 49 NSString *format = GetTextFormat(_this);
48 50
49 pool = [[NSAutoreleasePool alloc] init]; 51 pool = [[NSAutoreleasePool alloc] init];
50 52
51 pasteboard = [NSPasteboard generalPasteboard]; 53 pasteboard = [NSPasteboard generalPasteboard];
52 [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil]; 54 data->clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil];
53 [pasteboard setString:[NSString stringWithUTF8String:text] forType:format]; 55 [pasteboard setString:[NSString stringWithUTF8String:text] forType:format];
54 56
55 [pool release]; 57 [pool release];
56 58
57 return 0; 59 return 0;
112 [pool release]; 114 [pool release];
113 115
114 return result; 116 return result;
115 } 117 }
116 118
119 void
120 Cocoa_CheckClipboardUpdate(struct SDL_VideoData * data)
121 {
122 NSAutoreleasePool *pool;
123 NSPasteboard *pasteboard;
124 NSInteger count;
125
126 pool = [[NSAutoreleasePool alloc] init];
127
128 pasteboard = [NSPasteboard generalPasteboard];
129 count = [pasteboard changeCount];
130 if (count != data->clipboard_count) {
131 if (data->clipboard_count) {
132 SDL_SendClipboardUpdate();
133 }
134 data->clipboard_count = count;
135 }
136
137 [pool release];
138 }
139
117 /* vi: set ts=4 sw=4 expandtab: */ 140 /* vi: set ts=4 sw=4 expandtab: */