1 /*
2 clipbrd_beos.cpp - BeOS clipbrd interaction.
3
4 Copyright (C) 2011 Fran�ois Revol <revol@free.fr>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "sysdeps.h"
22 #if defined(OS_beos)
23 #include <Clipboard.h>
24 #include <String.h>
25 #include <string.h>
26 #include <stdio.h>
27
28 #include "SDL_compat.h"
29 #include "clipbrd.h"
30
31 #define DEBUG 0
32 #include "debug.h"
33
init_aclip()34 int init_aclip() { return 0; }
35
filter_aclip(const SDL_Event * event)36 int filter_aclip(const SDL_Event *event) { UNUSED(event); return 1; }
37
write_aclip(char * data,size_t len)38 void write_aclip(char *data, size_t len)
39 {
40 BMessage *clip = NULL;
41 fprintf(stderr, "%s()\n", __FUNCTION__);
42 if (be_clipboard->Lock()) {
43 be_clipboard->Clear();
44 clip = be_clipboard->Data();
45 if (clip) {
46 BString text(data, len);
47 text.RemoveAll("\r");
48 clip->AddData("text/plain", B_MIME_TYPE, text.String(), text.Length());
49 be_clipboard->Commit();
50 }
51 be_clipboard->Unlock();
52 }
53 }
54
read_aclip(size_t * len)55 char * read_aclip( size_t *len)
56 {
57 const char *text;
58 ssize_t textLen;
59 BMessage *clip = NULL;
60 char *data = NULL;
61 fprintf(stderr, "%s()\n", __FUNCTION__);
62
63 if (be_clipboard->Lock()) {
64 clip = be_clipboard->Data();
65 if (clip && clip->FindData("text/plain", B_MIME_TYPE, (const void **)&text, &textLen) == B_OK) {
66 BString t(text, textLen);
67 t.ReplaceAll("\n", "\r\n");
68 *len = t.Length();
69 data = new char[*len];
70 memcpy( data, t.String(), *len);
71 }
72 be_clipboard->Unlock();
73 }
74 return data;
75 }
76
77 #endif
78
79