Mercurial > sdl-ios-xcode
comparison src/video/SDL_clipboard.c @ 4495:dbbfdb9ea716
Simplified clipboard API for sanity's sake.
A complete clipboard implementation would support multiple formats that could be queried at runtime, events for when the clipboard contents changed, support for HTML, images, etc. We're not going that crazy, at least for now. :)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 07 Jul 2010 23:54:03 -0700 |
parents | f0b7c8d169f5 |
children | eff4e88cc1e8 |
comparison
equal
deleted
inserted
replaced
4494:621dc91c7a04 | 4495:dbbfdb9ea716 |
---|---|
22 #include "SDL_config.h" | 22 #include "SDL_config.h" |
23 | 23 |
24 #include "SDL_clipboard.h" | 24 #include "SDL_clipboard.h" |
25 #include "SDL_sysvideo.h" | 25 #include "SDL_sysvideo.h" |
26 | 26 |
27 /* FOURCC values for text and image clipboard formats */ | |
28 #define TEXT_DATA SDL_FOURCC('T', 'E', 'X', 'T') | |
29 #define IMAGE_DATA SDL_FOURCC('B', 'M', 'P', ' ') | |
30 | 27 |
31 int | 28 int |
32 SDL_SetClipboardText(const char *text) | 29 SDL_SetClipboardText(const char *text) |
33 { | 30 { |
34 return SDL_SetClipboard(TEXT_DATA, text, SDL_strlen(text)+1); | 31 SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
32 | |
33 if (_this->SetClipboardText) { | |
34 return _this->SetClipboardText(_this, text); | |
35 } else { | |
36 _this->clipboard_text = SDL_strdup(text); | |
37 return 0; | |
38 } | |
35 } | 39 } |
36 | 40 |
37 char * | 41 char * |
38 SDL_GetClipboardText() | 42 SDL_GetClipboardText() |
39 { | 43 { |
40 void *data; | 44 SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
41 size_t length; | |
42 | 45 |
43 if (SDL_GetClipboard(TEXT_DATA, &data, &length) == 0) { | 46 if (_this->GetClipboardText) { |
44 return SDL_static_cast(char*, data); | 47 return _this->GetClipboardText(_this); |
45 } else { | 48 } else { |
46 return NULL; | 49 const char *text = _this->clipboard_text; |
50 if (!text) { | |
51 text = ""; | |
52 } | |
53 return SDL_strdup(text); | |
47 } | 54 } |
48 } | 55 } |
49 | 56 |
50 SDL_bool | 57 SDL_bool |
51 SDL_HasClipboardText() | 58 SDL_HasClipboardText() |
52 { | 59 { |
53 return SDL_HasClipboardFormat(TEXT_DATA); | 60 SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
54 } | |
55 | 61 |
56 int | 62 if (_this->HasClipboardText) { |
57 SDL_SetClipboardImage(SDL_Surface *image) | 63 return _this->HasClipboardText(_this); |
58 { | 64 } else { |
59 SDL_Unsupported(); | 65 if (_this->clipboard_text) { |
60 return -1; | 66 return SDL_TRUE; |
61 } | 67 } else { |
62 | 68 return SDL_FALSE; |
63 SDL_Surface * | 69 } |
64 SDL_GetClipboardImage() | 70 } |
65 { | |
66 SDL_Unsupported(); | |
67 return NULL; | |
68 } | |
69 | |
70 SDL_bool | |
71 SDL_HasClipboardImage() | |
72 { | |
73 return SDL_FALSE; | |
74 } | |
75 | |
76 int | |
77 SDL_SetClipboard(Uint32 format, void *data, size_t length) | |
78 { | |
79 SDL_Unsupported(); | |
80 return -1; | |
81 } | |
82 | |
83 int | |
84 SDL_GetClipboard(Uint32 format, void **data, size_t *length) | |
85 { | |
86 SDL_Unsupported(); | |
87 return -1; | |
88 } | |
89 | |
90 SDL_bool | |
91 SDL_HasClipboardFormat(Uint32 format) | |
92 { | |
93 return SDL_FALSE; | |
94 } | |
95 | |
96 void | |
97 SDL_ClearClipboard(void) | |
98 { | |
99 } | 71 } |
100 | 72 |
101 /* vi: set ts=4 sw=4 expandtab: */ | 73 /* vi: set ts=4 sw=4 expandtab: */ |