ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/BeOS/clip_beos.cpp
Revision: 1.10
Committed: 2008-01-01T09:40:32Z (16 years, 4 months ago) by gbeauche
Branch: MAIN
CVS Tags: HEAD
Changes since 1.9: +1 -1 lines
Log Message:
Happy New Year!

File Contents

# Content
1 /*
2 * clip_beos.cpp - Clipboard handling, BeOS implementation
3 *
4 * Basilisk II (C) 1997-2008 Christian Bauer
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #include "sysdeps.h"
22
23 #include <AppKit.h>
24 #include <support/UTF8.h>
25
26 #include "clip.h"
27 #include "prefs.h"
28
29 #define DEBUG 1
30 #include "debug.h"
31
32
33 // Flag: Don't convert clipboard text
34 static bool no_clip_conversion;
35
36
37 /*
38 * Initialization
39 */
40
41 void ClipInit(void)
42 {
43 no_clip_conversion = PrefsFindBool("noclipconversion");
44 }
45
46
47 /*
48 * Deinitialization
49 */
50
51 void ClipExit(void)
52 {
53 }
54
55
56 /*
57 * Mac application reads clipboard
58 */
59
60 void GetScrap(void **handle, uint32 type, int32 offset)
61 {
62 D(bug("GetScrap handle %p, type %08x, offset %d\n", handle, type, offset));
63 }
64
65
66 /*
67 * Mac application wrote to clipboard
68 */
69
70 void PutScrap(uint32 type, void *scrap, int32 length)
71 {
72 D(bug("PutScrap type %08lx, data %08lx, length %ld\n", type, scrap, length));
73 if (length <= 0)
74 return;
75
76 switch (type) {
77 case 'TEXT':
78 D(bug(" clipping TEXT\n"));
79 if (be_clipboard->Lock()) {
80 be_clipboard->Clear();
81 BMessage *clipper = be_clipboard->Data();
82
83 if (no_clip_conversion) {
84
85 // Only convert CR->LF
86 char *buf = new char[length];
87 for (int i=0; i<length; i++) {
88 if (i[(char *)scrap] == 13)
89 buf[i] = 10;
90 else
91 buf[i] = i[(char *)scrap];
92 }
93
94 // Add text to Be clipboard
95 clipper->AddData("text/plain", B_MIME_TYPE, buf, length);
96 be_clipboard->Commit();
97 delete[] buf;
98
99 } else {
100
101 // Convert text from Mac charset to UTF-8
102 int32 dest_length = length*3;
103 int32 state = 0;
104 char *buf = new char[dest_length];
105 if (convert_to_utf8(B_MAC_ROMAN_CONVERSION, (char *)scrap, &length, buf, &dest_length, &state) == B_OK) {
106 for (int i=0; i<dest_length; i++)
107 if (buf[i] == 13)
108 buf[i] = 10;
109
110 // Add text to Be clipboard
111 clipper->AddData("text/plain", B_MIME_TYPE, buf, dest_length);
112 be_clipboard->Commit();
113 }
114 delete[] buf;
115 }
116 be_clipboard->Unlock();
117 }
118 break;
119 }
120 }