| 1 |
/* Copyright (C) 2016 by Jeremy Tan */ |
| 2 |
/* |
| 3 |
* Redistribution and use in source and binary forms, with or without |
| 4 |
* modification, are permitted provided that the following conditions are met: |
| 5 |
|
| 6 |
* Redistributions of source code must retain the above copyright notice, this |
| 7 |
* list of conditions and the following disclaimer. |
| 8 |
|
| 9 |
* Redistributions in binary form must reproduce the above copyright notice, |
| 10 |
* this list of conditions and the following disclaimer in the documentation |
| 11 |
* and/or other materials provided with the distribution. |
| 12 |
|
| 13 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 14 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 15 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 16 |
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 17 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 18 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 19 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 20 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 21 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 22 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 |
*/ |
| 24 |
|
| 25 |
/** |
| 26 |
* @file ggdkcocoa.m |
| 27 |
* @brief macOS specific functions, written in Objective C. |
| 28 |
*/ |
| 29 |
|
| 30 |
#include "ggdkdrawP.h" |
| 31 |
|
| 32 |
#include "ustring.h" |
| 33 |
#include <Cocoa/Cocoa.h> |
| 34 |
|
| 35 |
char *_GGDKDrawCocoa_GetClipboardText(void) { |
| 36 |
NSString *ns_clip = [[NSPasteboard generalPasteboard] stringForType:NSStringPboardType]; |
| 37 |
if (ns_clip == nil) { |
| 38 |
return NULL; |
| 39 |
} |
| 40 |
|
| 41 |
return copy([ns_clip UTF8String]); |
| 42 |
} |
| 43 |
|
| 44 |
void _GGDKDrawCocoa_SetClipboardText(const char *text) { |
| 45 |
if (text == NULL || text[0] == '\0') { |
| 46 |
return; |
| 47 |
} |
| 48 |
|
| 49 |
NSString *ns_clip = [[NSString alloc] initWithUTF8String:text]; |
| 50 |
if (ns_clip == nil) { |
| 51 |
return; |
| 52 |
} |
| 53 |
|
| 54 |
NSPasteboard *pb = [NSPasteboard generalPasteboard]; |
| 55 |
[pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil]; |
| 56 |
[pb setString:ns_clip forType:NSStringPboardType]; |
| 57 |
[ns_clip release]; |
| 58 |
} |