1 |
cebix |
1.1 |
/* |
2 |
|
|
* clip_amiga.cpp - Clipboard handling, AmigaOS implementation |
3 |
|
|
* |
4 |
|
|
* Basilisk II (C) 1997-1999 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 <exec/types.h> |
22 |
|
|
#include <libraries/iffparse.h> |
23 |
|
|
#include <devices/clipboard.h> |
24 |
|
|
#include <proto/exec.h> |
25 |
|
|
#include <proto/iffparse.h> |
26 |
|
|
|
27 |
|
|
#include "sysdeps.h" |
28 |
|
|
#include "clip.h" |
29 |
|
|
|
30 |
|
|
#define DEBUG 0 |
31 |
|
|
#include "debug.h" |
32 |
|
|
|
33 |
|
|
|
34 |
|
|
// Global variables |
35 |
|
|
static struct IFFHandle *iffw = NULL; |
36 |
|
|
static struct ClipboardHandle *ch = NULL; |
37 |
|
|
static bool clipboard_open = false; |
38 |
|
|
|
39 |
|
|
|
40 |
|
|
// Conversion tables |
41 |
|
|
static const uint8 mac2iso[0x80] = { |
42 |
|
|
0xc4, 0xc5, 0xc7, 0xc9, 0xd1, 0xd6, 0xdc, 0xe1, |
43 |
|
|
0xe0, 0xe2, 0xe4, 0xe3, 0xe5, 0xe7, 0xe9, 0xe8, |
44 |
|
|
0xea, 0xeb, 0xed, 0xec, 0xee, 0xef, 0xf1, 0xf3, |
45 |
|
|
0xf2, 0xf4, 0xf6, 0xf5, 0xfa, 0xf9, 0xfb, 0xfc, |
46 |
|
|
0x2b, 0xb0, 0xa2, 0xa3, 0xa7, 0xb7, 0xb6, 0xdf, |
47 |
|
|
0xae, 0xa9, 0x20, 0xb4, 0xa8, 0x23, 0xc6, 0xd8, |
48 |
|
|
0x20, 0xb1, 0x3c, 0x3e, 0xa5, 0xb5, 0xf0, 0x53, |
49 |
|
|
0x50, 0x70, 0x2f, 0xaa, 0xba, 0x4f, 0xe6, 0xf8, |
50 |
|
|
0xbf, 0xa1, 0xac, 0x2f, 0x66, 0x7e, 0x44, 0xab, |
51 |
|
|
0xbb, 0x2e, 0x20, 0xc0, 0xc3, 0xd5, 0x4f, 0x6f, |
52 |
|
|
0x2d, 0x2d, 0x22, 0x22, 0x60, 0x27, 0xf7, 0x20, |
53 |
|
|
0xff, 0x59, 0x2f, 0xa4, 0x3c, 0x3e, 0x66, 0x66, |
54 |
|
|
0x23, 0xb7, 0x2c, 0x22, 0x25, 0xc2, 0xca, 0xc1, |
55 |
|
|
0xcb, 0xc8, 0xcd, 0xce, 0xcf, 0xcc, 0xd3, 0xd4, |
56 |
|
|
0x20, 0xd2, 0xda, 0xdb, 0xd9, 0x69, 0x5e, 0x7e, |
57 |
|
|
0xaf, 0x20, 0xb7, 0xb0, 0xb8, 0x22, 0xb8, 0x20 |
58 |
|
|
}; |
59 |
|
|
|
60 |
|
|
|
61 |
|
|
/* |
62 |
|
|
* Initialization |
63 |
|
|
*/ |
64 |
|
|
|
65 |
|
|
void ClipInit(void) |
66 |
|
|
{ |
67 |
|
|
// Create clipboard IFF handle |
68 |
|
|
iffw = AllocIFF(); |
69 |
|
|
if (iffw) { |
70 |
|
|
ch = OpenClipboard(PRIMARY_CLIP); |
71 |
|
|
if (ch) { |
72 |
|
|
iffw->iff_Stream = (ULONG)ch; |
73 |
|
|
InitIFFasClip(iffw); |
74 |
|
|
clipboard_open = true; |
75 |
|
|
} |
76 |
|
|
} |
77 |
|
|
} |
78 |
|
|
|
79 |
|
|
|
80 |
|
|
/* |
81 |
|
|
* Deinitialization |
82 |
|
|
*/ |
83 |
|
|
|
84 |
|
|
void ClipExit(void) |
85 |
|
|
{ |
86 |
|
|
if (ch) |
87 |
|
|
CloseClipboard(ch); |
88 |
|
|
if (iffw) |
89 |
|
|
FreeIFF(iffw); |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
|
93 |
|
|
/* |
94 |
|
|
* Mac application wrote to clipboard |
95 |
|
|
*/ |
96 |
|
|
|
97 |
|
|
void PutScrap(uint32 type, void *scrap, int32 length) |
98 |
|
|
{ |
99 |
|
|
D(bug("PutScrap type %08lx, data %08lx, length %ld\n", type, scrap, length)); |
100 |
|
|
if (length <= 0 || !clipboard_open) |
101 |
|
|
return; |
102 |
|
|
|
103 |
|
|
switch (type) { |
104 |
|
|
case 'TEXT': { |
105 |
|
|
D(bug(" clipping TEXT\n")); |
106 |
|
|
|
107 |
|
|
// Open IFF stream |
108 |
|
|
if (OpenIFF(iffw, IFFF_WRITE)) |
109 |
|
|
break; |
110 |
|
|
|
111 |
|
|
// Convert text from Mac charset to ISO-Latin1 |
112 |
|
|
uint8 *buf = new uint8[length]; |
113 |
|
|
uint8 *p = (uint8 *)scrap; |
114 |
|
|
uint8 *q = buf; |
115 |
|
|
for (int i=0; i<length; i++) { |
116 |
|
|
uint8 c = *p++; |
117 |
|
|
if (c < 0x80) { |
118 |
|
|
if (c == 13) // CR -> LF |
119 |
|
|
c == 10; |
120 |
|
|
} else |
121 |
|
|
c = mac2iso[c & 0x7f]; |
122 |
|
|
*q++ = c; |
123 |
|
|
} |
124 |
|
|
|
125 |
|
|
// Write text |
126 |
|
|
if (!PushChunk(iffw, 'FTXT', 'FORM', IFFSIZE_UNKNOWN)) { |
127 |
|
|
if (!PushChunk(iffw, 0, 'CHRS', IFFSIZE_UNKNOWN)) { |
128 |
|
|
WriteChunkBytes(iffw, scrap, length); |
129 |
|
|
PopChunk(iffw); |
130 |
|
|
} |
131 |
|
|
PopChunk(iffw); |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
// Close IFF stream |
135 |
|
|
CloseIFF(iffw); |
136 |
|
|
delete[] buf; |
137 |
|
|
break; |
138 |
|
|
} |
139 |
|
|
} |
140 |
|
|
} |