annotate 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
rev   line source
4493
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 Copyright (C) 1997-2010 Sam Lantinga
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #include "SDL_config.h"
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 #include "SDL_clipboard.h"
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 #include "SDL_sysvideo.h"
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 int
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 SDL_SetClipboardText(const char *text)
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 {
4495
dbbfdb9ea716 Simplified clipboard API for sanity's sake.
Sam Lantinga <slouken@libsdl.org>
parents: 4493
diff changeset
31 SDL_VideoDevice *_this = SDL_GetVideoDevice();
dbbfdb9ea716 Simplified clipboard API for sanity's sake.
Sam Lantinga <slouken@libsdl.org>
parents: 4493
diff changeset
32
dbbfdb9ea716 Simplified clipboard API for sanity's sake.
Sam Lantinga <slouken@libsdl.org>
parents: 4493
diff changeset
33 if (_this->SetClipboardText) {
dbbfdb9ea716 Simplified clipboard API for sanity's sake.
Sam Lantinga <slouken@libsdl.org>
parents: 4493
diff changeset
34 return _this->SetClipboardText(_this, text);
dbbfdb9ea716 Simplified clipboard API for sanity's sake.
Sam Lantinga <slouken@libsdl.org>
parents: 4493
diff changeset
35 } else {
dbbfdb9ea716 Simplified clipboard API for sanity's sake.
Sam Lantinga <slouken@libsdl.org>
parents: 4493
diff changeset
36 _this->clipboard_text = SDL_strdup(text);
dbbfdb9ea716 Simplified clipboard API for sanity's sake.
Sam Lantinga <slouken@libsdl.org>
parents: 4493
diff changeset
37 return 0;
dbbfdb9ea716 Simplified clipboard API for sanity's sake.
Sam Lantinga <slouken@libsdl.org>
parents: 4493
diff changeset
38 }
4493
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 }
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 char *
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 SDL_GetClipboardText()
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 {
4495
dbbfdb9ea716 Simplified clipboard API for sanity's sake.
Sam Lantinga <slouken@libsdl.org>
parents: 4493
diff changeset
44 SDL_VideoDevice *_this = SDL_GetVideoDevice();
4493
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45
4495
dbbfdb9ea716 Simplified clipboard API for sanity's sake.
Sam Lantinga <slouken@libsdl.org>
parents: 4493
diff changeset
46 if (_this->GetClipboardText) {
dbbfdb9ea716 Simplified clipboard API for sanity's sake.
Sam Lantinga <slouken@libsdl.org>
parents: 4493
diff changeset
47 return _this->GetClipboardText(_this);
4493
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 } else {
4495
dbbfdb9ea716 Simplified clipboard API for sanity's sake.
Sam Lantinga <slouken@libsdl.org>
parents: 4493
diff changeset
49 const char *text = _this->clipboard_text;
dbbfdb9ea716 Simplified clipboard API for sanity's sake.
Sam Lantinga <slouken@libsdl.org>
parents: 4493
diff changeset
50 if (!text) {
dbbfdb9ea716 Simplified clipboard API for sanity's sake.
Sam Lantinga <slouken@libsdl.org>
parents: 4493
diff changeset
51 text = "";
dbbfdb9ea716 Simplified clipboard API for sanity's sake.
Sam Lantinga <slouken@libsdl.org>
parents: 4493
diff changeset
52 }
dbbfdb9ea716 Simplified clipboard API for sanity's sake.
Sam Lantinga <slouken@libsdl.org>
parents: 4493
diff changeset
53 return SDL_strdup(text);
4493
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 }
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 }
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 SDL_bool
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 SDL_HasClipboardText()
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 {
4495
dbbfdb9ea716 Simplified clipboard API for sanity's sake.
Sam Lantinga <slouken@libsdl.org>
parents: 4493
diff changeset
60 SDL_VideoDevice *_this = SDL_GetVideoDevice();
4493
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61
4495
dbbfdb9ea716 Simplified clipboard API for sanity's sake.
Sam Lantinga <slouken@libsdl.org>
parents: 4493
diff changeset
62 if (_this->HasClipboardText) {
dbbfdb9ea716 Simplified clipboard API for sanity's sake.
Sam Lantinga <slouken@libsdl.org>
parents: 4493
diff changeset
63 return _this->HasClipboardText(_this);
dbbfdb9ea716 Simplified clipboard API for sanity's sake.
Sam Lantinga <slouken@libsdl.org>
parents: 4493
diff changeset
64 } else {
dbbfdb9ea716 Simplified clipboard API for sanity's sake.
Sam Lantinga <slouken@libsdl.org>
parents: 4493
diff changeset
65 if (_this->clipboard_text) {
dbbfdb9ea716 Simplified clipboard API for sanity's sake.
Sam Lantinga <slouken@libsdl.org>
parents: 4493
diff changeset
66 return SDL_TRUE;
dbbfdb9ea716 Simplified clipboard API for sanity's sake.
Sam Lantinga <slouken@libsdl.org>
parents: 4493
diff changeset
67 } else {
dbbfdb9ea716 Simplified clipboard API for sanity's sake.
Sam Lantinga <slouken@libsdl.org>
parents: 4493
diff changeset
68 return SDL_FALSE;
dbbfdb9ea716 Simplified clipboard API for sanity's sake.
Sam Lantinga <slouken@libsdl.org>
parents: 4493
diff changeset
69 }
dbbfdb9ea716 Simplified clipboard API for sanity's sake.
Sam Lantinga <slouken@libsdl.org>
parents: 4493
diff changeset
70 }
4493
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 }
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72
f0b7c8d169f5 First pass at clipboard API, still very much in progress
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 /* vi: set ts=4 sw=4 expandtab: */