ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/BeOS/clip_beos.cpp
Revision: 1.5
Committed: 2001-02-09T20:04:15Z (23 years, 9 months ago) by cebix
Branch: MAIN
CVS Tags: snapshot-17022001, snapshot-29052001, release-0_9-1
Changes since 1.4: +1 -1 lines
Log Message:
fixed compilation problems under BeOS

File Contents

# Content
1 /*
2 * clip_beos.cpp - Clipboard handling, BeOS implementation
3 *
4 * Basilisk II (C) 1997-2001 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 wrote to clipboard
58 */
59
60 void PutScrap(uint32 type, void *scrap, int32 length)
61 {
62 D(bug("PutScrap type %08lx, data %08lx, length %ld\n", type, scrap, length));
63 if (length <= 0)
64 return;
65
66 switch (type) {
67 case 'TEXT':
68 D(bug(" clipping TEXT\n"));
69 if (be_clipboard->Lock()) {
70 be_clipboard->Clear();
71 BMessage *clipper = be_clipboard->Data();
72
73 if (no_clip_conversion) {
74
75 // Only convert CR->LF
76 char *buf = new char[length];
77 for (int i=0; i<length; i++) {
78 if (i[(char *)scrap] == 13)
79 buf[i] = 10;
80 else
81 buf[i] = i[(char *)scrap];
82 }
83
84 // Add text to Be clipboard
85 clipper->AddData("text/plain", B_MIME_TYPE, buf, length);
86 be_clipboard->Commit();
87 delete[] buf;
88
89 } else {
90
91 // Convert text from Mac charset to UTF-8
92 int32 dest_length = length*3;
93 int32 state = 0;
94 char *buf = new char[dest_length];
95 if (convert_to_utf8(B_MAC_ROMAN_CONVERSION, (char *)scrap, &length, buf, &dest_length, &state) == B_OK) {
96 for (int i=0; i<dest_length; i++)
97 if (buf[i] == 13)
98 buf[i] = 10;
99
100 // Add text to Be clipboard
101 clipper->AddData("text/plain", B_MIME_TYPE, buf, dest_length);
102 be_clipboard->Commit();
103 }
104 delete[] buf;
105 }
106 be_clipboard->Unlock();
107 }
108 break;
109 }
110 }