Debian Codegraph @

src/iphone/iphone_clipboard.m

raw
1 /* ______ ___ ___
2 * /\ _ \ /\_ \ /\_ \
3 * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
4 * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
5 * \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
6 * \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
7 * \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
8 * /\____/
9 * \_/__/
10 *
11 * MacOS X clipboard handling.
12 *
13 * By Beoran.
14 *
15 * See readme.txt for copyright information.
16 */
17
18
19 #include <allegro5/allegro.h>
20 #include <allegro5/allegro_opengl.h>
21 #include <allegro5/internal/aintern_iphone.h>
22 #include <allegro5/internal/aintern_opengl.h>
23 #include <allegro5/internal/aintern_vector.h>
24 #include <allegro5/internal/aintern.h>
25 #include <math.h>
26
27 #include "iphone.h"
28 #include "allegroAppDelegate.h"
29 #include <MobileCoreServices/MobileCoreServices.h>
30
31 ALLEGRO_DEBUG_CHANNEL("iphone")
32
33 #ifndef ALLEGRO_IPHONE
34 #error Something is wrong with the makefile
35 #endif
36
37 /* Ensure that we have the right version number available. */
38 #ifndef NSAppKitVersionNumber10_6
39 #define NSAppKitVersionNumber10_6 1038
40 #endif
41
42
43 static char *iphone_get_clipboard_text(ALLEGRO_DISPLAY *display)
44 {
45 const char *utf8;
46 NSString *pbtext;
47 size_t size;
48 char *text;
49
50 pbtext = [[UIPasteboard generalPasteboard] string];
51 if (pbtext == nil)
52 return NULL;
53
54 utf8 = [pbtext UTF8String];
55 size = strlen(utf8);
56 text = al_malloc(size+1);
57 text = _al_sane_strncpy(text, utf8, size+1);
58
59 return text;
60 }
61
62 static bool iphone_set_clipboard_text(ALLEGRO_DISPLAY *display, const char *text)
63 {
64 NSData *data = [NSData dataWithBytes:text length:strlen(text)];
65 [[UIPasteboard generalPasteboard] setData:data forPasteboardType:(NSString *)kUTTypeUTF8PlainText];
66 return true;
67 }
68
69 static bool iphone_has_clipboard_text(ALLEGRO_DISPLAY *display)
70 {
71 NSString *pbtext;
72
73 pbtext = [[UIPasteboard generalPasteboard] string];
74
75 return (pbtext != nil);
76 }
77
78 void _al_iphone_add_clipboard_functions(ALLEGRO_DISPLAY_INTERFACE *vt)
79 {
80 vt->set_clipboard_text = iphone_set_clipboard_text;
81 vt->get_clipboard_text = iphone_get_clipboard_text;
82 vt->has_clipboard_text = iphone_has_clipboard_text;
83 }
84
85 /* vim: set sts=3 sw=3 et: */