diff 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
line wrap: on
line diff
--- a/src/video/cocoa/SDL_cocoaclipboard.m	Thu Jul 08 06:21:48 2010 -0700
+++ b/src/video/cocoa/SDL_cocoaclipboard.m	Thu Jul 08 22:54:03 2010 -0700
@@ -22,6 +22,7 @@
 #include "SDL_config.h"
 
 #include "SDL_cocoavideo.h"
+#include "../../events/SDL_clipboardevents_c.h"
 
 static NSString *
 GetTextFormat(_THIS)
@@ -42,6 +43,7 @@
 int
 Cocoa_SetClipboardText(_THIS, const char *text)
 {
+    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     NSAutoreleasePool *pool;
 	NSPasteboard *pasteboard;
     NSString *format = GetTextFormat(_this);
@@ -49,7 +51,7 @@
     pool = [[NSAutoreleasePool alloc] init];
 
     pasteboard = [NSPasteboard generalPasteboard];
-    [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil];
+    data->clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil];
     [pasteboard setString:[NSString stringWithUTF8String:text] forType:format];
 
     [pool release];
@@ -114,4 +116,25 @@
     return result;
 }
 
+void
+Cocoa_CheckClipboardUpdate(struct SDL_VideoData * data)
+{
+    NSAutoreleasePool *pool;
+	NSPasteboard *pasteboard;
+    NSInteger count;
+
+    pool = [[NSAutoreleasePool alloc] init];
+
+    pasteboard = [NSPasteboard generalPasteboard];
+    count = [pasteboard changeCount];
+    if (count != data->clipboard_count) {
+        if (data->clipboard_count) {
+            SDL_SendClipboardUpdate();
+        }
+        data->clipboard_count = count;
+    }
+
+    [pool release];
+}
+
 /* vi: set ts=4 sw=4 expandtab: */