1 |
|
/* |
2 |
|
* clip_beos.cpp - Clipboard handling, BeOS implementation |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-2000 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2005 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 |
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 |
|
|
24 |
– |
#include "sysdeps.h" |
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 |
|
|
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 |
|
|
80 |
|
be_clipboard->Clear(); |
81 |
|
BMessage *clipper = be_clipboard->Data(); |
82 |
|
|
83 |
< |
// Convert text from Mac charset to UTF-8 |
84 |
< |
int32 dest_length = length*3; |
85 |
< |
int32 state = 0; |
86 |
< |
char *buf = new char[dest_length]; |
87 |
< |
if (convert_to_utf8(B_MAC_ROMAN_CONVERSION, (char *)scrap, &length, buf, &dest_length, &state) == B_OK) { |
88 |
< |
for (int i=0; i<dest_length; i++) |
72 |
< |
if (buf[i] == 13) |
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 |
< |
|
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, dest_length); |
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 |
|
} |
79 |
– |
delete[] buf; |
116 |
|
be_clipboard->Unlock(); |
117 |
|
} |
118 |
|
break; |